Refactor get_adjusted_key_size.

This commit is contained in:
Ondrej Kozina
2025-04-17 10:49:57 +02:00
committed by Milan Broz
parent 48683f7316
commit ff7a21eb94
4 changed files with 9 additions and 7 deletions

View File

@@ -1683,7 +1683,8 @@ int luksFormat(struct crypt_device **r_cd, char **r_password, size_t *r_password
goto out;
}
keysize = get_adjusted_key_size(cipher_mode, DEFAULT_LUKS1_KEYBITS, integrity_keysize);
keysize = get_adjusted_key_size(cipher_mode, ARG_UINT32(OPT_KEY_SIZE_ID),
DEFAULT_LUKS1_KEYBITS, integrity_keysize);
if (ARG_SET(OPT_HW_OPAL_ONLY_ID))
keysize = opal_params.user_key_size;

View File

@@ -139,12 +139,11 @@ int set_tries_tty(bool keyring)
return (tools_is_stdin(ARG_STR(OPT_KEY_FILE_ID)) && isatty(STDIN_FILENO)) ? ARG_UINT32(OPT_TRIES_ID) : 1;
}
int get_adjusted_key_size(const char *cipher_mode, uint32_t default_size_bits, int integrity_keysize)
int get_adjusted_key_size(const char *cipher_mode, uint32_t keysize_bits,
uint32_t default_size_bits, int integrity_keysize)
{
uint32_t keysize_bits = ARG_UINT32(OPT_KEY_SIZE_ID);
#if ENABLE_LUKS_ADJUST_XTS_KEYSIZE
if (!ARG_SET(OPT_KEY_SIZE_ID) && !strncmp(cipher_mode, "xts-", 4)) {
if (!keysize_bits && !strncmp(cipher_mode, "xts-", 4)) {
if (default_size_bits == 128)
keysize_bits = 256;
else if (default_size_bits == 256)

View File

@@ -27,7 +27,8 @@ int set_pbkdf_params(struct crypt_device *cd, const char *dev_type);
int set_tries_tty(bool keyring);
int get_adjusted_key_size(const char *cipher_mode, uint32_t default_size_bits, int integrity_keysize);
int get_adjusted_key_size(const char *cipher_mode, uint32_t keysize_bits,
uint32_t default_size_bits, int integrity_keysize);
int luksFormat(struct crypt_device **r_cd, char **r_password, size_t *r_passwordLen);

View File

@@ -1146,7 +1146,8 @@ static int reencrypt_luks2_init(struct crypt_device *cd, const char *data_device
/* key size */
if (ARG_SET(OPT_KEY_SIZE_ID) || new_cipher)
key_size = get_adjusted_key_size(mode, DEFAULT_LUKS1_KEYBITS, 0);
key_size = get_adjusted_key_size(mode, ARG_UINT32(OPT_KEY_SIZE_ID),
DEFAULT_LUKS1_KEYBITS, 0);
else
key_size = crypt_get_volume_key_size(cd);