14 #include "utils_crypt.h"
15 #include "utils_loop.h"
18 /* to silent gcc -Wcast-qual for const cast */
19 #define CONST_CAST(x) (x)(uintptr_t)
21 #define SECTOR_SHIFT 9
22 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
23 #define DEFAULT_DISK_ALIGNMENT 1048576 /* 1MiB */
24 #define DEFAULT_MEM_ALIGNMENT 4096
26 #define at_least(a, b) ({ __typeof__(a) __at_least = (a); (__at_least >= (b))?__at_least:(b); })
35 struct volume_key *crypt_alloc_volume_key(unsigned keylength, const char *key);
36 struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, unsigned keylength);
37 void crypt_free_volume_key(struct volume_key *vk);
39 int crypt_confirm(struct crypt_device *cd, const char *msg);
41 char *crypt_lookup_dev(const char *dev_id);
42 int crypt_sysfs_check_crypt_segment(const char *device, uint64_t offset, uint64_t size);
43 int crypt_sysfs_get_rotational(int major, int minor, int *rotational);
45 int sector_size_for_device(const char *device);
46 int device_read_ahead(const char *dev, uint32_t *read_ahead);
47 ssize_t write_blockwise(int fd, void *buf, size_t count);
48 ssize_t read_blockwise(int fd, void *_buf, size_t count);
49 ssize_t write_lseek_blockwise(int fd, char *buf, size_t count, off_t offset);
50 int device_ready(struct crypt_device *cd, const char *device, int mode);
51 int device_size(const char *device, uint64_t *size);
53 enum devcheck { DEV_OK = 0, DEV_EXCL = 1, DEV_SHARED = 2 };
54 int device_check_and_adjust(struct crypt_device *cd,
56 enum devcheck device_check,
61 void logger(struct crypt_device *cd, int class, const char *file, int line, const char *format, ...);
62 #define log_dbg(x...) logger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
63 #define log_std(c, x...) logger(c, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
64 #define log_verbose(c, x...) logger(c, CRYPT_LOG_VERBOSE, __FILE__, __LINE__, x)
65 #define log_err(c, x...) logger(c, CRYPT_LOG_ERROR, __FILE__, __LINE__, x)
67 int crypt_get_debug_level(void);
68 void debug_processes_using_device(const char *name);
70 int crypt_memlock_inc(struct crypt_device *ctx);
71 int crypt_memlock_dec(struct crypt_device *ctx);
73 void get_topology_alignment(const char *device,
74 unsigned long *required_alignment, /* bytes */
75 unsigned long *alignment_offset, /* bytes */
76 unsigned long default_alignment);
78 enum { CRYPT_RND_NORMAL = 0, CRYPT_RND_KEY = 1 };
79 int crypt_random_init(struct crypt_device *ctx);
80 int crypt_random_get(struct crypt_device *ctx, char *buf, size_t len, int quality);
81 void crypt_random_exit(void);
82 int crypt_random_default_key_rng(void);
84 int crypt_plain_hash(struct crypt_device *ctx,
85 const char *hash_name,
86 char *key, size_t key_size,
87 const char *passphrase, size_t passphrase_size);
88 int PLAIN_activate(struct crypt_device *cd,
90 struct volume_key *vk,
95 * Different methods used to erase sensitive data concerning
96 * either encrypted payload area or master key inside keyslot
100 CRYPT_WIPE_ZERO, /**< overwrite area using zero blocks */
101 CRYPT_WIPE_DISK, /**< erase disk (using Gutmann method if it is rotational disk)*/
102 CRYPT_WIPE_SSD, /**< erase solid state disk (random write) */
103 CRYPT_WIPE_RANDOM /**< overwrite area using some up to now unspecified
104 * random algorithm */
107 int crypt_wipe(const char *device,
110 crypt_wipe_type type,
113 #endif /* INTERNAL_H */