Skip to content

Commit 4288880

Browse files
onikombroz
authored andcommitted
Switch LUKS2 convert code to LUKS_check_cipher check.
1 parent 3504525 commit 4288880

2 files changed

Lines changed: 1 addition & 39 deletions

File tree

lib/luks2/luks2_internal.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,6 @@ int LUKS2_find_area_max_gap(struct crypt_device *cd, struct luks2_hdr *hdr,
226226

227227
uint64_t LUKS2_hdr_and_areas_size_jobj(json_object *jobj);
228228

229-
int LUKS2_check_cipher(struct crypt_device *cd,
230-
size_t keylength,
231-
const char *cipher,
232-
const char *cipher_mode);
233-
234229
static inline const char *crypt_reencrypt_mode_to_str(crypt_reencrypt_mode_info mi)
235230
{
236231
if (mi == CRYPT_REENCRYPT_REENCRYPT)

lib/luks2/luks2_luks1_convert.c

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,6 @@
1111
#include "../luks1/luks.h"
1212
#include "../luks1/af.h"
1313

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-
4714
static int json_luks1_keyslot(const struct luks_phdr *hdr_v1, int keyslot, json_object **keyslot_object)
4815
{
4916
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
585552
return -EINVAL;
586553
}
587554

588-
if (LUKS2_check_cipher(cd, hdr1->keyBytes, hdr1->cipherName, hdr1->cipherMode)) {
555+
if (crypt_check_cipher(cd, hdr1->keyBytes, hdr1->cipherName, hdr1->cipherMode)) {
589556
log_err(cd, _("Unable to use cipher specification %s-%s for LUKS2."),
590557
hdr1->cipherName, hdr1->cipherMode);
591558
return -EINVAL;

0 commit comments

Comments
 (0)