]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Include/Library/BaseCryptLib.h
CryptoPkg/BaseCryptLib: Retire the TDES 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
1326/**\r
1327 Performs AES encryption on a data buffer of the specified size in ECB mode.\r
1328\r
1329 This function performs AES encryption on data buffer pointed by Input, of specified\r
1330 size of InputSize, in ECB 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 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1334 invalid AES context is undefined.\r
1335\r
16d2c32c 1336 If AesContext is NULL, then return FALSE.\r
1337 If Input is NULL, then return FALSE.\r
1338 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1339 If Output is NULL, then return FALSE.\r
532616bb 1340 If this interface is not supported, then return FALSE.\r
a8c44645 1341\r
1342 @param[in] AesContext Pointer to the AES context.\r
1343 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1344 @param[in] InputSize Size of the Input buffer in bytes.\r
1345 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1346\r
1347 @retval TRUE AES encryption succeeded.\r
1348 @retval FALSE AES encryption failed.\r
532616bb 1349 @retval FALSE This interface is not supported.\r
a8c44645 1350\r
1351**/\r
1352BOOLEAN\r
1353EFIAPI\r
1354AesEcbEncrypt (\r
1355 IN VOID *AesContext,\r
1356 IN CONST UINT8 *Input,\r
1357 IN UINTN InputSize,\r
1358 OUT UINT8 *Output\r
1359 );\r
1360\r
1361/**\r
1362 Performs AES decryption on a data buffer of the specified size in ECB mode.\r
1363\r
1364 This function performs AES decryption on data buffer pointed by Input, of specified\r
1365 size of InputSize, in ECB mode.\r
1366 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1367 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1368 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1369 invalid AES context is undefined.\r
1370\r
16d2c32c 1371 If AesContext is NULL, then return FALSE.\r
1372 If Input is NULL, then return FALSE.\r
1373 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1374 If Output is NULL, then return FALSE.\r
532616bb 1375 If this interface is not supported, then return FALSE.\r
a8c44645 1376\r
1377 @param[in] AesContext Pointer to the AES context.\r
1378 @param[in] Input Pointer to the buffer containing the data to be decrypted.\r
1379 @param[in] InputSize Size of the Input buffer in bytes.\r
1380 @param[out] Output Pointer to a buffer that receives the AES decryption output.\r
1381\r
1382 @retval TRUE AES decryption succeeded.\r
1383 @retval FALSE AES decryption failed.\r
532616bb 1384 @retval FALSE This interface is not supported.\r
a8c44645 1385\r
1386**/\r
1387BOOLEAN\r
1388EFIAPI\r
1389AesEcbDecrypt (\r
1390 IN VOID *AesContext,\r
1391 IN CONST UINT8 *Input,\r
1392 IN UINTN InputSize,\r
1393 OUT UINT8 *Output\r
1394 );\r
1395\r
1396/**\r
1397 Performs AES encryption on a data buffer of the specified size in CBC mode.\r
1398\r
1399 This function performs AES encryption on data buffer pointed by Input, of specified\r
1400 size of InputSize, in CBC mode.\r
1401 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1402 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1403 Initialization vector should be one block size (16 bytes).\r
1404 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1405 invalid AES context is undefined.\r
1406\r
16d2c32c 1407 If AesContext is NULL, then return FALSE.\r
1408 If Input is NULL, then return FALSE.\r
1409 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1410 If Ivec is NULL, then return FALSE.\r
1411 If Output is NULL, then return FALSE.\r
532616bb 1412 If this interface is not supported, then return FALSE.\r
a8c44645 1413\r
1414 @param[in] AesContext Pointer to the AES context.\r
1415 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1416 @param[in] InputSize Size of the Input buffer in bytes.\r
1417 @param[in] Ivec Pointer to initialization vector.\r
1418 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1419\r
1420 @retval TRUE AES encryption succeeded.\r
1421 @retval FALSE AES encryption failed.\r
532616bb 1422 @retval FALSE This interface is not supported.\r
a8c44645 1423\r
1424**/\r
1425BOOLEAN\r
1426EFIAPI\r
1427AesCbcEncrypt (\r
1428 IN VOID *AesContext,\r
1429 IN CONST UINT8 *Input,\r
1430 IN UINTN InputSize,\r
1431 IN CONST UINT8 *Ivec,\r
1432 OUT UINT8 *Output\r
1433 );\r
1434\r
1435/**\r
1436 Performs AES decryption on a data buffer of the specified size in CBC mode.\r
1437\r
1438 This function performs AES decryption on data buffer pointed by Input, of specified\r
1439 size of InputSize, in CBC mode.\r
1440 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1441 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1442 Initialization vector should be one block size (16 bytes).\r
1443 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1444 invalid AES context is undefined.\r
1445\r
16d2c32c 1446 If AesContext is NULL, then return FALSE.\r
1447 If Input is NULL, then return FALSE.\r
1448 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1449 If Ivec is NULL, then return FALSE.\r
1450 If Output is NULL, then return FALSE.\r
532616bb 1451 If this interface is not supported, then return FALSE.\r
a8c44645 1452\r
1453 @param[in] AesContext Pointer to the AES context.\r
1454 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1455 @param[in] InputSize Size of the Input buffer in bytes.\r
1456 @param[in] Ivec Pointer to initialization vector.\r
1457 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1458\r
1459 @retval TRUE AES decryption succeeded.\r
1460 @retval FALSE AES decryption failed.\r
532616bb 1461 @retval FALSE This interface is not supported.\r
a8c44645 1462\r
1463**/\r
1464BOOLEAN\r
1465EFIAPI\r
1466AesCbcDecrypt (\r
1467 IN VOID *AesContext,\r
1468 IN CONST UINT8 *Input,\r
1469 IN UINTN InputSize,\r
1470 IN CONST UINT8 *Ivec,\r
1471 OUT UINT8 *Output\r
1472 );\r
1473\r
97f98500
HT
1474//=====================================================================================\r
1475// Asymmetric Cryptography Primitive\r
1476//=====================================================================================\r
1477\r
1478/**\r
a8c44645 1479 Allocates and initializes one RSA context for subsequent use.\r
97f98500 1480\r
a8c44645 1481 @return Pointer to the RSA context that has been initialized.\r
97f98500
HT
1482 If the allocations fails, RsaNew() returns NULL.\r
1483\r
1484**/\r
1485VOID *\r
1486EFIAPI\r
1487RsaNew (\r
1488 VOID\r
1489 );\r
1490\r
97f98500 1491/**\r
a8c44645 1492 Release the specified RSA context.\r
1493\r
16d2c32c 1494 If RsaContext is NULL, then return FALSE.\r
97f98500
HT
1495\r
1496 @param[in] RsaContext Pointer to the RSA context to be released.\r
1497\r
1498**/\r
1499VOID\r
1500EFIAPI\r
1501RsaFree (\r
1502 IN VOID *RsaContext\r
1503 );\r
1504\r
97f98500 1505/**\r
a8c44645 1506 Sets the tag-designated key component into the established RSA context.\r
1507\r
1508 This function sets the tag-designated RSA key component into the established\r
1509 RSA context from the user-specified non-negative integer (octet string format\r
1510 represented in RSA PKCS#1).\r
2998af86 1511 If BigNumber is NULL, then the specified key component in RSA context is cleared.\r
97f98500 1512\r
16d2c32c 1513 If RsaContext is NULL, then return FALSE.\r
97f98500
HT
1514\r
1515 @param[in, out] RsaContext Pointer to RSA context being set.\r
1516 @param[in] KeyTag Tag of RSA key component being set.\r
1517 @param[in] BigNumber Pointer to octet integer buffer.\r
2998af86 1518 If NULL, then the specified key component in RSA\r
a8c44645 1519 context is cleared.\r
1520 @param[in] BnSize Size of big number buffer in bytes.\r
1521 If BigNumber is NULL, then it is ignored.\r
97f98500 1522\r
a8c44645 1523 @retval TRUE RSA key component was set successfully.\r
1524 @retval FALSE Invalid RSA key component tag.\r
97f98500
HT
1525\r
1526**/\r
1527BOOLEAN\r
1528EFIAPI\r
1529RsaSetKey (\r
a8c44645 1530 IN OUT VOID *RsaContext,\r
1531 IN RSA_KEY_TAG KeyTag,\r
1532 IN CONST UINT8 *BigNumber,\r
1533 IN UINTN BnSize\r
1534 );\r
1535\r
1536/**\r
1537 Gets the tag-designated RSA key component from the established RSA context.\r
1538\r
1539 This function retrieves the tag-designated RSA key component from the\r
1540 established RSA context as a non-negative integer (octet string format\r
1541 represented in RSA PKCS#1).\r
1542 If specified key component has not been set or has been cleared, then returned\r
1543 BnSize is set to 0.\r
1544 If the BigNumber buffer is too small to hold the contents of the key, FALSE\r
1545 is returned and BnSize is set to the required buffer size to obtain the key.\r
1546\r
16d2c32c 1547 If RsaContext is NULL, then return FALSE.\r
1548 If BnSize is NULL, then return FALSE.\r
1549 If BnSize is large enough but BigNumber is NULL, then return FALSE.\r
532616bb 1550 If this interface is not supported, then return FALSE.\r
a8c44645 1551\r
1552 @param[in, out] RsaContext Pointer to RSA context being set.\r
1553 @param[in] KeyTag Tag of RSA key component being set.\r
1554 @param[out] BigNumber Pointer to octet integer buffer.\r
1555 @param[in, out] BnSize On input, the size of big number buffer in bytes.\r
1556 On output, the size of data returned in big number buffer in bytes.\r
1557\r
1558 @retval TRUE RSA key component was retrieved successfully.\r
1559 @retval FALSE Invalid RSA key component tag.\r
1560 @retval FALSE BnSize is too small.\r
532616bb 1561 @retval FALSE This interface is not supported.\r
a8c44645 1562\r
1563**/\r
1564BOOLEAN\r
1565EFIAPI\r
1566RsaGetKey (\r
1567 IN OUT VOID *RsaContext,\r
1568 IN RSA_KEY_TAG KeyTag,\r
1569 OUT UINT8 *BigNumber,\r
1570 IN OUT UINTN *BnSize\r
1571 );\r
1572\r
1573/**\r
1574 Generates RSA key components.\r
1575\r
1576 This function generates RSA key components. It takes RSA public exponent E and\r
1577 length in bits of RSA modulus N as input, and generates all key components.\r
1578 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r
1579\r
1580 Before this function can be invoked, pseudorandom number generator must be correctly\r
1581 initialized by RandomSeed().\r
1582\r
16d2c32c 1583 If RsaContext is NULL, then return FALSE.\r
532616bb 1584 If this interface is not supported, then return FALSE.\r
a8c44645 1585\r
1586 @param[in, out] RsaContext Pointer to RSA context being set.\r
1587 @param[in] ModulusLength Length of RSA modulus N in bits.\r
1588 @param[in] PublicExponent Pointer to RSA public exponent.\r
2ac68e8b 1589 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r
a8c44645 1590\r
1591 @retval TRUE RSA key component was generated successfully.\r
1592 @retval FALSE Invalid RSA key component tag.\r
532616bb 1593 @retval FALSE This interface is not supported.\r
a8c44645 1594\r
1595**/\r
1596BOOLEAN\r
1597EFIAPI\r
1598RsaGenerateKey (\r
1599 IN OUT VOID *RsaContext,\r
1600 IN UINTN ModulusLength,\r
1601 IN CONST UINT8 *PublicExponent,\r
1602 IN UINTN PublicExponentSize\r
1603 );\r
1604\r
1605/**\r
1606 Validates key components of RSA context.\r
952bd229
QL
1607 NOTE: This function performs integrity checks on all the RSA key material, so\r
1608 the RSA key structure must contain all the private key data.\r
a8c44645 1609\r
2998af86 1610 This function validates key components of RSA context in following aspects:\r
a8c44645 1611 - Whether p is a prime\r
1612 - Whether q is a prime\r
1613 - Whether n = p * q\r
1614 - Whether d*e = 1 mod lcm(p-1,q-1)\r
1615\r
16d2c32c 1616 If RsaContext is NULL, then return FALSE.\r
532616bb 1617 If this interface is not supported, then return FALSE.\r
a8c44645 1618\r
1619 @param[in] RsaContext Pointer to RSA context to check.\r
1620\r
1621 @retval TRUE RSA key components are valid.\r
1622 @retval FALSE RSA key components are not valid.\r
532616bb 1623 @retval FALSE This interface is not supported.\r
a8c44645 1624\r
1625**/\r
1626BOOLEAN\r
1627EFIAPI\r
1628RsaCheckKey (\r
1629 IN VOID *RsaContext\r
97f98500
HT
1630 );\r
1631\r
a8c44645 1632/**\r
1633 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r
1634\r
1635 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1636 RSA PKCS#1.\r
1637 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1638 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1639\r
16d2c32c 1640 If RsaContext is NULL, then return FALSE.\r
1641 If MessageHash is NULL, then return FALSE.\r
1642 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r
1643 If SigSize is large enough but Signature is NULL, then return FALSE.\r
532616bb 1644 If this interface is not supported, then return FALSE.\r
a8c44645 1645\r
1646 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1647 @param[in] MessageHash Pointer to octet message hash to be signed.\r
1648 @param[in] HashSize Size of the message hash in bytes.\r
1649 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
1650 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
b7d320f8 1651 On output, the size of data returned in Signature buffer in bytes.\r
a8c44645 1652\r
1653 @retval TRUE Signature successfully generated in PKCS1-v1_5.\r
1654 @retval FALSE Signature generation failed.\r
1655 @retval FALSE SigSize is too small.\r
532616bb 1656 @retval FALSE This interface is not supported.\r
a8c44645 1657\r
1658**/\r
1659BOOLEAN\r
1660EFIAPI\r
1661RsaPkcs1Sign (\r
1662 IN VOID *RsaContext,\r
1663 IN CONST UINT8 *MessageHash,\r
1664 IN UINTN HashSize,\r
1665 OUT UINT8 *Signature,\r
1666 IN OUT UINTN *SigSize\r
1667 );\r
97f98500
HT
1668\r
1669/**\r
1670 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1671 RSA PKCS#1.\r
1672\r
16d2c32c 1673 If RsaContext is NULL, then return FALSE.\r
1674 If MessageHash is NULL, then return FALSE.\r
1675 If Signature is NULL, then return FALSE.\r
1676 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r
97f98500
HT
1677\r
1678 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1679 @param[in] MessageHash Pointer to octet message hash to be checked.\r
a8c44645 1680 @param[in] HashSize Size of the message hash in bytes.\r
97f98500 1681 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r
a8c44645 1682 @param[in] SigSize Size of signature in bytes.\r
97f98500 1683\r
a8c44645 1684 @retval TRUE Valid signature encoded in PKCS1-v1_5.\r
1685 @retval FALSE Invalid signature or invalid RSA context.\r
97f98500
HT
1686\r
1687**/\r
1688BOOLEAN\r
1689EFIAPI\r
1690RsaPkcs1Verify (\r
1691 IN VOID *RsaContext,\r
1692 IN CONST UINT8 *MessageHash,\r
a8c44645 1693 IN UINTN HashSize,\r
8c5720b4 1694 IN CONST UINT8 *Signature,\r
a8c44645 1695 IN UINTN SigSize\r
97f98500
HT
1696 );\r
1697\r
4a567c96 1698/**\r
1699 Retrieve the RSA Private Key from the password-protected PEM key data.\r
1700\r
532616bb 1701 If PemData is NULL, then return FALSE.\r
1702 If RsaContext is NULL, then return FALSE.\r
1703 If this interface is not supported, then return FALSE.\r
1704\r
4a567c96 1705 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
1706 @param[in] PemSize Size of the PEM key data in bytes.\r
1707 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
1708 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1709 RSA private key component. Use RsaFree() function to free the\r
1710 resource.\r
1711\r
4a567c96 1712 @retval TRUE RSA Private Key was retrieved successfully.\r
1713 @retval FALSE Invalid PEM key data or incorrect password.\r
532616bb 1714 @retval FALSE This interface is not supported.\r
4a567c96 1715\r
1716**/\r
1717BOOLEAN\r
1718EFIAPI\r
1719RsaGetPrivateKeyFromPem (\r
1720 IN CONST UINT8 *PemData,\r
1721 IN UINTN PemSize,\r
1722 IN CONST CHAR8 *Password,\r
1723 OUT VOID **RsaContext\r
1724 );\r
1725\r
1726/**\r
1727 Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r
1728\r
532616bb 1729 If Cert is NULL, then return FALSE.\r
1730 If RsaContext is NULL, then return FALSE.\r
1731 If this interface is not supported, then return FALSE.\r
1732\r
4a567c96 1733 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1734 @param[in] CertSize Size of the X509 certificate in bytes.\r
1735 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1736 RSA public key component. Use RsaFree() function to free the\r
1737 resource.\r
1738\r
4a567c96 1739 @retval TRUE RSA Public Key was retrieved successfully.\r
1740 @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r
532616bb 1741 @retval FALSE This interface is not supported.\r
4a567c96 1742\r
1743**/\r
1744BOOLEAN\r
1745EFIAPI\r
1746RsaGetPublicKeyFromX509 (\r
1747 IN CONST UINT8 *Cert,\r
1748 IN UINTN CertSize,\r
1749 OUT VOID **RsaContext\r
1750 );\r
1751\r
1752/**\r
1753 Retrieve the subject bytes from one X.509 certificate.\r
1754\r
532616bb 1755 If Cert is NULL, then return FALSE.\r
1756 If SubjectSize is NULL, then return FALSE.\r
1757 If this interface is not supported, then return FALSE.\r
1758\r
4a567c96 1759 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1760 @param[in] CertSize Size of the X509 certificate in bytes.\r
1761 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r
1762 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r
1763 and the size of buffer returned CertSubject on output.\r
1764\r
4a567c96 1765 @retval TRUE The certificate subject retrieved successfully.\r
1766 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r
1767 The SubjectSize will be updated with the required size.\r
532616bb 1768 @retval FALSE This interface is not supported.\r
4a567c96 1769\r
1770**/\r
1771BOOLEAN\r
1772EFIAPI\r
1773X509GetSubjectName (\r
1774 IN CONST UINT8 *Cert,\r
1775 IN UINTN CertSize,\r
1776 OUT UINT8 *CertSubject,\r
1777 IN OUT UINTN *SubjectSize\r
1778 );\r
1779\r
5b7c2245
QL
1780/**\r
1781 Retrieve the common name (CN) string from one X.509 certificate.\r
1782\r
1783 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1784 @param[in] CertSize Size of the X509 certificate in bytes.\r
1785 @param[out] CommonName Buffer to contain the retrieved certificate common\r
0b6457ef 1786 name string (UTF8). At most CommonNameSize bytes will be\r
5b7c2245
QL
1787 written and the string will be null terminated. May be\r
1788 NULL in order to determine the size buffer needed.\r
1789 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
1790 and the size of buffer returned CommonName on output.\r
1791 If CommonName is NULL then the amount of space needed\r
1792 in buffer (including the final null) is returned.\r
1793\r
1794 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r
1795 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1796 If CommonNameSize is NULL.\r
1797 If CommonName is not NULL and *CommonNameSize is 0.\r
1798 If Certificate is invalid.\r
1799 @retval RETURN_NOT_FOUND If no CommonName entry exists.\r
1800 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r
630f67dd 1801 (including the final null) is returned in the\r
5b7c2245
QL
1802 CommonNameSize parameter.\r
1803 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1804\r
1805**/\r
1806RETURN_STATUS\r
1807EFIAPI\r
1808X509GetCommonName (\r
1809 IN CONST UINT8 *Cert,\r
1810 IN UINTN CertSize,\r
1811 OUT CHAR8 *CommonName, OPTIONAL\r
1812 IN OUT UINTN *CommonNameSize\r
1813 );\r
1814\r
e2a673b8
BB
1815/**\r
1816 Retrieve the organization name (O) string from one X.509 certificate.\r
1817\r
1818 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1819 @param[in] CertSize Size of the X509 certificate in bytes.\r
1820 @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r
1821 name string. At most NameBufferSize bytes will be\r
1822 written and the string will be null terminated. May be\r
1823 NULL in order to determine the size buffer needed.\r
1824 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r
1825 and the size of buffer returned Name on output.\r
1826 If NameBuffer is NULL then the amount of space needed\r
1827 in buffer (including the final null) is returned.\r
1828\r
1829 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r
1830 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1831 If NameBufferSize is NULL.\r
1832 If NameBuffer is not NULL and *CommonNameSize is 0.\r
1833 If Certificate is invalid.\r
1834 @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r
1835 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r
1836 (including the final null) is returned in the\r
1837 CommonNameSize parameter.\r
1838 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1839\r
1840**/\r
1841RETURN_STATUS\r
1842EFIAPI\r
1843X509GetOrganizationName (\r
1844 IN CONST UINT8 *Cert,\r
1845 IN UINTN CertSize,\r
1846 OUT CHAR8 *NameBuffer, OPTIONAL\r
1847 IN OUT UINTN *NameBufferSize\r
1848 );\r
1849\r
4a567c96 1850/**\r
1851 Verify one X509 certificate was issued by the trusted CA.\r
1852\r
532616bb 1853 If Cert is NULL, then return FALSE.\r
1854 If CACert is NULL, then return FALSE.\r
1855 If this interface is not supported, then return FALSE.\r
1856\r
4a567c96 1857 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r
1858 @param[in] CertSize Size of the X509 certificate in bytes.\r
1859 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r
1860 @param[in] CACertSize Size of the CA Certificate in bytes.\r
1861\r
4a567c96 1862 @retval TRUE The certificate was issued by the trusted CA.\r
1863 @retval FALSE Invalid certificate or the certificate was not issued by the given\r
1864 trusted CA.\r
532616bb 1865 @retval FALSE This interface is not supported.\r
4a567c96 1866\r
1867**/\r
1868BOOLEAN\r
1869EFIAPI\r
1870X509VerifyCert (\r
1871 IN CONST UINT8 *Cert,\r
1872 IN UINTN CertSize,\r
1873 IN CONST UINT8 *CACert,\r
1874 IN UINTN CACertSize\r
1875 );\r
1876\r
b7d320f8 1877/**\r
1878 Construct a X509 object from DER-encoded certificate data.\r
1879\r
16d2c32c 1880 If Cert is NULL, then return FALSE.\r
1881 If SingleX509Cert is NULL, then return FALSE.\r
532616bb 1882 If this interface is not supported, then return FALSE.\r
b7d320f8 1883\r
1884 @param[in] Cert Pointer to the DER-encoded certificate data.\r
1885 @param[in] CertSize The size of certificate data in bytes.\r
1886 @param[out] SingleX509Cert The generated X509 object.\r
1887\r
1888 @retval TRUE The X509 object generation succeeded.\r
1889 @retval FALSE The operation failed.\r
532616bb 1890 @retval FALSE This interface is not supported.\r
b7d320f8 1891\r
1892**/\r
1893BOOLEAN\r
1894EFIAPI\r
1895X509ConstructCertificate (\r
1896 IN CONST UINT8 *Cert,\r
1897 IN UINTN CertSize,\r
1898 OUT UINT8 **SingleX509Cert\r
1899 );\r
1900\r
66862136
MK
1901/**\r
1902 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1903\r
1904 If X509Stack is NULL, then return FALSE.\r
1905 If this interface is not supported, then return FALSE.\r
1906\r
1907 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
1908 On output, pointer to the X509 stack object with new\r
1909 inserted X509 certificate.\r
1910 @param[in] Args VA_LIST marker for the variable argument list.\r
1911 A list of DER-encoded single certificate data followed\r
1912 by certificate size. A NULL terminates the list. The\r
1913 pairs are the arguments to X509ConstructCertificate().\r
1914\r
1915 @retval TRUE The X509 stack construction succeeded.\r
1916 @retval FALSE The construction operation failed.\r
1917 @retval FALSE This interface is not supported.\r
1918\r
1919**/\r
1920BOOLEAN\r
1921EFIAPI\r
1922X509ConstructCertificateStackV (\r
1923 IN OUT UINT8 **X509Stack,\r
1924 IN VA_LIST Args\r
1925 );\r
1926\r
b7d320f8 1927/**\r
1928 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1929\r
16d2c32c 1930 If X509Stack is NULL, then return FALSE.\r
532616bb 1931 If this interface is not supported, then return FALSE.\r
b7d320f8 1932\r
952bd229 1933 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
b7d320f8 1934 On output, pointer to the X509 stack object with new\r
1935 inserted X509 certificate.\r
1936 @param ... A list of DER-encoded single certificate data followed\r
1937 by certificate size. A NULL terminates the list. The\r
1938 pairs are the arguments to X509ConstructCertificate().\r
2ac68e8b 1939\r
b7d320f8 1940 @retval TRUE The X509 stack construction succeeded.\r
1941 @retval FALSE The construction operation failed.\r
532616bb 1942 @retval FALSE This interface is not supported.\r
b7d320f8 1943\r
1944**/\r
1945BOOLEAN\r
1946EFIAPI\r
1947X509ConstructCertificateStack (\r
1948 IN OUT UINT8 **X509Stack,\r
2ac68e8b 1949 ...\r
b7d320f8 1950 );\r
1951\r
1952/**\r
1953 Release the specified X509 object.\r
1954\r
532616bb 1955 If the interface is not supported, then ASSERT().\r
b7d320f8 1956\r
1957 @param[in] X509Cert Pointer to the X509 object to be released.\r
1958\r
1959**/\r
1960VOID\r
1961EFIAPI\r
1962X509Free (\r
1963 IN VOID *X509Cert\r
1964 );\r
1965\r
1966/**\r
1967 Release the specified X509 stack object.\r
1968\r
532616bb 1969 If the interface is not supported, then ASSERT().\r
b7d320f8 1970\r
1971 @param[in] X509Stack Pointer to the X509 stack object to be released.\r
1972\r
1973**/\r
1974VOID\r
1975EFIAPI\r
1976X509StackFree (\r
1977 IN VOID *X509Stack\r
1978 );\r
1979\r
12d95665
LQ
1980/**\r
1981 Retrieve the TBSCertificate from one given X.509 certificate.\r
1982\r
1983 @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r
1984 @param[in] CertSize Size of the X509 certificate in bytes.\r
1985 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r
1986 @param[out] TBSCertSize Size of the TBS certificate in bytes.\r
1987\r
1988 If Cert is NULL, then return FALSE.\r
1989 If TBSCert is NULL, then return FALSE.\r
1990 If TBSCertSize is NULL, then return FALSE.\r
1991 If this interface is not supported, then return FALSE.\r
1992\r
1993 @retval TRUE The TBSCertificate was retrieved successfully.\r
1994 @retval FALSE Invalid X.509 certificate.\r
1995\r
1996**/\r
1997BOOLEAN\r
1998EFIAPI\r
1999X509GetTBSCert (\r
2000 IN CONST UINT8 *Cert,\r
2001 IN UINTN CertSize,\r
2002 OUT UINT8 **TBSCert,\r
2003 OUT UINTN *TBSCertSize\r
2004 );\r
2005\r
a8f37449
QL
2006/**\r
2007 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r
2008 password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r
2009\r
2010 If Password or Salt or OutKey is NULL, then return FALSE.\r
2011 If the hash algorithm could not be determined, then return FALSE.\r
2012 If this interface is not supported, then return FALSE.\r
2013\r
2014 @param[in] PasswordLength Length of input password in bytes.\r
2015 @param[in] Password Pointer to the array for the password.\r
2016 @param[in] SaltLength Size of the Salt in bytes.\r
2017 @param[in] Salt Pointer to the Salt.\r
2018 @param[in] IterationCount Number of iterations to perform. Its value should be\r
2019 greater than or equal to 1.\r
2020 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r
2021 NOTE: DigestSize will be used to determine the hash algorithm.\r
2022 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r
2023 @param[in] KeyLength Size of the derived key buffer in bytes.\r
2024 @param[out] OutKey Pointer to the output derived key buffer.\r
2025\r
2026 @retval TRUE A key was derived successfully.\r
2027 @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r
2028 @retval FALSE The hash algorithm could not be determined from the digest size.\r
2029 @retval FALSE The key derivation operation failed.\r
2030 @retval FALSE This interface is not supported.\r
2031\r
2032**/\r
2033BOOLEAN\r
2034EFIAPI\r
2035Pkcs5HashPassword (\r
2036 IN UINTN PasswordLength,\r
2037 IN CONST CHAR8 *Password,\r
2038 IN UINTN SaltLength,\r
2039 IN CONST UINT8 *Salt,\r
2040 IN UINTN IterationCount,\r
2041 IN UINTN DigestSize,\r
2042 IN UINTN KeyLength,\r
2043 OUT UINT8 *OutKey\r
2044 );\r
2045\r
aed90bee
BB
2046/**\r
2047 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r
2048 encrypted message in a newly allocated buffer.\r
2049\r
2050 Things that can cause a failure include:\r
2051 - X509 key size does not match any known key size.\r
2052 - Fail to parse X509 certificate.\r
2053 - Fail to allocate an intermediate buffer.\r
2054 - Null pointer provided for a non-optional parameter.\r
2055 - Data size is too large for the provided key size (max size is a function of key size\r
2056 and hash digest size).\r
2057\r
2058 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r
2059 will be used to encrypt the data.\r
2060 @param[in] PublicKeySize Size of the X509 cert buffer.\r
2061 @param[in] InData Data to be encrypted.\r
2062 @param[in] InDataSize Size of the data buffer.\r
2063 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r
2064 to be used when initializing the PRNG. NULL otherwise.\r
2065 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r
2066 0 otherwise.\r
2067 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r
2068 message.\r
2069 @param[out] EncryptedDataSize Size of the encrypted message buffer.\r
2070\r
2071 @retval TRUE Encryption was successful.\r
2072 @retval FALSE Encryption failed.\r
2073\r
2074**/\r
2075BOOLEAN\r
2076EFIAPI\r
2077Pkcs1v2Encrypt (\r
2078 IN CONST UINT8 *PublicKey,\r
2079 IN UINTN PublicKeySize,\r
2080 IN UINT8 *InData,\r
2081 IN UINTN InDataSize,\r
2082 IN CONST UINT8 *PrngSeed, OPTIONAL\r
2083 IN UINTN PrngSeedSize, OPTIONAL\r
2084 OUT UINT8 **EncryptedData,\r
2085 OUT UINTN *EncryptedDataSize\r
2086 );\r
2087\r
3702637a 2088/**\r
2089 The 3rd parameter of Pkcs7GetSigners will return all embedded\r
2090 X.509 certificate in one given PKCS7 signature. The format is:\r
2091 //\r
2092 // UINT8 CertNumber;\r
2093 // UINT32 Cert1Length;\r
2094 // UINT8 Cert1[];\r
2095 // UINT32 Cert2Length;\r
2096 // UINT8 Cert2[];\r
2097 // ...\r
2098 // UINT32 CertnLength;\r
2099 // UINT8 Certn[];\r
2100 //\r
2101\r
2102 The two following C-structure are used for parsing CertStack more clearly.\r
2103**/\r
2104#pragma pack(1)\r
2105\r
2106typedef struct {\r
2107 UINT32 CertDataLength; // The length in bytes of X.509 certificate.\r
2108 UINT8 CertDataBuffer[0]; // The X.509 certificate content (DER).\r
2109} EFI_CERT_DATA;\r
2110\r
2111typedef struct {\r
2112 UINT8 CertNumber; // Number of X.509 certificate.\r
2113 //EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.\r
2114} EFI_CERT_STACK;\r
2115\r
2116#pragma pack()\r
2117\r
e8b4eb04 2118/**\r
2119 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r
2120 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2121 in a ContentInfo structure.\r
2122\r
2123 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r
2998af86 2124 return FALSE. If P7Length overflow, then return FALSE.\r
532616bb 2125 If this interface is not supported, then return FALSE.\r
e8b4eb04 2126\r
2127 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
2128 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2129 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r
6fe575d0
LQ
2130 It's caller's responsibility to free the buffer with\r
2131 Pkcs7FreeSigners().\r
3702637a 2132 This data structure is EFI_CERT_STACK type.\r
e8b4eb04 2133 @param[out] StackLength Length of signer's certificates in bytes.\r
2134 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r
6fe575d0
LQ
2135 It's caller's responsibility to free the buffer with\r
2136 Pkcs7FreeSigners().\r
e8b4eb04 2137 @param[out] CertLength Length of the trusted certificate in bytes.\r
2138\r
2139 @retval TRUE The operation is finished successfully.\r
2140 @retval FALSE Error occurs during the operation.\r
532616bb 2141 @retval FALSE This interface is not supported.\r
e8b4eb04 2142\r
2143**/\r
2144BOOLEAN\r
2145EFIAPI\r
2146Pkcs7GetSigners (\r
2147 IN CONST UINT8 *P7Data,\r
2148 IN UINTN P7Length,\r
2149 OUT UINT8 **CertStack,\r
2150 OUT UINTN *StackLength,\r
2151 OUT UINT8 **TrustedCert,\r
2152 OUT UINTN *CertLength\r
2153 );\r
2154\r
2155/**\r
2156 Wrap function to use free() to free allocated memory for certificates.\r
2157\r
532616bb 2158 If this interface is not supported, then ASSERT().\r
2159\r
e8b4eb04 2160 @param[in] Certs Pointer to the certificates to be freed.\r
2161\r
2162**/\r
2163VOID\r
2164EFIAPI\r
2165Pkcs7FreeSigners (\r
2166 IN UINT8 *Certs\r
45419de6
QL
2167 );\r
2168\r
2169/**\r
2170 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r
2171 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r
2172 unchained to the signer's certificates.\r
2173 The input signed data could be wrapped in a ContentInfo structure.\r
2174\r
2175 @param[in] P7Data Pointer to the PKCS#7 message.\r
2176 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
0f5f6b3d 2177 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r
6fe575d0
LQ
2178 certificate. It's caller's responsibility to free the buffer\r
2179 with Pkcs7FreeSigners().\r
3702637a 2180 This data structure is EFI_CERT_STACK type.\r
45419de6
QL
2181 @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r
2182 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r
6fe575d0 2183 responsibility to free the buffer with Pkcs7FreeSigners().\r
3702637a 2184 This data structure is EFI_CERT_STACK type.\r
45419de6
QL
2185 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r
2186\r
2187 @retval TRUE The operation is finished successfully.\r
2188 @retval FALSE Error occurs during the operation.\r
2189\r
2190**/\r
2191BOOLEAN\r
2192EFIAPI\r
2193Pkcs7GetCertificatesList (\r
2194 IN CONST UINT8 *P7Data,\r
2195 IN UINTN P7Length,\r
2196 OUT UINT8 **SignerChainCerts,\r
2197 OUT UINTN *ChainLength,\r
2198 OUT UINT8 **UnchainCerts,\r
2199 OUT UINTN *UnchainLength\r
e8b4eb04 2200 );\r
2201\r
b7d320f8 2202/**\r
2203 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
2204 Syntax Standard, version 1.5". This interface is only intended to be used for\r
2205 application to perform PKCS#7 functionality validation.\r
2206\r
532616bb 2207 If this interface is not supported, then return FALSE.\r
2208\r
b7d320f8 2209 @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r
2210 data signing.\r
2211 @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r
2212 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r
2213 key data.\r
2214 @param[in] InData Pointer to the content to be signed.\r
2215 @param[in] InDataSize Size of InData in bytes.\r
2216 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r
2217 @param[in] OtherCerts Pointer to an optional additional set of certificates to\r
2218 include in the PKCS#7 signedData (e.g. any intermediate\r
2219 CAs in the chain).\r
6fe575d0
LQ
2220 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r
2221 responsibility to free the buffer with FreePool().\r
b7d320f8 2222 @param[out] SignedDataSize Size of SignedData in bytes.\r
2223\r
2224 @retval TRUE PKCS#7 data signing succeeded.\r
2225 @retval FALSE PKCS#7 data signing failed.\r
532616bb 2226 @retval FALSE This interface is not supported.\r
b7d320f8 2227\r
2228**/\r
2229BOOLEAN\r
2230EFIAPI\r
2231Pkcs7Sign (\r
2232 IN CONST UINT8 *PrivateKey,\r
2233 IN UINTN PrivateKeySize,\r
2234 IN CONST UINT8 *KeyPassword,\r
2235 IN UINT8 *InData,\r
2236 IN UINTN InDataSize,\r
2237 IN UINT8 *SignCert,\r
2238 IN UINT8 *OtherCerts OPTIONAL,\r
2239 OUT UINT8 **SignedData,\r
2240 OUT UINTN *SignedDataSize\r
2241 );\r
2242\r
97f98500 2243/**\r
2998af86 2244 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r
e8b4eb04 2245 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2246 in a ContentInfo structure.\r
97f98500 2247\r
e8b4eb04 2248 If P7Data, TrustedCert or InData is NULL, then return FALSE.\r
2998af86 2249 If P7Length, CertLength or DataLength overflow, then return FALSE.\r
532616bb 2250 If this interface is not supported, then return FALSE.\r
97f98500
HT
2251\r
2252 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
e8b4eb04 2253 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
97f98500
HT
2254 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2255 is used for certificate chain verification.\r
e8b4eb04 2256 @param[in] CertLength Length of the trusted certificate in bytes.\r
97f98500 2257 @param[in] InData Pointer to the content to be verified.\r
e8b4eb04 2258 @param[in] DataLength Length of InData in bytes.\r
97f98500 2259\r
a8c44645 2260 @retval TRUE The specified PKCS#7 signed data is valid.\r
2261 @retval FALSE Invalid PKCS#7 signed data.\r
532616bb 2262 @retval FALSE This interface is not supported.\r
97f98500
HT
2263\r
2264**/\r
2265BOOLEAN\r
2266EFIAPI\r
2267Pkcs7Verify (\r
2268 IN CONST UINT8 *P7Data,\r
e8b4eb04 2269 IN UINTN P7Length,\r
97f98500 2270 IN CONST UINT8 *TrustedCert,\r
e8b4eb04 2271 IN UINTN CertLength,\r
97f98500 2272 IN CONST UINT8 *InData,\r
e8b4eb04 2273 IN UINTN DataLength\r
a8c44645 2274 );\r
2275\r
1796a394
BB
2276/**\r
2277 This function receives a PKCS7 formatted signature, and then verifies that\r
2278 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r
2279 leaf signing certificate.\r
2280 Note that this function does not validate the certificate chain.\r
2281\r
2282 Applications for custom EKU's are quite flexible. For example, a policy EKU\r
2283 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r
2284 certificate issued might also contain this EKU, thus constraining the\r
2285 sub-ordinate certificate. Other applications might allow a certificate\r
2286 embedded in a device to specify that other Object Identifiers (OIDs) are\r
2287 present which contains binary data specifying custom capabilities that\r
2288 the device is able to do.\r
2289\r
2290 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r
2291 containing the content block with both the signature,\r
2292 the signer's certificate, and any necessary intermediate\r
2293 certificates.\r
2294 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r
2295 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r
2296 required EKUs that must be present in the signature.\r
2297 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r
2298 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r
2299 must be present in the leaf signer. If it is\r
2300 FALSE, then we will succeed if we find any\r
2301 of the specified EKU's.\r
2302\r
2303 @retval EFI_SUCCESS The required EKUs were found in the signature.\r
2304 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
2305 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r
2306\r
2307**/\r
2308RETURN_STATUS\r
2309EFIAPI\r
2310VerifyEKUsInPkcs7Signature (\r
2311 IN CONST UINT8 *Pkcs7Signature,\r
2312 IN CONST UINT32 SignatureSize,\r
2313 IN CONST CHAR8 *RequiredEKUs[],\r
2314 IN CONST UINT32 RequiredEKUsSize,\r
2315 IN BOOLEAN RequireAllPresent\r
2316 );\r
2317\r
afeb55e4
QL
2318/**\r
2319 Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r
2320 data could be wrapped in a ContentInfo structure.\r
2321\r
2322 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r
2998af86 2323 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r
afeb55e4
QL
2324\r
2325 Caution: This function may receive untrusted input. So this function will do\r
2326 basic check for PKCS#7 data structure.\r
2327\r
2328 @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r
2329 @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r
2330 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r
6fe575d0 2331 It's caller's responsibility to free the buffer with FreePool().\r
afeb55e4
QL
2332 @param[out] ContentSize The size of the extracted content in bytes.\r
2333\r
2334 @retval TRUE The P7Data was correctly formatted for processing.\r
2335 @retval FALSE The P7Data was not correctly formatted for processing.\r
2336\r
0c9fc4b1 2337**/\r
afeb55e4
QL
2338BOOLEAN\r
2339EFIAPI\r
2340Pkcs7GetAttachedContent (\r
2341 IN CONST UINT8 *P7Data,\r
2342 IN UINTN P7Length,\r
2343 OUT VOID **Content,\r
2344 OUT UINTN *ContentSize\r
2345 );\r
2346\r
b7d320f8 2347/**\r
2998af86 2348 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r
b7d320f8 2349 Authenticode Portable Executable Signature Format".\r
2350\r
16d2c32c 2351 If AuthData is NULL, then return FALSE.\r
2352 If ImageHash is NULL, then return FALSE.\r
532616bb 2353 If this interface is not supported, then return FALSE.\r
b7d320f8 2354\r
2355 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2356 PE/COFF image to be verified.\r
2357 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2358 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2359 is used for certificate chain verification.\r
2360 @param[in] CertSize Size of the trusted certificate in bytes.\r
2998af86 2361 @param[in] ImageHash Pointer to the original image file hash value. The procedure\r
b7d320f8 2362 for calculating the image hash value is described in Authenticode\r
2363 specification.\r
2364 @param[in] HashSize Size of Image hash value in bytes.\r
2365\r
2366 @retval TRUE The specified Authenticode Signature is valid.\r
2367 @retval FALSE Invalid Authenticode Signature.\r
532616bb 2368 @retval FALSE This interface is not supported.\r
b7d320f8 2369\r
2370**/\r
2371BOOLEAN\r
2372EFIAPI\r
2373AuthenticodeVerify (\r
2374 IN CONST UINT8 *AuthData,\r
2375 IN UINTN DataSize,\r
2376 IN CONST UINT8 *TrustedCert,\r
2377 IN UINTN CertSize,\r
2378 IN CONST UINT8 *ImageHash,\r
2379 IN UINTN HashSize\r
2380 );\r
2381\r
2ac68e8b 2382/**\r
2998af86 2383 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r
2ac68e8b
QL
2384 signature.\r
2385\r
2386 If AuthData is NULL, then return FALSE.\r
12d95665 2387 If this interface is not supported, then return FALSE.\r
2ac68e8b
QL
2388\r
2389 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2390 PE/COFF image to be verified.\r
2391 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2392 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r
2393 is used for TSA certificate chain verification.\r
2394 @param[in] CertSize Size of the trusted certificate in bytes.\r
2395 @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r
2396 signature is valid.\r
2397\r
2398 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r
2399 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r
2400\r
2401**/\r
2402BOOLEAN\r
2403EFIAPI\r
2404ImageTimestampVerify (\r
2405 IN CONST UINT8 *AuthData,\r
2406 IN UINTN DataSize,\r
2407 IN CONST UINT8 *TsaCert,\r
2408 IN UINTN CertSize,\r
2409 OUT EFI_TIME *SigningTime\r
2410 );\r
2411\r
a8c44645 2412//=====================================================================================\r
2413// DH Key Exchange Primitive\r
2414//=====================================================================================\r
2415\r
2416/**\r
2417 Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r
2418\r
2419 @return Pointer to the Diffie-Hellman Context that has been initialized.\r
2420 If the allocations fails, DhNew() returns NULL.\r
532616bb 2421 If the interface is not supported, DhNew() returns NULL.\r
a8c44645 2422\r
2423**/\r
2424VOID *\r
2425EFIAPI\r
2426DhNew (\r
2427 VOID\r
2428 );\r
2429\r
2430/**\r
2431 Release the specified DH context.\r
2432\r
532616bb 2433 If the interface is not supported, then ASSERT().\r
a8c44645 2434\r
2435 @param[in] DhContext Pointer to the DH context to be released.\r
2436\r
2437**/\r
2438VOID\r
2439EFIAPI\r
2440DhFree (\r
2441 IN VOID *DhContext\r
2442 );\r
2443\r
2444/**\r
2445 Generates DH parameter.\r
2446\r
2447 Given generator g, and length of prime number p in bits, this function generates p,\r
2448 and sets DH context according to value of g and p.\r
2ac68e8b 2449\r
a8c44645 2450 Before this function can be invoked, pseudorandom number generator must be correctly\r
2451 initialized by RandomSeed().\r
2452\r
16d2c32c 2453 If DhContext is NULL, then return FALSE.\r
2454 If Prime is NULL, then return FALSE.\r
532616bb 2455 If this interface is not supported, then return FALSE.\r
a8c44645 2456\r
2457 @param[in, out] DhContext Pointer to the DH context.\r
2458 @param[in] Generator Value of generator.\r
2459 @param[in] PrimeLength Length in bits of prime to be generated.\r
2460 @param[out] Prime Pointer to the buffer to receive the generated prime number.\r
2461\r
2998af86 2462 @retval TRUE DH parameter generation succeeded.\r
a8c44645 2463 @retval FALSE Value of Generator is not supported.\r
2464 @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r
532616bb 2465 @retval FALSE This interface is not supported.\r
a8c44645 2466\r
2467**/\r
2468BOOLEAN\r
2469EFIAPI\r
2470DhGenerateParameter (\r
2471 IN OUT VOID *DhContext,\r
2472 IN UINTN Generator,\r
2473 IN UINTN PrimeLength,\r
2474 OUT UINT8 *Prime\r
2475 );\r
2476\r
2477/**\r
2478 Sets generator and prime parameters for DH.\r
2479\r
2480 Given generator g, and prime number p, this function and sets DH\r
2481 context accordingly.\r
2482\r
16d2c32c 2483 If DhContext is NULL, then return FALSE.\r
2484 If Prime is NULL, then return FALSE.\r
532616bb 2485 If this interface is not supported, then return FALSE.\r
a8c44645 2486\r
2487 @param[in, out] DhContext Pointer to the DH context.\r
2488 @param[in] Generator Value of generator.\r
2489 @param[in] PrimeLength Length in bits of prime to be generated.\r
2490 @param[in] Prime Pointer to the prime number.\r
2491\r
2998af86 2492 @retval TRUE DH parameter setting succeeded.\r
a8c44645 2493 @retval FALSE Value of Generator is not supported.\r
2494 @retval FALSE Value of Generator is not suitable for the Prime.\r
2495 @retval FALSE Value of Prime is not a prime number.\r
2496 @retval FALSE Value of Prime is not a safe prime number.\r
532616bb 2497 @retval FALSE This interface is not supported.\r
a8c44645 2498\r
2499**/\r
2500BOOLEAN\r
2501EFIAPI\r
2502DhSetParameter (\r
2503 IN OUT VOID *DhContext,\r
2504 IN UINTN Generator,\r
2505 IN UINTN PrimeLength,\r
2506 IN CONST UINT8 *Prime\r
97f98500
HT
2507 );\r
2508\r
a8c44645 2509/**\r
2510 Generates DH public key.\r
2511\r
2ac68e8b 2512 This function generates random secret exponent, and computes the public key, which is\r
a8c44645 2513 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r
2514 If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r
2515 PublicKeySize is set to the required buffer size to obtain the public key.\r
2516\r
16d2c32c 2517 If DhContext is NULL, then return FALSE.\r
2518 If PublicKeySize is NULL, then return FALSE.\r
2519 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r
532616bb 2520 If this interface is not supported, then return FALSE.\r
a8c44645 2521\r
2522 @param[in, out] DhContext Pointer to the DH context.\r
2523 @param[out] PublicKey Pointer to the buffer to receive generated public key.\r
2524 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r
2525 On output, the size of data returned in PublicKey buffer in bytes.\r
2526\r
2527 @retval TRUE DH public key generation succeeded.\r
2528 @retval FALSE DH public key generation failed.\r
2529 @retval FALSE PublicKeySize is not large enough.\r
532616bb 2530 @retval FALSE This interface is not supported.\r
a8c44645 2531\r
2532**/\r
2533BOOLEAN\r
2534EFIAPI\r
2535DhGenerateKey (\r
2536 IN OUT VOID *DhContext,\r
2537 OUT UINT8 *PublicKey,\r
2538 IN OUT UINTN *PublicKeySize\r
2539 );\r
2540\r
2541/**\r
2542 Computes exchanged common key.\r
2543\r
2544 Given peer's public key, this function computes the exchanged common key, based on its own\r
dda39f3a 2545 context including value of prime modulus and random secret exponent.\r
a8c44645 2546\r
16d2c32c 2547 If DhContext is NULL, then return FALSE.\r
2548 If PeerPublicKey is NULL, then return FALSE.\r
2549 If KeySize is NULL, then return FALSE.\r
dda39f3a 2550 If Key is NULL, then return FALSE.\r
2551 If KeySize is not large enough, then return FALSE.\r
532616bb 2552 If this interface is not supported, then return FALSE.\r
a8c44645 2553\r
2554 @param[in, out] DhContext Pointer to the DH context.\r
2555 @param[in] PeerPublicKey Pointer to the peer's public key.\r
2556 @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r
2557 @param[out] Key Pointer to the buffer to receive generated key.\r
2558 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
2559 On output, the size of data returned in Key buffer in bytes.\r
2560\r
2561 @retval TRUE DH exchanged key generation succeeded.\r
2562 @retval FALSE DH exchanged key generation failed.\r
2563 @retval FALSE KeySize is not large enough.\r
532616bb 2564 @retval FALSE This interface is not supported.\r
a8c44645 2565\r
2566**/\r
2567BOOLEAN\r
2568EFIAPI\r
2569DhComputeKey (\r
2570 IN OUT VOID *DhContext,\r
2571 IN CONST UINT8 *PeerPublicKey,\r
2572 IN UINTN PeerPublicKeySize,\r
2573 OUT UINT8 *Key,\r
2574 IN OUT UINTN *KeySize\r
2575 );\r
2576\r
2577//=====================================================================================\r
2578// Pseudo-Random Generation Primitive\r
2579//=====================================================================================\r
2580\r
2581/**\r
2582 Sets up the seed value for the pseudorandom number generator.\r
2583\r
2584 This function sets up the seed value for the pseudorandom number generator.\r
2585 If Seed is not NULL, then the seed passed in is used.\r
2586 If Seed is NULL, then default seed is used.\r
532616bb 2587 If this interface is not supported, then return FALSE.\r
a8c44645 2588\r
2589 @param[in] Seed Pointer to seed value.\r
2590 If NULL, default seed is used.\r
2591 @param[in] SeedSize Size of seed value.\r
2592 If Seed is NULL, this parameter is ignored.\r
2593\r
2594 @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r
2595 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r
532616bb 2596 @retval FALSE This interface is not supported.\r
a8c44645 2597\r
2598**/\r
2599BOOLEAN\r
2600EFIAPI\r
2601RandomSeed (\r
2602 IN CONST UINT8 *Seed OPTIONAL,\r
2603 IN UINTN SeedSize\r
2604 );\r
2605\r
2606/**\r
2607 Generates a pseudorandom byte stream of the specified size.\r
2608\r
16d2c32c 2609 If Output is NULL, then return FALSE.\r
532616bb 2610 If this interface is not supported, then return FALSE.\r
a8c44645 2611\r
2612 @param[out] Output Pointer to buffer to receive random value.\r
2998af86 2613 @param[in] Size Size of random bytes to generate.\r
a8c44645 2614\r
2615 @retval TRUE Pseudorandom byte stream generated successfully.\r
2616 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r
532616bb 2617 @retval FALSE This interface is not supported.\r
a8c44645 2618\r
2619**/\r
2620BOOLEAN\r
2621EFIAPI\r
2622RandomBytes (\r
2623 OUT UINT8 *Output,\r
2624 IN UINTN Size\r
2625 );\r
97f98500 2626\r
4b1b7c19
GW
2627//=====================================================================================\r
2628// Key Derivation Function Primitive\r
2629//=====================================================================================\r
2630\r
2631/**\r
2632 Derive key data using HMAC-SHA256 based KDF.\r
2633\r
2634 @param[in] Key Pointer to the user-supplied key.\r
2635 @param[in] KeySize Key size in bytes.\r
2636 @param[in] Salt Pointer to the salt(non-secret) value.\r
2637 @param[in] SaltSize Salt size in bytes.\r
2638 @param[in] Info Pointer to the application specific info.\r
2639 @param[in] InfoSize Info size in bytes.\r
944bd5cf 2640 @param[out] Out Pointer to buffer to receive hkdf value.\r
4b1b7c19
GW
2641 @param[in] OutSize Size of hkdf bytes to generate.\r
2642\r
2643 @retval TRUE Hkdf generated successfully.\r
2644 @retval FALSE Hkdf generation failed.\r
2645\r
2646**/\r
2647BOOLEAN\r
2648EFIAPI\r
2649HkdfSha256ExtractAndExpand (\r
2650 IN CONST UINT8 *Key,\r
2651 IN UINTN KeySize,\r
2652 IN CONST UINT8 *Salt,\r
2653 IN UINTN SaltSize,\r
2654 IN CONST UINT8 *Info,\r
2655 IN UINTN InfoSize,\r
2656 OUT UINT8 *Out,\r
2657 IN UINTN OutSize\r
2658 );\r
2659\r
afeb55e4 2660#endif // __BASE_CRYPT_LIB_H__\r