| 1 |
|
| 2 | |
| 3 | * Copyright (C) 2010 IBM Corporation
|
| 4 | * Author: David Safford <[email protected]>
|
| 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 | uint32_t keyhandle;
|
| 43 | unsigned char keyauth[TPM_DIGEST_SIZE];
|
| 44 | uint32_t blobauth_len;
|
| 45 | unsigned char blobauth[TPM_DIGEST_SIZE];
|
| 46 | uint32_t pcrinfo_len;
|
| 47 | unsigned char pcrinfo[MAX_PCRINFO_SIZE];
|
| 48 | int pcrlock;
|
| 49 | uint32_t hash;
|
| 50 | uint32_t policydigest_len;
|
| 51 | unsigned char policydigest[MAX_DIGEST_SIZE];
|
| 52 | uint32_t policyhandle;
|
| 53 | void *private;
|
| 54 | };
|
| 55 |
|
| 56 | struct trusted_key_ops {
|
| 57 | |
| 58 | * flag to indicate if trusted key implementation supports migration
|
| 59 | * or not.
|
| 60 |
|
| 61 | unsigned char migratable;
|
| 62 |
|
| 63 |
|
| 64 | int (*init)(void);
|
| 65 |
|
| 66 |
|
| 67 | int (*seal)(struct trusted_key_payload *p, char *datablob);
|
| 68 |
|
| 69 |
|
| 70 | int (*unseal)(struct trusted_key_payload *p, char *datablob);
|
| 71 |
|
| 72 |
|
| 73 | int (*get_random)(unsigned char *key, size_t key_len);
|
| 74 |
|
| 75 |
|
| 76 | void (*exit)(void);
|
| 77 | };
|
| 78 |
|
| 79 | struct trusted_key_source {
|
| 80 | char *name;
|
| 81 | struct trusted_key_ops *ops;
|
| 82 | };
|
| 83 |
|
| 84 | extern struct key_type key_type_trusted;
|
| 85 |
|
| 86 | #ifdef CONFIG_TRUSTED_KEYS_DEBUG
|
| 87 | extern bool trusted_debug;
|
| 88 |
|
| 89 | static inline void dump_payload(struct trusted_key_payload *p)
|
| 90 | {
|
| 91 | if (!trusted_debug)
|
| 92 | return;
|
| 93 |
|
| 94 | pr_debug("key_len %d\n", p->key_len);
|
| 95 | print_hex_dump_debug("key ", DUMP_PREFIX_NONE,
|
| 96 | 16, 1, p->key, p->key_len, 0);
|
| 97 | pr_debug("bloblen %d\n", p->blob_len);
|
| 98 | print_hex_dump_debug("blob ", DUMP_PREFIX_NONE,
|
| 99 | 16, 1, p->blob, p->blob_len, 0);
|
| 100 | pr_debug("migratable %d\n", p->migratable);
|
| 101 | }
|
| 102 | #else
|
| 103 | static inline void dump_payload(struct trusted_key_payload *p)
|
| 104 | {
|
| 105 | }
|
| 106 | #endif
|
| 107 |
|
| 108 | #endif
|