This repository has been archived by the owner on Jul 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
SpdmDeviceSecretLib.h
247 lines (214 loc) · 10.2 KB
/
SpdmDeviceSecretLib.h
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/** @file
SPDM device secret library.
It follows the SPDM Specification.
Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __SPDM_DEVICE_SECRET_LIB_H__
#define __SPDM_DEVICE_SECRET_LIB_H__
#include "SpdmLibConfig.h"
#include <Base.h>
#include <IndustryStandard/Spdm.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseCryptLib.h>
#include <Library/SpdmCryptLib.h>
/**
Collect the device measurement.
@param MeasurementSpecification Indicates the measurement specification.
It must align with MeasurementSpecification (SPDM_MEASUREMENT_BLOCK_HEADER_SPECIFICATION_*)
@param MeasurementHashAlgo Indicates the measurement hash algorithm.
It must align with MeasurementHashAlgo (SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_*)
@param DeviceMeasurementCount The count of the device measurement block.
@param DeviceMeasurement A pointer to a destination buffer to store the concatenation of all device measurement blocks.
@param DeviceMeasurementSize On input, indicates the size in bytes of the destination buffer.
On output, indicates the size in bytes of all device measurement blocks in the buffer.
@retval TRUE the device measurement collection success and measurement is returned.
@retval FALSE the device measurement collection fail.
**/
typedef
BOOLEAN
(EFIAPI *SPDM_MEASUREMENT_COLLECTION_FUNC) (
IN UINT8 MeasurementSpecification,
IN UINT32 MeasurementHashAlgo,
OUT UINT8 *DeviceMeasurementCount,
OUT VOID *DeviceMeasurement,
IN OUT UINTN *DeviceMeasurementSize
);
/**
Sign an SPDM message data.
@param ReqBaseAsymAlg Indicates the signing algorithm.
@param MessageHash A pointer to a message hash to be signed.
@param HashSize The size in bytes of the message hash to be signed.
@param Signature A pointer to a destination buffer to store the signature.
@param SigSize On input, indicates the size in bytes of the destination buffer to store the signature.
On output, indicates the size in bytes of the signature in the buffer.
@retval TRUE signing success.
@retval FALSE signing fail.
**/
typedef
BOOLEAN
(EFIAPI *SPDM_REQUESTER_DATA_SIGN_FUNC) (
IN UINT16 ReqBaseAsymAlg,
IN CONST UINT8 *MessageHash,
IN UINTN HashSize,
OUT UINT8 *Signature,
IN OUT UINTN *SigSize
);
/**
Sign an SPDM message data.
@param BaseAsymAlgo Indicates the signing algorithm.
@param MessageHash A pointer to a message hash to be signed.
@param HashSize The size in bytes of the message hash to be signed.
@param Signature A pointer to a destination buffer to store the signature.
@param SigSize On input, indicates the size in bytes of the destination buffer to store the signature.
On output, indicates the size in bytes of the signature in the buffer.
@retval TRUE signing success.
@retval FALSE signing fail.
**/
typedef
BOOLEAN
(EFIAPI *SPDM_RESPONDER_DATA_SIGN_FUNC) (
IN UINT32 BaseAsymAlgo,
IN CONST UINT8 *MessageHash,
IN UINTN HashSize,
OUT UINT8 *Signature,
IN OUT UINTN *SigSize
);
/**
Derive HMAC-based Expand Key Derivation Function (HKDF) Expand, based upon the negotiated HKDF algorithm.
@param HashAlgo Indicates the hash algorithm.
It must align with BaseHashAlgo (SPDM_ALGORITHMS_BASE_HASH_ALGO_TPM_ALG_*)
@param PskHint Pointer to the user-supplied PSK Hint.
@param PskHintSize PSK Hint size in bytes.
@param Info Pointer to the application specific info.
@param InfoSize Info size in bytes.
@param Out Pointer to buffer to receive hkdf value.
@param OutSize Size of hkdf bytes to generate.
@retval TRUE Hkdf generated successfully.
@retval FALSE Hkdf generation failed.
**/
typedef
BOOLEAN
(EFIAPI *SPDM_PSK_HKDF_EXPAND_FUNC) (
IN UINT32 HashAlgo,
IN CONST UINT8 *PskHint, OPTIONAL
IN UINTN PskHintSize, OPTIONAL
IN CONST UINT8 *Info,
IN UINTN InfoSize,
OUT UINT8 *Out,
IN UINTN OutSize
);
/**
Collect the device measurement.
@param MeasurementSpecification Indicates the measurement specification.
It must align with MeasurementSpecification (SPDM_MEASUREMENT_BLOCK_HEADER_SPECIFICATION_*)
@param MeasurementHashAlgo Indicates the measurement hash algorithm.
It must align with MeasurementHashAlgo (SPDM_ALGORITHMS_MEASUREMENT_HASH_ALGO_*)
@param DeviceMeasurementCount The count of the device measurement block.
@param DeviceMeasurement A pointer to a destination buffer to store the concatenation of all device measurement blocks.
@param DeviceMeasurementSize On input, indicates the size in bytes of the destination buffer.
On output, indicates the size in bytes of all device measurement blocks in the buffer.
@retval TRUE the device measurement collection success and measurement is returned.
@retval FALSE the device measurement collection fail.
**/
BOOLEAN
EFIAPI
SpdmMeasurementCollectionFunc (
IN UINT8 MeasurementSpecification,
IN UINT32 MeasurementHashAlgo,
OUT UINT8 *DeviceMeasurementCount,
OUT VOID *DeviceMeasurement,
IN OUT UINTN *DeviceMeasurementSize
);
/**
Sign an SPDM message data.
@param ReqBaseAsymAlg Indicates the signing algorithm.
@param BaseHashAlgo Indicates the hash algorithm.
@param Message A pointer to a message to be signed (before hash).
@param MessageSize The size in bytes of the message to be signed.
@param Signature A pointer to a destination buffer to store the signature.
@param SigSize On input, indicates the size in bytes of the destination buffer to store the signature.
On output, indicates the size in bytes of the signature in the buffer.
@retval TRUE signing success.
@retval FALSE signing fail.
**/
BOOLEAN
EFIAPI
SpdmRequesterDataSignFunc (
IN UINT16 ReqBaseAsymAlg,
IN UINT32 BaseHashAlgo,
IN CONST UINT8 *Message,
IN UINTN MessageSize,
OUT UINT8 *Signature,
IN OUT UINTN *SigSize
);
/**
Sign an SPDM message data.
@param BaseAsymAlgo Indicates the signing algorithm.
@param BaseHashAlgo Indicates the hash algorithm.
@param Message A pointer to a message to be signed (before hash).
@param MessageSize The size in bytes of the message to be signed.
@param Signature A pointer to a destination buffer to store the signature.
@param SigSize On input, indicates the size in bytes of the destination buffer to store the signature.
On output, indicates the size in bytes of the signature in the buffer.
@retval TRUE signing success.
@retval FALSE signing fail.
**/
BOOLEAN
EFIAPI
SpdmResponderDataSignFunc (
IN UINT32 BaseAsymAlgo,
IN UINT32 BaseHashAlgo,
IN CONST UINT8 *Message,
IN UINTN MessageSize,
OUT UINT8 *Signature,
IN OUT UINTN *SigSize
);
/**
Derive HMAC-based Expand Key Derivation Function (HKDF) Expand, based upon the negotiated HKDF algorithm.
@param BaseHashAlgo Indicates the hash algorithm.
@param PskHint Pointer to the user-supplied PSK Hint.
@param PskHintSize PSK Hint size in bytes.
@param Info Pointer to the application specific info.
@param InfoSize Info size in bytes.
@param Out Pointer to buffer to receive hkdf value.
@param OutSize Size of hkdf bytes to generate.
@retval TRUE Hkdf generated successfully.
@retval FALSE Hkdf generation failed.
**/
BOOLEAN
EFIAPI
SpdmPskHandshakeSecretHkdfExpandFunc (
IN UINT32 BaseHashAlgo,
IN CONST UINT8 *PskHint, OPTIONAL
IN UINTN PskHintSize, OPTIONAL
IN CONST UINT8 *Info,
IN UINTN InfoSize,
OUT UINT8 *Out,
IN UINTN OutSize
);
/**
Derive HMAC-based Expand Key Derivation Function (HKDF) Expand, based upon the negotiated HKDF algorithm.
@param BaseHashAlgo Indicates the hash algorithm.
@param PskHint Pointer to the user-supplied PSK Hint.
@param PskHintSize PSK Hint size in bytes.
@param Info Pointer to the application specific info.
@param InfoSize Info size in bytes.
@param Out Pointer to buffer to receive hkdf value.
@param OutSize Size of hkdf bytes to generate.
@retval TRUE Hkdf generated successfully.
@retval FALSE Hkdf generation failed.
**/
BOOLEAN
EFIAPI
SpdmPskMasterSecretHkdfExpandFunc (
IN UINT32 BaseHashAlgo,
IN CONST UINT8 *PskHint, OPTIONAL
IN UINTN PskHintSize, OPTIONAL
IN CONST UINT8 *Info,
IN UINTN InfoSize,
OUT UINT8 *Out,
IN UINTN OutSize
);
#endif