2 * libcryptsetup - cryptsetup library
4 * Copyright (C) 2004, Christophe Saout <christophe@saout.de>
5 * Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
6 * Copyright (C) 2009-2011, Red Hat, Inc. All rights reserved.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "libcryptsetup.h"
33 #include "crypto_backend.h"
39 char *metadata_device;
43 struct volume_key *volume_key;
45 uint64_t iteration_time;
50 /* used in CRYPT_LUKS1 */
52 uint64_t PBKDF2_per_sec;
54 /* used in CRYPT_PLAIN */
55 struct crypt_params_plain plain_hdr;
57 char *plain_cipher_mode;
60 /* used in CRYPT_LOOPAES */
61 struct crypt_params_loopaes loopaes_hdr;
63 char *loopaes_cipher_mode;
65 unsigned int loopaes_key_size;
67 /* callbacks definitions */
68 void (*log)(int level, const char *msg, void *usrptr);
70 int (*confirm)(const char *msg, void *usrptr);
72 int (*password)(const char *msg, char *buf, size_t length, void *usrptr);
73 void *password_usrptr;
77 static void (*_default_log)(int level, const char *msg, void *usrptr) = NULL;
78 static int _debug_level = 0;
80 void crypt_set_debug_level(int level)
85 int crypt_get_debug_level(void)
90 void crypt_log(struct crypt_device *cd, int level, const char *msg)
93 cd->log(level, msg, cd->log_usrptr);
94 else if (_default_log)
95 _default_log(level, msg, NULL);
98 __attribute__((format(printf, 5, 6)))
99 void logger(struct crypt_device *cd, int level, const char *file,
100 int line, const char *format, ...)
105 va_start(argp, format);
107 if (vasprintf(&target, format, argp) > 0) {
109 crypt_log(cd, level, target);
111 } else if (_debug_level)
112 printf("# %s:%d %s\n", file ?: "?", line, target);
114 } else if (_debug_level)
115 printf("# %s\n", target);
123 static const char *mdata_device(struct crypt_device *cd)
125 return cd->metadata_device ?: cd->device;
128 static int init_crypto(struct crypt_device *ctx)
132 r = crypt_random_init(ctx);
134 log_err(ctx, _("Cannot initialize crypto RNG backend.\n"));
138 r = crypt_backend_init(ctx);
140 log_err(ctx, _("Cannot initialize crypto backend.\n"));
145 static int process_key(struct crypt_device *cd, const char *hash_name,
146 size_t key_size, const char *pass, size_t passLen,
147 struct volume_key **vk)
154 *vk = crypt_alloc_volume_key(key_size, NULL);
159 r = crypt_plain_hash(cd, hash_name, (*vk)->key, key_size, pass, passLen);
162 log_err(cd, _("Hash algorithm %s not supported.\n"),
165 log_err(cd, _("Key processing error (using hash %s).\n"),
167 crypt_free_volume_key(*vk);
171 } else if (passLen > key_size) {
172 memcpy((*vk)->key, pass, key_size);
174 memcpy((*vk)->key, pass, passLen);
180 static int isPLAIN(const char *type)
182 return (type && !strcmp(CRYPT_PLAIN, type));
185 static int isLUKS(const char *type)
187 return (type && !strcmp(CRYPT_LUKS1, type));
190 static int isLOOPAES(const char *type)
192 return (type && !strcmp(CRYPT_LOOPAES, type));
195 /* keyslot helpers */
196 static int keyslot_verify_or_find_empty(struct crypt_device *cd, int *keyslot)
198 if (*keyslot == CRYPT_ANY_SLOT) {
199 *keyslot = LUKS_keyslot_find_empty(&cd->hdr);
201 log_err(cd, _("All key slots full.\n"));
206 switch (LUKS_keyslot_info(&cd->hdr, *keyslot)) {
207 case CRYPT_SLOT_INVALID:
208 log_err(cd, _("Key slot %d is invalid, please select between 0 and %d.\n"),
209 *keyslot, LUKS_NUMKEYS - 1);
211 case CRYPT_SLOT_INACTIVE:
214 log_err(cd, _("Key slot %d is full, please select another one.\n"),
223 * compares UUIDs returned by device-mapper (striped by cryptsetup) and uuid in header
225 static int crypt_uuid_cmp(const char *dm_uuid, const char *hdr_uuid)
230 if (!dm_uuid || !hdr_uuid)
233 str = strchr(dm_uuid, '-');
237 for (i = 0, j = 1; hdr_uuid[i]; i++) {
238 if (hdr_uuid[i] == '-')
241 if (!str[j] || str[j] == '-')
244 if (str[j] != hdr_uuid[i])
252 int PLAIN_activate(struct crypt_device *cd,
254 struct volume_key *vk,
259 char *dm_cipher = NULL;
260 struct crypt_dm_active_device dmd = {
261 .device = crypt_get_device_name(cd),
263 .uuid = crypt_get_uuid(cd),
265 .offset = crypt_get_data_offset(cd),
266 .iv_offset = crypt_get_iv_offset(cd),
271 r = device_check_and_adjust(cd, dmd.device,
272 (dmd.flags & CRYPT_ACTIVATE_SHARED) ? DEV_SHARED : DEV_EXCL,
273 &dmd.size, &dmd.offset, &flags);
277 if (crypt_get_cipher_mode(cd))
278 r = asprintf(&dm_cipher, "%s-%s", crypt_get_cipher(cd), crypt_get_cipher_mode(cd));
280 r = asprintf(&dm_cipher, "%s", crypt_get_cipher(cd));
284 dmd.cipher = dm_cipher;
285 log_dbg("Trying to activate PLAIN device %s using cipher %s.", name, dmd.cipher);
287 r = dm_create_device(name, CRYPT_PLAIN, &dmd, 0);
290 if (!cd->plain_uuid && dm_query_device(name, DM_ACTIVE_UUID, &dmd) >= 0)
291 cd->plain_uuid = CONST_CAST(char*)dmd.uuid;
297 int crypt_confirm(struct crypt_device *cd, const char *msg)
299 if (!cd || !cd->confirm)
302 return cd->confirm(msg, cd->confirm_usrptr);
305 static int key_from_terminal(struct crypt_device *cd, char *msg, char **key,
306 size_t *key_len, int force_verify)
312 if(!msg && asprintf(&prompt, _("Enter passphrase for %s: "),
313 cd->backing_file ?: crypt_get_device_name(cd)) < 0)
320 *key = crypt_safe_alloc(DEFAULT_PASSPHRASE_SIZE_MAX);
325 r = cd->password(msg, *key, DEFAULT_PASSPHRASE_SIZE_MAX,
326 cd->password_usrptr);
328 crypt_safe_free(*key);
333 r = crypt_get_key(msg, key, key_len, 0, NULL, cd->timeout,
334 (force_verify || cd->password_verify), cd);
337 return (r < 0) ? r: 0;
340 static int volume_key_by_terminal_passphrase(struct crypt_device *cd, int keyslot,
341 struct volume_key **vk)
343 char *passphrase_read = NULL;
344 size_t passphrase_size_read;
345 int r = -EINVAL, eperm = 0, tries = cd->tries;
349 crypt_free_volume_key(*vk);
352 r = key_from_terminal(cd, NULL, &passphrase_read,
353 &passphrase_size_read, 0);
357 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase_read,
358 passphrase_size_read, &cd->hdr, vk, cd);
361 crypt_safe_free(passphrase_read);
362 passphrase_read = NULL;
363 } while (r == -EPERM && (--tries > 0));
366 crypt_free_volume_key(*vk);
369 /* Report wrong passphrase if at least one try failed */
370 if (eperm && r == -EPIPE)
374 crypt_safe_free(passphrase_read);
378 static int key_from_file(struct crypt_device *cd, char *msg,
379 char **key, size_t *key_len,
380 const char *key_file, size_t key_size)
382 return crypt_get_key(msg, key, key_len, key_size, key_file,
386 void crypt_set_log_callback(struct crypt_device *cd,
387 void (*log)(int level, const char *msg, void *usrptr),
394 cd->log_usrptr = usrptr;
398 void crypt_set_confirm_callback(struct crypt_device *cd,
399 int (*confirm)(const char *msg, void *usrptr),
402 cd->confirm = confirm;
403 cd->confirm_usrptr = usrptr;
406 void crypt_set_password_callback(struct crypt_device *cd,
407 int (*password)(const char *msg, char *buf, size_t length, void *usrptr),
410 cd->password = password;
411 cd->password_usrptr = usrptr;
414 void crypt_get_error(char *buf, size_t size)
416 const char *error = get_error();
418 if (!buf || size < 1)
421 strncpy(buf, error, size - 1);
422 buf[size - 1] = '\0';
428 const char *crypt_get_dir(void)
433 int crypt_init(struct crypt_device **cd, const char *device)
435 struct crypt_device *h = NULL;
441 log_dbg("Allocating crypt device %s context.", device);
443 if (!(h = malloc(sizeof(struct crypt_device))))
446 memset(h, 0, sizeof(*h));
450 r = device_ready(NULL, device, O_RDONLY);
452 h->device = crypt_loop_get_device();
453 log_dbg("Not a block device, %s%s.",
454 h->device ? "using free loop device " :
455 "no free loop device found",
458 log_err(NULL, _("Cannot find a free loopback device.\n"));
463 /* Keep the loop open, dettached on last close. */
464 h->loop_fd = crypt_loop_attach(h->device, device, 0, 1, &readonly);
465 if (h->loop_fd == -1) {
466 log_err(NULL, _("Attaching loopback device failed "
467 "(loop device with autoclear flag is required).\n"));
472 h->backing_file = crypt_loop_backing_file(h->device);
473 r = device_ready(NULL, h->device, O_RDONLY);
481 if (!h->device && device && !(h->device = strdup(device))) {
486 if (dm_init(h, 1) < 0) {
491 h->iteration_time = 1000;
492 h->password_verify = 0;
494 h->rng_type = crypt_random_default_key_rng();
500 if (h->loop_fd != -1)
503 free(h->backing_file);
509 static int crypt_check_data_device_size(struct crypt_device *cd)
512 uint64_t size, size_min;
514 /* Check data device size, require at least one sector */
515 size_min = crypt_get_data_offset(cd) << SECTOR_SHIFT ?: SECTOR_SIZE;
517 r = device_size(crypt_get_device_name(cd), &size);
521 if (size < size_min) {
522 log_err(cd, _("LUKS header detected but device %s is too small.\n"),
523 crypt_get_device_name(cd));
530 int crypt_set_data_device(struct crypt_device *cd, const char *device)
535 log_dbg("Setting ciphertext data device to %s.", device ?: "(none)");
537 if (!isLUKS(cd->type)) {
538 log_err(cd, _("This operation is not supported for this device type.\n"));
542 /* metadata device must be set */
546 r = device_ready(NULL, device, O_RDONLY);
550 if (!(data_device = strdup(device)))
553 if (!cd->metadata_device)
554 cd->metadata_device = cd->device;
558 cd->device = data_device;
560 return crypt_check_data_device_size(cd);
563 int crypt_init_by_name_and_header(struct crypt_device **cd,
565 const char *header_device)
567 crypt_status_info ci;
568 struct crypt_dm_active_device dmd;
569 char cipher[MAX_CIPHER_LEN], cipher_mode[MAX_CIPHER_LEN];
573 log_dbg("Allocating crypt device context by device %s.", name);
575 ci = crypt_status(NULL, name);
576 if (ci == CRYPT_INVALID)
579 if (ci < CRYPT_ACTIVE) {
580 log_err(NULL, _("Device %s is not active.\n"), name);
584 r = dm_query_device(name, DM_ACTIVE_DEVICE | DM_ACTIVE_CIPHER |
585 DM_ACTIVE_UUID | DM_ACTIVE_KEYSIZE, &dmd);
592 r = crypt_init(cd, header_device);
594 r = crypt_init(cd, dmd.device);
596 /* Underlying device disappeared but mapping still active */
597 if (!dmd.device || r == -ENOTBLK)
598 log_verbose(NULL, _("Underlying device for crypt device %s disappeared.\n"),
601 /* Underlying device is not readable but crypt mapping exists */
603 free(CONST_CAST(void*)dmd.device);
605 r = crypt_init(cd, NULL);
613 if (!strncmp(CRYPT_PLAIN, dmd.uuid, sizeof(CRYPT_PLAIN)-1))
614 (*cd)->type = strdup(CRYPT_PLAIN);
615 else if (!strncmp(CRYPT_LOOPAES, dmd.uuid, sizeof(CRYPT_LOOPAES)-1))
616 (*cd)->type = strdup(CRYPT_LOOPAES);
617 else if (!strncmp(CRYPT_LUKS1, dmd.uuid, sizeof(CRYPT_LUKS1)-1))
618 (*cd)->type = strdup(CRYPT_LUKS1);
620 log_dbg("Unknown UUID set, some parameters are not set.");
622 log_dbg("Active device has no UUID set, some parameters are not set.");
625 r = crypt_set_data_device(*cd, dmd.device);
630 /* Try to initialise basic parameters from active device */
632 if (!(*cd)->backing_file && dmd.device && crypt_loop_device(dmd.device) &&
633 !((*cd)->backing_file = crypt_loop_backing_file(dmd.device))) {
638 if (isPLAIN((*cd)->type)) {
639 (*cd)->plain_uuid = strdup(dmd.uuid);
640 (*cd)->plain_hdr.hash = NULL; /* no way to get this */
641 (*cd)->plain_hdr.offset = dmd.offset;
642 (*cd)->plain_hdr.skip = dmd.iv_offset;
644 r = crypt_parse_name_and_mode(dmd.cipher, cipher, NULL, cipher_mode);
646 (*cd)->plain_cipher = strdup(cipher);
647 (*cd)->plain_cipher_mode = strdup(cipher_mode);
649 } else if (isLOOPAES((*cd)->type)) {
650 (*cd)->loopaes_uuid = strdup(dmd.uuid);
651 (*cd)->loopaes_hdr.offset = dmd.offset;
653 r = crypt_parse_name_and_mode(dmd.cipher, cipher,
654 &key_nums, cipher_mode);
656 (*cd)->loopaes_cipher = strdup(cipher);
657 (*cd)->loopaes_cipher_mode = strdup(cipher_mode);
658 /* version 3 uses last key for IV */
659 if (dmd.vk->keylength % key_nums)
661 (*cd)->loopaes_key_size = dmd.vk->keylength / key_nums;
663 } else if (isLUKS((*cd)->type)) {
664 if (mdata_device(*cd)) {
665 r = crypt_load(*cd, CRYPT_LUKS1, NULL);
667 log_dbg("LUKS device header does not match active device.");
673 /* checks whether UUIDs match each other */
674 r = crypt_uuid_cmp(dmd.uuid, (*cd)->hdr.uuid);
676 log_dbg("LUKS device header uuid: %s mismatches DM returned uuid %s",
677 (*cd)->hdr.uuid, dmd.uuid);
691 crypt_free_volume_key(dmd.vk);
692 free(CONST_CAST(void*)dmd.device);
693 free(CONST_CAST(void*)dmd.cipher);
694 free(CONST_CAST(void*)dmd.uuid);
698 int crypt_init_by_name(struct crypt_device **cd, const char *name)
700 return crypt_init_by_name_and_header(cd, name, NULL);
703 static int _crypt_format_plain(struct crypt_device *cd,
705 const char *cipher_mode,
707 size_t volume_key_size,
708 struct crypt_params_plain *params)
710 if (!cipher || !cipher_mode) {
711 log_err(cd, _("Invalid plain crypt parameters.\n"));
715 if (volume_key_size > 1024) {
716 log_err(cd, _("Invalid key size.\n"));
720 cd->volume_key = crypt_alloc_volume_key(volume_key_size, NULL);
724 cd->plain_cipher = strdup(cipher);
725 cd->plain_cipher_mode = strdup(cipher_mode);
728 cd->plain_uuid = strdup(uuid);
730 if (params && params->hash)
731 cd->plain_hdr.hash = strdup(params->hash);
733 cd->plain_hdr.offset = params ? params->offset : 0;
734 cd->plain_hdr.skip = params ? params->skip : 0;
735 cd->plain_hdr.size = params ? params->size : 0;
737 if (!cd->plain_cipher || !cd->plain_cipher_mode)
743 static int _crypt_format_luks1(struct crypt_device *cd,
745 const char *cipher_mode,
747 const char *volume_key,
748 size_t volume_key_size,
749 struct crypt_params_luks1 *params)
752 unsigned long required_alignment = DEFAULT_DISK_ALIGNMENT;
753 unsigned long alignment_offset = 0;
755 if (!mdata_device(cd)) {
756 log_err(cd, _("Can't format LUKS without device.\n"));
761 cd->volume_key = crypt_alloc_volume_key(volume_key_size,
764 cd->volume_key = crypt_generate_volume_key(cd, volume_key_size);
769 if (params && params->data_device) {
770 cd->metadata_device = cd->device;
771 if (!(cd->device = strdup(params->data_device)))
773 required_alignment = params->data_alignment * SECTOR_SIZE;
774 } else if (params && params->data_alignment) {
775 required_alignment = params->data_alignment * SECTOR_SIZE;
777 get_topology_alignment(cd->device, &required_alignment,
778 &alignment_offset, DEFAULT_DISK_ALIGNMENT);
780 r = LUKS_generate_phdr(&cd->hdr, cd->volume_key, cipher, cipher_mode,
781 (params && params->hash) ? params->hash : "sha1",
783 required_alignment / SECTOR_SIZE,
784 alignment_offset / SECTOR_SIZE,
785 cd->iteration_time, &cd->PBKDF2_per_sec,
786 cd->metadata_device, cd);
790 /* Wipe first 8 sectors - fs magic numbers etc. */
791 r = wipe_device_header(mdata_device(cd), 8);
794 log_err(cd, _("Cannot format device %s which is still in use.\n"),
797 log_err(cd, _("Cannot wipe header on device %s.\n"),
803 r = LUKS_write_phdr(mdata_device(cd), &cd->hdr, cd);
808 static int _crypt_format_loopaes(struct crypt_device *cd,
811 size_t volume_key_size,
812 struct crypt_params_loopaes *params)
814 if (!mdata_device(cd)) {
815 log_err(cd, _("Can't format LOOPAES without device.\n"));
819 if (volume_key_size > 1024) {
820 log_err(cd, _("Invalid key size.\n"));
824 cd->loopaes_key_size = volume_key_size;
826 cd->loopaes_cipher = strdup(cipher ?: DEFAULT_LOOPAES_CIPHER);
829 cd->loopaes_uuid = strdup(uuid);
831 if (params && params->hash)
832 cd->loopaes_hdr.hash = strdup(params->hash);
834 cd->loopaes_hdr.offset = params ? params->offset : 0;
835 cd->loopaes_hdr.skip = params ? params->skip : 0;
840 int crypt_format(struct crypt_device *cd,
843 const char *cipher_mode,
845 const char *volume_key,
846 size_t volume_key_size,
854 log_dbg("Formatting device %s as type %s.", mdata_device(cd) ?: "(none)", type);
861 r = _crypt_format_plain(cd, cipher, cipher_mode,
862 uuid, volume_key_size, params);
863 else if (isLUKS(type))
864 r = _crypt_format_luks1(cd, cipher, cipher_mode,
865 uuid, volume_key, volume_key_size, params);
866 else if (isLOOPAES(type))
867 r = _crypt_format_loopaes(cd, cipher, uuid, volume_key_size, params);
869 /* FIXME: allow plugins here? */
870 log_err(cd, _("Unknown crypt device type %s requested.\n"), type);
874 if (!r && !(cd->type = strdup(type)))
878 crypt_free_volume_key(cd->volume_key);
879 cd->volume_key = NULL;
885 int crypt_load(struct crypt_device *cd,
886 const char *requested_type,
887 void *params __attribute__((unused)))
889 struct luks_phdr hdr;
892 log_dbg("Trying to load %s crypt type from device %s.",
893 requested_type ?: "any", mdata_device(cd) ?: "(none)");
895 if (!mdata_device(cd))
898 if (requested_type && !isLUKS(requested_type))
901 if (cd->type && !isLUKS(cd->type)) {
902 log_dbg("Context is already initialised to type %s", cd->type);
910 r = LUKS_read_phdr(mdata_device(cd), &hdr, 1, cd);
914 if (!cd->type && !(cd->type = strdup(CRYPT_LUKS1)))
917 memcpy(&cd->hdr, &hdr, sizeof(hdr));
919 /* cd->type and header must be set in context */
920 r = crypt_check_data_device_size(cd);
929 int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size)
931 struct crypt_dm_active_device dmd;
934 /* Device context type must be initialised */
935 if (!cd->type || !crypt_get_uuid(cd))
938 log_dbg("Resizing device %s to %" PRIu64 " sectors.", name, new_size);
940 r = dm_query_device(name, DM_ACTIVE_DEVICE | DM_ACTIVE_CIPHER |
941 DM_ACTIVE_UUID | DM_ACTIVE_KEYSIZE |
942 DM_ACTIVE_KEY, &dmd);
944 log_err(NULL, _("Device %s is not active.\n"), name);
953 r = device_check_and_adjust(cd, dmd.device, DEV_OK, &new_size, &dmd.offset, &dmd.flags);
957 if (new_size == dmd.size) {
958 log_dbg("Device has already requested size %" PRIu64
959 " sectors.", dmd.size);
963 r = dm_create_device(name, cd->type, &dmd, 1);
966 crypt_free_volume_key(dmd.vk);
967 free(CONST_CAST(void*)dmd.cipher);
968 free(CONST_CAST(void*)dmd.device);
969 free(CONST_CAST(void*)dmd.uuid);
974 int crypt_set_uuid(struct crypt_device *cd, const char *uuid)
976 if (!isLUKS(cd->type)) {
977 log_err(cd, _("This operation is not supported for this device type.\n"));
981 if (uuid && !strncmp(uuid, cd->hdr.uuid, sizeof(cd->hdr.uuid))) {
982 log_dbg("UUID is the same as requested (%s) for device %s.",
983 uuid, mdata_device(cd));
988 log_dbg("Requested new UUID change to %s for %s.", uuid, mdata_device(cd));
990 log_dbg("Requested new UUID refresh for %s.", mdata_device(cd));
992 if (!crypt_confirm(cd, _("Do you really want to change UUID of device?")))
995 return LUKS_hdr_uuid_set(mdata_device(cd), &cd->hdr, uuid, cd);
998 int crypt_header_backup(struct crypt_device *cd,
999 const char *requested_type,
1000 const char *backup_file)
1004 if ((requested_type && !isLUKS(requested_type)) || !backup_file)
1007 r = init_crypto(cd);
1011 log_dbg("Requested header backup of device %s (%s) to "
1012 "file %s.", mdata_device(cd), requested_type, backup_file);
1014 return LUKS_hdr_backup(backup_file, mdata_device(cd), &cd->hdr, cd);
1017 int crypt_header_restore(struct crypt_device *cd,
1018 const char *requested_type,
1019 const char *backup_file)
1023 if (requested_type && !isLUKS(requested_type))
1026 /* Some hash functions need initialized gcrypt library */
1027 r = init_crypto(cd);
1031 log_dbg("Requested header restore to device %s (%s) from "
1032 "file %s.", mdata_device(cd), requested_type, backup_file);
1034 return LUKS_hdr_restore(backup_file, mdata_device(cd), &cd->hdr, cd);
1037 void crypt_free(struct crypt_device *cd)
1040 log_dbg("Releasing crypt device %s context.", mdata_device(cd));
1042 if (cd->loop_fd != -1)
1046 crypt_free_volume_key(cd->volume_key);
1049 free(cd->metadata_device);
1050 free(cd->backing_file);
1053 /* used in plain device only */
1054 free(CONST_CAST(void*)cd->plain_hdr.hash);
1055 free(cd->plain_cipher);
1056 free(cd->plain_cipher_mode);
1057 free(cd->plain_uuid);
1059 /* used in loop-AES device only */
1060 free(CONST_CAST(void*)cd->loopaes_hdr.hash);
1061 free(cd->loopaes_cipher);
1062 free(cd->loopaes_uuid);
1068 int crypt_suspend(struct crypt_device *cd,
1071 crypt_status_info ci;
1074 log_dbg("Suspending volume %s.", name);
1076 if (!isLUKS(cd->type)) {
1077 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1082 ci = crypt_status(NULL, name);
1083 if (ci < CRYPT_ACTIVE) {
1084 log_err(cd, _("Volume %s is not active.\n"), name);
1088 if (!cd && dm_init(NULL, 1) < 0)
1091 r = dm_status_suspended(name);
1096 log_err(cd, _("Volume %s is already suspended.\n"), name);
1101 r = dm_suspend_and_wipe_key(name);
1103 log_err(cd, "Suspend is not supported for device %s.\n", name);
1105 log_err(cd, "Error during suspending device %s.\n", name);
1112 int crypt_resume_by_passphrase(struct crypt_device *cd,
1115 const char *passphrase,
1116 size_t passphrase_size)
1118 struct volume_key *vk = NULL;
1121 log_dbg("Resuming volume %s.", name);
1123 if (!isLUKS(cd->type)) {
1124 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1129 r = dm_status_suspended(name);
1134 log_err(cd, _("Volume %s is not suspended.\n"), name);
1139 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase,
1140 passphrase_size, &cd->hdr, &vk, cd);
1142 r = volume_key_by_terminal_passphrase(cd, keyslot, &vk);
1146 r = dm_resume_and_reinstate_key(name, vk->keylength, vk->key);
1148 log_err(cd, "Resume is not supported for device %s.\n", name);
1150 log_err(cd, "Error during resuming device %s.\n", name);
1154 crypt_free_volume_key(vk);
1155 return r < 0 ? r : keyslot;
1158 int crypt_resume_by_keyfile(struct crypt_device *cd,
1161 const char *keyfile,
1162 size_t keyfile_size)
1164 struct volume_key *vk = NULL;
1165 char *passphrase_read = NULL;
1166 size_t passphrase_size_read;
1169 log_dbg("Resuming volume %s.", name);
1171 if (!isLUKS(cd->type)) {
1172 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1177 r = dm_status_suspended(name);
1182 log_err(cd, _("Volume %s is not suspended.\n"), name);
1189 r = key_from_file(cd, _("Enter passphrase: "), &passphrase_read,
1190 &passphrase_size_read, keyfile, keyfile_size);
1194 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase_read,
1195 passphrase_size_read, &cd->hdr, &vk, cd);
1200 r = dm_resume_and_reinstate_key(name, vk->keylength, vk->key);
1202 log_err(cd, "Error during resuming device %s.\n", name);
1204 crypt_safe_free(passphrase_read);
1205 crypt_free_volume_key(vk);
1206 return r < 0 ? r : keyslot;
1209 // slot manipulation
1210 int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
1211 int keyslot, // -1 any
1212 const char *passphrase, // NULL -> terminal
1213 size_t passphrase_size,
1214 const char *new_passphrase, // NULL -> terminal
1215 size_t new_passphrase_size)
1217 struct volume_key *vk = NULL;
1218 char *password = NULL, *new_password = NULL;
1219 size_t passwordLen, new_passwordLen;
1222 log_dbg("Adding new keyslot, existing passphrase %sprovided,"
1223 "new passphrase %sprovided.",
1224 passphrase ? "" : "not ", new_passphrase ? "" : "not ");
1226 if (!isLUKS(cd->type)) {
1227 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1231 r = keyslot_verify_or_find_empty(cd, &keyslot);
1235 if (!LUKS_keyslot_active_count(&cd->hdr)) {
1236 /* No slots used, try to use pre-generated key in header */
1237 if (cd->volume_key) {
1238 vk = crypt_alloc_volume_key(cd->volume_key->keylength, cd->volume_key->key);
1239 r = vk ? 0 : -ENOMEM;
1241 log_err(cd, _("Cannot add key slot, all slots disabled and no volume key provided.\n"));
1244 } else if (passphrase) {
1245 /* Passphrase provided, use it to unlock existing keyslot */
1246 r = LUKS_open_key_with_hdr(mdata_device(cd), CRYPT_ANY_SLOT, passphrase,
1247 passphrase_size, &cd->hdr, &vk, cd);
1249 /* Passphrase not provided, ask first and use it to unlock existing keyslot */
1250 r = key_from_terminal(cd, _("Enter any passphrase: "),
1251 &password, &passwordLen, 0);
1255 r = LUKS_open_key_with_hdr(mdata_device(cd), CRYPT_ANY_SLOT, password,
1256 passwordLen, &cd->hdr, &vk, cd);
1257 crypt_safe_free(password);
1263 if (new_passphrase) {
1264 new_password = CONST_CAST(char*)new_passphrase;
1265 new_passwordLen = new_passphrase_size;
1267 r = key_from_terminal(cd, _("Enter new passphrase for key slot: "),
1268 &new_password, &new_passwordLen, 1);
1273 r = LUKS_set_key(mdata_device(cd), keyslot, new_password, new_passwordLen,
1274 &cd->hdr, vk, cd->iteration_time, &cd->PBKDF2_per_sec, cd);
1279 if (!new_passphrase)
1280 crypt_safe_free(new_password);
1281 crypt_free_volume_key(vk);
1282 return r ?: keyslot;
1285 int crypt_keyslot_add_by_keyfile(struct crypt_device *cd,
1287 const char *keyfile,
1288 size_t keyfile_size,
1289 const char *new_keyfile,
1290 size_t new_keyfile_size)
1292 struct volume_key *vk = NULL;
1293 char *password = NULL; size_t passwordLen;
1294 char *new_password = NULL; size_t new_passwordLen;
1297 log_dbg("Adding new keyslot, existing keyfile %s, new keyfile %s.",
1298 keyfile ?: "[none]", new_keyfile ?: "[none]");
1300 if (!isLUKS(cd->type)) {
1301 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1305 r = keyslot_verify_or_find_empty(cd, &keyslot);
1309 if (!LUKS_keyslot_active_count(&cd->hdr)) {
1310 /* No slots used, try to use pre-generated key in header */
1311 if (cd->volume_key) {
1312 vk = crypt_alloc_volume_key(cd->volume_key->keylength, cd->volume_key->key);
1313 r = vk ? 0 : -ENOMEM;
1315 log_err(cd, _("Cannot add key slot, all slots disabled and no volume key provided.\n"));
1319 /* Read password from file of (if NULL) from terminal */
1321 r = key_from_file(cd, _("Enter any passphrase: "),
1322 &password, &passwordLen,
1323 keyfile, keyfile_size);
1325 r = key_from_terminal(cd, _("Enter any passphrase: "),
1326 &password, &passwordLen, 0);
1330 r = LUKS_open_key_with_hdr(mdata_device(cd), CRYPT_ANY_SLOT, password, passwordLen,
1338 r = key_from_file(cd, _("Enter new passphrase for key slot: "),
1339 &new_password, &new_passwordLen, new_keyfile,
1342 r = key_from_terminal(cd, _("Enter new passphrase for key slot: "),
1343 &new_password, &new_passwordLen, 1);
1347 r = LUKS_set_key(mdata_device(cd), keyslot, new_password, new_passwordLen,
1348 &cd->hdr, vk, cd->iteration_time, &cd->PBKDF2_per_sec, cd);
1350 crypt_safe_free(password);
1351 crypt_safe_free(new_password);
1352 crypt_free_volume_key(vk);
1353 return r < 0 ? r : keyslot;
1356 int crypt_keyslot_add_by_volume_key(struct crypt_device *cd,
1358 const char *volume_key,
1359 size_t volume_key_size,
1360 const char *passphrase,
1361 size_t passphrase_size)
1363 struct volume_key *vk = NULL;
1365 char *new_password = NULL; size_t new_passwordLen;
1367 log_dbg("Adding new keyslot %d using volume key.", keyslot);
1369 if (!isLUKS(cd->type)) {
1370 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1375 vk = crypt_alloc_volume_key(volume_key_size, volume_key);
1376 else if (cd->volume_key)
1377 vk = crypt_alloc_volume_key(cd->volume_key->keylength, cd->volume_key->key);
1382 r = LUKS_verify_volume_key(&cd->hdr, vk);
1384 log_err(cd, _("Volume key does not match the volume.\n"));
1388 r = keyslot_verify_or_find_empty(cd, &keyslot);
1393 r = key_from_terminal(cd, _("Enter new passphrase for key slot: "),
1394 &new_password, &new_passwordLen, 1);
1397 passphrase = new_password;
1398 passphrase_size = new_passwordLen;
1401 r = LUKS_set_key(mdata_device(cd), keyslot, passphrase, passphrase_size,
1402 &cd->hdr, vk, cd->iteration_time, &cd->PBKDF2_per_sec, cd);
1404 crypt_safe_free(new_password);
1405 crypt_free_volume_key(vk);
1406 return (r < 0) ? r : keyslot;
1409 int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot)
1411 crypt_keyslot_info ki;
1413 log_dbg("Destroying keyslot %d.", keyslot);
1415 if (!isLUKS(cd->type)) {
1416 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1420 ki = crypt_keyslot_status(cd, keyslot);
1421 if (ki == CRYPT_SLOT_INVALID) {
1422 log_err(cd, _("Key slot %d is invalid.\n"), keyslot);
1426 if (ki == CRYPT_SLOT_INACTIVE) {
1427 log_err(cd, _("Key slot %d is not used.\n"), keyslot);
1431 return LUKS_del_key(mdata_device(cd), keyslot, &cd->hdr, cd);
1434 // activation/deactivation of device mapping
1435 int crypt_activate_by_passphrase(struct crypt_device *cd,
1438 const char *passphrase,
1439 size_t passphrase_size,
1442 crypt_status_info ci;
1443 struct volume_key *vk = NULL;
1444 char *read_passphrase = NULL;
1445 size_t passphraseLen = 0;
1448 log_dbg("%s volume %s [keyslot %d] using %spassphrase.",
1449 name ? "Activating" : "Checking", name ?: "",
1450 keyslot, passphrase ? "" : "[none] ");
1453 ci = crypt_status(NULL, name);
1454 if (ci == CRYPT_INVALID)
1456 else if (ci >= CRYPT_ACTIVE) {
1457 log_err(cd, _("Device %s already exists.\n"), name);
1462 /* plain, use hashed passphrase */
1463 if (isPLAIN(cd->type)) {
1468 r = key_from_terminal(cd, NULL, &read_passphrase,
1472 passphrase = read_passphrase;
1473 passphrase_size = passphraseLen;
1476 r = process_key(cd, cd->plain_hdr.hash,
1477 cd->volume_key->keylength,
1478 passphrase, passphrase_size, &vk);
1482 r = PLAIN_activate(cd, name, vk, cd->plain_hdr.size, flags);
1484 } else if (isLUKS(cd->type)) {
1485 /* provided passphrase, do not retry */
1487 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase,
1488 passphrase_size, &cd->hdr, &vk, cd);
1490 r = volume_key_by_terminal_passphrase(cd, keyslot, &vk);
1495 r = LUKS1_activate(cd, name, vk, flags);
1500 crypt_safe_free(read_passphrase);
1501 crypt_free_volume_key(vk);
1503 return r < 0 ? r : keyslot;
1506 int crypt_activate_by_keyfile(struct crypt_device *cd,
1509 const char *keyfile,
1510 size_t keyfile_size,
1513 crypt_status_info ci;
1514 struct volume_key *vk = NULL;
1515 char *passphrase_read = NULL;
1516 size_t passphrase_size_read;
1517 unsigned int key_count = 0;
1520 log_dbg("Activating volume %s [keyslot %d] using keyfile %s.",
1521 name ?: "", keyslot, keyfile ?: "[none]");
1524 ci = crypt_status(NULL, name);
1525 if (ci == CRYPT_INVALID)
1527 else if (ci >= CRYPT_ACTIVE) {
1528 log_err(cd, _("Device %s already exists.\n"), name);
1536 if (isPLAIN(cd->type)) {
1540 r = key_from_file(cd, _("Enter passphrase: "),
1541 &passphrase_read, &passphrase_size_read,
1542 keyfile, keyfile_size);
1546 r = process_key(cd, cd->plain_hdr.hash,
1547 cd->volume_key->keylength,
1548 passphrase_read, passphrase_size_read, &vk);
1552 r = PLAIN_activate(cd, name, vk, cd->plain_hdr.size, flags);
1553 } else if (isLUKS(cd->type)) {
1554 r = key_from_file(cd, _("Enter passphrase: "), &passphrase_read,
1555 &passphrase_size_read, keyfile, keyfile_size);
1558 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase_read,
1559 passphrase_size_read, &cd->hdr, &vk, cd);
1565 r = LUKS1_activate(cd, name, vk, flags);
1570 } else if (isLOOPAES(cd->type)) {
1571 r = key_from_file(cd, NULL, &passphrase_read, &passphrase_size_read,
1572 keyfile, keyfile_size);
1575 r = LOOPAES_parse_keyfile(cd, &vk, cd->loopaes_hdr.hash, &key_count,
1576 passphrase_read, passphrase_size_read);
1580 r = LOOPAES_activate(cd, name, cd->loopaes_cipher,
1581 key_count, vk, flags);
1586 crypt_safe_free(passphrase_read);
1587 crypt_free_volume_key(vk);
1592 int crypt_activate_by_volume_key(struct crypt_device *cd,
1594 const char *volume_key,
1595 size_t volume_key_size,
1598 crypt_status_info ci;
1599 struct volume_key *vk = NULL;
1602 log_dbg("Activating volume %s by volume key.", name);
1605 ci = crypt_status(NULL, name);
1606 if (ci == CRYPT_INVALID)
1608 else if (ci >= CRYPT_ACTIVE) {
1609 log_err(cd, _("Device %s already exists.\n"), name);
1614 /* use key directly, no hash */
1615 if (isPLAIN(cd->type)) {
1619 if (!volume_key || !volume_key_size || !cd->volume_key ||
1620 volume_key_size != cd->volume_key->keylength) {
1621 log_err(cd, _("Incorrect volume key specified for plain device.\n"));
1625 vk = crypt_alloc_volume_key(volume_key_size, volume_key);
1629 r = PLAIN_activate(cd, name, vk, cd->plain_hdr.size, flags);
1630 } else if (isLUKS(cd->type)) {
1631 /* If key is not provided, try to use internal key */
1633 if (!cd->volume_key) {
1634 log_err(cd, _("Volume key does not match the volume.\n"));
1637 volume_key_size = cd->volume_key->keylength;
1638 volume_key = cd->volume_key->key;
1641 vk = crypt_alloc_volume_key(volume_key_size, volume_key);
1644 r = LUKS_verify_volume_key(&cd->hdr, vk);
1647 log_err(cd, _("Volume key does not match the volume.\n"));
1650 r = LUKS1_activate(cd, name, vk, flags);
1652 log_err(cd, _("Device type is not properly initialised.\n"));
1654 crypt_free_volume_key(vk);
1659 int crypt_deactivate(struct crypt_device *cd, const char *name)
1666 log_dbg("Deactivating volume %s.", name);
1668 if (!cd && dm_init(NULL, 1) < 0)
1671 switch (crypt_status(cd, name)) {
1673 r = dm_remove_device(name, 0, 0);
1676 log_err(cd, _("Device %s is busy.\n"), name);
1679 case CRYPT_INACTIVE:
1680 log_err(cd, _("Device %s is not active.\n"), name);
1684 log_err(cd, _("Invalid device %s.\n"), name);
1694 int crypt_volume_key_get(struct crypt_device *cd,
1697 size_t *volume_key_size,
1698 const char *passphrase,
1699 size_t passphrase_size)
1701 struct volume_key *vk = NULL;
1705 key_len = crypt_get_volume_key_size(cd);
1706 if (key_len > *volume_key_size) {
1707 log_err(cd, _("Volume key buffer too small.\n"));
1711 if (isPLAIN(cd->type) && cd->plain_hdr.hash) {
1712 r = process_key(cd, cd->plain_hdr.hash, key_len,
1713 passphrase, passphrase_size, &vk);
1715 log_err(cd, _("Cannot retrieve volume key for plain device.\n"));
1716 } else if (isLUKS(cd->type)) {
1717 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase,
1718 passphrase_size, &cd->hdr, &vk, cd);
1721 log_err(cd, _("This operation is not supported for %s crypt device.\n"), cd->type ?: "(none)");
1724 memcpy(volume_key, vk->key, vk->keylength);
1725 *volume_key_size = vk->keylength;
1728 crypt_free_volume_key(vk);
1732 int crypt_volume_key_verify(struct crypt_device *cd,
1733 const char *volume_key,
1734 size_t volume_key_size)
1736 struct volume_key *vk;
1739 if (!isLUKS(cd->type)) {
1740 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1744 vk = crypt_alloc_volume_key(volume_key_size, volume_key);
1748 r = LUKS_verify_volume_key(&cd->hdr, vk);
1751 log_err(cd, _("Volume key does not match the volume.\n"));
1753 crypt_free_volume_key(vk);
1758 void crypt_set_timeout(struct crypt_device *cd, uint64_t timeout_sec)
1760 log_dbg("Timeout set to %" PRIu64 " miliseconds.", timeout_sec);
1761 cd->timeout = timeout_sec;
1764 void crypt_set_password_retry(struct crypt_device *cd, int tries)
1766 log_dbg("Password retry count set to %d.", tries);
1770 void crypt_set_iterarion_time(struct crypt_device *cd, uint64_t iteration_time_ms)
1772 log_dbg("Iteration time set to %" PRIu64 " miliseconds.", iteration_time_ms);
1773 cd->iteration_time = iteration_time_ms;
1776 void crypt_set_password_verify(struct crypt_device *cd, int password_verify)
1778 log_dbg("Password verification %s.", password_verify ? "enabled" : "disabled");
1779 cd->password_verify = password_verify ? 1 : 0;
1782 void crypt_set_rng_type(struct crypt_device *cd, int rng_type)
1785 case CRYPT_RNG_URANDOM:
1786 case CRYPT_RNG_RANDOM:
1787 log_dbg("RNG set to %d (%s).", rng_type, rng_type ? "random" : "urandom");
1788 cd->rng_type = rng_type;
1792 int crypt_get_rng_type(struct crypt_device *cd)
1797 return cd->rng_type;
1800 int crypt_memory_lock(struct crypt_device *cd, int lock)
1802 return lock ? crypt_memlock_inc(cd) : crypt_memlock_dec(cd);
1806 crypt_status_info crypt_status(struct crypt_device *cd, const char *name)
1810 if (!cd && dm_init(NULL, 1) < 0)
1811 return CRYPT_INVALID;
1813 r = dm_status_device(name);
1818 if (r < 0 && r != -ENODEV)
1819 return CRYPT_INVALID;
1822 return CRYPT_ACTIVE;
1827 return CRYPT_INACTIVE;
1830 static void hexprintICB(struct crypt_device *cd, char *d, int n)
1833 for(i = 0; i < n; i++)
1834 log_std(cd, "%02hhx ", (char)d[i]);
1837 int crypt_dump(struct crypt_device *cd)
1840 if (!isLUKS(cd->type)) { //FIXME
1841 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1845 log_std(cd, "LUKS header information for %s\n\n", mdata_device(cd));
1846 log_std(cd, "Version: \t%d\n", cd->hdr.version);
1847 log_std(cd, "Cipher name: \t%s\n", cd->hdr.cipherName);
1848 log_std(cd, "Cipher mode: \t%s\n", cd->hdr.cipherMode);
1849 log_std(cd, "Hash spec: \t%s\n", cd->hdr.hashSpec);
1850 log_std(cd, "Payload offset:\t%d\n", cd->hdr.payloadOffset);
1851 log_std(cd, "MK bits: \t%d\n", cd->hdr.keyBytes * 8);
1852 log_std(cd, "MK digest: \t");
1853 hexprintICB(cd, cd->hdr.mkDigest, LUKS_DIGESTSIZE);
1855 log_std(cd, "MK salt: \t");
1856 hexprintICB(cd, cd->hdr.mkDigestSalt, LUKS_SALTSIZE/2);
1857 log_std(cd, "\n \t");
1858 hexprintICB(cd, cd->hdr.mkDigestSalt+LUKS_SALTSIZE/2, LUKS_SALTSIZE/2);
1860 log_std(cd, "MK iterations: \t%d\n", cd->hdr.mkDigestIterations);
1861 log_std(cd, "UUID: \t%s\n\n", cd->hdr.uuid);
1862 for(i = 0; i < LUKS_NUMKEYS; i++) {
1863 if(cd->hdr.keyblock[i].active == LUKS_KEY_ENABLED) {
1864 log_std(cd, "Key Slot %d: ENABLED\n",i);
1865 log_std(cd, "\tIterations: \t%d\n",
1866 cd->hdr.keyblock[i].passwordIterations);
1867 log_std(cd, "\tSalt: \t");
1868 hexprintICB(cd, cd->hdr.keyblock[i].passwordSalt,
1870 log_std(cd, "\n\t \t");
1871 hexprintICB(cd, cd->hdr.keyblock[i].passwordSalt +
1872 LUKS_SALTSIZE/2, LUKS_SALTSIZE/2);
1875 log_std(cd, "\tKey material offset:\t%d\n",
1876 cd->hdr.keyblock[i].keyMaterialOffset);
1877 log_std(cd, "\tAF stripes: \t%d\n",
1878 cd->hdr.keyblock[i].stripes);
1881 log_std(cd, "Key Slot %d: DISABLED\n", i);
1887 const char *crypt_get_cipher(struct crypt_device *cd)
1889 if (isPLAIN(cd->type))
1890 return cd->plain_cipher;
1892 if (isLUKS(cd->type))
1893 return cd->hdr.cipherName;
1895 if (isLOOPAES(cd->type))
1896 return cd->loopaes_cipher;
1901 const char *crypt_get_cipher_mode(struct crypt_device *cd)
1903 if (isPLAIN(cd->type))
1904 return cd->plain_cipher_mode;
1906 if (isLUKS(cd->type))
1907 return cd->hdr.cipherMode;
1909 if (isLOOPAES(cd->type))
1910 return cd->loopaes_cipher_mode;
1915 const char *crypt_get_uuid(struct crypt_device *cd)
1917 if (isLUKS(cd->type))
1918 return cd->hdr.uuid;
1920 if (isPLAIN(cd->type))
1921 return cd->plain_uuid;
1923 if (isLOOPAES(cd->type))
1924 return cd->loopaes_uuid;
1929 const char *crypt_get_device_name(struct crypt_device *cd)
1935 int crypt_get_volume_key_size(struct crypt_device *cd)
1937 if (isPLAIN(cd->type) && cd->volume_key)
1938 return cd->volume_key->keylength;
1940 if (isLUKS(cd->type))
1941 return cd->hdr.keyBytes;
1943 if (isLOOPAES(cd->type))
1944 return cd->loopaes_key_size;
1949 uint64_t crypt_get_data_offset(struct crypt_device *cd)
1951 if (isPLAIN(cd->type))
1952 return cd->plain_hdr.offset;
1954 if (isLUKS(cd->type))
1955 return cd->hdr.payloadOffset;
1957 if (isLOOPAES(cd->type))
1958 return cd->loopaes_hdr.offset;
1963 uint64_t crypt_get_iv_offset(struct crypt_device *cd)
1965 if (isPLAIN(cd->type))
1966 return cd->plain_hdr.skip;
1968 if (isLUKS(cd->type))
1971 if (isLOOPAES(cd->type))
1972 return cd->loopaes_hdr.skip;
1977 crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot)
1979 if (!isLUKS(cd->type)) {
1980 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1981 return CRYPT_SLOT_INVALID;
1984 return LUKS_keyslot_info(&cd->hdr, keyslot);
1987 int crypt_keyslot_max(const char *type)
1989 if (type && isLUKS(type))
1990 return LUKS_NUMKEYS;
1995 const char *crypt_get_type(struct crypt_device *cd)
2000 int crypt_get_active_device(struct crypt_device *cd __attribute__((unused)),
2002 struct crypt_active_device *cad)
2004 struct crypt_dm_active_device dmd;
2007 r = dm_query_device(name, 0, &dmd);
2011 cad->offset = dmd.offset;
2012 cad->iv_offset = dmd.iv_offset;
2013 cad->size = dmd.size;
2014 cad->flags = dmd.flags;