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