Move cipher_null check in internal function crypt_is_cipher_null.

Also removes tools helper so that we keep check in one place.
This commit is contained in:
Ondrej Kozina
2021-02-10 17:48:56 +01:00
parent 7d912c7d3e
commit a4d7c46d80
5 changed files with 14 additions and 13 deletions

View File

@@ -175,3 +175,10 @@ ssize_t crypt_hex_to_bytes(const char *hex, char **result, int safe_alloc)
*result = bytes; *result = bytes;
return i; 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"));
}

View File

@@ -23,6 +23,7 @@
#ifndef _UTILS_CRYPT_H #ifndef _UTILS_CRYPT_H
#define _UTILS_CRYPT_H #define _UTILS_CRYPT_H
#include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#define MAX_CIPHER_LEN 32 #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); 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 */ #endif /* _UTILS_CRYPT_H */

View File

@@ -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 */ /* Never call pwquality if using null cipher */
if (tools_is_cipher_null(cipher)) if (crypt_is_cipher_null(cipher))
ARG_SET_TRUE(OPT_FORCE_PASSWORD_ID); ARG_SET_TRUE(OPT_FORCE_PASSWORD_ID);
if ((r = crypt_init(&cd, header_device))) { if ((r = crypt_init(&cd, header_device))) {
@@ -1732,7 +1732,7 @@ static int luksAddUnboundKey(void)
goto out; goto out;
/* Never call pwquality if using null cipher */ /* 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)))
ARG_SET_TRUE(OPT_FORCE_PASSWORD_ID); ARG_SET_TRUE(OPT_FORCE_PASSWORD_ID);
keysize = ARG_UINT32(OPT_KEY_SIZE_ID) / 8; keysize = ARG_UINT32(OPT_KEY_SIZE_ID) / 8;
@@ -1797,7 +1797,7 @@ static int action_luksAddKey(void)
goto out; goto out;
/* Never call pwquality if using null cipher */ /* 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)))
ARG_SET_TRUE(OPT_FORCE_PASSWORD_ID); ARG_SET_TRUE(OPT_FORCE_PASSWORD_ID);
keysize = crypt_get_volume_key_size(cd); keysize = crypt_get_volume_key_size(cd);
@@ -1900,7 +1900,7 @@ static int action_luksChangeKey(void)
goto out; goto out;
/* Never call pwquality if using null cipher */ /* 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)))
ARG_SET_TRUE(OPT_FORCE_PASSWORD_ID); ARG_SET_TRUE(OPT_FORCE_PASSWORD_ID);
r = set_pbkdf_params(cd, crypt_get_type(cd)); r = set_pbkdf_params(cd, crypt_get_type(cd));

View File

@@ -87,7 +87,6 @@ int tools_get_key(const char *prompt,
void tools_passphrase_msg(int r); void tools_passphrase_msg(int r);
int tools_is_stdin(const char *key_file); int tools_is_stdin(const char *key_file);
int tools_string_to_size(const char *s, uint64_t *size); int tools_string_to_size(const char *s, uint64_t *size);
int tools_is_cipher_null(const char *cipher);
struct tools_progress_params { struct tools_progress_params {
uint32_t frequency; uint32_t frequency;

View File

@@ -435,14 +435,6 @@ int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr)
return r; 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). * Keyfile - is standard input treated as a binary file (no EOL handling).
*/ */