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