Skip to content

Commit 3da919f

Browse files
onikombroz
authored andcommitted
tests: test truncated keys with trailing zero byte(s).
It tests hardening for pbkdf2(hmac-sha256) digest verification in LUKS for keys (hmac input message) shorter than the hash internal block size. Any shorter message is padded with zeroes (up to internal block hash size) before the digest is calculated.
1 parent 382e300 commit 3da919f

4 files changed

Lines changed: 308 additions & 2 deletions

File tree

tests/api-test-2.c

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6067,6 +6067,149 @@ static void KeyslotContextAndKeyringLink(void)
60676067
#endif
60686068
}
60696069

6070+
static void TruncatedKeys(void)
6071+
{
6072+
char key[64], key2[64], key3[64], key4[64];
6073+
const char *passphrase = PASSPHRASE;
6074+
6075+
/* test key with trailing zero bytes susceptible to padding conflict in pbkdf2(hmac) */
6076+
const char *vk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a00";
6077+
const char *vk_hex2 = "bb21158c733229347bd4e681891e213d00000000000000000000000000000000";
6078+
6079+
const char *vk_hex3 = "8ca7689d9d422cd87f86b18cbb6aa834a632e8d74a43ccfd86415bb9c65979c3" \
6080+
"2636b79b74458807fffbda615f6fe5d5deeefef5c890879d66fc6b5ce1105d00";
6081+
const char *vk_hex4 = "8ca7689d9d422cd87f86b18cbb6aa834a632e8d74a43ccfd86415bb9c65979c3" \
6082+
"0000000000000000000000000000000000000000000000000000000000000000";
6083+
size_t key_size = strlen(vk_hex) / 2, key_size2 = strlen(vk_hex3) / 2;
6084+
const char *cipher = "aes";
6085+
const char *cbc_mode = "cbc-essiv:sha256", *xts_mode = "xts-plain64";
6086+
uint64_t r_payload_offset;
6087+
6088+
OK_(crypt_decode_key(key, vk_hex, key_size));
6089+
OK_(crypt_decode_key(key2, vk_hex2, key_size));
6090+
OK_(crypt_decode_key(key3, vk_hex3, key_size2));
6091+
OK_(crypt_decode_key(key4, vk_hex4, key_size2));
6092+
6093+
// init test devices
6094+
OK_(get_luks2_offsets(0, 0, 0, NULL, &r_payload_offset));
6095+
OK_(create_dmdevice_over_loop(H_DEVICE, r_payload_offset + 1));
6096+
6097+
// cbc mode
6098+
// format with trailing zero byte key
6099+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6100+
OK_(set_fast_pbkdf(cd));
6101+
OK_(crypt_format(cd, CRYPT_LUKS2, cipher, cbc_mode, NULL, key, key_size, NULL));
6102+
// the truncated key (cut off zero byte) must not pass verification
6103+
FAIL_(crypt_volume_key_verify(cd, key, key_size - 1), "Key does not match the volume.");
6104+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key, key_size - 1, passphrase, strlen(passphrase)), "Key does not match the volume.");
6105+
// add keyslot so LUKS2 can verify key size properly later
6106+
EQ_(crypt_keyslot_add_by_volume_key(cd, 0, key, key_size, passphrase, strlen(passphrase)), 0);
6107+
// no need to test activation since AES will not accept short keys
6108+
CRYPT_FREE(cd);
6109+
6110+
// test again with cached volume key dropped
6111+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6112+
OK_(crypt_load(cd, CRYPT_LUKS2, NULL));
6113+
FAIL_(crypt_volume_key_verify(cd, key, key_size - 1), "Key does not match the volume.");
6114+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key, key_size - 1, passphrase, strlen(passphrase)), "Key does not match the volume.");
6115+
CRYPT_FREE(cd);
6116+
6117+
// format device with zeroed second half of the key
6118+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6119+
OK_(set_fast_pbkdf(cd));
6120+
OK_(crypt_format(cd, CRYPT_LUKS2, cipher, cbc_mode, NULL, key2, key_size, NULL));
6121+
FAIL_(crypt_volume_key_verify(cd, key2, key_size / 2), "Key does not match the volume.");
6122+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key2, key_size / 2, passphrase, strlen(passphrase)), "Key does not match the volume.");
6123+
// activation must fail, we test with 128 bits AES key (the original key was 256 bits)
6124+
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key2, key_size / 2, 0), "Key does not match the volume.");
6125+
EQ_(crypt_keyslot_add_by_volume_key(cd, 0, key2, key_size, passphrase, strlen(passphrase)), 0);
6126+
CRYPT_FREE(cd);
6127+
6128+
// test again with cached volume key dropped
6129+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6130+
OK_(crypt_load(cd, CRYPT_LUKS2, NULL));
6131+
FAIL_(crypt_volume_key_verify(cd, key2, key_size / 2), "Key does not match the volume.");
6132+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key2, key_size / 2, passphrase, strlen(passphrase)), "Key does not match the volume.");
6133+
// activation must fail, we test with 128 bits AES key (the original key was 256 bits)
6134+
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key2, key_size / 2, 0), "Key does not match the volume.");
6135+
CRYPT_FREE(cd);
6136+
6137+
// xts mode
6138+
// format with trailing zero byte key
6139+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6140+
OK_(set_fast_pbkdf(cd));
6141+
OK_(crypt_format(cd, CRYPT_LUKS2, cipher, xts_mode, NULL, key3, key_size2, NULL));
6142+
// the truncated key (cut off zero byte) must not pass verification
6143+
FAIL_(crypt_volume_key_verify(cd, key3, key_size2 - 1), "Key does not match the volume.");
6144+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key3, key_size2 - 1, passphrase, strlen(passphrase)), "Key does not match the volume.");
6145+
// add keyslot so LUKS2 can verify key size properly later
6146+
EQ_(crypt_keyslot_add_by_volume_key(cd, 0, key3, key_size2, passphrase, strlen(passphrase)), 0);
6147+
// no need to test activation since AES will not accept short keys
6148+
CRYPT_FREE(cd);
6149+
6150+
// test again with cached volume key dropped
6151+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6152+
OK_(crypt_load(cd, CRYPT_LUKS2, NULL));
6153+
FAIL_(crypt_volume_key_verify(cd, key3, key_size2 - 1), "Key does not match the volume.");
6154+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key3, key_size2 - 1, passphrase, strlen(passphrase)), "Key does not match the volume.");
6155+
CRYPT_FREE(cd);
6156+
6157+
// format device with zeroed second half of the key
6158+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6159+
OK_(set_fast_pbkdf(cd));
6160+
OK_(crypt_format(cd, CRYPT_LUKS2, cipher, xts_mode, NULL, key4, key_size2, NULL));
6161+
FAIL_(crypt_volume_key_verify(cd, key4, key_size2 / 2), "Key does not match the volume.");
6162+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key4, key_size2 / 2, passphrase, strlen(passphrase)), "Key does not match the volume.");
6163+
// activation must fail, we test with (doubled for xts) 128 bits AES key (the original key was 256 bits)
6164+
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key4, key_size2 / 2, 0), "Key does not match the volume.");
6165+
EQ_(crypt_keyslot_add_by_volume_key(cd, 0, key4, key_size2, passphrase, strlen(passphrase)), 0);
6166+
CRYPT_FREE(cd);
6167+
6168+
// test again with cached volume key dropped
6169+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6170+
OK_(crypt_load(cd, CRYPT_LUKS2, NULL));
6171+
FAIL_(crypt_volume_key_verify(cd, key4, key_size2 / 2), "Key does not match the volume.");
6172+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key4, key_size2 / 2, passphrase, strlen(passphrase)), "Key does not match the volume.");
6173+
// activation must fail, we test with (doubled for xts) 128 bits AES key (the original key was 256 bits)
6174+
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key4, key_size2 / 2, 0), "Key does not match the volume.");
6175+
CRYPT_FREE(cd);
6176+
6177+
// check unbound key verification
6178+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6179+
OK_(set_fast_pbkdf(cd));
6180+
OK_(crypt_format(cd, CRYPT_LUKS2, cipher, xts_mode, NULL, key3, key_size2, NULL));
6181+
// keyslot must always be unbound if created with CRYPT_VOLUME_KEY_NO_SEGMENT
6182+
EQ_(crypt_keyslot_add_by_key(cd, 1, key3, key_size2 - 1, passphrase, strlen(passphrase), CRYPT_VOLUME_KEY_NO_SEGMENT), 1);
6183+
EQ_(crypt_keyslot_status(cd, 1), CRYPT_SLOT_UNBOUND);
6184+
FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, 1, passphrase, strlen(passphrase), 0), "Keyslot unusable for device activation.");
6185+
CRYPT_FREE(cd);
6186+
6187+
// check unbound key verification with CRYPT_VOLUME_KEY_DIGEST_REUSE
6188+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6189+
OK_(set_fast_pbkdf(cd));
6190+
OK_(crypt_format(cd, CRYPT_LUKS2, cipher, xts_mode, NULL, key4, key_size2, NULL));
6191+
// drop cached volume key
6192+
CRYPT_FREE(cd);
6193+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
6194+
OK_(crypt_load(cd, CRYPT_LUKS2, NULL));
6195+
EQ_(crypt_keyslot_add_by_key(cd, 0, key4, key_size2 - 1, passphrase, strlen(passphrase), CRYPT_VOLUME_KEY_NO_SEGMENT), 0);
6196+
EQ_(crypt_keyslot_add_by_key(cd, 1, key4, key_size2 - 2, passphrase, strlen(passphrase), CRYPT_VOLUME_KEY_NO_SEGMENT | CRYPT_VOLUME_KEY_DIGEST_REUSE), 1);
6197+
/* it must not reuse default segment digest */
6198+
EQ_(crypt_keyslot_status(cd, 1), CRYPT_SLOT_UNBOUND);
6199+
FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, 1, passphrase, strlen(passphrase), 0), "Keyslot unusable for device activation.");
6200+
EQ_(crypt_keyslot_add_by_key(cd, 2, key4, key_size2 - 3, passphrase, strlen(passphrase), CRYPT_VOLUME_KEY_NO_SEGMENT | CRYPT_VOLUME_KEY_DIGEST_REUSE), 2);
6201+
EQ_(crypt_keyslot_add_by_key(cd, 3, key4, key_size2 - 4, passphrase, strlen(passphrase), CRYPT_VOLUME_KEY_NO_SEGMENT | CRYPT_VOLUME_KEY_DIGEST_REUSE), 3);
6202+
EQ_(crypt_keyslot_add_by_key(cd, 4, key4, key_size2 - 5, passphrase, strlen(passphrase), CRYPT_VOLUME_KEY_NO_SEGMENT | CRYPT_VOLUME_KEY_DIGEST_REUSE), 4);
6203+
EQ_(crypt_keyslot_add_by_key(cd, 5, key4, key_size2 - 6, passphrase, strlen(passphrase), CRYPT_VOLUME_KEY_NO_SEGMENT | CRYPT_VOLUME_KEY_DIGEST_REUSE), 5);
6204+
EQ_(crypt_keyslot_add_by_key(cd, 6, key4, key_size2 - 7, passphrase, strlen(passphrase), CRYPT_VOLUME_KEY_NO_SEGMENT | CRYPT_VOLUME_KEY_DIGEST_REUSE), 6);
6205+
// It must run out of free digests by now
6206+
FAIL_(crypt_keyslot_add_by_key(cd, 7, key4, key_size2 - 8, passphrase, strlen(passphrase), CRYPT_VOLUME_KEY_NO_SEGMENT | CRYPT_VOLUME_KEY_DIGEST_REUSE), "No free digest slot.");
6207+
CRYPT_FREE(cd);
6208+
6209+
_remove_keyfiles();
6210+
_cleanup_dmdevices();
6211+
}
6212+
60706213
static int _crypt_load_check(struct crypt_device *_cd)
60716214
{
60726215
#if HAVE_BLKID
@@ -6195,6 +6338,7 @@ int main(int argc, char *argv[])
61956338
RUN_(LuksKeyslotAdd, "Adding keyslot via new API");
61966339
RUN_(VolumeKeyGet, "Getting volume key via keyslot context API");
61976340
RUN_(KeyslotContextAndKeyringLink, "Activate via keyslot context API and linking VK to a keyring");
6341+
RUN_(TruncatedKeys, "Test truncated candidate keys.");
61986342
RUN_(Luks2Repair, "LUKS2 repair"); // test disables metadata locking. Run always last!
61996343

62006344
_cleanup();

tests/api-test.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,85 @@ static void VolumeKeyGet(void)
23732373
_cleanup_dmdevices();
23742374
}
23752375

