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)
400 struct crypt_params_tcrypt {
401 const char *passphrase; /**< passphrase to unlock header (input only) */
402 size_t passphrase_size; /**< passphrase size (input only) */
403 const char **keyfiles; /**< keyfile paths to unlock header (input only) */
404 unsigned int keyfiles_count;/**< keyfiles count (input only) */
405 const char *hash_name; /**< hash function for PBKDF */
406 const char *cipher; /**< cipher chain c1[-c2[-c3]] */
407 const char *mode; /**< cipher block mode */
408 size_t key_size; /**< key size in bytes (the whole chain) */
409 uint32_t flags; /**< CRYPT_TCRYPT* flags */
415 * Create (format) new crypt device (and possible header on-disk) but not activates it.
417 * @pre @e cd contains initialized and not formatted device context (device type must @b not be set)
419 * @param cd crypt device handle
420 * @param type type of device (optional params struct must be of this type)
421 * @param cipher (e.g. "aes")
422 * @param cipher_mode including IV specification (e.g. "xts-plain")
423 * @param uuid requested UUID or @e NULL if it should be generated
424 * @param volume_key pre-generated volume key or @e NULL if it should be generated (only for LUKS)
425 * @param volume_key_size size of volume key in bytes.
426 * @param params crypt type specific parameters (see @link crypt_type @endlink)
428 * @returns @e 0 on success or negative errno value otherwise.
430 * @note Note that crypt_format does not enable any keyslot (in case of work with LUKS device),
431 * but it stores volume key internally and subsequent crypt_keyslot_add_* calls can be used.
432 * @note For VERITY @link crypt_type @endlink, only uuid parameter is used, others paramaters
433 * are ignored and verity specific attributes are set through mandatory params option.
435 int crypt_format(struct crypt_device *cd,
438 const char *cipher_mode,
440 const char *volume_key,
441 size_t volume_key_size,
445 * Set new UUID for already existing device
447 * @param cd crypt device handle
448 * @param uuid requested UUID or @e NULL if it should be generated
450 * @returns 0 on success or negative errno value otherwise.
452 * @note Currently, only LUKS device type are supported
454 int crypt_set_uuid(struct crypt_device *cd,
458 * Load crypt device parameters from on-disk header
460 * @param cd crypt device handle
461 * @param requested_type @link crypt_type @endlink or @e NULL for all known
462 * @param params crypt type specific parameters (see @link crypt_type @endlink)
464 * @returns 0 on success or negative errno value otherwise.
466 * @post In case LUKS header is read successfully but payload device is too small
467 * error is returned and device type in context is set to @e NULL
469 * @note Note that in current version load works only for LUKS and VERITY device type.
472 int crypt_load(struct crypt_device *cd,
473 const char *requested_type,
477 * Try to repair crypt device on-disk header if invalid
479 * @param cd crypt device handle
480 * @param requested_type @link crypt_type @endlink or @e NULL for all known
481 * @param params crypt type specific parameters (see @link crypt_type @endlink)
483 * @returns 0 on success or negative errno value otherwise.
486 int crypt_repair(struct crypt_device *cd,
487 const char *requested_type,
491 * Resize crypt device
493 * @param cd - crypt device handle
494 * @param name - name of device to resize
495 * @param new_size - new device size in sectors or @e 0 to use all of the underlying device size
497 * @return @e 0 on success or negative errno value otherwise.
499 int crypt_resize(struct crypt_device *cd,
504 * Suspends crypt device.
506 * @param cd crypt device handle, can be @e NULL
507 * @param name name of device to suspend
509 * @return 0 on success or negative errno value otherwise.
511 * @note Only LUKS device type is supported
514 int crypt_suspend(struct crypt_device *cd,
518 * Resumes crypt device using passphrase.
521 * @param cd crypt device handle
522 * @param name name of device to resume
523 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
524 * @param passphrase passphrase used to unlock volume key, @e NULL for query
525 * @param passphrase_size size of @e passphrase (binary data)
527 * @return unlocked key slot number or negative errno otherwise.
529 * @note Only LUKS device type is supported
531 int crypt_resume_by_passphrase(struct crypt_device *cd,
534 const char *passphrase,
535 size_t passphrase_size);
538 * Resumes crypt device using key file.
540 * @param cd crypt device handle
541 * @param name name of device to resume
542 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
543 * @param keyfile key file used to unlock volume key, @e NULL for passphrase query
544 * @param keyfile_size number of bytes to read from keyfile, 0 is unlimited
545 * @param keyfile_offset number of bytes to skip at start of keyfile
547 * @return unlocked key slot number or negative errno otherwise.
549 int crypt_resume_by_keyfile_offset(struct crypt_device *cd,
554 size_t keyfile_offset);
556 * Backward compatible crypt_resume_by_keyfile_offset() (without offset).
558 int crypt_resume_by_keyfile(struct crypt_device *cd,
562 size_t keyfile_size);
565 * Releases crypt device context and used memory.
567 * @param cd crypt device handle
569 void crypt_free(struct crypt_device *cd);
572 * @defgroup keyslot "Cryptsetup LUKS keyslots"
573 * @addtogroup keyslot
578 /** iterate through all keyslots and find first one that fits */
579 #define CRYPT_ANY_SLOT -1
582 * Add key slot using provided passphrase
584 * @pre @e cd contains initialized and formatted LUKS device context
586 * @param cd crypt device handle
587 * @param keyslot requested keyslot or @e CRYPT_ANY_SLOT
588 * @param passphrase passphrase used to unlock volume key, @e NULL for query
589 * @param passphrase_size size of passphrase (binary data)
590 * @param new_passphrase passphrase for new keyslot, @e NULL for query
591 * @param new_passphrase_size size of @e new_passphrase (binary data)
593 * @return allocated key slot number or negative errno otherwise.
595 int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
597 const char *passphrase,
598 size_t passphrase_size,
599 const char *new_passphrase,
600 size_t new_passphrase_size);
603 * Change defined key slot using provided passphrase
605 * @pre @e cd contains initialized and formatted LUKS device context
607 * @param cd crypt device handle
608 * @param keyslot_old old keyslot or @e CRYPT_ANY_SLOT
609 * @param keyslot_new new keyslot (can be the same as old)
610 * @param passphrase passphrase used to unlock volume key, @e NULL for query
611 * @param passphrase_size size of passphrase (binary data)
612 * @param new_passphrase passphrase for new keyslot, @e NULL for query
613 * @param new_passphrase_size size of @e new_passphrase (binary data)
615 * @return allocated key slot number or negative errno otherwise.
617 * @note This function is just internal implementation of luksChange
618 * command to avoid reading of volume key outside libcryptsetup boundary
621 int crypt_keyslot_change_by_passphrase(struct crypt_device *cd,
624 const char *passphrase,
625 size_t passphrase_size,
626 const char *new_passphrase,
627 size_t new_passphrase_size);
630 * Add key slot using provided key file path
632 * @pre @e cd contains initialized and formatted LUKS device context
634 * @param cd crypt device handle
635 * @param keyslot requested keyslot or @e CRYPT_ANY_SLOT
636 * @param keyfile key file used to unlock volume key, @e NULL for passphrase query
637 * @param keyfile_size number of bytes to read from keyfile, @e 0 is unlimited
638 * @param keyfile_offset number of bytes to skip at start of keyfile
639 * @param new_keyfile keyfile for new keyslot, @e NULL for passphrase query
640 * @param new_keyfile_size number of bytes to read from @e new_keyfile, @e 0 is unlimited
641 * @param new_keyfile_offset number of bytes to skip at start of new_keyfile
643 * @return allocated key slot number or negative errno otherwise.
645 * @note Note that @e keyfile can be "-" for STDIN
648 int crypt_keyslot_add_by_keyfile_offset(struct crypt_device *cd,
652 size_t keyfile_offset,
653 const char *new_keyfile,
654 size_t new_keyfile_size,
655 size_t new_keyfile_offset);
657 * Backward compatible crypt_keyslot_add_by_keyfile_offset() (without offset).
659 int crypt_keyslot_add_by_keyfile(struct crypt_device *cd,
663 const char *new_keyfile,
664 size_t new_keyfile_size);
667 * Add key slot using provided volume key
669 * @pre @e cd contains initialized and formatted LUKS device context
671 * @param cd crypt device handle
672 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
673 * @param volume_key provided volume key or @e NULL if used after crypt_format
674 * @param volume_key_size size of volume_key
675 * @param passphrase passphrase for new keyslot, @e NULL for query
676 * @param passphrase_size size of passphrase
678 * @return allocated key slot number or negative errno otherwise.
681 int crypt_keyslot_add_by_volume_key(struct crypt_device *cd,
683 const char *volume_key,
684 size_t volume_key_size,
685 const char *passphrase,
686 size_t passphrase_size);
689 * Destroy (and disable) key slot
691 * @pre @e cd contains initialized and formatted LUKS device context
693 * @param cd crypt device handle
694 * @param keyslot requested key slot to destroy
696 * @return @e 0 on success or negative errno value otherwise.
698 * @note Note that there is no passphrase verification used.
700 int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot);
705 * @defgroup aflags "Device runtime attributes"
713 /** device is read only */
714 #define CRYPT_ACTIVATE_READONLY (1 << 0)
715 /** only reported for device without uuid */
716 #define CRYPT_ACTIVATE_NO_UUID (1 << 1)
717 /** activate even if cannot grant exclusive access (DANGEROUS) */
718 #define CRYPT_ACTIVATE_SHARED (1 << 2)
719 /** enable discards aka TRIM */
720 #define CRYPT_ACTIVATE_ALLOW_DISCARDS (1 << 3)
721 /** skip global udev rules in activation ("private device"), input only */
722 #define CRYPT_ACTIVATE_PRIVATE (1 << 4)
723 /** corruption detected (verity), output only */
724 #define CRYPT_ACTIVATE_CORRUPTED (1 << 5)
727 * Active device runtime attributes
729 struct crypt_active_device {
730 uint64_t offset; /**< offset in sectors */
731 uint64_t iv_offset; /**< IV initialization sector */
732 uint64_t size; /**< active device size */
733 uint32_t flags; /**< activation flags */
737 * Receives runtime attributes of active crypt device
739 * @param cd crypt device handle (can be @e NULL)
740 * @param name name of active device
741 * @param cad preallocated active device attributes to fill
743 * @return @e 0 on success or negative errno value otherwise
746 int crypt_get_active_device(struct crypt_device *cd,
748 struct crypt_active_device *cad);
753 * Activate device or check passphrase
755 * @param cd crypt device handle
756 * @param name name of device to create, if @e NULL only check passphrase
757 * @param keyslot requested keyslot to check or @e CRYPT_ANY_SLOT
758 * @param passphrase passphrase used to unlock volume key, @e NULL for query
759 * @param passphrase_size size of @e passphrase
760 * @param flags activation flags
762 * @return unlocked key slot number or negative errno otherwise.
764 int crypt_activate_by_passphrase(struct crypt_device *cd,
767 const char *passphrase,
768 size_t passphrase_size,
772 * Activate device or check using key file
774 * @param cd crypt device handle
775 * @param name name of device to create, if @e NULL only check keyfile
776 * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
777 * @param keyfile key file used to unlock volume key
778 * @param keyfile_size number of bytes to read from keyfile, 0 is unlimited
779 * @param keyfile_offset number of bytes to skip at start of keyfile
780 * @param flags activation flags
782 * @return unlocked key slot number or negative errno otherwise.
784 int crypt_activate_by_keyfile_offset(struct crypt_device *cd,
789 size_t keyfile_offset,
792 * Backward compatible crypt_activate_by_keyfile_offset() (without offset).
794 int crypt_activate_by_keyfile(struct crypt_device *cd,
802 * Activate device using provided volume key
805 * @param cd crypt device handle
806 * @param name name of device to create, if @e NULL only check volume key
807 * @param volume_key provided volume key (or @e NULL to use internal)
808 * @param volume_key_size size of volume_key
809 * @param flags activation flags
811 * @return @e 0 on success or negative errno value otherwise.
813 * @note If @e NULL is used for volume_key, device has to be initialized
814 * by previous operation (like @ref crypt_format
815 * or @ref crypt_init_by_name)
816 * @note For VERITY the volume key means root hash required for activation.
817 * Because kernel dm-verity is always read only, you have to provide
818 * CRYPT_ACTIVATE_READONLY flag always.
819 * @note For TCRYPT the volume key should be always NULL and because master
820 * key from decrypted header is used instead.
822 int crypt_activate_by_volume_key(struct crypt_device *cd,
824 const char *volume_key,
825 size_t volume_key_size,
829 * Deactivate crypt device. This function tries to remove active device-mapper
830 * mapping from kernel. Also, sensitive data like the volume key are removed from
833 * @param cd crypt device handle, can be @e NULL
834 * @param name name of device to deactivate
836 * @return @e 0 on success or negative errno value otherwise.
839 int crypt_deactivate(struct crypt_device *cd, const char *name);
842 * Get volume key from of crypt device
844 * @param cd crypt device handle
845 * @param keyslot use this keyslot or @e CRYPT_ANY_SLOT
846 * @param volume_key buffer for volume key
847 * @param volume_key_size on input, size of buffer @e volume_key,
848 * on output size of @e volume_key
849 * @param passphrase passphrase used to unlock volume key
850 * @param passphrase_size size of @e passphrase
852 * @return unlocked key slot number or negative errno otherwise.
854 * @note For TCRYPT cipher chain is the volume key concatenated
855 * for all ciphers in chain.
857 int crypt_volume_key_get(struct crypt_device *cd,
860 size_t *volume_key_size,
861 const char *passphrase,
862 size_t passphrase_size);
865 * Verify that provided volume key is valid for crypt device
867 * @param cd crypt device handle
868 * @param volume_key provided volume key
869 * @param volume_key_size size of @e volume_key
871 * @return @e 0 on success or negative errno value otherwise.
873 int crypt_volume_key_verify(struct crypt_device *cd,
874 const char *volume_key,
875 size_t volume_key_size);
878 * @defgroup devstat "Crypt and Verity device status"
879 * @addtogroup devstat
887 CRYPT_INVALID, /**< device mapping is invalid in this context */
888 CRYPT_INACTIVE, /**< no such mapped device */
889 CRYPT_ACTIVE, /**< device is active */
890 CRYPT_BUSY /**< device is active and has open count > 0 */
894 * Get status info about device name
896 * @param cd crypt device handle, can be @e NULL
897 * @param name crypt device name
899 * @return value defined by crypt_status_info.
902 crypt_status_info crypt_status(struct crypt_device *cd, const char *name);
905 * Dump text-formatted information about crypt or verity device to log output
907 * @param cd crypt device handle
909 * @return @e 0 on success or negative errno value otherwise.
911 int crypt_dump(struct crypt_device *cd);
914 * Informational benchmark for ciphers
916 * @param cd crypt device handle
917 * @param cipher (e.g. "aes")
918 * @param cipher_mode (e.g. "xts"), IV generator is ignored
919 * @param volume_key_size size of volume key in bytes
920 * @param iv_size size of IV in bytes
921 * @param buffer_size size of encryption buffer in bytes used in test
922 * @param encryption_mbs measured encryption speed in MiB/s
923 * @param decryption_mbs measured decryption speed in MiB/s
925 * @return @e 0 on success or negative errno value otherwise.
927 int crypt_benchmark(struct crypt_device *cd,
929 const char *cipher_mode,
930 size_t volume_key_size,
933 double *encryption_mbs,
934 double *decryption_mbs);
936 int crypt_benchmark_kdf(struct crypt_device *cd,
939 const char *password,
940 size_t password_size,
943 uint64_t *iterations_sec);
946 * Get cipher used in device
948 * @param cd crypt device handle
950 * @return used cipher, e.g. "aes" or @e NULL otherwise
953 const char *crypt_get_cipher(struct crypt_device *cd);
956 * Get cipher mode used in device
958 * @param cd crypt device handle
960 * @return used cipher mode e.g. "xts-plain" or @e otherwise
963 const char *crypt_get_cipher_mode(struct crypt_device *cd);
968 * @param cd crypt device handle
970 * @return device UUID or @e NULL if not set
973 const char *crypt_get_uuid(struct crypt_device *cd);
976 * Get path to underlaying device
978 * @param cd crypt device handle
980 * @return path to underlaying device name
983 const char *crypt_get_device_name(struct crypt_device *cd);
986 * Get device offset in sectors where real data starts on underlying device)
988 * @param cd crypt device handle
990 * @return device offset in sectors
993 uint64_t crypt_get_data_offset(struct crypt_device *cd);
996 * Get IV offset in sectors (skip)
998 * @param cd crypt device handle
1003 uint64_t crypt_get_iv_offset(struct crypt_device *cd);
1006 * Get size (in bytes) of volume key for crypt device
1008 * @param cd crypt device handle
1010 * @return volume key size
1013 int crypt_get_volume_key_size(struct crypt_device *cd);
1016 * Get device parameters for VERITY device
1018 * @param cd crypt device handle
1019 * @param vp verity device info
1021 * @e 0 on success or negative errno value otherwise.
1024 int crypt_get_verity_info(struct crypt_device *cd,
1025 struct crypt_params_verity *vp);
1029 * @addtogroup keyslot
1035 * Crypt keyslot info
1038 CRYPT_SLOT_INVALID, /**< invalid keyslot */
1039 CRYPT_SLOT_INACTIVE, /**< keyslot is inactive (free) */
1040 CRYPT_SLOT_ACTIVE, /**< keyslot is active (used) */
1041 CRYPT_SLOT_ACTIVE_LAST /**< keylost is active (used)
1042 * and last used at the same time */
1043 } crypt_keyslot_info;
1046 * Get information about particular key slot
1049 * @param cd crypt device handle
1050 * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
1052 * @return value defined by crypt_keyslot_info
1055 crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot);
1059 * Get number of keyslots supported for device type.
1061 * @param type crypt device type
1063 * @return slot count or negative errno otherwise if device
1064 * doesn't not support keyslots.
1066 int crypt_keyslot_max(const char *type);
1069 * Get keyslot area pointers (relative to metadata device)
1071 * @param cd crypt device handle
1072 * @param keyslot keyslot number
1073 * @param offset offset on metadata device (in bytes)
1074 * @param length length of keyslot area (in bytes)
1076 * @return @e 0 on success or negative errno value otherwise.
1079 int crypt_keyslot_area(struct crypt_device *cd,
1085 * Backup header and keyslots to file
1087 * @param cd crypt device handle
1088 * @param requested_type @link crypt_type @endlink or @e NULL for all known
1089 * @param backup_file file to backup header to
1091 * @return @e 0 on success or negative errno value otherwise.
1094 int crypt_header_backup(struct crypt_device *cd,
1095 const char *requested_type,
1096 const char *backup_file);
1099 * Restore header and keyslots from backup file
1102 * @param cd crypt device handle
1103 * @param requested_type @link crypt_type @endlink or @e NULL for all known
1104 * @param backup_file file to restore header from
1106 * @return @e 0 on success or negative errno value otherwise.
1109 int crypt_header_restore(struct crypt_device *cd,
1110 const char *requested_type,
1111 const char *backup_file);
1114 * Receives last reported error
1116 * @param cd crypt device handle
1117 * @param buf buffef for message
1118 * @param size size of buffer
1120 * @note Note that this is old API function using global context.
1121 * All error messages are reported also through log callback.
1123 void crypt_last_error(struct crypt_device *cd, char *buf, size_t size);
1126 * Receives last reported error, DEPRECATED
1128 * @param buf buffef for message
1129 * @param size size of buffer
1131 * @note Note that this is old API function using global context.
1132 * All error messages are reported also through log callback.
1134 void crypt_get_error(char *buf, size_t size);
1137 * Get directory where mapped crypt devices are created
1139 * @return the directory path
1141 const char *crypt_get_dir(void);
1144 * @defgroup dbg "Library debug level"
1146 * Set library debug level
1153 #define CRYPT_DEBUG_ALL -1
1155 #define CRYPT_DEBUG_NONE 0
1158 * Set the debug level for library
1160 * @param level debug level
1163 void crypt_set_debug_level(int level);
1170 #endif /* _LIBCRYPTSETUP_H */