]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Include/Library/BaseCryptLib.h
IntelFsp2Pkg/FspSecCore: Use UefiCpuLib.
[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-SHA256 use.\r
885\r
886 @return Pointer to the HMAC_CTX context that has been initialized.\r
887 If the allocations fails, HmacSha256New() returns NULL.\r
888\r
889**/\r
890VOID *\r
891EFIAPI\r
892HmacSha256New (\r
893 VOID\r
894 );\r
895\r
896/**\r
897 Release the specified HMAC_CTX context.\r
898\r
899 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.\r
900\r
901**/\r
902VOID\r
903EFIAPI\r
904HmacSha256Free (\r
905 IN VOID *HmacSha256Ctx\r
906 );\r
907\r
72009c62 908/**\r
a23fdff6
JW
909 Set user-supplied key for subsequent use. It must be done before any\r
910 calling to HmacSha256Update().\r
72009c62
QL
911\r
912 If HmacSha256Context is NULL, then return FALSE.\r
913 If this interface is not supported, then return FALSE.\r
914\r
a23fdff6 915 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.\r
72009c62
QL
916 @param[in] Key Pointer to the user-supplied key.\r
917 @param[in] KeySize Key size in bytes.\r
918\r
a23fdff6
JW
919 @retval TRUE The Key is set successfully.\r
920 @retval FALSE The Key is set unsuccessfully.\r
72009c62
QL
921 @retval FALSE This interface is not supported.\r
922\r
923**/\r
924BOOLEAN\r
925EFIAPI\r
a23fdff6 926HmacSha256SetKey (\r
72009c62
QL
927 OUT VOID *HmacSha256Context,\r
928 IN CONST UINT8 *Key,\r
929 IN UINTN KeySize\r
930 );\r
931\r
932/**\r
933 Makes a copy of an existing HMAC-SHA256 context.\r
934\r
935 If HmacSha256Context is NULL, then return FALSE.\r
936 If NewHmacSha256Context is NULL, then return FALSE.\r
937 If this interface is not supported, then return FALSE.\r
938\r
939 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.\r
940 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.\r
941\r
942 @retval TRUE HMAC-SHA256 context copy succeeded.\r
943 @retval FALSE HMAC-SHA256 context copy failed.\r
944 @retval FALSE This interface is not supported.\r
945\r
946**/\r
947BOOLEAN\r
948EFIAPI\r
949HmacSha256Duplicate (\r
950 IN CONST VOID *HmacSha256Context,\r
951 OUT VOID *NewHmacSha256Context\r
952 );\r
953\r
954/**\r
955 Digests the input data and updates HMAC-SHA256 context.\r
956\r
957 This function performs HMAC-SHA256 digest on a data buffer of the specified size.\r
958 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
a23fdff6
JW
959 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
960 by HmacSha256Final(). Behavior with invalid context is undefined.\r
72009c62
QL
961\r
962 If HmacSha256Context is NULL, then return FALSE.\r
963 If this interface is not supported, then return FALSE.\r
964\r
965 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
966 @param[in] Data Pointer to the buffer containing the data to be digested.\r
967 @param[in] DataSize Size of Data buffer in bytes.\r
968\r
969 @retval TRUE HMAC-SHA256 data digest succeeded.\r
970 @retval FALSE HMAC-SHA256 data digest failed.\r
971 @retval FALSE This interface is not supported.\r
972\r
973**/\r
974BOOLEAN\r
975EFIAPI\r
976HmacSha256Update (\r
977 IN OUT VOID *HmacSha256Context,\r
978 IN CONST VOID *Data,\r
979 IN UINTN DataSize\r
980 );\r
981\r
982/**\r
983 Completes computation of the HMAC-SHA256 digest value.\r
984\r
985 This function completes HMAC-SHA256 hash computation and retrieves the digest value into\r
986 the specified memory. After this function has been called, the HMAC-SHA256 context cannot\r
987 be used again.\r
a23fdff6
JW
988 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
989 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.\r
72009c62
QL
990\r
991 If HmacSha256Context is NULL, then return FALSE.\r
68ae7cd6 992 If HmacValue is NULL, then return FALSE.\r
72009c62
QL
993 If this interface is not supported, then return FALSE.\r
994\r
995 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
68ae7cd6 996 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
72009c62
QL
997 value (32 bytes).\r
998\r
999 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1000 @retval FALSE HMAC-SHA256 digest computation failed.\r
1001 @retval FALSE This interface is not supported.\r
1002\r
1003**/\r
1004BOOLEAN\r
1005EFIAPI\r
1006HmacSha256Final (\r
1007 IN OUT VOID *HmacSha256Context,\r
1008 OUT UINT8 *HmacValue\r
1009 );\r
1010\r
97f98500
HT
1011//=====================================================================================\r
1012// Symmetric Cryptography Primitive\r
1013//=====================================================================================\r
1014\r
a8c44645 1015/**\r
1016 Retrieves the size, in bytes, of the context buffer required for AES operations.\r
1017\r
532616bb 1018 If this interface is not supported, then return zero.\r
1019\r
a8c44645 1020 @return The size, in bytes, of the context buffer required for AES operations.\r
532616bb 1021 @retval 0 This interface is not supported.\r
a8c44645 1022\r
1023**/\r
1024UINTN\r
1025EFIAPI\r
1026AesGetContextSize (\r
1027 VOID\r
1028 );\r
1029\r
1030/**\r
1031 Initializes user-supplied memory as AES context for subsequent use.\r
1032\r
1033 This function initializes user-supplied memory pointed by AesContext as AES context.\r
6b8ebcb8 1034 In addition, it sets up all AES key materials for subsequent encryption and decryption\r
a8c44645 1035 operations.\r
1036 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r
1037\r
16d2c32c 1038 If AesContext is NULL, then return FALSE.\r
1039 If Key is NULL, then return FALSE.\r
1040 If KeyLength is not valid, then return FALSE.\r
532616bb 1041 If this interface is not supported, then return FALSE.\r
a8c44645 1042\r
1043 @param[out] AesContext Pointer to AES context being initialized.\r
1044 @param[in] Key Pointer to the user-supplied AES key.\r
1045 @param[in] KeyLength Length of AES key in bits.\r
1046\r
1047 @retval TRUE AES context initialization succeeded.\r
1048 @retval FALSE AES context initialization failed.\r
532616bb 1049 @retval FALSE This interface is not supported.\r
a8c44645 1050\r
1051**/\r
1052BOOLEAN\r
1053EFIAPI\r
1054AesInit (\r
1055 OUT VOID *AesContext,\r
1056 IN CONST UINT8 *Key,\r
1057 IN UINTN KeyLength\r
1058 );\r
1059\r
a8c44645 1060/**\r
1061 Performs AES encryption on a data buffer of the specified size in CBC mode.\r
1062\r
1063 This function performs AES encryption on data buffer pointed by Input, of specified\r
1064 size of InputSize, in CBC mode.\r
1065 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1066 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1067 Initialization vector should be one block size (16 bytes).\r
1068 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1069 invalid AES context is undefined.\r
1070\r
16d2c32c 1071 If AesContext is NULL, then return FALSE.\r
1072 If Input is NULL, then return FALSE.\r
1073 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1074 If Ivec is NULL, then return FALSE.\r
1075 If Output is NULL, then return FALSE.\r
532616bb 1076 If this interface is not supported, then return FALSE.\r
a8c44645 1077\r
1078 @param[in] AesContext Pointer to the AES context.\r
1079 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1080 @param[in] InputSize Size of the Input buffer in bytes.\r
1081 @param[in] Ivec Pointer to initialization vector.\r
1082 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1083\r
1084 @retval TRUE AES encryption succeeded.\r
1085 @retval FALSE AES encryption failed.\r
532616bb 1086 @retval FALSE This interface is not supported.\r
a8c44645 1087\r
1088**/\r
1089BOOLEAN\r
1090EFIAPI\r
1091AesCbcEncrypt (\r
1092 IN VOID *AesContext,\r
1093 IN CONST UINT8 *Input,\r
1094 IN UINTN InputSize,\r
1095 IN CONST UINT8 *Ivec,\r
1096 OUT UINT8 *Output\r
1097 );\r
1098\r
1099/**\r
1100 Performs AES decryption on a data buffer of the specified size in CBC mode.\r
1101\r
1102 This function performs AES decryption on data buffer pointed by Input, of specified\r
1103 size of InputSize, in CBC mode.\r
1104 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1105 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1106 Initialization vector should be one block size (16 bytes).\r
1107 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1108 invalid AES context is undefined.\r
1109\r
16d2c32c 1110 If AesContext is NULL, then return FALSE.\r
1111 If Input is NULL, then return FALSE.\r
1112 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1113 If Ivec is NULL, then return FALSE.\r
1114 If Output is NULL, then return FALSE.\r
532616bb 1115 If this interface is not supported, then return FALSE.\r
a8c44645 1116\r
1117 @param[in] AesContext Pointer to the AES context.\r
1118 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1119 @param[in] InputSize Size of the Input buffer in bytes.\r
1120 @param[in] Ivec Pointer to initialization vector.\r
1121 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1122\r
1123 @retval TRUE AES decryption succeeded.\r
1124 @retval FALSE AES decryption failed.\r
532616bb 1125 @retval FALSE This interface is not supported.\r
a8c44645 1126\r
1127**/\r
1128BOOLEAN\r
1129EFIAPI\r
1130AesCbcDecrypt (\r
1131 IN VOID *AesContext,\r
1132 IN CONST UINT8 *Input,\r
1133 IN UINTN InputSize,\r
1134 IN CONST UINT8 *Ivec,\r
1135 OUT UINT8 *Output\r
1136 );\r
1137\r
97f98500
HT
1138//=====================================================================================\r
1139// Asymmetric Cryptography Primitive\r
1140//=====================================================================================\r
1141\r
1142/**\r
a8c44645 1143 Allocates and initializes one RSA context for subsequent use.\r
97f98500 1144\r
a8c44645 1145 @return Pointer to the RSA context that has been initialized.\r
97f98500
HT
1146 If the allocations fails, RsaNew() returns NULL.\r
1147\r
1148**/\r
1149VOID *\r
1150EFIAPI\r
1151RsaNew (\r
1152 VOID\r
1153 );\r
1154\r
97f98500 1155/**\r
a8c44645 1156 Release the specified RSA context.\r
1157\r
16d2c32c 1158 If RsaContext is NULL, then return FALSE.\r
97f98500
HT
1159\r
1160 @param[in] RsaContext Pointer to the RSA context to be released.\r
1161\r
1162**/\r
1163VOID\r
1164EFIAPI\r
1165RsaFree (\r
1166 IN VOID *RsaContext\r
1167 );\r
1168\r
97f98500 1169/**\r
a8c44645 1170 Sets the tag-designated key component into the established RSA context.\r
1171\r
1172 This function sets the tag-designated RSA key component into the established\r
1173 RSA context from the user-specified non-negative integer (octet string format\r
1174 represented in RSA PKCS#1).\r
2998af86 1175 If BigNumber is NULL, then the specified key component in RSA context is cleared.\r
97f98500 1176\r
16d2c32c 1177 If RsaContext is NULL, then return FALSE.\r
97f98500
HT
1178\r
1179 @param[in, out] RsaContext Pointer to RSA context being set.\r
1180 @param[in] KeyTag Tag of RSA key component being set.\r
1181 @param[in] BigNumber Pointer to octet integer buffer.\r
2998af86 1182 If NULL, then the specified key component in RSA\r
a8c44645 1183 context is cleared.\r
1184 @param[in] BnSize Size of big number buffer in bytes.\r
1185 If BigNumber is NULL, then it is ignored.\r
97f98500 1186\r
a8c44645 1187 @retval TRUE RSA key component was set successfully.\r
1188 @retval FALSE Invalid RSA key component tag.\r
97f98500
HT
1189\r
1190**/\r
1191BOOLEAN\r
1192EFIAPI\r
1193RsaSetKey (\r
a8c44645 1194 IN OUT VOID *RsaContext,\r
1195 IN RSA_KEY_TAG KeyTag,\r
1196 IN CONST UINT8 *BigNumber,\r
1197 IN UINTN BnSize\r
1198 );\r
1199\r
1200/**\r
1201 Gets the tag-designated RSA key component from the established RSA context.\r
1202\r
1203 This function retrieves the tag-designated RSA key component from the\r
1204 established RSA context as a non-negative integer (octet string format\r
1205 represented in RSA PKCS#1).\r
1206 If specified key component has not been set or has been cleared, then returned\r
1207 BnSize is set to 0.\r
1208 If the BigNumber buffer is too small to hold the contents of the key, FALSE\r
1209 is returned and BnSize is set to the required buffer size to obtain the key.\r
1210\r
16d2c32c 1211 If RsaContext is NULL, then return FALSE.\r
1212 If BnSize is NULL, then return FALSE.\r
1213 If BnSize is large enough but BigNumber is NULL, then return FALSE.\r
532616bb 1214 If this interface is not supported, then return FALSE.\r
a8c44645 1215\r
1216 @param[in, out] RsaContext Pointer to RSA context being set.\r
1217 @param[in] KeyTag Tag of RSA key component being set.\r
1218 @param[out] BigNumber Pointer to octet integer buffer.\r
1219 @param[in, out] BnSize On input, the size of big number buffer in bytes.\r
1220 On output, the size of data returned in big number buffer in bytes.\r
1221\r
1222 @retval TRUE RSA key component was retrieved successfully.\r
1223 @retval FALSE Invalid RSA key component tag.\r
1224 @retval FALSE BnSize is too small.\r
532616bb 1225 @retval FALSE This interface is not supported.\r
a8c44645 1226\r
1227**/\r
1228BOOLEAN\r
1229EFIAPI\r
1230RsaGetKey (\r
1231 IN OUT VOID *RsaContext,\r
1232 IN RSA_KEY_TAG KeyTag,\r
1233 OUT UINT8 *BigNumber,\r
1234 IN OUT UINTN *BnSize\r
1235 );\r
1236\r
1237/**\r
1238 Generates RSA key components.\r
1239\r
1240 This function generates RSA key components. It takes RSA public exponent E and\r
1241 length in bits of RSA modulus N as input, and generates all key components.\r
1242 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r
1243\r
1244 Before this function can be invoked, pseudorandom number generator must be correctly\r
1245 initialized by RandomSeed().\r
1246\r
16d2c32c 1247 If RsaContext is NULL, then return FALSE.\r
532616bb 1248 If this interface is not supported, then return FALSE.\r
a8c44645 1249\r
1250 @param[in, out] RsaContext Pointer to RSA context being set.\r
1251 @param[in] ModulusLength Length of RSA modulus N in bits.\r
1252 @param[in] PublicExponent Pointer to RSA public exponent.\r
2ac68e8b 1253 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r
a8c44645 1254\r
1255 @retval TRUE RSA key component was generated successfully.\r
1256 @retval FALSE Invalid RSA key component tag.\r
532616bb 1257 @retval FALSE This interface is not supported.\r
a8c44645 1258\r
1259**/\r
1260BOOLEAN\r
1261EFIAPI\r
1262RsaGenerateKey (\r
1263 IN OUT VOID *RsaContext,\r
1264 IN UINTN ModulusLength,\r
1265 IN CONST UINT8 *PublicExponent,\r
1266 IN UINTN PublicExponentSize\r
1267 );\r
1268\r
1269/**\r
1270 Validates key components of RSA context.\r
952bd229
QL
1271 NOTE: This function performs integrity checks on all the RSA key material, so\r
1272 the RSA key structure must contain all the private key data.\r
a8c44645 1273\r
2998af86 1274 This function validates key components of RSA context in following aspects:\r
a8c44645 1275 - Whether p is a prime\r
1276 - Whether q is a prime\r
1277 - Whether n = p * q\r
1278 - Whether d*e = 1 mod lcm(p-1,q-1)\r
1279\r
16d2c32c 1280 If RsaContext is NULL, then return FALSE.\r
532616bb 1281 If this interface is not supported, then return FALSE.\r
a8c44645 1282\r
1283 @param[in] RsaContext Pointer to RSA context to check.\r
1284\r
1285 @retval TRUE RSA key components are valid.\r
1286 @retval FALSE RSA key components are not valid.\r
532616bb 1287 @retval FALSE This interface is not supported.\r
a8c44645 1288\r
1289**/\r
1290BOOLEAN\r
1291EFIAPI\r
1292RsaCheckKey (\r
1293 IN VOID *RsaContext\r
97f98500
HT
1294 );\r
1295\r
a8c44645 1296/**\r
1297 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r
1298\r
1299 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1300 RSA PKCS#1.\r
1301 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1302 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1303\r
16d2c32c 1304 If RsaContext is NULL, then return FALSE.\r
1305 If MessageHash is NULL, then return FALSE.\r
1306 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r
1307 If SigSize is large enough but Signature is NULL, then return FALSE.\r
532616bb 1308 If this interface is not supported, then return FALSE.\r
a8c44645 1309\r
1310 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1311 @param[in] MessageHash Pointer to octet message hash to be signed.\r
1312 @param[in] HashSize Size of the message hash in bytes.\r
1313 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
1314 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
b7d320f8 1315 On output, the size of data returned in Signature buffer in bytes.\r
a8c44645 1316\r
1317 @retval TRUE Signature successfully generated in PKCS1-v1_5.\r
1318 @retval FALSE Signature generation failed.\r
1319 @retval FALSE SigSize is too small.\r
532616bb 1320 @retval FALSE This interface is not supported.\r
a8c44645 1321\r
1322**/\r
1323BOOLEAN\r
1324EFIAPI\r
1325RsaPkcs1Sign (\r
1326 IN VOID *RsaContext,\r
1327 IN CONST UINT8 *MessageHash,\r
1328 IN UINTN HashSize,\r
1329 OUT UINT8 *Signature,\r
1330 IN OUT UINTN *SigSize\r
1331 );\r
97f98500
HT
1332\r
1333/**\r
1334 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1335 RSA PKCS#1.\r
1336\r
16d2c32c 1337 If RsaContext is NULL, then return FALSE.\r
1338 If MessageHash is NULL, then return FALSE.\r
1339 If Signature is NULL, then return FALSE.\r
1340 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r
97f98500
HT
1341\r
1342 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1343 @param[in] MessageHash Pointer to octet message hash to be checked.\r
a8c44645 1344 @param[in] HashSize Size of the message hash in bytes.\r
97f98500 1345 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r
a8c44645 1346 @param[in] SigSize Size of signature in bytes.\r
97f98500 1347\r
a8c44645 1348 @retval TRUE Valid signature encoded in PKCS1-v1_5.\r
1349 @retval FALSE Invalid signature or invalid RSA context.\r
97f98500
HT
1350\r
1351**/\r
1352BOOLEAN\r
1353EFIAPI\r
1354RsaPkcs1Verify (\r
1355 IN VOID *RsaContext,\r
1356 IN CONST UINT8 *MessageHash,\r
a8c44645 1357 IN UINTN HashSize,\r
8c5720b4 1358 IN CONST UINT8 *Signature,\r
a8c44645 1359 IN UINTN SigSize\r
97f98500
HT
1360 );\r
1361\r
4a567c96 1362/**\r
1363 Retrieve the RSA Private Key from the password-protected PEM key data.\r
1364\r
532616bb 1365 If PemData is NULL, then return FALSE.\r
1366 If RsaContext is NULL, then return FALSE.\r
1367 If this interface is not supported, then return FALSE.\r
1368\r
4a567c96 1369 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
1370 @param[in] PemSize Size of the PEM key data in bytes.\r
1371 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
1372 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1373 RSA private key component. Use RsaFree() function to free the\r
1374 resource.\r
1375\r
4a567c96 1376 @retval TRUE RSA Private Key was retrieved successfully.\r
1377 @retval FALSE Invalid PEM key data or incorrect password.\r
532616bb 1378 @retval FALSE This interface is not supported.\r
4a567c96 1379\r
1380**/\r
1381BOOLEAN\r
1382EFIAPI\r
1383RsaGetPrivateKeyFromPem (\r
1384 IN CONST UINT8 *PemData,\r
1385 IN UINTN PemSize,\r
1386 IN CONST CHAR8 *Password,\r
1387 OUT VOID **RsaContext\r
1388 );\r
1389\r
1390/**\r
1391 Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r
1392\r
532616bb 1393 If Cert is NULL, then return FALSE.\r
1394 If RsaContext is NULL, then return FALSE.\r
1395 If this interface is not supported, then return FALSE.\r
1396\r
4a567c96 1397 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1398 @param[in] CertSize Size of the X509 certificate in bytes.\r
1399 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1400 RSA public key component. Use RsaFree() function to free the\r
1401 resource.\r
1402\r
4a567c96 1403 @retval TRUE RSA Public Key was retrieved successfully.\r
1404 @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r
532616bb 1405 @retval FALSE This interface is not supported.\r
4a567c96 1406\r
1407**/\r
1408BOOLEAN\r
1409EFIAPI\r
1410RsaGetPublicKeyFromX509 (\r
1411 IN CONST UINT8 *Cert,\r
1412 IN UINTN CertSize,\r
1413 OUT VOID **RsaContext\r
1414 );\r
1415\r
1416/**\r
1417 Retrieve the subject bytes from one X.509 certificate.\r
1418\r
532616bb 1419 If Cert is NULL, then return FALSE.\r
1420 If SubjectSize is NULL, then return FALSE.\r
1421 If this interface is not supported, then return FALSE.\r
1422\r
4a567c96 1423 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1424 @param[in] CertSize Size of the X509 certificate in bytes.\r
1425 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r
1426 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r
1427 and the size of buffer returned CertSubject on output.\r
1428\r
4a567c96 1429 @retval TRUE The certificate subject retrieved successfully.\r
1430 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r
1431 The SubjectSize will be updated with the required size.\r
532616bb 1432 @retval FALSE This interface is not supported.\r
4a567c96 1433\r
1434**/\r
1435BOOLEAN\r
1436EFIAPI\r
1437X509GetSubjectName (\r
1438 IN CONST UINT8 *Cert,\r
1439 IN UINTN CertSize,\r
1440 OUT UINT8 *CertSubject,\r
1441 IN OUT UINTN *SubjectSize\r
1442 );\r
1443\r
5b7c2245
QL
1444/**\r
1445 Retrieve the common name (CN) string from one X.509 certificate.\r
1446\r
1447 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1448 @param[in] CertSize Size of the X509 certificate in bytes.\r
1449 @param[out] CommonName Buffer to contain the retrieved certificate common\r
0b6457ef 1450 name string (UTF8). At most CommonNameSize bytes will be\r
5b7c2245
QL
1451 written and the string will be null terminated. May be\r
1452 NULL in order to determine the size buffer needed.\r
1453 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
1454 and the size of buffer returned CommonName on output.\r
1455 If CommonName is NULL then the amount of space needed\r
1456 in buffer (including the final null) is returned.\r
1457\r
1458 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r
1459 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1460 If CommonNameSize is NULL.\r
1461 If CommonName is not NULL and *CommonNameSize is 0.\r
1462 If Certificate is invalid.\r
1463 @retval RETURN_NOT_FOUND If no CommonName entry exists.\r
1464 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r
630f67dd 1465 (including the final null) is returned in the\r
5b7c2245
QL
1466 CommonNameSize parameter.\r
1467 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1468\r
1469**/\r
1470RETURN_STATUS\r
1471EFIAPI\r
1472X509GetCommonName (\r
1473 IN CONST UINT8 *Cert,\r
1474 IN UINTN CertSize,\r
1475 OUT CHAR8 *CommonName, OPTIONAL\r
1476 IN OUT UINTN *CommonNameSize\r
1477 );\r
1478\r
e2a673b8
BB
1479/**\r
1480 Retrieve the organization name (O) string from one X.509 certificate.\r
1481\r
1482 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1483 @param[in] CertSize Size of the X509 certificate in bytes.\r
1484 @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r
1485 name string. At most NameBufferSize bytes will be\r
1486 written and the string will be null terminated. May be\r
1487 NULL in order to determine the size buffer needed.\r
1488 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r
1489 and the size of buffer returned Name on output.\r
1490 If NameBuffer is NULL then the amount of space needed\r
1491 in buffer (including the final null) is returned.\r
1492\r
1493 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r
1494 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1495 If NameBufferSize is NULL.\r
1496 If NameBuffer is not NULL and *CommonNameSize is 0.\r
1497 If Certificate is invalid.\r
1498 @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r
1499 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r
1500 (including the final null) is returned in the\r
1501 CommonNameSize parameter.\r
1502 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1503\r
1504**/\r
1505RETURN_STATUS\r
1506EFIAPI\r
1507X509GetOrganizationName (\r
1508 IN CONST UINT8 *Cert,\r
1509 IN UINTN CertSize,\r
1510 OUT CHAR8 *NameBuffer, OPTIONAL\r
1511 IN OUT UINTN *NameBufferSize\r
1512 );\r
1513\r
4a567c96 1514/**\r
1515 Verify one X509 certificate was issued by the trusted CA.\r
1516\r
532616bb 1517 If Cert is NULL, then return FALSE.\r
1518 If CACert is NULL, then return FALSE.\r
1519 If this interface is not supported, then return FALSE.\r
1520\r
4a567c96 1521 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r
1522 @param[in] CertSize Size of the X509 certificate in bytes.\r
1523 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r
1524 @param[in] CACertSize Size of the CA Certificate in bytes.\r
1525\r
4a567c96 1526 @retval TRUE The certificate was issued by the trusted CA.\r
1527 @retval FALSE Invalid certificate or the certificate was not issued by the given\r
1528 trusted CA.\r
532616bb 1529 @retval FALSE This interface is not supported.\r
4a567c96 1530\r
1531**/\r
1532BOOLEAN\r
1533EFIAPI\r
1534X509VerifyCert (\r
1535 IN CONST UINT8 *Cert,\r
1536 IN UINTN CertSize,\r
1537 IN CONST UINT8 *CACert,\r
1538 IN UINTN CACertSize\r
1539 );\r
1540\r
b7d320f8 1541/**\r
1542 Construct a X509 object from DER-encoded certificate data.\r
1543\r
16d2c32c 1544 If Cert is NULL, then return FALSE.\r
1545 If SingleX509Cert is NULL, then return FALSE.\r
532616bb 1546 If this interface is not supported, then return FALSE.\r
b7d320f8 1547\r
1548 @param[in] Cert Pointer to the DER-encoded certificate data.\r
1549 @param[in] CertSize The size of certificate data in bytes.\r
1550 @param[out] SingleX509Cert The generated X509 object.\r
1551\r
1552 @retval TRUE The X509 object generation succeeded.\r
1553 @retval FALSE The operation failed.\r
532616bb 1554 @retval FALSE This interface is not supported.\r
b7d320f8 1555\r
1556**/\r
1557BOOLEAN\r
1558EFIAPI\r
1559X509ConstructCertificate (\r
1560 IN CONST UINT8 *Cert,\r
1561 IN UINTN CertSize,\r
1562 OUT UINT8 **SingleX509Cert\r
1563 );\r
1564\r
66862136
MK
1565/**\r
1566 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1567\r
1568 If X509Stack is NULL, then return FALSE.\r
1569 If this interface is not supported, then return FALSE.\r
1570\r
1571 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
1572 On output, pointer to the X509 stack object with new\r
1573 inserted X509 certificate.\r
1574 @param[in] Args VA_LIST marker for the variable argument list.\r
1575 A list of DER-encoded single certificate data followed\r
1576 by certificate size. A NULL terminates the list. The\r
1577 pairs are the arguments to X509ConstructCertificate().\r
1578\r
1579 @retval TRUE The X509 stack construction succeeded.\r
1580 @retval FALSE The construction operation failed.\r
1581 @retval FALSE This interface is not supported.\r
1582\r
1583**/\r
1584BOOLEAN\r
1585EFIAPI\r
1586X509ConstructCertificateStackV (\r
1587 IN OUT UINT8 **X509Stack,\r
1588 IN VA_LIST Args\r
1589 );\r
1590\r
b7d320f8 1591/**\r
1592 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1593\r
16d2c32c 1594 If X509Stack is NULL, then return FALSE.\r
532616bb 1595 If this interface is not supported, then return FALSE.\r
b7d320f8 1596\r
952bd229 1597 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
b7d320f8 1598 On output, pointer to the X509 stack object with new\r
1599 inserted X509 certificate.\r
1600 @param ... A list of DER-encoded single certificate data followed\r
1601 by certificate size. A NULL terminates the list. The\r
1602 pairs are the arguments to X509ConstructCertificate().\r
2ac68e8b 1603\r
b7d320f8 1604 @retval TRUE The X509 stack construction succeeded.\r
1605 @retval FALSE The construction operation failed.\r
532616bb 1606 @retval FALSE This interface is not supported.\r
b7d320f8 1607\r
1608**/\r
1609BOOLEAN\r
1610EFIAPI\r
1611X509ConstructCertificateStack (\r
1612 IN OUT UINT8 **X509Stack,\r
2ac68e8b 1613 ...\r
b7d320f8 1614 );\r
1615\r
1616/**\r
1617 Release the specified X509 object.\r
1618\r
532616bb 1619 If the interface is not supported, then ASSERT().\r
b7d320f8 1620\r
1621 @param[in] X509Cert Pointer to the X509 object to be released.\r
1622\r
1623**/\r
1624VOID\r
1625EFIAPI\r
1626X509Free (\r
1627 IN VOID *X509Cert\r
1628 );\r
1629\r
1630/**\r
1631 Release the specified X509 stack object.\r
1632\r
532616bb 1633 If the interface is not supported, then ASSERT().\r
b7d320f8 1634\r
1635 @param[in] X509Stack Pointer to the X509 stack object to be released.\r
1636\r
1637**/\r
1638VOID\r
1639EFIAPI\r
1640X509StackFree (\r
1641 IN VOID *X509Stack\r
1642 );\r
1643\r
12d95665
LQ
1644/**\r
1645 Retrieve the TBSCertificate from one given X.509 certificate.\r
1646\r
1647 @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r
1648 @param[in] CertSize Size of the X509 certificate in bytes.\r
1649 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r
1650 @param[out] TBSCertSize Size of the TBS certificate in bytes.\r
1651\r
1652 If Cert is NULL, then return FALSE.\r
1653 If TBSCert is NULL, then return FALSE.\r
1654 If TBSCertSize is NULL, then return FALSE.\r
1655 If this interface is not supported, then return FALSE.\r
1656\r
1657 @retval TRUE The TBSCertificate was retrieved successfully.\r
1658 @retval FALSE Invalid X.509 certificate.\r
1659\r
1660**/\r
1661BOOLEAN\r
1662EFIAPI\r
1663X509GetTBSCert (\r
1664 IN CONST UINT8 *Cert,\r
1665 IN UINTN CertSize,\r
1666 OUT UINT8 **TBSCert,\r
1667 OUT UINTN *TBSCertSize\r
1668 );\r
1669\r
a8f37449
QL
1670/**\r
1671 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r
1672 password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r
1673\r
1674 If Password or Salt or OutKey is NULL, then return FALSE.\r
1675 If the hash algorithm could not be determined, then return FALSE.\r
1676 If this interface is not supported, then return FALSE.\r
1677\r
1678 @param[in] PasswordLength Length of input password in bytes.\r
1679 @param[in] Password Pointer to the array for the password.\r
1680 @param[in] SaltLength Size of the Salt in bytes.\r
1681 @param[in] Salt Pointer to the Salt.\r
1682 @param[in] IterationCount Number of iterations to perform. Its value should be\r
1683 greater than or equal to 1.\r
1684 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r
1685 NOTE: DigestSize will be used to determine the hash algorithm.\r
1686 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r
1687 @param[in] KeyLength Size of the derived key buffer in bytes.\r
1688 @param[out] OutKey Pointer to the output derived key buffer.\r
1689\r
1690 @retval TRUE A key was derived successfully.\r
1691 @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r
1692 @retval FALSE The hash algorithm could not be determined from the digest size.\r
1693 @retval FALSE The key derivation operation failed.\r
1694 @retval FALSE This interface is not supported.\r
1695\r
1696**/\r
1697BOOLEAN\r
1698EFIAPI\r
1699Pkcs5HashPassword (\r
1700 IN UINTN PasswordLength,\r
1701 IN CONST CHAR8 *Password,\r
1702 IN UINTN SaltLength,\r
1703 IN CONST UINT8 *Salt,\r
1704 IN UINTN IterationCount,\r
1705 IN UINTN DigestSize,\r
1706 IN UINTN KeyLength,\r
1707 OUT UINT8 *OutKey\r
1708 );\r
1709\r
aed90bee
BB
1710/**\r
1711 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r
1712 encrypted message in a newly allocated buffer.\r
1713\r
1714 Things that can cause a failure include:\r
1715 - X509 key size does not match any known key size.\r
1716 - Fail to parse X509 certificate.\r
1717 - Fail to allocate an intermediate buffer.\r
1718 - Null pointer provided for a non-optional parameter.\r
1719 - Data size is too large for the provided key size (max size is a function of key size\r
1720 and hash digest size).\r
1721\r
1722 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r
1723 will be used to encrypt the data.\r
1724 @param[in] PublicKeySize Size of the X509 cert buffer.\r
1725 @param[in] InData Data to be encrypted.\r
1726 @param[in] InDataSize Size of the data buffer.\r
1727 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r
1728 to be used when initializing the PRNG. NULL otherwise.\r
1729 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r
1730 0 otherwise.\r
1731 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r
1732 message.\r
1733 @param[out] EncryptedDataSize Size of the encrypted message buffer.\r
1734\r
1735 @retval TRUE Encryption was successful.\r
1736 @retval FALSE Encryption failed.\r
1737\r
1738**/\r
1739BOOLEAN\r
1740EFIAPI\r
1741Pkcs1v2Encrypt (\r
1742 IN CONST UINT8 *PublicKey,\r
1743 IN UINTN PublicKeySize,\r
1744 IN UINT8 *InData,\r
1745 IN UINTN InDataSize,\r
1746 IN CONST UINT8 *PrngSeed, OPTIONAL\r
1747 IN UINTN PrngSeedSize, OPTIONAL\r
1748 OUT UINT8 **EncryptedData,\r
1749 OUT UINTN *EncryptedDataSize\r
1750 );\r
1751\r
3702637a 1752/**\r
1753 The 3rd parameter of Pkcs7GetSigners will return all embedded\r
1754 X.509 certificate in one given PKCS7 signature. The format is:\r
1755 //\r
1756 // UINT8 CertNumber;\r
1757 // UINT32 Cert1Length;\r
1758 // UINT8 Cert1[];\r
1759 // UINT32 Cert2Length;\r
1760 // UINT8 Cert2[];\r
1761 // ...\r
1762 // UINT32 CertnLength;\r
1763 // UINT8 Certn[];\r
1764 //\r
1765\r
1766 The two following C-structure are used for parsing CertStack more clearly.\r
1767**/\r
1768#pragma pack(1)\r
1769\r
1770typedef struct {\r
1771 UINT32 CertDataLength; // The length in bytes of X.509 certificate.\r
1772 UINT8 CertDataBuffer[0]; // The X.509 certificate content (DER).\r
1773} EFI_CERT_DATA;\r
1774\r
1775typedef struct {\r
1776 UINT8 CertNumber; // Number of X.509 certificate.\r
1777 //EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.\r
1778} EFI_CERT_STACK;\r
1779\r
1780#pragma pack()\r
1781\r
e8b4eb04 1782/**\r
1783 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r
1784 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
1785 in a ContentInfo structure.\r
1786\r
1787 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r
2998af86 1788 return FALSE. If P7Length overflow, then return FALSE.\r
532616bb 1789 If this interface is not supported, then return FALSE.\r
e8b4eb04 1790\r
1791 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
1792 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
1793 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r
6fe575d0
LQ
1794 It's caller's responsibility to free the buffer with\r
1795 Pkcs7FreeSigners().\r
3702637a 1796 This data structure is EFI_CERT_STACK type.\r
e8b4eb04 1797 @param[out] StackLength Length of signer's certificates in bytes.\r
1798 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r
6fe575d0
LQ
1799 It's caller's responsibility to free the buffer with\r
1800 Pkcs7FreeSigners().\r
e8b4eb04 1801 @param[out] CertLength Length of the trusted certificate in bytes.\r
1802\r
1803 @retval TRUE The operation is finished successfully.\r
1804 @retval FALSE Error occurs during the operation.\r
532616bb 1805 @retval FALSE This interface is not supported.\r
e8b4eb04 1806\r
1807**/\r
1808BOOLEAN\r
1809EFIAPI\r
1810Pkcs7GetSigners (\r
1811 IN CONST UINT8 *P7Data,\r
1812 IN UINTN P7Length,\r
1813 OUT UINT8 **CertStack,\r
1814 OUT UINTN *StackLength,\r
1815 OUT UINT8 **TrustedCert,\r
1816 OUT UINTN *CertLength\r
1817 );\r
1818\r
1819/**\r
1820 Wrap function to use free() to free allocated memory for certificates.\r
1821\r
532616bb 1822 If this interface is not supported, then ASSERT().\r
1823\r
e8b4eb04 1824 @param[in] Certs Pointer to the certificates to be freed.\r
1825\r
1826**/\r
1827VOID\r
1828EFIAPI\r
1829Pkcs7FreeSigners (\r
1830 IN UINT8 *Certs\r
45419de6
QL
1831 );\r
1832\r
1833/**\r
1834 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r
1835 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r
1836 unchained to the signer's certificates.\r
1837 The input signed data could be wrapped in a ContentInfo structure.\r
1838\r
1839 @param[in] P7Data Pointer to the PKCS#7 message.\r
1840 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
0f5f6b3d 1841 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r
6fe575d0
LQ
1842 certificate. It's caller's responsibility to free the buffer\r
1843 with Pkcs7FreeSigners().\r
3702637a 1844 This data structure is EFI_CERT_STACK type.\r
45419de6
QL
1845 @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r
1846 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r
6fe575d0 1847 responsibility to free the buffer with Pkcs7FreeSigners().\r
3702637a 1848 This data structure is EFI_CERT_STACK type.\r
45419de6
QL
1849 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r
1850\r
1851 @retval TRUE The operation is finished successfully.\r
1852 @retval FALSE Error occurs during the operation.\r
1853\r
1854**/\r
1855BOOLEAN\r
1856EFIAPI\r
1857Pkcs7GetCertificatesList (\r
1858 IN CONST UINT8 *P7Data,\r
1859 IN UINTN P7Length,\r
1860 OUT UINT8 **SignerChainCerts,\r
1861 OUT UINTN *ChainLength,\r
1862 OUT UINT8 **UnchainCerts,\r
1863 OUT UINTN *UnchainLength\r
e8b4eb04 1864 );\r
1865\r
b7d320f8 1866/**\r
1867 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
1868 Syntax Standard, version 1.5". This interface is only intended to be used for\r
1869 application to perform PKCS#7 functionality validation.\r
1870\r
532616bb 1871 If this interface is not supported, then return FALSE.\r
1872\r
b7d320f8 1873 @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r
1874 data signing.\r
1875 @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r
1876 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r
1877 key data.\r
1878 @param[in] InData Pointer to the content to be signed.\r
1879 @param[in] InDataSize Size of InData in bytes.\r
1880 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r
1881 @param[in] OtherCerts Pointer to an optional additional set of certificates to\r
1882 include in the PKCS#7 signedData (e.g. any intermediate\r
1883 CAs in the chain).\r
6fe575d0
LQ
1884 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r
1885 responsibility to free the buffer with FreePool().\r
b7d320f8 1886 @param[out] SignedDataSize Size of SignedData in bytes.\r
1887\r
1888 @retval TRUE PKCS#7 data signing succeeded.\r
1889 @retval FALSE PKCS#7 data signing failed.\r
532616bb 1890 @retval FALSE This interface is not supported.\r
b7d320f8 1891\r
1892**/\r
1893BOOLEAN\r
1894EFIAPI\r
1895Pkcs7Sign (\r
1896 IN CONST UINT8 *PrivateKey,\r
1897 IN UINTN PrivateKeySize,\r
1898 IN CONST UINT8 *KeyPassword,\r
1899 IN UINT8 *InData,\r
1900 IN UINTN InDataSize,\r
1901 IN UINT8 *SignCert,\r
1902 IN UINT8 *OtherCerts OPTIONAL,\r
1903 OUT UINT8 **SignedData,\r
1904 OUT UINTN *SignedDataSize\r
1905 );\r
1906\r
97f98500 1907/**\r
2998af86 1908 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r
e8b4eb04 1909 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
1910 in a ContentInfo structure.\r
97f98500 1911\r
e8b4eb04 1912 If P7Data, TrustedCert or InData is NULL, then return FALSE.\r
2998af86 1913 If P7Length, CertLength or DataLength overflow, then return FALSE.\r
532616bb 1914 If this interface is not supported, then return FALSE.\r
97f98500
HT
1915\r
1916 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
e8b4eb04 1917 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
97f98500
HT
1918 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
1919 is used for certificate chain verification.\r
e8b4eb04 1920 @param[in] CertLength Length of the trusted certificate in bytes.\r
97f98500 1921 @param[in] InData Pointer to the content to be verified.\r
e8b4eb04 1922 @param[in] DataLength Length of InData in bytes.\r
97f98500 1923\r
a8c44645 1924 @retval TRUE The specified PKCS#7 signed data is valid.\r
1925 @retval FALSE Invalid PKCS#7 signed data.\r
532616bb 1926 @retval FALSE This interface is not supported.\r
97f98500
HT
1927\r
1928**/\r
1929BOOLEAN\r
1930EFIAPI\r
1931Pkcs7Verify (\r
1932 IN CONST UINT8 *P7Data,\r
e8b4eb04 1933 IN UINTN P7Length,\r
97f98500 1934 IN CONST UINT8 *TrustedCert,\r
e8b4eb04 1935 IN UINTN CertLength,\r
97f98500 1936 IN CONST UINT8 *InData,\r
e8b4eb04 1937 IN UINTN DataLength\r
a8c44645 1938 );\r
1939\r
1796a394
BB
1940/**\r
1941 This function receives a PKCS7 formatted signature, and then verifies that\r
1942 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r
1943 leaf signing certificate.\r
1944 Note that this function does not validate the certificate chain.\r
1945\r
1946 Applications for custom EKU's are quite flexible. For example, a policy EKU\r
1947 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r
1948 certificate issued might also contain this EKU, thus constraining the\r
1949 sub-ordinate certificate. Other applications might allow a certificate\r
1950 embedded in a device to specify that other Object Identifiers (OIDs) are\r
1951 present which contains binary data specifying custom capabilities that\r
1952 the device is able to do.\r
1953\r
1954 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r
1955 containing the content block with both the signature,\r
1956 the signer's certificate, and any necessary intermediate\r
1957 certificates.\r
1958 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r
1959 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r
1960 required EKUs that must be present in the signature.\r
1961 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r
1962 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r
1963 must be present in the leaf signer. If it is\r
1964 FALSE, then we will succeed if we find any\r
1965 of the specified EKU's.\r
1966\r
1967 @retval EFI_SUCCESS The required EKUs were found in the signature.\r
1968 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
1969 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r
1970\r
1971**/\r
1972RETURN_STATUS\r
1973EFIAPI\r
1974VerifyEKUsInPkcs7Signature (\r
1975 IN CONST UINT8 *Pkcs7Signature,\r
1976 IN CONST UINT32 SignatureSize,\r
1977 IN CONST CHAR8 *RequiredEKUs[],\r
1978 IN CONST UINT32 RequiredEKUsSize,\r
1979 IN BOOLEAN RequireAllPresent\r
1980 );\r
1981\r
afeb55e4
QL
1982/**\r
1983 Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r
1984 data could be wrapped in a ContentInfo structure.\r
1985\r
1986 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r
2998af86 1987 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r
afeb55e4
QL
1988\r
1989 Caution: This function may receive untrusted input. So this function will do\r
1990 basic check for PKCS#7 data structure.\r
1991\r
1992 @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r
1993 @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r
1994 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r
6fe575d0 1995 It's caller's responsibility to free the buffer with FreePool().\r
afeb55e4
QL
1996 @param[out] ContentSize The size of the extracted content in bytes.\r
1997\r
1998 @retval TRUE The P7Data was correctly formatted for processing.\r
1999 @retval FALSE The P7Data was not correctly formatted for processing.\r
2000\r
0c9fc4b1 2001**/\r
afeb55e4
QL
2002BOOLEAN\r
2003EFIAPI\r
2004Pkcs7GetAttachedContent (\r
2005 IN CONST UINT8 *P7Data,\r
2006 IN UINTN P7Length,\r
2007 OUT VOID **Content,\r
2008 OUT UINTN *ContentSize\r
2009 );\r
2010\r
b7d320f8 2011/**\r
2998af86 2012 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r
b7d320f8 2013 Authenticode Portable Executable Signature Format".\r
2014\r
16d2c32c 2015 If AuthData is NULL, then return FALSE.\r
2016 If ImageHash is NULL, then return FALSE.\r
532616bb 2017 If this interface is not supported, then return FALSE.\r
b7d320f8 2018\r
2019 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2020 PE/COFF image to be verified.\r
2021 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2022 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2023 is used for certificate chain verification.\r
2024 @param[in] CertSize Size of the trusted certificate in bytes.\r
2998af86 2025 @param[in] ImageHash Pointer to the original image file hash value. The procedure\r
b7d320f8 2026 for calculating the image hash value is described in Authenticode\r
2027 specification.\r
2028 @param[in] HashSize Size of Image hash value in bytes.\r
2029\r
2030 @retval TRUE The specified Authenticode Signature is valid.\r
2031 @retval FALSE Invalid Authenticode Signature.\r
532616bb 2032 @retval FALSE This interface is not supported.\r
b7d320f8 2033\r
2034**/\r
2035BOOLEAN\r
2036EFIAPI\r
2037AuthenticodeVerify (\r
2038 IN CONST UINT8 *AuthData,\r
2039 IN UINTN DataSize,\r
2040 IN CONST UINT8 *TrustedCert,\r
2041 IN UINTN CertSize,\r
2042 IN CONST UINT8 *ImageHash,\r
2043 IN UINTN HashSize\r
2044 );\r
2045\r
2ac68e8b 2046/**\r
2998af86 2047 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r
2ac68e8b
QL
2048 signature.\r
2049\r
2050 If AuthData is NULL, then return FALSE.\r
12d95665 2051 If this interface is not supported, then return FALSE.\r
2ac68e8b
QL
2052\r
2053 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2054 PE/COFF image to be verified.\r
2055 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2056 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r
2057 is used for TSA certificate chain verification.\r
2058 @param[in] CertSize Size of the trusted certificate in bytes.\r
2059 @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r
2060 signature is valid.\r
2061\r
2062 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r
2063 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r
2064\r
2065**/\r
2066BOOLEAN\r
2067EFIAPI\r
2068ImageTimestampVerify (\r
2069 IN CONST UINT8 *AuthData,\r
2070 IN UINTN DataSize,\r
2071 IN CONST UINT8 *TsaCert,\r
2072 IN UINTN CertSize,\r
2073 OUT EFI_TIME *SigningTime\r
2074 );\r
2075\r
a8c44645 2076//=====================================================================================\r
2077// DH Key Exchange Primitive\r
2078//=====================================================================================\r
2079\r
2080/**\r
2081 Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r
2082\r
2083 @return Pointer to the Diffie-Hellman Context that has been initialized.\r
2084 If the allocations fails, DhNew() returns NULL.\r
532616bb 2085 If the interface is not supported, DhNew() returns NULL.\r
a8c44645 2086\r
2087**/\r
2088VOID *\r
2089EFIAPI\r
2090DhNew (\r
2091 VOID\r
2092 );\r
2093\r
2094/**\r
2095 Release the specified DH context.\r
2096\r
532616bb 2097 If the interface is not supported, then ASSERT().\r
a8c44645 2098\r
2099 @param[in] DhContext Pointer to the DH context to be released.\r
2100\r
2101**/\r
2102VOID\r
2103EFIAPI\r
2104DhFree (\r
2105 IN VOID *DhContext\r
2106 );\r
2107\r
2108/**\r
2109 Generates DH parameter.\r
2110\r
2111 Given generator g, and length of prime number p in bits, this function generates p,\r
2112 and sets DH context according to value of g and p.\r
2ac68e8b 2113\r
a8c44645 2114 Before this function can be invoked, pseudorandom number generator must be correctly\r
2115 initialized by RandomSeed().\r
2116\r
16d2c32c 2117 If DhContext is NULL, then return FALSE.\r
2118 If Prime is NULL, then return FALSE.\r
532616bb 2119 If this interface is not supported, then return FALSE.\r
a8c44645 2120\r
2121 @param[in, out] DhContext Pointer to the DH context.\r
2122 @param[in] Generator Value of generator.\r
2123 @param[in] PrimeLength Length in bits of prime to be generated.\r
2124 @param[out] Prime Pointer to the buffer to receive the generated prime number.\r
2125\r
2998af86 2126 @retval TRUE DH parameter generation succeeded.\r
a8c44645 2127 @retval FALSE Value of Generator is not supported.\r
2128 @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r
532616bb 2129 @retval FALSE This interface is not supported.\r
a8c44645 2130\r
2131**/\r
2132BOOLEAN\r
2133EFIAPI\r
2134DhGenerateParameter (\r
2135 IN OUT VOID *DhContext,\r
2136 IN UINTN Generator,\r
2137 IN UINTN PrimeLength,\r
2138 OUT UINT8 *Prime\r
2139 );\r
2140\r
2141/**\r
2142 Sets generator and prime parameters for DH.\r
2143\r
2144 Given generator g, and prime number p, this function and sets DH\r
2145 context accordingly.\r
2146\r
16d2c32c 2147 If DhContext is NULL, then return FALSE.\r
2148 If Prime is NULL, then return FALSE.\r
532616bb 2149 If this interface is not supported, then return FALSE.\r
a8c44645 2150\r
2151 @param[in, out] DhContext Pointer to the DH context.\r
2152 @param[in] Generator Value of generator.\r
2153 @param[in] PrimeLength Length in bits of prime to be generated.\r
2154 @param[in] Prime Pointer to the prime number.\r
2155\r
2998af86 2156 @retval TRUE DH parameter setting succeeded.\r
a8c44645 2157 @retval FALSE Value of Generator is not supported.\r
2158 @retval FALSE Value of Generator is not suitable for the Prime.\r
2159 @retval FALSE Value of Prime is not a prime number.\r
2160 @retval FALSE Value of Prime is not a safe prime number.\r
532616bb 2161 @retval FALSE This interface is not supported.\r
a8c44645 2162\r
2163**/\r
2164BOOLEAN\r
2165EFIAPI\r
2166DhSetParameter (\r
2167 IN OUT VOID *DhContext,\r
2168 IN UINTN Generator,\r
2169 IN UINTN PrimeLength,\r
2170 IN CONST UINT8 *Prime\r
97f98500
HT
2171 );\r
2172\r
a8c44645 2173/**\r
2174 Generates DH public key.\r
2175\r
2ac68e8b 2176 This function generates random secret exponent, and computes the public key, which is\r
a8c44645 2177 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r
2178 If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r
2179 PublicKeySize is set to the required buffer size to obtain the public key.\r
2180\r
16d2c32c 2181 If DhContext is NULL, then return FALSE.\r
2182 If PublicKeySize is NULL, then return FALSE.\r
2183 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r
532616bb 2184 If this interface is not supported, then return FALSE.\r
a8c44645 2185\r
2186 @param[in, out] DhContext Pointer to the DH context.\r
2187 @param[out] PublicKey Pointer to the buffer to receive generated public key.\r
2188 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r
2189 On output, the size of data returned in PublicKey buffer in bytes.\r
2190\r
2191 @retval TRUE DH public key generation succeeded.\r
2192 @retval FALSE DH public key generation failed.\r
2193 @retval FALSE PublicKeySize is not large enough.\r
532616bb 2194 @retval FALSE This interface is not supported.\r
a8c44645 2195\r
2196**/\r
2197BOOLEAN\r
2198EFIAPI\r
2199DhGenerateKey (\r
2200 IN OUT VOID *DhContext,\r
2201 OUT UINT8 *PublicKey,\r
2202 IN OUT UINTN *PublicKeySize\r
2203 );\r
2204\r
2205/**\r
2206 Computes exchanged common key.\r
2207\r
2208 Given peer's public key, this function computes the exchanged common key, based on its own\r
dda39f3a 2209 context including value of prime modulus and random secret exponent.\r
a8c44645 2210\r
16d2c32c 2211 If DhContext is NULL, then return FALSE.\r
2212 If PeerPublicKey is NULL, then return FALSE.\r
2213 If KeySize is NULL, then return FALSE.\r
dda39f3a 2214 If Key is NULL, then return FALSE.\r
2215 If KeySize is not large enough, then return FALSE.\r
532616bb 2216 If this interface is not supported, then return FALSE.\r
a8c44645 2217\r
2218 @param[in, out] DhContext Pointer to the DH context.\r
2219 @param[in] PeerPublicKey Pointer to the peer's public key.\r
2220 @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r
2221 @param[out] Key Pointer to the buffer to receive generated key.\r
2222 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
2223 On output, the size of data returned in Key buffer in bytes.\r
2224\r
2225 @retval TRUE DH exchanged key generation succeeded.\r
2226 @retval FALSE DH exchanged key generation failed.\r
2227 @retval FALSE KeySize is not large enough.\r
532616bb 2228 @retval FALSE This interface is not supported.\r
a8c44645 2229\r
2230**/\r
2231BOOLEAN\r
2232EFIAPI\r
2233DhComputeKey (\r
2234 IN OUT VOID *DhContext,\r
2235 IN CONST UINT8 *PeerPublicKey,\r
2236 IN UINTN PeerPublicKeySize,\r
2237 OUT UINT8 *Key,\r
2238 IN OUT UINTN *KeySize\r
2239 );\r
2240\r
2241//=====================================================================================\r
2242// Pseudo-Random Generation Primitive\r
2243//=====================================================================================\r
2244\r
2245/**\r
2246 Sets up the seed value for the pseudorandom number generator.\r
2247\r
2248 This function sets up the seed value for the pseudorandom number generator.\r
2249 If Seed is not NULL, then the seed passed in is used.\r
2250 If Seed is NULL, then default seed is used.\r
532616bb 2251 If this interface is not supported, then return FALSE.\r
a8c44645 2252\r
2253 @param[in] Seed Pointer to seed value.\r
2254 If NULL, default seed is used.\r
2255 @param[in] SeedSize Size of seed value.\r
2256 If Seed is NULL, this parameter is ignored.\r
2257\r
2258 @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r
2259 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r
532616bb 2260 @retval FALSE This interface is not supported.\r
a8c44645 2261\r
2262**/\r
2263BOOLEAN\r
2264EFIAPI\r
2265RandomSeed (\r
2266 IN CONST UINT8 *Seed OPTIONAL,\r
2267 IN UINTN SeedSize\r
2268 );\r
2269\r
2270/**\r
2271 Generates a pseudorandom byte stream of the specified size.\r
2272\r
16d2c32c 2273 If Output is NULL, then return FALSE.\r
532616bb 2274 If this interface is not supported, then return FALSE.\r
a8c44645 2275\r
2276 @param[out] Output Pointer to buffer to receive random value.\r
2998af86 2277 @param[in] Size Size of random bytes to generate.\r
a8c44645 2278\r
2279 @retval TRUE Pseudorandom byte stream generated successfully.\r
2280 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r
532616bb 2281 @retval FALSE This interface is not supported.\r
a8c44645 2282\r
2283**/\r
2284BOOLEAN\r
2285EFIAPI\r
2286RandomBytes (\r
2287 OUT UINT8 *Output,\r
2288 IN UINTN Size\r
2289 );\r
97f98500 2290\r
4b1b7c19
GW
2291//=====================================================================================\r
2292// Key Derivation Function Primitive\r
2293//=====================================================================================\r
2294\r
2295/**\r
2296 Derive key data using HMAC-SHA256 based KDF.\r
2297\r
2298 @param[in] Key Pointer to the user-supplied key.\r
2299 @param[in] KeySize Key size in bytes.\r
2300 @param[in] Salt Pointer to the salt(non-secret) value.\r
2301 @param[in] SaltSize Salt size in bytes.\r
2302 @param[in] Info Pointer to the application specific info.\r
2303 @param[in] InfoSize Info size in bytes.\r
944bd5cf 2304 @param[out] Out Pointer to buffer to receive hkdf value.\r
4b1b7c19
GW
2305 @param[in] OutSize Size of hkdf bytes to generate.\r
2306\r
2307 @retval TRUE Hkdf generated successfully.\r
2308 @retval FALSE Hkdf generation failed.\r
2309\r
2310**/\r
2311BOOLEAN\r
2312EFIAPI\r
2313HkdfSha256ExtractAndExpand (\r
2314 IN CONST UINT8 *Key,\r
2315 IN UINTN KeySize,\r
2316 IN CONST UINT8 *Salt,\r
2317 IN UINTN SaltSize,\r
2318 IN CONST UINT8 *Info,\r
2319 IN UINTN InfoSize,\r
2320 OUT UINT8 *Out,\r
2321 IN UINTN OutSize\r
2322 );\r
2323\r
afeb55e4 2324#endif // __BASE_CRYPT_LIB_H__\r