14 #include "utils_crypt.h"
16 #define SECTOR_SHIFT 9
17 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
18 #define DEFAULT_DISK_ALIGNMENT 1048576 /* 1MiB */
19 #define DEFAULT_MEM_ALIGNMENT 4096
21 /* private struct crypt_options flags */
23 #define CRYPT_FLAG_FREE_DEVICE (1 << 24)
24 #define CRYPT_FLAG_FREE_CIPHER (1 << 25)
26 #define CRYPT_FLAG_PRIVATE_MASK ((unsigned int)-1 << 24)
28 #define at_least(a, b) ({ __typeof__(a) __at_least = (a); (__at_least >= (b))?__at_least:(b); })
33 int (*fn)(void *data, int size, char *key,
34 int sizep, const char *passphrase);
39 struct hash_type * (*get_hashes)(void);
40 void (*free_hashes)(struct hash_type *hashes);
52 struct volume_key *crypt_alloc_volume_key(unsigned keylength, const char *key);
53 struct volume_key *crypt_generate_volume_key(unsigned keylength);
54 void crypt_free_volume_key(struct volume_key *mk);
57 int crypt_confirm(struct crypt_device *cd, const char *msg);
59 void set_error_va(const char *fmt, va_list va);
60 void set_error(const char *fmt, ...);
61 const char *get_error(void);
62 void set_debug_level(int level);
64 int init_crypto(struct crypt_device *ctx);
65 struct hash_backend *get_hash_backend(const char *name);
66 void put_hash_backend(struct hash_backend *backend);
67 int hash(const char *backend_name, const char *hash_name,
68 char *result, size_t size,
69 const char *passphrase, size_t sizep);
71 /* Device mapper backend */
72 const char *dm_get_dir(void);
73 int dm_init(struct crypt_device *context, int check_kernel);
75 int dm_remove_device(const char *name, int force, uint64_t size);
76 int dm_status_device(const char *name);
77 int dm_query_device(const char *name,
88 int dm_create_device(const char *name, const char *device, const char *cipher,
89 const char *type, const char *uuid,
90 uint64_t size, uint64_t skip, uint64_t offset,
91 size_t key_size, const char *key,
92 int read_only, int reload);
93 int dm_suspend_and_wipe_key(const char *name);
94 int dm_resume_and_reinstate_key(const char *name,
98 int sector_size_for_device(const char *device);
99 ssize_t write_blockwise(int fd, const void *buf, size_t count);
100 ssize_t read_blockwise(int fd, void *_buf, size_t count);
101 ssize_t write_lseek_blockwise(int fd, const char *buf, size_t count, off_t offset);
102 int device_ready(struct crypt_device *cd, const char *device, int mode);
103 int get_device_infos(const char *device, struct device_infos *infos, struct crypt_device *cd);
104 int wipe_device_header(const char *device, int sectors);
106 void logger(struct crypt_device *cd, int class, const char *file, int line, const char *format, ...);
107 #define log_dbg(x...) logger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
108 #define log_std(c, x...) logger(c, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
109 #define log_verbose(c, x...) logger(c, CRYPT_LOG_VERBOSE, __FILE__, __LINE__, x)
110 #define log_err(c, x...) do { \
111 logger(c, CRYPT_LOG_ERROR, __FILE__, __LINE__, x); \
112 set_error(x); } while(0)
114 int crypt_get_debug_level(void);
115 void debug_processes_using_device(const char *name);
117 int crypt_memlock_inc(struct crypt_device *ctx);
118 int crypt_memlock_dec(struct crypt_device *ctx);
120 void get_topology_alignment(const char *device,
121 unsigned long *required_alignment, /* bytes */
122 unsigned long *alignment_offset, /* bytes */
123 unsigned long default_alignment);
125 #endif /* INTERNAL_H */