14 #include "utils_crypt.h"
15 #include "utils_loop.h"
17 #define SECTOR_SHIFT 9
18 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
19 #define DEFAULT_DISK_ALIGNMENT 1048576 /* 1MiB */
20 #define DEFAULT_MEM_ALIGNMENT 4096
22 /* private struct crypt_options flags */
24 #define CRYPT_FLAG_FREE_DEVICE (1 << 24)
25 #define CRYPT_FLAG_FREE_CIPHER (1 << 25)
27 #define CRYPT_FLAG_PRIVATE_MASK ((unsigned int)-1 << 24)
29 #define at_least(a, b) ({ __typeof__(a) __at_least = (a); (__at_least >= (b))?__at_least:(b); })
36 int (*fn)(void *data, int size, char *key,
37 int sizep, const char *passphrase);
42 struct hash_type * (*get_hashes)(void);
43 void (*free_hashes)(struct hash_type *hashes);
51 struct volume_key *crypt_alloc_volume_key(unsigned keylength, const char *key);
52 struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, unsigned keylength);
53 void crypt_free_volume_key(struct volume_key *vk);
55 int crypt_confirm(struct crypt_device *cd, const char *msg);
57 void set_error_va(const char *fmt, va_list va);
58 void set_error(const char *fmt, ...);
59 const char *get_error(void);
61 /* Device mapper backend - kernel support flags */
62 #define DM_KEY_WIPE_SUPPORTED (1 << 0) /* key wipe message */
63 #define DM_LMK_SUPPORTED (1 << 1) /* lmk mode */
64 #define DM_SECURE_SUPPORTED (1 << 2) /* wipe (secure) buffer flag */
65 #define DM_PLAIN64_SUPPORTED (1 << 3) /* plain64 IV */
66 uint32_t dm_flags(void);
68 const char *dm_get_dir(void);
69 int dm_init(struct crypt_device *context, int check_kernel);
71 int dm_remove_device(const char *name, int force, uint64_t size);
72 int dm_status_device(const char *name);
73 int dm_query_device(const char *name,
84 int dm_create_device(const char *name, const char *device, const char *cipher,
85 const char *type, const char *uuid,
86 uint64_t size, uint64_t skip, uint64_t offset,
87 size_t key_size, const char *key,
88 int read_only, int reload);
89 int dm_suspend_and_wipe_key(const char *name);
90 int dm_resume_and_reinstate_key(const char *name,
94 int sector_size_for_device(const char *device);
95 ssize_t write_blockwise(int fd, void *buf, size_t count);
96 ssize_t read_blockwise(int fd, void *_buf, size_t count);
97 ssize_t write_lseek_blockwise(int fd, char *buf, size_t count, off_t offset);
98 int device_ready(struct crypt_device *cd, const char *device, int mode);
99 int get_device_infos(const char *device,
103 int device_check_and_adjust(struct crypt_device *cd,
109 int wipe_device_header(const char *device, int sectors);
111 void logger(struct crypt_device *cd, int class, const char *file, int line, const char *format, ...);
112 #define log_dbg(x...) logger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
113 #define log_std(c, x...) logger(c, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
114 #define log_verbose(c, x...) logger(c, CRYPT_LOG_VERBOSE, __FILE__, __LINE__, x)
115 #define log_err(c, x...) do { \
116 logger(c, CRYPT_LOG_ERROR, __FILE__, __LINE__, x); \
117 set_error(x); } while(0)
119 int crypt_get_debug_level(void);
120 void debug_processes_using_device(const char *name);
122 int crypt_memlock_inc(struct crypt_device *ctx);
123 int crypt_memlock_dec(struct crypt_device *ctx);
125 void get_topology_alignment(const char *device,
126 unsigned long *required_alignment, /* bytes */
127 unsigned long *alignment_offset, /* bytes */
128 unsigned long default_alignment);
130 enum { CRYPT_RND_NORMAL = 0, CRYPT_RND_KEY = 1 };
131 int crypt_random_init(struct crypt_device *ctx);
132 int crypt_random_get(struct crypt_device *ctx, char *buf, size_t len, int quality);
133 void crypt_random_exit(void);
134 int crypt_random_default_key_rng(void);
136 int crypt_plain_hash(struct crypt_device *ctx,
137 const char *hash_name,
138 char *key, size_t key_size,
139 const char *passphrase, size_t passphrase_size);
141 #endif /* INTERNAL_H */