2376+
static void TruncatedKeys(void)
2377+
{
2378+
enum { OFFSET_1M = 2048 };
2379+
struct crypt_params_luks1 params = {
2380+
.hash = "sha256",
2381+
.data_alignment = OFFSET_1M, // 4M, data offset will be 4096
2382+
};
2383+
const struct crypt_pbkdf_type fast_pbkdf = {
2384+
.type = "pbkdf2",
2385+
.hash = "sha256",
2386+
.iterations = 1000,
2387+
.flags = CRYPT_PBKDF_NO_BENCHMARK
2388+
};
2389+
char key[64], key2[64];
2390+
2391+
const char *passphrase = PASSPHRASE;
2392+
2393+
/* test key with trailing zero bytes susceptible to padding conflict in pbkdf2(hmac) */
2394+
const char *vk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a00";
2395+
const char *vk_hex2 = "bb21158c733229347bd4e681891e213d00000000000000000000000000000000";
2396+
size_t key_size = strlen(vk_hex) / 2;
2397+
const char *cipher = "aes";
2398+
const char *cipher_mode = "cbc-essiv:sha256";
2399+
uint64_t r_payload_offset, r_header_size;
2400+
2401+
OK_(crypt_decode_key(key, vk_hex, key_size));
2402+
OK_(crypt_decode_key(key2, vk_hex2, key_size));
2403+
2404+
// init test devices
2405+
OK_(get_luks_offsets(0, key_size, params.data_alignment, 0, &r_header_size, &r_payload_offset));
2406+
OK_(create_dmdevice_over_loop(H_DEVICE, r_payload_offset + 1));
2407+
2408+
// format with key containing last trailing zero byte
2409+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
2410+
OK_(crypt_set_pbkdf_type(cd, &fast_pbkdf));
2411+
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, &params));
2412+
// the truncated key (cut off zero byte) must not pass verification
2413+
FAIL_(crypt_volume_key_verify(cd, key, key_size - 1), "Key does not match the volume.");
2414+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key, key_size - 1, passphrase, strlen(passphrase)), "Key does not match the volume.");
2415+
CRYPT_FREE(cd);
2416+
2417+
// same test as above, but with cached volume key dropped
2418+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
2419+
OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
2420+
// the truncated key (cut off zero byte) must not pass verification
2421+
FAIL_(crypt_volume_key_verify(cd, key, key_size - 1), "Key does not match the volume.");
2422+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key, key_size - 1, passphrase, strlen(passphrase)), "Key does not match the volume.");
2423+
// no need to test activation since AES will not accept short keys
2424+
CRYPT_FREE(cd);
2425+
2426+
/*
2427+
* Format with key in second half containing only zero bytes.
2428+
* Due to hmac zero padding of messages shorter than internal hash block size,
2429+
* we could use only first half of the key, pass the verification and upload
2430+
* the key in dm-crypt successfully. We pass 128 bits instead of 256 bits used
2431+
* in crypt_format().
2432+
*/
2433+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
2434+
OK_(crypt_set_pbkdf_type(cd, &fast_pbkdf));
2435+
OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key2, key_size, &params));
2436+
// the truncated key (cut off zero byte) must not pass verification
2437+
FAIL_(crypt_volume_key_verify(cd, key2, key_size / 2), "Key does not match the volume.");
2438+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key2, key_size / 2, passphrase, strlen(passphrase)), "Key does not match the volume.");
2439+
// activation must fail
2440+
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key2, key_size / 2, 0), "Key does not match the volume.");
2441+
CRYPT_FREE(cd);
2442+
2443+
// same test as above, but with cached volume key dropped
2444+
OK_(crypt_init(&cd, DMDIR H_DEVICE));
2445+
OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
2446+
FAIL_(crypt_volume_key_verify(cd, key2, key_size / 2), "Key does not match the volume.");
2447+
FAIL_(crypt_keyslot_add_by_volume_key(cd, CRYPT_ANY_SLOT, key2, key_size / 2, passphrase, strlen(passphrase)), "Key does not match the volume.");
2448+
FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key2, key_size / 2, 0), "Key does not match the volume.");
2449+
CRYPT_FREE(cd);
2450+
2451+
_remove_keyfiles();
2452+
_cleanup_dmdevices();
2453+
}
2454+
23762455
// Check that gcrypt is properly initialised in format
23772456
static void NonFIPSAlg(void)
23782457
{
@@ -2469,6 +2548,7 @@ int main(int argc, char *argv[])
24692548
RUN_(WipeTest, "Wipe device");
24702549
RUN_(LuksKeyslotAdd, "Adding keyslot via new API");
24712550
RUN_(VolumeKeyGet, "Getting volume key via keyslot context API");
2551+
RUN_(TruncatedKeys, "Test truncated candidate keys.");
24722552

24732553
_cleanup();
24742554
return 0;

tests/compat-test

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ KEY1=key1
2424
KEY2=key2
2525
KEY5=key5
2626
KEYE=keye
27+
KEY_TZERO=key_trailing_zero
28+
KEY_HALF_ZERO=key_half_zeroes
2729
PWD0="compatkey"
2830
PWD1="93R4P4pIqAH8"
2931
PWD2="mymJeD8ivEhE"
@@ -57,7 +59,7 @@ remove_mapping()
5759
[ -b /dev/mapper/$DEV_NAME2 ] && dmsetup remove --retry $DEV_NAME2 >/dev/null 2>&1
5860
[ -b /dev/mapper/$DEV_NAME ] && dmsetup remove --retry $DEV_NAME >/dev/null 2>&1
5961
losetup -d $LOOPDEV >/dev/null 2>&1
60-
rm -f $ORIG_IMG $IMG $IMG10 $KEY1 $KEY2 $KEY5 $KEYE $HEADER_IMG $VK_FILE missing-file >/dev/null 2>&1
62+
rm -f $ORIG_IMG $IMG $IMG10 $KEY1 $KEY2 $KEY5 $KEYE $KEY_TZERO $KEY_HALF_ZERO $HEADER_IMG $VK_FILE missing-file >/dev/null 2>&1
6163
rmmod scsi_debug >/dev/null 2>&1
6264
scsi_debug_teardown $DEV
6365
}
@@ -137,6 +139,18 @@ prepare()
137139
echo -n $'\x9c\x03\x5e\x1b\x4d\x0f\x9a\x75\xb3\x90\x70\x32\x0a\xf8\xae\xc4'>>$KEY1
138140
fi
139141

