15 #define SECTOR_SHIFT 9
16 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
17 #define DEFAULT_DISK_ALIGNMENT 1048576 /* 1MiB */
18 #define DEFAULT_MEM_ALIGNMENT 4096
20 #define MAX_TTY_PASSWORD_LEN 512
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); })
34 int (*fn)(void *data, int size, char *key,
35 int sizep, const char *passphrase);
40 struct hash_type * (*get_hashes)(void);
41 void (*free_hashes)(struct hash_type *hashes);
50 int crypt_confirm(struct crypt_device *cd, const char *msg);
52 void set_error_va(const char *fmt, va_list va);
53 void set_error(const char *fmt, ...);
54 const char *get_error(void);
55 void *safe_alloc(size_t size);
56 void safe_free(void *data);
57 void *safe_realloc(void *data, size_t size);
58 char *safe_strdup(const char *s);
59 void set_debug_level(int level);
61 int init_crypto(void);
62 struct hash_backend *get_hash_backend(const char *name);
63 void put_hash_backend(struct hash_backend *backend);
64 int hash(const char *backend_name, const char *hash_name,
65 char *result, size_t size,
66 const char *passphrase, size_t sizep);
68 void hexprint(char *d, int n);
70 /* Device mapper backend */
71 const char *dm_get_dir(void);
72 int dm_init(struct crypt_device *context, int check_kernel);
74 int dm_remove_device(const char *name, int force, uint64_t size);
75 int dm_status_device(const char *name);
76 int dm_query_device(const char *name,
87 int dm_create_device(const char *name, const char *device, const char *cipher,
88 const char *type, const char *uuid,
89 uint64_t size, uint64_t skip, uint64_t offset,
90 size_t key_size, const char *key,
91 int read_only, int reload);
92 int dm_suspend_and_wipe_key(const char *name);
93 int dm_resume_and_reinstate_key(const char *name,
97 int sector_size_for_device(const char *device);
98 ssize_t write_blockwise(int fd, const void *buf, size_t count);
99 ssize_t read_blockwise(int fd, void *_buf, size_t count);
100 ssize_t write_lseek_blockwise(int fd, const char *buf, size_t count, off_t offset);
101 int device_ready(struct crypt_device *cd, const char *device, int mode);
102 int get_device_infos(const char *device, struct device_infos *infos, struct crypt_device *cd);
103 int wipe_device_header(const char *device, int sectors);
105 void get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
106 const char *key_file, int timeout, int how2verify,
107 struct crypt_device *cd);
109 int parse_into_name_and_mode(const char *nameAndMode, char *name, char *mode);
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 #endif /* INTERNAL_H */