9bf8ab4f13c59f13e05bdb0f7ce72c9b4d6970e8
[platform/upstream/cryptsetup.git] / lib / utils_crypt.h
1 /*
2  * utils_crypt - cipher utilities for cryptsetup
3  *
4  * Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
5  * Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #ifndef _UTILS_CRYPT_H
22 #define _UTILS_CRYPT_H
23
24 #include <unistd.h>
25 #include "config.h"
26
27 #define MAX_CIPHER_LEN          32
28 #define MAX_CIPHER_LEN_STR      "32"
29 #define MAX_KEYFILES            32
30
31 struct crypt_device;
32
33 int crypt_parse_name_and_mode(const char *s, char *cipher,
34                               int *key_nums, char *cipher_mode);
35
36 int crypt_get_key(const char *prompt,
37                   char **key, size_t *key_size,
38                   size_t keyfile_offset, size_t keyfile_size_max,
39                   const char *key_file,
40                   int timeout, int verify,
41                   struct crypt_device *cd);
42
43 void *crypt_safe_alloc(size_t size);
44 void crypt_safe_free(void *data);
45 void *crypt_safe_realloc(void *data, size_t size);
46
47 ssize_t crypt_hex_to_bytes(const char *hex, char **result, int safe_alloc);
48 int crypt_string_to_size(struct crypt_device *cd, const char *s, uint64_t *size);
49
50 #endif /* _UTILS_CRYPT_H */