encrypted.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ENCRYPTED_KEY_H
  3. #define __ENCRYPTED_KEY_H
  4. #define ENCRYPTED_DEBUG 0
  5. #if defined(CONFIG_TRUSTED_KEYS) || \
  6. (defined(CONFIG_TRUSTED_KEYS_MODULE) && defined(CONFIG_ENCRYPTED_KEYS_MODULE))
  7. extern struct key *request_trusted_key(const char *trusted_desc,
  8. const u8 **master_key, size_t *master_keylen);
  9. #else
  10. static inline struct key *request_trusted_key(const char *trusted_desc,
  11. const u8 **master_key,
  12. size_t *master_keylen)
  13. {
  14. return ERR_PTR(-EOPNOTSUPP);
  15. }
  16. #endif
  17. #if ENCRYPTED_DEBUG
  18. static inline void dump_master_key(const u8 *master_key, size_t master_keylen)
  19. {
  20. print_hex_dump(KERN_ERR, "master key: ", DUMP_PREFIX_NONE, 32, 1,
  21. master_key, master_keylen, 0);
  22. }
  23. static inline void dump_decrypted_data(struct encrypted_key_payload *epayload)
  24. {
  25. print_hex_dump(KERN_ERR, "decrypted data: ", DUMP_PREFIX_NONE, 32, 1,
  26. epayload->decrypted_data,
  27. epayload->decrypted_datalen, 0);
  28. }
  29. static inline void dump_encrypted_data(struct encrypted_key_payload *epayload,
  30. unsigned int encrypted_datalen)
  31. {
  32. print_hex_dump(KERN_ERR, "encrypted data: ", DUMP_PREFIX_NONE, 32, 1,
  33. epayload->encrypted_data, encrypted_datalen, 0);
  34. }
  35. static inline void dump_hmac(const char *str, const u8 *digest,
  36. unsigned int hmac_size)
  37. {
  38. if (str)
  39. pr_info("encrypted_key: %s", str);
  40. print_hex_dump(KERN_ERR, "hmac: ", DUMP_PREFIX_NONE, 32, 1, digest,
  41. hmac_size, 0);
  42. }
  43. #else
  44. static inline void dump_master_key(const u8 *master_key, size_t master_keylen)
  45. {
  46. }
  47. static inline void dump_decrypted_data(struct encrypted_key_payload *epayload)
  48. {
  49. }
  50. static inline void dump_encrypted_data(struct encrypted_key_payload *epayload,
  51. unsigned int encrypted_datalen)
  52. {
  53. }
  54. static inline void dump_hmac(const char *str, const u8 *digest,
  55. unsigned int hmac_size)
  56. {
  57. }
  58. #endif
  59. #endif