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.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * @file libcryptsetup.h
24 * @brief Public cryptsetup API
26 * For more verbose examples of LUKS related use cases,
27 * please read @ref index "examples".
30 #ifndef _LIBCRYPTSETUP_H
31 #define _LIBCRYPTSETUP_H
39 struct crypt_device; /* crypt device handle */
42 * Initialize crypt device handle and check if provided device exists.
44 * @param cd Returns pointer to crypt device handle
45 * @param device Path to the backing device.
46 * If @e device is not a block device but a path to some file,
47 * the function will try to create a loopdevice and attach
48 * the file to the loopdevice with AUTOCLEAR flag set.
49 * If @e device is @e NULL function it will initialize dm backend only.
51 * @return @e 0 on success or negative errno value otherwise.
53 * @note Note that logging is not initialized here, possible messages uses
54 * default log function.
56 int crypt_init(struct crypt_device **cd, const char *device);
59 * Initialize crypt device handle from provided active device name,
60 * and, optionally, from separate metadata (header) device
61 * and check if provided device exists.
63 * @return @e 0 on success or negative errno value otherwise.
65 * @param cd returns crypt device handle for active device
66 * @param name name of active crypt device
67 * @param header_device optional device containing on-disk header
68 * (@e NULL if it the same as underlying device on there is no on-disk header)
70 * @post In case @e device points to active LUKS device but header load fails,
71 * context device type is set to @e NULL and @e 0 is returned as if it were successful.
72 * Context with @e NULL device type can only be deactivated by crypt_deactivate
74 * @note @link crypt_init_by_name @endlink is equivalent to calling
75 * crypt_init_by_name_and_header(cd, name, NULL);
77 int crypt_init_by_name_and_header(struct crypt_device **cd,
79 const char *header_device);
82 * This is equivalent to call
83 * @ref crypt_init_by_name_and_header "crypt_init_by_name_and_header(cd, name, NULL)"
85 * @sa crypt_init_by_name_and_header
87 int crypt_init_by_name(struct crypt_device **cd, const char *name);
90 * @defgroup loglevel "Cryptsetup logging"
92 * Set of functions and defines used in cryptsetup for
98 * @addtogroup loglevel
102 /** normal log level */
103 #define CRYPT_LOG_NORMAL 0
104 /** error log level */
105 #define CRYPT_LOG_ERROR 1
106 /** verbose log level */
107 #define CRYPT_LOG_VERBOSE 2
108 /** debug log level - always on stdout */
109 #define CRYPT_LOG_DEBUG -1
114 * @param cd crypt device handle (can be @e NULL to set default log function)
115 * @param log user defined log function reference
116 * @param usrptr provided identification in callback
117 * @param level log level below (debug messages can uses other levels)
118 * @param msg log message
120 void crypt_set_log_callback(struct crypt_device *cd,
121 void (*log)(int level, const char *msg, void *usrptr),
125 * Defines log function or use the default one otherwise.
127 * @see crypt_set_log_callback
129 * @param cd crypt device handle
130 * @param level log level
131 * @param msg log message
133 void crypt_log(struct crypt_device *cd, int level, const char *msg);
137 * Set confirmation callback (yes/no)
139 * If code need confirmation (like resetting uuid or restoring LUKS header from file)
140 * this function is called. If not defined, everything is confirmed.
142 * Callback function @e confirm should return @e 0 if operation is declined,
143 * other values mean accepted.
145 * @param cd crypt device handle
146 * @param confirm user defined confirm callback reference
147 * @param usrptr provided identification in callback
148 * @param msg Message for user to confirm
150 * @note Current version of cryptsetup API requires confirmation only when UUID is being changed
152 void crypt_set_confirm_callback(struct crypt_device *cd,
153 int (*confirm)(const char *msg, void *usrptr),
157 * Set password query callback.
159 * If code need @e _interactive_ query for password, this callback is called.
160 * If not defined, compiled-in default is called (uses terminal input).
162 * Callback should return length of password in buffer
163 * or negative errno value in case of error.
165 * @param cd crypt device handle
166 * @param password user defined password callback reference
167 * @param usrptr provided identification in callback
168 * @param msg Message for user
169 * @param buf buffer for password
170 * @param length size of buffer
172 * @note Note that if this function is defined, verify option is ignored
173 * (caller which provided callback is responsible for password verification)
174 * @note Only zero terminated passwords can be entered this way, for complex
175 * use API functions directly.
176 * @note Maximal length of password is limited to @e length @e - @e 1 (minimal 511 chars)
178 * @see Callback function is used in these call provided, that certain conditions are met:
179 * @li crypt_keyslot_add_by_passphrase
180 * @li crypt_activate_by_passphrase
181 * @li crypt_resume_by_passphrase
182 * @li crypt_resume_by_keyfile
183 * @li crypt_keyslot_add_by_keyfile
184 * @li crypt_keyslot_add_by_volume_key
187 void crypt_set_password_callback(struct crypt_device *cd,
188 int (*password)(const char *msg, char *buf, size_t length, void *usrptr),
192 * Set timeout for interactive password entry using default
195 * @param cd crypt device handle
196 * @param timeout_sec timeout in seconds
198 void crypt_set_timeout(struct crypt_device *cd, uint64_t timeout_sec);
201 * Set number of retries in case password input has been incorrect
203 * @param cd crypt device handle
204 * @param tries the number
206 void crypt_set_password_retry(struct crypt_device *cd, int tries);
209 * Set how long should cryptsetup iterate in PBKDF2 function.
210 * Default value heads towards the iterations which takes around 1 second
212 * @param cd crypt device handle
213 * @param iteration_time_ms the time in ms
215 void crypt_set_iteration_time(struct crypt_device *cd, uint64_t iteration_time_ms);
217 void crypt_set_iterarion_time(struct crypt_device *cd, uint64_t iteration_time_ms);
220 * Set whether passphrase will be verified on input
221 * (user has to input same passphrase twice)
223 * @param cd crypt device handle
224 * @param password_verify @e 0 = false, @e !0 true
226 void crypt_set_password_verify(struct crypt_device *cd, int password_verify);
229 * Set data device (encrypted payload area device) if LUKS header is separated
231 * @param cd crypt device handle
232 * @param device path to device
234 * @pre context is of LUKS type
235 * @pre unlike @ref crypt_init, in this function param @e device
236 * has to be block device (at least 512B large)
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"
310 * @param cd crypt device handle
311 * @return string according to device type or @e NULL if not known.
313 const char *crypt_get_type(struct crypt_device *cd);
317 * Structure used as parameter for PLAIN device type
321 struct crypt_params_plain {
322 const char *hash; /**< password hash function */
323 uint64_t offset; /**< offset in sectors */
324 uint64_t skip; /**< IV offset / initialization sector */
325 uint64_t size; /**< size of mapped device or @e 0 for autodetection */
329 * Structure used as parameter for LUKS device type
331 * @see crypt_format, crypt_load
333 * @note during crypt_format @e data_device attribute determines
334 * if the LUKS header is separated from encrypted payload device
337 struct crypt_params_luks1 {
338 const char *hash; /**< hash used in LUKS header */
339 size_t data_alignment; /**< data alignment in sectors, data offset is multiple of this */
340 const char *data_device; /**< detached encrypted data device or @e NULL */
345 * Structure used as parameter for loop-AES device type
350 struct crypt_params_loopaes {
351 const char *hash; /**< key hash function */
352 uint64_t offset; /**< offset in sectors */
353 uint64_t skip; /**< IV offset / initialization sector */
358 * Structure used as parameter for dm-verity device type
360 * @see crypt_format, crypt_load
363 /** No on-disk header (only hashes) */
364 #define CRYPT_VERITY_NO_HEADER (1 << 0)
365 /** Verity hash in userspace before activation */
366 #define CRYPT_VERITY_CHECK_HASH (1 << 1)
367 /** Create hash - format hash device */
368 #define CRYPT_VERITY_CREATE_HASH (1 << 2)
370 struct crypt_params_verity {
371 const char *hash_name; /**< hash function */
372 const char *data_device; /**< data_device (CRYPT_VERITY_CREATE_HASH) */
373 const char *salt; /**< salt */
374 uint64_t salt_size; /**< salt size (in bytes) */
375 uint32_t data_block_size; /**< data block size (in bytes) */
376 uint32_t hash_block_size; /**< hash block size (in bytes) */
377 uint64_t data_size; /**< data area size (in data blocks) */
378 uint64_t hash_area_offset; /**< hash/header offset (in bytes) */
379 uint32_t version; /**< in-kernel hash version */
380 uint32_t flags; /**< CRYPT_VERITY* flags */
386 * Create (format) new crypt device (and possible header on-disk) but not activates it.
388 * @pre @e cd contains initialized and not formatted device context (device type must @b not be set)
390 * @param cd crypt device handle
391 * @param type type of device (optional params struct must be of this type)
392 * @param cipher (e.g. "aes")
393 * @param cipher_mode including IV specification (e.g. "xts-plain")
394 * @param uuid requested UUID or @e NULL if it should be generated
395 * @param volume_key pre-generated volume key or @e NULL if it should be generated (only for LUKS)
396 * @param volume_key_size size of volume key in bytes.
397 * @param params crypt type specific parameters (see @link crypt_type @endlink)
399 * @returns @e 0 on success or negative errno value otherwise.
401 * @note Note that crypt_format does not enable any keyslot (in case of work with LUKS device), but it stores volume key internally
402 * and subsequent crypt_keyslot_add_* calls can be used.
404 int crypt_format(struct crypt_device *cd,
407 const char *cipher_mode,
409 const char *volume_key,
410 size_t volume_key_size,
414 * Set new UUID for already existing device
416 * @param cd crypt device handle
417 * @param uuid requested UUID or @e NULL if it should be generated
419 * @returns 0 on success or negative errno value otherwise.
421 * @note Currently, only LUKS device type are supported
423 int crypt_set_uuid(struct crypt_device *cd,
427 * Load crypt device parameters from on-disk header
429 * @param cd crypt device handle
430 * @param requested_type @link crypt_type @endlink or @e NULL for all known
431 * @param params crypt type specific parameters (see @link crypt_type @endlink)
433 * @returns 0 on success or negative errno value otherwise.
435 * @post In case LUKS header is read successfully but payload device is too small
436 * error is returned and device type in context is set to @e NULL
438 * @note Note that in current version load works only for LUKS device type
441 int crypt_load(struct crypt_device *cd,
442 const char *requested_type,
446 * Try to repair crypt device on-disk header if invalid
448 * @param cd crypt device handle
449 * @param requested_type @link crypt_type @endlink or @e NULL for all known
450 * @param params crypt type specific parameters (see @link crypt_type @endlink)
452 * @returns 0 on success or negative errno value otherwise.
455 int crypt_repair(struct crypt_device *cd,
456 const char *requested_type,
460 * Resize crypt device
462 * @param cd - crypt device handle
463 * @param name - name of device to resize
464 * @param new_size - new device size in sectors or @e 0 to use all of the underlying device size
466 * @return @e 0 on success or negative errno value otherwise.
468 int crypt_resize(struct crypt_device *cd,
473 * Suspends crypt device.
475 * @param cd crypt device handle, can be @e NULL
476 * @param name name of device to suspend
478 * @return 0 on success or negative errno value otherwise.
480 * @note Only LUKS device type is supported
483 int crypt_suspend(struct crypt_device *cd,
487 * Resumes crypt device using passphrase.
490 * @param cd crypt device handle
491 * @param name name of device to resume
492 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
493 * @param passphrase passphrase used to unlock volume key, @e NULL for query
494 * @param passphrase_size size of @e passphrase (binary data)
496 * @return unlocked key slot number or negative errno otherwise.
498 * @note Only LUKS device type is supported
500 int crypt_resume_by_passphrase(struct crypt_device *cd,
503 const char *passphrase,
504 size_t passphrase_size);
507 * Resumes crypt device using key file.
509 * @param cd crypt device handle
510 * @param name name of device to resume
511 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
512 * @param keyfile key file used to unlock volume key, @e NULL for passphrase query
513 * @param keyfile_size number of bytes to read from keyfile, 0 is unlimited
514 * @param keyfile_offset number of bytes to skip at start of keyfile
516 * @return unlocked key slot number or negative errno otherwise.
518 int crypt_resume_by_keyfile_offset(struct crypt_device *cd,
523 size_t keyfile_offset);
525 * Backward compatible crypt_resume_by_keyfile_offset() (without offset).
527 int crypt_resume_by_keyfile(struct crypt_device *cd,
531 size_t keyfile_size);
534 * Releases crypt device context and used memory.
536 * @param cd crypt device handle
538 void crypt_free(struct crypt_device *cd);
541 * @defgroup keyslot "Cryptsetup LUKS keyslots"
542 * @addtogroup keyslot
547 /** iterate through all keyslots and find first one that fits */
548 #define CRYPT_ANY_SLOT -1
551 * Add key slot using provided passphrase
553 * @pre @e cd contains initialized and formatted LUKS device context
555 * @param cd crypt device handle
556 * @param keyslot requested keyslot or @e CRYPT_ANY_SLOT
557 * @param passphrase passphrase used to unlock volume key, @e NULL for query
558 * @param passphrase_size size of passphrase (binary data)
559 * @param new_passphrase passphrase for new keyslot, @e NULL for query
560 * @param new_passphrase_size size of @e new_passphrase (binary data)
562 * @return allocated key slot number or negative errno otherwise.
564 int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
566 const char *passphrase,
567 size_t passphrase_size,
568 const char *new_passphrase,
569 size_t new_passphrase_size);
572 * Get number of keyslots supported for device type.
574 * @param type crypt device type
576 * @return slot count or negative errno otherwise if device
577 * doesn't not support keyslots.
579 int crypt_keyslot_max(const char *type);
582 * Add key slot using provided key file path
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 keyfile key file used to unlock volume key, @e NULL for passphrase query
589 * @param keyfile_size number of bytes to read from keyfile, @e 0 is unlimited
590 * @param keyfile_offset number of bytes to skip at start of keyfile
591 * @param new_keyfile keyfile for new keyslot, @e NULL for passphrase query
592 * @param new_keyfile_size number of bytes to read from @e new_keyfile, @e 0 is unlimited
593 * @param new_keyfile_offset number of bytes to skip at start of new_keyfile
595 * @return allocated key slot number or negative errno otherwise.
597 * @note Note that @e keyfile can be "-" for STDIN
600 int crypt_keyslot_add_by_keyfile_offset(struct crypt_device *cd,
604 size_t keyfile_offset,
605 const char *new_keyfile,
606 size_t new_keyfile_size,
607 size_t new_keyfile_offset);
609 * Backward compatible crypt_keyslot_add_by_keyfile_offset() (without offset).
611 int crypt_keyslot_add_by_keyfile(struct crypt_device *cd,
615 const char *new_keyfile,
616 size_t new_keyfile_size);
619 * Add key slot using provided volume key
621 * @pre @e cd contains initialized and formatted LUKS device context
623 * @param cd crypt device handle
624 * @param keyslot requested keyslot or CRYPT_ANY_SLOT
625 * @param volume_key provided volume key or @e NULL if used after crypt_format
626 * @param volume_key_size size of volume_key
627 * @param passphrase passphrase for new keyslot, @e NULL for query
628 * @param passphrase_size size of passphrase
630 * @return allocated key slot number or negative errno otherwise.
633 int crypt_keyslot_add_by_volume_key(struct crypt_device *cd,
635 const char *volume_key,
636 size_t volume_key_size,
637 const char *passphrase,
638 size_t passphrase_size);
641 * Destroy (and disable) key slot
643 * @pre @e cd contains initialized and formatted LUKS device context
645 * @param cd crypt device handle
646 * @param keyslot requested key slot to destroy
648 * @return @e 0 on success or negative errno value otherwise.
650 * @note Note that there is no passphrase verification used.
652 int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot);
657 * @defgroup aflags "Device runtime attributes"
665 /** device is read only */
666 #define CRYPT_ACTIVATE_READONLY (1 << 0)
667 /** only reported for device without uuid */
668 #define CRYPT_ACTIVATE_NO_UUID (1 << 1)
669 /** activate even if cannot grant exclusive access (DANGEROUS) */
670 #define CRYPT_ACTIVATE_SHARED (1 << 2)
671 /** enable discards aka TRIM */
672 #define CRYPT_ACTIVATE_ALLOW_DISCARDS (1 << 3)
673 /** skip global udev rules in activation ("private device"), input only */
674 #define CRYPT_ACTIVATE_PRIVATE (1 << 4)
677 * Active device runtime attributes
679 struct crypt_active_device {
680 uint64_t offset; /**< offset in sectors */
681 uint64_t iv_offset; /**< IV initialization sector */
682 uint64_t size; /**< active device size */
683 uint32_t flags; /**< activation flags */
687 * Receives runtime attributes of active crypt device
689 * @param cd crypt device handle (can be @e NULL)
690 * @param name name of active device
691 * @param cad preallocated active device attributes to fill
693 * @return @e 0 on success or negative errno value otherwise
696 int crypt_get_active_device(struct crypt_device *cd,
698 struct crypt_active_device *cad);
703 * Activate device or check passphrase
705 * @param cd crypt device handle
706 * @param name name of device to create, if @e NULL only check passphrase
707 * @param keyslot requested keyslot to check or @e CRYPT_ANY_SLOT
708 * @param passphrase passphrase used to unlock volume key, @e NULL for query
709 * @param passphrase_size size of @e passphrase
710 * @param flags activation flags
712 * @return unlocked key slot number or negative errno otherwise.
714 int crypt_activate_by_passphrase(struct crypt_device *cd,
717 const char *passphrase,
718 size_t passphrase_size,
722 * Activate device or check using key file
724 * @param cd crypt device handle
725 * @param name name of device to create, if @e NULL only check keyfile
726 * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
727 * @param keyfile key file used to unlock volume key
728 * @param keyfile_size number of bytes to read from keyfile, 0 is unlimited
729 * @param keyfile_offset number of bytes to skip at start of keyfile
730 * @param flags activation flags
732 * @return unlocked key slot number or negative errno otherwise.
734 int crypt_activate_by_keyfile_offset(struct crypt_device *cd,
739 size_t keyfile_offset,
742 * Backward compatible crypt_activate_by_keyfile_offset() (without offset).
744 int crypt_activate_by_keyfile(struct crypt_device *cd,
752 * Activate device using provided volume key
755 * @param cd crypt device handle
756 * @param name name of device to create, if @e NULL only check volume key
757 * @param volume_key provided volume key (or @e NULL to use internal)
758 * @param volume_key_size size of volume_key
759 * @param flags activation flags
761 * @return @e 0 on success or negative errno value otherwise.
763 * @note If @e NULL is used for volume_key, device has to be initialized
764 * by previous operation (like @ref crypt_format
765 * or @ref crypt_init_by_name)
767 int crypt_activate_by_volume_key(struct crypt_device *cd,
769 const char *volume_key,
770 size_t volume_key_size,
774 * Deactivate crypt device. This function tries to remove active device-mapper
775 * mapping from kernel. Also, sensitive data like the volume key are removed from
778 * @param cd crypt device handle, can be @e NULL
779 * @param name name of device to deactivate
781 * @return @e 0 on success or negative errno value otherwise.
784 int crypt_deactivate(struct crypt_device *cd, const char *name);
787 * Get volume key from of crypt device
789 * @param cd crypt device handle
790 * @param keyslot use this keyslot or @e CRYPT_ANY_SLOT
791 * @param volume_key buffer for volume key
792 * @param volume_key_size on input, size of buffer @e volume_key,
793 * on output size of @e volume_key
794 * @param passphrase passphrase used to unlock volume key
795 * @param passphrase_size size of @e passphrase
797 * @return unlocked key slot number or negative errno otherwise.
799 int crypt_volume_key_get(struct crypt_device *cd,
802 size_t *volume_key_size,
803 const char *passphrase,
804 size_t passphrase_size);
807 * Verify that provided volume key is valid for crypt device
809 * @param cd crypt device handle
810 * @param volume_key provided volume key
811 * @param volume_key_size size of @e volume_key
813 * @return @e 0 on success or negative errno value otherwise.
815 int crypt_volume_key_verify(struct crypt_device *cd,
816 const char *volume_key,
817 size_t volume_key_size);
821 * @defgroup devstat "dmcrypt device status"
822 * @addtogroup devstat
830 CRYPT_INVALID, /**< device mapping is invalid in this context */
831 CRYPT_INACTIVE, /**< no such mapped device */
832 CRYPT_ACTIVE, /**< device is active */
833 CRYPT_BUSY /**< device is active and has open count > 0 */
837 * Get status info about device name
839 * @param cd crypt device handle, can be @e NULL
840 * @param name crypt device name
842 * @return value defined by crypt_status_info.
845 crypt_status_info crypt_status(struct crypt_device *cd, const char *name);
848 * Dump text-formatted information about crypt device to log output
850 * @param cd crypt device handle
852 * @return @e 0 on success or negative errno value otherwise.
854 int crypt_dump(struct crypt_device *cd);
857 * Get cipher used in device
859 * @param cd crypt device handle
861 * @return used cipher, e.g. "aes" or @e NULL otherwise
864 const char *crypt_get_cipher(struct crypt_device *cd);
867 * Get cipher mode used in device
869 * @param cd crypt device handle
871 * @return used cipher mode e.g. "xts-plain" or @e otherwise
874 const char *crypt_get_cipher_mode(struct crypt_device *cd);
879 * @param cd crypt device handle
881 * @return device UUID or @e NULL if not set
884 const char *crypt_get_uuid(struct crypt_device *cd);
887 * Get path to underlaying device
889 * @param cd crypt device handle
891 * @return path to underlaying device name
894 const char *crypt_get_device_name(struct crypt_device *cd);
897 * Get device offset in sectors where real data starts on underlying device)
899 * @param cd crypt device handle
901 * @return device offset in sectors
904 uint64_t crypt_get_data_offset(struct crypt_device *cd);
907 * Get IV offset in sectors (skip)
909 * @param cd crypt device handle
914 uint64_t crypt_get_iv_offset(struct crypt_device *cd);
917 * Get size (in bytes) of volume key for crypt device
919 * @param cd crypt device handle
921 * @return volume key size
924 int crypt_get_volume_key_size(struct crypt_device *cd);
927 * @addtogroup keyslot
936 CRYPT_SLOT_INVALID, /**< invalid keyslot */
937 CRYPT_SLOT_INACTIVE, /**< keyslot is inactive (free) */
938 CRYPT_SLOT_ACTIVE, /**< keyslot is active (used) */
939 CRYPT_SLOT_ACTIVE_LAST /**< keylost is active (used)
940 * and last used at the same time */
941 } crypt_keyslot_info;
944 * Get information about particular key slot
947 * @param cd crypt device handle
948 * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
950 * @return value defined by crypt_keyslot_info
953 crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot);
957 * Backup header and keyslots to file
959 * @param cd crypt device handle
960 * @param requested_type @link crypt_type @endlink or @e NULL for all known
961 * @param backup_file file to backup header to
963 * @return @e 0 on success or negative errno value otherwise.
966 int crypt_header_backup(struct crypt_device *cd,
967 const char *requested_type,
968 const char *backup_file);
971 * Restore header and keyslots from backup file
974 * @param cd crypt device handle
975 * @param requested_type @link crypt_type @endlink or @e NULL for all known
976 * @param backup_file file to restore header from
978 * @return @e 0 on success or negative errno value otherwise.
981 int crypt_header_restore(struct crypt_device *cd,
982 const char *requested_type,
983 const char *backup_file);
986 * Receives last reported error
988 * @param cd crypt device handle
989 * @param buf buffef for message
990 * @param size size of buffer
992 * @note Note that this is old API function using global context.
993 * All error messages are reported also through log callback.
995 void crypt_last_error(struct crypt_device *cd, char *buf, size_t size);
998 * Receives last reported error, DEPRECATED
1000 * @param buf buffef for message
1001 * @param size size of buffer
1003 * @note Note that this is old API function using global context.
1004 * All error messages are reported also through log callback.
1006 void crypt_get_error(char *buf, size_t size);
1009 * Get directory where mapped crypt devices are created
1011 * @return the directory path
1013 const char *crypt_get_dir(void);
1016 * @defgroup dbg "Library debug level"
1018 * Set library debug level
1025 #define CRYPT_DEBUG_ALL -1
1027 #define CRYPT_DEBUG_NONE 0
1030 * Set the debug level for library
1032 * @param level debug level
1035 void crypt_set_debug_level(int level);
1042 #endif /* _LIBCRYPTSETUP_H */