Fix sscanf cipher string and avoid warning wih -fsanitize=address.
[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  * Copyright (C) 2009-2012, Milan Broz
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef _UTILS_CRYPT_H
24 #define _UTILS_CRYPT_H
25
26 #include <unistd.h>
27
28 #define MAX_CIPHER_LEN          32
29 #define MAX_CIPHER_LEN_STR      "31"
30 #define MAX_KEYFILES            32
31
32 struct crypt_device;
33
34 int crypt_parse_name_and_mode(const char *s, char *cipher,
35                               int *key_nums, char *cipher_mode);
36
37 int crypt_get_key(const char *prompt,
38                   char **key, size_t *key_size,
39                   size_t keyfile_offset, size_t keyfile_size_max,
40                   const char *key_file,
41                   int timeout, int verify,
42                   struct crypt_device *cd);
43
44 void *crypt_safe_alloc(size_t size);
45 void crypt_safe_free(void *data);
46 void *crypt_safe_realloc(void *data, size_t size);
47
48 ssize_t crypt_hex_to_bytes(const char *hex, char **result, int safe_alloc);
49 int crypt_string_to_size(struct crypt_device *cd, const char *s, uint64_t *size);
50
51 #endif /* _UTILS_CRYPT_H */