142+
if [ ! -e $KEY_TZERO ]; then
143+
echo -ne '\xa6\x32\x09\x5f\xdb\xbe\xf3\xc6\xa7\x4c\xe5\x85\x73\xac\xa8\xfb' >$KEY_TZERO
144+
echo -ne '\x09\xd4\x38\xfd\x58\x24\x17\x1b\x98\xa3\xef\x1e\xe4\x4b\xbc\x00'>>$KEY_TZERO
145+
fi
146+
147+
if [ ! -e $KEY_HALF_ZERO ]; then
148+
echo -ne '\xa6\x32\x09\x5f\xdb\xbe\xf3\xc6\xa7\x4c\xe5\x85\x73\xac\xa8\xfb' >$KEY_HALF_ZERO
149+
echo -ne '\x09\xd4\x38\xfd\x58\x24\x17\x1b\x98\xa3\xef\x1e\xe4\x4b\xbc\xc9'>>$KEY_HALF_ZERO
150+
echo -ne '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'>>$KEY_HALF_ZERO
151+
echo -ne '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'>>$KEY_HALF_ZERO
152+
fi
153+
140154
if [ ! -e $KEY2 ]; then
141155
dd if=/dev/urandom of=$KEY2 count=1 bs=16 >/dev/null 2>&1
142156
fi
@@ -1158,5 +1172,29 @@ echo $PWD1 | $CRYPTSETUP luksFormat --type luks1 $FAST_PBKDF_OPT $LOOPDEV || fai
11581172
echo $PWD1 | $CRYPTSETUP luksOpen $LOOPDEV $DM_BAD_NAME 2>/dev/null && fail
11591173
echo $PWD1 | $CRYPTSETUP luksOpen $LOOPDEV $DM_LONG_NAME 2>/dev/null && fail
11601174

