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