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-2012, Red Hat, Inc. All rights reserved.
7 * Copyright (C) 2009-2012, 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 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * @file libcryptsetup.h
25 * @brief Public cryptsetup API
27 * For more verbose examples of LUKS related use cases,
28 * please read @ref index "examples".
31 #ifndef _LIBCRYPTSETUP_H
32 #define _LIBCRYPTSETUP_H
40 struct crypt_device; /* crypt device handle */
43 * Initialize crypt device handle and check if provided device exists.
45 * @param cd Returns pointer to crypt device handle
46 * @param device Path to the backing device.
47 * If @e device is not a block device but a path to some file,
48 * the function will try to create a loopdevice and attach
49 * the file to the loopdevice with AUTOCLEAR flag set.
50 * If @e device is @e NULL function it will initialize dm backend only.
52 * @return @e 0 on success or negative errno value otherwise.
54 * @note Note that logging is not initialized here, possible messages uses
55 * default log function.
57 int crypt_init(struct crypt_device **cd, const char *device);
60 * Initialize crypt device handle from provided active device name,
61 * and, optionally, from separate metadata (header) device
62 * and check if provided device exists.
64 * @return @e 0 on success or negative errno value otherwise.
66 * @param cd returns crypt device handle for active device
67 * @param name name of active crypt device
68 * @param header_device optional device containing on-disk header
69 * (@e NULL if it the same as underlying device on there is no on-disk header)
71 * @post In case @e device points to active LUKS device but header load fails,
72 * context device type is set to @e NULL and @e 0 is returned as if it were successful.
73 * Context with @e NULL device type can only be deactivated by crypt_deactivate
75 * @note @link crypt_init_by_name @endlink is equivalent to calling
76 * crypt_init_by_name_and_header(cd, name, NULL);
78 int crypt_init_by_name_and_header(struct crypt_device **cd,
80 const char *header_device);
83 * This is equivalent to call
84 * @ref crypt_init_by_name_and_header "crypt_init_by_name_and_header(cd, name, NULL)"
86 * @sa crypt_init_by_name_and_header
88 int crypt_init_by_name(struct crypt_device **cd, const char *name);
91 * @defgroup loglevel "Cryptsetup logging"
93 * Set of functions and defines used in cryptsetup for
99 * @addtogroup loglevel
103 /** normal log level */
104 #define CRYPT_LOG_NORMAL 0
105 /** error log level */
106 #define CRYPT_LOG_ERROR 1
107 /** verbose log level */
108 #define CRYPT_LOG_VERBOSE 2
109 /** debug log level - always on stdout */
110 #define CRYPT_LOG_DEBUG -1
115 * @param cd crypt device handle (can be @e NULL to set default log function)
116 * @param log user defined log function reference
117 * @param usrptr provided identification in callback
118 * @param level log level below (debug messages can uses other levels)
119 * @param msg log message
121 void crypt_set_log_callback(struct crypt_device *cd,
122 void (*log)(int level, const char *msg, void *usrptr),
126 * Defines log function or use the default one otherwise.
128 * @see crypt_set_log_callback
130 * @param cd crypt device handle
131 * @param level log level
132 * @param msg log message
134 void crypt_log(struct crypt_device *cd, int level, const char *msg);
138 * Set confirmation callback (yes/no)
140 * If code need confirmation (like resetting uuid or restoring LUKS header from file)
141 * this function is called. If not defined, everything is confirmed.
143 * Callback function @e confirm should return @e 0 if operation is declined,
144 * other values mean accepted.
146 * @param cd crypt device handle
147 * @param confirm user defined confirm callback reference
148 * @param usrptr provided identification in callback
149 * @param msg Message for user to confirm
151 * @note Current version of cryptsetup API requires confirmation only when UUID is being changed
153 void crypt_set_confirm_callback(struct crypt_device *cd,
154 int (*confirm)(const char *msg, void *usrptr),
158 * Set password query callback.
160 * If code need @e _interactive_ query for password, this callback is called.
161 * If not defined, compiled-in default is called (uses terminal input).
163 * Callback should return length of password in buffer
164 * or negative errno value in case of error.
166 * @param cd crypt device handle
167 * @param password user defined password callback reference
168 * @param usrptr provided identification in callback
169 * @param msg Message for user
170 * @param buf buffer for password
171 * @param length size of buffer
173 * @note Note that if this function is defined, verify option is ignored
174 * (caller which provided callback is responsible for password verification)
175 * @note Only zero terminated passwords can be entered this way, for complex
176 * use API functions directly.
177 * @note Maximal length of password is limited to @e length @e - @e 1 (minimal 511 chars)
179 * @see Callback function is used in these call provided, that certain conditions are met:
180 * @li crypt_keyslot_add_by_passphrase
181 * @li crypt_activate_by_passphrase
182 * @li crypt_resume_by_passphrase
183 * @li crypt_resume_by_keyfile
184 * @li crypt_keyslot_add_by_keyfile
185 * @li crypt_keyslot_add_by_volume_key
188 void crypt_set_password_callback(struct crypt_device *cd,
189 int (*password)(const char *msg, char *buf, size_t length, void *usrptr),
193 * Set timeout for interactive password entry using default
196 * @param cd crypt device handle
197 * @param timeout_sec timeout in seconds
199 void crypt_set_timeout(struct crypt_device *cd, uint64_t timeout_sec);
202 * Set number of retries in case password input has been incorrect
204 * @param cd crypt device handle
205 * @param tries the number
207 void crypt_set_password_retry(struct crypt_device *cd, int tries);
210 * Set how long should cryptsetup iterate in PBKDF2 function.
211 * Default value heads towards the iterations which takes around 1 second
213 * @param cd crypt device handle
214 * @param iteration_time_ms the time in ms
216 void crypt_set_iteration_time(struct crypt_device *cd, uint64_t iteration_time_ms);
218 void crypt_set_iterarion_time(struct crypt_device *cd, uint64_t iteration_time_ms);
221 * Set whether passphrase will be verified on input
222 * (user has to input same passphrase twice)
224 * @param cd crypt device handle
225 * @param password_verify @e 0 = false, @e !0 true
227 void crypt_set_password_verify(struct crypt_device *cd, int password_verify);
231 * For LUKS it is encrypted data device when LUKS header is separated.
232 * For VERITY it is data device when hash device is separated.
234 * @param cd crypt device handle
235 * @param device path to device
238 int crypt_set_data_device(struct crypt_device *cd, const char *device);
241 * @defgroup rng "Cryptsetup RNG"
248 /** CRYPT_RNG_URANDOM - use /dev/urandom */
249 #define CRYPT_RNG_URANDOM 0
250 /** CRYPT_RNG_RANDOM - use /dev/random (waits if no entropy in system) */
251 #define CRYPT_RNG_RANDOM 1
254 * Set which RNG (random number generator) is used for generating long term key
256 * @param cd crypt device handle
257 * @param rng_type kernel random number generator to use
260 void crypt_set_rng_type(struct crypt_device *cd, int rng_type);
263 * Get which RNG (random number generator) is used for generating long term key
265 * @param cd crypt device handle
266 * @return RNG type on success or negative errno value otherwise.
269 int crypt_get_rng_type(struct crypt_device *cd);
274 * Helper to lock/unlock memory to avoid swap sensitive data to disk
276 * @param cd crypt device handle, can be @e NULL
277 * @param lock 0 to unlock otherwise lock memory
279 * @returns Value indicating whether the memory is locked (function can be called multiple times).
281 * @note Only root can do this.
282 * @note It locks/unlocks all process memory, not only crypt context.
284 int crypt_memory_lock(struct crypt_device *cd, int lock);
287 * @defgroup crypt_type "Cryptsetup on-disk format types"
289 * Set of functions, \#defines and structs related
290 * to on-disk format types
294 * @addtogroup crypt_type
298 /** plain crypt device, no on-disk header */
299 #define CRYPT_PLAIN "PLAIN"
300 /** LUKS version 1 header on-disk */
301 #define CRYPT_LUKS1 "LUKS1"
302 /** loop-AES compatibility mode */
303 #define CRYPT_LOOPAES "LOOPAES"
304 /** dm-verity mode */
305 #define CRYPT_VERITY "VERITY"
306 /** TCRYPT (TrueCrypt-compatible) mode */
307 #define CRYPT_TCRYPT "TCRYPT"
312 * @param cd crypt device handle
313 * @return string according to device type or @e NULL if not known.
315 const char *crypt_get_type(struct crypt_device *cd);
319 * Structure used as parameter for PLAIN device type
323 struct crypt_params_plain {
324 const char *hash; /**< password hash function */
325 uint64_t offset; /**< offset in sectors */
326 uint64_t skip; /**< IV offset / initialization sector */
327 uint64_t size; /**< size of mapped device or @e 0 for autodetection */
331 * Structure used as parameter for LUKS device type
333 * @see crypt_format, crypt_load
335 * @note during crypt_format @e data_device attribute determines
336 * if the LUKS header is separated from encrypted payload device
339 struct crypt_params_luks1 {
340 const char *hash; /**< hash used in LUKS header */
341 size_t data_alignment; /**< data alignment in sectors, data offset is multiple of this */
342 const char *data_device; /**< detached encrypted data device or @e NULL */
347 * Structure used as parameter for loop-AES device type
352 struct crypt_params_loopaes {
353 const char *hash; /**< key hash function */
354 uint64_t offset; /**< offset in sectors */
355 uint64_t skip; /**< IV offset / initialization sector */
360 * Structure used as parameter for dm-verity device type
362 * @see crypt_format, crypt_load
365 /** No on-disk header (only hashes) */
366 #define CRYPT_VERITY_NO_HEADER (1 << 0)
367 /** Verity hash in userspace before activation */
368 #define CRYPT_VERITY_CHECK_HASH (1 << 1)
369 /** Create hash - format hash device */
370 #define CRYPT_VERITY_CREATE_HASH (1 << 2)
372 struct crypt_params_verity {
373 const char *hash_name; /**< hash function */
374 const char *data_device; /**< data_device (CRYPT_VERITY_CREATE_HASH) */
375 const char *hash_device; /**< hash_device (output only) */
376 const char *salt; /**< salt */
377 uint32_t salt_size; /**< salt size (in bytes) */
378 uint32_t hash_type; /**< in-kernel hashing type */
379 uint32_t data_block_size; /**< data block size (in bytes) */
380 uint32_t hash_block_size; /**< hash block size (in bytes) */
381 uint64_t data_size; /**< data area size (in data blocks) */
382 uint64_t hash_area_offset; /**< hash/header offset (in bytes) */
383 uint32_t flags; /**< CRYPT_VERITY* flags */
388 * Structure used as parameter for TCRYPT device type
393 /** Include legacy modes ehn scannig for header*/
394 #define CRYPT_TCRYPT_LEGACY_MODES (1 << 0)
395 /** Try to load hidden header (describing hidden device) */
396 #define CRYPT_TCRYPT_HIDDEN_HEADER (1 << 1)
397 /** Try to load backup header */
398 #define CRYPT_TCRYPT_BACKUP_HEADER (1 << 2)
399 /** Device contains encrypted system (with boot loader) */
400 #define CRYPT_TCRYPT_SYSTEM_HEADER (1 << 3)
402 struct crypt_params_tcrypt {
403 const char *passphrase; /**< passphrase to unlock header (input only) */
404 size_t passphrase_size; /**< passphrase size (input only) */
405 const char **keyfiles; /**< keyfile paths to unlock header (input only) */
406 unsigned int keyfiles_count;/**< keyfiles count (input only) */
407 const char *hash_name; /**< hash function for PBKDF */
408 const char *cipher; /**< cipher chain c1[-c2[-c3]] */
409 const char *mode; /**< cipher block mode */
410 size_t key_size; /**< key size in bytes (the whole chain) */
411 uint32_t flags; /**< CRYPT_TCRYPT* flags */
417 * Create (format) new crypt device (and possible header on-disk) but not activates it.
419 * @pre @e cd contains initialized and not formatted device context (device type must @b not be set)
421 * @param cd crypt device handle
422 * @param type type of device (optional params struct must be of this type)
423 * @param cipher (e.g. "aes")
424 * @param cipher_mode including IV specification (e.g. "xts-plain")
425 * @param uuid requested UUID or @e NULL if it should be generated
426 * @param volume_key pre-generated volume key or @e NULL if it should be generated (only for LUKS)
427 * @param volume_key_size size of volume key in bytes.
428 * @param params crypt type specific parameters (see @link crypt_type @endlink)
430 * @returns @e 0 on success or negative errno value otherwise.
432 * @note Note that crypt_format does not enable any keyslot (in case of work with LUKS device),
433 * but it stores volume key internally and subsequent crypt_keyslot_add_* calls can be used.
434 * @note For VERITY @link crypt_type @endlink, only uuid parameter is used, others paramaters
435 * are ignored and verity specific attributes are set through mandatory params option.
437 int crypt_format(struct crypt_device *cd,
440 const char *cipher_mode,
442 const char *volume_key,
443 size_t volume_key_size,
447 * Set new UUID for already existing device
449 * @param cd crypt device handle
450 * @param uuid requested UUID or @e NULL if it should be generated
452 * @returns 0 on success or negative errno value otherwise.
454 * @note Currently, only LUKS device type are supported
456 int crypt_set_uuid(struct crypt_device *cd,
460 * Load crypt device parameters from on-disk header
462 * @param cd crypt device handle
463 * @param requested_type @link crypt_type @endlink or @e NULL for all known
464 * @param params crypt type specific parameters (see @link crypt_type @endlink)
466 * @returns 0 on success or negative errno value otherwise.
468 * @post In case LUKS header is read successfully but payload device is too small
469 * error is returned and device type in context is set to @e NULL
471 * @note Note that in current version load works only for LUKS and VERITY device type.
474 int crypt_load(struct crypt_device *cd,
475 const char *requested_type,
479 * Try to repair crypt device on-disk header if invalid
481 * @param cd crypt device handle
482 * @param requested_type @link crypt_type @endlink or @e NULL for all known
483 * @param params crypt type specific parameters (see @link crypt_type @endlink)
485 * @returns 0 on success or negative errno value otherwise.
488 int crypt_repair(struct crypt_device *cd,
489 const char *requested_type,
493 * Resize crypt device
495 * @param cd - crypt device handle
496 * @param name - name of device to resize
497 * @param new_size - new device size in sectors or @e 0 to use all of the underlying device size
499 * @return @e 0 on success or negative errno value otherwise.
501 int crypt_resize(struct crypt_device *cd,
506 * Suspends crypt device.
508 * @param cd crypt device handle, can be @e NULL
509 * @param name name of device to suspend
511 * @return 0 on success or negative errno value otherwise.
513 * @note Only LUKS device type is supported
516 int crypt_suspend(struct crypt_device *cd,
520 * Resumes crypt device using passphrase.
523 * @param cd crypt device handle
524 * @param name name of device to resume
525 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
526 * @param passphrase passphrase used to unlock volume key, @e NULL for query
527 * @param passphrase_size size of @e passphrase (binary data)
529 * @return unlocked key slot number or negative errno otherwise.
531 * @note Only LUKS device type is supported
533 int crypt_resume_by_passphrase(struct crypt_device *cd,
536 const char *passphrase,
537 size_t passphrase_size);
540 * Resumes crypt device using key file.
542 * @param cd crypt device handle
543 * @param name name of device to resume
544 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
545 * @param keyfile key file used to unlock volume key, @e NULL for passphrase query
546 * @param keyfile_size number of bytes to read from keyfile, 0 is unlimited
547 * @param keyfile_offset number of bytes to skip at start of keyfile
549 * @return unlocked key slot number or negative errno otherwise.
551 int crypt_resume_by_keyfile_offset(struct crypt_device *cd,
556 size_t keyfile_offset);
558 * Backward compatible crypt_resume_by_keyfile_offset() (without offset).
560 int crypt_resume_by_keyfile(struct crypt_device *cd,
564 size_t keyfile_size);
567 * Releases crypt device context and used memory.
569 * @param cd crypt device handle
571 void crypt_free(struct crypt_device *cd);
574 * @defgroup keyslot "Cryptsetup LUKS keyslots"
575 * @addtogroup keyslot
580 /** iterate through all keyslots and find first one that fits */
581 #define CRYPT_ANY_SLOT -1
584 * Add key slot using provided passphrase
586 * @pre @e cd contains initialized and formatted LUKS device context
588 * @param cd crypt device handle
589 * @param keyslot requested keyslot or @e CRYPT_ANY_SLOT
590 * @param passphrase passphrase used to unlock volume key, @e NULL for query
591 * @param passphrase_size size of passphrase (binary data)
592 * @param new_passphrase passphrase for new keyslot, @e NULL for query
593 * @param new_passphrase_size size of @e new_passphrase (binary data)
595 * @return allocated key slot number or negative errno otherwise.
597 int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
599 const char *passphrase,
600 size_t passphrase_size,
601 const char *new_passphrase,
602 size_t new_passphrase_size);
605 * Change defined key slot using provided passphrase
607 * @pre @e cd contains initialized and formatted LUKS device context
609 * @param cd crypt device handle
610 * @param keyslot_old old keyslot or @e CRYPT_ANY_SLOT
611 * @param keyslot_new new keyslot (can be the same as old)
612 * @param passphrase passphrase used to unlock volume key, @e NULL for query
613 * @param passphrase_size size of passphrase (binary data)
614 * @param new_passphrase passphrase for new keyslot, @e NULL for query
615 * @param new_passphrase_size size of @e new_passphrase (binary data)
617 * @return allocated key slot number or negative errno otherwise.
619 * @note This function is just internal implementation of luksChange
620 * command to avoid reading of volume key outside libcryptsetup boundary
623 int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
626 const char *passphrase,
627 size_t passphrase_size,
628 const char *new_passphrase,
629 size_t new_passphrase_size);
632 * Add key slot using provided key file path
634 * @pre @e cd contains initialized and formatted LUKS device context
636 * @param cd crypt device handle
637 * @param keyslot requested keyslot or @e CRYPT_ANY_SLOT
638 * @param keyfile key file used to unlock volume key, @e NULL for passphrase query
639 * @param keyfile_size number of bytes to read from keyfile, @e 0 is unlimited
640 * @param keyfile_offset number of bytes to skip at start of keyfile
641 * @param new_keyfile keyfile for new keyslot, @e NULL for passphrase query
642 * @param new_keyfile_size number of bytes to read from @e new_keyfile, @e 0 is unlimited
643 * @param new_keyfile_offset number of bytes to skip at start of new_keyfile
645 * @return allocated key slot number or negative errno otherwise.
647 * @note Note that @e keyfile can be "-" for STDIN
650 int crypt_keyslot_add_by_keyfile_offset(struct crypt_device *cd,
654 size_t keyfile_offset,
655 const char *new_keyfile,
656 size_t new_keyfile_size,
657 size_t new_keyfile_offset);
659 * Backward compatible crypt_keyslot_add_by_keyfile_offset() (without offset).
661 int crypt_keyslot_add_by_keyfile(struct crypt_device *cd,
665 const char *new_keyfile,
666 size_t new_keyfile_size);
669 * Add key slot using provided volume key
671 * @pre @e cd contains initialized and formatted LUKS device context
673 * @param cd crypt device handle
674 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
675 * @param volume_key provided volume key or @e NULL if used after crypt_format
676 * @param volume_key_size size of volume_key
677 * @param passphrase passphrase for new keyslot, @e NULL for query
678 * @param passphrase_size size of passphrase
680 * @return allocated key slot number or negative errno otherwise.
683 int crypt_keyslot_add_by_volume_key(struct crypt_device *cd,
685 const char *volume_key,
686 size_t volume_key_size,
687 const char *passphrase,
688 size_t passphrase_size);
691 * Destroy (and disable) key slot
693 * @pre @e cd contains initialized and formatted LUKS device context
695 * @param cd crypt device handle
696 * @param keyslot requested key slot to destroy
698 * @return @e 0 on success or negative errno value otherwise.
700 * @note Note that there is no passphrase verification used.
702 int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot);
707 * @defgroup aflags "Device runtime attributes"
715 /** device is read only */
716 #define CRYPT_ACTIVATE_READONLY (1 << 0)
717 /** only reported for device without uuid */
718 #define CRYPT_ACTIVATE_NO_UUID (1 << 1)
719 /** activate even if cannot grant exclusive access (DANGEROUS) */
720 #define CRYPT_ACTIVATE_SHARED (1 << 2)
721 /** enable discards aka TRIM */
722 #define CRYPT_ACTIVATE_ALLOW_DISCARDS (1 << 3)
723 /** skip global udev rules in activation ("private device"), input only */
724 #define CRYPT_ACTIVATE_PRIVATE (1 << 4)
725 /** corruption detected (verity), output only */
726 #define CRYPT_ACTIVATE_CORRUPTED (1 << 5)
729 * Active device runtime attributes
731 struct crypt_active_device {
732 uint64_t offset; /**< offset in sectors */
733 uint64_t iv_offset; /**< IV initialization sector */
734 uint64_t size; /**< active device size */
735 uint32_t flags; /**< activation flags */
739 * Receives runtime attributes of active crypt device
741 * @param cd crypt device handle (can be @e NULL)
742 * @param name name of active device
743 * @param cad preallocated active device attributes to fill
745 * @return @e 0 on success or negative errno value otherwise
748 int crypt_get_active_device(struct crypt_device *cd,
750 struct crypt_active_device *cad);
755 * Activate device or check passphrase
757 * @param cd crypt device handle
758 * @param name name of device to create, if @e NULL only check passphrase
759 * @param keyslot requested keyslot to check or @e CRYPT_ANY_SLOT
760 * @param passphrase passphrase used to unlock volume key, @e NULL for query
761 * @param passphrase_size size of @e passphrase
762 * @param flags activation flags
764 * @return unlocked key slot number or negative errno otherwise.
766 int crypt_activate_by_passphrase(struct crypt_device *cd,
769 const char *passphrase,
770 size_t passphrase_size,
774 * Activate device or check using key file
776 * @param cd crypt device handle
777 * @param name name of device to create, if @e NULL only check keyfile
778 * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
779 * @param keyfile key file used to unlock volume key
780 * @param keyfile_size number of bytes to read from keyfile, 0 is unlimited
781 * @param keyfile_offset number of bytes to skip at start of keyfile
782 * @param flags activation flags
784 * @return unlocked key slot number or negative errno otherwise.
786 int crypt_activate_by_keyfile_offset(struct crypt_device *cd,
791 size_t keyfile_offset,
794 * Backward compatible crypt_activate_by_keyfile_offset() (without offset).
796 int crypt_activate_by_keyfile(struct crypt_device *cd,
804 * Activate device using provided volume key
807 * @param cd crypt device handle
808 * @param name name of device to create, if @e NULL only check volume key
809 * @param volume_key provided volume key (or @e NULL to use internal)
810 * @param volume_key_size size of volume_key
811 * @param flags activation flags
813 * @return @e 0 on success or negative errno value otherwise.
815 * @note If @e NULL is used for volume_key, device has to be initialized
816 * by previous operation (like @ref crypt_format
817 * or @ref crypt_init_by_name)
818 * @note For VERITY the volume key means root hash required for activation.
819 * Because kernel dm-verity is always read only, you have to provide
820 * CRYPT_ACTIVATE_READONLY flag always.
821 * @note For TCRYPT the volume key should be always NULL and because master
822 * key from decrypted header is used instead.
824 int crypt_activate_by_volume_key(struct crypt_device *cd,
826 const char *volume_key,
827 size_t volume_key_size,
831 * Deactivate crypt device. This function tries to remove active device-mapper
832 * mapping from kernel. Also, sensitive data like the volume key are removed from
835 * @param cd crypt device handle, can be @e NULL
836 * @param name name of device to deactivate
838 * @return @e 0 on success or negative errno value otherwise.
841 int crypt_deactivate(struct crypt_device *cd, const char *name);
844 * Get volume key from of crypt device
846 * @param cd crypt device handle
847 * @param keyslot use this keyslot or @e CRYPT_ANY_SLOT
848 * @param volume_key buffer for volume key
849 * @param volume_key_size on input, size of buffer @e volume_key,
850 * on output size of @e volume_key
851 * @param passphrase passphrase used to unlock volume key
852 * @param passphrase_size size of @e passphrase
854 * @return unlocked key slot number or negative errno otherwise.
856 * @note For TCRYPT cipher chain is the volume key concatenated
857 * for all ciphers in chain.
859 int crypt_volume_key_get(struct crypt_device *cd,
862 size_t *volume_key_size,
863 const char *passphrase,
864 size_t passphrase_size);
867 * Verify that provided volume key is valid for crypt device
869 * @param cd crypt device handle
870 * @param volume_key provided volume key
871 * @param volume_key_size size of @e volume_key
873 * @return @e 0 on success or negative errno value otherwise.
875 int crypt_volume_key_verify(struct crypt_device *cd,
876 const char *volume_key,
877 size_t volume_key_size);
880 * @defgroup devstat "Crypt and Verity device status"
881 * @addtogroup devstat
889 CRYPT_INVALID, /**< device mapping is invalid in this context */
890 CRYPT_INACTIVE, /**< no such mapped device */
891 CRYPT_ACTIVE, /**< device is active */
892 CRYPT_BUSY /**< device is active and has open count > 0 */
896 * Get status info about device name
898 * @param cd crypt device handle, can be @e NULL
899 * @param name crypt device name
901 * @return value defined by crypt_status_info.
904 crypt_status_info crypt_status(struct crypt_device *cd, const char *name);
907 * Dump text-formatted information about crypt or verity device to log output
909 * @param cd crypt device handle
911 * @return @e 0 on success or negative errno value otherwise.
913 int crypt_dump(struct crypt_device *cd);
916 * Informational benchmark for ciphers
918 * @param cd crypt device handle
919 * @param cipher (e.g. "aes")
920 * @param cipher_mode (e.g. "xts"), IV generator is ignored
921 * @param volume_key_size size of volume key in bytes
922 * @param iv_size size of IV in bytes
923 * @param buffer_size size of encryption buffer in bytes used in test
924 * @param encryption_mbs measured encryption speed in MiB/s
925 * @param decryption_mbs measured decryption speed in MiB/s
927 * @return @e 0 on success or negative errno value otherwise.
929 int crypt_benchmark(struct crypt_device *cd,
931 const char *cipher_mode,
932 size_t volume_key_size,
935 double *encryption_mbs,
936 double *decryption_mbs);
938 int crypt_benchmark_kdf(struct crypt_device *cd,
941 const char *password,
942 size_t password_size,
945 uint64_t *iterations_sec);
948 * Get cipher used in device
950 * @param cd crypt device handle
952 * @return used cipher, e.g. "aes" or @e NULL otherwise
955 const char *crypt_get_cipher(struct crypt_device *cd);
958 * Get cipher mode used in device
960 * @param cd crypt device handle
962 * @return used cipher mode e.g. "xts-plain" or @e otherwise
965 const char *crypt_get_cipher_mode(struct crypt_device *cd);
970 * @param cd crypt device handle
972 * @return device UUID or @e NULL if not set
975 const char *crypt_get_uuid(struct crypt_device *cd);
978 * Get path to underlaying device
980 * @param cd crypt device handle
982 * @return path to underlaying device name
985 const char *crypt_get_device_name(struct crypt_device *cd);
988 * Get device offset in sectors where real data starts on underlying device)
990 * @param cd crypt device handle
992 * @return device offset in sectors
995 uint64_t crypt_get_data_offset(struct crypt_device *cd);
998 * Get IV offset in sectors (skip)
1000 * @param cd crypt device handle
1005 uint64_t crypt_get_iv_offset(struct crypt_device *cd);
1008 * Get size (in bytes) of volume key for crypt device
1010 * @param cd crypt device handle
1012 * @return volume key size
1015 int crypt_get_volume_key_size(struct crypt_device *cd);
1018 * Get device parameters for VERITY device
1020 * @param cd crypt device handle
1021 * @param vp verity device info
1023 * @e 0 on success or negative errno value otherwise.
1026 int crypt_get_verity_info(struct crypt_device *cd,
1027 struct crypt_params_verity *vp);
1031 * @addtogroup keyslot
1037 * Crypt keyslot info
1040 CRYPT_SLOT_INVALID, /**< invalid keyslot */
1041 CRYPT_SLOT_INACTIVE, /**< keyslot is inactive (free) */
1042 CRYPT_SLOT_ACTIVE, /**< keyslot is active (used) */
1043 CRYPT_SLOT_ACTIVE_LAST /**< keylost is active (used)
1044 * and last used at the same time */
1045 } crypt_keyslot_info;
1048 * Get information about particular key slot
1051 * @param cd crypt device handle
1052 * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
1054 * @return value defined by crypt_keyslot_info
1057 crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot);
1061 * Get number of keyslots supported for device type.
1063 * @param type crypt device type
1065 * @return slot count or negative errno otherwise if device
1066 * doesn't not support keyslots.
1068 int crypt_keyslot_max(const char *type);
1071 * Get keyslot area pointers (relative to metadata device)
1073 * @param cd crypt device handle
1074 * @param keyslot keyslot number
1075 * @param offset offset on metadata device (in bytes)
1076 * @param length length of keyslot area (in bytes)
1078 * @return @e 0 on success or negative errno value otherwise.
1081 int crypt_keyslot_area(struct crypt_device *cd,
1087 * Backup header and keyslots to file
1089 * @param cd crypt device handle
1090 * @param requested_type @link crypt_type @endlink or @e NULL for all known
1091 * @param backup_file file to backup header to
1093 * @return @e 0 on success or negative errno value otherwise.
1096 int crypt_header_backup(struct crypt_device *cd,
1097 const char *requested_type,
1098 const char *backup_file);
1101 * Restore header and keyslots from backup file
1104 * @param cd crypt device handle
1105 * @param requested_type @link crypt_type @endlink or @e NULL for all known
1106 * @param backup_file file to restore header from
1108 * @return @e 0 on success or negative errno value otherwise.
1111 int crypt_header_restore(struct crypt_device *cd,
1112 const char *requested_type,
1113 const char *backup_file);
1116 * Receives last reported error
1118 * @param cd crypt device handle
1119 * @param buf buffef for message
1120 * @param size size of buffer
1122 * @note Note that this is old API function using global context.
1123 * All error messages are reported also through log callback.
1125 void crypt_last_error(struct crypt_device *cd, char *buf, size_t size);
1128 * Receives last reported error, DEPRECATED
1130 * @param buf buffef for message
1131 * @param size size of buffer
1133 * @note Note that this is old API function using global context.
1134 * All error messages are reported also through log callback.
1136 void crypt_get_error(char *buf, size_t size);
1139 * Get directory where mapped crypt devices are created
1141 * @return the directory path
1143 const char *crypt_get_dir(void);
1146 * @defgroup dbg "Library debug level"
1148 * Set library debug level
1155 #define CRYPT_DEBUG_ALL -1
1157 #define CRYPT_DEBUG_NONE 0
1160 * Set the debug level for library
1162 * @param level debug level
1165 void crypt_set_debug_level(int level);
1172 #endif /* _LIBCRYPTSETUP_H */