2 * libcryptsetup - cryptsetup library
4 * Copyright (C) 2004 Jana Saout <jana@saout.de>
5 * Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
6 * Copyright (C) 2009-2020 Red Hat, Inc. All rights reserved.
7 * Copyright (C) 2009-2020 Milan Broz
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * @file libcryptsetup.h
26 * @brief Public cryptsetup API
28 * For more verbose examples of LUKS related use cases,
29 * please read @ref index "examples".
32 #ifndef _LIBCRYPTSETUP_H
33 #define _LIBCRYPTSETUP_H
42 * @defgroup crypt-init Cryptsetup device context initialization
43 * Set of functions for creating and destroying @e crypt_device context
44 * @addtogroup crypt-init
48 struct crypt_device; /* crypt device handle */
51 * Initialize crypt device handle and check if the provided device exists.
53 * @param cd Returns pointer to crypt device handle
54 * @param device Path to the backing device.
55 * If @e device is not a block device but a path to some file,
56 * the function will try to create a loopdevice and attach
57 * the file to the loopdevice with AUTOCLEAR flag set.
58 * If @e device is @e NULL function it will initialize dm backend only.
60 * @return @e 0 on success or negative errno value otherwise.
62 * @note Note that logging is not initialized here, possible messages use
63 * default log function.
65 int crypt_init(struct crypt_device **cd, const char *device);
68 * Initialize crypt device handle with optional data device and check
71 * @param cd Returns pointer to crypt device handle
72 * @param device Path to the backing device or detached header.
73 * @param data_device Path to the data device or @e NULL.
75 * @return @e 0 on success or negative errno value otherwise.
77 * @note Note that logging is not initialized here, possible messages use
78 * default log function.
80 int crypt_init_data_device(struct crypt_device **cd,
82 const char *data_device);
85 * Initialize crypt device handle from provided active device name,
86 * and, optionally, from separate metadata (header) device
87 * and check if provided device exists.
89 * @return @e 0 on success or negative errno value otherwise.
91 * @param cd returns crypt device handle for active device
92 * @param name name of active crypt device
93 * @param header_device optional device containing on-disk header
94 * (@e NULL if it the same as underlying device on there is no on-disk header)
96 * @post In case @e device points to active LUKS device but header load fails,
97 * context device type is set to @e NULL and @e 0 is returned as if it were successful.
98 * Context with @e NULL device type can only be deactivated by crypt_deactivate
100 * @note @link crypt_init_by_name @endlink is equivalent to calling
101 * crypt_init_by_name_and_header(cd, name, NULL);
103 int crypt_init_by_name_and_header(struct crypt_device **cd,
105 const char *header_device);
108 * This is equivalent to call
109 * @ref crypt_init_by_name_and_header "crypt_init_by_name_and_header(cd, name, NULL)"
111 * @sa crypt_init_by_name_and_header
113 int crypt_init_by_name(struct crypt_device **cd, const char *name);
116 * Release crypt device context and used memory.
118 * @param cd crypt device handle
120 void crypt_free(struct crypt_device *cd);
123 * Set confirmation callback (yes/no).
125 * If code need confirmation (like resetting uuid or restoring LUKS header from file)
126 * this function is called. If not defined, everything is confirmed.
128 * Callback function @e confirm should return @e 0 if operation is declined,
129 * other values mean accepted.
131 * @param cd crypt device handle
132 * @param confirm user defined confirm callback reference
133 * @param usrptr provided identification in callback
134 * @param msg Message for user to confirm
136 * @note Current version of cryptsetup API requires confirmation for UUID change and
137 * LUKS header restore only.
139 void crypt_set_confirm_callback(struct crypt_device *cd,
140 int (*confirm)(const char *msg, void *usrptr),
145 * For LUKS it is encrypted data device when LUKS header is separated.
146 * For VERITY it is data device when hash device is separated.
148 * @param cd crypt device handle
149 * @param device path to device
151 * @returns 0 on success or negative errno value otherwise.
153 int crypt_set_data_device(struct crypt_device *cd, const char *device);
156 * Set data device offset in 512-byte sectors.
158 * This function is replacement for data alignment fields in LUKS param struct.
159 * If set to 0 (default), old behaviour is preserved.
160 * This value is reset on @link crypt_load @endlink.
162 * @param cd crypt device handle
163 * @param data_offset data offset in bytes
165 * @returns 0 on success or negative errno value otherwise.
167 * @note Data offset must be aligned to multiple of 8 (alignment to 4096-byte sectors)
168 * and must be big enough to accommodate the whole LUKS header with all keyslots.
169 * @note Data offset is enforced by this function, device topology
170 * information is no longer used after calling this function.
172 int crypt_set_data_offset(struct crypt_device *cd, uint64_t data_offset);
177 * @defgroup crypt-log Cryptsetup logging
178 * Set of functions and defines used in cryptsetup for
180 * @addtogroup crypt-log
184 /** normal log level */
185 #define CRYPT_LOG_NORMAL 0
186 /** error log level */
187 #define CRYPT_LOG_ERROR 1
188 /** verbose log level */
189 #define CRYPT_LOG_VERBOSE 2
190 /** debug log level - always on stdout */
191 #define CRYPT_LOG_DEBUG -1
192 /** debug log level - additional JSON output (for LUKS2) */
193 #define CRYPT_LOG_DEBUG_JSON -2
198 * @param cd crypt device handle (can be @e NULL to set default log function)
199 * @param log user defined log function reference
200 * @param usrptr provided identification in callback
201 * @param level log level below (debug messages can uses other levels)
202 * @param msg log message
204 void crypt_set_log_callback(struct crypt_device *cd,
205 void (*log)(int level, const char *msg, void *usrptr),
209 * Defines log function or use the default one otherwise.
211 * @see crypt_set_log_callback
213 * @param cd crypt device handle
214 * @param level log level
215 * @param msg log message
217 void crypt_log(struct crypt_device *cd, int level, const char *msg);
221 * @defgroup crypt-set Cryptsetup settings (RNG, PBKDF, locking)
222 * @addtogroup crypt-set
226 /** CRYPT_RNG_URANDOM - use /dev/urandom */
227 #define CRYPT_RNG_URANDOM 0
228 /** CRYPT_RNG_RANDOM - use /dev/random (waits if no entropy in system) */
229 #define CRYPT_RNG_RANDOM 1
232 * Set which RNG (random number generator) is used for generating long term key
234 * @param cd crypt device handle
235 * @param rng_type kernel random number generator to use
238 void crypt_set_rng_type(struct crypt_device *cd, int rng_type);
241 * Get which RNG (random number generator) is used for generating long term key.
243 * @param cd crypt device handle
244 * @return RNG type on success or negative errno value otherwise.
247 int crypt_get_rng_type(struct crypt_device *cd);
252 struct crypt_pbkdf_type {
253 const char *type; /**< PBKDF algorithm */
254 const char *hash; /**< Hash algorithm */
255 uint32_t time_ms; /**< Requested time cost [milliseconds] */
256 uint32_t iterations; /**< Iterations, 0 or benchmarked value. */
257 uint32_t max_memory_kb; /**< Requested or benchmarked memory cost [kilobytes] */
258 uint32_t parallel_threads;/**< Requested parallel cost [threads] */
259 uint32_t flags; /**< CRYPT_PBKDF* flags */
262 /** Iteration time set by crypt_set_iteration_time(), for compatibility only. */
263 #define CRYPT_PBKDF_ITER_TIME_SET (1 << 0)
264 /** Never run benchmarks, use pre-set value or defaults. */
265 #define CRYPT_PBKDF_NO_BENCHMARK (1 << 1)
267 /** PBKDF2 according to RFC2898, LUKS1 legacy */
268 #define CRYPT_KDF_PBKDF2 "pbkdf2"
269 /** Argon2i according to RFC */
270 #define CRYPT_KDF_ARGON2I "argon2i"
271 /** Argon2id according to RFC */
272 #define CRYPT_KDF_ARGON2ID "argon2id"
275 * Set default PBKDF (Password-Based Key Derivation Algorithm) for next keyslot
276 * about to get created with any crypt_keyslot_add_*() call.
278 * @param cd crypt device handle
279 * @param pbkdf PBKDF parameters
281 * @return 0 on success or negative errno value otherwise.
283 * @note For LUKS1, only PBKDF2 is supported, other settings will be rejected.
284 * @note For non-LUKS context types the call succeeds, but PBKDF is not used.
286 int crypt_set_pbkdf_type(struct crypt_device *cd,
287 const struct crypt_pbkdf_type *pbkdf);
290 * Get PBKDF (Password-Based Key Derivation Algorithm) parameters.
292 * @param pbkdf_type type of PBKDF
294 * @return struct on success or NULL value otherwise.
297 const struct crypt_pbkdf_type *crypt_get_pbkdf_type_params(const char *pbkdf_type);
300 * Get default PBKDF (Password-Based Key Derivation Algorithm) settings for keyslots.
301 * Works only with LUKS device handles (both versions).
303 * @param type type of device (see @link crypt-type @endlink)
305 * @return struct on success or NULL value otherwise.
308 const struct crypt_pbkdf_type *crypt_get_pbkdf_default(const char *type);
311 * Get current PBKDF (Password-Based Key Derivation Algorithm) settings for keyslots.
312 * Works only with LUKS device handles (both versions).
314 * @param cd crypt device handle
316 * @return struct on success or NULL value otherwise.
319 const struct crypt_pbkdf_type *crypt_get_pbkdf_type(struct crypt_device *cd);
322 * Set how long should cryptsetup iterate in PBKDF2 function.
323 * Default value heads towards the iterations which takes around 1 second.
324 * \b Deprecated, only for backward compatibility.
325 * Use @link crypt_set_pbkdf_type @endlink.
327 * @param cd crypt device handle
328 * @param iteration_time_ms the time in ms
330 * @note If the time value is not acceptable for active PBKDF, value is quietly ignored.
332 void crypt_set_iteration_time(struct crypt_device *cd, uint64_t iteration_time_ms);
335 * Helper to lock/unlock memory to avoid swap sensitive data to disk.
337 * @param cd crypt device handle, can be @e NULL
338 * @param lock 0 to unlock otherwise lock memory
340 * @returns Value indicating whether the memory is locked (function can be called multiple times).
342 * @note Only root can do this.
343 * @note It locks/unlocks all process memory, not only crypt context.
345 int crypt_memory_lock(struct crypt_device *cd, int lock);
348 * Set global lock protection for on-disk metadata (file-based locking).
350 * @param cd crypt device handle, can be @e NULL
351 * @param enable 0 to disable locking otherwise enable it (default)
353 * @returns @e 0 on success or negative errno value otherwise.
355 * @note Locking applied only for some metadata formats (LUKS2).
356 * @note The switch is global on the library level.
357 * In current version locking can be only switched off and cannot be switched on later.
359 int crypt_metadata_locking(struct crypt_device *cd, int enable);
362 * Set metadata header area sizes. This applies only to LUKS2.
363 * These values limit amount of metadata anf number of supportable keyslots.
365 * @param cd crypt device handle, can be @e NULL
366 * @param metadata_size size in bytes of JSON area + 4k binary header
367 * @param keyslots_size size in bytes of binary keyslots area
369 * @returns @e 0 on success or negative errno value otherwise.
371 * @note The metadata area is stored twice and both copies contain 4k binary header.
372 * Only 16,32,64,128,256,512,1024,2048 and 4096 kB value is allowed (see LUKS2 specification).
373 * @note Keyslots area size must be multiple of 4k with maximum 128MB.
375 int crypt_set_metadata_size(struct crypt_device *cd,
376 uint64_t metadata_size,
377 uint64_t keyslots_size);
380 * Get metadata header area sizes. This applies only to LUKS2.
381 * These values limit amount of metadata anf number of supportable keyslots.
383 * @param cd crypt device handle
384 * @param metadata_size size in bytes of JSON area + 4k binary header
385 * @param keyslots_size size in bytes of binary keyslots area
387 * @returns @e 0 on success or negative errno value otherwise.
389 int crypt_get_metadata_size(struct crypt_device *cd,
390 uint64_t *metadata_size,
391 uint64_t *keyslots_size);
396 * @defgroup crypt-type Cryptsetup on-disk format types
397 * Set of functions, \#defines and structs related
398 * to on-disk format types
399 * @addtogroup crypt-type
403 /** plain crypt device, no on-disk header */
404 #define CRYPT_PLAIN "PLAIN"
405 /** LUKS version 1 header on-disk */
406 #define CRYPT_LUKS1 "LUKS1"
407 /** LUKS version 2 header on-disk */
408 #define CRYPT_LUKS2 "LUKS2"
409 /** loop-AES compatibility mode */
410 #define CRYPT_LOOPAES "LOOPAES"
411 /** dm-verity mode */
412 #define CRYPT_VERITY "VERITY"
413 /** TCRYPT (TrueCrypt-compatible and VeraCrypt-compatible) mode */
414 #define CRYPT_TCRYPT "TCRYPT"
415 /** INTEGRITY dm-integrity device */
416 #define CRYPT_INTEGRITY "INTEGRITY"
417 /** BITLK (BitLocker-compatible mode) */
418 #define CRYPT_BITLK "BITLK"
420 /** LUKS any version */
421 #define CRYPT_LUKS NULL
426 * @param cd crypt device handle
427 * @return string according to device type or @e NULL if not known.
429 const char *crypt_get_type(struct crypt_device *cd);
432 * Get device default LUKS type
434 * @return string according to device type (CRYPT_LUKS1 or CRYPT_LUKS2).
436 const char *crypt_get_default_type(void);
440 * Structure used as parameter for PLAIN device type.
444 struct crypt_params_plain {
445 const char *hash; /**< password hash function */
446 uint64_t offset; /**< offset in sectors */
447 uint64_t skip; /**< IV offset / initialization sector */
448 uint64_t size; /**< size of mapped device or @e 0 for autodetection */
449 uint32_t sector_size; /**< sector size in bytes (@e 0 means 512 for compatibility) */
453 * Structure used as parameter for LUKS device type.
455 * @see crypt_format, crypt_load
457 * @note during crypt_format @e data_device attribute determines
458 * if the LUKS header is separated from encrypted payload device
461 struct crypt_params_luks1 {
462 const char *hash; /**< hash used in LUKS header */
463 size_t data_alignment; /**< data area alignment in 512B sectors, data offset is multiple of this */
464 const char *data_device; /**< detached encrypted data device or @e NULL */
469 * Structure used as parameter for loop-AES device type.
474 struct crypt_params_loopaes {
475 const char *hash; /**< key hash function */
476 uint64_t offset; /**< offset in sectors */
477 uint64_t skip; /**< IV offset / initialization sector */
482 * Structure used as parameter for dm-verity device type.
484 * @see crypt_format, crypt_load
487 struct crypt_params_verity {
488 const char *hash_name; /**< hash function */
489 const char *data_device; /**< data_device (CRYPT_VERITY_CREATE_HASH) */
490 const char *hash_device; /**< hash_device (output only) */
491 const char *fec_device; /**< fec_device (output only) */
492 const char *salt; /**< salt */
493 uint32_t salt_size; /**< salt size (in bytes) */
494 uint32_t hash_type; /**< in-kernel hashing type */
495 uint32_t data_block_size; /**< data block size (in bytes) */
496 uint32_t hash_block_size; /**< hash block size (in bytes) */
497 uint64_t data_size; /**< data area size (in data blocks) */
498 uint64_t hash_area_offset; /**< hash/header offset (in bytes) */
499 uint64_t fec_area_offset; /**< FEC/header offset (in bytes) */
500 uint32_t fec_roots; /**< Reed-Solomon FEC roots */
501 uint32_t flags; /**< CRYPT_VERITY* flags */
504 /** No on-disk header (only hashes) */
505 #define CRYPT_VERITY_NO_HEADER (1 << 0)
506 /** Verity hash in userspace before activation */
507 #define CRYPT_VERITY_CHECK_HASH (1 << 1)
508 /** Create hash - format hash device */
509 #define CRYPT_VERITY_CREATE_HASH (1 << 2)
510 /** Root hash signature required for activation */
511 #define CRYPT_VERITY_ROOT_HASH_SIGNATURE (1 << 3)
515 * Structure used as parameter for TCRYPT device type.
520 struct crypt_params_tcrypt {
521 const char *passphrase; /**< passphrase to unlock header (input only) */
522 size_t passphrase_size; /**< passphrase size (input only, max length is 64) */
523 const char **keyfiles; /**< keyfile paths to unlock header (input only) */
524 unsigned int keyfiles_count;/**< keyfiles count (input only) */
525 const char *hash_name; /**< hash function for PBKDF */
526 const char *cipher; /**< cipher chain c1[-c2[-c3]] */
527 const char *mode; /**< cipher block mode */
528 size_t key_size; /**< key size in bytes (the whole chain) */
529 uint32_t flags; /**< CRYPT_TCRYPT* flags */
530 uint32_t veracrypt_pim; /**< VeraCrypt Personal Iteration Multiplier */
533 /** Include legacy modes when scanning for header */
534 #define CRYPT_TCRYPT_LEGACY_MODES (1 << 0)
535 /** Try to load hidden header (describing hidden device) */
536 #define CRYPT_TCRYPT_HIDDEN_HEADER (1 << 1)
537 /** Try to load backup header */
538 #define CRYPT_TCRYPT_BACKUP_HEADER (1 << 2)
539 /** Device contains encrypted system (with boot loader) */
540 #define CRYPT_TCRYPT_SYSTEM_HEADER (1 << 3)
541 /** Include VeraCrypt modes when scanning for header,
542 * all other TCRYPT flags applies as well.
543 * VeraCrypt device is reported as TCRYPT type.
545 #define CRYPT_TCRYPT_VERA_MODES (1 << 4)
549 * Structure used as parameter for dm-integrity device type.
551 * @see crypt_format, crypt_load
553 * @note In bitmap tracking mode, the journal is implicitly disabled.
554 * As an ugly workaround for compatibility, journal_watermark is overloaded
555 * to mean 512-bytes sectors-per-bit and journal_commit_time means bitmap flush time.
556 * All other journal parameters are not applied in the bitmap mode.
558 struct crypt_params_integrity {
559 uint64_t journal_size; /**< size of journal in bytes */
560 unsigned int journal_watermark; /**< journal flush watermark in percents; in bitmap mode sectors-per-bit */
561 unsigned int journal_commit_time; /**< journal commit time (or bitmap flush time) in ms */
562 uint32_t interleave_sectors; /**< number of interleave sectors (power of two) */
563 uint32_t tag_size; /**< tag size per-sector in bytes */
564 uint32_t sector_size; /**< sector size in bytes */
565 uint32_t buffer_sectors; /**< number of sectors in one buffer */
566 const char *integrity; /**< integrity algorithm, NULL for LUKS2 */
567 uint32_t integrity_key_size; /**< integrity key size in bytes, info only, 0 for LUKS2 */
569 const char *journal_integrity; /**< journal integrity algorithm */
570 const char *journal_integrity_key; /**< journal integrity key, only for crypt_load */
571 uint32_t journal_integrity_key_size; /**< journal integrity key size in bytes, only for crypt_load */
573 const char *journal_crypt; /**< journal encryption algorithm */
574 const char *journal_crypt_key; /**< journal crypt key, only for crypt_load */
575 uint32_t journal_crypt_key_size; /**< journal crypt key size in bytes, only for crypt_load */
579 * Structure used as parameter for LUKS2 device type.
581 * @see crypt_format, crypt_load
583 * @note during crypt_format @e data_device attribute determines
584 * if the LUKS2 header is separated from encrypted payload device
587 struct crypt_params_luks2 {
588 const struct crypt_pbkdf_type *pbkdf; /**< PBKDF (and hash) parameters or @e NULL*/
589 const char *integrity; /**< integrity algorithm or @e NULL */
590 const struct crypt_params_integrity *integrity_params; /**< Data integrity parameters or @e NULL*/
591 size_t data_alignment; /**< data area alignment in 512B sectors, data offset is multiple of this */
592 const char *data_device; /**< detached encrypted data device or @e NULL */
593 uint32_t sector_size; /**< encryption sector size */
594 const char *label; /**< header label or @e NULL*/
595 const char *subsystem; /**< header subsystem label or @e NULL*/
600 * @defgroup crypt-actions Cryptsetup device context actions
601 * Set of functions for formatting and manipulating with specific crypt_type
602 * @addtogroup crypt-actions
607 * Create (format) new crypt device (and possible header on-disk) but do not activate it.
609 * @pre @e cd contains initialized and not formatted device context (device type must @b not be set)
611 * @param cd crypt device handle
612 * @param type type of device (optional params struct must be of this type)
613 * @param cipher (e.g. "aes")
614 * @param cipher_mode including IV specification (e.g. "xts-plain")
615 * @param uuid requested UUID or @e NULL if it should be generated
616 * @param volume_key pre-generated volume key or @e NULL if it should be generated (only for LUKS)
617 * @param volume_key_size size of volume key in bytes.
618 * @param params crypt type specific parameters (see @link crypt-type @endlink)
620 * @returns @e 0 on success or negative errno value otherwise.
622 * @note Note that crypt_format does not create LUKS keyslot (any version). To create keyslot
623 * call any crypt_keyslot_add_* function.
624 * @note For VERITY @link crypt-type @endlink, only uuid parameter is used, other parameters
625 * are ignored and verity specific attributes are set through mandatory params option.
627 int crypt_format(struct crypt_device *cd,
630 const char *cipher_mode,
632 const char *volume_key,
633 size_t volume_key_size,
637 * Set format compatibility flags.
639 * @param cd crypt device handle
640 * @param flags CRYPT_COMPATIBILITY_* flags
642 void crypt_set_compatibility(struct crypt_device *cd, uint32_t flags);
645 * Get compatibility flags.
647 * @param cd crypt device handle
649 * @returns compatibility flags
651 uint32_t crypt_get_compatibility(struct crypt_device *cd);
653 /** dm-integrity device uses less effective (legacy) padding (old kernels) */
654 #define CRYPT_COMPAT_LEGACY_INTEGRITY_PADDING (1 << 0)
657 * Convert to new type for already existing device.
659 * @param cd crypt device handle
660 * @param type type of device (optional params struct must be of this type)
661 * @param params crypt type specific parameters (see @link crypt-type @endlink)
663 * @returns 0 on success or negative errno value otherwise.
665 * @note Currently, only LUKS1->LUKS2 and LUKS2->LUKS1 conversions are supported.
666 * Not all LUKS2 devices may be converted back to LUKS1. To make such a conversion
667 * possible all active LUKS2 keyslots must be in LUKS1 compatible mode (i.e. pbkdf
668 * type must be PBKDF2) and device cannot be formatted with any authenticated
671 * @note Device must be offline for conversion. UUID change is not possible for active
674 int crypt_convert(struct crypt_device *cd,
679 * Set new UUID for already existing device.
681 * @param cd crypt device handle
682 * @param uuid requested UUID or @e NULL if it should be generated
684 * @returns 0 on success or negative errno value otherwise.
686 * @note Currently, only LUKS device type are supported
688 int crypt_set_uuid(struct crypt_device *cd,
692 * Set new labels (label and subsystem) for already existing device.
694 * @param cd crypt device handle
695 * @param label requested label or @e NULL
696 * @param subsystem requested subsystem label or @e NULL
698 * @returns 0 on success or negative errno value otherwise.
700 * @note Currently, only LUKS2 device type is supported
702 int crypt_set_label(struct crypt_device *cd,
704 const char *subsystem);
707 * Enable or disable loading of volume keys via kernel keyring. When set to
708 * 'enabled' library loads key in kernel keyring first and pass the key
709 * description to dm-crypt instead of binary key copy. If set to 'disabled'
710 * library fallbacks to old method of loading volume key directly in
713 * @param cd crypt device handle, can be @e NULL
714 * @param enable 0 to disable loading of volume keys via kernel keyring
715 * (classical method) otherwise enable it (default)
717 * @returns @e 0 on success or negative errno value otherwise.
719 * @note Currently loading of volume keys via kernel keyring is supported
720 * (and enabled by default) only for LUKS2 devices.
721 * @note The switch is global on the library level.
723 int crypt_volume_key_keyring(struct crypt_device *cd, int enable);
726 * Load crypt device parameters from on-disk header.
728 * @param cd crypt device handle
729 * @param requested_type @link crypt-type @endlink or @e NULL for all known
730 * @param params crypt type specific parameters (see @link crypt-type @endlink)
732 * @returns 0 on success or negative errno value otherwise.
734 * @post In case LUKS header is read successfully but payload device is too small
735 * error is returned and device type in context is set to @e NULL
737 * @note Note that in current version load works only for LUKS and VERITY device type.
740 int crypt_load(struct crypt_device *cd,
741 const char *requested_type,
745 * Try to repair crypt device LUKS on-disk header if invalid.
747 * @param cd crypt device handle
748 * @param requested_type @link crypt-type @endlink or @e NULL for all known
749 * @param params crypt type specific parameters (see @link crypt-type @endlink)
751 * @returns 0 on success or negative errno value otherwise.
753 * @note For LUKS2 device crypt_repair bypass blkid checks and
754 * perform auto-recovery even though there're third party device
755 * signatures found by blkid probes. Currently the crypt_repair on LUKS2
756 * works only if exactly one header checksum does not match or exactly
757 * one header is missing.
759 int crypt_repair(struct crypt_device *cd,
760 const char *requested_type,
764 * Resize crypt device.
766 * @param cd - crypt device handle
767 * @param name - name of device to resize
768 * @param new_size - new device size in sectors or @e 0 to use all of the underlying device size
770 * @return @e 0 on success or negative errno value otherwise.
772 * @note Most notably it returns -EPERM when device was activated with volume key
773 * in kernel keyring and current device handle (context) doesn't have verified key
774 * loaded in kernel. To load volume key for already active device use any of
775 * @link crypt_activate_by_passphrase @endlink, @link crypt_activate_by_keyfile @endlink,
776 * @link crypt_activate_by_keyfile_offset @endlink, @link crypt_activate_by_volume_key @endlink,
777 * @link crypt_activate_by_keyring @endlink or @link crypt_activate_by_token @endlink with flag
778 * @e CRYPT_ACTIVATE_KEYRING_KEY raised and @e name parameter set to @e NULL.
780 int crypt_resize(struct crypt_device *cd,
785 * Suspend crypt device.
787 * @param cd crypt device handle, can be @e NULL
788 * @param name name of device to suspend
790 * @return 0 on success or negative errno value otherwise.
792 * @note Only LUKS device type is supported
795 int crypt_suspend(struct crypt_device *cd,
799 * Resume crypt device using passphrase.
802 * @param cd crypt device handle
803 * @param name name of device to resume
804 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
805 * @param passphrase passphrase used to unlock volume key
806 * @param passphrase_size size of @e passphrase (binary data)
808 * @return unlocked key slot number or negative errno otherwise.
810 * @note Only LUKS device type is supported
812 int crypt_resume_by_passphrase(struct crypt_device *cd,
815 const char *passphrase,
816 size_t passphrase_size);
819 * Resume crypt device using key file.
821 * @param cd crypt device handle
822 * @param name name of device to resume
823 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
824 * @param keyfile key file used to unlock volume key
825 * @param keyfile_size number of bytes to read from keyfile, 0 is unlimited
826 * @param keyfile_offset number of bytes to skip at start of keyfile
828 * @return unlocked key slot number or negative errno otherwise.
830 int crypt_resume_by_keyfile_device_offset(struct crypt_device *cd,
835 uint64_t keyfile_offset);
838 * Backward compatible crypt_resume_by_keyfile_device_offset() (with size_t offset).
840 int crypt_resume_by_keyfile_offset(struct crypt_device *cd,
845 size_t keyfile_offset);
848 * Backward compatible crypt_resume_by_keyfile_device_offset() (without offset).
850 int crypt_resume_by_keyfile(struct crypt_device *cd,
854 size_t keyfile_size);
856 * Resume crypt device using provided volume key.
858 * @param cd crypt device handle
859 * @param name name of device to resume
860 * @param volume_key provided volume key
861 * @param volume_key_size size of volume_key
863 * @return @e 0 on success or negative errno value otherwise.
865 int crypt_resume_by_volume_key(struct crypt_device *cd,
867 const char *volume_key,
868 size_t volume_key_size);
872 * @defgroup crypt-keyslot LUKS keyslots
873 * @addtogroup crypt-keyslot
877 /** iterate through all keyslots and find first one that fits */
878 #define CRYPT_ANY_SLOT -1
881 * Add key slot using provided passphrase.
883 * @pre @e cd contains initialized and formatted LUKS device context
885 * @param cd crypt device handle
886 * @param keyslot requested keyslot or @e CRYPT_ANY_SLOT
887 * @param passphrase passphrase used to unlock volume key
888 * @param passphrase_size size of passphrase (binary data)
889 * @param new_passphrase passphrase for new keyslot
890 * @param new_passphrase_size size of @e new_passphrase (binary data)
892 * @return allocated key slot number or negative errno otherwise.
894 int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
896 const char *passphrase,
897 size_t passphrase_size,
898 const char *new_passphrase,
899 size_t new_passphrase_size);
902 * Change defined key slot using provided passphrase.
904 * @pre @e cd contains initialized and formatted LUKS device context
906 * @param cd crypt device handle
907 * @param keyslot_old old keyslot or @e CRYPT_ANY_SLOT
908 * @param keyslot_new new keyslot (can be the same as old)
909 * @param passphrase passphrase used to unlock volume key
910 * @param passphrase_size size of passphrase (binary data)
911 * @param new_passphrase passphrase for new keyslot
912 * @param new_passphrase_size size of @e new_passphrase (binary data)
914 * @return allocated key slot number or negative errno otherwise.
916 int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
919 const char *passphrase,
920 size_t passphrase_size,
921 const char *new_passphrase,
922 size_t new_passphrase_size);
925 * Add key slot using provided key file path.
927 * @pre @e cd contains initialized and formatted LUKS device context
929 * @param cd crypt device handle
930 * @param keyslot requested keyslot or @e CRYPT_ANY_SLOT
931 * @param keyfile key file used to unlock volume key
932 * @param keyfile_size number of bytes to read from keyfile, @e 0 is unlimited
933 * @param keyfile_offset number of bytes to skip at start of keyfile
934 * @param new_keyfile keyfile for new keyslot
935 * @param new_keyfile_size number of bytes to read from @e new_keyfile, @e 0 is unlimited
936 * @param new_keyfile_offset number of bytes to skip at start of new_keyfile
938 * @return allocated key slot number or negative errno otherwise.
940 int crypt_keyslot_add_by_keyfile_device_offset(struct crypt_device *cd,
944 uint64_t keyfile_offset,
945 const char *new_keyfile,
946 size_t new_keyfile_size,
947 uint64_t new_keyfile_offset);
950 * Backward compatible crypt_keyslot_add_by_keyfile_device_offset() (with size_t offset).
952 int crypt_keyslot_add_by_keyfile_offset(struct crypt_device *cd,
956 size_t keyfile_offset,
957 const char *new_keyfile,
958 size_t new_keyfile_size,
959 size_t new_keyfile_offset);
962 * Backward compatible crypt_keyslot_add_by_keyfile_device_offset() (without offset).
964 int crypt_keyslot_add_by_keyfile(struct crypt_device *cd,
968 const char *new_keyfile,
969 size_t new_keyfile_size);
972 * Add key slot using provided volume key.
974 * @pre @e cd contains initialized and formatted LUKS device context
976 * @param cd crypt device handle
977 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
978 * @param volume_key provided volume key or @e NULL if used after crypt_format
979 * @param volume_key_size size of volume_key
980 * @param passphrase passphrase for new keyslot
981 * @param passphrase_size size of passphrase
983 * @return allocated key slot number or negative errno otherwise.
985 int crypt_keyslot_add_by_volume_key(struct crypt_device *cd,
987 const char *volume_key,
988 size_t volume_key_size,
989 const char *passphrase,
990 size_t passphrase_size);
992 /** create keyslot with volume key not associated with current dm-crypt segment */
993 #define CRYPT_VOLUME_KEY_NO_SEGMENT (1 << 0)
995 /** create keyslot with new volume key and assign it to current dm-crypt segment */
996 #define CRYPT_VOLUME_KEY_SET (1 << 1)
998 /** Assign key to first matching digest before creating new digest */
999 #define CRYPT_VOLUME_KEY_DIGEST_REUSE (1 << 2)
1002 * Add key slot using provided key.
1004 * @pre @e cd contains initialized and formatted LUKS2 device context
1006 * @param cd crypt device handle
1007 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
1008 * @param volume_key provided volume key or @e NULL (see note below)
1009 * @param volume_key_size size of volume_key
1010 * @param passphrase passphrase for new keyslot
1011 * @param passphrase_size size of passphrase
1012 * @param flags key flags to set
1014 * @return allocated key slot number or negative errno otherwise.
1016 * @note in case volume_key is @e NULL following first matching rule will apply:
1017 * @li if cd is device handle used in crypt_format() by current process, the volume
1018 * key generated (or passed) in crypt_format() will be stored in keyslot.
1019 * @li if CRYPT_VOLUME_KEY_NO_SEGMENT flag is raised the new volume_key will be
1020 * generated and stored in keyslot. The keyslot will become unbound (unusable to
1021 * dm-crypt device activation).
1022 * @li fails with -EINVAL otherwise
1024 * @warning CRYPT_VOLUME_KEY_SET flag force updates volume key. It is @b not @b reencryption!
1025 * By doing so you will most probably destroy your ciphertext data device. It's supposed
1026 * to be used only in wrapped keys scheme for key refresh process where real (inner) volume
1027 * key stays untouched. It may be involed on active @e keyslot which makes the (previously
1028 * unbound) keyslot new regular keyslot.
1030 int crypt_keyslot_add_by_key(struct crypt_device *cd,
1032 const char *volume_key,
1033 size_t volume_key_size,
1034 const char *passphrase,
1035 size_t passphrase_size,
1039 * Destroy (and disable) key slot.
1041 * @pre @e cd contains initialized and formatted LUKS device context
1043 * @param cd crypt device handle
1044 * @param keyslot requested key slot to destroy
1046 * @return @e 0 on success or negative errno value otherwise.
1048 * @note Note that there is no passphrase verification used.
1050 int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot);
1054 * @defgroup crypt-aflags Device runtime attributes
1056 * @addtogroup crypt-aflags
1060 /** device is read only */
1061 #define CRYPT_ACTIVATE_READONLY (1 << 0)
1062 /** only reported for device without uuid */
1063 #define CRYPT_ACTIVATE_NO_UUID (1 << 1)
1064 /** activate even if cannot grant exclusive access (DANGEROUS) */
1065 #define CRYPT_ACTIVATE_SHARED (1 << 2)
1066 /** enable discards aka TRIM */
1067 #define CRYPT_ACTIVATE_ALLOW_DISCARDS (1 << 3)
1068 /** skip global udev rules in activation ("private device"), input only */
1069 #define CRYPT_ACTIVATE_PRIVATE (1 << 4)
1070 /** corruption detected (verity), output only */
1071 #define CRYPT_ACTIVATE_CORRUPTED (1 << 5)
1072 /** use same_cpu_crypt option for dm-crypt */
1073 #define CRYPT_ACTIVATE_SAME_CPU_CRYPT (1 << 6)
1074 /** use submit_from_crypt_cpus for dm-crypt */
1075 #define CRYPT_ACTIVATE_SUBMIT_FROM_CRYPT_CPUS (1 << 7)
1076 /** dm-verity: ignore_corruption flag - ignore corruption, log it only */
1077 #define CRYPT_ACTIVATE_IGNORE_CORRUPTION (1 << 8)
1078 /** dm-verity: restart_on_corruption flag - restart kernel on corruption */
1079 #define CRYPT_ACTIVATE_RESTART_ON_CORRUPTION (1 << 9)
1080 /** dm-verity: ignore_zero_blocks - do not verify zero blocks */
1081 #define CRYPT_ACTIVATE_IGNORE_ZERO_BLOCKS (1 << 10)
1082 /** key loaded in kernel keyring instead directly in dm-crypt */
1083 #define CRYPT_ACTIVATE_KEYRING_KEY (1 << 11)
1084 /** dm-integrity: direct writes, do not use journal */
1085 #define CRYPT_ACTIVATE_NO_JOURNAL (1 << 12)
1086 /** dm-integrity: recovery mode - no journal, no integrity checks */
1087 #define CRYPT_ACTIVATE_RECOVERY (1 << 13)
1088 /** ignore persistently stored flags */
1089 #define CRYPT_ACTIVATE_IGNORE_PERSISTENT (1 << 14)
1090 /** dm-verity: check_at_most_once - check data blocks only the first time */
1091 #define CRYPT_ACTIVATE_CHECK_AT_MOST_ONCE (1 << 15)
1092 /** allow activation check including unbound keyslots (keyslots without segments) */
1093 #define CRYPT_ACTIVATE_ALLOW_UNBOUND_KEY (1 << 16)
1094 /** dm-integrity: activate automatic recalculation */
1095 #define CRYPT_ACTIVATE_RECALCULATE (1 << 17)
1096 /** reactivate existing and update flags, input only */
1097 #define CRYPT_ACTIVATE_REFRESH (1 << 18)
1098 /** Use global lock to serialize memory hard KDF on activation (OOM workaround) */
1099 #define CRYPT_ACTIVATE_SERIALIZE_MEMORY_HARD_PBKDF (1 << 19)
1100 /** dm-integrity: direct writes, use bitmap to track dirty sectors */
1101 #define CRYPT_ACTIVATE_NO_JOURNAL_BITMAP (1 << 20)
1102 /** device is suspended (key should be wiped from memory), output only */
1103 #define CRYPT_ACTIVATE_SUSPENDED (1 << 21)
1104 /** use IV sector counted in sector_size instead of default 512 bytes sectors */
1105 #define CRYPT_ACTIVATE_IV_LARGE_SECTORS (1 << 22)
1108 * Active device runtime attributes
1110 struct crypt_active_device {
1111 uint64_t offset; /**< offset in sectors */
1112 uint64_t iv_offset; /**< IV initialization sector */
1113 uint64_t size; /**< active device size */
1114 uint32_t flags; /**< activation flags */
1118 * Receive runtime attributes of active crypt device.
1120 * @param cd crypt device handle (can be @e NULL)
1121 * @param name name of active device
1122 * @param cad preallocated active device attributes to fill
1124 * @return @e 0 on success or negative errno value otherwise
1127 int crypt_get_active_device(struct crypt_device *cd,
1129 struct crypt_active_device *cad);
1132 * Get detected number of integrity failures.
1134 * @param cd crypt device handle (can be @e NULL)
1135 * @param name name of active device
1137 * @return number of integrity failures or @e 0 otherwise
1140 uint64_t crypt_get_active_integrity_failures(struct crypt_device *cd,
1145 * @defgroup crypt-pflags LUKS2 Device persistent flags and requirements
1146 * @addtogroup crypt-pflags
1151 * LUKS2 header requirements
1153 /** Unfinished offline reencryption */
1154 #define CRYPT_REQUIREMENT_OFFLINE_REENCRYPT (1 << 0)
1155 /** Online reencryption in-progress */
1156 #define CRYPT_REQUIREMENT_ONLINE_REENCRYPT (1 << 1)
1157 /** unknown requirement in header (output only) */
1158 #define CRYPT_REQUIREMENT_UNKNOWN (1 << 31)
1161 * Persistent flags type
1164 CRYPT_FLAGS_ACTIVATION, /**< activation flags, @see aflags */
1165 CRYPT_FLAGS_REQUIREMENTS /**< requirements flags */
1169 * Set persistent flags.
1171 * @param cd crypt device handle (can be @e NULL)
1172 * @param type type to set (CRYPT_FLAGS_ACTIVATION or CRYPT_FLAGS_REQUIREMENTS)
1173 * @param flags flags to set
1175 * @return @e 0 on success or negative errno value otherwise
1177 * @note Valid only for LUKS2.
1179 * @note Not all activation flags can be stored. Only ALLOW_DISCARD,
1180 * SAME_CPU_CRYPT, SUBMIT_FROM_CRYPT_CPU and NO_JOURNAL can be
1181 * stored persistently.
1183 * @note Only requirements flags recognised by current library may be set.
1184 * CRYPT_REQUIREMENT_UNKNOWN is illegal (output only) in set operation.
1186 int crypt_persistent_flags_set(struct crypt_device *cd,
1187 crypt_flags_type type,
1191 * Get persistent flags stored in header.
1193 * @param cd crypt device handle (can be @e NULL)
1194 * @param type flags type to retrieve (CRYPT_FLAGS_ACTIVATION or CRYPT_FLAGS_REQUIREMENTS)
1195 * @param flags reference to output variable
1197 * @return @e 0 on success or negative errno value otherwise
1199 int crypt_persistent_flags_get(struct crypt_device *cd,
1200 crypt_flags_type type,
1205 * @defgroup crypt-activation Device activation
1206 * @addtogroup crypt-activation
1211 * Activate device or check passphrase.
1213 * @param cd crypt device handle
1214 * @param name name of device to create, if @e NULL only check passphrase
1215 * @param keyslot requested keyslot to check or @e CRYPT_ANY_SLOT
1216 * @param passphrase passphrase used to unlock volume key
1217 * @param passphrase_size size of @e passphrase
1218 * @param flags activation flags
1220 * @return unlocked key slot number or negative errno otherwise.
1222 int crypt_activate_by_passphrase(struct crypt_device *cd,
1225 const char *passphrase,
1226 size_t passphrase_size,
1230 * Activate device or check using key file.
1232 * @param cd crypt device handle
1233 * @param name name of device to create, if @e NULL only check keyfile
1234 * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
1235 * @param keyfile key file used to unlock volume key
1236 * @param keyfile_size number of bytes to read from keyfile, 0 is unlimited
1237 * @param keyfile_offset number of bytes to skip at start of keyfile
1238 * @param flags activation flags
1240 * @return unlocked key slot number or negative errno otherwise.
1242 int crypt_activate_by_keyfile_device_offset(struct crypt_device *cd,
1245 const char *keyfile,
1246 size_t keyfile_size,
1247 uint64_t keyfile_offset,
1251 * Backward compatible crypt_activate_by_keyfile_device_offset() (with size_t offset).
1253 int crypt_activate_by_keyfile_offset(struct crypt_device *cd,
1256 const char *keyfile,
1257 size_t keyfile_size,
1258 size_t keyfile_offset,
1262 * Backward compatible crypt_activate_by_keyfile_device_offset() (without offset).
1264 int crypt_activate_by_keyfile(struct crypt_device *cd,
1267 const char *keyfile,
1268 size_t keyfile_size,
1272 * Activate device using provided volume key.
1274 * @param cd crypt device handle
1275 * @param name name of device to create, if @e NULL only check volume key
1276 * @param volume_key provided volume key (or @e NULL to use internal)
1277 * @param volume_key_size size of volume_key
1278 * @param flags activation flags
1280 * @return @e 0 on success or negative errno value otherwise.
1282 * @note If @e NULL is used for volume_key, device has to be initialized
1283 * by previous operation (like @ref crypt_format
1284 * or @ref crypt_init_by_name)
1285 * @note For VERITY the volume key means root hash required for activation.
1286 * Because kernel dm-verity is always read only, you have to provide
1287 * CRYPT_ACTIVATE_READONLY flag always.
1288 * @note For TCRYPT the volume key should be always NULL and because master
1289 * key from decrypted header is used instead.
1291 int crypt_activate_by_volume_key(struct crypt_device *cd,
1293 const char *volume_key,
1294 size_t volume_key_size,
1298 * Activate VERITY device using provided key and optional signature).
1300 * @param cd crypt device handle
1301 * @param name name of device to create
1302 * @param volume_key provided volume key
1303 * @param volume_key_size size of volume_key
1304 * @param signature buffer with signature for the key
1305 * @param signature_size bsize of signature buffer
1306 * @param flags activation flags
1308 * @return @e 0 on success or negative errno value otherwise.
1310 * @note For VERITY the volume key means root hash required for activation.
1311 * Because kernel dm-verity is always read only, you have to provide
1312 * CRYPT_ACTIVATE_READONLY flag always.
1314 int crypt_activate_by_signed_key(struct crypt_device *cd,
1316 const char *volume_key,
1317 size_t volume_key_size,
1318 const char *signature,
1319 size_t signature_size,
1323 * Activate device using passphrase stored in kernel keyring.
1325 * @param cd crypt device handle
1326 * @param name name of device to create, if @e NULL only check passphrase in keyring
1327 * @param key_description kernel keyring key description library should look
1329 * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
1330 * @param flags activation flags
1332 * @return @e unlocked keyslot number on success or negative errno value otherwise.
1334 * @note Keyslot passphrase must be stored in 'user' key type
1335 * and the key has to be reachable for process context
1336 * on behalf of which this function is called.
1338 int crypt_activate_by_keyring(struct crypt_device *cd,
1340 const char *key_description,
1344 /** lazy deactivation - remove once last user releases it */
1345 #define CRYPT_DEACTIVATE_DEFERRED (1 << 0)
1346 /** force deactivation - if the device is busy, it is replaced by error device */
1347 #define CRYPT_DEACTIVATE_FORCE (1 << 1)
1350 * Deactivate crypt device. This function tries to remove active device-mapper
1351 * mapping from kernel. Also, sensitive data like the volume key are removed from
1354 * @param cd crypt device handle, can be @e NULL
1355 * @param name name of device to deactivate
1356 * @param flags deactivation flags
1358 * @return @e 0 on success or negative errno value otherwise.
1361 int crypt_deactivate_by_name(struct crypt_device *cd,
1366 * Deactivate crypt device. See @ref crypt_deactivate_by_name with empty @e flags.
1368 int crypt_deactivate(struct crypt_device *cd, const char *name);
1372 * @defgroup crypt-key Volume Key manipulation
1373 * @addtogroup crypt-key
1378 * Get volume key from crypt device.
1380 * @param cd crypt device handle
1381 * @param keyslot use this keyslot or @e CRYPT_ANY_SLOT
1382 * @param volume_key buffer for volume key
1383 * @param volume_key_size on input, size of buffer @e volume_key,
1384 * on output size of @e volume_key
1385 * @param passphrase passphrase used to unlock volume key
1386 * @param passphrase_size size of @e passphrase
1388 * @return unlocked key slot number or negative errno otherwise.
1390 * @note For TCRYPT cipher chain is the volume key concatenated
1391 * for all ciphers in chain.
1392 * @note For VERITY the volume key means root hash used for activation.
1394 int crypt_volume_key_get(struct crypt_device *cd,
1397 size_t *volume_key_size,
1398 const char *passphrase,
1399 size_t passphrase_size);
1402 * Verify that provided volume key is valid for crypt device.
1404 * @param cd crypt device handle
1405 * @param volume_key provided volume key
1406 * @param volume_key_size size of @e volume_key
1408 * @return @e 0 on success or negative errno value otherwise.
1410 int crypt_volume_key_verify(struct crypt_device *cd,
1411 const char *volume_key,
1412 size_t volume_key_size);
1416 * @defgroup crypt-devstat Crypt and Verity device status
1417 * @addtogroup crypt-devstat
1425 CRYPT_INVALID, /**< device mapping is invalid in this context */
1426 CRYPT_INACTIVE, /**< no such mapped device */
1427 CRYPT_ACTIVE, /**< device is active */
1428 CRYPT_BUSY /**< device is active and has open count > 0 */
1429 } crypt_status_info;
1432 * Get status info about device name.
1434 * @param cd crypt device handle, can be @e NULL
1435 * @param name crypt device name
1437 * @return value defined by crypt_status_info.
1440 crypt_status_info crypt_status(struct crypt_device *cd, const char *name);
1443 * Dump text-formatted information about crypt or verity device to log output.
1445 * @param cd crypt device handle
1447 * @return @e 0 on success or negative errno value otherwise.
1449 int crypt_dump(struct crypt_device *cd);
1452 * Get cipher used in device.
1454 * @param cd crypt device handle
1456 * @return used cipher, e.g. "aes" or @e NULL otherwise
1459 const char *crypt_get_cipher(struct crypt_device *cd);
1462 * Get cipher mode used in device.
1464 * @param cd crypt device handle
1466 * @return used cipher mode e.g. "xts-plain" or @e otherwise
1469 const char *crypt_get_cipher_mode(struct crypt_device *cd);
1474 * @param cd crypt device handle
1476 * @return device UUID or @e NULL if not set
1479 const char *crypt_get_uuid(struct crypt_device *cd);
1482 * Get path to underlaying device.
1484 * @param cd crypt device handle
1486 * @return path to underlaying device name
1489 const char *crypt_get_device_name(struct crypt_device *cd);
1492 * Get path to detached metadata device or @e NULL if it is not detached.
1494 * @param cd crypt device handle
1496 * @return path to underlaying device name
1499 const char *crypt_get_metadata_device_name(struct crypt_device *cd);
1502 * Get device offset in 512-bytes sectors where real data starts (on underlying device).
1504 * @param cd crypt device handle
1506 * @return device offset in sectors
1509 uint64_t crypt_get_data_offset(struct crypt_device *cd);
1512 * Get IV offset in 512-bytes sectors (skip).
1514 * @param cd crypt device handle
1519 uint64_t crypt_get_iv_offset(struct crypt_device *cd);
1522 * Get size (in bytes) of volume key for crypt device.
1524 * @param cd crypt device handle
1526 * @return volume key size
1528 * @note For LUKS2, this function can be used only if there is at least
1529 * one keyslot assigned to data segment.
1531 int crypt_get_volume_key_size(struct crypt_device *cd);
1534 * Get size (in bytes) of encryption sector for crypt device.
1536 * @param cd crypt device handle
1538 * @return sector size
1541 int crypt_get_sector_size(struct crypt_device *cd);
1544 * Get device parameters for VERITY device.
1546 * @param cd crypt device handle
1547 * @param vp verity device info
1549 * @e 0 on success or negative errno value otherwise.
1552 int crypt_get_verity_info(struct crypt_device *cd,
1553 struct crypt_params_verity *vp);
1556 * Get device parameters for INTEGRITY device.
1558 * @param cd crypt device handle
1559 * @param ip verity device info
1561 * @e 0 on success or negative errno value otherwise.
1564 int crypt_get_integrity_info(struct crypt_device *cd,
1565 struct crypt_params_integrity *ip);
1569 * @defgroup crypt-benchmark Benchmarking
1570 * Benchmarking of algorithms
1571 * @addtogroup crypt-benchmark
1576 * Informational benchmark for ciphers.
1578 * @param cd crypt device handle
1579 * @param cipher (e.g. "aes")
1580 * @param cipher_mode (e.g. "xts"), IV generator is ignored
1581 * @param volume_key_size size of volume key in bytes
1582 * @param iv_size size of IV in bytes
1583 * @param buffer_size size of encryption buffer in bytes used in test
1584 * @param encryption_mbs measured encryption speed in MiB/s
1585 * @param decryption_mbs measured decryption speed in MiB/s
1587 * @return @e 0 on success or negative errno value otherwise.
1589 * @note If encryption_buffer_size is too small and encryption time
1590 * cannot be properly measured, -ERANGE is returned.
1592 int crypt_benchmark(struct crypt_device *cd,
1594 const char *cipher_mode,
1595 size_t volume_key_size,
1598 double *encryption_mbs,
1599 double *decryption_mbs);
1602 * Informational benchmark for PBKDF.
1604 * @param cd crypt device handle
1605 * @param pbkdf PBKDF parameters
1606 * @param password password for benchmark
1607 * @param password_size size of password
1608 * @param salt salt for benchmark
1609 * @param salt_size size of salt
1610 * @param volume_key_size output volume key size
1611 * @param progress callback function
1612 * @param usrptr provided identification in callback
1614 * @return @e 0 on success or negative errno value otherwise.
1616 int crypt_benchmark_pbkdf(struct crypt_device *cd,
1617 struct crypt_pbkdf_type *pbkdf,
1618 const char *password,
1619 size_t password_size,
1622 size_t volume_key_size,
1623 int (*progress)(uint32_t time_ms, void *usrptr),
1628 * @addtogroup crypt-keyslot
1633 * Crypt keyslot info
1636 CRYPT_SLOT_INVALID, /**< invalid keyslot */
1637 CRYPT_SLOT_INACTIVE, /**< keyslot is inactive (free) */
1638 CRYPT_SLOT_ACTIVE, /**< keyslot is active (used) */
1639 CRYPT_SLOT_ACTIVE_LAST,/**< keylost is active (used)
1640 * and last used at the same time */
1641 CRYPT_SLOT_UNBOUND /**< keyslot is active and not bound
1642 * to any crypt segment (LUKS2 only) */
1643 } crypt_keyslot_info;
1646 * Get information about particular key slot.
1648 * @param cd crypt device handle
1649 * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
1651 * @return value defined by crypt_keyslot_info
1654 crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot);
1657 * Crypt keyslot priority
1660 CRYPT_SLOT_PRIORITY_INVALID =-1, /**< no such slot */
1661 CRYPT_SLOT_PRIORITY_IGNORE = 0, /**< CRYPT_ANY_SLOT will ignore it for open */
1662 CRYPT_SLOT_PRIORITY_NORMAL = 1, /**< default priority, tried after preferred */
1663 CRYPT_SLOT_PRIORITY_PREFER = 2, /**< will try to open first */
1664 } crypt_keyslot_priority;
1667 * Get keyslot priority (LUKS2)
1669 * @param cd crypt device handle
1670 * @param keyslot keyslot number
1672 * @return value defined by crypt_keyslot_priority
1674 crypt_keyslot_priority crypt_keyslot_get_priority(struct crypt_device *cd, int keyslot);
1677 * Set keyslot priority (LUKS2)
1679 * @param cd crypt device handle
1680 * @param keyslot keyslot number
1681 * @param priority priority defined in crypt_keyslot_priority
1683 * @return @e 0 on success or negative errno value otherwise.
1685 int crypt_keyslot_set_priority(struct crypt_device *cd, int keyslot, crypt_keyslot_priority priority);
1688 * Get number of keyslots supported for device type.
1690 * @param type crypt device type
1692 * @return slot count or negative errno otherwise if device
1693 * doesn't not support keyslots.
1695 int crypt_keyslot_max(const char *type);
1698 * Get keyslot area pointers (relative to metadata device).
1700 * @param cd crypt device handle
1701 * @param keyslot keyslot number
1702 * @param offset offset on metadata device (in bytes)
1703 * @param length length of keyslot area (in bytes)
1705 * @return @e 0 on success or negative errno value otherwise.
1708 int crypt_keyslot_area(struct crypt_device *cd,
1714 * Get size (in bytes) of stored key in particular keyslot.
1715 * Use for LUKS2 unbound keyslots, for other keyslots it is the same as @ref crypt_get_volume_key_size
1717 * @param cd crypt device handle
1718 * @param keyslot keyslot number
1720 * @return volume key size or negative errno value otherwise.
1723 int crypt_keyslot_get_key_size(struct crypt_device *cd, int keyslot);
1726 * Get cipher and key size for keyslot encryption.
1727 * Use for LUKS2 keyslot to set different encryption type than for data encryption.
1728 * Parameters will be used for next keyslot operations.
1730 * @param cd crypt device handle
1731 * @param keyslot keyslot number of CRYPT_ANY_SLOT for default
1732 * @param key_size encryption key size (in bytes)
1734 * @return cipher specification on success or @e NULL.
1736 * @note This is the encryption of keyslot itself, not the data encryption algorithm!
1738 const char *crypt_keyslot_get_encryption(struct crypt_device *cd, int keyslot, size_t *key_size);
1741 * Get PBKDF parameters for keyslot.
1743 * @param cd crypt device handle
1744 * @param keyslot keyslot number
1745 * @param pbkdf struct with returned PBKDF parameters
1747 * @return @e 0 on success or negative errno value otherwise.
1749 int crypt_keyslot_get_pbkdf(struct crypt_device *cd, int keyslot, struct crypt_pbkdf_type *pbkdf);
1752 * Set encryption for keyslot.
1753 * Use for LUKS2 keyslot to set different encryption type than for data encryption.
1754 * Parameters will be used for next keyslot operations that create or change a keyslot.
1756 * @param cd crypt device handle
1757 * @param cipher (e.g. "aes-xts-plain64")
1758 * @param key_size encryption key size (in bytes)
1760 * @return @e 0 on success or negative errno value otherwise.
1762 * @note To reset to default keyslot encryption (the same as for data)
1763 * set cipher to NULL and key size to 0.
1765 int crypt_keyslot_set_encryption(struct crypt_device *cd,
1770 * Get directory where mapped crypt devices are created
1772 * @return the directory path
1774 const char *crypt_get_dir(void);
1779 * @defgroup crypt-backup Device metadata backup
1780 * @addtogroup crypt-backup
1784 * Backup header and keyslots to file.
1786 * @param cd crypt device handle
1787 * @param requested_type @link crypt-type @endlink or @e NULL for all known
1788 * @param backup_file file to backup header to
1790 * @return @e 0 on success or negative errno value otherwise.
1793 int crypt_header_backup(struct crypt_device *cd,
1794 const char *requested_type,
1795 const char *backup_file);
1798 * Restore header and keyslots from backup file.
1800 * @param cd crypt device handle
1801 * @param requested_type @link crypt-type @endlink or @e NULL for all known
1802 * @param backup_file file to restore header from
1804 * @return @e 0 on success or negative errno value otherwise.
1807 int crypt_header_restore(struct crypt_device *cd,
1808 const char *requested_type,
1809 const char *backup_file);
1813 * @defgroup crypt-dbg Library debug level
1814 * Set library debug level
1815 * @addtogroup crypt-dbg
1820 #define CRYPT_DEBUG_ALL -1
1821 /** Debug all with additional JSON dump (for LUKS2) */
1822 #define CRYPT_DEBUG_JSON -2
1824 #define CRYPT_DEBUG_NONE 0
1827 * Set the debug level for library
1829 * @param level debug level
1832 void crypt_set_debug_level(int level);
1836 * @defgroup crypt-keyfile Function to read keyfile
1837 * @addtogroup crypt-keyfile
1844 * @param cd crypt device handle
1845 * @param keyfile keyfile to read
1846 * @param key buffer for key
1847 * @param key_size_read size of read key
1848 * @param keyfile_offset key offset in keyfile
1849 * @param key_size exact key length to read from file or 0
1850 * @param flags keyfile read flags
1852 * @return @e 0 on success or negative errno value otherwise.
1854 * @note If key_size is set to zero we read internal max length
1855 * and actual size read is returned via key_size_read parameter.
1857 int crypt_keyfile_device_read(struct crypt_device *cd,
1858 const char *keyfile,
1859 char **key, size_t *key_size_read,
1860 uint64_t keyfile_offset,
1865 * Backward compatible crypt_keyfile_device_read() (with size_t offset).
1867 int crypt_keyfile_read(struct crypt_device *cd,
1868 const char *keyfile,
1869 char **key, size_t *key_size_read,
1870 size_t keyfile_offset,
1874 /** Read key only to the first end of line (\\n). */
1875 #define CRYPT_KEYFILE_STOP_EOL (1 << 0)
1879 * @defgroup crypt-wipe Function to wipe device
1880 * @addtogroup crypt-wipe
1887 CRYPT_WIPE_ZERO, /**< Fill with zeroes */
1888 CRYPT_WIPE_RANDOM, /**< Use RNG to fill data */
1889 CRYPT_WIPE_ENCRYPTED_ZERO, /**< Add encryption and fill with zeroes as plaintext */
1890 CRYPT_WIPE_SPECIAL, /**< Compatibility only, do not use (Gutmann method) */
1891 } crypt_wipe_pattern;
1894 * Wipe/Fill (part of) a device with the selected pattern.
1896 * @param cd crypt device handle
1897 * @param dev_path path to device to wipe or @e NULL if data device should be used
1898 * @param pattern selected wipe pattern
1899 * @param offset offset on device (in bytes)
1900 * @param length length of area to be wiped (in bytes)
1901 * @param wipe_block_size used block for wiping (one step) (in bytes)
1902 * @param flags wipe flags
1903 * @param progress callback function called after each @e wipe_block_size or @e NULL
1904 * @param usrptr provided identification in callback
1906 * @return @e 0 on success or negative errno value otherwise.
1908 * @note A @e progress callback can interrupt wipe process by returning non-zero code.
1910 * @note If the error values is -EIO or -EINTR, some part of the device could
1911 * be overwritten. Other error codes (-EINVAL, -ENOMEM) means that no IO was performed.
1913 int crypt_wipe(struct crypt_device *cd,
1914 const char *dev_path, /* if null, use data device */
1915 crypt_wipe_pattern pattern,
1918 size_t wipe_block_size,
1920 int (*progress)(uint64_t size, uint64_t offset, void *usrptr),
1924 /** Use direct-io */
1925 #define CRYPT_WIPE_NO_DIRECT_IO (1 << 0)
1929 * @defgroup crypt-tokens LUKS2 token wrapper access
1931 * Utilities for handling tokens LUKS2
1932 * Token is a device or a method how to read password for particular keyslot
1933 * automatically. It can be chunk of data stored on hardware token or
1934 * just a metadata how to generate the password.
1936 * @addtogroup crypt-tokens
1940 /** Iterate through all tokens */
1941 #define CRYPT_ANY_TOKEN -1
1944 * Get content of a token definition in JSON format.
1946 * @param cd crypt device handle
1947 * @param token token id
1948 * @param json buffer with JSON
1950 * @return allocated token id or negative errno otherwise.
1952 int crypt_token_json_get(struct crypt_device *cd,
1957 * Store content of a token definition in JSON format.
1959 * @param cd crypt device handle
1960 * @param token token id or @e CRYPT_ANY_TOKEN to allocate new one
1961 * @param json buffer with JSON or @e NULL to remove token
1963 * @return allocated token id or negative errno otherwise.
1965 * @note The buffer must be in proper JSON format and must contain at least
1966 * string "type" with slot type and an array of string names "keyslots".
1967 * Keyslots array contains assignments to particular slots and can be empty.
1969 int crypt_token_json_set(struct crypt_device *cd,
1977 CRYPT_TOKEN_INVALID, /**< token is invalid */
1978 CRYPT_TOKEN_INACTIVE, /**< token is empty (free) */
1979 CRYPT_TOKEN_INTERNAL, /**< active internal token with driver */
1980 CRYPT_TOKEN_INTERNAL_UNKNOWN, /**< active internal token (reserved name) with missing token driver */
1981 CRYPT_TOKEN_EXTERNAL, /**< active external (user defined) token with driver */
1982 CRYPT_TOKEN_EXTERNAL_UNKNOWN, /**< active external (user defined) token with missing token driver */
1986 * Get info for specific token.
1988 * @param cd crypt device handle
1989 * @param token existing token id
1990 * @param type pointer for returned type string
1992 * @return token status info. For any returned status (besides CRYPT_TOKEN_INVALID
1993 * and CRYPT_TOKEN_INACTIVE) and if type parameter is not NULL it will
1994 * contain address of type string.
1996 * @note if required, create a copy of string referenced in *type before calling next
1997 * libcryptsetup API function. The reference may become invalid.
1999 crypt_token_info crypt_token_status(struct crypt_device *cd, int token, const char **type);
2002 * LUKS2 keyring token parameters.
2004 * @see crypt_token_builtin_set
2007 struct crypt_token_params_luks2_keyring {
2008 const char *key_description; /**< Reference in keyring */
2012 * Create a new luks2 keyring token.
2014 * @param cd crypt device handle
2015 * @param token token id or @e CRYPT_ANY_TOKEN to allocate new one
2016 * @param params luks2 keyring token params
2018 * @return allocated token id or negative errno otherwise.
2021 int crypt_token_luks2_keyring_set(struct crypt_device *cd,
2023 const struct crypt_token_params_luks2_keyring *params);
2026 * Get LUKS2 keyring token params
2028 * @param cd crypt device handle
2029 * @param token existing luks2 keyring token id
2030 * @param params returned luks2 keyring token params
2032 * @return allocated token id or negative errno otherwise.
2034 * @note do not call free() on params members. Members are valid only
2035 * until next libcryptsetup function is called.
2037 int crypt_token_luks2_keyring_get(struct crypt_device *cd,
2039 struct crypt_token_params_luks2_keyring *params);
2042 * Assign a token to particular keyslot.
2043 * (There can be more keyslots assigned to one token id.)
2045 * @param cd crypt device handle
2046 * @param token token id
2047 * @param keyslot keyslot to be assigned to token (CRYPT_ANY SLOT
2048 * assigns all active keyslots to token)
2050 * @return allocated token id or negative errno otherwise.
2052 int crypt_token_assign_keyslot(struct crypt_device *cd,
2057 * Unassign a token from particular keyslot.
2058 * (There can be more keyslots assigned to one token id.)
2060 * @param cd crypt device handle
2061 * @param token token id
2062 * @param keyslot keyslot to be unassigned from token (CRYPT_ANY SLOT
2063 * unassigns all active keyslots from token)
2065 * @return allocated token id or negative errno otherwise.
2067 int crypt_token_unassign_keyslot(struct crypt_device *cd,
2072 * Get info about token assignment to particular keyslot.
2074 * @param cd crypt device handle
2075 * @param token token id
2076 * @param keyslot keyslot
2078 * @return 0 on success (token exists and is assigned to the keyslot),
2079 * -ENOENT if token is not assigned to a keyslot (token, keyslot
2080 * or both may be inactive) or other negative errno otherwise.
2082 int crypt_token_is_assigned(struct crypt_device *cd,
2087 * Token handler open function prototype.
2088 * This function retrieves password from a token and return allocated buffer
2089 * containing this password. This buffer has to be deallocated by calling
2090 * free() function and content should be wiped before deallocation.
2092 * @param cd crypt device handle
2093 * @param token token id
2094 * @param buffer returned allocated buffer with password
2095 * @param buffer_len length of the buffer
2096 * @param usrptr user data in @link crypt_activate_by_token @endlink
2098 typedef int (*crypt_token_open_func) (
2099 struct crypt_device *cd,
2106 * Token handler buffer free function prototype.
2107 * This function is used by library to free the buffer with keyslot
2108 * passphrase when it's no longer needed. If not defined the library
2109 * overwrites buffer with zeroes and call free().
2111 * @param buffer the buffer with keyslot passphrase
2112 * @param buffer_len the buffer length
2114 typedef void (*crypt_token_buffer_free_func) (void *buffer, size_t buffer_len);
2117 * Token handler validate function prototype.
2118 * This function validates JSON representation of user defined token for additional data
2119 * specific for its token type. If defined in the handler, it's called
2120 * during @link crypt_activate_by_token @endlink. It may also be called during
2121 * @link crypt_token_json_set @endlink when appropriate token handler was registered before
2122 * with @link crypt_token_register @endlink.
2124 * @param cd crypt device handle
2125 * @param json buffer with JSON
2127 typedef int (*crypt_token_validate_func) (struct crypt_device *cd, const char *json);
2130 * Token handler dump function prototype.
2131 * This function is supposed to print token implementation specific details. It gets
2132 * called during @link crypt_dump @endlink if token handler was registered before.
2134 * @param cd crypt device handle
2135 * @param json buffer with token JSON
2137 * @note dump implementations are advised to use @link crypt_log @endlink function
2138 * to dump token details.
2140 typedef void (*crypt_token_dump_func) (struct crypt_device *cd, const char *json);
2146 const char *name; /**< token handler name */
2147 crypt_token_open_func open; /**< token handler open function */
2148 crypt_token_buffer_free_func buffer_free; /**< token handler buffer_free function (optional) */
2149 crypt_token_validate_func validate; /**< token handler validate function (optional) */
2150 crypt_token_dump_func dump; /**< token handler dump function (optional) */
2151 } crypt_token_handler;
2154 * Register token handler
2156 * @param handler token handler to register
2158 * @return @e 0 on success or negative errno value otherwise.
2160 int crypt_token_register(const crypt_token_handler *handler);
2163 * Activate device or check key using a token.
2165 * @param cd crypt device handle
2166 * @param name name of device to create, if @e NULL only check token
2167 * @param token requested token to check or CRYPT_ANY_TOKEN to check all
2168 * @param usrptr provided identification in callback
2169 * @param flags activation flags
2171 * @return unlocked key slot number or negative errno otherwise.
2173 int crypt_activate_by_token(struct crypt_device *cd,
2181 * @defgroup crypt-reencryption LUKS2 volume reencryption support
2183 * Set of functions to handling LUKS2 volume reencryption
2185 * @addtogroup crypt-reencryption
2189 /** Initialize reencryption metadata but do not run reencryption yet. (in) */
2190 #define CRYPT_REENCRYPT_INITIALIZE_ONLY (1 << 0)
2191 /** Move the first segment, used only with data shift. (in/out) */
2192 #define CRYPT_REENCRYPT_MOVE_FIRST_SEGMENT (1 << 1)
2193 /** Resume already initialized reencryption only. (in) */
2194 #define CRYPT_REENCRYPT_RESUME_ONLY (1 << 2)
2195 /** Run reencryption recovery only. (in) */
2196 #define CRYPT_REENCRYPT_RECOVERY (1 << 3)
2199 * Reencryption direction
2202 CRYPT_REENCRYPT_FORWARD = 0, /**< forward direction */
2203 CRYPT_REENCRYPT_BACKWARD /**< backward direction */
2204 } crypt_reencrypt_direction_info;
2210 CRYPT_REENCRYPT_REENCRYPT = 0, /**< Reencryption mode */
2211 CRYPT_REENCRYPT_ENCRYPT, /**< Encryption mode */
2212 CRYPT_REENCRYPT_DECRYPT, /**< Decryption mode */
2213 } crypt_reencrypt_mode_info;
2216 * LUKS2 reencryption options.
2218 struct crypt_params_reencrypt {
2219 crypt_reencrypt_mode_info mode; /**< Reencryption mode, immutable after first init. */
2220 crypt_reencrypt_direction_info direction; /**< Reencryption direction, immutable after first init. */
2221 const char *resilience; /**< Resilience mode: "none", "checksum", "journal" or "shift" (only "shift" is immutable after init) */
2222 const char *hash; /**< Used hash for "checksum" resilience type, ignored otherwise. */
2223 uint64_t data_shift; /**< Used in "shift" mode, must be non-zero, immutable after first init. */
2224 uint64_t max_hotzone_size; /**< Exact hotzone size for "none" mode. Maximum hotzone size for "checksum" and "journal" modes. */
2225 uint64_t device_size; /**< Reencrypt only initial part of the data device. */
2226 const struct crypt_params_luks2 *luks2; /**< LUKS2 parameters for the final reencryption volume.*/
2227 uint32_t flags; /**< Reencryption flags. */
2231 * Initialize reencryption metadata using passphrase.
2233 * This function initializes on-disk metadata to include all reencryption segments,
2234 * according to the provided options.
2235 * If metadata already contains ongoing reencryption metadata, it loads these parameters
2236 * (in this situation all parameters except @e name and @e passphrase can be omitted).
2238 * @param cd crypt device handle
2239 * @param name name of active device or @e NULL for offline reencryption
2240 * @param passphrase passphrase used to unlock volume key
2241 * @param passphrase_size size of @e passphrase (binary data)
2242 * @param keyslot_old keyslot to unlock existing device or CRYPT_ANY_SLOT
2243 * @param keyslot_new existing (unbound) reencryption keyslot; must be set except for decryption
2244 * @param cipher cipher specification (e.g. "aes")
2245 * @param cipher_mode cipher mode and IV (e.g. "xts-plain64")
2246 * @param params reencryption parameters @link crypt_params_reencrypt @endlink.
2248 * @return reencryption key slot number or negative errno otherwise.
2250 int crypt_reencrypt_init_by_passphrase(struct crypt_device *cd,
2252 const char *passphrase,
2253 size_t passphrase_size,
2257 const char *cipher_mode,
2258 const struct crypt_params_reencrypt *params);
2261 * Initialize reencryption metadata using passphrase in keyring.
2263 * This function initializes on-disk metadata to include all reencryption segments,
2264 * according to the provided options.
2265 * If metadata already contains ongoing reencryption metadata, it loads these parameters
2266 * (in this situation all parameters except @e name and @e key_description can be omitted).
2268 * @param cd crypt device handle
2269 * @param name name of active device or @e NULL for offline reencryption
2270 * @param key_description passphrase (key) identification in keyring
2271 * @param keyslot_old keyslot to unlock existing device or CRYPT_ANY_SLOT
2272 * @param keyslot_new existing (unbound) reencryption keyslot; must be set except for decryption
2273 * @param cipher cipher specification (e.g. "aes")
2274 * @param cipher_mode cipher mode and IV (e.g. "xts-plain64")
2275 * @param params reencryption parameters @link crypt_params_reencrypt @endlink.
2277 * @return reencryption key slot number or negative errno otherwise.
2279 int crypt_reencrypt_init_by_keyring(struct crypt_device *cd,
2281 const char *key_description,
2285 const char *cipher_mode,
2286 const struct crypt_params_reencrypt *params);
2289 * Run data reencryption.
2291 * @param cd crypt device handle
2292 * @param progress is a callback funtion reporting device \b size,
2293 * current \b offset of reencryption and provided \b usrptr identification
2295 * @return @e 0 on success or negative errno value otherwise.
2297 int crypt_reencrypt(struct crypt_device *cd,
2298 int (*progress)(uint64_t size, uint64_t offset, void *usrptr));
2301 * Reencryption status info
2304 CRYPT_REENCRYPT_NONE = 0, /**< No reencryption in progress */
2305 CRYPT_REENCRYPT_CLEAN, /**< Ongoing reencryption in a clean state. */
2306 CRYPT_REENCRYPT_CRASH, /**< Aborted reencryption that need internal recovery. */
2307 CRYPT_REENCRYPT_INVALID /**< Invalid state. */
2308 } crypt_reencrypt_info;
2311 * LUKS2 reencryption status.
2313 * @param cd crypt device handle
2314 * @param params reencryption parameters
2316 * @return reencryption status info and parameters.
2318 crypt_reencrypt_info crypt_reencrypt_status(struct crypt_device *cd,
2319 struct crypt_params_reencrypt *params);
2323 * @defgroup crypt-memory Safe memory helpers functions
2324 * @addtogroup crypt-memory
2329 * Allocate safe memory (content is safely wiped on deallocation).
2331 * @param size size of memory in bytes
2333 * @return pointer to allocate memory or @e NULL.
2335 void *crypt_safe_alloc(size_t size);
2338 * Release safe memory, content is safely wiped
2339 * The pointer must be allocated with @link crypt_safe_alloc @endlink
2341 * @param data pointer to memory to be deallocated
2343 * @return pointer to allocate memory or @e NULL.
2345 void crypt_safe_free(void *data);
2348 * Reallocate safe memory (content is copied and safely wiped on deallocation).
2350 * @param data pointer to memory to be deallocated
2351 * @param size new size of memory in bytes
2353 * @return pointer to allocate memory or @e NULL.
2355 void *crypt_safe_realloc(void *data, size_t size);
2358 * Safe clear memory area (compile should not compile this call out).
2360 * @param data pointer to memory to cleared
2361 * @param size new size of memory in bytes
2363 * @return pointer to allocate memory or @e NULL.
2365 void crypt_safe_memzero(void *data, size_t size);
2372 #endif /* _LIBCRYPTSETUP_H */