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