encrypted.h 1.8 KB

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