0001
0002
0003
0004
0005
0006 #ifndef __LINUX_BLK_CRYPTO_H
0007 #define __LINUX_BLK_CRYPTO_H
0008
0009 #include <linux/types.h>
0010
0011 enum blk_crypto_mode_num {
0012 BLK_ENCRYPTION_MODE_INVALID,
0013 BLK_ENCRYPTION_MODE_AES_256_XTS,
0014 BLK_ENCRYPTION_MODE_AES_128_CBC_ESSIV,
0015 BLK_ENCRYPTION_MODE_ADIANTUM,
0016 BLK_ENCRYPTION_MODE_MAX,
0017 };
0018
0019 #define BLK_CRYPTO_MAX_KEY_SIZE 64
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 struct blk_crypto_config {
0030 enum blk_crypto_mode_num crypto_mode;
0031 unsigned int data_unit_size;
0032 unsigned int dun_bytes;
0033 };
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 struct blk_crypto_key {
0048 struct blk_crypto_config crypto_cfg;
0049 unsigned int data_unit_size_bits;
0050 unsigned int size;
0051 u8 raw[BLK_CRYPTO_MAX_KEY_SIZE];
0052 };
0053
0054 #define BLK_CRYPTO_MAX_IV_SIZE 32
0055 #define BLK_CRYPTO_DUN_ARRAY_SIZE (BLK_CRYPTO_MAX_IV_SIZE / sizeof(u64))
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 struct bio_crypt_ctx {
0067 const struct blk_crypto_key *bc_key;
0068 u64 bc_dun[BLK_CRYPTO_DUN_ARRAY_SIZE];
0069 };
0070
0071 #include <linux/blk_types.h>
0072 #include <linux/blkdev.h>
0073
0074 struct request;
0075 struct request_queue;
0076
0077 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
0078
0079 static inline bool bio_has_crypt_ctx(struct bio *bio)
0080 {
0081 return bio->bi_crypt_context;
0082 }
0083
0084 void bio_crypt_set_ctx(struct bio *bio, const struct blk_crypto_key *key,
0085 const u64 dun[BLK_CRYPTO_DUN_ARRAY_SIZE],
0086 gfp_t gfp_mask);
0087
0088 bool bio_crypt_dun_is_contiguous(const struct bio_crypt_ctx *bc,
0089 unsigned int bytes,
0090 const u64 next_dun[BLK_CRYPTO_DUN_ARRAY_SIZE]);
0091
0092 int blk_crypto_init_key(struct blk_crypto_key *blk_key, const u8 *raw_key,
0093 enum blk_crypto_mode_num crypto_mode,
0094 unsigned int dun_bytes,
0095 unsigned int data_unit_size);
0096
0097 int blk_crypto_start_using_key(const struct blk_crypto_key *key,
0098 struct request_queue *q);
0099
0100 int blk_crypto_evict_key(struct request_queue *q,
0101 const struct blk_crypto_key *key);
0102
0103 bool blk_crypto_config_supported(struct request_queue *q,
0104 const struct blk_crypto_config *cfg);
0105
0106 #else
0107
0108 static inline bool bio_has_crypt_ctx(struct bio *bio)
0109 {
0110 return false;
0111 }
0112
0113 #endif
0114
0115 int __bio_crypt_clone(struct bio *dst, struct bio *src, gfp_t gfp_mask);
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 static inline int bio_crypt_clone(struct bio *dst, struct bio *src,
0128 gfp_t gfp_mask)
0129 {
0130 if (bio_has_crypt_ctx(src))
0131 return __bio_crypt_clone(dst, src, gfp_mask);
0132 return 0;
0133 }
0134
0135 #endif