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