1
2
3
4
5
6#ifndef __LINUX_BLK_CRYPTO_H
7#define __LINUX_BLK_CRYPTO_H
8
9#include <linux/types.h>
10
11enum blk_crypto_mode_num {
12 BLK_ENCRYPTION_MODE_INVALID,
13 BLK_ENCRYPTION_MODE_AES_256_XTS,
14 BLK_ENCRYPTION_MODE_AES_128_CBC_ESSIV,
15 BLK_ENCRYPTION_MODE_ADIANTUM,
16 BLK_ENCRYPTION_MODE_MAX,
17};
18
19#define BLK_CRYPTO_MAX_KEY_SIZE 64
20
21
22
23
24
25
26
27
28
29struct blk_crypto_config {
30 enum blk_crypto_mode_num crypto_mode;
31 unsigned int data_unit_size;
32 unsigned int dun_bytes;
33};
34
35
36
37
38
39
40
41
42
43
44
45
46
47struct blk_crypto_key {
48 struct blk_crypto_config crypto_cfg;
49 unsigned int data_unit_size_bits;
50 unsigned int size;
51 u8 raw[BLK_CRYPTO_MAX_KEY_SIZE];
52};
53
54#define BLK_CRYPTO_MAX_IV_SIZE 32
55#define BLK_CRYPTO_DUN_ARRAY_SIZE (BLK_CRYPTO_MAX_IV_SIZE / sizeof(u64))
56
57
58
59
60
61
62
63
64
65
66struct bio_crypt_ctx {
67 const struct blk_crypto_key *bc_key;
68 u64 bc_dun[BLK_CRYPTO_DUN_ARRAY_SIZE];
69};
70
71#include <linux/blk_types.h>
72#include <linux/blkdev.h>
73
74struct request;
75struct request_queue;
76
77#ifdef CONFIG_BLK_INLINE_ENCRYPTION
78
79static inline bool bio_has_crypt_ctx(struct bio *bio)
80{
81 return bio->bi_crypt_context;
82}
83
84void bio_crypt_set_ctx(struct bio *bio, const struct blk_crypto_key *key,
85 const u64 dun[BLK_CRYPTO_DUN_ARRAY_SIZE],
86 gfp_t gfp_mask);
87
88bool bio_crypt_dun_is_contiguous(const struct bio_crypt_ctx *bc,
89 unsigned int bytes,
90 const u64 next_dun[BLK_CRYPTO_DUN_ARRAY_SIZE]);
91
92int blk_crypto_init_key(struct blk_crypto_key *blk_key, const u8 *raw_key,
93 enum blk_crypto_mode_num crypto_mode,
94 unsigned int dun_bytes,
95 unsigned int data_unit_size);
96
97int blk_crypto_start_using_key(const struct blk_crypto_key *key,
98 struct request_queue *q);
99
100int blk_crypto_evict_key(struct request_queue *q,
101 const struct blk_crypto_key *key);
102
103bool blk_crypto_config_supported(struct request_queue *q,
104 const struct blk_crypto_config *cfg);
105
106#else
107
108static inline bool bio_has_crypt_ctx(struct bio *bio)
109{
110 return false;
111}
112
113#endif
114
115int __bio_crypt_clone(struct bio *dst, struct bio *src, gfp_t gfp_mask);
116
117
118
119
120
121
122
123
124
125
126
127static inline int bio_crypt_clone(struct bio *dst, struct bio *src,
128 gfp_t gfp_mask)
129{
130 if (bio_has_crypt_ctx(src))
131 return __bio_crypt_clone(dst, src, gfp_mask);
132 return 0;
133}
134
135#endif
136