* Revert default initialisation of volume key in crypt_init_by_name().
[platform/upstream/cryptsetup.git] / tests / api-test.c
1 /*
2  * cryptsetup library API check functions
3  *
4  * Copyright (C) 2009-2010 Red Hat, Inc. All rights reserved.
5  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <linux/fs.h>
26 #include <errno.h>
27 #include <assert.h>
28 #include <sys/stat.h>
29 #include <sys/ioctl.h>
30 #include <libdevmapper.h>
31
32 #include "libcryptsetup.h"
33 #include "utils_loop.h"
34
35 #define DMDIR "/dev/mapper/"
36
37 #define DEVICE_1_UUID "28632274-8c8a-493f-835b-da802e1c576b"
38 #define DEVICE_EMPTY_name "crypt_zero"
39 #define DEVICE_EMPTY DMDIR DEVICE_EMPTY_name
40 #define DEVICE_ERROR_name "crypt_error"
41 #define DEVICE_ERROR DMDIR DEVICE_ERROR_name
42
43 #define CDEVICE_1 "ctest1"
44 #define CDEVICE_2 "ctest2"
45 #define CDEVICE_WRONG "O_o"
46
47 #define IMAGE1 "compatimage.img"
48 #define IMAGE_EMPTY "empty.img"
49
50 #define KEYFILE1 "key1.file"
51 #define KEY1 "compatkey"
52
53 #define KEYFILE2 "key2.file"
54 #define KEY2 "0123456789abcdef"
55
56 #define PASSPHRASE "blabla"
57
58 #define DEVICE_TEST_UUID "12345678-1234-1234-1234-123456789abc"
59
60 static int _debug   = 0;
61 static int _verbose = 1;
62
63 static char global_log[4096];
64 static int global_lines = 0;
65
66 static char *DEVICE_1 = NULL;
67 static char *DEVICE_2 = NULL;
68
69 // Helpers
70
71 // Get key from kernel dm mapping table using dm-ioctl
72 static int _get_key_dm(const char *name, char *buffer, unsigned int buffer_size)
73 {
74         struct dm_task *dmt;
75         struct dm_info dmi;
76         uint64_t start, length;
77         char *target_type, *rcipher, *key, *params;
78         void *next = NULL;
79         int r = -EINVAL;
80
81         if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
82                 goto out;
83         if (!dm_task_set_name(dmt, name))
84                 goto out;
85         if (!dm_task_run(dmt))
86                 goto out;
87         if (!dm_task_get_info(dmt, &dmi))
88                 goto out;
89         if (!dmi.exists)
90                 goto out;
91
92         next = dm_get_next_target(dmt, next, &start, &length, &target_type, &params);
93         if (!target_type || strcmp(target_type, "crypt") != 0)
94                 goto out;
95
96         rcipher = strsep(&params, " ");
97         key = strsep(&params, " ");
98
99         if (buffer_size <= strlen(key))
100                 goto out;
101
102         strncpy(buffer, key, buffer_size);
103         r = 0;
104 out:
105         if (dmt)
106                 dm_task_destroy(dmt);
107
108         return r;
109 }
110
111 static int _prepare_keyfile(const char *name, const char *passphrase, int size)
112 {
113         int fd, r;
114
115         fd = open(name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR);
116         if (fd != -1) {
117                 r = write(fd, passphrase, size);
118                 close(fd);
119         } else
120                 r = 0;
121
122         return r == size ? 0 : 1;
123 }
124
125 static void _remove_keyfiles(void)
126 {
127         remove(KEYFILE1);
128         remove(KEYFILE2);
129 }
130
131 // Decode key from its hex representation
132 static int crypt_decode_key(char *key, char *hex, unsigned int size)
133 {
134         char buffer[3];
135         char *endp;
136         unsigned int i;
137
138         buffer[2] = '\0';
139
140         for (i = 0; i < size; i++) {
141                 buffer[0] = *hex++;
142                 buffer[1] = *hex++;
143
144                 key[i] = (unsigned char)strtoul(buffer, &endp, 16);
145
146                 if (endp != &buffer[2])
147                         return -1;
148         }
149
150         if (*hex != '\0')
151                 return -1;
152
153         return 0;
154 }
155
156 static void cmdLineLog(int level, char *msg)
157 {
158         strncat(global_log, msg, sizeof(global_log) - strlen(global_log));
159         global_lines++;
160 }
161
162 static void new_log(int level, const char *msg, void *usrptr)
163 {
164         cmdLineLog(level, (char*)msg);
165 }
166
167 static void reset_log()
168 {
169         memset(global_log, 0, sizeof(global_log));
170         global_lines = 0;
171 }
172
173 static void _system(const char *command, int warn)
174 {
175         if (system(command) < 0 && warn)
176                 printf("System command failed: %s", command);
177 }
178
179 static void _cleanup(void)
180 {
181         struct stat st;
182
183         //_system("udevadm settle", 0);
184
185         if (!stat(DMDIR CDEVICE_1, &st))
186                 _system("dmsetup remove " CDEVICE_1, 0);
187
188         if (!stat(DMDIR CDEVICE_2, &st))
189                 _system("dmsetup remove " CDEVICE_2, 0);
190
191         if (!stat(DEVICE_EMPTY, &st))
192                 _system("dmsetup remove " DEVICE_EMPTY_name, 0);
193
194         if (!stat(DEVICE_ERROR, &st))
195                 _system("dmsetup remove " DEVICE_ERROR_name, 0);
196
197         if (crypt_loop_device(DEVICE_1))
198                 crypt_loop_detach(DEVICE_1);
199
200         if (crypt_loop_device(DEVICE_2))
201                 crypt_loop_detach(DEVICE_2);
202
203         _system("rm -f " IMAGE_EMPTY, 0);
204         _remove_keyfiles();
205 }
206
207 static int _setup(void)
208 {
209         int fd, ro = 0;
210
211         _system("dmsetup create " DEVICE_EMPTY_name " --table \"0 10000 zero\"", 1);
212         _system("dmsetup create " DEVICE_ERROR_name " --table \"0 10000 error\"", 1);
213         if (!DEVICE_1)
214                 DEVICE_1 = crypt_loop_get_device();
215         if (!DEVICE_1) {
216                 printf("Cannot find free loop device.\n");
217                 return 1;
218         }
219         if (crypt_loop_device(DEVICE_1)) {
220                 _system(" [ ! -e " IMAGE1 " ] && bzip2 -dk " IMAGE1 ".bz2", 1);
221                 fd = crypt_loop_attach(DEVICE_1, IMAGE1, 0, 0, &ro);
222                 close(fd);
223         }
224         if (!DEVICE_2)
225                 DEVICE_2 = crypt_loop_get_device();
226         if (!DEVICE_2) {
227                 printf("Cannot find free loop device.\n");
228                 return 1;
229         }
230         if (crypt_loop_device(DEVICE_2)) {
231                 _system("dd if=/dev/zero of=" IMAGE_EMPTY " bs=1M count=4", 1);
232                 fd = crypt_loop_attach(DEVICE_2, IMAGE_EMPTY, 0, 0, &ro);
233                 close(fd);
234         }
235         return 0;
236 }
237
238 void check_ok(int status, int line, const char *func)
239 {
240         char buf[256];
241
242         if (status) {
243                 crypt_get_error(buf, sizeof(buf));
244                 printf("FAIL line %d [%s]: code %d, %s\n", line, func, status, buf);
245                 _cleanup();
246                 exit(-1);
247         }
248 }
249
250 void check_ko(int status, int line, const char *func)
251 {
252         char buf[256];
253
254         memset(buf, 0, sizeof(buf));
255         crypt_get_error(buf, sizeof(buf));
256         if (status >= 0) {
257                 printf("FAIL line %d [%s]: code %d, %s\n", line, func, status, buf);
258                 _cleanup();
259                 exit(-1);
260         } else if (_verbose)
261                 printf("   => errno %d, errmsg: %s\n", status, buf);
262 }
263
264 void check_equal(int line, const char *func)
265 {
266         printf("FAIL line %d [%s]: expected equal values differs.\n", line, func);
267         _cleanup();
268         exit(-1);
269 }
270
271 void xlog(const char *msg, const char *tst, const char *func, int line, const char *txt)
272 {
273         if (_verbose) {
274                 if (txt)
275                         printf(" [%s,%s:%d] %s [%s]\n", msg, func, line, tst, txt);
276                 else
277                         printf(" [%s,%s:%d] %s\n", msg, func, line, tst);
278         }
279 }
280 #define OK_(x)          do { xlog("(success)", #x, __FUNCTION__, __LINE__, NULL); \
281                              check_ok((x), __LINE__, __FUNCTION__); \
282                         } while(0)
283 #define FAIL_(x, y)     do { xlog("(fail)   ", #x, __FUNCTION__, __LINE__, y); \
284                              check_ko((x), __LINE__, __FUNCTION__); \
285                         } while(0)
286 #define EQ_(x, y)       do { xlog("(equal)  ", #x " == " #y, __FUNCTION__, __LINE__, NULL); \
287                              if ((x) != (y)) check_equal(__LINE__, __FUNCTION__); \
288                         } while(0)
289
290 #define RUN_(x, y)              do { printf("%s: %s\n", #x, (y)); x(); } while (0)
291
292 #if 0
293 static int yesDialog(char *msg)
294 {
295         return 1;
296 }
297
298 static struct interface_callbacks cmd_icb = {
299         .yesDialog = yesDialog,
300         .log = cmdLineLog,
301 };
302
303 // OLD API TESTS
304 static void LuksUUID(void)
305 {
306         struct crypt_options co = { .icb = &cmd_icb };
307
308         co.device = DEVICE_EMPTY;
309         EQ_(crypt_luksUUID(&co), -EINVAL);
310
311         co.device = DEVICE_ERROR;
312         EQ_(crypt_luksUUID(&co), -EINVAL);
313
314         reset_log();
315         co.device = DEVICE_1;
316         OK_(crypt_luksUUID(&co));
317         EQ_(strlen(global_log), 37); /* UUID + "\n" */
318         EQ_(strncmp(global_log, DEVICE_1_UUID, strlen(DEVICE_1_UUID)), 0);
319
320 }
321
322 static void IsLuks(void)
323 {
324         struct crypt_options co = {  .icb = &cmd_icb };
325
326         co.device = DEVICE_EMPTY;
327         EQ_(crypt_isLuks(&co), -EINVAL);
328
329         co.device = DEVICE_ERROR;
330         EQ_(crypt_isLuks(&co), -EINVAL);
331
332         co.device = DEVICE_1;
333         OK_(crypt_isLuks(&co));
334 }
335
336 static void LuksOpen(void)
337 {
338         struct crypt_options co = {
339                 .name = CDEVICE_1,
340                 //.passphrase = "blabla",
341                 .icb = &cmd_icb,
342         };
343
344         OK_(_prepare_keyfile(KEYFILE1, KEY1, strlen(KEY1)));
345         co.key_file = KEYFILE1;
346
347         co.device = DEVICE_EMPTY;
348         EQ_(crypt_luksOpen(&co), -EINVAL);
349
350         co.device = DEVICE_ERROR;
351         EQ_(crypt_luksOpen(&co), -EINVAL);
352
353         co.device = DEVICE_1;
354         OK_(crypt_luksOpen(&co));
355         FAIL_(crypt_luksOpen(&co), "already open");
356
357         _remove_keyfiles();
358 }
359
360 static void query_device(void)
361 {
362         struct crypt_options co = {.icb = &cmd_icb };
363
364         co.name = CDEVICE_WRONG;
365         EQ_(crypt_query_device(&co), 0);
366
367         co.name = CDEVICE_1;
368         EQ_(crypt_query_device(&co), 1);
369
370         OK_(strncmp(crypt_get_dir(), DMDIR, 11));
371         OK_(strcmp(co.cipher, "aes-cbc-essiv:sha256"));
372         EQ_(co.key_size, 16);
373         EQ_(co.offset, 1032);
374         EQ_(co.flags & CRYPT_FLAG_READONLY, 0);
375         EQ_(co.skip, 0);
376         crypt_put_options(&co);
377 }
378
379 static void remove_device(void)
380 {
381         int fd;
382         struct crypt_options co = {.icb = &cmd_icb };
383
384         co.name = CDEVICE_WRONG;
385         EQ_(crypt_remove_device(&co), -ENODEV);
386
387         fd = open(DMDIR CDEVICE_1, O_RDONLY);
388         co.name = CDEVICE_1;
389         FAIL_(crypt_remove_device(&co), "device busy");
390         close(fd);
391
392         OK_(crypt_remove_device(&co));
393 }
394
395 static void LuksFormat(void)
396 {
397         struct crypt_options co = {
398                 .device = DEVICE_2,
399                 .key_size = 256 / 8,
400                 .key_slot = -1,
401                 .cipher = "aes-cbc-essiv:sha256",
402                 .hash = "sha1",
403                 .flags = 0,
404                 .iteration_time = 10,
405                 .align_payload = 0,
406                 .icb = &cmd_icb,
407         };
408
409         OK_(_prepare_keyfile(KEYFILE1, KEY1, strlen(KEY1)));
410
411         co.new_key_file = KEYFILE1;
412         co.device = DEVICE_ERROR;
413         FAIL_(crypt_luksFormat(&co), "error device");
414
415         co.device = DEVICE_2;
416         OK_(crypt_luksFormat(&co));
417
418         co.new_key_file = NULL;
419         co.key_file = KEYFILE1;
420         co.name = CDEVICE_2;
421         OK_(crypt_luksOpen(&co));
422         OK_(crypt_remove_device(&co));
423         _remove_keyfiles();
424 }
425
426 static void LuksKeyGame(void)
427 {
428         int i;
429         struct crypt_options co = {
430                 .device = DEVICE_2,
431                 .key_size = 256 / 8,
432                 .key_slot = -1,
433                 .cipher = "aes-cbc-essiv:sha256",
434                 .hash = "sha1",
435                 .flags = 0,
436                 .iteration_time = 10,
437                 .align_payload = 0,
438                 .icb = &cmd_icb,
439         };
440
441         OK_(_prepare_keyfile(KEYFILE1, KEY1, strlen(KEY1)));
442         OK_(_prepare_keyfile(KEYFILE2, KEY2, strlen(KEY2)));
443
444         co.new_key_file = KEYFILE1;
445         co.device = DEVICE_2;
446         co.key_slot = 8;
447         FAIL_(crypt_luksFormat(&co), "wrong slot #");
448
449         co.key_slot = 7; // last slot
450         OK_(crypt_luksFormat(&co));
451
452         co.new_key_file = KEYFILE1;
453         co.key_file = KEYFILE1;
454         co.key_slot = 8;
455         FAIL_(crypt_luksAddKey(&co), "wrong slot #");
456         co.key_slot = 7;
457         FAIL_(crypt_luksAddKey(&co), "slot already used");
458
459         co.key_slot = 6;
460         OK_(crypt_luksAddKey(&co));
461
462         co.key_file = KEYFILE2 "blah";
463         co.key_slot = 5;
464         FAIL_(crypt_luksAddKey(&co), "keyfile not found");
465
466         co.new_key_file = KEYFILE2; // key to add
467         co.key_file = KEYFILE1;
468         co.key_slot = -1;
469         for (i = 0; i < 6; i++)
470                 OK_(crypt_luksAddKey(&co)); //FIXME: EQ_(i)?
471
472         FAIL_(crypt_luksAddKey(&co), "all slots full");
473
474         // REMOVE KEY
475         co.new_key_file = KEYFILE1; // key to remove
476         co.key_file = NULL;
477         co.key_slot = 8; // should be ignored
478          // only 2 slots should use KEYFILE1
479         OK_(crypt_luksRemoveKey(&co));
480         OK_(crypt_luksRemoveKey(&co));
481         FAIL_(crypt_luksRemoveKey(&co), "no slot with this passphrase");
482
483         co.new_key_file = KEYFILE2 "blah";
484         co.key_file = NULL;
485         FAIL_(crypt_luksRemoveKey(&co), "keyfile not found");
486
487         // KILL SLOT
488         co.new_key_file = NULL;
489         co.key_file = NULL;
490         co.key_slot = 8;
491         FAIL_(crypt_luksKillSlot(&co), "wrong slot #");
492         co.key_slot = 7;
493         FAIL_(crypt_luksKillSlot(&co), "slot already wiped");
494
495         co.key_slot = 5;
496         OK_(crypt_luksKillSlot(&co));
497
498         _remove_keyfiles();
499 }
500
501 size_t _get_device_size(const char *device)
502 {
503         unsigned long size = 0;
504         int fd;
505
506         fd = open(device, O_RDONLY);
507         if (fd == -1)
508                 return 0;
509         (void)ioctl(fd, BLKGETSIZE, &size);
510         close(fd);
511
512         return size;
513 }
514
515 void DeviceResizeGame(void)
516 {
517         size_t orig_size;
518         struct crypt_options co = {
519                 .name = CDEVICE_2,
520                 .device = DEVICE_2,
521                 .key_size = 128 / 8,
522                 .cipher = "aes-cbc-plain",
523                 .hash = "sha1",
524                 .offset = 333,
525                 .skip = 0,
526                 .icb = &cmd_icb,
527         };
528
529         orig_size = _get_device_size(DEVICE_2);
530
531         OK_(_prepare_keyfile(KEYFILE2, KEY2, strlen(KEY2)));
532
533         co.key_file = KEYFILE2;
534         co.size = 1000;
535         OK_(crypt_create_device(&co));
536         EQ_(_get_device_size(DMDIR CDEVICE_2), 1000);
537
538         co.size = 2000;
539         OK_(crypt_resize_device(&co));
540         EQ_(_get_device_size(DMDIR CDEVICE_2), 2000);
541
542         co.size = 0;
543         OK_(crypt_resize_device(&co));
544         EQ_(_get_device_size(DMDIR CDEVICE_2), (orig_size - 333));
545         co.size = 0;
546         co.offset = 444;
547         co.skip = 555;
548         co.cipher = "aes-cbc-essiv:sha256";
549         OK_(crypt_update_device(&co));
550         EQ_(_get_device_size(DMDIR CDEVICE_2), (orig_size - 444));
551
552         memset(&co, 0, sizeof(co));
553         co.icb = &cmd_icb,
554         co.name = CDEVICE_2;
555         EQ_(crypt_query_device(&co), 1);
556         EQ_(strcmp(co.cipher, "aes-cbc-essiv:sha256"), 0);
557         EQ_(co.key_size, 128 / 8);
558         EQ_(co.offset, 444);
559         EQ_(co.skip, 555);
560         crypt_put_options(&co);
561
562         // dangerous switch device still works
563         memset(&co, 0, sizeof(co));
564         co.name = CDEVICE_2,
565         co.device = DEVICE_1;
566         co.key_file = KEYFILE2;
567         co.key_size = 128 / 8;
568         co.cipher = "aes-cbc-plain";
569         co.hash = "sha1";
570         co.icb = &cmd_icb;
571         OK_(crypt_update_device(&co));
572
573         memset(&co, 0, sizeof(co));
574         co.icb = &cmd_icb,
575         co.name = CDEVICE_2;
576         EQ_(crypt_query_device(&co), 1);
577         EQ_(strcmp(co.cipher, "aes-cbc-plain"), 0);
578         EQ_(co.key_size, 128 / 8);
579         EQ_(co.offset, 0);
580         EQ_(co.skip, 0);
581         // This expect lookup returns prefered /dev/loopX
582         EQ_(strcmp(co.device, DEVICE_1), 0);
583         crypt_put_options(&co);
584
585         memset(&co, 0, sizeof(co));
586         co.icb = &cmd_icb,
587         co.name = CDEVICE_2;
588         OK_(crypt_remove_device(&co));
589
590         _remove_keyfiles();
591 }
592 #endif
593
594 // NEW API tests
595
596 static void AddDevicePlain(void)
597 {
598         struct crypt_device *cd;
599         struct crypt_params_plain params = {
600                 .hash = "sha1",
601                 .skip = 0,
602                 .offset = 0,
603         };
604         int fd;
605         char key[128], key2[128], path[128];
606
607         char *passphrase = PASSPHRASE;
608         char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
609         size_t key_size = strlen(mk_hex) / 2;
610         char *cipher = "aes";
611         char *cipher_mode = "cbc-essiv:sha256";
612
613         crypt_decode_key(key, mk_hex, key_size);
614
615         FAIL_(crypt_init(&cd, ""), "empty device string");
616
617         // default is "plain" hash - no password hash
618         OK_(crypt_init(&cd, DEVICE_1));
619         OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, NULL));
620         FAIL_(crypt_activate_by_volume_key(cd, NULL, key, key_size, 0), "cannot verify key with plain");
621         OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
622         EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
623         // FIXME: this should get key from active device?
624         //OK_(crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key2, &key_size, passphrase, strlen(passphrase)));
625         //OK_(memcmp(key, key2, key_size));
626         OK_(crypt_deactivate(cd, CDEVICE_1));
627         crypt_free(cd);
628
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, &params));
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));
635
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");
642         close(fd);
643         OK_(crypt_deactivate(cd, CDEVICE_1));
644         EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
645
646         OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
647         EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
648
649         // retrieve volume key check
650         memset(key2, 0, key_size);
651         key_size--;
652         // small buffer
653         FAIL_(crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key2, &key_size, passphrase, strlen(passphrase)), "small buffer");
654         key_size++;
655         OK_(crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key2, &key_size, passphrase, strlen(passphrase)));
656
657         OK_(memcmp(key, key2, key_size));
658         OK_(strcmp(cipher, crypt_get_cipher(cd)));
659         OK_(strcmp(cipher_mode, crypt_get_cipher_mode(cd)));
660         EQ_(key_size, crypt_get_volume_key_size(cd));
661         EQ_(0, crypt_get_data_offset(cd));
662         OK_(crypt_deactivate(cd, CDEVICE_1));
663
664         // now with keyfile
665         OK_(_prepare_keyfile(KEYFILE1, KEY1, strlen(KEY1)));
666         FAIL_(crypt_activate_by_keyfile(cd, NULL, CRYPT_ANY_SLOT, KEYFILE1, 0, 0), "cannot verify key with plain");
667         EQ_(0, crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0, 0));
668         EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
669         OK_(crypt_deactivate(cd, CDEVICE_1));
670         _remove_keyfiles();
671
672         crypt_free(cd);
673 }
674
675 #define CALLBACK_ERROR "calback_error xyz"
676 static int pass_callback_err(const char *msg, char *buf, size_t length, void *usrptr)
677 {
678         struct crypt_device *cd = usrptr;
679
680         assert(cd);
681         assert(length);
682         assert(msg);
683
684         crypt_log(cd, CRYPT_LOG_ERROR, CALLBACK_ERROR);
685         return -EINVAL;
686 }
687
688 static int pass_callback_ok(const char *msg, char *buf, size_t length, void *usrptr)
689 {
690         assert(length);
691         assert(msg);
692         strcpy(buf, PASSPHRASE);
693         return strlen(buf);
694 }
695
696 static void CallbacksTest(void)
697 {
698         struct crypt_device *cd;
699         struct crypt_params_plain params = {
700                 .hash = "sha1",
701                 .skip = 0,
702                 .offset = 0,
703         };
704
705         size_t key_size = 256 / 8;
706         char *cipher = "aes";
707         char *cipher_mode = "cbc-essiv:sha256";
708         char *passphrase = PASSPHRASE;
709
710         OK_(crypt_init(&cd, DEVICE_1));
711         crypt_set_log_callback(cd, &new_log, NULL);
712         //crypt_set_log_callback(cd, NULL, NULL);
713
714         OK_(crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode, NULL, NULL, key_size, &params));
715
716         OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
717         EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
718         OK_(crypt_deactivate(cd, CDEVICE_1));
719
720         reset_log();
721         crypt_set_password_callback(cd, pass_callback_err, cd);
722         FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, NULL, 0, 0), "callback fails");
723         EQ_(strncmp(global_log, CALLBACK_ERROR, strlen(CALLBACK_ERROR)), 0);
724
725         crypt_set_password_callback(cd, pass_callback_ok, NULL);
726         OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, NULL, 0, 0));
727         EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
728         OK_(crypt_deactivate(cd, CDEVICE_1));
729
730         crypt_free(cd);
731 }
732
733 static void UseLuksDevice(void)
734 {
735         struct crypt_device *cd;
736         char key[128];
737         size_t key_size;
738
739         OK_(crypt_init(&cd, DEVICE_1));
740         OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
741         EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
742         OK_(crypt_activate_by_passphrase(cd, NULL, CRYPT_ANY_SLOT, KEY1, strlen(KEY1), 0));
743         OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1), 0));
744         FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1), 0), "already open");
745         EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
746         OK_(crypt_deactivate(cd, CDEVICE_1));
747         FAIL_(crypt_deactivate(cd, CDEVICE_1), "no such device");
748
749         key_size = 16;
750         OK_(strcmp("aes", crypt_get_cipher(cd)));
751         OK_(strcmp("cbc-essiv:sha256", crypt_get_cipher_mode(cd)));
752         OK_(strcmp(DEVICE_1_UUID, crypt_get_uuid(cd)));
753         EQ_(key_size, crypt_get_volume_key_size(cd));
754         EQ_(1032, crypt_get_data_offset(cd));
755
756         EQ_(0, crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key, &key_size, KEY1, strlen(KEY1)));
757         OK_(crypt_volume_key_verify(cd, key, key_size));
758         OK_(crypt_activate_by_volume_key(cd, NULL, key, key_size, 0));
759         OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
760         EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
761         OK_(crypt_deactivate(cd, CDEVICE_1));
762
763         key[1] = ~key[1];
764         FAIL_(crypt_volume_key_verify(cd, key, key_size), "key mismatch");
765         FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0), "key mismatch");
766         crypt_free(cd);
767 }
768
769 static void SuspendDevice(void)
770 {
771         int suspend_status;
772         struct crypt_device *cd;
773
774         OK_(crypt_init(&cd, DEVICE_1));
775         OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
776         OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1), 0));
777
778         suspend_status = crypt_suspend(cd, CDEVICE_1);
779         if (suspend_status == -ENOTSUP) {
780                 printf("WARNING: Suspend/Resume not supported, skipping test.\n");
781                 goto out;
782         }
783         OK_(suspend_status);
784         FAIL_(crypt_suspend(cd, CDEVICE_1), "already suspended");
785
786         FAIL_(crypt_resume_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1)-1), "wrong key");
787         OK_(crypt_resume_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1)));
788         FAIL_(crypt_resume_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1)), "not suspended");
789
790         OK_(_prepare_keyfile(KEYFILE1, KEY1, strlen(KEY1)));
791         OK_(crypt_suspend(cd, CDEVICE_1));
792         FAIL_(crypt_resume_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1 "blah", 0), "wrong keyfile");
793         OK_(crypt_resume_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0));
794         FAIL_(crypt_resume_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0), "not suspended");
795         _remove_keyfiles();
796 out:
797         OK_(crypt_deactivate(cd, CDEVICE_1));
798         crypt_free(cd);
799 }
800
801 static void AddDeviceLuks(void)
802 {
803         struct crypt_device *cd;
804         struct crypt_params_luks1 params = {
805                 .hash = "sha512",
806                 .data_alignment = 2048, // 4M, data offset will be 4096
807         };
808         char key[128], key2[128];
809
810         char *passphrase = "blabla";
811         char *mk_hex = "bb21158c733229347bd4e681891e213d94c685be6a5b84818afe7a78a6de7a1a";
812         size_t key_size = strlen(mk_hex) / 2;
813         char *cipher = "aes";
814         char *cipher_mode = "cbc-essiv:sha256";
815
816         crypt_decode_key(key, mk_hex, key_size);
817
818         OK_(crypt_init(&cd, DEVICE_2));
819         OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, &params));
820
821         // even with no keyslots defined it can be activated by volume key
822         OK_(crypt_volume_key_verify(cd, key, key_size));
823         OK_(crypt_activate_by_volume_key(cd, CDEVICE_2, key, key_size, 0));
824         EQ_(crypt_status(cd, CDEVICE_2), CRYPT_ACTIVE);
825         OK_(crypt_deactivate(cd, CDEVICE_2));
826
827         // now with keyslot
828         EQ_(7, crypt_keyslot_add_by_volume_key(cd, 7, key, key_size, passphrase, strlen(passphrase)));
829         EQ_(CRYPT_SLOT_ACTIVE_LAST, crypt_keyslot_status(cd, 7));
830         EQ_(7, crypt_activate_by_passphrase(cd, CDEVICE_2, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
831         EQ_(crypt_status(cd, CDEVICE_2), CRYPT_ACTIVE);
832         OK_(crypt_deactivate(cd, CDEVICE_2));
833
834         EQ_(1, crypt_keyslot_add_by_volume_key(cd, 1, key, key_size, KEY1, strlen(KEY1)));
835         OK_(_prepare_keyfile(KEYFILE1, KEY1, strlen(KEY1)));
836         OK_(_prepare_keyfile(KEYFILE2, KEY2, strlen(KEY2)));
837         EQ_(2, crypt_keyslot_add_by_keyfile(cd, 2, KEYFILE1, 0, KEYFILE2, 0));
838         FAIL_(crypt_activate_by_keyfile(cd, CDEVICE_2, CRYPT_ANY_SLOT, KEYFILE2, strlen(KEY2)-1, 0), "key mismatch");
839         EQ_(2, crypt_activate_by_keyfile(cd, NULL, CRYPT_ANY_SLOT, KEYFILE2, 0, 0));
840         EQ_(2, crypt_activate_by_keyfile(cd, CDEVICE_2, CRYPT_ANY_SLOT, KEYFILE2, 0, 0));
841         OK_(crypt_keyslot_destroy(cd, 1));
842         OK_(crypt_keyslot_destroy(cd, 2));
843         OK_(crypt_deactivate(cd, CDEVICE_2));
844         _remove_keyfiles();
845
846         FAIL_(crypt_keyslot_add_by_volume_key(cd, 7, key, key_size, passphrase, strlen(passphrase)), "slot used");
847         key[1] = ~key[1];
848         FAIL_(crypt_keyslot_add_by_volume_key(cd, 6, key, key_size, passphrase, strlen(passphrase)), "key mismatch");
849         key[1] = ~key[1];
850         EQ_(6, crypt_keyslot_add_by_volume_key(cd, 6, key, key_size, passphrase, strlen(passphrase)));
851         EQ_(CRYPT_SLOT_ACTIVE, crypt_keyslot_status(cd, 6));
852
853         FAIL_(crypt_keyslot_destroy(cd, 8), "invalid keyslot");
854         FAIL_(crypt_keyslot_destroy(cd, CRYPT_ANY_SLOT), "invalid keyslot");
855         FAIL_(crypt_keyslot_destroy(cd, 0), "keyslot not used");
856         OK_(crypt_keyslot_destroy(cd, 7));
857         EQ_(CRYPT_SLOT_INACTIVE, crypt_keyslot_status(cd, 7));
858         EQ_(CRYPT_SLOT_ACTIVE_LAST, crypt_keyslot_status(cd, 6));
859
860         EQ_(6, crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key2, &key_size, passphrase, strlen(passphrase)));
861         OK_(crypt_volume_key_verify(cd, key2, key_size));
862
863         OK_(memcmp(key, key2, key_size));
864         OK_(strcmp(cipher, crypt_get_cipher(cd)));
865         OK_(strcmp(cipher_mode, crypt_get_cipher_mode(cd)));
866         EQ_(key_size, crypt_get_volume_key_size(cd));
867         EQ_(4096, crypt_get_data_offset(cd));
868         OK_(strcmp(DEVICE_2, crypt_get_device_name(cd)));
869
870         reset_log();
871         crypt_set_log_callback(cd, &new_log, NULL);
872         OK_(crypt_dump(cd));
873         OK_(!(global_lines != 0));
874         crypt_set_log_callback(cd, NULL, NULL);
875         reset_log();
876
877         FAIL_(crypt_set_uuid(cd, "blah"), "wrong UUID format");
878         OK_(crypt_set_uuid(cd, DEVICE_TEST_UUID));
879         OK_(strcmp(DEVICE_TEST_UUID, crypt_get_uuid(cd)));
880
881         FAIL_(crypt_deactivate(cd, CDEVICE_2), "not active");
882         crypt_free(cd);
883 }
884
885 static void UseTempVolumes(void)
886 {
887         struct crypt_device *cd;
888         char tmp[256];
889
890         // Tepmporary device without keyslot but with on-disk LUKS header
891         OK_(crypt_init(&cd, DEVICE_2));
892         FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, NULL, 0, 0), "not yet formatted");
893         OK_(crypt_format(cd, CRYPT_LUKS1, "aes", "cbc-essiv:sha256", NULL, NULL, 16, NULL));
894         OK_(crypt_activate_by_volume_key(cd, CDEVICE_2, NULL, 0, 0));
895         EQ_(crypt_status(cd, CDEVICE_2), CRYPT_ACTIVE);
896         crypt_free(cd);
897
898         OK_(crypt_init_by_name(&cd, CDEVICE_2));
899         OK_(crypt_deactivate(cd, CDEVICE_2));
900         crypt_free(cd);
901
902         // Dirty checks: device without UUID
903         // we should be able to remove it but not manuipulate with it
904         snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
905                 "0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
906                 "%s 2048\"", CDEVICE_2, DEVICE_2);
907         _system(tmp, 1);
908         OK_(crypt_init_by_name(&cd, CDEVICE_2));
909         OK_(crypt_deactivate(cd, CDEVICE_2));
910         FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, NULL, 0, 0), "No known device type");
911         crypt_free(cd);
912
913         // Dirty checks: device with UUID but LUKS header key fingerprint must fail)
914         snprintf(tmp, sizeof(tmp), "dmsetup create %s --table \""
915                 "0 100 crypt aes-cbc-essiv:sha256 deadbabedeadbabedeadbabedeadbabe 0 "
916                 "%s 2048\" -u CRYPT-LUKS1-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-ctest1",
917                  CDEVICE_2, DEVICE_2);
918         _system(tmp, 1);
919         OK_(crypt_init_by_name(&cd, CDEVICE_2));
920         OK_(crypt_deactivate(cd, CDEVICE_2));
921         FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, NULL, 0, 0), "wrong volume key");
922         crypt_free(cd);
923
924         // No slots
925         OK_(crypt_init(&cd, DEVICE_2));
926         OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
927         FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, NULL, 0, 0), "volume key is lost");
928         crypt_free(cd);
929
930         // Plain device
931         OK_(crypt_init(&cd, DEVICE_2));
932         OK_(crypt_format(cd, CRYPT_PLAIN, "aes", "cbc-essiv:sha256", NULL, NULL, 16, NULL));
933         FAIL_(crypt_activate_by_volume_key(cd, NULL, "xxx", 3, 0), "cannot verify key with plain");
934         FAIL_(crypt_volume_key_verify(cd, "xxx", 3), "cannot verify key with plain");
935         FAIL_(crypt_activate_by_volume_key(cd, CDEVICE_2, "xxx", 3, 0), "wrong key lenght");
936         OK_(crypt_activate_by_volume_key(cd, CDEVICE_2, "volumekeyvolumek", 16, 0));
937         EQ_(crypt_status(cd, CDEVICE_2), CRYPT_ACTIVE);
938         OK_(crypt_deactivate(cd, CDEVICE_2));
939         crypt_free(cd);
940 }
941
942 static void HashDevicePlain(void)
943 {
944         struct crypt_device *cd;
945         struct crypt_params_plain params = {
946                 .hash = NULL,
947                 .skip = 0,
948                 .offset = 0,
949         };
950
951         size_t key_size;
952         char *mk_hex, *keystr, key[256];
953
954         OK_(crypt_init(&cd, DEVICE_1));
955         OK_(crypt_format(cd, CRYPT_PLAIN, "aes", "cbc-essiv:sha256", NULL, NULL, 16, &params));
956
957         // hash PLAIN, short key
958         OK_(_prepare_keyfile(KEYFILE1, "tooshort", 8));
959         FAIL_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 16, 0), "not enough data in keyfile");
960         _remove_keyfiles();
961
962         // hash PLAIN, exact key
963         //         0 1 2 3 4 5 6 7 8 9 a b c d e f
964         mk_hex = "caffeecaffeecaffeecaffeecaffee88";
965         key_size = 16;
966         crypt_decode_key(key, mk_hex, key_size);
967         OK_(_prepare_keyfile(KEYFILE1, key, key_size));
968         OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, key_size, 0));
969         OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
970         OK_(strcmp(key, mk_hex));
971         OK_(crypt_deactivate(cd, CDEVICE_1));
972
973         // Limit plain key
974         mk_hex = "caffeecaffeecaffeecaffeeca000000";
975         OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, key_size - 3, 0));
976         OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
977         OK_(strcmp(key, mk_hex));
978         OK_(crypt_deactivate(cd, CDEVICE_1));
979
980         _remove_keyfiles();
981
982         // hash PLAIN, long key
983         //         0 1 2 3 4 5 6 7 8 9 a b c d e f
984         mk_hex = "caffeecaffeecaffeecaffeecaffee88babebabe";
985         key_size = 16;
986         crypt_decode_key(key, mk_hex, key_size);
987         OK_(_prepare_keyfile(KEYFILE1, key, strlen(mk_hex) / 2));
988         OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, key_size, 0));
989         OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
990         FAIL_(strcmp(key, mk_hex), "only key length used");
991         OK_(strncmp(key, mk_hex, key_size));
992         OK_(crypt_deactivate(cd, CDEVICE_1));
993
994         // Now without explicit limit
995         OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0, 0));
996         OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
997         FAIL_(strcmp(key, mk_hex), "only key length used");
998         OK_(strncmp(key, mk_hex, key_size));
999         OK_(crypt_deactivate(cd, CDEVICE_1));
1000
1001         _remove_keyfiles();
1002
1003         // hash sha256
1004         params.hash = "sha256";
1005         OK_(crypt_format(cd, CRYPT_PLAIN, "aes", "cbc-essiv:sha256", NULL, NULL, 16, &params));
1006
1007         //         0 1 2 3 4 5 6 7 8 9 a b c d e f
1008         mk_hex = "c62e4615bd39e222572f3a1bf7c2132e";
1009         keystr = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
1010         key_size = strlen(keystr); // 32
1011         OK_(_prepare_keyfile(KEYFILE1, keystr, strlen(keystr)));
1012         OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, key_size, 0));
1013         OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1014         OK_(strcmp(key, mk_hex));
1015         OK_(crypt_deactivate(cd, CDEVICE_1));
1016
1017         // Read full keyfile
1018         OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0, 0));
1019         OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1020         OK_(strcmp(key, mk_hex));
1021         OK_(crypt_deactivate(cd, CDEVICE_1));
1022
1023         _remove_keyfiles();
1024
1025         // Limit keyfile read
1026         keystr = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxAAAAAAAA";
1027         OK_(_prepare_keyfile(KEYFILE1, keystr, strlen(keystr)));
1028         OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, key_size, 0));
1029         OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1030         OK_(strcmp(key, mk_hex));
1031         OK_(crypt_deactivate(cd, CDEVICE_1));
1032
1033         // Full keyfile
1034         OK_(crypt_activate_by_keyfile(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEYFILE1, 0, 0));
1035         OK_(_get_key_dm(CDEVICE_1, key, sizeof(key)));
1036         OK_(strcmp(key, "0e49cb34a1dee1df33f6505e4de44a66"));
1037         OK_(crypt_deactivate(cd, CDEVICE_1));
1038
1039         _remove_keyfiles();
1040
1041         // FIXME: add keyfile="-" tests somehow
1042
1043         crypt_free(cd);
1044 }
1045
1046 // Check that gcrypt is properly initialised in format
1047 static void NonFIPSAlg(void)
1048 {
1049         struct crypt_device *cd;
1050         struct crypt_params_luks1 params = {0};
1051         char key[128] = "";
1052         size_t key_size = 128;
1053         char *cipher = "aes";
1054         char *cipher_mode = "cbc-essiv:sha256";
1055         int ret;
1056
1057         OK_(crypt_init(&cd, DEVICE_2));
1058         params.hash = "sha256";
1059         OK_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, &params));
1060
1061         params.hash = "whirlpool";
1062         ret = crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, &params);
1063         if (ret < 0) {
1064                 printf("WARNING: whirlpool not supported, skipping test.\n");
1065                 crypt_free(cd);
1066                 return;
1067         }
1068
1069         params.hash = "md5";
1070         FAIL_(crypt_format(cd, CRYPT_LUKS1, cipher, cipher_mode, NULL, key, key_size, &params),
1071               "MD5 unsupported, too short");
1072         crypt_free(cd);
1073 }
1074
1075 int main (int argc, char *argv[])
1076 {
1077         int i;
1078
1079         if (getuid() != 0) {
1080                 printf("You must be root to run this test.\n");
1081                 exit(0);
1082         }
1083
1084         for (i = 1; i < argc; i++) {
1085                 if (!strcmp("-v", argv[i]) || !strcmp("--verbose", argv[i]))
1086                         _verbose = 1;
1087                 else if (!strcmp("--debug", argv[i]))
1088                         _debug = _verbose = 1;
1089         }
1090
1091         _cleanup();
1092         if (_setup())
1093                 goto out;
1094
1095         crypt_set_debug_level(_debug ? CRYPT_DEBUG_ALL : CRYPT_DEBUG_NONE);
1096
1097         RUN_(NonFIPSAlg, "Crypto is properly initialised in format"); //must be the first!
1098 #if 0
1099         RUN_(LuksUUID, "luksUUID API call");
1100         RUN_(IsLuks, "isLuks API call");
1101         RUN_(LuksOpen, "luksOpen API call");
1102         RUN_(query_device, "crypt_query_device API call");
1103         RUN_(remove_device, "crypt_remove_device API call");
1104         RUN_(LuksFormat, "luksFormat API call");
1105         RUN_(LuksKeyGame, "luksAddKey, RemoveKey, KillSlot API calls");
1106         RUN_(DeviceResizeGame, "regular crypto, resize calls");
1107 #endif
1108         RUN_(AddDevicePlain, "plain device API creation exercise");
1109         RUN_(HashDevicePlain, "plain device API hash test");
1110         RUN_(AddDeviceLuks, "Format and use LUKS device");
1111         RUN_(UseLuksDevice, "Use pre-formated LUKS device");
1112         RUN_(SuspendDevice, "Suspend/Resume test");
1113         RUN_(UseTempVolumes, "Format and use temporary encrypted device");
1114
1115         RUN_(CallbacksTest, "API callbacks test");
1116 out:
1117         _cleanup();
1118         return 0;
1119 }