2 * cryptsetup library API check functions
4 * Copyright (C) 2009-2010 Red Hat, Inc. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <sys/ioctl.h>
30 #include <libdevmapper.h>
33 #include "libcryptsetup.h"
34 #include "utils_loop.h"
36 #define DMDIR "/dev/mapper/"
38 #define DEVICE_1_UUID "28632274-8c8a-493f-835b-da802e1c576b"
39 #define DEVICE_EMPTY_name "crypt_zero"
40 #define DEVICE_EMPTY DMDIR DEVICE_EMPTY_name
41 #define DEVICE_ERROR_name "crypt_error"
42 #define DEVICE_ERROR DMDIR DEVICE_ERROR_name
44 #define CDEVICE_1 "ctest1"
45 #define CDEVICE_2 "ctest2"
46 #define CDEVICE_WRONG "O_o"
47 #define H_DEVICE "head_ok"
48 #define H_DEVICE_WRONG "head_wr"
49 #define L_DEVICE_1S "luks_onesec"
50 #define L_DEVICE_0S "luks_zerosec"
51 #define L_DEVICE_WRONG "luks_wr"
52 #define L_DEVICE_OK "luks_ok"
53 #define EVL_HEADER_1 "evil_hdr-luks_hdr_damage"
54 #define EVL_HEADER_2 "evil_hdr-payload_overwrite"
55 #define EVL_HEADER_3 "evil_hdr-stripes_payload_dmg"
56 #define EVL_HEADER_4 "evil_hdr-small_luks_device"
57 #define VALID_HEADER "valid_header_file"
58 #define BACKUP_FILE "csetup_backup_file"
59 #define IMAGE1 "compatimage.img"
60 #define IMAGE_EMPTY "empty.img"
62 #define KEYFILE1 "key1.file"
63 #define KEY1 "compatkey"
65 #define KEYFILE2 "key2.file"
66 #define KEY2 "0123456789abcdef"
68 #define PASSPHRASE "blabla"
70 #define DEVICE_TEST_UUID "12345678-1234-1234-1234-123456789abc"
72 #define DEVICE_WRONG "/dev/Ooo_"
73 #define DEVICE_CHAR "/dev/zero"
74 #define THE_LFILE_TEMPLATE "cryptsetup-tstlp.XXXXXX"
76 #define SECTOR_SHIFT 9L
77 #define SECTOR_SIZE 512
78 #define TST_LOOP_FILE_SIZE (((1<<20)*50)>>SECTOR_SHIFT)
79 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
80 #define DIV_ROUND_UP_MODULO(n,d) (DIV_ROUND_UP(n,d)*(d))
81 #define LUKS_PHDR_SIZE_B 1024
83 static int _debug = 0;
84 static int _verbose = 1;
86 static char global_log[4096];
87 static int global_lines = 0;
89 static char *DEVICE_1 = NULL;
90 static char *DEVICE_2 = NULL;
91 static char *THE_LOOP_DEV = NULL;
93 static char *tmp_file_1 = NULL;
94 static char *test_loop_file = NULL;
95 static uint64_t t_dev_offset = 0;
97 static int _system(const char*, int);
101 static int device_size(const char *device, uint64_t *size)
105 devfd = open(device, O_RDONLY);
109 if (ioctl(devfd, BLKGETSIZE64, size) < 0)
115 static int get_luks_offsets(int metadata_device,
117 unsigned int alignpayload_sec,
118 unsigned int alignoffset_sec,
119 uint64_t *r_header_size,
120 uint64_t *r_payload_offset)
123 uint64_t current_sector;
127 uint32_t sectors_per_stripes_set = DIV_ROUND_UP(keylength*LUKS_STRIPES, SECTOR_SIZE);
128 printf("sectors_per_stripes %" PRIu32 "\n", sectors_per_stripes_set);
129 current_sector = DIV_ROUND_UP_MODULO(DIV_ROUND_UP(LUKS_PHDR_SIZE_B, SECTOR_SIZE),
130 LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
131 for(i=0;i < (LUKS_NUMKEYS - 1);i++)
132 current_sector = DIV_ROUND_UP_MODULO(current_sector + sectors_per_stripes_set,
133 LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
135 *r_header_size = current_sector + sectors_per_stripes_set;
137 current_sector = DIV_ROUND_UP_MODULO(current_sector + sectors_per_stripes_set,
138 LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
140 if (r_payload_offset) {
142 *r_payload_offset = alignpayload_sec;
144 *r_payload_offset = DIV_ROUND_UP_MODULO(current_sector, alignpayload_sec)
152 * Creates dm-linear target over the test loop device. Offset is held in
153 * global variables so that size can be tested whether it fits into remaining
154 * size of the loop device or not
156 static int create_dmdevice_over_loop(const char *dm_name, const uint64_t size)
162 if(device_size(THE_LOOP_DEV, &r_size) < 0 || r_size <= t_dev_offset || !size)
164 if ((r_size - t_dev_offset) < size) {
165 printf("No enough space on backing loop device\n.");
168 snprintf(cmd, sizeof(cmd),
169 "dmsetup create %s --table \"0 %" PRIu64 " linear %s %" PRIu64 "\"",
170 dm_name, size, THE_LOOP_DEV, t_dev_offset);
171 if (!(r = _system(cmd, 1))) {
172 t_dev_offset += size;
177 // TODO some utility to remove dmdevice over the loop file
179 // Get key from kernel dm mapping table using dm-ioctl
180 static int _get_key_dm(const char *name, char *buffer, unsigned int buffer_size)
184 uint64_t start, length;
185 char *target_type, *rcipher, *key, *params;
189 if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
191 if (!dm_task_set_name(dmt, name))
193 if (!dm_task_run(dmt))
195 if (!dm_task_get_info(dmt, &dmi))
200 next = dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms);
201 if (!target_type || strcmp(target_type, "crypt") != 0)
204 rcipher = strsep(¶ms, " ");
205 key = strsep(¶ms, " ");
207 if (buffer_size <= strlen(key))
210 strncpy(buffer, key, buffer_size);
214 dm_task_destroy(dmt);
219 static int _prepare_keyfile(const char *name, const char *passphrase, int size)
223 fd = open(name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR);
225 r = write(fd, passphrase, size);
230 return r == size ? 0 : 1;
233 static void _remove_keyfiles(void)
239 // Decode key from its hex representation
240 static int crypt_decode_key(char *key, char *hex, unsigned int size)
248 for (i = 0; i < size; i++) {
252 key[i] = (unsigned char)strtoul(buffer, &endp, 16);
254 if (endp != &buffer[2])
264 static void cmdLineLog(int level, char *msg)
266 strncat(global_log, msg, sizeof(global_log) - strlen(global_log));
270 static void new_log(int level, const char *msg, void *usrptr)
272 cmdLineLog(level, (char*)msg);
275 static void reset_log()
277 memset(global_log, 0, sizeof(global_log));
281 static int _system(const char *command, int warn)
284 if ((r=system(command)) < 0 && warn)
285 printf("System command failed: %s", command);
289 static void _cleanup_dmdevices(void)
293 if (!stat(DMDIR H_DEVICE, &st)) {
294 _system("dmsetup remove " H_DEVICE, 0);
296 if (!stat(DMDIR H_DEVICE_WRONG, &st)) {
297 _system("dmsetup remove " H_DEVICE_WRONG, 0);
299 if (!stat(DMDIR L_DEVICE_0S, &st)) {
300 _system("dmsetup remove " L_DEVICE_0S, 0);
302 if (!stat(DMDIR L_DEVICE_1S, &st)) {
303 _system("dmsetup remove " L_DEVICE_1S, 0);
305 if (!stat(DMDIR L_DEVICE_WRONG, &st)) {
306 _system("dmsetup remove " L_DEVICE_WRONG, 0);
308 if (!stat(DMDIR L_DEVICE_OK, &st)) {
309 _system("dmsetup remove " L_DEVICE_OK, 0);
315 static void _cleanup(void)
319 //_system("udevadm settle", 0);
321 if (!stat(DMDIR CDEVICE_1, &st))
322 _system("dmsetup remove " CDEVICE_1, 0);
324 if (!stat(DMDIR CDEVICE_2, &st))
325 _system("dmsetup remove " CDEVICE_2, 0);
327 if (!stat(DEVICE_EMPTY, &st))
328 _system("dmsetup remove " DEVICE_EMPTY_name, 0);
330 if (!stat(DEVICE_ERROR, &st))
331 _system("dmsetup remove " DEVICE_ERROR_name, 0);
333 _cleanup_dmdevices();
335 if (crypt_loop_device(THE_LOOP_DEV))
336 crypt_loop_detach(THE_LOOP_DEV);
338 if (crypt_loop_device(DEVICE_1))
339 crypt_loop_detach(DEVICE_1);
341 if (crypt_loop_device(DEVICE_2))
342 crypt_loop_detach(DEVICE_2);
344 _system("rm -f " IMAGE_EMPTY, 0);
345 _system("rm -f " IMAGE1, 0);
347 remove(test_loop_file);
350 remove(EVL_HEADER_1);
351 remove(EVL_HEADER_2);
352 remove(EVL_HEADER_3);
353 remove(EVL_HEADER_4);
354 remove(VALID_HEADER);
360 static int _setup(void)
365 test_loop_file = strdup(THE_LFILE_TEMPLATE);
366 if ((fd=mkstemp(test_loop_file)) == -1) {
367 printf("cannot create temporary file with template %s\n", test_loop_file);
371 snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d",
372 test_loop_file, SECTOR_SIZE, TST_LOOP_FILE_SIZE);
377 THE_LOOP_DEV = crypt_loop_get_device();
379 printf("Cannot find free loop device.\n");
382 if (crypt_loop_device(THE_LOOP_DEV)) {
383 fd = crypt_loop_attach(THE_LOOP_DEV, test_loop_file, 0, 0, &ro);
387 tmp_file_1 = strdup(THE_LFILE_TEMPLATE);
388 if ((fd=mkstemp(tmp_file_1)) == -1) {
389 printf("cannot create temporary file with template %s\n", tmp_file_1);
393 snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=%s bs=%d count=%d",
394 tmp_file_1, SECTOR_SIZE, 10);
398 _system("dmsetup create " DEVICE_EMPTY_name " --table \"0 10000 zero\"", 1);
399 _system("dmsetup create " DEVICE_ERROR_name " --table \"0 10000 error\"", 1);
401 DEVICE_1 = crypt_loop_get_device();
403 printf("Cannot find free loop device.\n");
406 if (crypt_loop_device(DEVICE_1)) {
407 _system(" [ ! -e " IMAGE1 " ] && bzip2 -dk " IMAGE1 ".bz2", 1);
408 fd = crypt_loop_attach(DEVICE_1, IMAGE1, 0, 0, &ro);
412 DEVICE_2 = crypt_loop_get_device();
414 printf("Cannot find free loop device.\n");
417 if (crypt_loop_device(DEVICE_2)) {
418 _system("dd if=/dev/zero of=" IMAGE_EMPTY " bs=1M count=4", 1);
419 fd = crypt_loop_attach(DEVICE_2, IMAGE_EMPTY, 0, 0, &ro);
422 /* Keymaterial offset is less than 8 sectors */
423 _system(" [ ! -e " EVL_HEADER_1 " ] && bzip2 -dk " EVL_HEADER_1 ".bz2", 1);
424 /* keymaterial offset aims into payload area */
425 _system(" [ ! -e " EVL_HEADER_2 " ] && bzip2 -dk " EVL_HEADER_2 ".bz2", 1);
426 /* keymaterial offset is valid, number of stripes causes payload area to be overwriten */
427 _system(" [ ! -e " EVL_HEADER_3 " ] && bzip2 -dk " EVL_HEADER_3 ".bz2", 1);
428 /* luks device header for data and header on same device. payloadOffset is greater than
429 * device size (crypt_load() test) */
430 _system(" [ ! -e " EVL_HEADER_4 " ] && bzip2 -dk " EVL_HEADER_4 ".bz2", 1);
431 /* valid header: payloadOffset=4096, key_size=32,
432 * volume_key = bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a */
433 _system(" [ ! -e " VALID_HEADER " ] && bzip2 -dk " VALID_HEADER ".bz2", 1);
438 void check_ok(int status, int line, const char *func)
443 crypt_get_error(buf, sizeof(buf));
444 printf("FAIL line %d [%s]: code %d, %s\n", line, func, status, buf);
450 void check_ko(int status, int line, const char *func)
454 memset(buf, 0, sizeof(buf));
455 crypt_get_error(buf, sizeof(buf));
457 printf("FAIL line %d [%s]: code %d, %s\n", line, func, status, buf);
461 printf(" => errno %d, errmsg: %s\n", status, buf);
464 void check_equal(int line, const char *func)
466 printf("FAIL line %d [%s]: expected equal values differs.\n", line, func);
471 void xlog(const char *msg, const char *tst, const char *func, int line, const char *txt)
475 printf(" [%s,%s:%d] %s [%s]\n", msg, func, line, tst, txt);
477 printf(" [%s,%s:%d] %s\n", msg, func, line, tst);
480 #define OK_(x) do { xlog("(success)", #x, __FUNCTION__, __LINE__, NULL); \
481 check_ok((x), __LINE__, __FUNCTION__); \
483 #define FAIL_(x, y) do { xlog("(fail) ", #x, __FUNCTION__, __LINE__, y); \
484 check_ko((x), __LINE__, __FUNCTION__); \
486 #define EQ_(x, y) do { xlog("(equal) ", #x " == " #y, __FUNCTION__, __LINE__, NULL); \
487 if ((x) != (y)) check_equal(__LINE__, __FUNCTION__); \
490 #define RUN_(x, y) do { printf("%s: %s\n", #x, (y)); x(); } while (0)
494 static void AddDevicePlain(void)
496 struct crypt_device *cd, *cd2;
497 struct crypt_params_plain params = {
504 char key[128], key2[128], path[128];
506 char *passphrase = PASSPHRASE;
507 // hashed hex version of PASSPHRASE
508 char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
509 size_t key_size = strlen(mk_hex) / 2;
510 char *cipher = "aes";
511 char *cipher_mode = "cbc-essiv:sha256";
513 uint64_t size, r_size;
515 crypt_decode_key(key, mk_hex, key_size);
516 FAIL_(crypt_init(&cd, ""), "empty device string");
517 FAIL_(crypt_init(&cd, DEVICE_WRONG), "nonexistent device name ");
518 FAIL_(crypt_init(&cd, DEVICE_CHAR), "character device as backing device");
519 OK_(crypt_init(&cd, tmp_file_1));
522 // test crypt_format, crypt_get_cipher, crypt_get_cipher_mode, crypt_get_volume_key_size
523 OK_(crypt_init(&cd,DEVICE_1));
526 FAIL_(crypt_format(cd,CRYPT_PLAIN,NULL,cipher_mode,NULL,NULL,key_size,¶ms),"cipher param is null");
527 FAIL_(crypt_format(cd,CRYPT_PLAIN,cipher,NULL,NULL,NULL,key_size,¶ms),"cipher_mode param is null");
528 OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,¶ms));
529 OK_(strcmp(cipher_mode,crypt_get_cipher_mode(cd)));
530 OK_(strcmp(cipher,crypt_get_cipher(cd)));
531 EQ_(key_size, crypt_get_volume_key_size(cd));
532 EQ_(params.skip, crypt_get_iv_offset(cd));
533 EQ_(params.offset, crypt_get_data_offset(cd));
538 FAIL_(crypt_set_uuid(cd,DEVICE_1_UUID),"can't set uuid to plain device");
542 // default is "plain" hash - no password hash
543 OK_(crypt_init(&cd, DEVICE_1));
544 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, NULL));
545 FAIL_(crypt_activate_by_volume_key(cd, NULL, key, key_size, 0), "cannot verify key with plain");
546 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
547 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
548 OK_(crypt_deactivate(cd, CDEVICE_1));
551 // test boundaries in offset parameter
552 device_size(DEVICE_1,&size);
554 // zero sectors length
555 params.offset = size >> SECTOR_SHIFT;
556 OK_(crypt_init(&cd, DEVICE_1));
557 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
558 EQ_(crypt_get_data_offset(cd),params.offset);
559 // device size is 0 sectors
560 FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0), "invalid device size (0 blocks)");
561 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
562 // data part of crypt device is of 1 sector size
563 params.offset = (size >> SECTOR_SHIFT) - 1;
566 OK_(crypt_init(&cd, DEVICE_1));
567 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
568 OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
569 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
570 snprintf(path, sizeof(path), "%s/%s", crypt_get_dir(), CDEVICE_1);
571 if (device_size(path, &r_size) >= 0)
572 EQ_(r_size>>SECTOR_SHIFT, 1);
573 OK_(crypt_deactivate(cd, CDEVICE_1));
576 // size > device_size
578 params.size = (size >> SECTOR_SHIFT) + 1;
579 crypt_init(&cd, DEVICE_1);
580 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
581 FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0),"Device too small");
582 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
585 // offset == device_size (autodetect size)
586 params.offset = (size >> SECTOR_SHIFT);
588 crypt_init(&cd, DEVICE_1);
589 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
590 FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0),"Device too small");
591 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
594 // offset == device_size (user defined size)
595 params.offset = (size >> SECTOR_SHIFT);
597 crypt_init(&cd, DEVICE_1);
598 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
599 FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0),"Device too small");
600 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
603 // offset+size > device_size
605 params.size = (size >> SECTOR_SHIFT) - params.offset + 1;
606 crypt_init(&cd, DEVICE_1);
607 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
608 FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0),"Offset and size are beyond device real size");
609 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
612 // offset+size == device_size
614 params.size = (size >> SECTOR_SHIFT) - params.offset;
615 crypt_init(&cd, DEVICE_1);
616 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
617 OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
618 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
619 if (!device_size(path, &r_size))
620 EQ_((r_size >> SECTOR_SHIFT),params.size);
621 OK_(crypt_deactivate(cd,CDEVICE_1));
624 params.hash = "sha1";
629 // Now use hashed password
630 OK_(crypt_init(&cd, DEVICE_1));
631 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
632 FAIL_(crypt_activate_by_passphrase(cd, NULL, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0),
633 "cannot verify passphrase with plain" );
634 OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
636 // device status check
637 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
638 snprintf(path, sizeof(path), "%s/%s", crypt_get_dir(), CDEVICE_1);
639 fd = open(path, O_RDONLY);
640 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_BUSY);
641 FAIL_(crypt_deactivate(cd, CDEVICE_1), "Device is busy");
643 OK_(crypt_deactivate(cd, CDEVICE_1));
644 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
647 // crypt_init_by_name_and_header
648 OK_(crypt_init(&cd,DEVICE_1));
649 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
650 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
651 FAIL_(crypt_init_by_name_and_header(&cd2, CDEVICE_1, H_DEVICE),"can't init plain device by header device");
652 OK_(crypt_init_by_name(&cd2,CDEVICE_1));
653 OK_(crypt_deactivate(cd,CDEVICE_1));
657 OK_(crypt_init(&cd,DEVICE_1));
658 OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,¶ms));
662 // crypt_set_data_device
663 FAIL_(crypt_set_data_device(cd,H_DEVICE),"can't set data device for plain device");
666 OK_(strcmp(crypt_get_type(cd),CRYPT_PLAIN));
668 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
669 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
672 OK_(crypt_resize(cd,CDEVICE_1,size>>SECTOR_SHIFT)); // same size
673 if (!device_size(path,&r_size))
677 FAIL_(crypt_resize(cd, CDEVICE_1, ULLONG_MAX),"Backing device is too small");
678 FAIL_(crypt_resize(cd, CDEVICE_1, (size>>SECTOR_SHIFT)+1),"crypt device overlaps backing device");
681 OK_(crypt_resize(cd,CDEVICE_1, 123));
682 if (!device_size(path,&r_size))
683 EQ_(r_size>>SECTOR_SHIFT, 123);
684 OK_(crypt_resize(cd,CDEVICE_1,0)); // full size (autodetect)
685 if (!device_size(path,&r_size))
687 OK_(crypt_deactivate(cd,CDEVICE_1));
688 EQ_(crypt_status(cd,CDEVICE_1),CRYPT_INACTIVE);
692 OK_(crypt_init(&cd,DEVICE_1));
694 params.size = (size>>SECTOR_SHIFT) - params.offset - 10;
695 OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,¶ms));
696 OK_(crypt_activate_by_volume_key(cd,CDEVICE_1,key,key_size,0));
697 if (!device_size(path,&r_size))
698 EQ_(r_size>>SECTOR_SHIFT, params.size);
699 // resize to fill remaining capacity
700 OK_(crypt_resize(cd,CDEVICE_1,params.size + 10));
701 if (!device_size(path,&r_size))
702 EQ_(r_size>>SECTOR_SHIFT, params.size + 10);
704 // 1 sector beyond real size
705 FAIL_(crypt_resize(cd,CDEVICE_1,params.size + 11), "new device size overlaps backing device"); // with respect to offset
706 if (!device_size(path,&r_size))
707 EQ_(r_size>>SECTOR_SHIFT, params.size + 10);
708 EQ_(crypt_status(cd,CDEVICE_1),CRYPT_ACTIVE);
709 fd = open(path, O_RDONLY);
713 // resize to minimal size
714 OK_(crypt_resize(cd,CDEVICE_1, 1)); // minimal device size
715 if (!device_size(path,&r_size))
716 EQ_(r_size>>SECTOR_SHIFT, 1);
717 // use size of backing device (autodetect with respect to offset)
718 OK_(crypt_resize(cd,CDEVICE_1,0));
719 if (!device_size(path,&r_size))
720 EQ_(r_size>>SECTOR_SHIFT, (size >> SECTOR_SHIFT)- 42);
721 OK_(crypt_deactivate(cd,CDEVICE_1));
726 OK_(crypt_init(&cd,DEVICE_1));
727 OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,¶ms));
728 OK_(crypt_activate_by_volume_key(cd,CDEVICE_1,key,key_size,0));
730 // suspend/resume tests
731 FAIL_(crypt_suspend(cd,CDEVICE_1),"cannot suspend plain device");
732 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
733 FAIL_(crypt_resume_by_passphrase(cd,CDEVICE_1,CRYPT_ANY_SLOT,passphrase, strlen(passphrase)),"cannot resume plain device");
734 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
736 // retrieve volume key check
737 memset(key2, 0, key_size);
740 FAIL_(crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key2, &key_size, passphrase, strlen(passphrase)), "small buffer");
742 OK_(crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key2, &key_size, passphrase, strlen(passphrase)));
744 OK_(memcmp(key, key2, key_size));
745 OK_(strcmp(cipher, crypt_get_cipher(cd)));
746 OK_(strcmp(cipher_mode, crypt_get_cipher_mode(cd)));
747 EQ_(key_size, crypt_get_volume_key_size(cd));
748 EQ_(0, crypt_get_data_offset(cd));
749 OK_(crypt_deactivate(cd, CDEVICE_1));
752 OK_(_prepare_keyfile(KEYFILE1, KEY1, strlen(KEY1)));
753 OK_(_prepare_keyfile(KEYFILE2, KEY2, strlen(KEY2)));
754 FAIL_(crypt_activate_by_keyfile(cd, NULL, CRYPT_ANY_SLOT, KEYFILE1, 0, 0), "cannot verify key with plain");
755 EQ_(0, crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0, 0));
756 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
757 OK_(crypt_deactivate(cd, CDEVICE_1));
761 OK_(crypt_init(&cd,DEVICE_1));
762 OK_(crypt_format(cd,CRYPT_PLAIN,cipher,cipher_mode,NULL,NULL,key_size,¶ms));
765 FAIL_(crypt_keyslot_add_by_passphrase(cd,CRYPT_ANY_SLOT,passphrase,strlen(passphrase),passphrase,strlen(passphrase)), "can't add keyslot to plain device");
766 FAIL_(crypt_keyslot_add_by_volume_key(cd,CRYPT_ANY_SLOT ,key,key_size,passphrase,strlen(passphrase)),"can't add keyslot to plain device");
767 FAIL_(crypt_keyslot_add_by_keyfile(cd,CRYPT_ANY_SLOT,KEYFILE1,strlen(KEY1),KEYFILE2,strlen(KEY2)),"can't add keyslot to plain device");
768 FAIL_(crypt_keyslot_destroy(cd,1),"can't manipulate keyslots on plain device");
769 EQ_(crypt_keyslot_status(cd, 0), CRYPT_SLOT_INVALID);
775 #define CALLBACK_ERROR "calback_error xyz"
776 static int pass_callback_err(const char *msg, char *buf, size_t length, void *usrptr)
778 struct crypt_device *cd = usrptr;
784 crypt_log(cd, CRYPT_LOG_ERROR, CALLBACK_ERROR);
788 static int pass_callback_ok(const char *msg, char *buf, size_t length, void *usrptr)
792 strcpy(buf, PASSPHRASE);
796 static void CallbacksTest(void)
798 struct crypt_device *cd;
799 struct crypt_params_plain params = {
805 size_t key_size = 256 / 8;
806 char *cipher = "aes";
807 char *cipher_mode = "cbc-essiv:sha256";
808 char *passphrase = PASSPHRASE;
810 OK_(crypt_init(&cd, DEVICE_1));
811 crypt_set_log_callback(cd, &new_log, NULL);
812 //crypt_set_log_callback(cd, NULL, NULL);
814 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, ¶ms));
816 OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
817 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
818 OK_(crypt_deactivate(cd, CDEVICE_1));
821 crypt_set_password_callback(cd, pass_callback_err, cd);
822 FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, NULL, 0, 0), "callback fails");
823 EQ_(strncmp(global_log, CALLBACK_ERROR, strlen(CALLBACK_ERROR)), 0);
825 crypt_set_password_callback(cd, pass_callback_ok, NULL);
826 OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, NULL, 0, 0));
827 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
828 OK_(crypt_deactivate(cd, CDEVICE_1));
833 static void UseLuksDevice(void)
835 struct crypt_device *cd;
839 OK_(crypt_init(&cd, DEVICE_1));
840 OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
841 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
842 OK_(crypt_activate_by_passphrase(cd, NULL, CRYPT_ANY_SLOT, KEY1, strlen(KEY1), 0));
843 OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1), 0));
844 FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1), 0), "already open");
845 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
846 OK_(crypt_deactivate(cd, CDEVICE_1));
847 FAIL_(crypt_deactivate(cd, CDEVICE_1), "no such device");
850 OK_(strcmp("aes", crypt_get_cipher(cd)));
851 OK_(strcmp("cbc-essiv:sha256", crypt_get_cipher_mode(cd)));
852 OK_(strcmp(DEVICE_1_UUID, crypt_get_uuid(cd)));
853 EQ_(key_size, crypt_get_volume_key_size(cd));
854 EQ_(1032, crypt_get_data_offset(cd));
856 EQ_(0, crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key, &key_size, KEY1, strlen(KEY1)));
857 OK_(crypt_volume_key_verify(cd, key, key_size));
858 OK_(crypt_activate_by_volume_key(cd, NULL, key, key_size, 0));
859 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
860 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
861 OK_(crypt_deactivate(cd, CDEVICE_1));
864 FAIL_(crypt_volume_key_verify(cd, key, key_size), "key mismatch");
865 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "key mismatch");
869 static void SuspendDevice(void)
872 struct crypt_device *cd;
874 OK_(crypt_init(&cd, DEVICE_1));
875 OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
876 OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1), 0));
878 suspend_status = crypt_suspend(cd, CDEVICE_1);
879 if (suspend_status == -ENOTSUP) {
880 printf("WARNING: Suspend/Resume not supported, skipping test.\n");
884 FAIL_(crypt_suspend(cd, CDEVICE_1), "already suspended");
886 FAIL_(crypt_resume_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1)-1), "wrong key");
887 OK_(crypt_resume_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1)));
888 FAIL_(crypt_resume_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1)), "not suspended");
890 OK_(_prepare_keyfile(KEYFILE1, KEY1, strlen(KEY1)));
891 OK_(crypt_suspend(cd, CDEVICE_1));
892 FAIL_(crypt_resume_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1 "blah", 0), "wrong keyfile");
893 OK_(crypt_resume_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0));
894 FAIL_(crypt_resume_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0), "not suspended");
897 OK_(crypt_deactivate(cd, CDEVICE_1));
901 static void AddDeviceLuks(void)
903 struct crypt_device *cd;
904 struct crypt_params_luks1 params = {
906 .data_alignment = 2048, // 4M, data offset will be 4096
907 .data_device = DEVICE_2
909 char key[128], key2[128];
911 char *passphrase = "blabla";
912 char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
913 size_t key_size = strlen(mk_hex) / 2;
914 char *cipher = "aes";
915 char *cipher_mode = "cbc-essiv:sha256";
916 uint64_t r_payload_offset, r_header_size, r_size_1;
918 crypt_decode_key(key, mk_hex, key_size);
921 OK_(get_luks_offsets(1, key_size, 0, 0, &r_header_size, &r_payload_offset));
922 OK_(create_dmdevice_over_loop(H_DEVICE, r_header_size));
923 OK_(create_dmdevice_over_loop(H_DEVICE_WRONG, r_header_size - 1));
926 OK_(crypt_init(&cd, DMDIR H_DEVICE_WRONG));
927 params.data_alignment = 0;
928 FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms), "Not enough space for keyslots material");
931 // test payload_offset = 0 for encrypted device with external header device
932 OK_(crypt_init(&cd, DMDIR H_DEVICE));
933 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
934 EQ_(crypt_get_data_offset(cd), 0);
937 params.data_alignment = 0;
938 params.data_device = NULL;
940 // test payload_offset = 0. format() should look up alignment offset from device topology
941 OK_(crypt_init(&cd, DEVICE_2));
942 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
943 OK_(!(crypt_get_data_offset(cd) > 0));
947 * test limit values for backing device size
949 params.data_alignment = 4096;
950 OK_(get_luks_offsets(0, key_size, params.data_alignment, 0, NULL, &r_payload_offset));
951 OK_(create_dmdevice_over_loop(L_DEVICE_0S, r_payload_offset));
952 OK_(create_dmdevice_over_loop(L_DEVICE_1S, r_payload_offset + 1));
953 OK_(create_dmdevice_over_loop(L_DEVICE_WRONG, r_payload_offset - 1));
955 // 1 sector less than required
956 OK_(crypt_init(&cd, DMDIR L_DEVICE_WRONG));
957 FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms), "Device too small");
960 // 0 sectors for encrypted area
961 OK_(crypt_init(&cd, DMDIR L_DEVICE_0S));
962 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
963 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Encrypted area too small");
966 // 1 sector for encrypted area
967 OK_(crypt_init(&cd, DMDIR L_DEVICE_1S));
968 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
969 EQ_(crypt_get_data_offset(cd), params.data_alignment);
970 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
971 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
972 OK_(device_size(DMDIR CDEVICE_1, &r_size_1));
973 EQ_(r_size_1, SECTOR_SIZE);
974 OK_(crypt_deactivate(cd, CDEVICE_1));
975 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
976 // restrict format only to empty context
977 // FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms), "Context is already formated");
978 // FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, NULL), "Context is already formated");
979 // change data device to wrong one
980 OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_0S));
981 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Device too small");
982 OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_1S));
983 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
984 OK_(crypt_deactivate(cd, CDEVICE_1));
987 params.data_alignment = 0;
988 params.data_device = DEVICE_2;
990 // generate keyslot material at the end of luks header
991 OK_(crypt_init(&cd, DMDIR H_DEVICE));
992 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
993 EQ_(crypt_keyslot_add_by_volume_key(cd, 7, key, key_size, passphrase, strlen(passphrase)), 7);
994 EQ_(crypt_activate_by_passphrase(cd, CDEVICE_1, 7, passphrase, strlen(passphrase) ,0), 7);
996 OK_(crypt_init_by_name_and_header(&cd, CDEVICE_1, DMDIR H_DEVICE));
997 FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms), "Context is already formated");
998 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
999 OK_(crypt_deactivate(cd, CDEVICE_1));
1002 params.data_alignment = 2048;
1003 params.data_device = NULL;
1005 // test uuid mismatch and _init_by_name_and_header
1006 OK_(crypt_init(&cd, DMDIR L_DEVICE_1S));
1007 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1008 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
1010 params.data_alignment = 0;
1011 params.data_device = DEVICE_2;
1012 OK_(crypt_init(&cd, DMDIR H_DEVICE));
1013 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1015 // there we've got uuid mismatch
1016 OK_(crypt_init_by_name_and_header(&cd, CDEVICE_1, DMDIR H_DEVICE));
1017 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
1018 EQ_(crypt_get_type(cd), NULL);
1019 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Device is active");
1020 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, key, key_size, 0), "Device is active");
1021 EQ_(crypt_status(cd, CDEVICE_2), CRYPT_INACTIVE);
1022 OK_(crypt_deactivate(cd, CDEVICE_1));
1025 params.data_device = NULL;
1027 OK_(crypt_init(&cd, DEVICE_2));
1028 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1030 // even with no keyslots defined it can be activated by volume key
1031 OK_(crypt_volume_key_verify(cd, key, key_size));
1032 OK_(crypt_activate_by_volume_key(cd, CDEVICE_2, key, key_size, 0));
1033 EQ_(crypt_status(cd, CDEVICE_2), CRYPT_ACTIVE);
1034 OK_(crypt_deactivate(cd, CDEVICE_2));
1037 EQ_(7, crypt_keyslot_add_by_volume_key(cd, 7, key, key_size, passphrase, strlen(passphrase)));
1038 EQ_(CRYPT_SLOT_ACTIVE_LAST, crypt_keyslot_status(cd, 7));
1039 EQ_(7, crypt_activate_by_passphrase(cd, CDEVICE_2, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
1040 EQ_(crypt_status(cd, CDEVICE_2), CRYPT_ACTIVE);
1041 OK_(crypt_deactivate(cd, CDEVICE_2));
1043 EQ_(1, crypt_keyslot_add_by_volume_key(cd, 1, key, key_size, KEY1, strlen(KEY1)));
1044 OK_(_prepare_keyfile(KEYFILE1, KEY1, strlen(KEY1)));
1045 OK_(_prepare_keyfile(KEYFILE2, KEY2, strlen(KEY2)));
1046 EQ_(2, crypt_keyslot_add_by_keyfile(cd, 2, KEYFILE1, 0, KEYFILE2, 0));
1047 FAIL_(crypt_activate_by_keyfile(cd, CDEVICE_2, CRYPT_ANY_SLOT, KEYFILE2, strlen(KEY2)-1, 0), "key mismatch");
1048 EQ_(2, crypt_activate_by_keyfile(cd, NULL, CRYPT_ANY_SLOT, KEYFILE2, 0, 0));
1049 EQ_(2, crypt_activate_by_keyfile(cd, CDEVICE_2, CRYPT_ANY_SLOT, KEYFILE2, 0, 0));
1050 OK_(crypt_keyslot_destroy(cd, 1));
1051 OK_(crypt_keyslot_destroy(cd, 2));
1052 OK_(crypt_deactivate(cd, CDEVICE_2));
1055 FAIL_(crypt_keyslot_add_by_volume_key(cd, 7, key, key_size, passphrase, strlen(passphrase)), "slot used");
1057 FAIL_(crypt_keyslot_add_by_volume_key(cd, 6, key, key_size, passphrase, strlen(passphrase)), "key mismatch");
1059 EQ_(6, crypt_keyslot_add_by_volume_key(cd, 6, key, key_size, passphrase, strlen(passphrase)));
1060 EQ_(CRYPT_SLOT_ACTIVE, crypt_keyslot_status(cd, 6));
1062 FAIL_(crypt_keyslot_destroy(cd, 8), "invalid keyslot");
1063 FAIL_(crypt_keyslot_destroy(cd, CRYPT_ANY_SLOT), "invalid keyslot");
1064 FAIL_(crypt_keyslot_destroy(cd, 0), "keyslot not used");
1065 OK_(crypt_keyslot_destroy(cd, 7));
1066 EQ_(CRYPT_SLOT_INACTIVE, crypt_keyslot_status(cd, 7));
1067 EQ_(CRYPT_SLOT_ACTIVE_LAST, crypt_keyslot_status(cd, 6));
1069 EQ_(6, crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key2, &key_size, passphrase, strlen(passphrase)));
1070 OK_(crypt_volume_key_verify(cd, key2, key_size));
1072 OK_(memcmp(key, key2, key_size));
1073 OK_(strcmp(cipher, crypt_get_cipher(cd)));
1074 OK_(strcmp(cipher_mode, crypt_get_cipher_mode(cd)));
1075 EQ_(key_size, crypt_get_volume_key_size(cd));
1076 EQ_(4096, crypt_get_data_offset(cd));
1077 OK_(strcmp(DEVICE_2, crypt_get_device_name(cd)));
1080 crypt_set_log_callback(cd, &new_log, NULL);
1081 OK_(crypt_dump(cd));
1082 OK_(!(global_lines != 0));
1083 crypt_set_log_callback(cd, NULL, NULL);
1086 FAIL_(crypt_set_uuid(cd, "blah"), "wrong UUID format");
1087 OK_(crypt_set_uuid(cd, DEVICE_TEST_UUID));
1088 OK_(strcmp(DEVICE_TEST_UUID, crypt_get_uuid(cd)));
1090 FAIL_(crypt_deactivate(cd, CDEVICE_2), "not active");
1092 _cleanup_dmdevices();
1095 static void UseTempVolumes(void)
1097 struct crypt_device *cd;
1100 // Tepmporary device without keyslot but with on-disk LUKS header
1101 OK_(crypt_init(&cd, DEVICE_2));
1102 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, NULL, 0, 0), "not yet formatted");
1103 OK_(crypt_format(cd, CRYPT_LUKS1, "aes", "cbc-essiv:sha256", NULL, NULL, 16, NULL));
1104 OK_(crypt_activate_by_volume_key(cd, CDEVICE_2, NULL, 0, 0));
1105 EQ_(crypt_status(cd, CDEVICE_2), CRYPT_ACTIVE);
1108 OK_(crypt_init_by_name(&cd, CDEVICE_2));
1109 OK_(crypt_deactivate(cd, CDEVICE_2));
1112 // Dirty checks: device without UUID
1113 // we should be able to remove it but not manuipulate with it
1114 snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
1115 "0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
1116 "%s 2048\"", CDEVICE_2, DEVICE_2);
1118 OK_(crypt_init_by_name(&cd, CDEVICE_2));
1119 OK_(crypt_deactivate(cd, CDEVICE_2));
1120 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, NULL, 0, 0), "No known device type");
1123 // Dirty checks: device with UUID but LUKS header key fingerprint must fail)
1124 snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
1125 "0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
1126 "%s 2048\" -u CRYPT-LUKS1-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-ctest1",
1127 CDEVICE_2, DEVICE_2);
1129 OK_(crypt_init_by_name(&cd, CDEVICE_2));
1130 OK_(crypt_deactivate(cd, CDEVICE_2));
1131 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, NULL, 0, 0), "wrong volume key");
1135 OK_(crypt_init(&cd, DEVICE_2));
1136 OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
1137 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, NULL, 0, 0), "volume key is lost");
1141 OK_(crypt_init(&cd, DEVICE_2));
1142 OK_(crypt_format(cd, CRYPT_PLAIN, "aes", "cbc-essiv:sha256", NULL, NULL, 16, NULL));
1143 FAIL_(crypt_activate_by_volume_key(cd, NULL, "xxx", 3, 0), "cannot verify key with plain");
1144 FAIL_(crypt_volume_key_verify(cd, "xxx", 3), "cannot verify key with plain");
1145 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, "xxx", 3, 0), "wrong key lenght");
1146 OK_(crypt_activate_by_volume_key(cd, CDEVICE_2, "volumekeyvolumek", 16, 0));
1147 EQ_(crypt_status(cd, CDEVICE_2), CRYPT_ACTIVE);
1148 OK_(crypt_deactivate(cd, CDEVICE_2));
1152 static void LuksHeaderRestore(void)
1154 struct crypt_device *cd;
1155 struct crypt_params_luks1 params = {
1157 .data_alignment = 2048, // 4M, data offset will be 4096
1159 struct crypt_params_plain pl_params = {
1165 char key[128], key2[128], cmd[256];
1167 char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
1168 size_t key_size = strlen(mk_hex) / 2;
1169 char *cipher = "aes";
1170 char *cipher_mode = "cbc-essiv:sha256";
1171 uint64_t r_payload_offset;
1173 crypt_decode_key(key, mk_hex, key_size);
1175 OK_(get_luks_offsets(0, key_size, params.data_alignment, 0, NULL, &r_payload_offset));
1176 OK_(create_dmdevice_over_loop(L_DEVICE_OK, r_payload_offset + 5000));
1178 // do not restore header over plain device
1179 OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
1180 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, &pl_params));
1181 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
1182 FAIL_(crypt_header_restore(cd, CRYPT_PLAIN, VALID_HEADER), "Cannot restore header to PLAIN type device");
1183 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, VALID_HEADER), "Cannot restore header over PLAIN type device");
1184 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
1185 OK_(crypt_deactivate(cd, CDEVICE_1));
1189 OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
1190 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1191 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_1), "Header corrupted");
1192 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_2), "Header corrupted");
1193 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_3), "Header corrupted");
1194 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_4), "Header too small");
1195 OK_(crypt_header_restore(cd, CRYPT_LUKS1, VALID_HEADER));
1196 // wipe valid luks header
1197 snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=" DMDIR L_DEVICE_OK " bs=512 count=%" PRIu64, r_payload_offset);
1198 OK_(_system(cmd, 1));
1199 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_1), "Header corrupted");
1200 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_2), "Header corrupted");
1201 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_3), "Header corrupted");
1202 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, EVL_HEADER_4), "Header too small");
1203 OK_(crypt_header_restore(cd, CRYPT_LUKS1, VALID_HEADER));
1204 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
1205 OK_(crypt_deactivate(cd, CDEVICE_1));
1208 // volume key_size mismatch
1209 OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
1210 memcpy(key2, key, key_size - 1);
1211 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key2, key_size - 1, ¶ms));
1212 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, VALID_HEADER), "Volume keysize mismatch");
1215 // payload offset mismatch
1216 params.data_alignment = 8192;
1217 OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
1218 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1219 FAIL_(crypt_header_restore(cd, CRYPT_LUKS1, VALID_HEADER), "Payload offset mismatch");
1220 //_system("dmsetup table;sleep 1",1);
1223 _cleanup_dmdevices();
1226 static void LuksHeaderLoad(void)
1228 struct crypt_device *cd;
1229 struct crypt_params_luks1 params = {
1231 .data_alignment = 2048,
1233 struct crypt_params_plain pl_params = {
1239 char key[128], cmd[256];
1241 char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
1242 size_t key_size = strlen(mk_hex) / 2;
1243 char *cipher = "aes";
1244 char *cipher_mode = "cbc-essiv:sha256";
1245 uint64_t r_payload_offset, r_header_size;
1247 crypt_decode_key(key, mk_hex, key_size);
1250 OK_(get_luks_offsets(0, key_size, params.data_alignment, 0, &r_header_size, &r_payload_offset));
1251 // external header device
1252 OK_(create_dmdevice_over_loop(H_DEVICE, r_header_size));
1253 // prepared header on a device too small to contain header and payload
1254 OK_(create_dmdevice_over_loop(H_DEVICE_WRONG, r_payload_offset - 1));
1255 snprintf(cmd, sizeof(cmd), "dd if=" EVL_HEADER_4 " of=" DMDIR H_DEVICE_WRONG " bs=512 count=%" PRIu64, r_payload_offset - 1);
1256 OK_(_system(cmd, 1));
1258 OK_(create_dmdevice_over_loop(L_DEVICE_OK, r_payload_offset + 1000));
1260 OK_(create_dmdevice_over_loop(L_DEVICE_1S, r_payload_offset + 1));
1261 // 0 sectors device for payload
1262 OK_(create_dmdevice_over_loop(L_DEVICE_0S, r_payload_offset));
1264 // valid metadata and device size
1265 params.data_alignment = 0;
1266 params.data_device = DMDIR L_DEVICE_OK;
1267 OK_(crypt_init(&cd, DMDIR H_DEVICE));
1268 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1270 OK_(crypt_init(&cd, DMDIR H_DEVICE));
1271 OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
1272 OK_(crypt_set_data_device(cd, DMDIR L_DEVICE_OK));
1273 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
1274 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
1275 OK_(crypt_deactivate(cd, CDEVICE_1));
1278 // bad header: device too small (payloadOffset > device_size)
1279 OK_(crypt_init(&cd, DMDIR H_DEVICE_WRONG));
1280 FAIL_(crypt_load(cd, CRYPT_LUKS1, NULL), "Device too small");
1281 EQ_(crypt_get_type(cd), NULL);
1284 // 0 secs for encrypted data area
1285 params.data_alignment = 2048;
1286 params.data_device = NULL;
1287 OK_(crypt_init(&cd, DMDIR L_DEVICE_0S));
1288 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1290 // load should be ok
1291 OK_(crypt_init(&cd, DMDIR L_DEVICE_0S));
1292 OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
1293 FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "Device too small");
1294 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
1298 OK_(_system("dd if=/dev/zero of=" DMDIR L_DEVICE_0S "bs=512 count=8", 1));
1299 OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
1300 FAIL_(crypt_load(cd, CRYPT_LUKS1, NULL), "Header not found");
1304 OK_(crypt_init(&cd, DMDIR H_DEVICE));
1305 FAIL_(crypt_load(cd, CRYPT_PLAIN, NULL), "Can't load nonLUKS device type");
1307 OK_(crypt_init(&cd, DMDIR H_DEVICE));
1308 OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, key, key_size, &pl_params));
1309 FAIL_(crypt_load(cd, CRYPT_LUKS1, NULL), "Can't load over nonLUKS device type");
1312 _cleanup_dmdevices();
1315 static void LuksHeaderBackup(void)
1317 struct crypt_device *cd;
1318 struct crypt_params_luks1 params = {
1320 .data_alignment = 2048,
1324 char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
1325 size_t key_size = strlen(mk_hex) / 2;
1326 char *cipher = "aes";
1327 char *cipher_mode = "cbc-essiv:sha256";
1328 uint64_t r_payload_offset;
1330 crypt_decode_key(key, mk_hex, key_size);
1332 OK_(get_luks_offsets(0, key_size, params.data_alignment, 0, NULL, &r_payload_offset));
1333 OK_(create_dmdevice_over_loop(L_DEVICE_OK, r_payload_offset + 1));
1335 // create LUKS device and backup the header
1336 OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
1337 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1338 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
1339 OK_(crypt_header_backup(cd, CRYPT_LUKS1, BACKUP_FILE));
1340 OK_(crypt_deactivate(cd, CDEVICE_1));
1343 // restore header from backup
1344 OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
1345 OK_(crypt_header_restore(cd, CRYPT_LUKS1, BACKUP_FILE));
1346 OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
1347 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
1348 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
1349 OK_(crypt_deactivate(cd, CDEVICE_1));
1352 _cleanup_dmdevices();
1355 static void ResizeDeviceLuks(void)
1357 struct crypt_device *cd;
1358 struct crypt_params_luks1 params = {
1360 .data_alignment = 2048,
1364 char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
1365 size_t key_size = strlen(mk_hex) / 2;
1366 char *cipher = "aes";
1367 char *cipher_mode = "cbc-essiv:sha256";
1368 uint64_t r_payload_offset, r_header_size, r_size;
1370 crypt_decode_key(key, mk_hex, key_size);
1373 OK_(get_luks_offsets(0, key_size, params.data_alignment, 0, NULL, &r_payload_offset));
1374 OK_(get_luks_offsets(1, key_size, 0, 0, &r_header_size, NULL));
1375 OK_(create_dmdevice_over_loop(H_DEVICE, r_header_size));
1376 OK_(create_dmdevice_over_loop(L_DEVICE_OK, r_payload_offset + 1000));
1377 OK_(create_dmdevice_over_loop(L_DEVICE_0S, 1000));
1379 // test header and encrypted payload all in one device
1380 OK_(crypt_init(&cd, DMDIR L_DEVICE_OK));
1381 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1382 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
1383 OK_(crypt_resize(cd, CDEVICE_1, 42));
1384 if (!device_size(DMDIR CDEVICE_1, &r_size))
1385 EQ_(42, r_size >> SECTOR_SHIFT);
1386 // autodetect encrypted device area size
1387 OK_(crypt_resize(cd, CDEVICE_1, 0));
1388 if (!device_size(DMDIR CDEVICE_1, &r_size))
1389 EQ_(1000, r_size >> SECTOR_SHIFT);
1390 FAIL_(crypt_resize(cd, CDEVICE_1, 1001), "Device too small");
1391 if (!device_size(DMDIR CDEVICE_1, &r_size))
1392 EQ_(1000, r_size >> SECTOR_SHIFT);
1393 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
1394 OK_(crypt_deactivate(cd, CDEVICE_1));
1397 params.data_alignment = 0;
1398 params.data_device = DMDIR L_DEVICE_0S;
1399 // test case for external header
1400 OK_(crypt_init(&cd, DMDIR H_DEVICE));
1401 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1402 OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
1403 OK_(crypt_resize(cd, CDEVICE_1, 666));
1404 if (!device_size(DMDIR CDEVICE_1, &r_size))
1405 EQ_(666, r_size >> SECTOR_SHIFT);
1406 // autodetect encrypted device size
1407 OK_(crypt_resize(cd, CDEVICE_1, 0));
1408 if (!device_size(DMDIR CDEVICE_1, &r_size))
1409 EQ_(1000, r_size >> SECTOR_SHIFT);
1410 FAIL_(crypt_resize(cd, CDEVICE_1, 1001), "Device too small");
1411 if (!device_size(DMDIR CDEVICE_1, &r_size))
1412 EQ_(1000, r_size >> SECTOR_SHIFT);
1413 EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
1414 OK_(crypt_deactivate(cd, CDEVICE_1));
1417 _cleanup_dmdevices();
1420 static void HashDevicePlain(void)
1422 struct crypt_device *cd;
1423 struct crypt_params_plain params = {
1430 char *mk_hex, *keystr, key[256];
1432 OK_(crypt_init(&cd, DEVICE_1));
1433 OK_(crypt_format(cd, CRYPT_PLAIN, "aes", "cbc-essiv:sha256", NULL, NULL, 16, ¶ms));
1435 // hash PLAIN, short key
1436 OK_(_prepare_keyfile(KEYFILE1, "tooshort", 8));
1437 FAIL_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 16, 0), "not enough data in keyfile");
1440 // hash PLAIN, exact key
1441 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
1442 mk_hex = "caffeecaffeecaffeecaffeecaffee88";
1444 crypt_decode_key(key, mk_hex, key_size);
1445 OK_(_prepare_keyfile(KEYFILE1, key, key_size));
1446 OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, key_size, 0));
1447 OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1448 OK_(strcmp(key, mk_hex));
1449 OK_(crypt_deactivate(cd, CDEVICE_1));
1452 mk_hex = "caffeecaffeecaffeecaffeeca000000";
1453 OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, key_size - 3, 0));
1454 OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1455 OK_(strcmp(key, mk_hex));
1456 OK_(crypt_deactivate(cd, CDEVICE_1));
1460 // hash PLAIN, long key
1461 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
1462 mk_hex = "caffeecaffeecaffeecaffeecaffee88babebabe";
1464 crypt_decode_key(key, mk_hex, key_size);
1465 OK_(_prepare_keyfile(KEYFILE1, key, strlen(mk_hex) / 2));
1466 OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, key_size, 0));
1467 OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1468 FAIL_(strcmp(key, mk_hex), "only key length used");
1469 OK_(strncmp(key, mk_hex, key_size));
1470 OK_(crypt_deactivate(cd, CDEVICE_1));
1473 // Now without explicit limit
1474 OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0, 0));
1475 OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1476 FAIL_(strcmp(key, mk_hex), "only key length used");
1477 OK_(strncmp(key, mk_hex, key_size));
1478 OK_(crypt_deactivate(cd, CDEVICE_1));
1484 params.hash = "sha256";
1485 OK_(crypt_init(&cd, DEVICE_1));
1486 OK_(crypt_format(cd, CRYPT_PLAIN, "aes", "cbc-essiv:sha256", NULL, NULL, 16, ¶ms));
1488 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
1489 mk_hex = "c62e4615bd39e222572f3a1bf7c2132e";
1490 keystr = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
1491 key_size = strlen(keystr); // 32
1492 OK_(_prepare_keyfile(KEYFILE1, keystr, strlen(keystr)));
1493 OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, key_size, 0));
1494 OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1495 OK_(strcmp(key, mk_hex));
1496 OK_(crypt_deactivate(cd, CDEVICE_1));
1498 // Read full keyfile
1499 OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0, 0));
1500 OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1501 OK_(strcmp(key, mk_hex));
1502 OK_(crypt_deactivate(cd, CDEVICE_1));
1506 // Limit keyfile read
1507 keystr = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxAAAAAAAA";
1508 OK_(_prepare_keyfile(KEYFILE1, keystr, strlen(keystr)));
1509 OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, key_size, 0));
1510 OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1511 OK_(strcmp(key, mk_hex));
1512 OK_(crypt_deactivate(cd, CDEVICE_1));
1515 OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0, 0));
1516 OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1517 OK_(strcmp(key, "0e49cb34a1dee1df33f6505e4de44a66"));
1518 OK_(crypt_deactivate(cd, CDEVICE_1));
1522 // FIXME: add keyfile="-" tests somehow
1527 // Check that gcrypt is properly initialised in format
1528 static void NonFIPSAlg(void)
1530 struct crypt_device *cd;
1531 struct crypt_params_luks1 params = {0};
1533 size_t key_size = 128;
1534 char *cipher = "aes";
1535 char *cipher_mode = "cbc-essiv:sha256";
1538 OK_(crypt_init(&cd, DEVICE_2));
1539 params.hash = "sha256";
1540 OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms));
1542 params.hash = "whirlpool";
1543 ret = crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms);
1545 printf("WARNING: whirlpool not supported, skipping test.\n");
1550 params.hash = "md5";
1551 FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, ¶ms),
1552 "MD5 unsupported, too short");
1556 int main (int argc, char *argv[])
1560 if (getuid() != 0) {
1561 printf("You must be root to run this test.\n");
1565 for (i = 1; i < argc; i++) {
1566 if (!strcmp("-v", argv[i]) || !strcmp("--verbose", argv[i]))
1568 else if (!strcmp("--debug", argv[i]))
1569 _debug = _verbose = 1;
1576 crypt_set_debug_level(_debug ? CRYPT_DEBUG_ALL : CRYPT_DEBUG_NONE);
1578 RUN_(NonFIPSAlg, "Crypto is properly initialised in format"); //must be the first!
1579 RUN_(AddDevicePlain, "plain device API creation exercise");
1580 RUN_(HashDevicePlain, "plain device API hash test");
1581 RUN_(AddDeviceLuks, "Format and use LUKS device");
1582 RUN_(LuksHeaderLoad, "test header load");
1583 RUN_(LuksHeaderRestore, "test LUKS header restore");
1584 RUN_(LuksHeaderBackup, "test LUKS header backup");
1585 RUN_(ResizeDeviceLuks, "Luks device resize tests");
1586 RUN_(UseLuksDevice, "Use pre-formated LUKS device");
1587 RUN_(SuspendDevice, "Suspend/Resume test");
1588 RUN_(UseTempVolumes, "Format and use temporary encrypted device");
1590 RUN_(CallbacksTest, "API callbacks test");