blk-crypto-internal.h 1.6 KB

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