Fix some doxygen docs warnings and mistakes.
[platform/upstream/cryptsetup.git] / lib / libcryptsetup.h
1 /**
2  * @file libcryptsetup.h
3  * @brief Public cryptsetup API
4  *
5  * For more verbose examples of LUKS related use cases,
6  * please read @ref index "examples".
7  */
8
9 #ifndef _LIBCRYPTSETUP_H
10 #define _LIBCRYPTSETUP_H
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 #include <stdint.h>
16
17 struct crypt_device; /* crypt device handle */
18
19 /**
20  * Initialize crypt device handle and check if provided device exists.
21  *
22  * @param cd Returns pointer to crypt device handle
23  * @param device Path to the backing device.
24  *        If @e device is not a block device but a path to some file,
25  *        the function will try to create a loopdevice and attach
26  *        the file to the loopdevice with AUTOCLEAR flag set.
27  *        If @e device is @e NULL function it will initialize dm backend only.
28  *
29  * @return @e 0 on success or negative errno value otherwise.
30  *
31  * @note Note that logging is not initialized here, possible messages uses
32  *       default log function.
33  */
34 int crypt_init(struct crypt_device **cd, const char *device);
35
36 /**
37  * Initialize crypt device handle from provided active device name,
38  * and, optionally, from separate metadata (header) device
39  * and check if provided device exists.
40  *
41  * @return @e 0 on success or negative errno value otherwise.
42  *
43  * @param cd returns crypt device handle for active device
44  * @param name name of active crypt device
45  * @param header_device optional device containing on-disk header
46  *        (@e NULL if it the same as underlying device on there is no on-disk header)
47  *
48  * @post In case @e device points to active LUKS device but header load fails,
49  * context device type is set to @e NULL and @e 0 is returned as if it were successful.
50  * Context with @e NULL device type can only be deactivated by crypt_deactivate
51  *
52  * @note @link crypt_init_by_name @endlink is equivalent to calling
53  *       crypt_init_by_name_and_header(cd, name, NULL);
54  */
55 int crypt_init_by_name_and_header(struct crypt_device **cd,
56                                   const char *name,
57                                   const char *header_device);
58
59 /**
60  * This is equivalent to call
61  * @ref crypt_init_by_name_and_header "crypt_init_by_name_and_header(cd, name, NULL)"
62  *
63  * @sa crypt_init_by_name_and_header
64  */
65 int crypt_init_by_name(struct crypt_device **cd, const char *name);
66
67 /**
68  * @defgroup loglevel "Cryptsetup logging"
69  *
70  * Set of functions and defines used in cryptsetup for
71  * logging purposes
72  *
73  */
74
75 /**
76  * @addtogroup loglevel
77  * @{
78  */
79
80 /** normal log level */
81 #define CRYPT_LOG_NORMAL 0
82 /** error log level */
83 #define CRYPT_LOG_ERROR  1
84 /** verbose log level */
85 #define CRYPT_LOG_VERBOSE  2
86 /** debug log level - always on stdout */
87 #define CRYPT_LOG_DEBUG -1
88
89 /**
90  * Set log function.
91  *
92  * @param cd crypt device handle (can be @e NULL to set default log function)
93  * @param log user defined log function reference
94  * @param usrptr provided identification in callback
95  * @param level log level below (debug messages can uses other levels)
96  * @param msg log message
97  */
98 void crypt_set_log_callback(struct crypt_device *cd,
99         void (*log)(int level, const char *msg, void *usrptr),
100         void *usrptr);
101
102 /**
103  * Defines log function or use the default one otherwise.
104  *
105  * @see crypt_set_log_callback
106  *
107  * @param cd crypt device handle
108  * @param level log level
109  * @param msg log message
110  */
111 void crypt_log(struct crypt_device *cd, int level, const char *msg);
112 /** @} */
113
114 /**
115  * Set confirmation callback (yes/no)
116  *
117  * If code need confirmation (like resetting uuid or restoring LUKS header from file)
118  * this function is called. If not defined, everything is confirmed.
119  *
120  * Callback function @e confirm should return @e 0 if operation is declined,
121  * other values mean accepted.
122  *
123  * @param cd crypt device handle
124  * @param confirm user defined confirm callback reference
125  * @param usrptr provided identification in callback
126  * @param msg Message for user to confirm
127  *
128  * @note Current version of cryptsetup API requires confirmation only when UUID is being changed
129  */
130 void crypt_set_confirm_callback(struct crypt_device *cd,
131         int (*confirm)(const char *msg, void *usrptr),
132         void *usrptr);
133
134 /**
135  * Set password query callback.
136  *
137  * If code need @e _interactive_ query for password, this callback is called.
138  * If not defined, compiled-in default is called (uses terminal input).
139  *
140  * Callback should return length of password in buffer
141  * or negative errno value in case of error.
142  *
143  * @param cd crypt device handle
144  * @param password user defined password callback reference
145  * @param usrptr provided identification in callback
146  * @param msg Message for user
147  * @param buf buffer for password
148  * @param length size of buffer
149  *
150  * @note Note that if this function is defined, verify option is ignored
151  *   (caller which provided callback is responsible for password verification)
152  * @note Only zero terminated passwords can be entered this way, for complex
153  *   use API functions directly.
154  * @note Maximal length of password is limited to @e length @e - @e 1 (minimal 511 chars)
155  *
156  * @see Callback function is used in these call provided, that certain conditions are met:
157  * @li crypt_keyslot_add_by_passphrase
158  * @li crypt_activate_by_passphrase
159  * @li crypt_resume_by_passphrase
160  * @li crypt_resume_by_keyfile
161  * @li crypt_keyslot_add_by_keyfile
162  * @li crypt_keyslot_add_by_volume_key
163  *
164  */
165 void crypt_set_password_callback(struct crypt_device *cd,
166         int (*password)(const char *msg, char *buf, size_t length, void *usrptr),
167         void *usrptr);
168
169 /**
170  * Set timeout for interactive password entry using default
171  * password callback
172  *
173  * @param cd crypt device handle
174  * @param timeout_sec timeout in seconds
175  */
176 void crypt_set_timeout(struct crypt_device *cd, uint64_t timeout_sec);
177
178 /**
179  * Set number of retries in case password input has been incorrect
180  *
181  * @param cd crypt device handle
182  * @param tries the number
183  */
184 void crypt_set_password_retry(struct crypt_device *cd, int tries);
185
186 /**
187  * Set how long should cryptsetup iterate in PBKDF2 function.
188  * Default value heads towards the iterations which takes around 1 second
189  *
190  * @param cd crypt device handle
191  * @param iteration_time_ms the time in ms
192  */
193 void crypt_set_iterarion_time(struct crypt_device *cd, uint64_t iteration_time_ms);
194
195 /**
196  * Set whether passphrase will be verified on input
197  * (user has to input same passphrase twice)
198  *
199  * @param cd crypt device handle
200  * @param password_verify @e 0 = false, @e !0 true
201  */
202 void crypt_set_password_verify(struct crypt_device *cd, int password_verify);
203
204 /**
205  * Set data device (encrypted payload area device) if LUKS header is separated
206  *
207  * @param cd crypt device handle
208  * @param device path to device
209  *
210  * @pre context is of LUKS type
211  * @pre unlike @ref crypt_init, in this function param @e device
212  *      has to be block device (at least 512B large)
213  */
214 int crypt_set_data_device(struct crypt_device *cd, const char *device);
215
216 /**
217  * @defgroup rng "Cryptsetup RNG"
218  *
219  * @addtogroup rng
220  * @{
221  *
222  */
223
224 /** CRYPT_RNG_URANDOM - use /dev/urandom */
225 #define CRYPT_RNG_URANDOM 0
226 /** CRYPT_RNG_RANDOM  - use /dev/random (waits if no entropy in system) */
227 #define CRYPT_RNG_RANDOM  1
228
229 /**
230  * Set which RNG (random number generator) is used for generating long term key
231  *
232  * @param cd crypt device handle
233  * @param rng_type kernel random number generator to use
234  *
235  */
236 void crypt_set_rng_type(struct crypt_device *cd, int rng_type);
237
238 /**
239  * Get which RNG (random number generator) is used for generating long term key
240  *
241  * @param cd crypt device handle
242  * @return RNG type on success or negative errno value otherwise.
243  *
244  */
245 int crypt_get_rng_type(struct crypt_device *cd);
246
247 /** @} */
248
249 /**
250  * Helper to lock/unlock memory to avoid swap sensitive data to disk
251  *
252  * @param cd crypt device handle, can be @e NULL
253  * @param lock 0 to unlock otherwise lock memory
254  *
255  * @returns Value indicating whether the memory is locked (function can be called multiple times).
256  *
257  * @note Only root can do this.
258  * @note It locks/unlocks all process memory, not only crypt context.
259  */
260 int crypt_memory_lock(struct crypt_device *cd, int lock);
261
262 /**
263  * @defgroup crypt_type "Cryptsetup on-disk format types"
264  *
265  * Set of functions, \#defines and structs related
266  * to on-disk format types
267  */
268
269 /**
270  * @addtogroup crypt_type
271  * @{
272  */
273
274 /** regular crypt device, no on-disk header */
275 #define CRYPT_PLAIN "PLAIN"
276 /** LUKS version 1 header on-disk */
277 #define CRYPT_LUKS1 "LUKS1"
278 /** loop-AES compatibility mode */
279 #define CRYPT_LOOPAES "LOOPAES"
280
281 /**
282  * Get device type
283  *
284  * @param cd crypt device handle
285  * @return string according to device type or @e NULL if not known.
286  */
287 const char *crypt_get_type(struct crypt_device *cd);
288
289 /**
290  *
291  * Structure used as parameter for PLAIN device type
292  *
293  * @see crypt_format
294  */
295 struct crypt_params_plain {
296         const char *hash; /**< password hash function */
297         uint64_t offset; /**< offset in sectors */
298         uint64_t skip; /**< IV offset / initialization sector */
299         uint64_t size; /**< size of mapped device or @e 0 for autodetection */
300 };
301
302 /**
303  * Structure used as parameter for LUKS device type
304  *
305  * @see crypt_format, crypt_load
306  *
307  * @note during crypt_format @e data_device attribute determines
308  *       if the LUKS header is separated from encrypted payload device
309  *
310  */
311 struct crypt_params_luks1 {
312         const char *hash; /**< hash used in LUKS header */
313         size_t data_alignment; /**< data alignment in sectors, data offset is multiple of this */
314         const char *data_device; /**< detached encrypted data device or @e NULL */
315 };
316
317 /**
318  *
319  * Structure used as parameter for loop-AES device type
320  *
321  * @see crypt_format
322  *
323  */
324 struct crypt_params_loopaes {
325         const char *hash; /**< key hash function */
326         uint64_t offset;  /**< offset in sectors */
327         uint64_t skip;    /**< IV offset / initialization sector */
328 };
329
330 /** @} */
331
332 /**
333  * Create (format) new crypt device (and possible header on-disk) but not activates it.
334  *
335  * @pre @e cd contains initialized and not formatted device context (device type must @b not be set)
336  *
337  * @param cd crypt device handle
338  * @param type type of device (optional params struct must be of this type)
339  * @param cipher (e.g. "aes")
340  * @param cipher_mode including IV specification (e.g. "xts-plain")
341  * @param uuid requested UUID or @e NULL if it should be generated
342  * @param volume_key pre-generated volume key or @e NULL if it should be generated (only for LUKS)
343  * @param volume_key_size size of volume key in bytes.
344  * @param params crypt type specific parameters (see @link crypt_type @endlink)
345  *
346  * @returns @e 0 on success or negative errno value otherwise.
347  *
348  * @note Note that crypt_format does not enable any keyslot (in case of work with LUKS device), but it stores volume key internally
349  *       and subsequent crypt_keyslot_add_* calls can be used.
350  */
351 int crypt_format(struct crypt_device *cd,
352         const char *type,
353         const char *cipher,
354         const char *cipher_mode,
355         const char *uuid,
356         const char *volume_key,
357         size_t volume_key_size,
358         void *params);
359
360 /**
361  * Set new UUID for already existing device
362  *
363  * @param cd crypt device handle
364  * @param uuid requested UUID or @e NULL if it should be generated
365  *
366  * @returns 0 on success or negative errno value otherwise.
367  *
368  * @note Currently, only LUKS device type are supported
369  */
370 int crypt_set_uuid(struct crypt_device *cd,
371                    const char *uuid);
372
373 /**
374  * Load crypt device parameters from on-disk header
375  *
376  * @param cd crypt device handle
377  * @param requested_type - use @e NULL for all known
378  * @param params crypt type specific parameters (see @link crypt_type @endlink)
379  *
380  * @returns 0 on success or negative errno value otherwise.
381  *
382  * @post In case LUKS header is read successfully but payload device is too small
383  * error is returned and device type in context is set to @e NULL
384  *
385  * @note Note that in current version load works only for LUKS device type
386  *
387  */
388 int crypt_load(struct crypt_device *cd,
389                const char *requested_type,
390                void *params);
391
392 /**
393  * Resize crypt device
394  *
395  * @param cd - crypt device handle
396  * @param name - name of device to resize
397  * @param new_size - new device size in sectors or @e 0 to use all of the underlying device size
398  *
399  * @return @e 0 on success or negative errno value otherwise.
400  */
401 int crypt_resize(struct crypt_device *cd,
402                  const char *name,
403                  uint64_t new_size);
404
405 /**
406  * Suspends crypt device.
407  *
408  * @param cd crypt device handle, can be @e NULL
409  * @param name name of device to suspend
410  *
411  * @return 0 on success or negative errno value otherwise.
412  *
413  * @note Only LUKS device type is supported
414  *
415  */
416 int crypt_suspend(struct crypt_device *cd,
417                   const char *name);
418
419 /**
420  * Resumes crypt device using passphrase.
421  *
422  *
423  * @param cd crypt device handle
424  * @param name name of device to resume
425  * @param keyslot requested keyslot or CRYPT_ANY_SLOT
426  * @param passphrase passphrase used to unlock volume key, @e NULL for query
427  * @param passphrase_size size of @e passphrase (binary data)
428  *
429  * @return unlocked key slot number or negative errno otherwise.
430  *
431  * @note Only LUKS device type is supported
432  */
433 int crypt_resume_by_passphrase(struct crypt_device *cd,
434                                const char *name,
435                                int keyslot,
436                                const char *passphrase,
437                                size_t passphrase_size);
438
439 /**
440  * Resumes crypt device using key file.
441  *
442  * @param cd crypt device handle
443  * @param name name of device to resume
444  * @param keyslot requested keyslot or CRYPT_ANY_SLOT
445  * @param keyfile key file used to unlock volume key, @e NULL for passphrase query
446  * @param keyfile_size number of bytes to read from keyfile, 0 is unlimited
447  *
448  * @return unlocked key slot number or negative errno otherwise.
449  */
450 int crypt_resume_by_keyfile(struct crypt_device *cd,
451                             const char *name,
452                             int keyslot,
453                             const char *keyfile,
454                             size_t keyfile_size);
455
456 /**
457  * Releases crypt device context and used memory.
458  *
459  * @param cd crypt device handle
460  */
461 void crypt_free(struct crypt_device *cd);
462
463 /**
464  * @defgroup keyslot "Cryptsetup LUKS keyslots"
465  * @addtogroup keyslot
466  * @{
467  *
468  */
469
470 /** iterate through all keyslots and find first one that fits */
471 #define CRYPT_ANY_SLOT -1
472
473 /**
474  * Add key slot using provided passphrase
475  *
476  * @pre @e cd contains initialized and formatted LUKS device context
477  *
478  * @param cd crypt device handle
479  * @param keyslot requested keyslot or @e CRYPT_ANY_SLOT
480  * @param passphrase passphrase used to unlock volume key, @e NULL for query
481  * @param passphrase_size size of passphrase (binary data)
482  * @param new_passphrase passphrase for new keyslot, @e NULL for query
483  * @param new_passphrase_size size of @e new_passphrase (binary data)
484  *
485  * @return allocated key slot number or negative errno otherwise.
486  */
487 int crypt_keyslot_add_by_passphrase(struct crypt_device *cd,
488         int keyslot,
489         const char *passphrase,
490         size_t passphrase_size,
491         const char *new_passphrase,
492         size_t new_passphrase_size);
493
494 /**
495  * Get number of keyslots supported for device type.
496  *
497  * @param type crypt device type
498  *
499  * @return slot count or negative errno otherwise if device
500  * doesn't not support keyslots.
501  */
502 int crypt_keyslot_max(const char *type);
503
504 /**
505 * Add key slot using provided key file path
506  *
507  * @pre @e cd contains initialized and formatted LUKS device context
508  *
509  * @param cd crypt device handle
510  * @param keyslot requested keyslot or @e CRYPT_ANY_SLOT
511  * @param keyfile key file used to unlock volume key, @e NULL for passphrase query
512  * @param keyfile_size number of bytes to read from keyfile, @e 0 is unlimited
513  * @param new_keyfile keyfile for new keyslot, @e NULL for passphrase query
514  * @param new_keyfile_size number of bytes to read from @e new_keyfile, @e 0 is unlimited
515  *
516  * @return allocated key slot number or negative errno otherwise.
517  *
518  * @note Note that @e keyfile can be "-" for STDIN
519  *
520  */
521 int crypt_keyslot_add_by_keyfile(struct crypt_device *cd,
522         int keyslot,
523         const char *keyfile,
524         size_t keyfile_size,
525         const char *new_keyfile,
526         size_t new_keyfile_size);
527
528 /**
529  * Add key slot using provided volume key
530  *
531  * @pre @e cd contains initialized and formatted LUKS device context
532  *
533  * @param cd crypt device handle
534  * @param keyslot requested keyslot or CRYPT_ANY_SLOT
535  * @param volume_key provided volume key or @e NULL if used after crypt_format
536  * @param volume_key_size size of volume_key
537  * @param passphrase passphrase for new keyslot, @e NULL for query
538  * @param passphrase_size size of passphrase
539  *
540  * @return allocated key slot number or negative errno otherwise.
541  *
542  */
543 int crypt_keyslot_add_by_volume_key(struct crypt_device *cd,
544         int keyslot,
545         const char *volume_key,
546         size_t volume_key_size,
547         const char *passphrase,
548         size_t passphrase_size);
549
550 /**
551  * Destroy (and disable) key slot
552  *
553  * @pre @e cd contains initialized and formatted LUKS device context
554  *
555  * @param cd crypt device handle
556  * @param keyslot requested key slot to destroy
557  *
558  * @return @e 0 on success or negative errno value otherwise.
559  *
560  * @note Note that there is no passphrase verification used.
561  */
562 int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot);
563
564 /** @} */
565
566 /**
567  * @defgroup aflags "Device runtime attributes"
568  *
569  * Activation flags
570  *
571  * @addtogroup aflags
572  * @{
573  *
574  */
575 /** device is read only */
576 #define CRYPT_ACTIVATE_READONLY (1 << 0)
577 /** ignored */
578 #define CRYPT_ACTIVATE_NO_UUID  (1 << 1)
579 /** ??? */
580 #define CRYPT_ACTIVATE_SHARED   (1 << 2)
581 /** enable discards aka TRIM */
582 #define CRYPT_ACTIVATE_ALLOW_DISCARDS (1 << 3)
583
584 /**
585  * Active device runtime attributes
586  */
587 struct crypt_active_device {
588         uint64_t offset; /**< offset in sectors */
589         uint64_t iv_offset; /**< IV initialization sector */
590         uint64_t size; /**< active device size */
591         uint32_t flags; /**< activation flags */
592 };
593
594 /**
595  * Receives runtime attributes of active crypt device
596  *
597  * @param cd crypt device handle (can be @e NULL)
598  * @param name name of active device
599  * @param cad preallocated active device attributes to fill
600  *
601  * @return @e 0 on success or negative errno value otherwise
602  *
603  */
604 int crypt_get_active_device(struct crypt_device *cd,
605                             const char *name,
606                             struct crypt_active_device *cad);
607
608 /** @} */
609
610 /**
611  * Activate device or check passphrase
612  *
613  * @param cd crypt device handle
614  * @param name name of device to create, if @e NULL only check passphrase
615  * @param keyslot requested keyslot to check or @e CRYPT_ANY_SLOT
616  * @param passphrase passphrase used to unlock volume key, @e NULL for query
617  * @param passphrase_size size of @e passphrase
618  * @param flags activation flags
619  *
620  * @return unlocked key slot number or negative errno otherwise.
621  */
622 int crypt_activate_by_passphrase(struct crypt_device *cd,
623         const char *name,
624         int keyslot,
625         const char *passphrase,
626         size_t passphrase_size,
627         uint32_t flags);
628
629 /**
630  * Activate device or check using key file
631  *
632  * @param cd crypt device handle
633  * @param name name of device to create, if @e NULL only check keyfile
634  * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
635  * @param keyfile key file used to unlock volume key
636  * @param keyfile_size number of bytes to read from keyfile, 0 is unlimited
637  * @param flags activation flags
638  *
639  * @return unlocked key slot number or negative errno otherwise.
640  */
641 int crypt_activate_by_keyfile(struct crypt_device *cd,
642         const char *name,
643         int keyslot,
644         const char *keyfile,
645         size_t keyfile_size,
646         uint32_t flags);
647
648 /**
649  * Activate device using provided volume key
650  *
651  *
652  * @param cd crypt device handle
653  * @param name name of device to create, if @e NULL only check volume key
654  * @param volume_key provided volume key (or @e NULL to use internal)
655  * @param volume_key_size size of volume_key
656  * @param flags activation flags
657  *
658  * @return @e 0 on success or negative errno value otherwise.
659  *
660  * @note If @e NULL is used for volume_key, device has to be initialized
661  *       by previous operation (like @ref crypt_format
662  *       or @ref crypt_init_by_name)
663  */
664 int crypt_activate_by_volume_key(struct crypt_device *cd,
665         const char *name,
666         const char *volume_key,
667         size_t volume_key_size,
668         uint32_t flags);
669
670 /**
671  * Deactivate crypt device. This function tries to remove active device-mapper
672  * mapping from kernel. Also, sensitive data like the volume key are removed from
673  * memory
674  *
675  * @param cd crypt device handle, can be @e NULL
676  * @param name name of device to deactivate
677  *
678  * @return @e 0 on success or negative errno value otherwise.
679  *
680  */
681 int crypt_deactivate(struct crypt_device *cd, const char *name);
682
683 /**
684  * Get volume key from of crypt device
685  *
686  * @param cd crypt device handle
687  * @param keyslot use this keyslot or @e CRYPT_ANY_SLOT
688  * @param volume_key buffer for volume key
689  * @param volume_key_size on input, size of buffer @e volume_key,
690  *        on output size of @e volume_key
691  * @param passphrase passphrase used to unlock volume key
692  * @param passphrase_size size of @e passphrase
693  *
694  * @return unlocked key slot number or negative errno otherwise.
695  */
696 int crypt_volume_key_get(struct crypt_device *cd,
697         int keyslot,
698         char *volume_key,
699         size_t *volume_key_size,
700         const char *passphrase,
701         size_t passphrase_size);
702
703 /**
704  * Verify that provided volume key is valid for crypt device
705  *
706  * @param cd crypt device handle
707  * @param volume_key provided volume key
708  * @param volume_key_size size of @e volume_key
709  *
710  * @return @e 0 on success or negative errno value otherwise.
711  */
712 int crypt_volume_key_verify(struct crypt_device *cd,
713         const char *volume_key,
714         size_t volume_key_size);
715
716
717 /*
718  * @defgroup devstat "dmcrypt device status"
719  * @addtogroup devstat
720  * @{
721  */
722
723 /**
724  * Device status
725  */
726 typedef enum {
727         CRYPT_INVALID, /**< device mapping is invalid in this context */
728         CRYPT_INACTIVE, /**< no such mapped device */
729         CRYPT_ACTIVE, /**< device is active */
730         CRYPT_BUSY /**< device is active and has open count > 0 */
731 } crypt_status_info;
732
733 /**
734  * Get status info about device name
735  *
736  * @param cd crypt device handle, can be @e NULL
737  * @param name crypt device name
738  *
739  * @return value defined by crypt_status_info.
740  *
741  */
742 crypt_status_info crypt_status(struct crypt_device *cd, const char *name);
743
744 /**
745  * Dump text-formatted information about crypt device to log output
746  *
747  * @param cd crypt device handle
748  *
749  * @return @e 0 on success or negative errno value otherwise.
750  */
751 int crypt_dump(struct crypt_device *cd);
752
753 /**
754  * Get cipher used in device
755  *
756  * @param cd crypt device handle
757  *
758  * @return used cipher, e.g. "aes" or @e NULL otherwise
759  *
760  */
761 const char *crypt_get_cipher(struct crypt_device *cd);
762
763 /**
764  * Get cipher mode used in device
765  *
766  * @param cd crypt device handle
767  *
768  * @return used cipher mode e.g. "xts-plain" or @e otherwise
769  *
770  */
771 const char *crypt_get_cipher_mode(struct crypt_device *cd);
772
773 /**
774  * Get device UUID
775  *
776  * @param cd crypt device handle
777  *
778  * @return device UUID or @e NULL if not set
779  *
780  */
781 const char *crypt_get_uuid(struct crypt_device *cd);
782
783 /**
784  * Get path to underlaying device
785  *
786  * @param cd crypt device handle
787  *
788  * @return path to underlaying device name
789  *
790  */
791 const char *crypt_get_device_name(struct crypt_device *cd);
792
793 /**
794  * Get device offset in sectors where real data starts on underlying device)
795  *
796  * @param cd crypt device handle
797  *
798  * @return device offset in sectors
799  *
800  */
801 uint64_t crypt_get_data_offset(struct crypt_device *cd);
802
803 /**
804  * Get IV offset in sectors (skip)
805  *
806  * @param cd crypt device handle
807  *
808  * @return IV offset
809  *
810  */
811 uint64_t crypt_get_iv_offset(struct crypt_device *cd);
812
813 /**
814  * Get size (in bytes) of volume key for crypt device
815  *
816  * @param cd crypt device handle
817  *
818  * @return volume key size
819  *
820  */
821 int crypt_get_volume_key_size(struct crypt_device *cd);
822
823 /**
824  * @addtogroup keyslot
825  * @{
826  *
827  */
828
829 /**
830  * Crypt keyslot info
831  */
832 typedef enum {
833         CRYPT_SLOT_INVALID, /**< invalid keyslot */
834         CRYPT_SLOT_INACTIVE, /**< keyslot is inactive (free) */
835         CRYPT_SLOT_ACTIVE, /**< keyslot is active (used) */
836         CRYPT_SLOT_ACTIVE_LAST /**< keylost is active (used)
837                                 *   and last used at the same time */
838 } crypt_keyslot_info;
839
840 /**
841  * Get information about particular key slot
842  *
843  *
844  * @param cd crypt device handle
845  * @param keyslot requested keyslot to check or CRYPT_ANY_SLOT
846  *
847  * @return value defined by crypt_keyslot_info
848  *
849  */
850 crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot);
851 /** @} */
852
853 /**
854  * Backup header and keyslots to file
855  *
856  * @param cd crypt device handle
857  * @param requested_type type of header to backup
858  * @param backup_file file to backup header to
859  *
860  * @return @e 0 on success or negative errno value otherwise.
861  *
862  */
863 int crypt_header_backup(struct crypt_device *cd,
864         const char *requested_type,
865         const char *backup_file);
866
867 /**
868  * Restore header and keyslots from backup file
869  *
870  *
871  * @param cd crypt device handle
872  * @param requested_type type of header to restore
873  * @param backup_file file to restore header from
874  *
875  * @return @e 0 on success or negative errno value otherwise.
876  *
877  */
878 int crypt_header_restore(struct crypt_device *cd,
879         const char *requested_type,
880         const char *backup_file);
881
882 /**
883  * Receives last reported error
884  *
885  * @param buf buffef for message
886  * @param size size of buffer
887  *
888  * @note Note that this is old API function using global context.
889  * All error messages are reported also through log callback.
890  */
891 void crypt_get_error(char *buf, size_t size);
892
893 /**
894  * Get directory where mapped crypt devices are created
895  *
896  * @return the directory path
897  */
898 const char *crypt_get_dir(void);
899
900 /**
901  * @defgroup dbg "Library debug level"
902  *
903  * Set library debug level
904  *
905  * @addtogroup dbg
906  * @{
907  */
908
909 /** Debug all */
910 #define CRYPT_DEBUG_ALL  -1
911 /** Debug none */
912 #define CRYPT_DEBUG_NONE  0
913
914 /**
915  * Set the debug level for library
916  *
917  * @param level debug level
918  *
919  */
920 void crypt_set_debug_level(int level);
921
922 /** @} */
923
924 #ifdef __cplusplus
925 }
926 #endif
927 #endif /* _LIBCRYPTSETUP_H */