Fix bad parsing of capi:xts(aes)-plain

Corrent logic confuses it with aes-plain (capi:xts(aes)-plain
does not work in luksFormat).
For CAPI format we need to skip this test.
This commit is contained in:
Milan Broz
2024-05-09 15:45:04 +02:00
parent d590c74a0e
commit 8f4a149ed3
2 changed files with 11 additions and 4 deletions

View File

@@ -28,15 +28,17 @@ int crypt_parse_name_and_mode(const char *s, char *cipher, int *key_nums,
if (sscanf(s, "%" MAX_CIPHER_LEN_STR "[^-]-%" MAX_CIPHER_LEN_STR "s",
cipher, cipher_mode) == 2) {
if (!strcmp(cipher_mode, "plain"))
strcpy(cipher_mode, "cbc-plain");
if (!strncmp(cipher, "capi:", 5)) {
/* CAPI must not use internal cipher driver names with dash */
if (strchr(cipher_mode, ')'))
return -EINVAL;
if (key_nums)
*key_nums = 1;
} else if (key_nums) {
return 0;
}
if (!strcmp(cipher_mode, "plain"))
strcpy(cipher_mode, "cbc-plain");
if (key_nums) {
char *tmp = strchr(cipher, ':');
*key_nums = tmp ? atoi(++tmp) : 1;
if (!*key_nums)
@@ -56,7 +58,8 @@ int crypt_parse_name_and_mode(const char *s, char *cipher, int *key_nums,
}
if (sscanf(s, "%" MAX_CIPHER_LEN_STR "[^-]", cipher) == 1) {
strcpy(cipher_mode, "cbc-plain");
if (strncmp(cipher, "capi:", 5))
strcpy(cipher_mode, "cbc-plain");
if (key_nums)
*key_nums = 1;
return 0;