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