• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright 2019 Google LLC
4  */
5 
6 #ifndef __LINUX_BLK_CRYPTO_INTERNAL_H
7 #define __LINUX_BLK_CRYPTO_INTERNAL_H
8 
9 #include <linux/bio.h>
10 
11 /* Represents a crypto mode supported by blk-crypto  */
12 struct blk_crypto_mode {
13 	const char *cipher_str; /* crypto API name (for fallback case) */
14 	unsigned int keysize; /* key size in bytes */
15 	unsigned int ivsize; /* iv size in bytes */
16 };
17 
18 extern const struct blk_crypto_mode blk_crypto_modes[];
19 
20 #ifdef CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK
21 
22 int blk_crypto_fallback_start_using_mode(enum blk_crypto_mode_num mode_num);
23 
24 int blk_crypto_fallback_submit_bio(struct bio **bio_ptr);
25 
26 bool blk_crypto_queue_decrypt_bio(struct bio *bio);
27 
28 int blk_crypto_fallback_evict_key(const struct blk_crypto_key *key);
29 
30 bool bio_crypt_fallback_crypted(const struct bio_crypt_ctx *bc);
31 
32 #else /* CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK */
33 
34 static inline int
blk_crypto_fallback_start_using_mode(enum blk_crypto_mode_num mode_num)35 blk_crypto_fallback_start_using_mode(enum blk_crypto_mode_num mode_num)
36 {
37 	pr_warn_once("crypto API fallback is disabled\n");
38 	return -ENOPKG;
39 }
40 
bio_crypt_fallback_crypted(const struct bio_crypt_ctx * bc)41 static inline bool bio_crypt_fallback_crypted(const struct bio_crypt_ctx *bc)
42 {
43 	return false;
44 }
45 
blk_crypto_fallback_submit_bio(struct bio ** bio_ptr)46 static inline int blk_crypto_fallback_submit_bio(struct bio **bio_ptr)
47 {
48 	pr_warn_once("crypto API fallback disabled; failing request\n");
49 	(*bio_ptr)->bi_status = BLK_STS_NOTSUPP;
50 	return -EIO;
51 }
52 
blk_crypto_queue_decrypt_bio(struct bio * bio)53 static inline bool blk_crypto_queue_decrypt_bio(struct bio *bio)
54 {
55 	WARN_ON(1);
56 	return false;
57 }
58 
59 static inline int
blk_crypto_fallback_evict_key(const struct blk_crypto_key * key)60 blk_crypto_fallback_evict_key(const struct blk_crypto_key *key)
61 {
62 	return 0;
63 }
64 
65 #endif /* CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK */
66 
67 #endif /* __LINUX_BLK_CRYPTO_INTERNAL_H */
68