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,
855 log_dbg("Context already formatted as %s.", cd->type);
859 log_dbg("Formatting device %s as type %s.", mdata_device(cd) ?: "(none)", type);
866 r = _crypt_format_plain(cd, cipher, cipher_mode,
867 uuid, volume_key_size, params);
868 else if (isLUKS(type))
869 r = _crypt_format_luks1(cd, cipher, cipher_mode,
870 uuid, volume_key, volume_key_size, params);
871 else if (isLOOPAES(type))
872 r = _crypt_format_loopaes(cd, cipher, uuid, volume_key_size, params);
874 /* FIXME: allow plugins here? */
875 log_err(cd, _("Unknown crypt device type %s requested.\n"), type);
879 if (!r && !(cd->type = strdup(type)))
883 crypt_free_volume_key(cd->volume_key);
884 cd->volume_key = NULL;
890 int crypt_load(struct crypt_device *cd,
891 const char *requested_type,
892 void *params __attribute__((unused)))
894 struct luks_phdr hdr;
897 log_dbg("Trying to load %s crypt type from device %s.",
898 requested_type ?: "any", mdata_device(cd) ?: "(none)");
900 if (!mdata_device(cd))
903 if (requested_type && !isLUKS(requested_type))
906 if (cd->type && !isLUKS(cd->type)) {
907 log_dbg("Context is already initialised to type %s", cd->type);
915 r = LUKS_read_phdr(mdata_device(cd), &hdr, 1, cd);
919 if (!cd->type && !(cd->type = strdup(CRYPT_LUKS1)))
922 memcpy(&cd->hdr, &hdr, sizeof(hdr));
924 /* cd->type and header must be set in context */
925 r = crypt_check_data_device_size(cd);
934 int crypt_resize(struct crypt_device *cd, const char *name, uint64_t new_size)
936 struct crypt_dm_active_device dmd;
939 /* Device context type must be initialised */
940 if (!cd->type || !crypt_get_uuid(cd))
943 log_dbg("Resizing device %s to %" PRIu64 " sectors.", name, new_size);
945 r = dm_query_device(name, DM_ACTIVE_DEVICE | DM_ACTIVE_CIPHER |
946 DM_ACTIVE_UUID | DM_ACTIVE_KEYSIZE |
947 DM_ACTIVE_KEY, &dmd);
949 log_err(NULL, _("Device %s is not active.\n"), name);
958 r = device_check_and_adjust(cd, dmd.device, DEV_OK, &new_size, &dmd.offset, &dmd.flags);
962 if (new_size == dmd.size) {
963 log_dbg("Device has already requested size %" PRIu64
964 " sectors.", dmd.size);
968 r = dm_create_device(name, cd->type, &dmd, 1);
971 crypt_free_volume_key(dmd.vk);
972 free(CONST_CAST(void*)dmd.cipher);
973 free(CONST_CAST(void*)dmd.device);
974 free(CONST_CAST(void*)dmd.uuid);
979 int crypt_set_uuid(struct crypt_device *cd, const char *uuid)
981 if (!isLUKS(cd->type)) {
982 log_err(cd, _("This operation is not supported for this device type.\n"));
986 if (uuid && !strncmp(uuid, cd->hdr.uuid, sizeof(cd->hdr.uuid))) {
987 log_dbg("UUID is the same as requested (%s) for device %s.",
988 uuid, mdata_device(cd));
993 log_dbg("Requested new UUID change to %s for %s.", uuid, mdata_device(cd));
995 log_dbg("Requested new UUID refresh for %s.", mdata_device(cd));
997 if (!crypt_confirm(cd, _("Do you really want to change UUID of device?")))
1000 return LUKS_hdr_uuid_set(mdata_device(cd), &cd->hdr, uuid, cd);
1003 int crypt_header_backup(struct crypt_device *cd,
1004 const char *requested_type,
1005 const char *backup_file)
1009 if ((requested_type && !isLUKS(requested_type)) || !backup_file)
1012 r = init_crypto(cd);
1016 log_dbg("Requested header backup of device %s (%s) to "
1017 "file %s.", mdata_device(cd), requested_type, backup_file);
1019 return LUKS_hdr_backup(backup_file, mdata_device(cd), &cd->hdr, cd);
1022 int crypt_header_restore(struct crypt_device *cd,
1023 const char *requested_type,
1024 const char *backup_file)
1028 if (requested_type && !isLUKS(requested_type))
1031 /* Some hash functions need initialized gcrypt library */
1032 r = init_crypto(cd);
1036 log_dbg("Requested header restore to device %s (%s) from "
1037 "file %s.", mdata_device(cd), requested_type, backup_file);
1039 return LUKS_hdr_restore(backup_file, mdata_device(cd), &cd->hdr, cd);
1042 void crypt_free(struct crypt_device *cd)
1045 log_dbg("Releasing crypt device %s context.", mdata_device(cd));
1047 if (cd->loop_fd != -1)
1051 crypt_free_volume_key(cd->volume_key);
1054 free(cd->metadata_device);
1055 free(cd->backing_file);
1058 /* used in plain device only */
1059 free(CONST_CAST(void*)cd->plain_hdr.hash);
1060 free(cd->plain_cipher);
1061 free(cd->plain_cipher_mode);
1062 free(cd->plain_uuid);
1064 /* used in loop-AES device only */
1065 free(CONST_CAST(void*)cd->loopaes_hdr.hash);
1066 free(cd->loopaes_cipher);
1067 free(cd->loopaes_uuid);
1073 int crypt_suspend(struct crypt_device *cd,
1076 crypt_status_info ci;
1079 log_dbg("Suspending volume %s.", name);
1081 if (!isLUKS(cd->type)) {
1082 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1087 ci = crypt_status(NULL, name);
1088 if (ci < CRYPT_ACTIVE) {
1089 log_err(cd, _("Volume %s is not active.\n"), name);
1093 if (!cd && dm_init(NULL, 1) < 0)
1096 r = dm_status_suspended(name);
1101 log_err(cd, _("Volume %s is already suspended.\n"), name);
1106 r = dm_suspend_and_wipe_key(name);
1108 log_err(cd, "Suspend is not supported for device %s.\n", name);
1110 log_err(cd, "Error during suspending device %s.\n", name);
1117 int crypt_resume_by_passphrase(struct crypt_device *cd,
1120 const char *passphrase,
1121 size_t passphrase_size)
1123 struct volume_key *vk = NULL;
1126 log_dbg("Resuming volume %s.", name);
1128 if (!isLUKS(cd->type)) {
1129 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1134 r = dm_status_suspended(name);
1139 log_err(cd, _("Volume %s is not suspended.\n"), name);
1144 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase,
1145 passphrase_size, &cd->hdr, &vk, cd);
1147 r = volume_key_by_terminal_passphrase(cd, keyslot, &vk);
1151 r = dm_resume_and_reinstate_key(name, vk->keylength, vk->key);
1153 log_err(cd, "Resume is not supported for device %s.\n", name);
1155 log_err(cd, "Error during resuming device %s.\n", name);
1159 crypt_free_volume_key(vk);
1160 return r < 0 ? r : keyslot;
1163 int crypt_resume_by_keyfile(struct crypt_device *cd,
1166 const char *keyfile,
1167 size_t keyfile_size)
1169 struct volume_key *vk = NULL;
1170 char *passphrase_read = NULL;
1171 size_t passphrase_size_read;
1174 log_dbg("Resuming volume %s.", name);
1176 if (!isLUKS(cd->type)) {
1177 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1182 r = dm_status_suspended(name);
1187 log_err(cd, _("Volume %s is not suspended.\n"), name);
1194 r = key_from_file(cd, _("Enter passphrase: "), &passphrase_read,
1195 &passphrase_size_read, keyfile, keyfile_size);
1199 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase_read,
1200 passphrase_size_read, &cd->hdr, &vk, cd);
1205 r = dm_resume_and_reinstate_key(name, vk->keylength, vk->key);
1207 log_err(cd, "Error during resuming device %s.\n", name);
1209 crypt_safe_free(passphrase_read);
1210 crypt_free_volume_key(vk);
1211 return r < 0 ? r : keyslot;
1214 // slot manipulation
1215 int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
1216 int keyslot, // -1 any
1217 const char *passphrase, // NULL -> terminal
1218 size_t passphrase_size,
1219 const char *new_passphrase, // NULL -> terminal
1220 size_t new_passphrase_size)
1222 struct volume_key *vk = NULL;
1223 char *password = NULL, *new_password = NULL;
1224 size_t passwordLen, new_passwordLen;
1227 log_dbg("Adding new keyslot, existing passphrase %sprovided,"
1228 "new passphrase %sprovided.",
1229 passphrase ? "" : "not ", new_passphrase ? "" : "not ");
1231 if (!isLUKS(cd->type)) {
1232 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1236 r = keyslot_verify_or_find_empty(cd, &keyslot);
1240 if (!LUKS_keyslot_active_count(&cd->hdr)) {
1241 /* No slots used, try to use pre-generated key in header */
1242 if (cd->volume_key) {
1243 vk = crypt_alloc_volume_key(cd->volume_key->keylength, cd->volume_key->key);
1244 r = vk ? 0 : -ENOMEM;
1246 log_err(cd, _("Cannot add key slot, all slots disabled and no volume key provided.\n"));
1249 } else if (passphrase) {
1250 /* Passphrase provided, use it to unlock existing keyslot */
1251 r = LUKS_open_key_with_hdr(mdata_device(cd), CRYPT_ANY_SLOT, passphrase,
1252 passphrase_size, &cd->hdr, &vk, cd);
1254 /* Passphrase not provided, ask first and use it to unlock existing keyslot */
1255 r = key_from_terminal(cd, _("Enter any passphrase: "),
1256 &password, &passwordLen, 0);
1260 r = LUKS_open_key_with_hdr(mdata_device(cd), CRYPT_ANY_SLOT, password,
1261 passwordLen, &cd->hdr, &vk, cd);
1262 crypt_safe_free(password);
1268 if (new_passphrase) {
1269 new_password = CONST_CAST(char*)new_passphrase;
1270 new_passwordLen = new_passphrase_size;
1272 r = key_from_terminal(cd, _("Enter new passphrase for key slot: "),
1273 &new_password, &new_passwordLen, 1);
1278 r = LUKS_set_key(mdata_device(cd), keyslot, new_password, new_passwordLen,
1279 &cd->hdr, vk, cd->iteration_time, &cd->PBKDF2_per_sec, cd);
1284 if (!new_passphrase)
1285 crypt_safe_free(new_password);
1286 crypt_free_volume_key(vk);
1287 return r ?: keyslot;
1290 int crypt_keyslot_add_by_keyfile(struct crypt_device *cd,
1292 const char *keyfile,
1293 size_t keyfile_size,
1294 const char *new_keyfile,
1295 size_t new_keyfile_size)
1297 struct volume_key *vk = NULL;
1298 char *password = NULL; size_t passwordLen;
1299 char *new_password = NULL; size_t new_passwordLen;
1302 log_dbg("Adding new keyslot, existing keyfile %s, new keyfile %s.",
1303 keyfile ?: "[none]", new_keyfile ?: "[none]");
1305 if (!isLUKS(cd->type)) {
1306 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1310 r = keyslot_verify_or_find_empty(cd, &keyslot);
1314 if (!LUKS_keyslot_active_count(&cd->hdr)) {
1315 /* No slots used, try to use pre-generated key in header */
1316 if (cd->volume_key) {
1317 vk = crypt_alloc_volume_key(cd->volume_key->keylength, cd->volume_key->key);
1318 r = vk ? 0 : -ENOMEM;
1320 log_err(cd, _("Cannot add key slot, all slots disabled and no volume key provided.\n"));
1324 /* Read password from file of (if NULL) from terminal */
1326 r = key_from_file(cd, _("Enter any passphrase: "),
1327 &password, &passwordLen,
1328 keyfile, keyfile_size);
1330 r = key_from_terminal(cd, _("Enter any passphrase: "),
1331 &password, &passwordLen, 0);
1335 r = LUKS_open_key_with_hdr(mdata_device(cd), CRYPT_ANY_SLOT, password, passwordLen,
1343 r = key_from_file(cd, _("Enter new passphrase for key slot: "),
1344 &new_password, &new_passwordLen, new_keyfile,
1347 r = key_from_terminal(cd, _("Enter new passphrase for key slot: "),
1348 &new_password, &new_passwordLen, 1);
1352 r = LUKS_set_key(mdata_device(cd), keyslot, new_password, new_passwordLen,
1353 &cd->hdr, vk, cd->iteration_time, &cd->PBKDF2_per_sec, cd);
1355 crypt_safe_free(password);
1356 crypt_safe_free(new_password);
1357 crypt_free_volume_key(vk);
1358 return r < 0 ? r : keyslot;
1361 int crypt_keyslot_add_by_volume_key(struct crypt_device *cd,
1363 const char *volume_key,
1364 size_t volume_key_size,
1365 const char *passphrase,
1366 size_t passphrase_size)
1368 struct volume_key *vk = NULL;
1370 char *new_password = NULL; size_t new_passwordLen;
1372 log_dbg("Adding new keyslot %d using volume key.", keyslot);
1374 if (!isLUKS(cd->type)) {
1375 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1380 vk = crypt_alloc_volume_key(volume_key_size, volume_key);
1381 else if (cd->volume_key)
1382 vk = crypt_alloc_volume_key(cd->volume_key->keylength, cd->volume_key->key);
1387 r = LUKS_verify_volume_key(&cd->hdr, vk);
1389 log_err(cd, _("Volume key does not match the volume.\n"));
1393 r = keyslot_verify_or_find_empty(cd, &keyslot);
1398 r = key_from_terminal(cd, _("Enter new passphrase for key slot: "),
1399 &new_password, &new_passwordLen, 1);
1402 passphrase = new_password;
1403 passphrase_size = new_passwordLen;
1406 r = LUKS_set_key(mdata_device(cd), keyslot, passphrase, passphrase_size,
1407 &cd->hdr, vk, cd->iteration_time, &cd->PBKDF2_per_sec, cd);
1409 crypt_safe_free(new_password);
1410 crypt_free_volume_key(vk);
1411 return (r < 0) ? r : keyslot;
1414 int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot)
1416 crypt_keyslot_info ki;
1418 log_dbg("Destroying keyslot %d.", keyslot);
1420 if (!isLUKS(cd->type)) {
1421 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1425 ki = crypt_keyslot_status(cd, keyslot);
1426 if (ki == CRYPT_SLOT_INVALID) {
1427 log_err(cd, _("Key slot %d is invalid.\n"), keyslot);
1431 if (ki == CRYPT_SLOT_INACTIVE) {
1432 log_err(cd, _("Key slot %d is not used.\n"), keyslot);
1436 return LUKS_del_key(mdata_device(cd), keyslot, &cd->hdr, cd);
1439 // activation/deactivation of device mapping
1440 int crypt_activate_by_passphrase(struct crypt_device *cd,
1443 const char *passphrase,
1444 size_t passphrase_size,
1447 crypt_status_info ci;
1448 struct volume_key *vk = NULL;
1449 char *read_passphrase = NULL;
1450 size_t passphraseLen = 0;
1453 log_dbg("%s volume %s [keyslot %d] using %spassphrase.",
1454 name ? "Activating" : "Checking", name ?: "",
1455 keyslot, passphrase ? "" : "[none] ");
1458 ci = crypt_status(NULL, name);
1459 if (ci == CRYPT_INVALID)
1461 else if (ci >= CRYPT_ACTIVE) {
1462 log_err(cd, _("Device %s already exists.\n"), name);
1467 /* plain, use hashed passphrase */
1468 if (isPLAIN(cd->type)) {
1473 r = key_from_terminal(cd, NULL, &read_passphrase,
1477 passphrase = read_passphrase;
1478 passphrase_size = passphraseLen;
1481 r = process_key(cd, cd->plain_hdr.hash,
1482 cd->volume_key->keylength,
1483 passphrase, passphrase_size, &vk);
1487 r = PLAIN_activate(cd, name, vk, cd->plain_hdr.size, flags);
1489 } else if (isLUKS(cd->type)) {
1490 /* provided passphrase, do not retry */
1492 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase,
1493 passphrase_size, &cd->hdr, &vk, cd);
1495 r = volume_key_by_terminal_passphrase(cd, keyslot, &vk);
1500 r = LUKS1_activate(cd, name, vk, flags);
1505 crypt_safe_free(read_passphrase);
1506 crypt_free_volume_key(vk);
1508 return r < 0 ? r : keyslot;
1511 int crypt_activate_by_keyfile(struct crypt_device *cd,
1514 const char *keyfile,
1515 size_t keyfile_size,
1518 crypt_status_info ci;
1519 struct volume_key *vk = NULL;
1520 char *passphrase_read = NULL;
1521 size_t passphrase_size_read;
1522 unsigned int key_count = 0;
1525 log_dbg("Activating volume %s [keyslot %d] using keyfile %s.",
1526 name ?: "", keyslot, keyfile ?: "[none]");
1529 ci = crypt_status(NULL, name);
1530 if (ci == CRYPT_INVALID)
1532 else if (ci >= CRYPT_ACTIVE) {
1533 log_err(cd, _("Device %s already exists.\n"), name);
1541 if (isPLAIN(cd->type)) {
1545 r = key_from_file(cd, _("Enter passphrase: "),
1546 &passphrase_read, &passphrase_size_read,
1547 keyfile, keyfile_size);
1551 r = process_key(cd, cd->plain_hdr.hash,
1552 cd->volume_key->keylength,
1553 passphrase_read, passphrase_size_read, &vk);
1557 r = PLAIN_activate(cd, name, vk, cd->plain_hdr.size, flags);
1558 } else if (isLUKS(cd->type)) {
1559 r = key_from_file(cd, _("Enter passphrase: "), &passphrase_read,
1560 &passphrase_size_read, keyfile, keyfile_size);
1563 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase_read,
1564 passphrase_size_read, &cd->hdr, &vk, cd);
1570 r = LUKS1_activate(cd, name, vk, flags);
1575 } else if (isLOOPAES(cd->type)) {
1576 r = key_from_file(cd, NULL, &passphrase_read, &passphrase_size_read,
1577 keyfile, keyfile_size);
1580 r = LOOPAES_parse_keyfile(cd, &vk, cd->loopaes_hdr.hash, &key_count,
1581 passphrase_read, passphrase_size_read);
1585 r = LOOPAES_activate(cd, name, cd->loopaes_cipher,
1586 key_count, vk, flags);
1591 crypt_safe_free(passphrase_read);
1592 crypt_free_volume_key(vk);
1597 int crypt_activate_by_volume_key(struct crypt_device *cd,
1599 const char *volume_key,
1600 size_t volume_key_size,
1603 crypt_status_info ci;
1604 struct volume_key *vk = NULL;
1607 log_dbg("Activating volume %s by volume key.", name);
1610 ci = crypt_status(NULL, name);
1611 if (ci == CRYPT_INVALID)
1613 else if (ci >= CRYPT_ACTIVE) {
1614 log_err(cd, _("Device %s already exists.\n"), name);
1619 /* use key directly, no hash */
1620 if (isPLAIN(cd->type)) {
1624 if (!volume_key || !volume_key_size || !cd->volume_key ||
1625 volume_key_size != cd->volume_key->keylength) {
1626 log_err(cd, _("Incorrect volume key specified for plain device.\n"));
1630 vk = crypt_alloc_volume_key(volume_key_size, volume_key);
1634 r = PLAIN_activate(cd, name, vk, cd->plain_hdr.size, flags);
1635 } else if (isLUKS(cd->type)) {
1636 /* If key is not provided, try to use internal key */
1638 if (!cd->volume_key) {
1639 log_err(cd, _("Volume key does not match the volume.\n"));
1642 volume_key_size = cd->volume_key->keylength;
1643 volume_key = cd->volume_key->key;
1646 vk = crypt_alloc_volume_key(volume_key_size, volume_key);
1649 r = LUKS_verify_volume_key(&cd->hdr, vk);
1652 log_err(cd, _("Volume key does not match the volume.\n"));
1655 r = LUKS1_activate(cd, name, vk, flags);
1657 log_err(cd, _("Device type is not properly initialised.\n"));
1659 crypt_free_volume_key(vk);
1664 int crypt_deactivate(struct crypt_device *cd, const char *name)
1671 log_dbg("Deactivating volume %s.", name);
1673 if (!cd && dm_init(NULL, 1) < 0)
1676 switch (crypt_status(cd, name)) {
1678 r = dm_remove_device(name, 0, 0);
1681 log_err(cd, _("Device %s is busy.\n"), name);
1684 case CRYPT_INACTIVE:
1685 log_err(cd, _("Device %s is not active.\n"), name);
1689 log_err(cd, _("Invalid device %s.\n"), name);
1699 int crypt_volume_key_get(struct crypt_device *cd,
1702 size_t *volume_key_size,
1703 const char *passphrase,
1704 size_t passphrase_size)
1706 struct volume_key *vk = NULL;
1710 key_len = crypt_get_volume_key_size(cd);
1711 if (key_len > *volume_key_size) {
1712 log_err(cd, _("Volume key buffer too small.\n"));
1716 if (isPLAIN(cd->type) && cd->plain_hdr.hash) {
1717 r = process_key(cd, cd->plain_hdr.hash, key_len,
1718 passphrase, passphrase_size, &vk);
1720 log_err(cd, _("Cannot retrieve volume key for plain device.\n"));
1721 } else if (isLUKS(cd->type)) {
1722 r = LUKS_open_key_with_hdr(mdata_device(cd), keyslot, passphrase,
1723 passphrase_size, &cd->hdr, &vk, cd);
1726 log_err(cd, _("This operation is not supported for %s crypt device.\n"), cd->type ?: "(none)");
1729 memcpy(volume_key, vk->key, vk->keylength);
1730 *volume_key_size = vk->keylength;
1733 crypt_free_volume_key(vk);
1737 int crypt_volume_key_verify(struct crypt_device *cd,
1738 const char *volume_key,
1739 size_t volume_key_size)
1741 struct volume_key *vk;
1744 if (!isLUKS(cd->type)) {
1745 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1749 vk = crypt_alloc_volume_key(volume_key_size, volume_key);
1753 r = LUKS_verify_volume_key(&cd->hdr, vk);
1756 log_err(cd, _("Volume key does not match the volume.\n"));
1758 crypt_free_volume_key(vk);
1763 void crypt_set_timeout(struct crypt_device *cd, uint64_t timeout_sec)
1765 log_dbg("Timeout set to %" PRIu64 " miliseconds.", timeout_sec);
1766 cd->timeout = timeout_sec;
1769 void crypt_set_password_retry(struct crypt_device *cd, int tries)
1771 log_dbg("Password retry count set to %d.", tries);
1775 void crypt_set_iterarion_time(struct crypt_device *cd, uint64_t iteration_time_ms)
1777 log_dbg("Iteration time set to %" PRIu64 " miliseconds.", iteration_time_ms);
1778 cd->iteration_time = iteration_time_ms;
1781 void crypt_set_password_verify(struct crypt_device *cd, int password_verify)
1783 log_dbg("Password verification %s.", password_verify ? "enabled" : "disabled");
1784 cd->password_verify = password_verify ? 1 : 0;
1787 void crypt_set_rng_type(struct crypt_device *cd, int rng_type)
1790 case CRYPT_RNG_URANDOM:
1791 case CRYPT_RNG_RANDOM:
1792 log_dbg("RNG set to %d (%s).", rng_type, rng_type ? "random" : "urandom");
1793 cd->rng_type = rng_type;
1797 int crypt_get_rng_type(struct crypt_device *cd)
1802 return cd->rng_type;
1805 int crypt_memory_lock(struct crypt_device *cd, int lock)
1807 return lock ? crypt_memlock_inc(cd) : crypt_memlock_dec(cd);
1811 crypt_status_info crypt_status(struct crypt_device *cd, const char *name)
1815 if (!cd && dm_init(NULL, 1) < 0)
1816 return CRYPT_INVALID;
1818 r = dm_status_device(name);
1823 if (r < 0 && r != -ENODEV)
1824 return CRYPT_INVALID;
1827 return CRYPT_ACTIVE;
1832 return CRYPT_INACTIVE;
1835 static void hexprintICB(struct crypt_device *cd, char *d, int n)
1838 for(i = 0; i < n; i++)
1839 log_std(cd, "%02hhx ", (char)d[i]);
1842 int crypt_dump(struct crypt_device *cd)
1845 if (!isLUKS(cd->type)) { //FIXME
1846 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1850 log_std(cd, "LUKS header information for %s\n\n", mdata_device(cd));
1851 log_std(cd, "Version: \t%d\n", cd->hdr.version);
1852 log_std(cd, "Cipher name: \t%s\n", cd->hdr.cipherName);
1853 log_std(cd, "Cipher mode: \t%s\n", cd->hdr.cipherMode);
1854 log_std(cd, "Hash spec: \t%s\n", cd->hdr.hashSpec);
1855 log_std(cd, "Payload offset:\t%d\n", cd->hdr.payloadOffset);
1856 log_std(cd, "MK bits: \t%d\n", cd->hdr.keyBytes * 8);
1857 log_std(cd, "MK digest: \t");
1858 hexprintICB(cd, cd->hdr.mkDigest, LUKS_DIGESTSIZE);
1860 log_std(cd, "MK salt: \t");
1861 hexprintICB(cd, cd->hdr.mkDigestSalt, LUKS_SALTSIZE/2);
1862 log_std(cd, "\n \t");
1863 hexprintICB(cd, cd->hdr.mkDigestSalt+LUKS_SALTSIZE/2, LUKS_SALTSIZE/2);
1865 log_std(cd, "MK iterations: \t%d\n", cd->hdr.mkDigestIterations);
1866 log_std(cd, "UUID: \t%s\n\n", cd->hdr.uuid);
1867 for(i = 0; i < LUKS_NUMKEYS; i++) {
1868 if(cd->hdr.keyblock[i].active == LUKS_KEY_ENABLED) {
1869 log_std(cd, "Key Slot %d: ENABLED\n",i);
1870 log_std(cd, "\tIterations: \t%d\n",
1871 cd->hdr.keyblock[i].passwordIterations);
1872 log_std(cd, "\tSalt: \t");
1873 hexprintICB(cd, cd->hdr.keyblock[i].passwordSalt,
1875 log_std(cd, "\n\t \t");
1876 hexprintICB(cd, cd->hdr.keyblock[i].passwordSalt +
1877 LUKS_SALTSIZE/2, LUKS_SALTSIZE/2);
1880 log_std(cd, "\tKey material offset:\t%d\n",
1881 cd->hdr.keyblock[i].keyMaterialOffset);
1882 log_std(cd, "\tAF stripes: \t%d\n",
1883 cd->hdr.keyblock[i].stripes);
1886 log_std(cd, "Key Slot %d: DISABLED\n", i);
1892 const char *crypt_get_cipher(struct crypt_device *cd)
1894 if (isPLAIN(cd->type))
1895 return cd->plain_cipher;
1897 if (isLUKS(cd->type))
1898 return cd->hdr.cipherName;
1900 if (isLOOPAES(cd->type))
1901 return cd->loopaes_cipher;
1906 const char *crypt_get_cipher_mode(struct crypt_device *cd)
1908 if (isPLAIN(cd->type))
1909 return cd->plain_cipher_mode;
1911 if (isLUKS(cd->type))
1912 return cd->hdr.cipherMode;
1914 if (isLOOPAES(cd->type))
1915 return cd->loopaes_cipher_mode;
1920 const char *crypt_get_uuid(struct crypt_device *cd)
1922 if (isLUKS(cd->type))
1923 return cd->hdr.uuid;
1925 if (isPLAIN(cd->type))
1926 return cd->plain_uuid;
1928 if (isLOOPAES(cd->type))
1929 return cd->loopaes_uuid;
1934 const char *crypt_get_device_name(struct crypt_device *cd)
1940 int crypt_get_volume_key_size(struct crypt_device *cd)
1942 if (isPLAIN(cd->type) && cd->volume_key)
1943 return cd->volume_key->keylength;
1945 if (isLUKS(cd->type))
1946 return cd->hdr.keyBytes;
1948 if (isLOOPAES(cd->type))
1949 return cd->loopaes_key_size;
1954 uint64_t crypt_get_data_offset(struct crypt_device *cd)
1956 if (isPLAIN(cd->type))
1957 return cd->plain_hdr.offset;
1959 if (isLUKS(cd->type))
1960 return cd->hdr.payloadOffset;
1962 if (isLOOPAES(cd->type))
1963 return cd->loopaes_hdr.offset;
1968 uint64_t crypt_get_iv_offset(struct crypt_device *cd)
1970 if (isPLAIN(cd->type))
1971 return cd->plain_hdr.skip;
1973 if (isLUKS(cd->type))
1976 if (isLOOPAES(cd->type))
1977 return cd->loopaes_hdr.skip;
1982 crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot)
1984 if (!isLUKS(cd->type)) {
1985 log_err(cd, _("This operation is supported only for LUKS device.\n"));
1986 return CRYPT_SLOT_INVALID;
1989 return LUKS_keyslot_info(&cd->hdr, keyslot);
1992 int crypt_keyslot_max(const char *type)
1994 if (type && isLUKS(type))
1995 return LUKS_NUMKEYS;
2000 const char *crypt_get_type(struct crypt_device *cd)
2005 int crypt_get_active_device(struct crypt_device *cd __attribute__((unused)),
2007 struct crypt_active_device *cad)
2009 struct crypt_dm_active_device dmd;
2012 r = dm_query_device(name, 0, &dmd);
2016 cad->offset = dmd.offset;
2017 cad->iv_offset = dmd.iv_offset;
2018 cad->size = dmd.size;
2019 cad->flags = dmd.flags;