1175+
prepare "[41] Truncated keys." wipe
1176+
echo "$PWD1" | $CRYPTSETUP luksFormat -q --type luks1 $FAST_PBKDF_OPT --volume-key-file $KEY_TZERO -s256 $IMG || fail
1177+
$CRYPTSETUP open -q --test-passphrase $IMG --volume-key-file $KEY_TZERO -s248 2>/dev/null && fail
1178+
# cut the trailing zero byte
1179+
truncate -c -s 31 $KEY_TZERO || fail
1180+
echo $PWD3 | $CRYPTSETUP luksAddKey -q $FAST_PBKDF_OPT -S5 --volume-key-file $KEY_TZERO $IMG 2>/dev/null && fail
1181+
$CRYPTSETUP luksErase -q $IMG || fail
1182+
echo $PWD3 | $CRYPTSETUP luksAddKey -q $FAST_PBKDF_OPT -S5 --volume-key-file $KEY_TZERO $IMG 2>/dev/null && fail
1183+
1184+
echo "$PWD1" | $CRYPTSETUP luksFormat -q --type luks1 $FAST_PBKDF_OPT --volume-key-file $KEY_HALF_ZERO -s512 $IMG || fail
1185+
$CRYPTSETUP open -q --test-passphrase $IMG --volume-key-file $KEY_HALF_ZERO -s496 2>/dev/null && fail
1186+
$CRYPTSETUP open -q --test-passphrase $IMG --volume-key-file $KEY_HALF_ZERO -s256 2>/dev/null && fail
1187+
# cut the trailing zero byte
1188+
truncate -c -s 63 $KEY_HALF_ZERO || fail
1189+
echo $PWD3 | $CRYPTSETUP luksAddKey -q $FAST_PBKDF_OPT -S5 --volume-key-file $KEY_HALF_ZERO $IMG 2>/dev/null && fail
1190+
# cut all remaining zero bytes down to 256bits key
1191+
truncate -c -s 32 $KEY_HALF_ZERO || fail
1192+
echo $PWD3 | $CRYPTSETUP luksAddKey -q $FAST_PBKDF_OPT -S5 --volume-key-file $KEY_HALF_ZERO $IMG 2>/dev/null && fail
1193+
$CRYPTSETUP luksErase -q $IMG || fail
1194+
truncate -c -s 63 $KEY_HALF_ZERO || fail
1195+
echo $PWD3 | $CRYPTSETUP luksAddKey -q $FAST_PBKDF_OPT -S5 --volume-key-file $KEY_HALF_ZERO $IMG 2>/dev/null && fail
1196+
truncate -c -s 32 $KEY_HALF_ZERO || fail
1197+
echo $PWD3 | $CRYPTSETUP luksAddKey -q $FAST_PBKDF_OPT -S5 --volume-key-file $KEY_HALF_ZERO $IMG 2>/dev/null && fail
1198+
11611199
remove_mapping
11621200
exit 0

0 commit comments

Comments
 (0)