forked from wolfSSL/wolfBoot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtpm.h
More file actions
148 lines (122 loc) · 5.67 KB
/
tpm.h
File metadata and controls
148 lines (122 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* tpm.h
*
* Copyright (C) 2025 wolfSSL Inc.
*
* This file is part of wolfBoot.
*
* wolfBoot is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef _WOLFBOOT_TPM_H_
#define _WOLFBOOT_TPM_H_
#ifdef WOLFBOOT_TPM
#include <image.h>
#include "wolftpm/tpm2.h"
#include "wolftpm/tpm2_wrap.h"
extern WOLFTPM2_DEV wolftpm_dev;
#if defined(WOLFBOOT_TPM_KEYSTORE) || defined(WOLFBOOT_TPM_SEAL)
extern WOLFTPM2_SESSION wolftpm_session;
extern WOLFTPM2_KEY wolftpm_srk;
#endif
#ifndef WOLFBOOT_TPM_KEYSTORE_NV_BASE
#define WOLFBOOT_TPM_KEYSTORE_NV_BASE 0x01400200
#endif
#ifndef WOLFBOOT_TPM_SEAL_NV_BASE
#define WOLFBOOT_TPM_SEAL_NV_BASE 0x01400300
#endif
#ifndef WOLFBOOT_TPM_PCR_ALG
/* Prefer SHA2-256 for PCR's, and all TPM 2.0 devices support it */
#define WOLFBOOT_TPM_PCR_ALG TPM_ALG_SHA256
#define WOLFBOOT_TPM_PCR_DIG_SZ 32
#endif
#define WOLFBOOT_MAX_SEAL_SZ MAX_SYM_DATA
/* API's that are callable from non-secure code */
int CSME_NSE_API wolfBoot_tpm2_caps(WOLFTPM2_CAPS* caps);
int CSME_NSE_API wolfBoot_tpm2_get_handles(TPM_HANDLE handle, TPML_HANDLE* handles);
const char* CSME_NSE_API wolfBoot_tpm2_get_alg_name(TPM_ALG_ID alg,
char* name, int name_sz);
const char* CSME_NSE_API wolfBoot_tpm2_get_rc_string(int rc,
char* error, int error_sz);
int CSME_NSE_API wolfBoot_tpm2_get_capability(GetCapability_In* in, GetCapability_Out* out);
int CSME_NSE_API wolfBoot_tpm2_read_pcr(uint8_t pcrIndex, uint8_t* digest, int* digestSz);
int CSME_NSE_API wolfBoot_tpm2_read_cert(uint32_t handle, uint8_t* cert, uint32_t* certSz);
#ifdef WOLFTPM_MFG_IDENTITY
int CSME_NSE_API wolfBoot_tpm2_get_aik(WOLFTPM2_KEY* aik,
uint8_t* masterPassword, uint16_t masterPasswordSz);
int CSME_NSE_API wolfBoot_tpm2_get_timestamp(WOLFTPM2_KEY* aik, GetTime_Out* getTime);
int CSME_NSE_API wolfBoot_tpm2_quote(WOLFTPM2_KEY* aik,
byte* pcrArray, word32 pcrArraySz, Quote_Out* quoteResult);
int CSME_NSE_API wolfBoot_tpm2_parse_attest(const TPM2B_ATTEST* in, TPMS_ATTEST* out);
#endif
/* Internal wolfBoot TPM API's */
int wolfBoot_tpm2_init(void);
void wolfBoot_tpm2_deinit(void);
int wolfBoot_tpm2_clear(void);
#if defined(WOLFBOOT_TPM_VERIFY) || defined(WOLFBOOT_TPM_SEAL)
int wolfBoot_load_pubkey(const uint8_t* pubkey_hint, WOLFTPM2_KEY* pubKey,
TPM_ALG_ID* pAlg);
#endif
#if defined(WOLFBOOT_TPM_KEYSTORE) || defined(WOLFBOOT_TPM_SEAL)
int wolfBoot_constant_compare(const uint8_t* a, const uint8_t* b, uint32_t len);
#endif
#ifdef WOLFBOOT_TPM_KEYSTORE
int wolfBoot_check_rot(int key_slot, uint8_t* pubkey_hint);
#endif
#ifdef WOLFBOOT_TPM_SEAL
int wolfBoot_get_random(uint8_t* buf, int sz);
int wolfBoot_get_pcr_active(uint8_t pcrAlg, uint32_t* pcrMask, uint8_t pcrMax);
int wolfBoot_build_policy(uint8_t pcrAlg, uint32_t pcrMask,
uint8_t* policy, uint32_t* policySz,
uint8_t* policyRef, uint32_t policyRefSz);
int wolfBoot_get_policy(struct wolfBoot_image* img,
uint8_t** policy, uint16_t* policySz);
int wolfBoot_seal(const uint8_t* pubkey_hint, const uint8_t* policy, uint16_t policySz,
int index, const uint8_t* secret, int secret_sz);
int wolfBoot_seal_auth(const uint8_t* pubkey_hint, const uint8_t* policy, uint16_t policySz,
int index, const uint8_t* secret, int secret_sz, const uint8_t* auth, int authSz);
int wolfBoot_seal_blob(const uint8_t* pubkey_hint, const uint8_t* policy, uint16_t policySz,
WOLFTPM2_KEYBLOB* seal_blob, const uint8_t* secret, int secret_sz, const uint8_t* auth, int authSz);
int wolfBoot_unseal(const uint8_t* pubkey_hint, const uint8_t* policy, uint16_t policySz,
int index, uint8_t* secret, int* secret_sz);
int wolfBoot_unseal_auth(const uint8_t* pubkey_hint, const uint8_t* policy, uint16_t policySz,
int index, uint8_t* secret, int* secret_sz, const uint8_t* auth, int authSz);
int wolfBoot_unseal_blob(const uint8_t* pubkey_hint, const uint8_t* policy, uint16_t policySz,
WOLFTPM2_KEYBLOB* seal_blob, uint8_t* secret, int* secret_sz, const uint8_t* auth, int authSz);
int wolfBoot_delete_seal(int index);
int wolfBoot_read_blob(uint32_t nvIndex, WOLFTPM2_KEYBLOB* blob,
const uint8_t* auth, uint32_t authSz);
int wolfBoot_store_blob(TPMI_RH_NV_AUTH authHandle, uint32_t nvIndex,
word32 nvAttributes, WOLFTPM2_KEYBLOB* blob,
const uint8_t* auth, uint32_t authSz);
int wolfBoot_delete_blob(TPMI_RH_NV_AUTH authHandle, uint32_t nvIndex,
const uint8_t* auth, uint32_t authSz);
uint32_t wolfBoot_tpm_pcrmask_sel(uint32_t pcrMask, uint8_t* pcrArray,
uint32_t pcrArraySz);
#endif
#ifdef WOLFBOOT_MEASURED_BOOT
int wolfBoot_tpm2_extend(uint8_t pcrIndex, uint8_t* hash, int line);
/* helper for measuring boot at line */
#define measure_boot(hash) \
wolfBoot_tpm2_extend(WOLFBOOT_MEASURED_PCR_A, (hash), __LINE__)
#endif /* WOLFBOOT_MEASURED_BOOT */
int wolfBoot_tpm_self_test(void);
/* debugging */
void wolfBoot_print_hexstr(const unsigned char* bin, unsigned long sz,
unsigned long maxLine);
void wolfBoot_print_bin(const uint8_t* buffer, uint32_t length);
#else
/* stubs */
#define measure_boot(hash)
#endif /* WOLFBOOT_TPM */
#endif /* !_WOLFBOOT_TPM_H_ */