1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2010 IBM Corporation 4 * Author: David Safford <safford@us.ibm.com> 5 */ 6 7 #ifndef _KEYS_TRUSTED_TYPE_H 8 #define _KEYS_TRUSTED_TYPE_H 9 10 #include <linux/key.h> 11 #include <linux/rcupdate.h> 12 #include <linux/tpm.h> 13 14 #ifdef pr_fmt 15 #undef pr_fmt 16 #endif 17 18 #define pr_fmt(fmt) "trusted_key: " fmt 19 20 #define MIN_KEY_SIZE 32 21 #define MAX_KEY_SIZE 128 22 #if IS_ENABLED(CONFIG_TRUSTED_KEYS_PKWM) 23 #define MAX_BLOB_SIZE 1152 24 #else 25 #define MAX_BLOB_SIZE 512 26 #endif 27 #define MAX_PCRINFO_SIZE 64 28 #define MAX_DIGEST_SIZE 64 29 30 struct trusted_key_payload { 31 struct rcu_head rcu; 32 unsigned int key_len; 33 unsigned int blob_len; 34 unsigned char migratable; 35 unsigned char old_format; 36 unsigned char key[MAX_KEY_SIZE + 1]; 37 unsigned char blob[MAX_BLOB_SIZE]; 38 }; 39 40 struct trusted_key_options { 41 uint16_t keytype; 42 void *private; 43 }; 44 45 struct trusted_key_ops { 46 /* 47 * flag to indicate if trusted key implementation supports migration 48 * or not. 49 */ 50 unsigned char migratable; 51 52 /* Initialize key interface. */ 53 int (*init)(void); 54 55 /* Seal a key. */ 56 int (*seal)(struct trusted_key_payload *p, char *datablob); 57 58 /* Unseal a key. */ 59 int (*unseal)(struct trusted_key_payload *p, char *datablob); 60 61 /* Optional: Get a randomized key. */ 62 int (*get_random)(unsigned char *key, size_t key_len); 63 64 /* Exit key interface. */ 65 void (*exit)(void); 66 }; 67 68 struct trusted_key_source { 69 char *name; 70 struct trusted_key_ops *ops; 71 }; 72 73 extern struct key_type key_type_trusted; 74 75 #ifdef CONFIG_TRUSTED_KEYS_DEBUG 76 extern bool trusted_debug; 77 78 static inline void dump_payload(struct trusted_key_payload *p) 79 { 80 if (!trusted_debug) 81 return; 82 83 pr_debug("key_len %d\n", p->key_len); 84 print_hex_dump_debug("key ", DUMP_PREFIX_NONE, 85 16, 1, p->key, p->key_len, 0); 86 pr_debug("bloblen %d\n", p->blob_len); 87 print_hex_dump_debug("blob ", DUMP_PREFIX_NONE, 88 16, 1, p->blob, p->blob_len, 0); 89 pr_debug("migratable %d\n", p->migratable); 90 } 91 #else 92 static inline void dump_payload(struct trusted_key_payload *p) 93 { 94 } 95 #endif 96 97 #endif /* _KEYS_TRUSTED_TYPE_H */ 98