diff --git a/lib/utils_crypt.c b/lib/utils_crypt.c index 7dff02e0..5c88f8f2 100644 --- a/lib/utils_crypt.c +++ b/lib/utils_crypt.c @@ -177,3 +177,10 @@ ssize_t crypt_hex_to_bytes(const char *hex, char **result, int safe_alloc) *result = bytes; return i; } + +bool crypt_is_cipher_null(const char *cipher_spec) +{ + if (!cipher_spec) + return false; + return (strstr(cipher_spec, "cipher_null") || !strcmp(cipher_spec, "null")); +} diff --git a/lib/utils_crypt.h b/lib/utils_crypt.h index 9ee6a617..9b749699 100644 --- a/lib/utils_crypt.h +++ b/lib/utils_crypt.h @@ -23,6 +23,7 @@ #ifndef _UTILS_CRYPT_H #define _UTILS_CRYPT_H +#include #include #define MAX_CIPHER_LEN 32 @@ -38,4 +39,6 @@ int crypt_parse_pbkdf(const char *s, const char **pbkdf); ssize_t crypt_hex_to_bytes(const char *hex, char **result, int safe_alloc); +bool crypt_is_cipher_null(const char *cipher_spec); + #endif /* _UTILS_CRYPT_H */ diff --git a/src/cryptsetup.c b/src/cryptsetup.c index bff46963..9fb01f8a 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -1327,7 +1327,7 @@ static int _luksFormat(struct crypt_device **r_cd, char **r_password, size_t *r_ } /* Never call pwquality if using null cipher */ - if (tools_is_cipher_null(cipher)) + if (crypt_is_cipher_null(cipher)) opt_force_password = 1; if ((r = crypt_init(&cd, header_device))) { @@ -1725,7 +1725,7 @@ static int luksAddUnboundKey(void) goto out; /* Never call pwquality if using null cipher */ - if (tools_is_cipher_null(crypt_get_cipher(cd))) + if (crypt_is_cipher_null(crypt_get_cipher(cd))) opt_force_password = 1; keysize = opt_key_size / 8; @@ -1792,7 +1792,7 @@ static int action_luksAddKey(void) goto out; /* Never call pwquality if using null cipher */ - if (tools_is_cipher_null(crypt_get_cipher(cd))) + if (crypt_is_cipher_null(crypt_get_cipher(cd))) opt_force_password = 1; keysize = crypt_get_volume_key_size(cd); @@ -1895,7 +1895,7 @@ static int action_luksChangeKey(void) goto out; /* Never call pwquality if using null cipher */ - if (tools_is_cipher_null(crypt_get_cipher(cd))) + if (crypt_is_cipher_null(crypt_get_cipher(cd))) opt_force_password = 1; r = set_pbkdf_params(cd, crypt_get_type(cd)); diff --git a/src/cryptsetup.h b/src/cryptsetup.h index eb77dbe2..5a23eeb5 100644 --- a/src/cryptsetup.h +++ b/src/cryptsetup.h @@ -97,7 +97,6 @@ int tools_get_key(const char *prompt, void tools_passphrase_msg(int r); int tools_is_stdin(const char *key_file); int tools_string_to_size(struct crypt_device *cd, const char *s, uint64_t *size); -int tools_is_cipher_null(const char *cipher); void tools_clear_line(void); diff --git a/src/utils_tools.c b/src/utils_tools.c index d523c1aa..390590a5 100644 --- a/src/utils_tools.c +++ b/src/utils_tools.c @@ -597,14 +597,6 @@ out: return r; } -int tools_is_cipher_null(const char *cipher) -{ - if (!cipher) - return 0; - - return !strcmp(cipher, "cipher_null") ? 1 : 0; -} - /* * Keyfile - is standard input treated as a binary file (no EOL handling). */