2 * utils_crypt - cipher utilities for cryptsetup
4 * Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
5 * Copyright (C) 2009-2023 Red Hat, Inc. All rights reserved.
6 * Copyright (C) 2009-2023 Milan Broz
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.
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.
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.
23 #ifndef _UTILS_CRYPT_H
24 #define _UTILS_CRYPT_H
30 #define MAX_CIPHER_LEN 32
31 #define MAX_CIPHER_LEN_STR "31"
32 #define MAX_KEYFILES 32
33 #define MAX_CAPI_ONE_LEN 2 * MAX_CIPHER_LEN
34 #define MAX_CAPI_ONE_LEN_STR "63" /* for sscanf length + '\0' */
35 #define MAX_CAPI_LEN 144 /* should be enough to fit whole capi string */
37 int crypt_parse_name_and_mode(const char *s, char *cipher,
38 int *key_nums, char *cipher_mode);
39 int crypt_parse_hash_integrity_mode(const char *s, char *integrity);
40 int crypt_parse_integrity_mode(const char *s, char *integrity,
41 int *integrity_key_size);
42 int crypt_parse_pbkdf(const char *s, const char **pbkdf);
44 ssize_t crypt_hex_to_bytes(const char *hex, char **result, int safe_alloc);
45 char *crypt_bytes_to_hex(size_t size, const char *bytes);
46 void crypt_log_hex(struct crypt_device *cd,
47 const char *bytes, size_t size,
48 const char *sep, int numwrap, const char *wrapsep);
50 bool crypt_is_cipher_null(const char *cipher_spec);
52 int crypt_capi_to_cipher(char **org_c, char **org_i, const char *c_dm, const char *i_dm);
54 #endif /* _UTILS_CRYPT_H */