|
11 | 11 | #include "../luks1/luks.h" |
12 | 12 | #include "../luks1/af.h" |
13 | 13 |
|
14 | | -/* This differs from LUKS_check_cipher() that it does not check dm-crypt fallback. */ |
15 | | -int LUKS2_check_cipher(struct crypt_device *cd, |
16 | | - size_t keylength, |
17 | | - const char *cipher, |
18 | | - const char *cipher_mode) |
19 | | -{ |
20 | | - int r; |
21 | | - struct crypt_storage *s; |
22 | | - char buf[SECTOR_SIZE], *empty_key; |
23 | | - |
24 | | - log_dbg(cd, "Checking if cipher %s-%s is usable (storage wrapper).", cipher, cipher_mode); |
25 | | - |
26 | | - empty_key = malloc(keylength); |
27 | | - if (!empty_key) |
28 | | - return -ENOMEM; |
29 | | - |
30 | | - /* No need to get KEY quality random but it must avoid known weak keys. */ |
31 | | - r = crypt_random_get(cd, empty_key, keylength, CRYPT_RND_NORMAL); |
32 | | - if (r < 0) |
33 | | - goto out; |
34 | | - |
35 | | - r = crypt_storage_init(&s, SECTOR_SIZE, cipher, cipher_mode, empty_key, keylength, false); |
36 | | - if (r < 0) |
37 | | - goto out; |
38 | | - |
39 | | - memset(buf, 0, sizeof(buf)); |
40 | | - r = crypt_storage_decrypt(s, 0, sizeof(buf), buf); |
41 | | - crypt_storage_destroy(s); |
42 | | -out: |
43 | | - free(empty_key); |
44 | | - return r; |
45 | | -} |
46 | | - |
47 | 14 | static int json_luks1_keyslot(const struct luks_phdr *hdr_v1, int keyslot, json_object **keyslot_object) |
48 | 15 | { |
49 | 16 | char *base64_str, cipher[LUKS_CIPHERNAME_L+LUKS_CIPHERMODE_L]; |
@@ -585,7 +552,7 @@ int LUKS2_luks1_to_luks2(struct crypt_device *cd, struct luks_phdr *hdr1, struct |
585 | 552 | return -EINVAL; |
586 | 553 | } |
587 | 554 |
|
588 | | - if (LUKS2_check_cipher(cd, hdr1->keyBytes, hdr1->cipherName, hdr1->cipherMode)) { |
| 555 | + if (crypt_check_cipher(cd, hdr1->keyBytes, hdr1->cipherName, hdr1->cipherMode)) { |
589 | 556 | log_err(cd, _("Unable to use cipher specification %s-%s for LUKS2."), |
590 | 557 | hdr1->cipherName, hdr1->cipherMode); |
591 | 558 | return -EINVAL; |
|
0 commit comments