Commit | Line | Data |
---|---|---|
97f98500 HT |
1 | /** @file\r |
2 | Defines base cryptographic library APIs.\r | |
3 | The Base Cryptographic Library provides implementations of basic cryptography\r | |
a8c44645 | 4 | primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security\r |
5 | functionality enabling.\r | |
97f98500 | 6 | \r |
c1e66210 | 7 | Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR>\r |
2009f6b4 | 8 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
97f98500 HT |
9 | \r |
10 | **/\r | |
11 | \r | |
12 | #ifndef __BASE_CRYPT_LIB_H__\r | |
13 | #define __BASE_CRYPT_LIB_H__\r | |
14 | \r | |
9e8841b4 QL |
15 | #include <Uefi/UefiBaseType.h>\r |
16 | \r | |
988e4d8f YL |
17 | #define CRYPTO_NID_NULL 0x0000\r |
18 | \r | |
f21a1d48 QZ |
19 | // Hash\r |
20 | #define CRYPTO_NID_SHA256 0x0001\r | |
21 | #define CRYPTO_NID_SHA384 0x0002\r | |
22 | #define CRYPTO_NID_SHA512 0x0003\r | |
23 | \r | |
988e4d8f YL |
24 | // Key Exchange\r |
25 | #define CRYPTO_NID_SECP256R1 0x0204\r | |
26 | #define CRYPTO_NID_SECP384R1 0x0205\r | |
27 | #define CRYPTO_NID_SECP521R1 0x0206\r | |
28 | \r | |
97f98500 HT |
29 | ///\r |
30 | /// MD5 digest size in bytes\r | |
31 | ///\r | |
7c342378 | 32 | #define MD5_DIGEST_SIZE 16\r |
97f98500 HT |
33 | \r |
34 | ///\r | |
35 | /// SHA-1 digest size in bytes.\r | |
36 | ///\r | |
7c342378 | 37 | #define SHA1_DIGEST_SIZE 20\r |
97f98500 HT |
38 | \r |
39 | ///\r | |
40 | /// SHA-256 digest size in bytes\r | |
41 | ///\r | |
42 | #define SHA256_DIGEST_SIZE 32\r | |
43 | \r | |
2ac68e8b QL |
44 | ///\r |
45 | /// SHA-384 digest size in bytes\r | |
46 | ///\r | |
47 | #define SHA384_DIGEST_SIZE 48\r | |
48 | \r | |
49 | ///\r | |
50 | /// SHA-512 digest size in bytes\r | |
51 | ///\r | |
52 | #define SHA512_DIGEST_SIZE 64\r | |
53 | \r | |
f0718d1d LX |
54 | ///\r |
55 | /// SM3 digest size in bytes\r | |
56 | ///\r | |
7c342378 | 57 | #define SM3_256_DIGEST_SIZE 32\r |
f0718d1d | 58 | \r |
a8c44645 | 59 | ///\r |
60 | /// TDES block size in bytes\r | |
61 | ///\r | |
7c342378 | 62 | #define TDES_BLOCK_SIZE 8\r |
a8c44645 | 63 | \r |
64 | ///\r | |
65 | /// AES block size in bytes\r | |
66 | ///\r | |
7c342378 | 67 | #define AES_BLOCK_SIZE 16\r |
a8c44645 | 68 | \r |
97f98500 HT |
69 | ///\r |
70 | /// RSA Key Tags Definition used in RsaSetKey() function for key component identification.\r | |
71 | ///\r | |
72 | typedef enum {\r | |
73 | RsaKeyN, ///< RSA public Modulus (N)\r | |
74 | RsaKeyE, ///< RSA Public exponent (e)\r | |
75 | RsaKeyD, ///< RSA Private exponent (d)\r | |
76 | RsaKeyP, ///< RSA secret prime factor of Modulus (p)\r | |
77 | RsaKeyQ, ///< RSA secret prime factor of Modules (q)\r | |
78 | RsaKeyDp, ///< p's CRT exponent (== d mod (p - 1))\r | |
79 | RsaKeyDq, ///< q's CRT exponent (== d mod (q - 1))\r | |
80 | RsaKeyQInv ///< The CRT coefficient (== 1/q mod p)\r | |
81 | } RSA_KEY_TAG;\r | |
82 | \r | |
7c342378 | 83 | // =====================================================================================\r |
97f98500 | 84 | // One-Way Cryptographic Hash Primitives\r |
7c342378 | 85 | // =====================================================================================\r |
97f98500 | 86 | \r |
e6a12a0f | 87 | #ifdef ENABLE_MD5_DEPRECATED_INTERFACES\r |
7c342378 | 88 | \r |
97f98500 HT |
89 | /**\r |
90 | Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r | |
91 | \r | |
532616bb | 92 | If this interface is not supported, then return zero.\r |
93 | \r | |
97f98500 | 94 | @return The size, in bytes, of the context buffer required for MD5 hash operations.\r |
532616bb | 95 | @retval 0 This interface is not supported.\r |
97f98500 HT |
96 | \r |
97 | **/\r | |
98 | UINTN\r | |
99 | EFIAPI\r | |
100 | Md5GetContextSize (\r | |
101 | VOID\r | |
102 | );\r | |
103 | \r | |
97f98500 HT |
104 | /**\r |
105 | Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r | |
106 | subsequent use.\r | |
107 | \r | |
16d2c32c | 108 | If Md5Context is NULL, then return FALSE.\r |
532616bb | 109 | If this interface is not supported, then return FALSE.\r |
97f98500 | 110 | \r |
a8c44645 | 111 | @param[out] Md5Context Pointer to MD5 context being initialized.\r |
97f98500 HT |
112 | \r |
113 | @retval TRUE MD5 context initialization succeeded.\r | |
114 | @retval FALSE MD5 context initialization failed.\r | |
532616bb | 115 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
116 | \r |
117 | **/\r | |
118 | BOOLEAN\r | |
119 | EFIAPI\r | |
120 | Md5Init (\r | |
a8c44645 | 121 | OUT VOID *Md5Context\r |
97f98500 HT |
122 | );\r |
123 | \r | |
a8c44645 | 124 | /**\r |
125 | Makes a copy of an existing MD5 context.\r | |
126 | \r | |
16d2c32c | 127 | If Md5Context is NULL, then return FALSE.\r |
128 | If NewMd5Context is NULL, then return FALSE.\r | |
532616bb | 129 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 130 | \r |
131 | @param[in] Md5Context Pointer to MD5 context being copied.\r | |
132 | @param[out] NewMd5Context Pointer to new MD5 context.\r | |
133 | \r | |
134 | @retval TRUE MD5 context copy succeeded.\r | |
135 | @retval FALSE MD5 context copy failed.\r | |
532616bb | 136 | @retval FALSE This interface is not supported.\r |
a8c44645 | 137 | \r |
138 | **/\r | |
139 | BOOLEAN\r | |
140 | EFIAPI\r | |
141 | Md5Duplicate (\r | |
142 | IN CONST VOID *Md5Context,\r | |
143 | OUT VOID *NewMd5Context\r | |
144 | );\r | |
97f98500 HT |
145 | \r |
146 | /**\r | |
a8c44645 | 147 | Digests the input data and updates MD5 context.\r |
148 | \r | |
149 | This function performs MD5 digest on a data buffer of the specified size.\r | |
150 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
2998af86 | 151 | MD5 context should be already correctly initialized by Md5Init(), and should not be finalized\r |
a8c44645 | 152 | by Md5Final(). Behavior with invalid context is undefined.\r |
97f98500 | 153 | \r |
16d2c32c | 154 | If Md5Context is NULL, then return FALSE.\r |
532616bb | 155 | If this interface is not supported, then return FALSE.\r |
97f98500 HT |
156 | \r |
157 | @param[in, out] Md5Context Pointer to the MD5 context.\r | |
158 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
a8c44645 | 159 | @param[in] DataSize Size of Data buffer in bytes.\r |
97f98500 HT |
160 | \r |
161 | @retval TRUE MD5 data digest succeeded.\r | |
a8c44645 | 162 | @retval FALSE MD5 data digest failed.\r |
532616bb | 163 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
164 | \r |
165 | **/\r | |
166 | BOOLEAN\r | |
167 | EFIAPI\r | |
168 | Md5Update (\r | |
169 | IN OUT VOID *Md5Context,\r | |
170 | IN CONST VOID *Data,\r | |
a8c44645 | 171 | IN UINTN DataSize\r |
97f98500 HT |
172 | );\r |
173 | \r | |
97f98500 | 174 | /**\r |
a8c44645 | 175 | Completes computation of the MD5 digest value.\r |
176 | \r | |
177 | This function completes MD5 hash computation and retrieves the digest value into\r | |
178 | the specified memory. After this function has been called, the MD5 context cannot\r | |
179 | be used again.\r | |
2998af86 | 180 | MD5 context should be already correctly initialized by Md5Init(), and should not be\r |
a8c44645 | 181 | finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r |
97f98500 | 182 | \r |
16d2c32c | 183 | If Md5Context is NULL, then return FALSE.\r |
184 | If HashValue is NULL, then return FALSE.\r | |
532616bb | 185 | If this interface is not supported, then return FALSE.\r |
97f98500 | 186 | \r |
a8c44645 | 187 | @param[in, out] Md5Context Pointer to the MD5 context.\r |
97f98500 HT |
188 | @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r |
189 | value (16 bytes).\r | |
190 | \r | |
191 | @retval TRUE MD5 digest computation succeeded.\r | |
192 | @retval FALSE MD5 digest computation failed.\r | |
532616bb | 193 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
194 | \r |
195 | **/\r | |
196 | BOOLEAN\r | |
197 | EFIAPI\r | |
198 | Md5Final (\r | |
199 | IN OUT VOID *Md5Context,\r | |
200 | OUT UINT8 *HashValue\r | |
201 | );\r | |
202 | \r | |
b7d1ba0a QL |
203 | /**\r |
204 | Computes the MD5 message digest of a input data buffer.\r | |
205 | \r | |
206 | This function performs the MD5 message digest of a given data buffer, and places\r | |
207 | the digest value into the specified memory.\r | |
208 | \r | |
209 | If this interface is not supported, then return FALSE.\r | |
210 | \r | |
211 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
212 | @param[in] DataSize Size of Data buffer in bytes.\r | |
213 | @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r | |
214 | value (16 bytes).\r | |
215 | \r | |
216 | @retval TRUE MD5 digest computation succeeded.\r | |
217 | @retval FALSE MD5 digest computation failed.\r | |
218 | @retval FALSE This interface is not supported.\r | |
219 | \r | |
220 | **/\r | |
221 | BOOLEAN\r | |
222 | EFIAPI\r | |
223 | Md5HashAll (\r | |
224 | IN CONST VOID *Data,\r | |
225 | IN UINTN DataSize,\r | |
226 | OUT UINT8 *HashValue\r | |
227 | );\r | |
7c342378 | 228 | \r |
acfd5557 | 229 | #endif\r |
b7d1ba0a | 230 | \r |
0f01cec5 | 231 | #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES\r |
7c342378 | 232 | \r |
97f98500 HT |
233 | /**\r |
234 | Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r | |
235 | \r | |
532616bb | 236 | If this interface is not supported, then return zero.\r |
237 | \r | |
97f98500 | 238 | @return The size, in bytes, of the context buffer required for SHA-1 hash operations.\r |
532616bb | 239 | @retval 0 This interface is not supported.\r |
97f98500 HT |
240 | \r |
241 | **/\r | |
242 | UINTN\r | |
243 | EFIAPI\r | |
244 | Sha1GetContextSize (\r | |
245 | VOID\r | |
246 | );\r | |
247 | \r | |
97f98500 | 248 | /**\r |
a8c44645 | 249 | Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for\r |
97f98500 HT |
250 | subsequent use.\r |
251 | \r | |
16d2c32c | 252 | If Sha1Context is NULL, then return FALSE.\r |
532616bb | 253 | If this interface is not supported, then return FALSE.\r |
97f98500 | 254 | \r |
a8c44645 | 255 | @param[out] Sha1Context Pointer to SHA-1 context being initialized.\r |
97f98500 | 256 | \r |
a8c44645 | 257 | @retval TRUE SHA-1 context initialization succeeded.\r |
258 | @retval FALSE SHA-1 context initialization failed.\r | |
532616bb | 259 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
260 | \r |
261 | **/\r | |
262 | BOOLEAN\r | |
263 | EFIAPI\r | |
264 | Sha1Init (\r | |
a8c44645 | 265 | OUT VOID *Sha1Context\r |
97f98500 HT |
266 | );\r |
267 | \r | |
a8c44645 | 268 | /**\r |
269 | Makes a copy of an existing SHA-1 context.\r | |
270 | \r | |
16d2c32c | 271 | If Sha1Context is NULL, then return FALSE.\r |
272 | If NewSha1Context is NULL, then return FALSE.\r | |
532616bb | 273 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 274 | \r |
275 | @param[in] Sha1Context Pointer to SHA-1 context being copied.\r | |
276 | @param[out] NewSha1Context Pointer to new SHA-1 context.\r | |
277 | \r | |
278 | @retval TRUE SHA-1 context copy succeeded.\r | |
279 | @retval FALSE SHA-1 context copy failed.\r | |
532616bb | 280 | @retval FALSE This interface is not supported.\r |
a8c44645 | 281 | \r |
282 | **/\r | |
283 | BOOLEAN\r | |
284 | EFIAPI\r | |
285 | Sha1Duplicate (\r | |
286 | IN CONST VOID *Sha1Context,\r | |
287 | OUT VOID *NewSha1Context\r | |
288 | );\r | |
97f98500 HT |
289 | \r |
290 | /**\r | |
a8c44645 | 291 | Digests the input data and updates SHA-1 context.\r |
292 | \r | |
293 | This function performs SHA-1 digest on a data buffer of the specified size.\r | |
294 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
2998af86 | 295 | SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized\r |
a8c44645 | 296 | by Sha1Final(). Behavior with invalid context is undefined.\r |
97f98500 | 297 | \r |
16d2c32c | 298 | If Sha1Context is NULL, then return FALSE.\r |
532616bb | 299 | If this interface is not supported, then return FALSE.\r |
97f98500 HT |
300 | \r |
301 | @param[in, out] Sha1Context Pointer to the SHA-1 context.\r | |
302 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
a8c44645 | 303 | @param[in] DataSize Size of Data buffer in bytes.\r |
97f98500 HT |
304 | \r |
305 | @retval TRUE SHA-1 data digest succeeded.\r | |
a8c44645 | 306 | @retval FALSE SHA-1 data digest failed.\r |
532616bb | 307 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
308 | \r |
309 | **/\r | |
310 | BOOLEAN\r | |
311 | EFIAPI\r | |
312 | Sha1Update (\r | |
313 | IN OUT VOID *Sha1Context,\r | |
314 | IN CONST VOID *Data,\r | |
a8c44645 | 315 | IN UINTN DataSize\r |
97f98500 HT |
316 | );\r |
317 | \r | |
97f98500 | 318 | /**\r |
a8c44645 | 319 | Completes computation of the SHA-1 digest value.\r |
320 | \r | |
321 | This function completes SHA-1 hash computation and retrieves the digest value into\r | |
322 | the specified memory. After this function has been called, the SHA-1 context cannot\r | |
323 | be used again.\r | |
2998af86 | 324 | SHA-1 context should be already correctly initialized by Sha1Init(), and should not be\r |
a8c44645 | 325 | finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.\r |
97f98500 | 326 | \r |
16d2c32c | 327 | If Sha1Context is NULL, then return FALSE.\r |
328 | If HashValue is NULL, then return FALSE.\r | |
532616bb | 329 | If this interface is not supported, then return FALSE.\r |
97f98500 | 330 | \r |
a8c44645 | 331 | @param[in, out] Sha1Context Pointer to the SHA-1 context.\r |
97f98500 HT |
332 | @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r |
333 | value (20 bytes).\r | |
334 | \r | |
335 | @retval TRUE SHA-1 digest computation succeeded.\r | |
336 | @retval FALSE SHA-1 digest computation failed.\r | |
532616bb | 337 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
338 | \r |
339 | **/\r | |
340 | BOOLEAN\r | |
341 | EFIAPI\r | |
342 | Sha1Final (\r | |
343 | IN OUT VOID *Sha1Context,\r | |
344 | OUT UINT8 *HashValue\r | |
345 | );\r | |
346 | \r | |
b7d1ba0a QL |
347 | /**\r |
348 | Computes the SHA-1 message digest of a input data buffer.\r | |
349 | \r | |
350 | This function performs the SHA-1 message digest of a given data buffer, and places\r | |
351 | the digest value into the specified memory.\r | |
352 | \r | |
353 | If this interface is not supported, then return FALSE.\r | |
354 | \r | |
355 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
356 | @param[in] DataSize Size of Data buffer in bytes.\r | |
357 | @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r | |
358 | value (20 bytes).\r | |
359 | \r | |
360 | @retval TRUE SHA-1 digest computation succeeded.\r | |
361 | @retval FALSE SHA-1 digest computation failed.\r | |
362 | @retval FALSE This interface is not supported.\r | |
363 | \r | |
364 | **/\r | |
365 | BOOLEAN\r | |
366 | EFIAPI\r | |
367 | Sha1HashAll (\r | |
368 | IN CONST VOID *Data,\r | |
369 | IN UINTN DataSize,\r | |
370 | OUT UINT8 *HashValue\r | |
371 | );\r | |
7c342378 | 372 | \r |
0f01cec5 | 373 | #endif\r |
b7d1ba0a | 374 | \r |
97f98500 | 375 | /**\r |
a8c44645 | 376 | Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.\r |
97f98500 | 377 | \r |
a8c44645 | 378 | @return The size, in bytes, of the context buffer required for SHA-256 hash operations.\r |
97f98500 HT |
379 | \r |
380 | **/\r | |
381 | UINTN\r | |
382 | EFIAPI\r | |
383 | Sha256GetContextSize (\r | |
384 | VOID\r | |
385 | );\r | |
386 | \r | |
97f98500 HT |
387 | /**\r |
388 | Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for\r | |
389 | subsequent use.\r | |
390 | \r | |
16d2c32c | 391 | If Sha256Context is NULL, then return FALSE.\r |
97f98500 | 392 | \r |
a8c44645 | 393 | @param[out] Sha256Context Pointer to SHA-256 context being initialized.\r |
97f98500 HT |
394 | \r |
395 | @retval TRUE SHA-256 context initialization succeeded.\r | |
396 | @retval FALSE SHA-256 context initialization failed.\r | |
397 | \r | |
398 | **/\r | |
399 | BOOLEAN\r | |
400 | EFIAPI\r | |
401 | Sha256Init (\r | |
a8c44645 | 402 | OUT VOID *Sha256Context\r |
97f98500 HT |
403 | );\r |
404 | \r | |
a8c44645 | 405 | /**\r |
406 | Makes a copy of an existing SHA-256 context.\r | |
407 | \r | |
16d2c32c | 408 | If Sha256Context is NULL, then return FALSE.\r |
409 | If NewSha256Context is NULL, then return FALSE.\r | |
532616bb | 410 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 411 | \r |
412 | @param[in] Sha256Context Pointer to SHA-256 context being copied.\r | |
413 | @param[out] NewSha256Context Pointer to new SHA-256 context.\r | |
414 | \r | |
415 | @retval TRUE SHA-256 context copy succeeded.\r | |
416 | @retval FALSE SHA-256 context copy failed.\r | |
532616bb | 417 | @retval FALSE This interface is not supported.\r |
a8c44645 | 418 | \r |
419 | **/\r | |
420 | BOOLEAN\r | |
421 | EFIAPI\r | |
422 | Sha256Duplicate (\r | |
423 | IN CONST VOID *Sha256Context,\r | |
424 | OUT VOID *NewSha256Context\r | |
425 | );\r | |
97f98500 HT |
426 | \r |
427 | /**\r | |
a8c44645 | 428 | Digests the input data and updates SHA-256 context.\r |
429 | \r | |
430 | This function performs SHA-256 digest on a data buffer of the specified size.\r | |
431 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
2998af86 | 432 | SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized\r |
a8c44645 | 433 | by Sha256Final(). Behavior with invalid context is undefined.\r |
97f98500 | 434 | \r |
16d2c32c | 435 | If Sha256Context is NULL, then return FALSE.\r |
97f98500 HT |
436 | \r |
437 | @param[in, out] Sha256Context Pointer to the SHA-256 context.\r | |
438 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
a8c44645 | 439 | @param[in] DataSize Size of Data buffer in bytes.\r |
97f98500 HT |
440 | \r |
441 | @retval TRUE SHA-256 data digest succeeded.\r | |
a8c44645 | 442 | @retval FALSE SHA-256 data digest failed.\r |
97f98500 HT |
443 | \r |
444 | **/\r | |
445 | BOOLEAN\r | |
446 | EFIAPI\r | |
447 | Sha256Update (\r | |
448 | IN OUT VOID *Sha256Context,\r | |
449 | IN CONST VOID *Data,\r | |
a8c44645 | 450 | IN UINTN DataSize\r |
97f98500 HT |
451 | );\r |
452 | \r | |
97f98500 | 453 | /**\r |
a8c44645 | 454 | Completes computation of the SHA-256 digest value.\r |
455 | \r | |
456 | This function completes SHA-256 hash computation and retrieves the digest value into\r | |
457 | the specified memory. After this function has been called, the SHA-256 context cannot\r | |
458 | be used again.\r | |
2998af86 | 459 | SHA-256 context should be already correctly initialized by Sha256Init(), and should not be\r |
a8c44645 | 460 | finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.\r |
97f98500 | 461 | \r |
16d2c32c | 462 | If Sha256Context is NULL, then return FALSE.\r |
463 | If HashValue is NULL, then return FALSE.\r | |
97f98500 | 464 | \r |
a8c44645 | 465 | @param[in, out] Sha256Context Pointer to the SHA-256 context.\r |
97f98500 HT |
466 | @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r |
467 | value (32 bytes).\r | |
468 | \r | |
469 | @retval TRUE SHA-256 digest computation succeeded.\r | |
470 | @retval FALSE SHA-256 digest computation failed.\r | |
471 | \r | |
472 | **/\r | |
473 | BOOLEAN\r | |
474 | EFIAPI\r | |
475 | Sha256Final (\r | |
476 | IN OUT VOID *Sha256Context,\r | |
477 | OUT UINT8 *HashValue\r | |
478 | );\r | |
479 | \r | |
b7d1ba0a QL |
480 | /**\r |
481 | Computes the SHA-256 message digest of a input data buffer.\r | |
482 | \r | |
483 | This function performs the SHA-256 message digest of a given data buffer, and places\r | |
484 | the digest value into the specified memory.\r | |
485 | \r | |
486 | If this interface is not supported, then return FALSE.\r | |
487 | \r | |
488 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
489 | @param[in] DataSize Size of Data buffer in bytes.\r | |
490 | @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r | |
491 | value (32 bytes).\r | |
492 | \r | |
493 | @retval TRUE SHA-256 digest computation succeeded.\r | |
494 | @retval FALSE SHA-256 digest computation failed.\r | |
495 | @retval FALSE This interface is not supported.\r | |
496 | \r | |
497 | **/\r | |
498 | BOOLEAN\r | |
499 | EFIAPI\r | |
500 | Sha256HashAll (\r | |
501 | IN CONST VOID *Data,\r | |
502 | IN UINTN DataSize,\r | |
503 | OUT UINT8 *HashValue\r | |
504 | );\r | |
505 | \r | |
2ac68e8b QL |
506 | /**\r |
507 | Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.\r | |
508 | \r | |
509 | @return The size, in bytes, of the context buffer required for SHA-384 hash operations.\r | |
510 | \r | |
511 | **/\r | |
512 | UINTN\r | |
513 | EFIAPI\r | |
514 | Sha384GetContextSize (\r | |
515 | VOID\r | |
516 | );\r | |
517 | \r | |
518 | /**\r | |
519 | Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for\r | |
520 | subsequent use.\r | |
521 | \r | |
522 | If Sha384Context is NULL, then return FALSE.\r | |
523 | \r | |
524 | @param[out] Sha384Context Pointer to SHA-384 context being initialized.\r | |
525 | \r | |
526 | @retval TRUE SHA-384 context initialization succeeded.\r | |
527 | @retval FALSE SHA-384 context initialization failed.\r | |
528 | \r | |
529 | **/\r | |
530 | BOOLEAN\r | |
531 | EFIAPI\r | |
532 | Sha384Init (\r | |
533 | OUT VOID *Sha384Context\r | |
534 | );\r | |
535 | \r | |
536 | /**\r | |
537 | Makes a copy of an existing SHA-384 context.\r | |
538 | \r | |
539 | If Sha384Context is NULL, then return FALSE.\r | |
540 | If NewSha384Context is NULL, then return FALSE.\r | |
541 | If this interface is not supported, then return FALSE.\r | |
542 | \r | |
543 | @param[in] Sha384Context Pointer to SHA-384 context being copied.\r | |
544 | @param[out] NewSha384Context Pointer to new SHA-384 context.\r | |
545 | \r | |
546 | @retval TRUE SHA-384 context copy succeeded.\r | |
547 | @retval FALSE SHA-384 context copy failed.\r | |
548 | @retval FALSE This interface is not supported.\r | |
549 | \r | |
550 | **/\r | |
551 | BOOLEAN\r | |
552 | EFIAPI\r | |
553 | Sha384Duplicate (\r | |
554 | IN CONST VOID *Sha384Context,\r | |
555 | OUT VOID *NewSha384Context\r | |
556 | );\r | |
557 | \r | |
558 | /**\r | |
559 | Digests the input data and updates SHA-384 context.\r | |
560 | \r | |
561 | This function performs SHA-384 digest on a data buffer of the specified size.\r | |
562 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
2998af86 | 563 | SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized\r |
2ac68e8b QL |
564 | by Sha384Final(). Behavior with invalid context is undefined.\r |
565 | \r | |
566 | If Sha384Context is NULL, then return FALSE.\r | |
567 | \r | |
568 | @param[in, out] Sha384Context Pointer to the SHA-384 context.\r | |
569 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
570 | @param[in] DataSize Size of Data buffer in bytes.\r | |
571 | \r | |
572 | @retval TRUE SHA-384 data digest succeeded.\r | |
573 | @retval FALSE SHA-384 data digest failed.\r | |
574 | \r | |
575 | **/\r | |
576 | BOOLEAN\r | |
577 | EFIAPI\r | |
578 | Sha384Update (\r | |
579 | IN OUT VOID *Sha384Context,\r | |
580 | IN CONST VOID *Data,\r | |
581 | IN UINTN DataSize\r | |
582 | );\r | |
583 | \r | |
584 | /**\r | |
585 | Completes computation of the SHA-384 digest value.\r | |
586 | \r | |
587 | This function completes SHA-384 hash computation and retrieves the digest value into\r | |
588 | the specified memory. After this function has been called, the SHA-384 context cannot\r | |
589 | be used again.\r | |
2998af86 | 590 | SHA-384 context should be already correctly initialized by Sha384Init(), and should not be\r |
2ac68e8b QL |
591 | finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.\r |
592 | \r | |
593 | If Sha384Context is NULL, then return FALSE.\r | |
594 | If HashValue is NULL, then return FALSE.\r | |
595 | \r | |
596 | @param[in, out] Sha384Context Pointer to the SHA-384 context.\r | |
597 | @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r | |
598 | value (48 bytes).\r | |
599 | \r | |
600 | @retval TRUE SHA-384 digest computation succeeded.\r | |
601 | @retval FALSE SHA-384 digest computation failed.\r | |
602 | \r | |
603 | **/\r | |
604 | BOOLEAN\r | |
605 | EFIAPI\r | |
606 | Sha384Final (\r | |
607 | IN OUT VOID *Sha384Context,\r | |
608 | OUT UINT8 *HashValue\r | |
609 | );\r | |
610 | \r | |
b7d1ba0a QL |
611 | /**\r |
612 | Computes the SHA-384 message digest of a input data buffer.\r | |
613 | \r | |
614 | This function performs the SHA-384 message digest of a given data buffer, and places\r | |
615 | the digest value into the specified memory.\r | |
616 | \r | |
617 | If this interface is not supported, then return FALSE.\r | |
618 | \r | |
619 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
620 | @param[in] DataSize Size of Data buffer in bytes.\r | |
621 | @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r | |
622 | value (48 bytes).\r | |
623 | \r | |
624 | @retval TRUE SHA-384 digest computation succeeded.\r | |
625 | @retval FALSE SHA-384 digest computation failed.\r | |
626 | @retval FALSE This interface is not supported.\r | |
627 | \r | |
628 | **/\r | |
629 | BOOLEAN\r | |
630 | EFIAPI\r | |
631 | Sha384HashAll (\r | |
632 | IN CONST VOID *Data,\r | |
633 | IN UINTN DataSize,\r | |
634 | OUT UINT8 *HashValue\r | |
635 | );\r | |
636 | \r | |
2ac68e8b QL |
637 | /**\r |
638 | Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r | |
639 | \r | |
640 | @return The size, in bytes, of the context buffer required for SHA-512 hash operations.\r | |
641 | \r | |
642 | **/\r | |
643 | UINTN\r | |
644 | EFIAPI\r | |
645 | Sha512GetContextSize (\r | |
646 | VOID\r | |
647 | );\r | |
648 | \r | |
649 | /**\r | |
650 | Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for\r | |
651 | subsequent use.\r | |
652 | \r | |
653 | If Sha512Context is NULL, then return FALSE.\r | |
654 | \r | |
655 | @param[out] Sha512Context Pointer to SHA-512 context being initialized.\r | |
656 | \r | |
657 | @retval TRUE SHA-512 context initialization succeeded.\r | |
658 | @retval FALSE SHA-512 context initialization failed.\r | |
659 | \r | |
660 | **/\r | |
661 | BOOLEAN\r | |
662 | EFIAPI\r | |
663 | Sha512Init (\r | |
664 | OUT VOID *Sha512Context\r | |
665 | );\r | |
666 | \r | |
667 | /**\r | |
668 | Makes a copy of an existing SHA-512 context.\r | |
669 | \r | |
670 | If Sha512Context is NULL, then return FALSE.\r | |
671 | If NewSha512Context is NULL, then return FALSE.\r | |
672 | If this interface is not supported, then return FALSE.\r | |
673 | \r | |
674 | @param[in] Sha512Context Pointer to SHA-512 context being copied.\r | |
675 | @param[out] NewSha512Context Pointer to new SHA-512 context.\r | |
676 | \r | |
677 | @retval TRUE SHA-512 context copy succeeded.\r | |
678 | @retval FALSE SHA-512 context copy failed.\r | |
679 | @retval FALSE This interface is not supported.\r | |
680 | \r | |
681 | **/\r | |
682 | BOOLEAN\r | |
683 | EFIAPI\r | |
684 | Sha512Duplicate (\r | |
685 | IN CONST VOID *Sha512Context,\r | |
686 | OUT VOID *NewSha512Context\r | |
687 | );\r | |
688 | \r | |
689 | /**\r | |
690 | Digests the input data and updates SHA-512 context.\r | |
691 | \r | |
692 | This function performs SHA-512 digest on a data buffer of the specified size.\r | |
693 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
2998af86 | 694 | SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized\r |
2ac68e8b QL |
695 | by Sha512Final(). Behavior with invalid context is undefined.\r |
696 | \r | |
697 | If Sha512Context is NULL, then return FALSE.\r | |
698 | \r | |
699 | @param[in, out] Sha512Context Pointer to the SHA-512 context.\r | |
700 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
701 | @param[in] DataSize Size of Data buffer in bytes.\r | |
702 | \r | |
703 | @retval TRUE SHA-512 data digest succeeded.\r | |
704 | @retval FALSE SHA-512 data digest failed.\r | |
705 | \r | |
706 | **/\r | |
707 | BOOLEAN\r | |
708 | EFIAPI\r | |
709 | Sha512Update (\r | |
710 | IN OUT VOID *Sha512Context,\r | |
711 | IN CONST VOID *Data,\r | |
712 | IN UINTN DataSize\r | |
713 | );\r | |
714 | \r | |
715 | /**\r | |
716 | Completes computation of the SHA-512 digest value.\r | |
717 | \r | |
718 | This function completes SHA-512 hash computation and retrieves the digest value into\r | |
719 | the specified memory. After this function has been called, the SHA-512 context cannot\r | |
720 | be used again.\r | |
2998af86 | 721 | SHA-512 context should be already correctly initialized by Sha512Init(), and should not be\r |
2ac68e8b QL |
722 | finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.\r |
723 | \r | |
724 | If Sha512Context is NULL, then return FALSE.\r | |
725 | If HashValue is NULL, then return FALSE.\r | |
726 | \r | |
727 | @param[in, out] Sha512Context Pointer to the SHA-512 context.\r | |
728 | @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r | |
729 | value (64 bytes).\r | |
730 | \r | |
731 | @retval TRUE SHA-512 digest computation succeeded.\r | |
732 | @retval FALSE SHA-512 digest computation failed.\r | |
733 | \r | |
734 | **/\r | |
735 | BOOLEAN\r | |
736 | EFIAPI\r | |
737 | Sha512Final (\r | |
738 | IN OUT VOID *Sha512Context,\r | |
739 | OUT UINT8 *HashValue\r | |
740 | );\r | |
97f98500 | 741 | \r |
b7d1ba0a QL |
742 | /**\r |
743 | Computes the SHA-512 message digest of a input data buffer.\r | |
744 | \r | |
745 | This function performs the SHA-512 message digest of a given data buffer, and places\r | |
746 | the digest value into the specified memory.\r | |
747 | \r | |
748 | If this interface is not supported, then return FALSE.\r | |
749 | \r | |
750 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
751 | @param[in] DataSize Size of Data buffer in bytes.\r | |
752 | @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r | |
753 | value (64 bytes).\r | |
754 | \r | |
755 | @retval TRUE SHA-512 digest computation succeeded.\r | |
756 | @retval FALSE SHA-512 digest computation failed.\r | |
757 | @retval FALSE This interface is not supported.\r | |
758 | \r | |
759 | **/\r | |
760 | BOOLEAN\r | |
761 | EFIAPI\r | |
762 | Sha512HashAll (\r | |
763 | IN CONST VOID *Data,\r | |
764 | IN UINTN DataSize,\r | |
765 | OUT UINT8 *HashValue\r | |
766 | );\r | |
767 | \r | |
c1e66210 ZL |
768 | /**\r |
769 | Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,\r | |
770 | published December 2016.\r | |
771 | \r | |
772 | @param[in] Input Pointer to the input message (X).\r | |
773 | @param[in] InputByteLen The number(>0) of input bytes provided for the input data.\r | |
774 | @param[in] BlockSize The size of each block (B).\r | |
775 | @param[out] Output Pointer to the output buffer.\r | |
776 | @param[in] OutputByteLen The desired number of output bytes (L).\r | |
777 | @param[in] Customization Pointer to the customization string (S).\r | |
778 | @param[in] CustomByteLen The length of the customization string in bytes.\r | |
779 | \r | |
780 | @retval TRUE ParallelHash256 digest computation succeeded.\r | |
781 | @retval FALSE ParallelHash256 digest computation failed.\r | |
782 | @retval FALSE This interface is not supported.\r | |
783 | \r | |
784 | **/\r | |
785 | BOOLEAN\r | |
786 | EFIAPI\r | |
787 | ParallelHash256HashAll (\r | |
788 | IN CONST VOID *Input,\r | |
789 | IN UINTN InputByteLen,\r | |
790 | IN UINTN BlockSize,\r | |
791 | OUT VOID *Output,\r | |
792 | IN UINTN OutputByteLen,\r | |
793 | IN CONST VOID *Customization,\r | |
794 | IN UINTN CustomByteLen\r | |
795 | );\r | |
796 | \r | |
f0718d1d LX |
797 | /**\r |
798 | Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.\r | |
799 | \r | |
800 | @return The size, in bytes, of the context buffer required for SM3 hash operations.\r | |
801 | \r | |
802 | **/\r | |
803 | UINTN\r | |
804 | EFIAPI\r | |
805 | Sm3GetContextSize (\r | |
806 | VOID\r | |
807 | );\r | |
808 | \r | |
809 | /**\r | |
810 | Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for\r | |
811 | subsequent use.\r | |
812 | \r | |
813 | If Sm3Context is NULL, then return FALSE.\r | |
814 | \r | |
815 | @param[out] Sm3Context Pointer to SM3 context being initialized.\r | |
816 | \r | |
817 | @retval TRUE SM3 context initialization succeeded.\r | |
818 | @retval FALSE SM3 context initialization failed.\r | |
819 | \r | |
820 | **/\r | |
821 | BOOLEAN\r | |
822 | EFIAPI\r | |
823 | Sm3Init (\r | |
824 | OUT VOID *Sm3Context\r | |
825 | );\r | |
826 | \r | |
827 | /**\r | |
828 | Makes a copy of an existing SM3 context.\r | |
829 | \r | |
830 | If Sm3Context is NULL, then return FALSE.\r | |
831 | If NewSm3Context is NULL, then return FALSE.\r | |
832 | If this interface is not supported, then return FALSE.\r | |
833 | \r | |
834 | @param[in] Sm3Context Pointer to SM3 context being copied.\r | |
835 | @param[out] NewSm3Context Pointer to new SM3 context.\r | |
836 | \r | |
837 | @retval TRUE SM3 context copy succeeded.\r | |
838 | @retval FALSE SM3 context copy failed.\r | |
839 | @retval FALSE This interface is not supported.\r | |
840 | \r | |
841 | **/\r | |
842 | BOOLEAN\r | |
843 | EFIAPI\r | |
844 | Sm3Duplicate (\r | |
845 | IN CONST VOID *Sm3Context,\r | |
846 | OUT VOID *NewSm3Context\r | |
847 | );\r | |
848 | \r | |
849 | /**\r | |
850 | Digests the input data and updates SM3 context.\r | |
851 | \r | |
852 | This function performs SM3 digest on a data buffer of the specified size.\r | |
853 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
854 | SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized\r | |
855 | by Sm3Final(). Behavior with invalid context is undefined.\r | |
856 | \r | |
857 | If Sm3Context is NULL, then return FALSE.\r | |
858 | \r | |
859 | @param[in, out] Sm3Context Pointer to the SM3 context.\r | |
860 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
861 | @param[in] DataSize Size of Data buffer in bytes.\r | |
862 | \r | |
863 | @retval TRUE SM3 data digest succeeded.\r | |
864 | @retval FALSE SM3 data digest failed.\r | |
865 | \r | |
866 | **/\r | |
867 | BOOLEAN\r | |
868 | EFIAPI\r | |
869 | Sm3Update (\r | |
870 | IN OUT VOID *Sm3Context,\r | |
871 | IN CONST VOID *Data,\r | |
872 | IN UINTN DataSize\r | |
873 | );\r | |
874 | \r | |
875 | /**\r | |
876 | Completes computation of the SM3 digest value.\r | |
877 | \r | |
878 | This function completes SM3 hash computation and retrieves the digest value into\r | |
879 | the specified memory. After this function has been called, the SM3 context cannot\r | |
880 | be used again.\r | |
881 | SM3 context should be already correctly initialized by Sm3Init(), and should not be\r | |
882 | finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.\r | |
883 | \r | |
884 | If Sm3Context is NULL, then return FALSE.\r | |
885 | If HashValue is NULL, then return FALSE.\r | |
886 | \r | |
887 | @param[in, out] Sm3Context Pointer to the SM3 context.\r | |
888 | @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r | |
889 | value (32 bytes).\r | |
890 | \r | |
891 | @retval TRUE SM3 digest computation succeeded.\r | |
892 | @retval FALSE SM3 digest computation failed.\r | |
893 | \r | |
894 | **/\r | |
895 | BOOLEAN\r | |
896 | EFIAPI\r | |
897 | Sm3Final (\r | |
898 | IN OUT VOID *Sm3Context,\r | |
899 | OUT UINT8 *HashValue\r | |
900 | );\r | |
901 | \r | |
902 | /**\r | |
903 | Computes the SM3 message digest of a input data buffer.\r | |
904 | \r | |
905 | This function performs the SM3 message digest of a given data buffer, and places\r | |
906 | the digest value into the specified memory.\r | |
907 | \r | |
908 | If this interface is not supported, then return FALSE.\r | |
909 | \r | |
910 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
911 | @param[in] DataSize Size of Data buffer in bytes.\r | |
912 | @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r | |
913 | value (32 bytes).\r | |
914 | \r | |
915 | @retval TRUE SM3 digest computation succeeded.\r | |
916 | @retval FALSE SM3 digest computation failed.\r | |
917 | @retval FALSE This interface is not supported.\r | |
918 | \r | |
919 | **/\r | |
920 | BOOLEAN\r | |
921 | EFIAPI\r | |
922 | Sm3HashAll (\r | |
923 | IN CONST VOID *Data,\r | |
924 | IN UINTN DataSize,\r | |
925 | OUT UINT8 *HashValue\r | |
926 | );\r | |
927 | \r | |
7c342378 | 928 | // =====================================================================================\r |
97f98500 | 929 | // MAC (Message Authentication Code) Primitive\r |
7c342378 | 930 | // =====================================================================================\r |
97f98500 | 931 | \r |
4c270243 QL |
932 | /**\r |
933 | Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.\r | |
934 | \r | |
935 | @return Pointer to the HMAC_CTX context that has been initialized.\r | |
936 | If the allocations fails, HmacSha256New() returns NULL.\r | |
937 | \r | |
938 | **/\r | |
939 | VOID *\r | |
940 | EFIAPI\r | |
941 | HmacSha256New (\r | |
942 | VOID\r | |
943 | );\r | |
944 | \r | |
945 | /**\r | |
946 | Release the specified HMAC_CTX context.\r | |
947 | \r | |
948 | @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.\r | |
949 | \r | |
950 | **/\r | |
951 | VOID\r | |
952 | EFIAPI\r | |
953 | HmacSha256Free (\r | |
954 | IN VOID *HmacSha256Ctx\r | |
955 | );\r | |
956 | \r | |
72009c62 | 957 | /**\r |
a23fdff6 JW |
958 | Set user-supplied key for subsequent use. It must be done before any\r |
959 | calling to HmacSha256Update().\r | |
72009c62 QL |
960 | \r |
961 | If HmacSha256Context is NULL, then return FALSE.\r | |
962 | If this interface is not supported, then return FALSE.\r | |
963 | \r | |
a23fdff6 | 964 | @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.\r |
72009c62 QL |
965 | @param[in] Key Pointer to the user-supplied key.\r |
966 | @param[in] KeySize Key size in bytes.\r | |
967 | \r | |
a23fdff6 JW |
968 | @retval TRUE The Key is set successfully.\r |
969 | @retval FALSE The Key is set unsuccessfully.\r | |
72009c62 QL |
970 | @retval FALSE This interface is not supported.\r |
971 | \r | |
972 | **/\r | |
973 | BOOLEAN\r | |
974 | EFIAPI\r | |
a23fdff6 | 975 | HmacSha256SetKey (\r |
72009c62 QL |
976 | OUT VOID *HmacSha256Context,\r |
977 | IN CONST UINT8 *Key,\r | |
978 | IN UINTN KeySize\r | |
979 | );\r | |
980 | \r | |
981 | /**\r | |
982 | Makes a copy of an existing HMAC-SHA256 context.\r | |
983 | \r | |
984 | If HmacSha256Context is NULL, then return FALSE.\r | |
985 | If NewHmacSha256Context is NULL, then return FALSE.\r | |
986 | If this interface is not supported, then return FALSE.\r | |
987 | \r | |
988 | @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.\r | |
989 | @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.\r | |
990 | \r | |
991 | @retval TRUE HMAC-SHA256 context copy succeeded.\r | |
992 | @retval FALSE HMAC-SHA256 context copy failed.\r | |
993 | @retval FALSE This interface is not supported.\r | |
994 | \r | |
995 | **/\r | |
996 | BOOLEAN\r | |
997 | EFIAPI\r | |
998 | HmacSha256Duplicate (\r | |
999 | IN CONST VOID *HmacSha256Context,\r | |
1000 | OUT VOID *NewHmacSha256Context\r | |
1001 | );\r | |
1002 | \r | |
1003 | /**\r | |
1004 | Digests the input data and updates HMAC-SHA256 context.\r | |
1005 | \r | |
1006 | This function performs HMAC-SHA256 digest on a data buffer of the specified size.\r | |
1007 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
a23fdff6 JW |
1008 | HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r |
1009 | by HmacSha256Final(). Behavior with invalid context is undefined.\r | |
72009c62 QL |
1010 | \r |
1011 | If HmacSha256Context is NULL, then return FALSE.\r | |
1012 | If this interface is not supported, then return FALSE.\r | |
1013 | \r | |
1014 | @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r | |
1015 | @param[in] Data Pointer to the buffer containing the data to be digested.\r | |
1016 | @param[in] DataSize Size of Data buffer in bytes.\r | |
1017 | \r | |
1018 | @retval TRUE HMAC-SHA256 data digest succeeded.\r | |
1019 | @retval FALSE HMAC-SHA256 data digest failed.\r | |
1020 | @retval FALSE This interface is not supported.\r | |
1021 | \r | |
1022 | **/\r | |
1023 | BOOLEAN\r | |
1024 | EFIAPI\r | |
1025 | HmacSha256Update (\r | |
1026 | IN OUT VOID *HmacSha256Context,\r | |
1027 | IN CONST VOID *Data,\r | |
1028 | IN UINTN DataSize\r | |
1029 | );\r | |
1030 | \r | |
1031 | /**\r | |
1032 | Completes computation of the HMAC-SHA256 digest value.\r | |
1033 | \r | |
1034 | This function completes HMAC-SHA256 hash computation and retrieves the digest value into\r | |
1035 | the specified memory. After this function has been called, the HMAC-SHA256 context cannot\r | |
1036 | be used again.\r | |
a23fdff6 JW |
1037 | HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r |
1038 | by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.\r | |
72009c62 QL |
1039 | \r |
1040 | If HmacSha256Context is NULL, then return FALSE.\r | |
68ae7cd6 | 1041 | If HmacValue is NULL, then return FALSE.\r |
72009c62 QL |
1042 | If this interface is not supported, then return FALSE.\r |
1043 | \r | |
1044 | @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r | |
68ae7cd6 | 1045 | @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r |
72009c62 QL |
1046 | value (32 bytes).\r |
1047 | \r | |
1048 | @retval TRUE HMAC-SHA256 digest computation succeeded.\r | |
1049 | @retval FALSE HMAC-SHA256 digest computation failed.\r | |
1050 | @retval FALSE This interface is not supported.\r | |
1051 | \r | |
1052 | **/\r | |
1053 | BOOLEAN\r | |
1054 | EFIAPI\r | |
1055 | HmacSha256Final (\r | |
1056 | IN OUT VOID *HmacSha256Context,\r | |
1057 | OUT UINT8 *HmacValue\r | |
1058 | );\r | |
1059 | \r | |
7bb42e32 QZ |
1060 | /**\r |
1061 | Computes the HMAC-SHA256 digest of a input data buffer.\r | |
1062 | \r | |
1063 | This function performs the HMAC-SHA256 digest of a given data buffer, and places\r | |
1064 | the digest value into the specified memory.\r | |
1065 | \r | |
1066 | If this interface is not supported, then return FALSE.\r | |
1067 | \r | |
1068 | @param[in] Data Pointer to the buffer containing the data to be digested.\r | |
1069 | @param[in] DataSize Size of Data buffer in bytes.\r | |
1070 | @param[in] Key Pointer to the user-supplied key.\r | |
1071 | @param[in] KeySize Key size in bytes.\r | |
1072 | @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA256 digest\r | |
1073 | value (32 bytes).\r | |
1074 | \r | |
1075 | @retval TRUE HMAC-SHA256 digest computation succeeded.\r | |
1076 | @retval FALSE HMAC-SHA256 digest computation failed.\r | |
1077 | @retval FALSE This interface is not supported.\r | |
1078 | \r | |
1079 | **/\r | |
1080 | BOOLEAN\r | |
1081 | EFIAPI\r | |
1082 | HmacSha256All (\r | |
1083 | IN CONST VOID *Data,\r | |
1084 | IN UINTN DataSize,\r | |
1085 | IN CONST UINT8 *Key,\r | |
1086 | IN UINTN KeySize,\r | |
1087 | OUT UINT8 *HmacValue\r | |
1088 | );\r | |
1089 | \r | |
1090 | /**\r | |
1091 | Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.\r | |
1092 | \r | |
1093 | @return Pointer to the HMAC_CTX context that has been initialized.\r | |
1094 | If the allocations fails, HmacSha384New() returns NULL.\r | |
1095 | \r | |
1096 | **/\r | |
1097 | VOID *\r | |
1098 | EFIAPI\r | |
1099 | HmacSha384New (\r | |
1100 | VOID\r | |
1101 | );\r | |
1102 | \r | |
1103 | /**\r | |
1104 | Release the specified HMAC_CTX context.\r | |
1105 | \r | |
1106 | @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be released.\r | |
1107 | \r | |
1108 | **/\r | |
1109 | VOID\r | |
1110 | EFIAPI\r | |
1111 | HmacSha384Free (\r | |
1112 | IN VOID *HmacSha384Ctx\r | |
1113 | );\r | |
1114 | \r | |
1115 | /**\r | |
1116 | Set user-supplied key for subsequent use. It must be done before any\r | |
1117 | calling to HmacSha384Update().\r | |
1118 | \r | |
1119 | If HmacSha384Context is NULL, then return FALSE.\r | |
1120 | If this interface is not supported, then return FALSE.\r | |
1121 | \r | |
1122 | @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.\r | |
1123 | @param[in] Key Pointer to the user-supplied key.\r | |
1124 | @param[in] KeySize Key size in bytes.\r | |
1125 | \r | |
1126 | @retval TRUE The Key is set successfully.\r | |
1127 | @retval FALSE The Key is set unsuccessfully.\r | |
1128 | @retval FALSE This interface is not supported.\r | |
1129 | \r | |
1130 | **/\r | |
1131 | BOOLEAN\r | |
1132 | EFIAPI\r | |
1133 | HmacSha384SetKey (\r | |
1134 | OUT VOID *HmacSha384Context,\r | |
1135 | IN CONST UINT8 *Key,\r | |
1136 | IN UINTN KeySize\r | |
1137 | );\r | |
1138 | \r | |
1139 | /**\r | |
1140 | Makes a copy of an existing HMAC-SHA384 context.\r | |
1141 | \r | |
1142 | If HmacSha384Context is NULL, then return FALSE.\r | |
1143 | If NewHmacSha384Context is NULL, then return FALSE.\r | |
1144 | If this interface is not supported, then return FALSE.\r | |
1145 | \r | |
1146 | @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being copied.\r | |
1147 | @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.\r | |
1148 | \r | |
1149 | @retval TRUE HMAC-SHA384 context copy succeeded.\r | |
1150 | @retval FALSE HMAC-SHA384 context copy failed.\r | |
1151 | @retval FALSE This interface is not supported.\r | |
1152 | \r | |
1153 | **/\r | |
1154 | BOOLEAN\r | |
1155 | EFIAPI\r | |
1156 | HmacSha384Duplicate (\r | |
1157 | IN CONST VOID *HmacSha384Context,\r | |
1158 | OUT VOID *NewHmacSha384Context\r | |
1159 | );\r | |
1160 | \r | |
1161 | /**\r | |
1162 | Digests the input data and updates HMAC-SHA384 context.\r | |
1163 | \r | |
1164 | This function performs HMAC-SHA384 digest on a data buffer of the specified size.\r | |
1165 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
1166 | HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r | |
1167 | by HmacSha384Final(). Behavior with invalid context is undefined.\r | |
1168 | \r | |
1169 | If HmacSha384Context is NULL, then return FALSE.\r | |
1170 | If this interface is not supported, then return FALSE.\r | |
1171 | \r | |
1172 | @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.\r | |
1173 | @param[in] Data Pointer to the buffer containing the data to be digested.\r | |
1174 | @param[in] DataSize Size of Data buffer in bytes.\r | |
1175 | \r | |
1176 | @retval TRUE HMAC-SHA384 data digest succeeded.\r | |
1177 | @retval FALSE HMAC-SHA384 data digest failed.\r | |
1178 | @retval FALSE This interface is not supported.\r | |
1179 | \r | |
1180 | **/\r | |
1181 | BOOLEAN\r | |
1182 | EFIAPI\r | |
1183 | HmacSha384Update (\r | |
1184 | IN OUT VOID *HmacSha384Context,\r | |
1185 | IN CONST VOID *Data,\r | |
1186 | IN UINTN DataSize\r | |
1187 | );\r | |
1188 | \r | |
1189 | /**\r | |
1190 | Completes computation of the HMAC-SHA384 digest value.\r | |
1191 | \r | |
1192 | This function completes HMAC-SHA384 hash computation and retrieves the digest value into\r | |
1193 | the specified memory. After this function has been called, the HMAC-SHA384 context cannot\r | |
1194 | be used again.\r | |
1195 | HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r | |
1196 | by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.\r | |
1197 | \r | |
1198 | If HmacSha384Context is NULL, then return FALSE.\r | |
1199 | If HmacValue is NULL, then return FALSE.\r | |
1200 | If this interface is not supported, then return FALSE.\r | |
1201 | \r | |
1202 | @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.\r | |
1203 | @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest\r | |
1204 | value (48 bytes).\r | |
1205 | \r | |
1206 | @retval TRUE HMAC-SHA384 digest computation succeeded.\r | |
1207 | @retval FALSE HMAC-SHA384 digest computation failed.\r | |
1208 | @retval FALSE This interface is not supported.\r | |
1209 | \r | |
1210 | **/\r | |
1211 | BOOLEAN\r | |
1212 | EFIAPI\r | |
1213 | HmacSha384Final (\r | |
1214 | IN OUT VOID *HmacSha384Context,\r | |
1215 | OUT UINT8 *HmacValue\r | |
1216 | );\r | |
1217 | \r | |
1218 | /**\r | |
1219 | Computes the HMAC-SHA384 digest of a input data buffer.\r | |
1220 | \r | |
1221 | This function performs the HMAC-SHA384 digest of a given data buffer, and places\r | |
1222 | the digest value into the specified memory.\r | |
1223 | \r | |
1224 | If this interface is not supported, then return FALSE.\r | |
1225 | \r | |
1226 | @param[in] Data Pointer to the buffer containing the data to be digested.\r | |
1227 | @param[in] DataSize Size of Data buffer in bytes.\r | |
1228 | @param[in] Key Pointer to the user-supplied key.\r | |
1229 | @param[in] KeySize Key size in bytes.\r | |
1230 | @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA384 digest\r | |
1231 | value (48 bytes).\r | |
1232 | \r | |
1233 | @retval TRUE HMAC-SHA384 digest computation succeeded.\r | |
1234 | @retval FALSE HMAC-SHA384 digest computation failed.\r | |
1235 | @retval FALSE This interface is not supported.\r | |
1236 | \r | |
1237 | **/\r | |
1238 | BOOLEAN\r | |
1239 | EFIAPI\r | |
1240 | HmacSha384All (\r | |
1241 | IN CONST VOID *Data,\r | |
1242 | IN UINTN DataSize,\r | |
1243 | IN CONST UINT8 *Key,\r | |
1244 | IN UINTN KeySize,\r | |
1245 | OUT UINT8 *HmacValue\r | |
1246 | );\r | |
1247 | \r | |
7c342378 | 1248 | // =====================================================================================\r |
97f98500 | 1249 | // Symmetric Cryptography Primitive\r |
7c342378 | 1250 | // =====================================================================================\r |
97f98500 | 1251 | \r |
a8c44645 | 1252 | /**\r |
1253 | Retrieves the size, in bytes, of the context buffer required for AES operations.\r | |
1254 | \r | |
532616bb | 1255 | If this interface is not supported, then return zero.\r |
1256 | \r | |
a8c44645 | 1257 | @return The size, in bytes, of the context buffer required for AES operations.\r |
532616bb | 1258 | @retval 0 This interface is not supported.\r |
a8c44645 | 1259 | \r |
1260 | **/\r | |
1261 | UINTN\r | |
1262 | EFIAPI\r | |
1263 | AesGetContextSize (\r | |
1264 | VOID\r | |
1265 | );\r | |
1266 | \r | |
1267 | /**\r | |
1268 | Initializes user-supplied memory as AES context for subsequent use.\r | |
1269 | \r | |
1270 | This function initializes user-supplied memory pointed by AesContext as AES context.\r | |
6b8ebcb8 | 1271 | In addition, it sets up all AES key materials for subsequent encryption and decryption\r |
a8c44645 | 1272 | operations.\r |
1273 | There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r | |
1274 | \r | |
16d2c32c | 1275 | If AesContext is NULL, then return FALSE.\r |
1276 | If Key is NULL, then return FALSE.\r | |
1277 | If KeyLength is not valid, then return FALSE.\r | |
532616bb | 1278 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1279 | \r |
1280 | @param[out] AesContext Pointer to AES context being initialized.\r | |
1281 | @param[in] Key Pointer to the user-supplied AES key.\r | |
1282 | @param[in] KeyLength Length of AES key in bits.\r | |
1283 | \r | |
1284 | @retval TRUE AES context initialization succeeded.\r | |
1285 | @retval FALSE AES context initialization failed.\r | |
532616bb | 1286 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1287 | \r |
1288 | **/\r | |
1289 | BOOLEAN\r | |
1290 | EFIAPI\r | |
1291 | AesInit (\r | |
1292 | OUT VOID *AesContext,\r | |
1293 | IN CONST UINT8 *Key,\r | |
1294 | IN UINTN KeyLength\r | |
1295 | );\r | |
1296 | \r | |
a8c44645 | 1297 | /**\r |
1298 | Performs AES encryption on a data buffer of the specified size in CBC mode.\r | |
1299 | \r | |
1300 | This function performs AES encryption on data buffer pointed by Input, of specified\r | |
1301 | size of InputSize, in CBC mode.\r | |
1302 | InputSize must be multiple of block size (16 bytes). This function does not perform\r | |
1303 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1304 | Initialization vector should be one block size (16 bytes).\r | |
1305 | AesContext should be already correctly initialized by AesInit(). Behavior with\r | |
1306 | invalid AES context is undefined.\r | |
1307 | \r | |
16d2c32c | 1308 | If AesContext is NULL, then return FALSE.\r |
1309 | If Input is NULL, then return FALSE.\r | |
1310 | If InputSize is not multiple of block size (16 bytes), then return FALSE.\r | |
1311 | If Ivec is NULL, then return FALSE.\r | |
1312 | If Output is NULL, then return FALSE.\r | |
532616bb | 1313 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1314 | \r |
1315 | @param[in] AesContext Pointer to the AES context.\r | |
1316 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1317 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1318 | @param[in] Ivec Pointer to initialization vector.\r | |
1319 | @param[out] Output Pointer to a buffer that receives the AES encryption output.\r | |
1320 | \r | |
1321 | @retval TRUE AES encryption succeeded.\r | |
1322 | @retval FALSE AES encryption failed.\r | |
532616bb | 1323 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1324 | \r |
1325 | **/\r | |
1326 | BOOLEAN\r | |
1327 | EFIAPI\r | |
1328 | AesCbcEncrypt (\r | |
1329 | IN VOID *AesContext,\r | |
1330 | IN CONST UINT8 *Input,\r | |
1331 | IN UINTN InputSize,\r | |
1332 | IN CONST UINT8 *Ivec,\r | |
1333 | OUT UINT8 *Output\r | |
1334 | );\r | |
1335 | \r | |
1336 | /**\r | |
1337 | Performs AES decryption on a data buffer of the specified size in CBC mode.\r | |
1338 | \r | |
1339 | This function performs AES decryption on data buffer pointed by Input, of specified\r | |
1340 | size of InputSize, in CBC mode.\r | |
1341 | InputSize must be multiple of block size (16 bytes). This function does not perform\r | |
1342 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1343 | Initialization vector should be one block size (16 bytes).\r | |
1344 | AesContext should be already correctly initialized by AesInit(). Behavior with\r | |
1345 | invalid AES context is undefined.\r | |
1346 | \r | |
16d2c32c | 1347 | If AesContext is NULL, then return FALSE.\r |
1348 | If Input is NULL, then return FALSE.\r | |
1349 | If InputSize is not multiple of block size (16 bytes), then return FALSE.\r | |
1350 | If Ivec is NULL, then return FALSE.\r | |
1351 | If Output is NULL, then return FALSE.\r | |
532616bb | 1352 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1353 | \r |
1354 | @param[in] AesContext Pointer to the AES context.\r | |
1355 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1356 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1357 | @param[in] Ivec Pointer to initialization vector.\r | |
1358 | @param[out] Output Pointer to a buffer that receives the AES encryption output.\r | |
1359 | \r | |
1360 | @retval TRUE AES decryption succeeded.\r | |
1361 | @retval FALSE AES decryption failed.\r | |
532616bb | 1362 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1363 | \r |
1364 | **/\r | |
1365 | BOOLEAN\r | |
1366 | EFIAPI\r | |
1367 | AesCbcDecrypt (\r | |
1368 | IN VOID *AesContext,\r | |
1369 | IN CONST UINT8 *Input,\r | |
1370 | IN UINTN InputSize,\r | |
1371 | IN CONST UINT8 *Ivec,\r | |
1372 | OUT UINT8 *Output\r | |
1373 | );\r | |
1374 | \r | |
acbc5747 QZ |
1375 | // =====================================================================================\r |
1376 | // Authenticated Encryption with Associated Data (AEAD) Cryptography Primitive\r | |
1377 | // =====================================================================================\r | |
1378 | \r | |
1379 | /**\r | |
1380 | Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).\r | |
1381 | \r | |
1382 | IvSize must be 12, otherwise FALSE is returned.\r | |
1383 | KeySize must be 16, 24 or 32, otherwise FALSE is returned.\r | |
1384 | TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.\r | |
1385 | \r | |
1386 | @param[in] Key Pointer to the encryption key.\r | |
1387 | @param[in] KeySize Size of the encryption key in bytes.\r | |
1388 | @param[in] Iv Pointer to the IV value.\r | |
1389 | @param[in] IvSize Size of the IV value in bytes.\r | |
1390 | @param[in] AData Pointer to the additional authenticated data (AAD).\r | |
1391 | @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.\r | |
1392 | @param[in] DataIn Pointer to the input data buffer to be encrypted.\r | |
1393 | @param[in] DataInSize Size of the input data buffer in bytes.\r | |
1394 | @param[out] TagOut Pointer to a buffer that receives the authentication tag output.\r | |
1395 | @param[in] TagSize Size of the authentication tag in bytes.\r | |
1396 | @param[out] DataOut Pointer to a buffer that receives the encryption output.\r | |
1397 | @param[out] DataOutSize Size of the output data buffer in bytes.\r | |
1398 | \r | |
1399 | @retval TRUE AEAD AES-GCM authenticated encryption succeeded.\r | |
1400 | @retval FALSE AEAD AES-GCM authenticated encryption failed.\r | |
1401 | \r | |
1402 | **/\r | |
1403 | BOOLEAN\r | |
1404 | EFIAPI\r | |
1405 | AeadAesGcmEncrypt (\r | |
1406 | IN CONST UINT8 *Key,\r | |
1407 | IN UINTN KeySize,\r | |
1408 | IN CONST UINT8 *Iv,\r | |
1409 | IN UINTN IvSize,\r | |
1410 | IN CONST UINT8 *AData,\r | |
1411 | IN UINTN ADataSize,\r | |
1412 | IN CONST UINT8 *DataIn,\r | |
1413 | IN UINTN DataInSize,\r | |
1414 | OUT UINT8 *TagOut,\r | |
1415 | IN UINTN TagSize,\r | |
1416 | OUT UINT8 *DataOut,\r | |
1417 | OUT UINTN *DataOutSize\r | |
1418 | );\r | |
1419 | \r | |
1420 | /**\r | |
1421 | Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).\r | |
1422 | \r | |
1423 | IvSize must be 12, otherwise FALSE is returned.\r | |
1424 | KeySize must be 16, 24 or 32, otherwise FALSE is returned.\r | |
1425 | TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.\r | |
1426 | If additional authenticated data verification fails, FALSE is returned.\r | |
1427 | \r | |
1428 | @param[in] Key Pointer to the encryption key.\r | |
1429 | @param[in] KeySize Size of the encryption key in bytes.\r | |
1430 | @param[in] Iv Pointer to the IV value.\r | |
1431 | @param[in] IvSize Size of the IV value in bytes.\r | |
1432 | @param[in] AData Pointer to the additional authenticated data (AAD).\r | |
1433 | @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.\r | |
1434 | @param[in] DataIn Pointer to the input data buffer to be decrypted.\r | |
1435 | @param[in] DataInSize Size of the input data buffer in bytes.\r | |
1436 | @param[in] Tag Pointer to a buffer that contains the authentication tag.\r | |
1437 | @param[in] TagSize Size of the authentication tag in bytes.\r | |
1438 | @param[out] DataOut Pointer to a buffer that receives the decryption output.\r | |
1439 | @param[out] DataOutSize Size of the output data buffer in bytes.\r | |
1440 | \r | |
1441 | @retval TRUE AEAD AES-GCM authenticated decryption succeeded.\r | |
1442 | @retval FALSE AEAD AES-GCM authenticated decryption failed.\r | |
1443 | \r | |
1444 | **/\r | |
1445 | BOOLEAN\r | |
1446 | EFIAPI\r | |
1447 | AeadAesGcmDecrypt (\r | |
1448 | IN CONST UINT8 *Key,\r | |
1449 | IN UINTN KeySize,\r | |
1450 | IN CONST UINT8 *Iv,\r | |
1451 | IN UINTN IvSize,\r | |
1452 | IN CONST UINT8 *AData,\r | |
1453 | IN UINTN ADataSize,\r | |
1454 | IN CONST UINT8 *DataIn,\r | |
1455 | IN UINTN DataInSize,\r | |
1456 | IN CONST UINT8 *Tag,\r | |
1457 | IN UINTN TagSize,\r | |
1458 | OUT UINT8 *DataOut,\r | |
1459 | OUT UINTN *DataOutSize\r | |
1460 | );\r | |
1461 | \r | |
7c342378 | 1462 | // =====================================================================================\r |
97f98500 | 1463 | // Asymmetric Cryptography Primitive\r |
7c342378 | 1464 | // =====================================================================================\r |
97f98500 HT |
1465 | \r |
1466 | /**\r | |
a8c44645 | 1467 | Allocates and initializes one RSA context for subsequent use.\r |
97f98500 | 1468 | \r |
a8c44645 | 1469 | @return Pointer to the RSA context that has been initialized.\r |
97f98500 HT |
1470 | If the allocations fails, RsaNew() returns NULL.\r |
1471 | \r | |
1472 | **/\r | |
1473 | VOID *\r | |
1474 | EFIAPI\r | |
1475 | RsaNew (\r | |
1476 | VOID\r | |
1477 | );\r | |
1478 | \r | |
97f98500 | 1479 | /**\r |
a8c44645 | 1480 | Release the specified RSA context.\r |
1481 | \r | |
16d2c32c | 1482 | If RsaContext is NULL, then return FALSE.\r |
97f98500 HT |
1483 | \r |
1484 | @param[in] RsaContext Pointer to the RSA context to be released.\r | |
1485 | \r | |
1486 | **/\r | |
1487 | VOID\r | |
1488 | EFIAPI\r | |
1489 | RsaFree (\r | |
1490 | IN VOID *RsaContext\r | |
1491 | );\r | |
1492 | \r | |
97f98500 | 1493 | /**\r |
a8c44645 | 1494 | Sets the tag-designated key component into the established RSA context.\r |
1495 | \r | |
1496 | This function sets the tag-designated RSA key component into the established\r | |
1497 | RSA context from the user-specified non-negative integer (octet string format\r | |
1498 | represented in RSA PKCS#1).\r | |
2998af86 | 1499 | If BigNumber is NULL, then the specified key component in RSA context is cleared.\r |
97f98500 | 1500 | \r |
16d2c32c | 1501 | If RsaContext is NULL, then return FALSE.\r |
97f98500 HT |
1502 | \r |
1503 | @param[in, out] RsaContext Pointer to RSA context being set.\r | |
1504 | @param[in] KeyTag Tag of RSA key component being set.\r | |
1505 | @param[in] BigNumber Pointer to octet integer buffer.\r | |
2998af86 | 1506 | If NULL, then the specified key component in RSA\r |
a8c44645 | 1507 | context is cleared.\r |
1508 | @param[in] BnSize Size of big number buffer in bytes.\r | |
1509 | If BigNumber is NULL, then it is ignored.\r | |
97f98500 | 1510 | \r |
a8c44645 | 1511 | @retval TRUE RSA key component was set successfully.\r |
1512 | @retval FALSE Invalid RSA key component tag.\r | |
97f98500 HT |
1513 | \r |
1514 | **/\r | |
1515 | BOOLEAN\r | |
1516 | EFIAPI\r | |
1517 | RsaSetKey (\r | |
a8c44645 | 1518 | IN OUT VOID *RsaContext,\r |
1519 | IN RSA_KEY_TAG KeyTag,\r | |
1520 | IN CONST UINT8 *BigNumber,\r | |
1521 | IN UINTN BnSize\r | |
1522 | );\r | |
1523 | \r | |
1524 | /**\r | |
1525 | Gets the tag-designated RSA key component from the established RSA context.\r | |
1526 | \r | |
1527 | This function retrieves the tag-designated RSA key component from the\r | |
1528 | established RSA context as a non-negative integer (octet string format\r | |
1529 | represented in RSA PKCS#1).\r | |
1530 | If specified key component has not been set or has been cleared, then returned\r | |
1531 | BnSize is set to 0.\r | |
1532 | If the BigNumber buffer is too small to hold the contents of the key, FALSE\r | |
1533 | is returned and BnSize is set to the required buffer size to obtain the key.\r | |
1534 | \r | |
16d2c32c | 1535 | If RsaContext is NULL, then return FALSE.\r |
1536 | If BnSize is NULL, then return FALSE.\r | |
1537 | If BnSize is large enough but BigNumber is NULL, then return FALSE.\r | |
532616bb | 1538 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1539 | \r |
1540 | @param[in, out] RsaContext Pointer to RSA context being set.\r | |
1541 | @param[in] KeyTag Tag of RSA key component being set.\r | |
1542 | @param[out] BigNumber Pointer to octet integer buffer.\r | |
1543 | @param[in, out] BnSize On input, the size of big number buffer in bytes.\r | |
1544 | On output, the size of data returned in big number buffer in bytes.\r | |
1545 | \r | |
1546 | @retval TRUE RSA key component was retrieved successfully.\r | |
1547 | @retval FALSE Invalid RSA key component tag.\r | |
1548 | @retval FALSE BnSize is too small.\r | |
532616bb | 1549 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1550 | \r |
1551 | **/\r | |
1552 | BOOLEAN\r | |
1553 | EFIAPI\r | |
1554 | RsaGetKey (\r | |
1555 | IN OUT VOID *RsaContext,\r | |
1556 | IN RSA_KEY_TAG KeyTag,\r | |
1557 | OUT UINT8 *BigNumber,\r | |
1558 | IN OUT UINTN *BnSize\r | |
1559 | );\r | |
1560 | \r | |
1561 | /**\r | |
1562 | Generates RSA key components.\r | |
1563 | \r | |
1564 | This function generates RSA key components. It takes RSA public exponent E and\r | |
1565 | length in bits of RSA modulus N as input, and generates all key components.\r | |
1566 | If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r | |
1567 | \r | |
1568 | Before this function can be invoked, pseudorandom number generator must be correctly\r | |
1569 | initialized by RandomSeed().\r | |
1570 | \r | |
16d2c32c | 1571 | If RsaContext is NULL, then return FALSE.\r |
532616bb | 1572 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1573 | \r |
1574 | @param[in, out] RsaContext Pointer to RSA context being set.\r | |
1575 | @param[in] ModulusLength Length of RSA modulus N in bits.\r | |
1576 | @param[in] PublicExponent Pointer to RSA public exponent.\r | |
2ac68e8b | 1577 | @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r |
a8c44645 | 1578 | \r |
1579 | @retval TRUE RSA key component was generated successfully.\r | |
1580 | @retval FALSE Invalid RSA key component tag.\r | |
532616bb | 1581 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1582 | \r |
1583 | **/\r | |
1584 | BOOLEAN\r | |
1585 | EFIAPI\r | |
1586 | RsaGenerateKey (\r | |
1587 | IN OUT VOID *RsaContext,\r | |
1588 | IN UINTN ModulusLength,\r | |
1589 | IN CONST UINT8 *PublicExponent,\r | |
1590 | IN UINTN PublicExponentSize\r | |
1591 | );\r | |
1592 | \r | |
1593 | /**\r | |
1594 | Validates key components of RSA context.\r | |
952bd229 QL |
1595 | NOTE: This function performs integrity checks on all the RSA key material, so\r |
1596 | the RSA key structure must contain all the private key data.\r | |
a8c44645 | 1597 | \r |
2998af86 | 1598 | This function validates key components of RSA context in following aspects:\r |
a8c44645 | 1599 | - Whether p is a prime\r |
1600 | - Whether q is a prime\r | |
1601 | - Whether n = p * q\r | |
1602 | - Whether d*e = 1 mod lcm(p-1,q-1)\r | |
1603 | \r | |
16d2c32c | 1604 | If RsaContext is NULL, then return FALSE.\r |
532616bb | 1605 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1606 | \r |
1607 | @param[in] RsaContext Pointer to RSA context to check.\r | |
1608 | \r | |
1609 | @retval TRUE RSA key components are valid.\r | |
1610 | @retval FALSE RSA key components are not valid.\r | |
532616bb | 1611 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1612 | \r |
1613 | **/\r | |
1614 | BOOLEAN\r | |
1615 | EFIAPI\r | |
1616 | RsaCheckKey (\r | |
1617 | IN VOID *RsaContext\r | |
97f98500 HT |
1618 | );\r |
1619 | \r | |
a8c44645 | 1620 | /**\r |
1621 | Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r | |
1622 | \r | |
1623 | This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r | |
1624 | RSA PKCS#1.\r | |
1625 | If the Signature buffer is too small to hold the contents of signature, FALSE\r | |
1626 | is returned and SigSize is set to the required buffer size to obtain the signature.\r | |
1627 | \r | |
16d2c32c | 1628 | If RsaContext is NULL, then return FALSE.\r |
1629 | If MessageHash is NULL, then return FALSE.\r | |
1630 | If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r | |
1631 | If SigSize is large enough but Signature is NULL, then return FALSE.\r | |
532616bb | 1632 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1633 | \r |
1634 | @param[in] RsaContext Pointer to RSA context for signature generation.\r | |
1635 | @param[in] MessageHash Pointer to octet message hash to be signed.\r | |
1636 | @param[in] HashSize Size of the message hash in bytes.\r | |
1637 | @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r | |
1638 | @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r | |
b7d320f8 | 1639 | On output, the size of data returned in Signature buffer in bytes.\r |
a8c44645 | 1640 | \r |
1641 | @retval TRUE Signature successfully generated in PKCS1-v1_5.\r | |
1642 | @retval FALSE Signature generation failed.\r | |
1643 | @retval FALSE SigSize is too small.\r | |
532616bb | 1644 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1645 | \r |
1646 | **/\r | |
1647 | BOOLEAN\r | |
1648 | EFIAPI\r | |
1649 | RsaPkcs1Sign (\r | |
1650 | IN VOID *RsaContext,\r | |
1651 | IN CONST UINT8 *MessageHash,\r | |
1652 | IN UINTN HashSize,\r | |
1653 | OUT UINT8 *Signature,\r | |
1654 | IN OUT UINTN *SigSize\r | |
1655 | );\r | |
97f98500 HT |
1656 | \r |
1657 | /**\r | |
1658 | Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r | |
1659 | RSA PKCS#1.\r | |
1660 | \r | |
16d2c32c | 1661 | If RsaContext is NULL, then return FALSE.\r |
1662 | If MessageHash is NULL, then return FALSE.\r | |
1663 | If Signature is NULL, then return FALSE.\r | |
1664 | If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r | |
97f98500 HT |
1665 | \r |
1666 | @param[in] RsaContext Pointer to RSA context for signature verification.\r | |
1667 | @param[in] MessageHash Pointer to octet message hash to be checked.\r | |
a8c44645 | 1668 | @param[in] HashSize Size of the message hash in bytes.\r |
97f98500 | 1669 | @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r |
a8c44645 | 1670 | @param[in] SigSize Size of signature in bytes.\r |
97f98500 | 1671 | \r |
a8c44645 | 1672 | @retval TRUE Valid signature encoded in PKCS1-v1_5.\r |
1673 | @retval FALSE Invalid signature or invalid RSA context.\r | |
97f98500 HT |
1674 | \r |
1675 | **/\r | |
1676 | BOOLEAN\r | |
1677 | EFIAPI\r | |
1678 | RsaPkcs1Verify (\r | |
1679 | IN VOID *RsaContext,\r | |
1680 | IN CONST UINT8 *MessageHash,\r | |
a8c44645 | 1681 | IN UINTN HashSize,\r |
8c5720b4 | 1682 | IN CONST UINT8 *Signature,\r |
a8c44645 | 1683 | IN UINTN SigSize\r |
97f98500 HT |
1684 | );\r |
1685 | \r | |
22ac5cc9 SA |
1686 | /**\r |
1687 | Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme.\r | |
1688 | \r | |
1689 | This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in\r | |
1690 | RFC 8017.\r | |
1691 | Mask generation function is the same as the message digest algorithm.\r | |
1692 | If the Signature buffer is too small to hold the contents of signature, FALSE\r | |
1693 | is returned and SigSize is set to the required buffer size to obtain the signature.\r | |
1694 | \r | |
1695 | If RsaContext is NULL, then return FALSE.\r | |
1696 | If Message is NULL, then return FALSE.\r | |
1697 | If MsgSize is zero or > INT_MAX, then return FALSE.\r | |
1698 | If DigestLen is NOT 32, 48 or 64, return FALSE.\r | |
20ca5288 | 1699 | If SaltLen is not equal to DigestLen, then return FALSE.\r |
22ac5cc9 SA |
1700 | If SigSize is large enough but Signature is NULL, then return FALSE.\r |
1701 | If this interface is not supported, then return FALSE.\r | |
1702 | \r | |
1703 | @param[in] RsaContext Pointer to RSA context for signature generation.\r | |
1704 | @param[in] Message Pointer to octet message to be signed.\r | |
1705 | @param[in] MsgSize Size of the message in bytes.\r | |
1706 | @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.\r | |
1707 | @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.\r | |
1708 | @param[out] Signature Pointer to buffer to receive RSA PSS signature.\r | |
1709 | @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r | |
1710 | On output, the size of data returned in Signature buffer in bytes.\r | |
1711 | \r | |
1712 | @retval TRUE Signature successfully generated in RSASSA-PSS.\r | |
1713 | @retval FALSE Signature generation failed.\r | |
1714 | @retval FALSE SigSize is too small.\r | |
1715 | @retval FALSE This interface is not supported.\r | |
1716 | \r | |
1717 | **/\r | |
1718 | BOOLEAN\r | |
1719 | EFIAPI\r | |
1720 | RsaPssSign (\r | |
1721 | IN VOID *RsaContext,\r | |
1722 | IN CONST UINT8 *Message,\r | |
1723 | IN UINTN MsgSize,\r | |
1724 | IN UINT16 DigestLen,\r | |
1725 | IN UINT16 SaltLen,\r | |
1726 | OUT UINT8 *Signature,\r | |
1727 | IN OUT UINTN *SigSize\r | |
1728 | );\r | |
1729 | \r | |
1730 | /**\r | |
1731 | Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.\r | |
1732 | Implementation determines salt length automatically from the signature encoding.\r | |
1733 | Mask generation function is the same as the message digest algorithm.\r | |
20ca5288 | 1734 | Salt length should be equal to digest length.\r |
22ac5cc9 SA |
1735 | \r |
1736 | @param[in] RsaContext Pointer to RSA context for signature verification.\r | |
1737 | @param[in] Message Pointer to octet message to be verified.\r | |
1738 | @param[in] MsgSize Size of the message in bytes.\r | |
1739 | @param[in] Signature Pointer to RSASSA-PSS signature to be verified.\r | |
1740 | @param[in] SigSize Size of signature in bytes.\r | |
1741 | @param[in] DigestLen Length of digest for RSA operation.\r | |
1742 | @param[in] SaltLen Salt length for PSS encoding.\r | |
1743 | \r | |
1744 | @retval TRUE Valid signature encoded in RSASSA-PSS.\r | |
1745 | @retval FALSE Invalid signature or invalid RSA context.\r | |
1746 | \r | |
1747 | **/\r | |
1748 | BOOLEAN\r | |
1749 | EFIAPI\r | |
1750 | RsaPssVerify (\r | |
1751 | IN VOID *RsaContext,\r | |
1752 | IN CONST UINT8 *Message,\r | |
1753 | IN UINTN MsgSize,\r | |
1754 | IN CONST UINT8 *Signature,\r | |
1755 | IN UINTN SigSize,\r | |
1756 | IN UINT16 DigestLen,\r | |
1757 | IN UINT16 SaltLen\r | |
1758 | );\r | |
1759 | \r | |
4a567c96 | 1760 | /**\r |
1761 | Retrieve the RSA Private Key from the password-protected PEM key data.\r | |
1762 | \r | |
532616bb | 1763 | If PemData is NULL, then return FALSE.\r |
1764 | If RsaContext is NULL, then return FALSE.\r | |
1765 | If this interface is not supported, then return FALSE.\r | |
1766 | \r | |
4a567c96 | 1767 | @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r |
1768 | @param[in] PemSize Size of the PEM key data in bytes.\r | |
1769 | @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r | |
1770 | @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r | |
1771 | RSA private key component. Use RsaFree() function to free the\r | |
1772 | resource.\r | |
1773 | \r | |
4a567c96 | 1774 | @retval TRUE RSA Private Key was retrieved successfully.\r |
1775 | @retval FALSE Invalid PEM key data or incorrect password.\r | |
532616bb | 1776 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1777 | \r |
1778 | **/\r | |
1779 | BOOLEAN\r | |
1780 | EFIAPI\r | |
1781 | RsaGetPrivateKeyFromPem (\r | |
1782 | IN CONST UINT8 *PemData,\r | |
1783 | IN UINTN PemSize,\r | |
1784 | IN CONST CHAR8 *Password,\r | |
1785 | OUT VOID **RsaContext\r | |
1786 | );\r | |
1787 | \r | |
1788 | /**\r | |
1789 | Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r | |
1790 | \r | |
532616bb | 1791 | If Cert is NULL, then return FALSE.\r |
1792 | If RsaContext is NULL, then return FALSE.\r | |
1793 | If this interface is not supported, then return FALSE.\r | |
1794 | \r | |
4a567c96 | 1795 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r |
1796 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1797 | @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r | |
1798 | RSA public key component. Use RsaFree() function to free the\r | |
1799 | resource.\r | |
1800 | \r | |
4a567c96 | 1801 | @retval TRUE RSA Public Key was retrieved successfully.\r |
1802 | @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r | |
532616bb | 1803 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1804 | \r |
1805 | **/\r | |
1806 | BOOLEAN\r | |
1807 | EFIAPI\r | |
1808 | RsaGetPublicKeyFromX509 (\r | |
1809 | IN CONST UINT8 *Cert,\r | |
1810 | IN UINTN CertSize,\r | |
1811 | OUT VOID **RsaContext\r | |
1812 | );\r | |
1813 | \r | |
1814 | /**\r | |
1815 | Retrieve the subject bytes from one X.509 certificate.\r | |
1816 | \r | |
532616bb | 1817 | If Cert is NULL, then return FALSE.\r |
1818 | If SubjectSize is NULL, then return FALSE.\r | |
1819 | If this interface is not supported, then return FALSE.\r | |
1820 | \r | |
4a567c96 | 1821 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r |
1822 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1823 | @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r | |
1824 | @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r | |
1825 | and the size of buffer returned CertSubject on output.\r | |
1826 | \r | |
4a567c96 | 1827 | @retval TRUE The certificate subject retrieved successfully.\r |
1828 | @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r | |
1829 | The SubjectSize will be updated with the required size.\r | |
532616bb | 1830 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1831 | \r |
1832 | **/\r | |
1833 | BOOLEAN\r | |
1834 | EFIAPI\r | |
1835 | X509GetSubjectName (\r | |
1836 | IN CONST UINT8 *Cert,\r | |
1837 | IN UINTN CertSize,\r | |
1838 | OUT UINT8 *CertSubject,\r | |
1839 | IN OUT UINTN *SubjectSize\r | |
1840 | );\r | |
1841 | \r | |
5b7c2245 QL |
1842 | /**\r |
1843 | Retrieve the common name (CN) string from one X.509 certificate.\r | |
1844 | \r | |
1845 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
1846 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1847 | @param[out] CommonName Buffer to contain the retrieved certificate common\r | |
0b6457ef | 1848 | name string (UTF8). At most CommonNameSize bytes will be\r |
5b7c2245 QL |
1849 | written and the string will be null terminated. May be\r |
1850 | NULL in order to determine the size buffer needed.\r | |
1851 | @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r | |
1852 | and the size of buffer returned CommonName on output.\r | |
1853 | If CommonName is NULL then the amount of space needed\r | |
1854 | in buffer (including the final null) is returned.\r | |
1855 | \r | |
1856 | @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r | |
1857 | @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r | |
1858 | If CommonNameSize is NULL.\r | |
1859 | If CommonName is not NULL and *CommonNameSize is 0.\r | |
1860 | If Certificate is invalid.\r | |
1861 | @retval RETURN_NOT_FOUND If no CommonName entry exists.\r | |
1862 | @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r | |
630f67dd | 1863 | (including the final null) is returned in the\r |
5b7c2245 QL |
1864 | CommonNameSize parameter.\r |
1865 | @retval RETURN_UNSUPPORTED The operation is not supported.\r | |
1866 | \r | |
1867 | **/\r | |
1868 | RETURN_STATUS\r | |
1869 | EFIAPI\r | |
1870 | X509GetCommonName (\r | |
1871 | IN CONST UINT8 *Cert,\r | |
1872 | IN UINTN CertSize,\r | |
c8f46130 | 1873 | OUT CHAR8 *CommonName OPTIONAL,\r |
5b7c2245 QL |
1874 | IN OUT UINTN *CommonNameSize\r |
1875 | );\r | |
1876 | \r | |
e2a673b8 BB |
1877 | /**\r |
1878 | Retrieve the organization name (O) string from one X.509 certificate.\r | |
1879 | \r | |
1880 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
1881 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1882 | @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r | |
1883 | name string. At most NameBufferSize bytes will be\r | |
1884 | written and the string will be null terminated. May be\r | |
1885 | NULL in order to determine the size buffer needed.\r | |
1886 | @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r | |
1887 | and the size of buffer returned Name on output.\r | |
1888 | If NameBuffer is NULL then the amount of space needed\r | |
1889 | in buffer (including the final null) is returned.\r | |
1890 | \r | |
1891 | @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r | |
1892 | @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r | |
1893 | If NameBufferSize is NULL.\r | |
1894 | If NameBuffer is not NULL and *CommonNameSize is 0.\r | |
1895 | If Certificate is invalid.\r | |
1896 | @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r | |
1897 | @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r | |
1898 | (including the final null) is returned in the\r | |
1899 | CommonNameSize parameter.\r | |
1900 | @retval RETURN_UNSUPPORTED The operation is not supported.\r | |
1901 | \r | |
1902 | **/\r | |
1903 | RETURN_STATUS\r | |
1904 | EFIAPI\r | |
1905 | X509GetOrganizationName (\r | |
7c342378 MK |
1906 | IN CONST UINT8 *Cert,\r |
1907 | IN UINTN CertSize,\r | |
1908 | OUT CHAR8 *NameBuffer OPTIONAL,\r | |
1909 | IN OUT UINTN *NameBufferSize\r | |
e2a673b8 BB |
1910 | );\r |
1911 | \r | |
4a567c96 | 1912 | /**\r |
1913 | Verify one X509 certificate was issued by the trusted CA.\r | |
1914 | \r | |
532616bb | 1915 | If Cert is NULL, then return FALSE.\r |
1916 | If CACert is NULL, then return FALSE.\r | |
1917 | If this interface is not supported, then return FALSE.\r | |
1918 | \r | |
4a567c96 | 1919 | @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r |
1920 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1921 | @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r | |
1922 | @param[in] CACertSize Size of the CA Certificate in bytes.\r | |
1923 | \r | |
4a567c96 | 1924 | @retval TRUE The certificate was issued by the trusted CA.\r |
1925 | @retval FALSE Invalid certificate or the certificate was not issued by the given\r | |
1926 | trusted CA.\r | |
532616bb | 1927 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1928 | \r |
1929 | **/\r | |
1930 | BOOLEAN\r | |
1931 | EFIAPI\r | |
1932 | X509VerifyCert (\r | |
1933 | IN CONST UINT8 *Cert,\r | |
1934 | IN UINTN CertSize,\r | |
1935 | IN CONST UINT8 *CACert,\r | |
1936 | IN UINTN CACertSize\r | |
1937 | );\r | |
1938 | \r | |
b7d320f8 | 1939 | /**\r |
1940 | Construct a X509 object from DER-encoded certificate data.\r | |
1941 | \r | |
16d2c32c | 1942 | If Cert is NULL, then return FALSE.\r |
1943 | If SingleX509Cert is NULL, then return FALSE.\r | |
532616bb | 1944 | If this interface is not supported, then return FALSE.\r |
b7d320f8 | 1945 | \r |
1946 | @param[in] Cert Pointer to the DER-encoded certificate data.\r | |
1947 | @param[in] CertSize The size of certificate data in bytes.\r | |
1948 | @param[out] SingleX509Cert The generated X509 object.\r | |
1949 | \r | |
1950 | @retval TRUE The X509 object generation succeeded.\r | |
1951 | @retval FALSE The operation failed.\r | |
532616bb | 1952 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 1953 | \r |
1954 | **/\r | |
1955 | BOOLEAN\r | |
1956 | EFIAPI\r | |
1957 | X509ConstructCertificate (\r | |
1958 | IN CONST UINT8 *Cert,\r | |
1959 | IN UINTN CertSize,\r | |
1960 | OUT UINT8 **SingleX509Cert\r | |
1961 | );\r | |
1962 | \r | |
66862136 MK |
1963 | /**\r |
1964 | Construct a X509 stack object from a list of DER-encoded certificate data.\r | |
1965 | \r | |
1966 | If X509Stack is NULL, then return FALSE.\r | |
1967 | If this interface is not supported, then return FALSE.\r | |
1968 | \r | |
1969 | @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r | |
1970 | On output, pointer to the X509 stack object with new\r | |
1971 | inserted X509 certificate.\r | |
1972 | @param[in] Args VA_LIST marker for the variable argument list.\r | |
1973 | A list of DER-encoded single certificate data followed\r | |
1974 | by certificate size. A NULL terminates the list. The\r | |
1975 | pairs are the arguments to X509ConstructCertificate().\r | |
1976 | \r | |
1977 | @retval TRUE The X509 stack construction succeeded.\r | |
1978 | @retval FALSE The construction operation failed.\r | |
1979 | @retval FALSE This interface is not supported.\r | |
1980 | \r | |
1981 | **/\r | |
1982 | BOOLEAN\r | |
1983 | EFIAPI\r | |
1984 | X509ConstructCertificateStackV (\r | |
1985 | IN OUT UINT8 **X509Stack,\r | |
1986 | IN VA_LIST Args\r | |
1987 | );\r | |
1988 | \r | |
b7d320f8 | 1989 | /**\r |
1990 | Construct a X509 stack object from a list of DER-encoded certificate data.\r | |
1991 | \r | |
16d2c32c | 1992 | If X509Stack is NULL, then return FALSE.\r |
532616bb | 1993 | If this interface is not supported, then return FALSE.\r |
b7d320f8 | 1994 | \r |
952bd229 | 1995 | @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r |
b7d320f8 | 1996 | On output, pointer to the X509 stack object with new\r |
1997 | inserted X509 certificate.\r | |
1998 | @param ... A list of DER-encoded single certificate data followed\r | |
1999 | by certificate size. A NULL terminates the list. The\r | |
2000 | pairs are the arguments to X509ConstructCertificate().\r | |
2ac68e8b | 2001 | \r |
b7d320f8 | 2002 | @retval TRUE The X509 stack construction succeeded.\r |
2003 | @retval FALSE The construction operation failed.\r | |
532616bb | 2004 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 2005 | \r |
2006 | **/\r | |
2007 | BOOLEAN\r | |
2008 | EFIAPI\r | |
2009 | X509ConstructCertificateStack (\r | |
2010 | IN OUT UINT8 **X509Stack,\r | |
2ac68e8b | 2011 | ...\r |
b7d320f8 | 2012 | );\r |
2013 | \r | |
2014 | /**\r | |
2015 | Release the specified X509 object.\r | |
2016 | \r | |
532616bb | 2017 | If the interface is not supported, then ASSERT().\r |
b7d320f8 | 2018 | \r |
2019 | @param[in] X509Cert Pointer to the X509 object to be released.\r | |
2020 | \r | |
2021 | **/\r | |
2022 | VOID\r | |
2023 | EFIAPI\r | |
2024 | X509Free (\r | |
2025 | IN VOID *X509Cert\r | |
2026 | );\r | |
2027 | \r | |
2028 | /**\r | |
2029 | Release the specified X509 stack object.\r | |
2030 | \r | |
532616bb | 2031 | If the interface is not supported, then ASSERT().\r |
b7d320f8 | 2032 | \r |
2033 | @param[in] X509Stack Pointer to the X509 stack object to be released.\r | |
2034 | \r | |
2035 | **/\r | |
2036 | VOID\r | |
2037 | EFIAPI\r | |
2038 | X509StackFree (\r | |
2039 | IN VOID *X509Stack\r | |
2040 | );\r | |
2041 | \r | |
12d95665 LQ |
2042 | /**\r |
2043 | Retrieve the TBSCertificate from one given X.509 certificate.\r | |
2044 | \r | |
2045 | @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r | |
2046 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
2047 | @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r | |
2048 | @param[out] TBSCertSize Size of the TBS certificate in bytes.\r | |
2049 | \r | |
2050 | If Cert is NULL, then return FALSE.\r | |
2051 | If TBSCert is NULL, then return FALSE.\r | |
2052 | If TBSCertSize is NULL, then return FALSE.\r | |
2053 | If this interface is not supported, then return FALSE.\r | |
2054 | \r | |
2055 | @retval TRUE The TBSCertificate was retrieved successfully.\r | |
2056 | @retval FALSE Invalid X.509 certificate.\r | |
2057 | \r | |
2058 | **/\r | |
2059 | BOOLEAN\r | |
2060 | EFIAPI\r | |
2061 | X509GetTBSCert (\r | |
2062 | IN CONST UINT8 *Cert,\r | |
2063 | IN UINTN CertSize,\r | |
2064 | OUT UINT8 **TBSCert,\r | |
2065 | OUT UINTN *TBSCertSize\r | |
2066 | );\r | |
2067 | \r | |
a8f37449 QL |
2068 | /**\r |
2069 | Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r | |
2070 | password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r | |
2071 | \r | |
2072 | If Password or Salt or OutKey is NULL, then return FALSE.\r | |
2073 | If the hash algorithm could not be determined, then return FALSE.\r | |
2074 | If this interface is not supported, then return FALSE.\r | |
2075 | \r | |
2076 | @param[in] PasswordLength Length of input password in bytes.\r | |
2077 | @param[in] Password Pointer to the array for the password.\r | |
2078 | @param[in] SaltLength Size of the Salt in bytes.\r | |
2079 | @param[in] Salt Pointer to the Salt.\r | |
2080 | @param[in] IterationCount Number of iterations to perform. Its value should be\r | |
2081 | greater than or equal to 1.\r | |
2082 | @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r | |
2083 | NOTE: DigestSize will be used to determine the hash algorithm.\r | |
2084 | Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r | |
2085 | @param[in] KeyLength Size of the derived key buffer in bytes.\r | |
2086 | @param[out] OutKey Pointer to the output derived key buffer.\r | |
2087 | \r | |
2088 | @retval TRUE A key was derived successfully.\r | |
2089 | @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r | |
2090 | @retval FALSE The hash algorithm could not be determined from the digest size.\r | |
2091 | @retval FALSE The key derivation operation failed.\r | |
2092 | @retval FALSE This interface is not supported.\r | |
2093 | \r | |
2094 | **/\r | |
2095 | BOOLEAN\r | |
2096 | EFIAPI\r | |
2097 | Pkcs5HashPassword (\r | |
2098 | IN UINTN PasswordLength,\r | |
2099 | IN CONST CHAR8 *Password,\r | |
2100 | IN UINTN SaltLength,\r | |
2101 | IN CONST UINT8 *Salt,\r | |
2102 | IN UINTN IterationCount,\r | |
2103 | IN UINTN DigestSize,\r | |
2104 | IN UINTN KeyLength,\r | |
2105 | OUT UINT8 *OutKey\r | |
2106 | );\r | |
2107 | \r | |
aed90bee BB |
2108 | /**\r |
2109 | Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r | |
2110 | encrypted message in a newly allocated buffer.\r | |
2111 | \r | |
2112 | Things that can cause a failure include:\r | |
2113 | - X509 key size does not match any known key size.\r | |
2114 | - Fail to parse X509 certificate.\r | |
2115 | - Fail to allocate an intermediate buffer.\r | |
2116 | - Null pointer provided for a non-optional parameter.\r | |
2117 | - Data size is too large for the provided key size (max size is a function of key size\r | |
2118 | and hash digest size).\r | |
2119 | \r | |
2120 | @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r | |
2121 | will be used to encrypt the data.\r | |
2122 | @param[in] PublicKeySize Size of the X509 cert buffer.\r | |
2123 | @param[in] InData Data to be encrypted.\r | |
2124 | @param[in] InDataSize Size of the data buffer.\r | |
2125 | @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r | |
2126 | to be used when initializing the PRNG. NULL otherwise.\r | |
2127 | @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r | |
2128 | 0 otherwise.\r | |
2129 | @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r | |
2130 | message.\r | |
2131 | @param[out] EncryptedDataSize Size of the encrypted message buffer.\r | |
2132 | \r | |
2133 | @retval TRUE Encryption was successful.\r | |
2134 | @retval FALSE Encryption failed.\r | |
2135 | \r | |
2136 | **/\r | |
2137 | BOOLEAN\r | |
2138 | EFIAPI\r | |
2139 | Pkcs1v2Encrypt (\r | |
2140 | IN CONST UINT8 *PublicKey,\r | |
2141 | IN UINTN PublicKeySize,\r | |
2142 | IN UINT8 *InData,\r | |
2143 | IN UINTN InDataSize,\r | |
c8f46130 MK |
2144 | IN CONST UINT8 *PrngSeed OPTIONAL,\r |
2145 | IN UINTN PrngSeedSize OPTIONAL,\r | |
aed90bee BB |
2146 | OUT UINT8 **EncryptedData,\r |
2147 | OUT UINTN *EncryptedDataSize\r | |
2148 | );\r | |
2149 | \r | |
3702637a | 2150 | /**\r |
2151 | The 3rd parameter of Pkcs7GetSigners will return all embedded\r | |
2152 | X.509 certificate in one given PKCS7 signature. The format is:\r | |
2153 | //\r | |
2154 | // UINT8 CertNumber;\r | |
2155 | // UINT32 Cert1Length;\r | |
2156 | // UINT8 Cert1[];\r | |
2157 | // UINT32 Cert2Length;\r | |
2158 | // UINT8 Cert2[];\r | |
2159 | // ...\r | |
2160 | // UINT32 CertnLength;\r | |
2161 | // UINT8 Certn[];\r | |
2162 | //\r | |
2163 | \r | |
2164 | The two following C-structure are used for parsing CertStack more clearly.\r | |
2165 | **/\r | |
2166 | #pragma pack(1)\r | |
2167 | \r | |
2168 | typedef struct {\r | |
2169 | UINT32 CertDataLength; // The length in bytes of X.509 certificate.\r | |
2170 | UINT8 CertDataBuffer[0]; // The X.509 certificate content (DER).\r | |
2171 | } EFI_CERT_DATA;\r | |
2172 | \r | |
2173 | typedef struct {\r | |
7c342378 MK |
2174 | UINT8 CertNumber; // Number of X.509 certificate.\r |
2175 | // EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.\r | |
3702637a | 2176 | } EFI_CERT_STACK;\r |
2177 | \r | |
2178 | #pragma pack()\r | |
2179 | \r | |
e8b4eb04 | 2180 | /**\r |
2181 | Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r | |
2182 | Cryptographic Message Syntax Standard". The input signed data could be wrapped\r | |
2183 | in a ContentInfo structure.\r | |
2184 | \r | |
2185 | If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r | |
2998af86 | 2186 | return FALSE. If P7Length overflow, then return FALSE.\r |
532616bb | 2187 | If this interface is not supported, then return FALSE.\r |
e8b4eb04 | 2188 | \r |
2189 | @param[in] P7Data Pointer to the PKCS#7 message to verify.\r | |
2190 | @param[in] P7Length Length of the PKCS#7 message in bytes.\r | |
2191 | @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r | |
6fe575d0 LQ |
2192 | It's caller's responsibility to free the buffer with\r |
2193 | Pkcs7FreeSigners().\r | |
3702637a | 2194 | This data structure is EFI_CERT_STACK type.\r |
e8b4eb04 | 2195 | @param[out] StackLength Length of signer's certificates in bytes.\r |
2196 | @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r | |
6fe575d0 LQ |
2197 | It's caller's responsibility to free the buffer with\r |
2198 | Pkcs7FreeSigners().\r | |
e8b4eb04 | 2199 | @param[out] CertLength Length of the trusted certificate in bytes.\r |
2200 | \r | |
2201 | @retval TRUE The operation is finished successfully.\r | |
2202 | @retval FALSE Error occurs during the operation.\r | |
532616bb | 2203 | @retval FALSE This interface is not supported.\r |
e8b4eb04 | 2204 | \r |
2205 | **/\r | |
2206 | BOOLEAN\r | |
2207 | EFIAPI\r | |
2208 | Pkcs7GetSigners (\r | |
2209 | IN CONST UINT8 *P7Data,\r | |
2210 | IN UINTN P7Length,\r | |
2211 | OUT UINT8 **CertStack,\r | |
2212 | OUT UINTN *StackLength,\r | |
2213 | OUT UINT8 **TrustedCert,\r | |
2214 | OUT UINTN *CertLength\r | |
2215 | );\r | |
2216 | \r | |
2217 | /**\r | |
2218 | Wrap function to use free() to free allocated memory for certificates.\r | |
2219 | \r | |
532616bb | 2220 | If this interface is not supported, then ASSERT().\r |
2221 | \r | |
e8b4eb04 | 2222 | @param[in] Certs Pointer to the certificates to be freed.\r |
2223 | \r | |
2224 | **/\r | |
2225 | VOID\r | |
2226 | EFIAPI\r | |
2227 | Pkcs7FreeSigners (\r | |
7c342378 | 2228 | IN UINT8 *Certs\r |
45419de6 QL |
2229 | );\r |
2230 | \r | |
2231 | /**\r | |
2232 | Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r | |
2233 | Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r | |
2234 | unchained to the signer's certificates.\r | |
2235 | The input signed data could be wrapped in a ContentInfo structure.\r | |
2236 | \r | |
2237 | @param[in] P7Data Pointer to the PKCS#7 message.\r | |
2238 | @param[in] P7Length Length of the PKCS#7 message in bytes.\r | |
0f5f6b3d | 2239 | @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r |
6fe575d0 LQ |
2240 | certificate. It's caller's responsibility to free the buffer\r |
2241 | with Pkcs7FreeSigners().\r | |
3702637a | 2242 | This data structure is EFI_CERT_STACK type.\r |
45419de6 QL |
2243 | @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r |
2244 | @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r | |
6fe575d0 | 2245 | responsibility to free the buffer with Pkcs7FreeSigners().\r |
3702637a | 2246 | This data structure is EFI_CERT_STACK type.\r |
45419de6 QL |
2247 | @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r |
2248 | \r | |
2249 | @retval TRUE The operation is finished successfully.\r | |
2250 | @retval FALSE Error occurs during the operation.\r | |
2251 | \r | |
2252 | **/\r | |
2253 | BOOLEAN\r | |
2254 | EFIAPI\r | |
2255 | Pkcs7GetCertificatesList (\r | |
2256 | IN CONST UINT8 *P7Data,\r | |
2257 | IN UINTN P7Length,\r | |
2258 | OUT UINT8 **SignerChainCerts,\r | |
2259 | OUT UINTN *ChainLength,\r | |
2260 | OUT UINT8 **UnchainCerts,\r | |
2261 | OUT UINTN *UnchainLength\r | |
e8b4eb04 | 2262 | );\r |
2263 | \r | |
b7d320f8 | 2264 | /**\r |
2265 | Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r | |
2266 | Syntax Standard, version 1.5". This interface is only intended to be used for\r | |
2267 | application to perform PKCS#7 functionality validation.\r | |
2268 | \r | |
532616bb | 2269 | If this interface is not supported, then return FALSE.\r |
2270 | \r | |
b7d320f8 | 2271 | @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r |
2272 | data signing.\r | |
2273 | @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r | |
2274 | @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r | |
2275 | key data.\r | |
2276 | @param[in] InData Pointer to the content to be signed.\r | |
2277 | @param[in] InDataSize Size of InData in bytes.\r | |
2278 | @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r | |
2279 | @param[in] OtherCerts Pointer to an optional additional set of certificates to\r | |
2280 | include in the PKCS#7 signedData (e.g. any intermediate\r | |
2281 | CAs in the chain).\r | |
6fe575d0 LQ |
2282 | @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r |
2283 | responsibility to free the buffer with FreePool().\r | |
b7d320f8 | 2284 | @param[out] SignedDataSize Size of SignedData in bytes.\r |
2285 | \r | |
2286 | @retval TRUE PKCS#7 data signing succeeded.\r | |
2287 | @retval FALSE PKCS#7 data signing failed.\r | |
532616bb | 2288 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 2289 | \r |
2290 | **/\r | |
2291 | BOOLEAN\r | |
2292 | EFIAPI\r | |
2293 | Pkcs7Sign (\r | |
2294 | IN CONST UINT8 *PrivateKey,\r | |
2295 | IN UINTN PrivateKeySize,\r | |
2296 | IN CONST UINT8 *KeyPassword,\r | |
2297 | IN UINT8 *InData,\r | |
2298 | IN UINTN InDataSize,\r | |
2299 | IN UINT8 *SignCert,\r | |
2300 | IN UINT8 *OtherCerts OPTIONAL,\r | |
2301 | OUT UINT8 **SignedData,\r | |
2302 | OUT UINTN *SignedDataSize\r | |
2303 | );\r | |
2304 | \r | |
97f98500 | 2305 | /**\r |
2998af86 | 2306 | Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r |
e8b4eb04 | 2307 | Cryptographic Message Syntax Standard". The input signed data could be wrapped\r |
2308 | in a ContentInfo structure.\r | |
97f98500 | 2309 | \r |
e8b4eb04 | 2310 | If P7Data, TrustedCert or InData is NULL, then return FALSE.\r |
2998af86 | 2311 | If P7Length, CertLength or DataLength overflow, then return FALSE.\r |
532616bb | 2312 | If this interface is not supported, then return FALSE.\r |
97f98500 HT |
2313 | \r |
2314 | @param[in] P7Data Pointer to the PKCS#7 message to verify.\r | |
e8b4eb04 | 2315 | @param[in] P7Length Length of the PKCS#7 message in bytes.\r |
97f98500 HT |
2316 | @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r |
2317 | is used for certificate chain verification.\r | |
e8b4eb04 | 2318 | @param[in] CertLength Length of the trusted certificate in bytes.\r |
97f98500 | 2319 | @param[in] InData Pointer to the content to be verified.\r |
e8b4eb04 | 2320 | @param[in] DataLength Length of InData in bytes.\r |
97f98500 | 2321 | \r |
a8c44645 | 2322 | @retval TRUE The specified PKCS#7 signed data is valid.\r |
2323 | @retval FALSE Invalid PKCS#7 signed data.\r | |
532616bb | 2324 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
2325 | \r |
2326 | **/\r | |
2327 | BOOLEAN\r | |
2328 | EFIAPI\r | |
2329 | Pkcs7Verify (\r | |
2330 | IN CONST UINT8 *P7Data,\r | |
e8b4eb04 | 2331 | IN UINTN P7Length,\r |
97f98500 | 2332 | IN CONST UINT8 *TrustedCert,\r |
e8b4eb04 | 2333 | IN UINTN CertLength,\r |
97f98500 | 2334 | IN CONST UINT8 *InData,\r |
e8b4eb04 | 2335 | IN UINTN DataLength\r |
a8c44645 | 2336 | );\r |
2337 | \r | |
1796a394 BB |
2338 | /**\r |
2339 | This function receives a PKCS7 formatted signature, and then verifies that\r | |
2340 | the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r | |
2341 | leaf signing certificate.\r | |
2342 | Note that this function does not validate the certificate chain.\r | |
2343 | \r | |
2344 | Applications for custom EKU's are quite flexible. For example, a policy EKU\r | |
2345 | may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r | |
2346 | certificate issued might also contain this EKU, thus constraining the\r | |
2347 | sub-ordinate certificate. Other applications might allow a certificate\r | |
2348 | embedded in a device to specify that other Object Identifiers (OIDs) are\r | |
2349 | present which contains binary data specifying custom capabilities that\r | |
2350 | the device is able to do.\r | |
2351 | \r | |
2352 | @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r | |
2353 | containing the content block with both the signature,\r | |
2354 | the signer's certificate, and any necessary intermediate\r | |
2355 | certificates.\r | |
2356 | @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r | |
2357 | @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r | |
2358 | required EKUs that must be present in the signature.\r | |
2359 | @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r | |
2360 | @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r | |
2361 | must be present in the leaf signer. If it is\r | |
2362 | FALSE, then we will succeed if we find any\r | |
2363 | of the specified EKU's.\r | |
2364 | \r | |
2365 | @retval EFI_SUCCESS The required EKUs were found in the signature.\r | |
2366 | @retval EFI_INVALID_PARAMETER A parameter was invalid.\r | |
2367 | @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r | |
2368 | \r | |
2369 | **/\r | |
2370 | RETURN_STATUS\r | |
2371 | EFIAPI\r | |
2372 | VerifyEKUsInPkcs7Signature (\r | |
2373 | IN CONST UINT8 *Pkcs7Signature,\r | |
2374 | IN CONST UINT32 SignatureSize,\r | |
2375 | IN CONST CHAR8 *RequiredEKUs[],\r | |
2376 | IN CONST UINT32 RequiredEKUsSize,\r | |
2377 | IN BOOLEAN RequireAllPresent\r | |
2378 | );\r | |
2379 | \r | |
afeb55e4 QL |
2380 | /**\r |
2381 | Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r | |
2382 | data could be wrapped in a ContentInfo structure.\r | |
2383 | \r | |
2384 | If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r | |
2998af86 | 2385 | then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r |
afeb55e4 QL |
2386 | \r |
2387 | Caution: This function may receive untrusted input. So this function will do\r | |
2388 | basic check for PKCS#7 data structure.\r | |
2389 | \r | |
2390 | @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r | |
2391 | @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r | |
2392 | @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r | |
6fe575d0 | 2393 | It's caller's responsibility to free the buffer with FreePool().\r |
afeb55e4 QL |
2394 | @param[out] ContentSize The size of the extracted content in bytes.\r |
2395 | \r | |
2396 | @retval TRUE The P7Data was correctly formatted for processing.\r | |
2397 | @retval FALSE The P7Data was not correctly formatted for processing.\r | |
2398 | \r | |
0c9fc4b1 | 2399 | **/\r |
afeb55e4 QL |
2400 | BOOLEAN\r |
2401 | EFIAPI\r | |
2402 | Pkcs7GetAttachedContent (\r | |
2403 | IN CONST UINT8 *P7Data,\r | |
2404 | IN UINTN P7Length,\r | |
2405 | OUT VOID **Content,\r | |
2406 | OUT UINTN *ContentSize\r | |
2407 | );\r | |
2408 | \r | |
b7d320f8 | 2409 | /**\r |
2998af86 | 2410 | Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r |
b7d320f8 | 2411 | Authenticode Portable Executable Signature Format".\r |
2412 | \r | |
16d2c32c | 2413 | If AuthData is NULL, then return FALSE.\r |
2414 | If ImageHash is NULL, then return FALSE.\r | |
532616bb | 2415 | If this interface is not supported, then return FALSE.\r |
b7d320f8 | 2416 | \r |
2417 | @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r | |
2418 | PE/COFF image to be verified.\r | |
2419 | @param[in] DataSize Size of the Authenticode Signature in bytes.\r | |
2420 | @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r | |
2421 | is used for certificate chain verification.\r | |
2422 | @param[in] CertSize Size of the trusted certificate in bytes.\r | |
2998af86 | 2423 | @param[in] ImageHash Pointer to the original image file hash value. The procedure\r |
b7d320f8 | 2424 | for calculating the image hash value is described in Authenticode\r |
2425 | specification.\r | |
2426 | @param[in] HashSize Size of Image hash value in bytes.\r | |
2427 | \r | |
2428 | @retval TRUE The specified Authenticode Signature is valid.\r | |
2429 | @retval FALSE Invalid Authenticode Signature.\r | |
532616bb | 2430 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 2431 | \r |
2432 | **/\r | |
2433 | BOOLEAN\r | |
2434 | EFIAPI\r | |
2435 | AuthenticodeVerify (\r | |
2436 | IN CONST UINT8 *AuthData,\r | |
2437 | IN UINTN DataSize,\r | |
2438 | IN CONST UINT8 *TrustedCert,\r | |
2439 | IN UINTN CertSize,\r | |
2440 | IN CONST UINT8 *ImageHash,\r | |
2441 | IN UINTN HashSize\r | |
2442 | );\r | |
2443 | \r | |
2ac68e8b | 2444 | /**\r |
2998af86 | 2445 | Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r |
2ac68e8b QL |
2446 | signature.\r |
2447 | \r | |
2448 | If AuthData is NULL, then return FALSE.\r | |
12d95665 | 2449 | If this interface is not supported, then return FALSE.\r |
2ac68e8b QL |
2450 | \r |
2451 | @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r | |
2452 | PE/COFF image to be verified.\r | |
2453 | @param[in] DataSize Size of the Authenticode Signature in bytes.\r | |
2454 | @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r | |
2455 | is used for TSA certificate chain verification.\r | |
2456 | @param[in] CertSize Size of the trusted certificate in bytes.\r | |
2457 | @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r | |
2458 | signature is valid.\r | |
2459 | \r | |
2460 | @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r | |
2461 | @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r | |
2462 | \r | |
2463 | **/\r | |
2464 | BOOLEAN\r | |
2465 | EFIAPI\r | |
2466 | ImageTimestampVerify (\r | |
2467 | IN CONST UINT8 *AuthData,\r | |
2468 | IN UINTN DataSize,\r | |
2469 | IN CONST UINT8 *TsaCert,\r | |
2470 | IN UINTN CertSize,\r | |
2471 | OUT EFI_TIME *SigningTime\r | |
2472 | );\r | |
2473 | \r | |
190f77f8 QZ |
2474 | /**\r |
2475 | Retrieve the version from one X.509 certificate.\r | |
2476 | \r | |
2477 | If Cert is NULL, then return FALSE.\r | |
2478 | If CertSize is 0, then return FALSE.\r | |
2479 | If this interface is not supported, then return FALSE.\r | |
2480 | \r | |
2481 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
2482 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
2483 | @param[out] Version Pointer to the retrieved version integer.\r | |
2484 | \r | |
2485 | @retval TRUE The certificate version retrieved successfully.\r | |
2486 | @retval FALSE If Cert is NULL or CertSize is Zero.\r | |
2487 | @retval FALSE The operation is not supported.\r | |
2488 | \r | |
2489 | **/\r | |
2490 | BOOLEAN\r | |
2491 | EFIAPI\r | |
2492 | X509GetVersion (\r | |
2493 | IN CONST UINT8 *Cert,\r | |
2494 | IN UINTN CertSize,\r | |
2495 | OUT UINTN *Version\r | |
2496 | );\r | |
2497 | \r | |
2498 | /**\r | |
2499 | Retrieve the serialNumber from one X.509 certificate.\r | |
2500 | \r | |
2501 | If Cert is NULL, then return FALSE.\r | |
2502 | If CertSize is 0, then return FALSE.\r | |
2503 | If this interface is not supported, then return FALSE.\r | |
2504 | \r | |
2505 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
2506 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
2507 | @param[out] SerialNumber Pointer to the retrieved certificate SerialNumber bytes.\r | |
2508 | @param[in, out] SerialNumberSize The size in bytes of the SerialNumber buffer on input,\r | |
2509 | and the size of buffer returned SerialNumber on output.\r | |
2510 | \r | |
2511 | @retval TRUE The certificate serialNumber retrieved successfully.\r | |
2512 | @retval FALSE If Cert is NULL or CertSize is Zero.\r | |
2513 | If SerialNumberSize is NULL.\r | |
2514 | If Certificate is invalid.\r | |
2515 | @retval FALSE If no SerialNumber exists.\r | |
2516 | @retval FALSE If the SerialNumber is NULL. The required buffer size\r | |
2517 | (including the final null) is returned in the\r | |
2518 | SerialNumberSize parameter.\r | |
2519 | @retval FALSE The operation is not supported.\r | |
2520 | **/\r | |
2521 | BOOLEAN\r | |
2522 | EFIAPI\r | |
2523 | X509GetSerialNumber (\r | |
2524 | IN CONST UINT8 *Cert,\r | |
2525 | IN UINTN CertSize,\r | |
2526 | OUT UINT8 *SerialNumber, OPTIONAL\r | |
2527 | IN OUT UINTN *SerialNumberSize\r | |
2528 | );\r | |
2529 | \r | |
2530 | /**\r | |
2531 | Retrieve the issuer bytes from one X.509 certificate.\r | |
2532 | \r | |
2533 | If Cert is NULL, then return FALSE.\r | |
2534 | If CertIssuerSize is NULL, then return FALSE.\r | |
2535 | If this interface is not supported, then return FALSE.\r | |
2536 | \r | |
2537 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
2538 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
2539 | @param[out] CertIssuer Pointer to the retrieved certificate subject bytes.\r | |
2540 | @param[in, out] CertIssuerSize The size in bytes of the CertIssuer buffer on input,\r | |
2541 | and the size of buffer returned CertSubject on output.\r | |
2542 | \r | |
2543 | @retval TRUE The certificate issuer retrieved successfully.\r | |
2544 | @retval FALSE Invalid certificate, or the CertIssuerSize is too small for the result.\r | |
2545 | The CertIssuerSize will be updated with the required size.\r | |
2546 | @retval FALSE This interface is not supported.\r | |
2547 | \r | |
2548 | **/\r | |
2549 | BOOLEAN\r | |
2550 | EFIAPI\r | |
2551 | X509GetIssuerName (\r | |
2552 | IN CONST UINT8 *Cert,\r | |
2553 | IN UINTN CertSize,\r | |
2554 | OUT UINT8 *CertIssuer,\r | |
2555 | IN OUT UINTN *CertIssuerSize\r | |
2556 | );\r | |
2557 | \r | |
2558 | /**\r | |
2559 | Retrieve the Signature Algorithm from one X.509 certificate.\r | |
2560 | \r | |
2561 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
2562 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
2563 | @param[out] Oid Signature Algorithm Object identifier buffer.\r | |
2564 | @param[in,out] OidSize Signature Algorithm Object identifier buffer size\r | |
2565 | \r | |
2566 | @retval TRUE The certificate Extension data retrieved successfully.\r | |
2567 | @retval FALSE If Cert is NULL.\r | |
2568 | If OidSize is NULL.\r | |
2569 | If Oid is not NULL and *OidSize is 0.\r | |
2570 | If Certificate is invalid.\r | |
2571 | @retval FALSE If no SignatureType.\r | |
2572 | @retval FALSE If the Oid is NULL. The required buffer size\r | |
2573 | is returned in the OidSize.\r | |
2574 | @retval FALSE The operation is not supported.\r | |
2575 | **/\r | |
2576 | BOOLEAN\r | |
2577 | EFIAPI\r | |
2578 | X509GetSignatureAlgorithm (\r | |
2579 | IN CONST UINT8 *Cert,\r | |
2580 | IN UINTN CertSize,\r | |
2581 | OUT UINT8 *Oid, OPTIONAL\r | |
2582 | IN OUT UINTN *OidSize\r | |
2583 | );\r | |
2584 | \r | |
2585 | /**\r | |
2586 | Retrieve Extension data from one X.509 certificate.\r | |
2587 | \r | |
2588 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
2589 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
2590 | @param[in] Oid Object identifier buffer\r | |
2591 | @param[in] OidSize Object identifier buffer size\r | |
2592 | @param[out] ExtensionData Extension bytes.\r | |
2593 | @param[in, out] ExtensionDataSize Extension bytes size.\r | |
2594 | \r | |
2595 | @retval TRUE The certificate Extension data retrieved successfully.\r | |
2596 | @retval FALSE If Cert is NULL.\r | |
2597 | If ExtensionDataSize is NULL.\r | |
2598 | If ExtensionData is not NULL and *ExtensionDataSize is 0.\r | |
2599 | If Certificate is invalid.\r | |
2600 | @retval FALSE If no Extension entry match Oid.\r | |
2601 | @retval FALSE If the ExtensionData is NULL. The required buffer size\r | |
2602 | is returned in the ExtensionDataSize parameter.\r | |
2603 | @retval FALSE The operation is not supported.\r | |
2604 | **/\r | |
2605 | BOOLEAN\r | |
2606 | EFIAPI\r | |
2607 | X509GetExtensionData (\r | |
2608 | IN CONST UINT8 *Cert,\r | |
2609 | IN UINTN CertSize,\r | |
2610 | IN CONST UINT8 *Oid,\r | |
2611 | IN UINTN OidSize,\r | |
2612 | OUT UINT8 *ExtensionData,\r | |
2613 | IN OUT UINTN *ExtensionDataSize\r | |
2614 | );\r | |
2615 | \r | |
2616 | /**\r | |
2617 | Retrieve the Validity from one X.509 certificate\r | |
2618 | \r | |
2619 | If Cert is NULL, then return FALSE.\r | |
2620 | If CertIssuerSize is NULL, then return FALSE.\r | |
2621 | If this interface is not supported, then return FALSE.\r | |
2622 | \r | |
2623 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
2624 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
2625 | @param[in] From notBefore Pointer to DateTime object.\r | |
2626 | @param[in,out] FromSize notBefore DateTime object size.\r | |
2627 | @param[in] To notAfter Pointer to DateTime object.\r | |
2628 | @param[in,out] ToSize notAfter DateTime object size.\r | |
2629 | \r | |
2630 | Note: X509CompareDateTime to compare DateTime oject\r | |
2631 | x509SetDateTime to get a DateTime object from a DateTimeStr\r | |
2632 | \r | |
2633 | @retval TRUE The certificate Validity retrieved successfully.\r | |
2634 | @retval FALSE Invalid certificate, or Validity retrieve failed.\r | |
2635 | @retval FALSE This interface is not supported.\r | |
2636 | **/\r | |
2637 | BOOLEAN\r | |
2638 | EFIAPI\r | |
2639 | X509GetValidity (\r | |
2640 | IN CONST UINT8 *Cert,\r | |
2641 | IN UINTN CertSize,\r | |
2642 | IN UINT8 *From,\r | |
2643 | IN OUT UINTN *FromSize,\r | |
2644 | IN UINT8 *To,\r | |
2645 | IN OUT UINTN *ToSize\r | |
2646 | );\r | |
2647 | \r | |
2648 | /**\r | |
2649 | Format a DateTimeStr to DataTime object in DataTime Buffer\r | |
2650 | \r | |
2651 | If DateTimeStr is NULL, then return FALSE.\r | |
2652 | If DateTimeSize is NULL, then return FALSE.\r | |
2653 | If this interface is not supported, then return FALSE.\r | |
2654 | \r | |
2655 | @param[in] DateTimeStr DateTime string like YYYYMMDDhhmmssZ\r | |
2656 | Ref: https://www.w3.org/TR/NOTE-datetime\r | |
2657 | Z stand for UTC time\r | |
2658 | @param[out] DateTime Pointer to a DateTime object.\r | |
2659 | @param[in,out] DateTimeSize DateTime object buffer size.\r | |
2660 | \r | |
2661 | @retval TRUE The DateTime object create successfully.\r | |
2662 | @retval FALSE If DateTimeStr is NULL.\r | |
2663 | If DateTimeSize is NULL.\r | |
2664 | If DateTime is not NULL and *DateTimeSize is 0.\r | |
2665 | If Year Month Day Hour Minute Second combination is invalid datetime.\r | |
2666 | @retval FALSE If the DateTime is NULL. The required buffer size\r | |
2667 | (including the final null) is returned in the\r | |
2668 | DateTimeSize parameter.\r | |
2669 | @retval FALSE The operation is not supported.\r | |
2670 | **/\r | |
2671 | BOOLEAN\r | |
2672 | EFIAPI\r | |
2673 | X509FormatDateTime (\r | |
2674 | IN CONST CHAR8 *DateTimeStr,\r | |
2675 | OUT VOID *DateTime,\r | |
2676 | IN OUT UINTN *DateTimeSize\r | |
2677 | );\r | |
2678 | \r | |
2679 | /**\r | |
2680 | Compare DateTime1 object and DateTime2 object.\r | |
2681 | \r | |
2682 | If DateTime1 is NULL, then return -2.\r | |
2683 | If DateTime2 is NULL, then return -2.\r | |
2684 | If DateTime1 == DateTime2, then return 0\r | |
2685 | If DateTime1 > DateTime2, then return 1\r | |
2686 | If DateTime1 < DateTime2, then return -1\r | |
2687 | \r | |
2688 | @param[in] DateTime1 Pointer to a DateTime Ojbect\r | |
2689 | @param[in] DateTime2 Pointer to a DateTime Object\r | |
2690 | \r | |
2691 | @retval 0 If DateTime1 == DateTime2\r | |
2692 | @retval 1 If DateTime1 > DateTime2\r | |
2693 | @retval -1 If DateTime1 < DateTime2\r | |
2694 | **/\r | |
2695 | INT32\r | |
2696 | EFIAPI\r | |
2697 | X509CompareDateTime (\r | |
2698 | IN CONST VOID *DateTime1,\r | |
2699 | IN CONST VOID *DateTime2\r | |
2700 | );\r | |
2701 | \r | |
2702 | /**\r | |
2703 | Retrieve the Key Usage from one X.509 certificate.\r | |
2704 | \r | |
2705 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
2706 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
2707 | @param[out] Usage Key Usage (CRYPTO_X509_KU_*)\r | |
2708 | \r | |
2709 | @retval TRUE The certificate Key Usage retrieved successfully.\r | |
2710 | @retval FALSE Invalid certificate, or Usage is NULL\r | |
2711 | @retval FALSE This interface is not supported.\r | |
2712 | **/\r | |
2713 | BOOLEAN\r | |
2714 | EFIAPI\r | |
2715 | X509GetKeyUsage (\r | |
2716 | IN CONST UINT8 *Cert,\r | |
2717 | IN UINTN CertSize,\r | |
2718 | OUT UINTN *Usage\r | |
2719 | );\r | |
2720 | \r | |
2721 | /**\r | |
2722 | Retrieve the Extended Key Usage from one X.509 certificate.\r | |
2723 | \r | |
2724 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
2725 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
2726 | @param[out] Usage Key Usage bytes.\r | |
2727 | @param[in, out] UsageSize Key Usage buffer sizs in bytes.\r | |
2728 | \r | |
2729 | @retval TRUE The Usage bytes retrieve successfully.\r | |
2730 | @retval FALSE If Cert is NULL.\r | |
2731 | If CertSize is NULL.\r | |
2732 | If Usage is not NULL and *UsageSize is 0.\r | |
2733 | If Cert is invalid.\r | |
2734 | @retval FALSE If the Usage is NULL. The required buffer size\r | |
2735 | is returned in the UsageSize parameter.\r | |
2736 | @retval FALSE The operation is not supported.\r | |
2737 | **/\r | |
2738 | BOOLEAN\r | |
2739 | EFIAPI\r | |
2740 | X509GetExtendedKeyUsage (\r | |
2741 | IN CONST UINT8 *Cert,\r | |
2742 | IN UINTN CertSize,\r | |
2743 | OUT UINT8 *Usage,\r | |
2744 | IN OUT UINTN *UsageSize\r | |
2745 | );\r | |
2746 | \r | |
2747 | /**\r | |
2748 | Verify one X509 certificate was issued by the trusted CA.\r | |
2749 | @param[in] RootCert Trusted Root Certificate buffer\r | |
2750 | \r | |
2751 | @param[in] RootCertLength Trusted Root Certificate buffer length\r | |
2752 | @param[in] CertChain One or more ASN.1 DER-encoded X.509 certificates\r | |
2753 | where the first certificate is signed by the Root\r | |
2754 | Certificate or is the Root Cerificate itself. and\r | |
2755 | subsequent cerificate is signed by the preceding\r | |
2756 | cerificate.\r | |
2757 | @param[in] CertChainLength Total length of the certificate chain, in bytes.\r | |
2758 | \r | |
2759 | @retval TRUE All cerificates was issued by the first certificate in X509Certchain.\r | |
2760 | @retval FALSE Invalid certificate or the certificate was not issued by the given\r | |
2761 | trusted CA.\r | |
2762 | **/\r | |
2763 | BOOLEAN\r | |
2764 | EFIAPI\r | |
2765 | X509VerifyCertChain (\r | |
2766 | IN CONST UINT8 *RootCert,\r | |
2767 | IN UINTN RootCertLength,\r | |
2768 | IN CONST UINT8 *CertChain,\r | |
2769 | IN UINTN CertChainLength\r | |
2770 | );\r | |
2771 | \r | |
2772 | /**\r | |
2773 | Get one X509 certificate from CertChain.\r | |
2774 | \r | |
2775 | @param[in] CertChain One or more ASN.1 DER-encoded X.509 certificates\r | |
2776 | where the first certificate is signed by the Root\r | |
2777 | Certificate or is the Root Cerificate itself. and\r | |
2778 | subsequent cerificate is signed by the preceding\r | |
2779 | cerificate.\r | |
2780 | @param[in] CertChainLength Total length of the certificate chain, in bytes.\r | |
2781 | \r | |
2782 | @param[in] CertIndex Index of certificate. If index is -1 indecate the\r | |
2783 | last certificate in CertChain.\r | |
2784 | \r | |
2785 | @param[out] Cert The certificate at the index of CertChain.\r | |
2786 | @param[out] CertLength The length certificate at the index of CertChain.\r | |
2787 | \r | |
2788 | @retval TRUE Success.\r | |
2789 | @retval FALSE Failed to get certificate from certificate chain.\r | |
2790 | **/\r | |
2791 | BOOLEAN\r | |
2792 | EFIAPI\r | |
2793 | X509GetCertFromCertChain (\r | |
2794 | IN CONST UINT8 *CertChain,\r | |
2795 | IN UINTN CertChainLength,\r | |
2796 | IN CONST INT32 CertIndex,\r | |
2797 | OUT CONST UINT8 **Cert,\r | |
2798 | OUT UINTN *CertLength\r | |
2799 | );\r | |
2800 | \r | |
2801 | /**\r | |
2802 | Retrieve the tag and length of the tag.\r | |
2803 | \r | |
2804 | @param Ptr The position in the ASN.1 data\r | |
2805 | @param End End of data\r | |
2806 | @param Length The variable that will receive the length\r | |
2807 | @param Tag The expected tag\r | |
2808 | \r | |
2809 | @retval TRUE Get tag successful\r | |
2810 | @retval FALSe Failed to get tag or tag not match\r | |
2811 | **/\r | |
2812 | BOOLEAN\r | |
2813 | EFIAPI\r | |
2814 | Asn1GetTag (\r | |
2815 | IN OUT UINT8 **Ptr,\r | |
2816 | IN CONST UINT8 *End,\r | |
2817 | OUT UINTN *Length,\r | |
2818 | IN UINT32 Tag\r | |
2819 | );\r | |
2820 | \r | |
2821 | /**\r | |
2822 | Retrieve the basic constraints from one X.509 certificate.\r | |
2823 | \r | |
2824 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r | |
2825 | @param[in] CertSize size of the X509 certificate in bytes.\r | |
2826 | @param[out] BasicConstraints basic constraints bytes.\r | |
2827 | @param[in, out] BasicConstraintsSize basic constraints buffer sizs in bytes.\r | |
2828 | \r | |
2829 | @retval TRUE The basic constraints retrieve successfully.\r | |
2830 | @retval FALSE If cert is NULL.\r | |
2831 | If cert_size is NULL.\r | |
2832 | If basic_constraints is not NULL and *basic_constraints_size is 0.\r | |
2833 | If cert is invalid.\r | |
2834 | @retval FALSE The required buffer size is small.\r | |
2835 | The return buffer size is basic_constraints_size parameter.\r | |
2836 | @retval FALSE If no Extension entry match oid.\r | |
2837 | @retval FALSE The operation is not supported.\r | |
2838 | **/\r | |
2839 | BOOLEAN\r | |
2840 | EFIAPI\r | |
2841 | X509GetExtendedBasicConstraints (\r | |
2842 | CONST UINT8 *Cert,\r | |
2843 | UINTN CertSize,\r | |
2844 | UINT8 *BasicConstraints,\r | |
2845 | UINTN *BasicConstraintsSize\r | |
2846 | );\r | |
2847 | \r | |
7c342378 | 2848 | // =====================================================================================\r |
a8c44645 | 2849 | // DH Key Exchange Primitive\r |
7c342378 | 2850 | // =====================================================================================\r |
a8c44645 | 2851 | \r |
2852 | /**\r | |
2853 | Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r | |
2854 | \r | |
2855 | @return Pointer to the Diffie-Hellman Context that has been initialized.\r | |
2856 | If the allocations fails, DhNew() returns NULL.\r | |
532616bb | 2857 | If the interface is not supported, DhNew() returns NULL.\r |
a8c44645 | 2858 | \r |
2859 | **/\r | |
2860 | VOID *\r | |
2861 | EFIAPI\r | |
2862 | DhNew (\r | |
2863 | VOID\r | |
2864 | );\r | |
2865 | \r | |
2866 | /**\r | |
2867 | Release the specified DH context.\r | |
2868 | \r | |
532616bb | 2869 | If the interface is not supported, then ASSERT().\r |
a8c44645 | 2870 | \r |
2871 | @param[in] DhContext Pointer to the DH context to be released.\r | |
2872 | \r | |
2873 | **/\r | |
2874 | VOID\r | |
2875 | EFIAPI\r | |
2876 | DhFree (\r | |
2877 | IN VOID *DhContext\r | |
2878 | );\r | |
2879 | \r | |
2880 | /**\r | |
2881 | Generates DH parameter.\r | |
2882 | \r | |
2883 | Given generator g, and length of prime number p in bits, this function generates p,\r | |
2884 | and sets DH context according to value of g and p.\r | |
2ac68e8b | 2885 | \r |
a8c44645 | 2886 | Before this function can be invoked, pseudorandom number generator must be correctly\r |
2887 | initialized by RandomSeed().\r | |
2888 | \r | |
16d2c32c | 2889 | If DhContext is NULL, then return FALSE.\r |
2890 | If Prime is NULL, then return FALSE.\r | |
532616bb | 2891 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2892 | \r |
2893 | @param[in, out] DhContext Pointer to the DH context.\r | |
2894 | @param[in] Generator Value of generator.\r | |
2895 | @param[in] PrimeLength Length in bits of prime to be generated.\r | |
2896 | @param[out] Prime Pointer to the buffer to receive the generated prime number.\r | |
2897 | \r | |
2998af86 | 2898 | @retval TRUE DH parameter generation succeeded.\r |
a8c44645 | 2899 | @retval FALSE Value of Generator is not supported.\r |
2900 | @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r | |
532616bb | 2901 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2902 | \r |
2903 | **/\r | |
2904 | BOOLEAN\r | |
2905 | EFIAPI\r | |
2906 | DhGenerateParameter (\r | |
2907 | IN OUT VOID *DhContext,\r | |
2908 | IN UINTN Generator,\r | |
2909 | IN UINTN PrimeLength,\r | |
2910 | OUT UINT8 *Prime\r | |
2911 | );\r | |
2912 | \r | |
2913 | /**\r | |
2914 | Sets generator and prime parameters for DH.\r | |
2915 | \r | |
2916 | Given generator g, and prime number p, this function and sets DH\r | |
2917 | context accordingly.\r | |
2918 | \r | |
16d2c32c | 2919 | If DhContext is NULL, then return FALSE.\r |
2920 | If Prime is NULL, then return FALSE.\r | |
532616bb | 2921 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2922 | \r |
2923 | @param[in, out] DhContext Pointer to the DH context.\r | |
2924 | @param[in] Generator Value of generator.\r | |
2925 | @param[in] PrimeLength Length in bits of prime to be generated.\r | |
2926 | @param[in] Prime Pointer to the prime number.\r | |
2927 | \r | |
2998af86 | 2928 | @retval TRUE DH parameter setting succeeded.\r |
a8c44645 | 2929 | @retval FALSE Value of Generator is not supported.\r |
2930 | @retval FALSE Value of Generator is not suitable for the Prime.\r | |
2931 | @retval FALSE Value of Prime is not a prime number.\r | |
2932 | @retval FALSE Value of Prime is not a safe prime number.\r | |
532616bb | 2933 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2934 | \r |
2935 | **/\r | |
2936 | BOOLEAN\r | |
2937 | EFIAPI\r | |
2938 | DhSetParameter (\r | |
2939 | IN OUT VOID *DhContext,\r | |
2940 | IN UINTN Generator,\r | |
2941 | IN UINTN PrimeLength,\r | |
2942 | IN CONST UINT8 *Prime\r | |
97f98500 HT |
2943 | );\r |
2944 | \r | |
a8c44645 | 2945 | /**\r |
2946 | Generates DH public key.\r | |
2947 | \r | |
2ac68e8b | 2948 | This function generates random secret exponent, and computes the public key, which is\r |
a8c44645 | 2949 | returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r |
2950 | If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r | |
2951 | PublicKeySize is set to the required buffer size to obtain the public key.\r | |
2952 | \r | |
16d2c32c | 2953 | If DhContext is NULL, then return FALSE.\r |
2954 | If PublicKeySize is NULL, then return FALSE.\r | |
2955 | If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r | |
532616bb | 2956 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2957 | \r |
2958 | @param[in, out] DhContext Pointer to the DH context.\r | |
2959 | @param[out] PublicKey Pointer to the buffer to receive generated public key.\r | |
2960 | @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r | |
2961 | On output, the size of data returned in PublicKey buffer in bytes.\r | |
2962 | \r | |
2963 | @retval TRUE DH public key generation succeeded.\r | |
2964 | @retval FALSE DH public key generation failed.\r | |
2965 | @retval FALSE PublicKeySize is not large enough.\r | |
532616bb | 2966 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2967 | \r |
2968 | **/\r | |
2969 | BOOLEAN\r | |
2970 | EFIAPI\r | |
2971 | DhGenerateKey (\r | |
2972 | IN OUT VOID *DhContext,\r | |
2973 | OUT UINT8 *PublicKey,\r | |
2974 | IN OUT UINTN *PublicKeySize\r | |
2975 | );\r | |
2976 | \r | |
2977 | /**\r | |
2978 | Computes exchanged common key.\r | |
2979 | \r | |
2980 | Given peer's public key, this function computes the exchanged common key, based on its own\r | |
dda39f3a | 2981 | context including value of prime modulus and random secret exponent.\r |
a8c44645 | 2982 | \r |
16d2c32c | 2983 | If DhContext is NULL, then return FALSE.\r |
2984 | If PeerPublicKey is NULL, then return FALSE.\r | |
2985 | If KeySize is NULL, then return FALSE.\r | |
dda39f3a | 2986 | If Key is NULL, then return FALSE.\r |
2987 | If KeySize is not large enough, then return FALSE.\r | |
532616bb | 2988 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2989 | \r |
2990 | @param[in, out] DhContext Pointer to the DH context.\r | |
2991 | @param[in] PeerPublicKey Pointer to the peer's public key.\r | |
2992 | @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r | |
2993 | @param[out] Key Pointer to the buffer to receive generated key.\r | |
2994 | @param[in, out] KeySize On input, the size of Key buffer in bytes.\r | |
2995 | On output, the size of data returned in Key buffer in bytes.\r | |
2996 | \r | |
2997 | @retval TRUE DH exchanged key generation succeeded.\r | |
2998 | @retval FALSE DH exchanged key generation failed.\r | |
2999 | @retval FALSE KeySize is not large enough.\r | |
532616bb | 3000 | @retval FALSE This interface is not supported.\r |
a8c44645 | 3001 | \r |
3002 | **/\r | |
3003 | BOOLEAN\r | |
3004 | EFIAPI\r | |
3005 | DhComputeKey (\r | |
3006 | IN OUT VOID *DhContext,\r | |
3007 | IN CONST UINT8 *PeerPublicKey,\r | |
3008 | IN UINTN PeerPublicKeySize,\r | |
3009 | OUT UINT8 *Key,\r | |
3010 | IN OUT UINTN *KeySize\r | |
3011 | );\r | |
3012 | \r | |
7c342378 | 3013 | // =====================================================================================\r |
a8c44645 | 3014 | // Pseudo-Random Generation Primitive\r |
7c342378 | 3015 | // =====================================================================================\r |
a8c44645 | 3016 | \r |
3017 | /**\r | |
3018 | Sets up the seed value for the pseudorandom number generator.\r | |
3019 | \r | |
3020 | This function sets up the seed value for the pseudorandom number generator.\r | |
3021 | If Seed is not NULL, then the seed passed in is used.\r | |
3022 | If Seed is NULL, then default seed is used.\r | |
532616bb | 3023 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 3024 | \r |
3025 | @param[in] Seed Pointer to seed value.\r | |
3026 | If NULL, default seed is used.\r | |
3027 | @param[in] SeedSize Size of seed value.\r | |
3028 | If Seed is NULL, this parameter is ignored.\r | |
3029 | \r | |
3030 | @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r | |
3031 | @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r | |
532616bb | 3032 | @retval FALSE This interface is not supported.\r |
a8c44645 | 3033 | \r |
3034 | **/\r | |
3035 | BOOLEAN\r | |
3036 | EFIAPI\r | |
3037 | RandomSeed (\r | |
3038 | IN CONST UINT8 *Seed OPTIONAL,\r | |
3039 | IN UINTN SeedSize\r | |
3040 | );\r | |
3041 | \r | |
3042 | /**\r | |
3043 | Generates a pseudorandom byte stream of the specified size.\r | |
3044 | \r | |
16d2c32c | 3045 | If Output is NULL, then return FALSE.\r |
532616bb | 3046 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 3047 | \r |
3048 | @param[out] Output Pointer to buffer to receive random value.\r | |
2998af86 | 3049 | @param[in] Size Size of random bytes to generate.\r |
a8c44645 | 3050 | \r |
3051 | @retval TRUE Pseudorandom byte stream generated successfully.\r | |
3052 | @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r | |
532616bb | 3053 | @retval FALSE This interface is not supported.\r |
a8c44645 | 3054 | \r |
3055 | **/\r | |
3056 | BOOLEAN\r | |
3057 | EFIAPI\r | |
3058 | RandomBytes (\r | |
3059 | OUT UINT8 *Output,\r | |
3060 | IN UINTN Size\r | |
3061 | );\r | |
97f98500 | 3062 | \r |
7c342378 | 3063 | // =====================================================================================\r |
4b1b7c19 | 3064 | // Key Derivation Function Primitive\r |
7c342378 | 3065 | // =====================================================================================\r |
4b1b7c19 GW |
3066 | \r |
3067 | /**\r | |
3068 | Derive key data using HMAC-SHA256 based KDF.\r | |
3069 | \r | |
3070 | @param[in] Key Pointer to the user-supplied key.\r | |
3071 | @param[in] KeySize Key size in bytes.\r | |
3072 | @param[in] Salt Pointer to the salt(non-secret) value.\r | |
3073 | @param[in] SaltSize Salt size in bytes.\r | |
3074 | @param[in] Info Pointer to the application specific info.\r | |
3075 | @param[in] InfoSize Info size in bytes.\r | |
944bd5cf | 3076 | @param[out] Out Pointer to buffer to receive hkdf value.\r |
4b1b7c19 GW |
3077 | @param[in] OutSize Size of hkdf bytes to generate.\r |
3078 | \r | |
3079 | @retval TRUE Hkdf generated successfully.\r | |
3080 | @retval FALSE Hkdf generation failed.\r | |
3081 | \r | |
3082 | **/\r | |
3083 | BOOLEAN\r | |
3084 | EFIAPI\r | |
3085 | HkdfSha256ExtractAndExpand (\r | |
3086 | IN CONST UINT8 *Key,\r | |
3087 | IN UINTN KeySize,\r | |
3088 | IN CONST UINT8 *Salt,\r | |
3089 | IN UINTN SaltSize,\r | |
3090 | IN CONST UINT8 *Info,\r | |
3091 | IN UINTN InfoSize,\r | |
3092 | OUT UINT8 *Out,\r | |
3093 | IN UINTN OutSize\r | |
3094 | );\r | |
3095 | \r | |
13364762 QZ |
3096 | /**\r |
3097 | Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).\r | |
3098 | \r | |
3099 | @param[in] Key Pointer to the user-supplied key.\r | |
3100 | @param[in] KeySize key size in bytes.\r | |
3101 | @param[in] Salt Pointer to the salt(non-secret) value.\r | |
3102 | @param[in] SaltSize salt size in bytes.\r | |
3103 | @param[out] PrkOut Pointer to buffer to receive hkdf value.\r | |
3104 | @param[in] PrkOutSize size of hkdf bytes to generate.\r | |
3105 | \r | |
3106 | @retval true Hkdf generated successfully.\r | |
3107 | @retval false Hkdf generation failed.\r | |
3108 | \r | |
3109 | **/\r | |
3110 | BOOLEAN\r | |
3111 | EFIAPI\r | |
3112 | HkdfSha256Extract (\r | |
3113 | IN CONST UINT8 *Key,\r | |
3114 | IN UINTN KeySize,\r | |
3115 | IN CONST UINT8 *Salt,\r | |
3116 | IN UINTN SaltSize,\r | |
3117 | OUT UINT8 *PrkOut,\r | |
3118 | UINTN PrkOutSize\r | |
3119 | );\r | |
3120 | \r | |
3121 | /**\r | |
3122 | Derive SHA256 HMAC-based Expand Key Derivation Function (HKDF).\r | |
3123 | \r | |
3124 | @param[in] Prk Pointer to the user-supplied key.\r | |
3125 | @param[in] PrkSize Key size in bytes.\r | |
3126 | @param[in] Info Pointer to the application specific info.\r | |
3127 | @param[in] InfoSize Info size in bytes.\r | |
3128 | @param[out] Out Pointer to buffer to receive hkdf value.\r | |
3129 | @param[in] OutSize Size of hkdf bytes to generate.\r | |