]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c
CryptoPkg: add new X509 function to Crypto Service.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLibOnProtocolPpi / CryptLib.c
CommitLineData
cd70de1c
MK
1/** @file\r
2 Implements the BaseCryptLib and TlsLib using the services of the EDK II Crypto\r
3 Protocol/PPI.\r
4\r
5 Copyright (C) Microsoft Corporation. All rights reserved.\r
c1e66210 6 Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>\r
cd70de1c
MK
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10\r
11#include <Base.h>\r
12#include <Library/BaseLib.h>\r
13#include <Library/DebugLib.h>\r
14#include <Library/BaseCryptLib.h>\r
15#include <Library/TlsLib.h>\r
16#include <Protocol/Crypto.h>\r
17\r
18/**\r
19 A macro used to call a non-void service in an EDK II Crypto Protocol.\r
20 If the protocol is NULL or the service in the protocol is NULL, then a debug\r
21 message and assert is generated and an appropriate return value is returned.\r
22\r
23 @param Function Name of the EDK II Crypto Protocol service to call.\r
24 @param Args The argument list to pass to Function.\r
25 @param ErrorReturnValue The value to return if the protocol is NULL or the\r
26 service in the protocol is NULL.\r
27\r
28**/\r
29#define CALL_CRYPTO_SERVICE(Function, Args, ErrorReturnValue) \\r
30 do { \\r
31 EDKII_CRYPTO_PROTOCOL *CryptoServices; \\r
32 \\r
33 CryptoServices = (EDKII_CRYPTO_PROTOCOL *)GetCryptoServices (); \\r
34 if (CryptoServices != NULL && CryptoServices->Function != NULL) { \\r
35 return (CryptoServices->Function) Args; \\r
36 } \\r
37 CryptoServiceNotAvailable (#Function); \\r
38 return ErrorReturnValue; \\r
39 } while (FALSE);\r
40\r
41/**\r
42 A macro used to call a void service in an EDK II Crypto Protocol.\r
43 If the protocol is NULL or the service in the protocol is NULL, then a debug\r
44 message and assert is generated.\r
45\r
46 @param Function Name of the EDK II Crypto Protocol service to call.\r
47 @param Args The argument list to pass to Function.\r
48\r
49**/\r
50#define CALL_VOID_CRYPTO_SERVICE(Function, Args) \\r
51 do { \\r
52 EDKII_CRYPTO_PROTOCOL *CryptoServices; \\r
53 \\r
54 CryptoServices = (EDKII_CRYPTO_PROTOCOL *)GetCryptoServices (); \\r
55 if (CryptoServices != NULL && CryptoServices->Function != NULL) { \\r
56 (CryptoServices->Function) Args; \\r
57 return; \\r
58 } \\r
59 CryptoServiceNotAvailable (#Function); \\r
60 return; \\r
61 } while (FALSE);\r
62\r
63/**\r
64 Internal worker function that returns the pointer to an EDK II Crypto\r
65 Protocol/PPI. The layout of the PPI, DXE Protocol, and SMM Protocol are\r
66 identical which allows the implementation of the BaseCryptLib functions that\r
67 call through a Protocol/PPI to be shared for the PEI, DXE, and SMM\r
68 implementations.\r
69**/\r
70VOID *\r
71GetCryptoServices (\r
72 VOID\r
73 );\r
74\r
75/**\r
76 Internal worker function that prints a debug message and asserts if a crypto\r
77 service is not available. This should never occur because library instances\r
78 have a dependency expression for the for the EDK II Crypto Protocol/PPI so\r
79 a module that uses these library instances are not dispatched until the EDK II\r
80 Crypto Protocol/PPI is available. The only case that this function handles is\r
81 if the EDK II Crypto Protocol/PPI installed is NULL or a function pointer in\r
82 the EDK II Protocol/PPI is NULL.\r
83\r
84 @param[in] FunctionName Null-terminated ASCII string that is the name of an\r
85 EDK II Crypto service.\r
86\r
87**/\r
88static\r
89VOID\r
90CryptoServiceNotAvailable (\r
91 IN CONST CHAR8 *FunctionName\r
92 )\r
93{\r
94 DEBUG ((DEBUG_ERROR, "[%a] Function %a is not available\n", gEfiCallerBaseName, FunctionName));\r
95 ASSERT_EFI_ERROR (EFI_UNSUPPORTED);\r
96}\r
97\r
7c342378 98// =====================================================================================\r
cd70de1c 99// One-Way Cryptographic Hash Primitives\r
7c342378 100// =====================================================================================\r
cd70de1c 101\r
e6a12a0f 102#ifdef ENABLE_MD5_DEPRECATED_INTERFACES\r
7c342378 103\r
cd70de1c
MK
104/**\r
105 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
106\r
107 If this interface is not supported, then return zero.\r
108\r
109 @return The size, in bytes, of the context buffer required for MD5 hash operations.\r
110 @retval 0 This interface is not supported.\r
111\r
112**/\r
113UINTN\r
114EFIAPI\r
115Md5GetContextSize (\r
116 VOID\r
117 )\r
118{\r
119 CALL_CRYPTO_SERVICE (Md5GetContextSize, (), 0);\r
120}\r
121\r
122/**\r
123 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r
124 subsequent use.\r
125\r
126 If Md5Context is NULL, then return FALSE.\r
127 If this interface is not supported, then return FALSE.\r
128\r
129 @param[out] Md5Context Pointer to MD5 context being initialized.\r
130\r
131 @retval TRUE MD5 context initialization succeeded.\r
132 @retval FALSE MD5 context initialization failed.\r
133 @retval FALSE This interface is not supported.\r
134\r
135**/\r
136BOOLEAN\r
137EFIAPI\r
138Md5Init (\r
139 OUT VOID *Md5Context\r
140 )\r
141{\r
142 CALL_CRYPTO_SERVICE (Md5Init, (Md5Context), FALSE);\r
143}\r
144\r
145/**\r
146 Makes a copy of an existing MD5 context.\r
147\r
148 If Md5Context is NULL, then return FALSE.\r
149 If NewMd5Context is NULL, then return FALSE.\r
150 If this interface is not supported, then return FALSE.\r
151\r
152 @param[in] Md5Context Pointer to MD5 context being copied.\r
153 @param[out] NewMd5Context Pointer to new MD5 context.\r
154\r
155 @retval TRUE MD5 context copy succeeded.\r
156 @retval FALSE MD5 context copy failed.\r
157 @retval FALSE This interface is not supported.\r
158\r
159**/\r
160BOOLEAN\r
161EFIAPI\r
162Md5Duplicate (\r
163 IN CONST VOID *Md5Context,\r
164 OUT VOID *NewMd5Context\r
165 )\r
166{\r
167 CALL_CRYPTO_SERVICE (Md5Duplicate, (Md5Context, NewMd5Context), FALSE);\r
168}\r
169\r
170/**\r
171 Digests the input data and updates MD5 context.\r
172\r
173 This function performs MD5 digest on a data buffer of the specified size.\r
174 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
175 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized\r
176 by Md5Final(). Behavior with invalid context is undefined.\r
177\r
178 If Md5Context is NULL, then return FALSE.\r
179 If this interface is not supported, then return FALSE.\r
180\r
181 @param[in, out] Md5Context Pointer to the MD5 context.\r
182 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
183 @param[in] DataSize Size of Data buffer in bytes.\r
184\r
185 @retval TRUE MD5 data digest succeeded.\r
186 @retval FALSE MD5 data digest failed.\r
187 @retval FALSE This interface is not supported.\r
188\r
189**/\r
190BOOLEAN\r
191EFIAPI\r
192Md5Update (\r
193 IN OUT VOID *Md5Context,\r
194 IN CONST VOID *Data,\r
195 IN UINTN DataSize\r
196 )\r
197{\r
198 CALL_CRYPTO_SERVICE (Md5Update, (Md5Context, Data, DataSize), FALSE);\r
199}\r
200\r
201/**\r
202 Completes computation of the MD5 digest value.\r
203\r
204 This function completes MD5 hash computation and retrieves the digest value into\r
205 the specified memory. After this function has been called, the MD5 context cannot\r
206 be used again.\r
207 MD5 context should be already correctly initialized by Md5Init(), and should not be\r
208 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r
209\r
210 If Md5Context is NULL, then return FALSE.\r
211 If HashValue is NULL, then return FALSE.\r
212 If this interface is not supported, then return FALSE.\r
213\r
214 @param[in, out] Md5Context Pointer to the MD5 context.\r
215 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
216 value (16 bytes).\r
217\r
218 @retval TRUE MD5 digest computation succeeded.\r
219 @retval FALSE MD5 digest computation failed.\r
220 @retval FALSE This interface is not supported.\r
221\r
222**/\r
223BOOLEAN\r
224EFIAPI\r
225Md5Final (\r
226 IN OUT VOID *Md5Context,\r
227 OUT UINT8 *HashValue\r
228 )\r
229{\r
230 CALL_CRYPTO_SERVICE (Md5Final, (Md5Context, HashValue), FALSE);\r
231}\r
232\r
233/**\r
234 Computes the MD5 message digest of a input data buffer.\r
235\r
236 This function performs the MD5 message digest of a given data buffer, and places\r
237 the digest value into the specified memory.\r
238\r
239 If this interface is not supported, then return FALSE.\r
240\r
241 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
242 @param[in] DataSize Size of Data buffer in bytes.\r
243 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
244 value (16 bytes).\r
245\r
246 @retval TRUE MD5 digest computation succeeded.\r
247 @retval FALSE MD5 digest computation failed.\r
248 @retval FALSE This interface is not supported.\r
249\r
250**/\r
251BOOLEAN\r
252EFIAPI\r
253Md5HashAll (\r
254 IN CONST VOID *Data,\r
255 IN UINTN DataSize,\r
256 OUT UINT8 *HashValue\r
257 )\r
258{\r
259 CALL_CRYPTO_SERVICE (Md5HashAll, (Data, DataSize, HashValue), FALSE);\r
260}\r
7c342378 261\r
acfd5557 262#endif\r
cd70de1c 263\r
0f01cec5 264#ifndef DISABLE_SHA1_DEPRECATED_INTERFACES\r
7c342378 265\r
cd70de1c
MK
266/**\r
267 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
268\r
269 If this interface is not supported, then return zero.\r
270\r
271 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.\r
272 @retval 0 This interface is not supported.\r
273\r
274**/\r
275UINTN\r
276EFIAPI\r
277Sha1GetContextSize (\r
278 VOID\r
279 )\r
280{\r
281 CALL_CRYPTO_SERVICE (Sha1GetContextSize, (), 0);\r
282}\r
283\r
284/**\r
285 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for\r
286 subsequent use.\r
287\r
288 If Sha1Context is NULL, then return FALSE.\r
289 If this interface is not supported, then return FALSE.\r
290\r
291 @param[out] Sha1Context Pointer to SHA-1 context being initialized.\r
292\r
293 @retval TRUE SHA-1 context initialization succeeded.\r
294 @retval FALSE SHA-1 context initialization failed.\r
295 @retval FALSE This interface is not supported.\r
296\r
297**/\r
298BOOLEAN\r
299EFIAPI\r
300Sha1Init (\r
301 OUT VOID *Sha1Context\r
302 )\r
303{\r
304 CALL_CRYPTO_SERVICE (Sha1Init, (Sha1Context), FALSE);\r
305}\r
306\r
307/**\r
308 Makes a copy of an existing SHA-1 context.\r
309\r
310 If Sha1Context is NULL, then return FALSE.\r
311 If NewSha1Context is NULL, then return FALSE.\r
312 If this interface is not supported, then return FALSE.\r
313\r
314 @param[in] Sha1Context Pointer to SHA-1 context being copied.\r
315 @param[out] NewSha1Context Pointer to new SHA-1 context.\r
316\r
317 @retval TRUE SHA-1 context copy succeeded.\r
318 @retval FALSE SHA-1 context copy failed.\r
319 @retval FALSE This interface is not supported.\r
320\r
321**/\r
322BOOLEAN\r
323EFIAPI\r
324Sha1Duplicate (\r
325 IN CONST VOID *Sha1Context,\r
326 OUT VOID *NewSha1Context\r
327 )\r
328{\r
329 CALL_CRYPTO_SERVICE (Sha1Duplicate, (Sha1Context, NewSha1Context), FALSE);\r
330}\r
331\r
332/**\r
333 Digests the input data and updates SHA-1 context.\r
334\r
335 This function performs SHA-1 digest on a data buffer of the specified size.\r
336 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
337 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized\r
338 by Sha1Final(). Behavior with invalid context is undefined.\r
339\r
340 If Sha1Context is NULL, then return FALSE.\r
341 If this interface is not supported, then return FALSE.\r
342\r
343 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
344 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
345 @param[in] DataSize Size of Data buffer in bytes.\r
346\r
347 @retval TRUE SHA-1 data digest succeeded.\r
348 @retval FALSE SHA-1 data digest failed.\r
349 @retval FALSE This interface is not supported.\r
350\r
351**/\r
352BOOLEAN\r
353EFIAPI\r
354Sha1Update (\r
355 IN OUT VOID *Sha1Context,\r
356 IN CONST VOID *Data,\r
357 IN UINTN DataSize\r
358 )\r
359{\r
360 CALL_CRYPTO_SERVICE (Sha1Update, (Sha1Context, Data, DataSize), FALSE);\r
361}\r
362\r
363/**\r
364 Completes computation of the SHA-1 digest value.\r
365\r
366 This function completes SHA-1 hash computation and retrieves the digest value into\r
367 the specified memory. After this function has been called, the SHA-1 context cannot\r
368 be used again.\r
369 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be\r
370 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.\r
371\r
372 If Sha1Context is NULL, then return FALSE.\r
373 If HashValue is NULL, then return FALSE.\r
374 If this interface is not supported, then return FALSE.\r
375\r
376 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
377 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
378 value (20 bytes).\r
379\r
380 @retval TRUE SHA-1 digest computation succeeded.\r
381 @retval FALSE SHA-1 digest computation failed.\r
382 @retval FALSE This interface is not supported.\r
383\r
384**/\r
385BOOLEAN\r
386EFIAPI\r
387Sha1Final (\r
388 IN OUT VOID *Sha1Context,\r
389 OUT UINT8 *HashValue\r
390 )\r
391{\r
392 CALL_CRYPTO_SERVICE (Sha1Final, (Sha1Context, HashValue), FALSE);\r
393}\r
394\r
395/**\r
396 Computes the SHA-1 message digest of a input data buffer.\r
397\r
398 This function performs the SHA-1 message digest of a given data buffer, and places\r
399 the digest value into the specified memory.\r
400\r
401 If this interface is not supported, then return FALSE.\r
402\r
403 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
404 @param[in] DataSize Size of Data buffer in bytes.\r
405 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
406 value (20 bytes).\r
407\r
408 @retval TRUE SHA-1 digest computation succeeded.\r
409 @retval FALSE SHA-1 digest computation failed.\r
410 @retval FALSE This interface is not supported.\r
411\r
412**/\r
413BOOLEAN\r
414EFIAPI\r
415Sha1HashAll (\r
416 IN CONST VOID *Data,\r
417 IN UINTN DataSize,\r
418 OUT UINT8 *HashValue\r
419 )\r
420{\r
421 CALL_CRYPTO_SERVICE (Sha1HashAll, (Data, DataSize, HashValue), FALSE);\r
422}\r
7c342378 423\r
0f01cec5 424#endif\r
cd70de1c
MK
425\r
426/**\r
427 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.\r
428\r
429 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.\r
430\r
431**/\r
432UINTN\r
433EFIAPI\r
434Sha256GetContextSize (\r
435 VOID\r
436 )\r
437{\r
438 CALL_CRYPTO_SERVICE (Sha256GetContextSize, (), 0);\r
439}\r
440\r
441/**\r
442 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for\r
443 subsequent use.\r
444\r
445 If Sha256Context is NULL, then return FALSE.\r
446\r
447 @param[out] Sha256Context Pointer to SHA-256 context being initialized.\r
448\r
449 @retval TRUE SHA-256 context initialization succeeded.\r
450 @retval FALSE SHA-256 context initialization failed.\r
451\r
452**/\r
453BOOLEAN\r
454EFIAPI\r
455Sha256Init (\r
456 OUT VOID *Sha256Context\r
457 )\r
458{\r
459 CALL_CRYPTO_SERVICE (Sha256Init, (Sha256Context), FALSE);\r
460}\r
461\r
462/**\r
463 Makes a copy of an existing SHA-256 context.\r
464\r
465 If Sha256Context is NULL, then return FALSE.\r
466 If NewSha256Context is NULL, then return FALSE.\r
467 If this interface is not supported, then return FALSE.\r
468\r
469 @param[in] Sha256Context Pointer to SHA-256 context being copied.\r
470 @param[out] NewSha256Context Pointer to new SHA-256 context.\r
471\r
472 @retval TRUE SHA-256 context copy succeeded.\r
473 @retval FALSE SHA-256 context copy failed.\r
474 @retval FALSE This interface is not supported.\r
475\r
476**/\r
477BOOLEAN\r
478EFIAPI\r
479Sha256Duplicate (\r
480 IN CONST VOID *Sha256Context,\r
481 OUT VOID *NewSha256Context\r
482 )\r
483{\r
484 CALL_CRYPTO_SERVICE (Sha256Duplicate, (Sha256Context, NewSha256Context), FALSE);\r
485}\r
486\r
487/**\r
488 Digests the input data and updates SHA-256 context.\r
489\r
490 This function performs SHA-256 digest on a data buffer of the specified size.\r
491 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
492 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized\r
493 by Sha256Final(). Behavior with invalid context is undefined.\r
494\r
495 If Sha256Context is NULL, then return FALSE.\r
496\r
497 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
498 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
499 @param[in] DataSize Size of Data buffer in bytes.\r
500\r
501 @retval TRUE SHA-256 data digest succeeded.\r
502 @retval FALSE SHA-256 data digest failed.\r
503\r
504**/\r
505BOOLEAN\r
506EFIAPI\r
507Sha256Update (\r
508 IN OUT VOID *Sha256Context,\r
509 IN CONST VOID *Data,\r
510 IN UINTN DataSize\r
511 )\r
512{\r
513 CALL_CRYPTO_SERVICE (Sha256Update, (Sha256Context, Data, DataSize), FALSE);\r
514}\r
515\r
516/**\r
517 Completes computation of the SHA-256 digest value.\r
518\r
519 This function completes SHA-256 hash computation and retrieves the digest value into\r
520 the specified memory. After this function has been called, the SHA-256 context cannot\r
521 be used again.\r
522 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be\r
523 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.\r
524\r
525 If Sha256Context is NULL, then return FALSE.\r
526 If HashValue is NULL, then return FALSE.\r
527\r
528 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
529 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
530 value (32 bytes).\r
531\r
532 @retval TRUE SHA-256 digest computation succeeded.\r
533 @retval FALSE SHA-256 digest computation failed.\r
534\r
535**/\r
536BOOLEAN\r
537EFIAPI\r
538Sha256Final (\r
539 IN OUT VOID *Sha256Context,\r
540 OUT UINT8 *HashValue\r
541 )\r
542{\r
543 CALL_CRYPTO_SERVICE (Sha256Final, (Sha256Context, HashValue), FALSE);\r
544}\r
545\r
546/**\r
547 Computes the SHA-256 message digest of a input data buffer.\r
548\r
549 This function performs the SHA-256 message digest of a given data buffer, and places\r
550 the digest value into the specified memory.\r
551\r
552 If this interface is not supported, then return FALSE.\r
553\r
554 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
555 @param[in] DataSize Size of Data buffer in bytes.\r
556 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
557 value (32 bytes).\r
558\r
559 @retval TRUE SHA-256 digest computation succeeded.\r
560 @retval FALSE SHA-256 digest computation failed.\r
561 @retval FALSE This interface is not supported.\r
562\r
563**/\r
564BOOLEAN\r
565EFIAPI\r
566Sha256HashAll (\r
567 IN CONST VOID *Data,\r
568 IN UINTN DataSize,\r
569 OUT UINT8 *HashValue\r
570 )\r
571{\r
572 CALL_CRYPTO_SERVICE (Sha256HashAll, (Data, DataSize, HashValue), FALSE);\r
573}\r
574\r
575/**\r
576 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.\r
577\r
578 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.\r
579\r
580**/\r
581UINTN\r
582EFIAPI\r
583Sha384GetContextSize (\r
584 VOID\r
585 )\r
586{\r
587 CALL_CRYPTO_SERVICE (Sha384GetContextSize, (), 0);\r
588}\r
589\r
590/**\r
591 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for\r
592 subsequent use.\r
593\r
594 If Sha384Context is NULL, then return FALSE.\r
595\r
596 @param[out] Sha384Context Pointer to SHA-384 context being initialized.\r
597\r
598 @retval TRUE SHA-384 context initialization succeeded.\r
599 @retval FALSE SHA-384 context initialization failed.\r
600\r
601**/\r
602BOOLEAN\r
603EFIAPI\r
604Sha384Init (\r
605 OUT VOID *Sha384Context\r
606 )\r
607{\r
608 CALL_CRYPTO_SERVICE (Sha384Init, (Sha384Context), FALSE);\r
609}\r
610\r
611/**\r
612 Makes a copy of an existing SHA-384 context.\r
613\r
614 If Sha384Context is NULL, then return FALSE.\r
615 If NewSha384Context is NULL, then return FALSE.\r
616 If this interface is not supported, then return FALSE.\r
617\r
618 @param[in] Sha384Context Pointer to SHA-384 context being copied.\r
619 @param[out] NewSha384Context Pointer to new SHA-384 context.\r
620\r
621 @retval TRUE SHA-384 context copy succeeded.\r
622 @retval FALSE SHA-384 context copy failed.\r
623 @retval FALSE This interface is not supported.\r
624\r
625**/\r
626BOOLEAN\r
627EFIAPI\r
628Sha384Duplicate (\r
629 IN CONST VOID *Sha384Context,\r
630 OUT VOID *NewSha384Context\r
631 )\r
632{\r
633 CALL_CRYPTO_SERVICE (Sha384Duplicate, (Sha384Context, NewSha384Context), FALSE);\r
634}\r
635\r
636/**\r
637 Digests the input data and updates SHA-384 context.\r
638\r
639 This function performs SHA-384 digest on a data buffer of the specified size.\r
640 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
641 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized\r
642 by Sha384Final(). Behavior with invalid context is undefined.\r
643\r
644 If Sha384Context is NULL, then return FALSE.\r
645\r
646 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
647 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
648 @param[in] DataSize Size of Data buffer in bytes.\r
649\r
650 @retval TRUE SHA-384 data digest succeeded.\r
651 @retval FALSE SHA-384 data digest failed.\r
652\r
653**/\r
654BOOLEAN\r
655EFIAPI\r
656Sha384Update (\r
657 IN OUT VOID *Sha384Context,\r
658 IN CONST VOID *Data,\r
659 IN UINTN DataSize\r
660 )\r
661{\r
662 CALL_CRYPTO_SERVICE (Sha384Update, (Sha384Context, Data, DataSize), FALSE);\r
663}\r
664\r
665/**\r
666 Completes computation of the SHA-384 digest value.\r
667\r
668 This function completes SHA-384 hash computation and retrieves the digest value into\r
669 the specified memory. After this function has been called, the SHA-384 context cannot\r
670 be used again.\r
671 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be\r
672 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.\r
673\r
674 If Sha384Context is NULL, then return FALSE.\r
675 If HashValue is NULL, then return FALSE.\r
676\r
677 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
678 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
679 value (48 bytes).\r
680\r
681 @retval TRUE SHA-384 digest computation succeeded.\r
682 @retval FALSE SHA-384 digest computation failed.\r
683\r
684**/\r
685BOOLEAN\r
686EFIAPI\r
687Sha384Final (\r
688 IN OUT VOID *Sha384Context,\r
689 OUT UINT8 *HashValue\r
690 )\r
691{\r
692 CALL_CRYPTO_SERVICE (Sha384Final, (Sha384Context, HashValue), FALSE);\r
693}\r
694\r
695/**\r
696 Computes the SHA-384 message digest of a input data buffer.\r
697\r
698 This function performs the SHA-384 message digest of a given data buffer, and places\r
699 the digest value into the specified memory.\r
700\r
701 If this interface is not supported, then return FALSE.\r
702\r
703 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
704 @param[in] DataSize Size of Data buffer in bytes.\r
705 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
706 value (48 bytes).\r
707\r
708 @retval TRUE SHA-384 digest computation succeeded.\r
709 @retval FALSE SHA-384 digest computation failed.\r
710 @retval FALSE This interface is not supported.\r
711\r
712**/\r
713BOOLEAN\r
714EFIAPI\r
715Sha384HashAll (\r
716 IN CONST VOID *Data,\r
717 IN UINTN DataSize,\r
718 OUT UINT8 *HashValue\r
719 )\r
720{\r
721 CALL_CRYPTO_SERVICE (Sha384HashAll, (Data, DataSize, HashValue), FALSE);\r
722}\r
723\r
724/**\r
725 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
726\r
727 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.\r
728\r
729**/\r
730UINTN\r
731EFIAPI\r
732Sha512GetContextSize (\r
733 VOID\r
734 )\r
735{\r
736 CALL_CRYPTO_SERVICE (Sha512GetContextSize, (), 0);\r
737}\r
738\r
739/**\r
740 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for\r
741 subsequent use.\r
742\r
743 If Sha512Context is NULL, then return FALSE.\r
744\r
745 @param[out] Sha512Context Pointer to SHA-512 context being initialized.\r
746\r
747 @retval TRUE SHA-512 context initialization succeeded.\r
748 @retval FALSE SHA-512 context initialization failed.\r
749\r
750**/\r
751BOOLEAN\r
752EFIAPI\r
753Sha512Init (\r
754 OUT VOID *Sha512Context\r
755 )\r
756{\r
757 CALL_CRYPTO_SERVICE (Sha512Init, (Sha512Context), FALSE);\r
758}\r
759\r
760/**\r
761 Makes a copy of an existing SHA-512 context.\r
762\r
763 If Sha512Context is NULL, then return FALSE.\r
764 If NewSha512Context is NULL, then return FALSE.\r
765 If this interface is not supported, then return FALSE.\r
766\r
767 @param[in] Sha512Context Pointer to SHA-512 context being copied.\r
768 @param[out] NewSha512Context Pointer to new SHA-512 context.\r
769\r
770 @retval TRUE SHA-512 context copy succeeded.\r
771 @retval FALSE SHA-512 context copy failed.\r
772 @retval FALSE This interface is not supported.\r
773\r
774**/\r
775BOOLEAN\r
776EFIAPI\r
777Sha512Duplicate (\r
778 IN CONST VOID *Sha512Context,\r
779 OUT VOID *NewSha512Context\r
780 )\r
781{\r
782 CALL_CRYPTO_SERVICE (Sha512Duplicate, (Sha512Context, NewSha512Context), FALSE);\r
783}\r
784\r
785/**\r
786 Digests the input data and updates SHA-512 context.\r
787\r
788 This function performs SHA-512 digest on a data buffer of the specified size.\r
789 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
790 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized\r
791 by Sha512Final(). Behavior with invalid context is undefined.\r
792\r
793 If Sha512Context is NULL, then return FALSE.\r
794\r
795 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
796 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
797 @param[in] DataSize Size of Data buffer in bytes.\r
798\r
799 @retval TRUE SHA-512 data digest succeeded.\r
800 @retval FALSE SHA-512 data digest failed.\r
801\r
802**/\r
803BOOLEAN\r
804EFIAPI\r
805Sha512Update (\r
806 IN OUT VOID *Sha512Context,\r
807 IN CONST VOID *Data,\r
808 IN UINTN DataSize\r
809 )\r
810{\r
811 CALL_CRYPTO_SERVICE (Sha512Update, (Sha512Context, Data, DataSize), FALSE);\r
812}\r
813\r
814/**\r
815 Completes computation of the SHA-512 digest value.\r
816\r
817 This function completes SHA-512 hash computation and retrieves the digest value into\r
818 the specified memory. After this function has been called, the SHA-512 context cannot\r
819 be used again.\r
820 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be\r
821 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.\r
822\r
823 If Sha512Context is NULL, then return FALSE.\r
824 If HashValue is NULL, then return FALSE.\r
825\r
826 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
827 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
828 value (64 bytes).\r
829\r
830 @retval TRUE SHA-512 digest computation succeeded.\r
831 @retval FALSE SHA-512 digest computation failed.\r
832\r
833**/\r
834BOOLEAN\r
835EFIAPI\r
836Sha512Final (\r
837 IN OUT VOID *Sha512Context,\r
838 OUT UINT8 *HashValue\r
839 )\r
840{\r
841 CALL_CRYPTO_SERVICE (Sha512Final, (Sha512Context, HashValue), FALSE);\r
842}\r
843\r
844/**\r
845 Computes the SHA-512 message digest of a input data buffer.\r
846\r
847 This function performs the SHA-512 message digest of a given data buffer, and places\r
848 the digest value into the specified memory.\r
849\r
850 If this interface is not supported, then return FALSE.\r
851\r
852 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
853 @param[in] DataSize Size of Data buffer in bytes.\r
854 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
855 value (64 bytes).\r
856\r
857 @retval TRUE SHA-512 digest computation succeeded.\r
858 @retval FALSE SHA-512 digest computation failed.\r
859 @retval FALSE This interface is not supported.\r
860\r
861**/\r
862BOOLEAN\r
863EFIAPI\r
864Sha512HashAll (\r
865 IN CONST VOID *Data,\r
866 IN UINTN DataSize,\r
867 OUT UINT8 *HashValue\r
868 )\r
869{\r
870 CALL_CRYPTO_SERVICE (Sha512HashAll, (Data, DataSize, HashValue), FALSE);\r
871}\r
872\r
c1e66210
ZL
873/**\r
874 Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,\r
875 published December 2016.\r
876\r
877 @param[in] Input Pointer to the input message (X).\r
878 @param[in] InputByteLen The number(>0) of input bytes provided for the input data.\r
879 @param[in] BlockSize The size of each block (B).\r
880 @param[out] Output Pointer to the output buffer.\r
881 @param[in] OutputByteLen The desired number of output bytes (L).\r
882 @param[in] Customization Pointer to the customization string (S).\r
883 @param[in] CustomByteLen The length of the customization string in bytes.\r
884\r
885 @retval TRUE ParallelHash256 digest computation succeeded.\r
886 @retval FALSE ParallelHash256 digest computation failed.\r
887 @retval FALSE This interface is not supported.\r
888\r
889**/\r
890BOOLEAN\r
891EFIAPI\r
892ParallelHash256HashAll (\r
893 IN CONST VOID *Input,\r
894 IN UINTN InputByteLen,\r
895 IN UINTN BlockSize,\r
896 OUT VOID *Output,\r
897 IN UINTN OutputByteLen,\r
898 IN CONST VOID *Customization,\r
899 IN UINTN CustomByteLen\r
900 )\r
901{\r
902 CALL_CRYPTO_SERVICE (ParallelHash256HashAll, (Input, InputByteLen, BlockSize, Output, OutputByteLen, Customization, CustomByteLen), FALSE);\r
903}\r
904\r
cd70de1c
MK
905/**\r
906 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.\r
907\r
908 @return The size, in bytes, of the context buffer required for SM3 hash operations.\r
909\r
910**/\r
911UINTN\r
912EFIAPI\r
913Sm3GetContextSize (\r
914 VOID\r
915 )\r
916{\r
917 CALL_CRYPTO_SERVICE (Sm3GetContextSize, (), 0);\r
918}\r
919\r
920/**\r
921 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for\r
922 subsequent use.\r
923\r
924 If Sm3Context is NULL, then return FALSE.\r
925\r
926 @param[out] Sm3Context Pointer to SM3 context being initialized.\r
927\r
928 @retval TRUE SM3 context initialization succeeded.\r
929 @retval FALSE SM3 context initialization failed.\r
930\r
931**/\r
932BOOLEAN\r
933EFIAPI\r
934Sm3Init (\r
935 OUT VOID *Sm3Context\r
936 )\r
937{\r
938 CALL_CRYPTO_SERVICE (Sm3Init, (Sm3Context), FALSE);\r
939}\r
940\r
941/**\r
942 Makes a copy of an existing SM3 context.\r
943\r
944 If Sm3Context is NULL, then return FALSE.\r
945 If NewSm3Context is NULL, then return FALSE.\r
946 If this interface is not supported, then return FALSE.\r
947\r
948 @param[in] Sm3Context Pointer to SM3 context being copied.\r
949 @param[out] NewSm3Context Pointer to new SM3 context.\r
950\r
951 @retval TRUE SM3 context copy succeeded.\r
952 @retval FALSE SM3 context copy failed.\r
953 @retval FALSE This interface is not supported.\r
954\r
955**/\r
956BOOLEAN\r
957EFIAPI\r
958Sm3Duplicate (\r
959 IN CONST VOID *Sm3Context,\r
960 OUT VOID *NewSm3Context\r
961 )\r
962{\r
963 CALL_CRYPTO_SERVICE (Sm3Duplicate, (Sm3Context, NewSm3Context), FALSE);\r
964}\r
965\r
966/**\r
967 Digests the input data and updates SM3 context.\r
968\r
969 This function performs SM3 digest on a data buffer of the specified size.\r
970 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
971 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized\r
972 by Sm3Final(). Behavior with invalid context is undefined.\r
973\r
974 If Sm3Context is NULL, then return FALSE.\r
975\r
976 @param[in, out] Sm3Context Pointer to the SM3 context.\r
977 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
978 @param[in] DataSize Size of Data buffer in bytes.\r
979\r
980 @retval TRUE SM3 data digest succeeded.\r
981 @retval FALSE SM3 data digest failed.\r
982\r
983**/\r
984BOOLEAN\r
985EFIAPI\r
986Sm3Update (\r
987 IN OUT VOID *Sm3Context,\r
988 IN CONST VOID *Data,\r
989 IN UINTN DataSize\r
990 )\r
991{\r
992 CALL_CRYPTO_SERVICE (Sm3Update, (Sm3Context, Data, DataSize), FALSE);\r
993}\r
994\r
995/**\r
996 Completes computation of the SM3 digest value.\r
997\r
998 This function completes SM3 hash computation and retrieves the digest value into\r
999 the specified memory. After this function has been called, the SM3 context cannot\r
1000 be used again.\r
1001 SM3 context should be already correctly initialized by Sm3Init(), and should not be\r
1002 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.\r
1003\r
1004 If Sm3Context is NULL, then return FALSE.\r
1005 If HashValue is NULL, then return FALSE.\r
1006\r
1007 @param[in, out] Sm3Context Pointer to the SM3 context.\r
1008 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
1009 value (32 bytes).\r
1010\r
1011 @retval TRUE SM3 digest computation succeeded.\r
1012 @retval FALSE SM3 digest computation failed.\r
1013\r
1014**/\r
1015BOOLEAN\r
1016EFIAPI\r
1017Sm3Final (\r
1018 IN OUT VOID *Sm3Context,\r
1019 OUT UINT8 *HashValue\r
1020 )\r
1021{\r
1022 CALL_CRYPTO_SERVICE (Sm3Final, (Sm3Context, HashValue), FALSE);\r
1023}\r
1024\r
1025/**\r
1026 Computes the SM3 message digest of a input data buffer.\r
1027\r
1028 This function performs the SM3 message digest of a given data buffer, and places\r
1029 the digest value into the specified memory.\r
1030\r
1031 If this interface is not supported, then return FALSE.\r
1032\r
1033 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
1034 @param[in] DataSize Size of Data buffer in bytes.\r
1035 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
1036 value (32 bytes).\r
1037\r
1038 @retval TRUE SM3 digest computation succeeded.\r
1039 @retval FALSE SM3 digest computation failed.\r
1040 @retval FALSE This interface is not supported.\r
1041\r
1042**/\r
1043BOOLEAN\r
1044EFIAPI\r
1045Sm3HashAll (\r
1046 IN CONST VOID *Data,\r
1047 IN UINTN DataSize,\r
1048 OUT UINT8 *HashValue\r
1049 )\r
1050{\r
1051 CALL_CRYPTO_SERVICE (Sm3HashAll, (Data, DataSize, HashValue), FALSE);\r
1052}\r
1053\r
7c342378 1054// =====================================================================================\r
cd70de1c 1055// MAC (Message Authentication Code) Primitive\r
7c342378 1056// =====================================================================================\r
cd70de1c 1057\r
cd70de1c
MK
1058/**\r
1059 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.\r
1060\r
1061 @return Pointer to the HMAC_CTX context that has been initialized.\r
1062 If the allocations fails, HmacSha256New() returns NULL.\r
1063\r
1064**/\r
1065VOID *\r
1066EFIAPI\r
1067HmacSha256New (\r
1068 VOID\r
1069 )\r
1070{\r
1071 CALL_CRYPTO_SERVICE (HmacSha256New, (), NULL);\r
1072}\r
1073\r
1074/**\r
1075 Release the specified HMAC_CTX context.\r
1076\r
1077 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.\r
1078\r
1079**/\r
1080VOID\r
1081EFIAPI\r
1082HmacSha256Free (\r
1083 IN VOID *HmacSha256Ctx\r
1084 )\r
1085{\r
1086 CALL_VOID_CRYPTO_SERVICE (HmacSha256Free, (HmacSha256Ctx));\r
1087}\r
1088\r
1089/**\r
1090 Set user-supplied key for subsequent use. It must be done before any\r
1091 calling to HmacSha256Update().\r
1092\r
1093 If HmacSha256Context is NULL, then return FALSE.\r
1094 If this interface is not supported, then return FALSE.\r
1095\r
1096 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.\r
1097 @param[in] Key Pointer to the user-supplied key.\r
1098 @param[in] KeySize Key size in bytes.\r
1099\r
1100 @retval TRUE The Key is set successfully.\r
1101 @retval FALSE The Key is set unsuccessfully.\r
1102 @retval FALSE This interface is not supported.\r
1103\r
1104**/\r
1105BOOLEAN\r
1106EFIAPI\r
1107HmacSha256SetKey (\r
1108 OUT VOID *HmacSha256Context,\r
1109 IN CONST UINT8 *Key,\r
1110 IN UINTN KeySize\r
1111 )\r
1112{\r
1113 CALL_CRYPTO_SERVICE (HmacSha256SetKey, (HmacSha256Context, Key, KeySize), FALSE);\r
1114}\r
1115\r
1116/**\r
1117 Makes a copy of an existing HMAC-SHA256 context.\r
1118\r
1119 If HmacSha256Context is NULL, then return FALSE.\r
1120 If NewHmacSha256Context is NULL, then return FALSE.\r
1121 If this interface is not supported, then return FALSE.\r
1122\r
1123 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.\r
1124 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.\r
1125\r
1126 @retval TRUE HMAC-SHA256 context copy succeeded.\r
1127 @retval FALSE HMAC-SHA256 context copy failed.\r
1128 @retval FALSE This interface is not supported.\r
1129\r
1130**/\r
1131BOOLEAN\r
1132EFIAPI\r
1133HmacSha256Duplicate (\r
1134 IN CONST VOID *HmacSha256Context,\r
1135 OUT VOID *NewHmacSha256Context\r
1136 )\r
1137{\r
1138 CALL_CRYPTO_SERVICE (HmacSha256Duplicate, (HmacSha256Context, NewHmacSha256Context), FALSE);\r
1139}\r
1140\r
1141/**\r
1142 Digests the input data and updates HMAC-SHA256 context.\r
1143\r
1144 This function performs HMAC-SHA256 digest on a data buffer of the specified size.\r
1145 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1146 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1147 by HmacSha256Final(). Behavior with invalid context is undefined.\r
1148\r
1149 If HmacSha256Context is NULL, then return FALSE.\r
1150 If this interface is not supported, then return FALSE.\r
1151\r
1152 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
1153 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1154 @param[in] DataSize Size of Data buffer in bytes.\r
1155\r
1156 @retval TRUE HMAC-SHA256 data digest succeeded.\r
1157 @retval FALSE HMAC-SHA256 data digest failed.\r
1158 @retval FALSE This interface is not supported.\r
1159\r
1160**/\r
1161BOOLEAN\r
1162EFIAPI\r
1163HmacSha256Update (\r
1164 IN OUT VOID *HmacSha256Context,\r
1165 IN CONST VOID *Data,\r
1166 IN UINTN DataSize\r
1167 )\r
1168{\r
1169 CALL_CRYPTO_SERVICE (HmacSha256Update, (HmacSha256Context, Data, DataSize), FALSE);\r
1170}\r
1171\r
1172/**\r
1173 Completes computation of the HMAC-SHA256 digest value.\r
1174\r
1175 This function completes HMAC-SHA256 hash computation and retrieves the digest value into\r
1176 the specified memory. After this function has been called, the HMAC-SHA256 context cannot\r
1177 be used again.\r
1178 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1179 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.\r
1180\r
1181 If HmacSha256Context is NULL, then return FALSE.\r
1182 If HmacValue is NULL, then return FALSE.\r
1183 If this interface is not supported, then return FALSE.\r
1184\r
1185 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
1186 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
1187 value (32 bytes).\r
1188\r
1189 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1190 @retval FALSE HMAC-SHA256 digest computation failed.\r
1191 @retval FALSE This interface is not supported.\r
1192\r
1193**/\r
1194BOOLEAN\r
1195EFIAPI\r
1196HmacSha256Final (\r
1197 IN OUT VOID *HmacSha256Context,\r
1198 OUT UINT8 *HmacValue\r
1199 )\r
1200{\r
1201 CALL_CRYPTO_SERVICE (HmacSha256Final, (HmacSha256Context, HmacValue), FALSE);\r
1202}\r
1203\r
3f77ccb9
QZ
1204/**\r
1205 Computes the HMAC-SHA256 digest of a input data buffer.\r
1206\r
1207 This function performs the HMAC-SHA256 digest of a given data buffer, and places\r
1208 the digest value into the specified memory.\r
1209\r
1210 If this interface is not supported, then return FALSE.\r
1211\r
1212 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1213 @param[in] DataSize Size of Data buffer in bytes.\r
1214 @param[in] Key Pointer to the user-supplied key.\r
1215 @param[in] KeySize Key size in bytes.\r
1216 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
1217 value (32 bytes).\r
1218\r
1219 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1220 @retval FALSE HMAC-SHA256 digest computation failed.\r
1221 @retval FALSE This interface is not supported.\r
1222\r
1223**/\r
1224BOOLEAN\r
1225EFIAPI\r
1226HmacSha256All (\r
1227 IN CONST VOID *Data,\r
1228 IN UINTN DataSize,\r
1229 IN CONST UINT8 *Key,\r
1230 IN UINTN KeySize,\r
1231 OUT UINT8 *HmacValue\r
1232 )\r
1233{\r
1234 CALL_CRYPTO_SERVICE (HmacSha256All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);\r
1235}\r
1236\r
1237/**\r
1238 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.\r
1239\r
1240 @return Pointer to the HMAC_CTX context that has been initialized.\r
1241 If the allocations fails, HmacSha384New() returns NULL.\r
1242\r
1243**/\r
1244VOID *\r
1245EFIAPI\r
1246HmacSha384New (\r
1247 VOID\r
1248 )\r
1249{\r
1250 CALL_CRYPTO_SERVICE (HmacSha384New, (), NULL);\r
1251}\r
1252\r
1253/**\r
1254 Release the specified HMAC_CTX context.\r
1255\r
1256 @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be released.\r
1257\r
1258**/\r
1259VOID\r
1260EFIAPI\r
1261HmacSha384Free (\r
1262 IN VOID *HmacSha384Ctx\r
1263 )\r
1264{\r
1265 CALL_VOID_CRYPTO_SERVICE (HmacSha384Free, (HmacSha384Ctx));\r
1266}\r
1267\r
1268/**\r
1269 Set user-supplied key for subsequent use. It must be done before any\r
1270 calling to HmacSha384Update().\r
1271\r
1272 If HmacSha384Context is NULL, then return FALSE.\r
1273 If this interface is not supported, then return FALSE.\r
1274\r
1275 @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.\r
1276 @param[in] Key Pointer to the user-supplied key.\r
1277 @param[in] KeySize Key size in bytes.\r
1278\r
1279 @retval TRUE The Key is set successfully.\r
1280 @retval FALSE The Key is set unsuccessfully.\r
1281 @retval FALSE This interface is not supported.\r
1282\r
1283**/\r
1284BOOLEAN\r
1285EFIAPI\r
1286HmacSha384SetKey (\r
1287 OUT VOID *HmacSha384Context,\r
1288 IN CONST UINT8 *Key,\r
1289 IN UINTN KeySize\r
1290 )\r
1291{\r
1292 CALL_CRYPTO_SERVICE (HmacSha384SetKey, (HmacSha384Context, Key, KeySize), FALSE);\r
1293}\r
1294\r
1295/**\r
1296 Makes a copy of an existing HMAC-SHA384 context.\r
1297\r
1298 If HmacSha384Context is NULL, then return FALSE.\r
1299 If NewHmacSha384Context is NULL, then return FALSE.\r
1300 If this interface is not supported, then return FALSE.\r
1301\r
1302 @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being copied.\r
1303 @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.\r
1304\r
1305 @retval TRUE HMAC-SHA384 context copy succeeded.\r
1306 @retval FALSE HMAC-SHA384 context copy failed.\r
1307 @retval FALSE This interface is not supported.\r
1308\r
1309**/\r
1310BOOLEAN\r
1311EFIAPI\r
1312HmacSha384Duplicate (\r
1313 IN CONST VOID *HmacSha384Context,\r
1314 OUT VOID *NewHmacSha384Context\r
1315 )\r
1316{\r
1317 CALL_CRYPTO_SERVICE (HmacSha384Duplicate, (HmacSha384Context, NewHmacSha384Context), FALSE);\r
1318}\r
1319\r
1320/**\r
1321 Digests the input data and updates HMAC-SHA384 context.\r
1322\r
1323 This function performs HMAC-SHA384 digest on a data buffer of the specified size.\r
1324 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1325 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
1326 by HmacSha384Final(). Behavior with invalid context is undefined.\r
1327\r
1328 If HmacSha384Context is NULL, then return FALSE.\r
1329 If this interface is not supported, then return FALSE.\r
1330\r
1331 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.\r
1332 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1333 @param[in] DataSize Size of Data buffer in bytes.\r
1334\r
1335 @retval TRUE HMAC-SHA384 data digest succeeded.\r
1336 @retval FALSE HMAC-SHA384 data digest failed.\r
1337 @retval FALSE This interface is not supported.\r
1338\r
1339**/\r
1340BOOLEAN\r
1341EFIAPI\r
1342HmacSha384Update (\r
1343 IN OUT VOID *HmacSha384Context,\r
1344 IN CONST VOID *Data,\r
1345 IN UINTN DataSize\r
1346 )\r
1347{\r
1348 CALL_CRYPTO_SERVICE (HmacSha384Update, (HmacSha384Context, Data, DataSize), FALSE);\r
1349}\r
1350\r
1351/**\r
1352 Completes computation of the HMAC-SHA384 digest value.\r
1353\r
1354 This function completes HMAC-SHA384 hash computation and retrieves the digest value into\r
1355 the specified memory. After this function has been called, the HMAC-SHA384 context cannot\r
1356 be used again.\r
1357 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
1358 by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.\r
1359\r
1360 If HmacSha384Context is NULL, then return FALSE.\r
1361 If HmacValue is NULL, then return FALSE.\r
1362 If this interface is not supported, then return FALSE.\r
1363\r
1364 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.\r
1365 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest\r
1366 value (48 bytes).\r
1367\r
1368 @retval TRUE HMAC-SHA384 digest computation succeeded.\r
1369 @retval FALSE HMAC-SHA384 digest computation failed.\r
1370 @retval FALSE This interface is not supported.\r
1371\r
1372**/\r
1373BOOLEAN\r
1374EFIAPI\r
1375HmacSha384Final (\r
1376 IN OUT VOID *HmacSha384Context,\r
1377 OUT UINT8 *HmacValue\r
1378 )\r
1379{\r
1380 CALL_CRYPTO_SERVICE (HmacSha384Final, (HmacSha384Context, HmacValue), FALSE);\r
1381}\r
1382\r
1383/**\r
1384 Computes the HMAC-SHA384 digest of a input data buffer.\r
1385\r
1386 This function performs the HMAC-SHA384 digest of a given data buffer, and places\r
1387 the digest value into the specified memory.\r
1388\r
1389 If this interface is not supported, then return FALSE.\r
1390\r
1391 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1392 @param[in] DataSize Size of Data buffer in bytes.\r
1393 @param[in] Key Pointer to the user-supplied key.\r
1394 @param[in] KeySize Key size in bytes.\r
1395 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest\r
1396 value (48 bytes).\r
1397\r
1398 @retval TRUE HMAC-SHA384 digest computation succeeded.\r
1399 @retval FALSE HMAC-SHA384 digest computation failed.\r
1400 @retval FALSE This interface is not supported.\r
1401\r
1402**/\r
1403BOOLEAN\r
1404EFIAPI\r
1405HmacSha384All (\r
1406 IN CONST VOID *Data,\r
1407 IN UINTN DataSize,\r
1408 IN CONST UINT8 *Key,\r
1409 IN UINTN KeySize,\r
1410 OUT UINT8 *HmacValue\r
1411 )\r
1412{\r
1413 CALL_CRYPTO_SERVICE (HmacSha384All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);\r
1414}\r
1415\r
7c342378 1416// =====================================================================================\r
cd70de1c 1417// Symmetric Cryptography Primitive\r
7c342378 1418// =====================================================================================\r
cd70de1c 1419\r
cd70de1c
MK
1420/**\r
1421 Retrieves the size, in bytes, of the context buffer required for AES operations.\r
1422\r
1423 If this interface is not supported, then return zero.\r
1424\r
1425 @return The size, in bytes, of the context buffer required for AES operations.\r
1426 @retval 0 This interface is not supported.\r
1427\r
1428**/\r
1429UINTN\r
1430EFIAPI\r
1431AesGetContextSize (\r
1432 VOID\r
1433 )\r
1434{\r
1435 CALL_CRYPTO_SERVICE (AesGetContextSize, (), 0);\r
1436}\r
1437\r
1438/**\r
1439 Initializes user-supplied memory as AES context for subsequent use.\r
1440\r
1441 This function initializes user-supplied memory pointed by AesContext as AES context.\r
1442 In addition, it sets up all AES key materials for subsequent encryption and decryption\r
1443 operations.\r
1444 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r
1445\r
1446 If AesContext is NULL, then return FALSE.\r
1447 If Key is NULL, then return FALSE.\r
1448 If KeyLength is not valid, then return FALSE.\r
1449 If this interface is not supported, then return FALSE.\r
1450\r
1451 @param[out] AesContext Pointer to AES context being initialized.\r
1452 @param[in] Key Pointer to the user-supplied AES key.\r
1453 @param[in] KeyLength Length of AES key in bits.\r
1454\r
1455 @retval TRUE AES context initialization succeeded.\r
1456 @retval FALSE AES context initialization failed.\r
1457 @retval FALSE This interface is not supported.\r
1458\r
1459**/\r
1460BOOLEAN\r
1461EFIAPI\r
1462AesInit (\r
1463 OUT VOID *AesContext,\r
1464 IN CONST UINT8 *Key,\r
1465 IN UINTN KeyLength\r
1466 )\r
1467{\r
1468 CALL_CRYPTO_SERVICE (AesInit, (AesContext, Key, KeyLength), FALSE);\r
1469}\r
1470\r
cd70de1c
MK
1471/**\r
1472 Performs AES encryption on a data buffer of the specified size in CBC mode.\r
1473\r
1474 This function performs AES encryption on data buffer pointed by Input, of specified\r
1475 size of InputSize, in CBC mode.\r
1476 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1477 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1478 Initialization vector should be one block size (16 bytes).\r
1479 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1480 invalid AES context is undefined.\r
1481\r
1482 If AesContext is NULL, then return FALSE.\r
1483 If Input is NULL, then return FALSE.\r
1484 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1485 If Ivec is NULL, then return FALSE.\r
1486 If Output is NULL, then return FALSE.\r
1487 If this interface is not supported, then return FALSE.\r
1488\r
1489 @param[in] AesContext Pointer to the AES context.\r
1490 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1491 @param[in] InputSize Size of the Input buffer in bytes.\r
1492 @param[in] Ivec Pointer to initialization vector.\r
1493 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1494\r
1495 @retval TRUE AES encryption succeeded.\r
1496 @retval FALSE AES encryption failed.\r
1497 @retval FALSE This interface is not supported.\r
1498\r
1499**/\r
1500BOOLEAN\r
1501EFIAPI\r
1502AesCbcEncrypt (\r
1503 IN VOID *AesContext,\r
1504 IN CONST UINT8 *Input,\r
1505 IN UINTN InputSize,\r
1506 IN CONST UINT8 *Ivec,\r
1507 OUT UINT8 *Output\r
1508 )\r
1509{\r
1510 CALL_CRYPTO_SERVICE (AesCbcEncrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);\r
1511}\r
1512\r
1513/**\r
1514 Performs AES decryption on a data buffer of the specified size in CBC mode.\r
1515\r
1516 This function performs AES decryption on data buffer pointed by Input, of specified\r
1517 size of InputSize, in CBC mode.\r
1518 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1519 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1520 Initialization vector should be one block size (16 bytes).\r
1521 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1522 invalid AES context is undefined.\r
1523\r
1524 If AesContext is NULL, then return FALSE.\r
1525 If Input is NULL, then return FALSE.\r
1526 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1527 If Ivec is NULL, then return FALSE.\r
1528 If Output is NULL, then return FALSE.\r
1529 If this interface is not supported, then return FALSE.\r
1530\r
1531 @param[in] AesContext Pointer to the AES context.\r
1532 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1533 @param[in] InputSize Size of the Input buffer in bytes.\r
1534 @param[in] Ivec Pointer to initialization vector.\r
1535 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1536\r
1537 @retval TRUE AES decryption succeeded.\r
1538 @retval FALSE AES decryption failed.\r
1539 @retval FALSE This interface is not supported.\r
1540\r
1541**/\r
1542BOOLEAN\r
1543EFIAPI\r
1544AesCbcDecrypt (\r
1545 IN VOID *AesContext,\r
1546 IN CONST UINT8 *Input,\r
1547 IN UINTN InputSize,\r
1548 IN CONST UINT8 *Ivec,\r
1549 OUT UINT8 *Output\r
1550 )\r
1551{\r
1552 CALL_CRYPTO_SERVICE (AesCbcDecrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);\r
1553}\r
1554\r
022787f8
QZ
1555// =====================================================================================\r
1556// Authenticated Encryption with Associated Data (AEAD) Cryptography Primitive\r
1557// =====================================================================================\r
1558\r
1559/**\r
1560 Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).\r
1561\r
1562 IvSize must be 12, otherwise FALSE is returned.\r
1563 KeySize must be 16, 24 or 32, otherwise FALSE is returned.\r
1564 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.\r
1565\r
1566 @param[in] Key Pointer to the encryption key.\r
1567 @param[in] KeySize Size of the encryption key in bytes.\r
1568 @param[in] Iv Pointer to the IV value.\r
1569 @param[in] IvSize Size of the IV value in bytes.\r
1570 @param[in] AData Pointer to the additional authenticated data (AAD).\r
1571 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.\r
1572 @param[in] DataIn Pointer to the input data buffer to be encrypted.\r
1573 @param[in] DataInSize Size of the input data buffer in bytes.\r
1574 @param[out] TagOut Pointer to a buffer that receives the authentication tag output.\r
1575 @param[in] TagSize Size of the authentication tag in bytes.\r
1576 @param[out] DataOut Pointer to a buffer that receives the encryption output.\r
1577 @param[out] DataOutSize Size of the output data buffer in bytes.\r
1578\r
1579 @retval TRUE AEAD AES-GCM authenticated encryption succeeded.\r
1580 @retval FALSE AEAD AES-GCM authenticated encryption failed.\r
1581\r
1582**/\r
1583BOOLEAN\r
1584EFIAPI\r
1585AeadAesGcmEncrypt (\r
1586 IN CONST UINT8 *Key,\r
1587 IN UINTN KeySize,\r
1588 IN CONST UINT8 *Iv,\r
1589 IN UINTN IvSize,\r
1590 IN CONST UINT8 *AData,\r
1591 IN UINTN ADataSize,\r
1592 IN CONST UINT8 *DataIn,\r
1593 IN UINTN DataInSize,\r
1594 OUT UINT8 *TagOut,\r
1595 IN UINTN TagSize,\r
1596 OUT UINT8 *DataOut,\r
1597 OUT UINTN *DataOutSize\r
1598 )\r
1599{\r
1600 CALL_CRYPTO_SERVICE (AeadAesGcmEncrypt, (Key, KeySize, Iv, IvSize, AData, ADataSize, DataIn, DataInSize, TagOut, TagSize, DataOut, DataOutSize), FALSE);\r
1601}\r
1602\r
1603/**\r
1604 Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).\r
1605\r
1606 IvSize must be 12, otherwise FALSE is returned.\r
1607 KeySize must be 16, 24 or 32, otherwise FALSE is returned.\r
1608 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.\r
1609 If additional authenticated data verification fails, FALSE is returned.\r
1610\r
1611 @param[in] Key Pointer to the encryption key.\r
1612 @param[in] KeySize Size of the encryption key in bytes.\r
1613 @param[in] Iv Pointer to the IV value.\r
1614 @param[in] IvSize Size of the IV value in bytes.\r
1615 @param[in] AData Pointer to the additional authenticated data (AAD).\r
1616 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.\r
1617 @param[in] DataIn Pointer to the input data buffer to be decrypted.\r
1618 @param[in] DataInSize Size of the input data buffer in bytes.\r
1619 @param[in] Tag Pointer to a buffer that contains the authentication tag.\r
1620 @param[in] TagSize Size of the authentication tag in bytes.\r
1621 @param[out] DataOut Pointer to a buffer that receives the decryption output.\r
1622 @param[out] DataOutSize Size of the output data buffer in bytes.\r
1623\r
1624 @retval TRUE AEAD AES-GCM authenticated decryption succeeded.\r
1625 @retval FALSE AEAD AES-GCM authenticated decryption failed.\r
1626\r
1627**/\r
1628BOOLEAN\r
1629EFIAPI\r
1630AeadAesGcmDecrypt (\r
1631 IN CONST UINT8 *Key,\r
1632 IN UINTN KeySize,\r
1633 IN CONST UINT8 *Iv,\r
1634 IN UINTN IvSize,\r
1635 IN CONST UINT8 *AData,\r
1636 IN UINTN ADataSize,\r
1637 IN CONST UINT8 *DataIn,\r
1638 IN UINTN DataInSize,\r
1639 IN CONST UINT8 *Tag,\r
1640 IN UINTN TagSize,\r
1641 OUT UINT8 *DataOut,\r
1642 OUT UINTN *DataOutSize\r
1643 )\r
1644{\r
1645 CALL_CRYPTO_SERVICE (AeadAesGcmDecrypt, (Key, KeySize, Iv, IvSize, AData, ADataSize, DataIn, DataInSize, Tag, TagSize, DataOut, DataOutSize), FALSE);\r
1646}\r
1647\r
7c342378 1648// =====================================================================================\r
cd70de1c 1649// Asymmetric Cryptography Primitive\r
7c342378 1650// =====================================================================================\r
cd70de1c
MK
1651\r
1652/**\r
1653 Allocates and initializes one RSA context for subsequent use.\r
1654\r
1655 @return Pointer to the RSA context that has been initialized.\r
1656 If the allocations fails, RsaNew() returns NULL.\r
1657\r
1658**/\r
1659VOID *\r
1660EFIAPI\r
1661RsaNew (\r
1662 VOID\r
1663 )\r
1664{\r
1665 CALL_CRYPTO_SERVICE (RsaNew, (), NULL);\r
1666}\r
1667\r
1668/**\r
1669 Release the specified RSA context.\r
1670\r
1671 If RsaContext is NULL, then return FALSE.\r
1672\r
1673 @param[in] RsaContext Pointer to the RSA context to be released.\r
1674\r
1675**/\r
1676VOID\r
1677EFIAPI\r
1678RsaFree (\r
1679 IN VOID *RsaContext\r
1680 )\r
1681{\r
1682 CALL_VOID_CRYPTO_SERVICE (RsaFree, (RsaContext));\r
1683}\r
1684\r
1685/**\r
1686 Sets the tag-designated key component into the established RSA context.\r
1687\r
1688 This function sets the tag-designated RSA key component into the established\r
1689 RSA context from the user-specified non-negative integer (octet string format\r
1690 represented in RSA PKCS#1).\r
1691 If BigNumber is NULL, then the specified key component in RSA context is cleared.\r
1692\r
1693 If RsaContext is NULL, then return FALSE.\r
1694\r
1695 @param[in, out] RsaContext Pointer to RSA context being set.\r
1696 @param[in] KeyTag Tag of RSA key component being set.\r
1697 @param[in] BigNumber Pointer to octet integer buffer.\r
1698 If NULL, then the specified key component in RSA\r
1699 context is cleared.\r
1700 @param[in] BnSize Size of big number buffer in bytes.\r
1701 If BigNumber is NULL, then it is ignored.\r
1702\r
1703 @retval TRUE RSA key component was set successfully.\r
1704 @retval FALSE Invalid RSA key component tag.\r
1705\r
1706**/\r
1707BOOLEAN\r
1708EFIAPI\r
1709RsaSetKey (\r
1710 IN OUT VOID *RsaContext,\r
1711 IN RSA_KEY_TAG KeyTag,\r
1712 IN CONST UINT8 *BigNumber,\r
1713 IN UINTN BnSize\r
1714 )\r
1715{\r
1716 CALL_CRYPTO_SERVICE (RsaSetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);\r
1717}\r
1718\r
1719/**\r
1720 Gets the tag-designated RSA key component from the established RSA context.\r
1721\r
1722 This function retrieves the tag-designated RSA key component from the\r
1723 established RSA context as a non-negative integer (octet string format\r
1724 represented in RSA PKCS#1).\r
1725 If specified key component has not been set or has been cleared, then returned\r
1726 BnSize is set to 0.\r
1727 If the BigNumber buffer is too small to hold the contents of the key, FALSE\r
1728 is returned and BnSize is set to the required buffer size to obtain the key.\r
1729\r
1730 If RsaContext is NULL, then return FALSE.\r
1731 If BnSize is NULL, then return FALSE.\r
1732 If BnSize is large enough but BigNumber is NULL, then return FALSE.\r
1733 If this interface is not supported, then return FALSE.\r
1734\r
1735 @param[in, out] RsaContext Pointer to RSA context being set.\r
1736 @param[in] KeyTag Tag of RSA key component being set.\r
1737 @param[out] BigNumber Pointer to octet integer buffer.\r
1738 @param[in, out] BnSize On input, the size of big number buffer in bytes.\r
1739 On output, the size of data returned in big number buffer in bytes.\r
1740\r
1741 @retval TRUE RSA key component was retrieved successfully.\r
1742 @retval FALSE Invalid RSA key component tag.\r
1743 @retval FALSE BnSize is too small.\r
1744 @retval FALSE This interface is not supported.\r
1745\r
1746**/\r
1747BOOLEAN\r
1748EFIAPI\r
1749RsaGetKey (\r
1750 IN OUT VOID *RsaContext,\r
1751 IN RSA_KEY_TAG KeyTag,\r
1752 OUT UINT8 *BigNumber,\r
1753 IN OUT UINTN *BnSize\r
1754 )\r
1755{\r
1756 CALL_CRYPTO_SERVICE (RsaGetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);\r
1757}\r
1758\r
1759/**\r
1760 Generates RSA key components.\r
1761\r
1762 This function generates RSA key components. It takes RSA public exponent E and\r
1763 length in bits of RSA modulus N as input, and generates all key components.\r
1764 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r
1765\r
1766 Before this function can be invoked, pseudorandom number generator must be correctly\r
1767 initialized by RandomSeed().\r
1768\r
1769 If RsaContext is NULL, then return FALSE.\r
1770 If this interface is not supported, then return FALSE.\r
1771\r
1772 @param[in, out] RsaContext Pointer to RSA context being set.\r
1773 @param[in] ModulusLength Length of RSA modulus N in bits.\r
1774 @param[in] PublicExponent Pointer to RSA public exponent.\r
1775 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r
1776\r
1777 @retval TRUE RSA key component was generated successfully.\r
1778 @retval FALSE Invalid RSA key component tag.\r
1779 @retval FALSE This interface is not supported.\r
1780\r
1781**/\r
1782BOOLEAN\r
1783EFIAPI\r
1784RsaGenerateKey (\r
1785 IN OUT VOID *RsaContext,\r
1786 IN UINTN ModulusLength,\r
1787 IN CONST UINT8 *PublicExponent,\r
1788 IN UINTN PublicExponentSize\r
1789 )\r
1790{\r
1791 CALL_CRYPTO_SERVICE (RsaGenerateKey, (RsaContext, ModulusLength, PublicExponent, PublicExponentSize), FALSE);\r
1792}\r
1793\r
1794/**\r
1795 Validates key components of RSA context.\r
1796 NOTE: This function performs integrity checks on all the RSA key material, so\r
1797 the RSA key structure must contain all the private key data.\r
1798\r
1799 This function validates key components of RSA context in following aspects:\r
1800 - Whether p is a prime\r
1801 - Whether q is a prime\r
1802 - Whether n = p * q\r
1803 - Whether d*e = 1 mod lcm(p-1,q-1)\r
1804\r
1805 If RsaContext is NULL, then return FALSE.\r
1806 If this interface is not supported, then return FALSE.\r
1807\r
1808 @param[in] RsaContext Pointer to RSA context to check.\r
1809\r
1810 @retval TRUE RSA key components are valid.\r
1811 @retval FALSE RSA key components are not valid.\r
1812 @retval FALSE This interface is not supported.\r
1813\r
1814**/\r
1815BOOLEAN\r
1816EFIAPI\r
1817RsaCheckKey (\r
1818 IN VOID *RsaContext\r
1819 )\r
1820{\r
1821 CALL_CRYPTO_SERVICE (RsaCheckKey, (RsaContext), FALSE);\r
1822}\r
1823\r
1824/**\r
1825 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r
1826\r
1827 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1828 RSA PKCS#1.\r
1829 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1830 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1831\r
1832 If RsaContext is NULL, then return FALSE.\r
1833 If MessageHash is NULL, then return FALSE.\r
1834 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r
1835 If SigSize is large enough but Signature is NULL, then return FALSE.\r
1836 If this interface is not supported, then return FALSE.\r
1837\r
1838 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1839 @param[in] MessageHash Pointer to octet message hash to be signed.\r
1840 @param[in] HashSize Size of the message hash in bytes.\r
1841 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
1842 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
1843 On output, the size of data returned in Signature buffer in bytes.\r
1844\r
1845 @retval TRUE Signature successfully generated in PKCS1-v1_5.\r
1846 @retval FALSE Signature generation failed.\r
1847 @retval FALSE SigSize is too small.\r
1848 @retval FALSE This interface is not supported.\r
1849\r
1850**/\r
1851BOOLEAN\r
1852EFIAPI\r
1853RsaPkcs1Sign (\r
1854 IN VOID *RsaContext,\r
1855 IN CONST UINT8 *MessageHash,\r
1856 IN UINTN HashSize,\r
1857 OUT UINT8 *Signature,\r
1858 IN OUT UINTN *SigSize\r
1859 )\r
1860{\r
1861 CALL_CRYPTO_SERVICE (RsaPkcs1Sign, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);\r
1862}\r
1863\r
1864/**\r
1865 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1866 RSA PKCS#1.\r
1867\r
1868 If RsaContext is NULL, then return FALSE.\r
1869 If MessageHash is NULL, then return FALSE.\r
1870 If Signature is NULL, then return FALSE.\r
1871 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r
1872\r
1873 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1874 @param[in] MessageHash Pointer to octet message hash to be checked.\r
1875 @param[in] HashSize Size of the message hash in bytes.\r
1876 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r
1877 @param[in] SigSize Size of signature in bytes.\r
1878\r
1879 @retval TRUE Valid signature encoded in PKCS1-v1_5.\r
1880 @retval FALSE Invalid signature or invalid RSA context.\r
1881\r
1882**/\r
1883BOOLEAN\r
1884EFIAPI\r
1885RsaPkcs1Verify (\r
1886 IN VOID *RsaContext,\r
1887 IN CONST UINT8 *MessageHash,\r
1888 IN UINTN HashSize,\r
1889 IN CONST UINT8 *Signature,\r
1890 IN UINTN SigSize\r
1891 )\r
1892{\r
1893 CALL_CRYPTO_SERVICE (RsaPkcs1Verify, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);\r
1894}\r
1895\r
22ac5cc9
SA
1896/**\r
1897 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.\r
1898 Implementation determines salt length automatically from the signature encoding.\r
1899 Mask generation function is the same as the message digest algorithm.\r
20ca5288 1900 Salt length should be equal to digest length.\r
22ac5cc9
SA
1901\r
1902 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1903 @param[in] Message Pointer to octet message to be verified.\r
1904 @param[in] MsgSize Size of the message in bytes.\r
1905 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.\r
1906 @param[in] SigSize Size of signature in bytes.\r
1907 @param[in] DigestLen Length of digest for RSA operation.\r
1908 @param[in] SaltLen Salt length for PSS encoding.\r
1909\r
1910 @retval TRUE Valid signature encoded in RSASSA-PSS.\r
1911 @retval FALSE Invalid signature or invalid RSA context.\r
1912\r
1913**/\r
1914BOOLEAN\r
1915EFIAPI\r
1916RsaPssVerify (\r
1917 IN VOID *RsaContext,\r
1918 IN CONST UINT8 *Message,\r
1919 IN UINTN MsgSize,\r
1920 IN CONST UINT8 *Signature,\r
1921 IN UINTN SigSize,\r
1922 IN UINT16 DigestLen,\r
1923 IN UINT16 SaltLen\r
1924 )\r
1925{\r
1926 CALL_CRYPTO_SERVICE (RsaPssVerify, (RsaContext, Message, MsgSize, Signature, SigSize, DigestLen, SaltLen), FALSE);\r
1927}\r
1928\r
1929/**\r
1930 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in\r
1931 RFC 8017.\r
1932 Mask generation function is the same as the message digest algorithm.\r
1933 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1934 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1935\r
20ca5288
AS
1936 If RsaContext is NULL, then return FALSE.\r
1937 If Message is NULL, then return FALSE.\r
1938 If MsgSize is zero or > INT_MAX, then return FALSE.\r
1939 If DigestLen is NOT 32, 48 or 64, return FALSE.\r
1940 If SaltLen is not equal to DigestLen, then return FALSE.\r
1941 If SigSize is large enough but Signature is NULL, then return FALSE.\r
1942 If this interface is not supported, then return FALSE.\r
1943\r
22ac5cc9
SA
1944 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1945 @param[in] Message Pointer to octet message to be signed.\r
1946 @param[in] MsgSize Size of the message in bytes.\r
1947 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.\r
1948 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.\r
1949 @param[out] Signature Pointer to buffer to receive RSA PSS signature.\r
1950 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
1951 On output, the size of data returned in Signature buffer in bytes.\r
1952\r
1953 @retval TRUE Signature successfully generated in RSASSA-PSS.\r
1954 @retval FALSE Signature generation failed.\r
1955 @retval FALSE SigSize is too small.\r
1956 @retval FALSE This interface is not supported.\r
1957\r
1958**/\r
1959BOOLEAN\r
1960EFIAPI\r
1961RsaPssSign (\r
1962 IN VOID *RsaContext,\r
1963 IN CONST UINT8 *Message,\r
1964 IN UINTN MsgSize,\r
1965 IN UINT16 DigestLen,\r
1966 IN UINT16 SaltLen,\r
1967 OUT UINT8 *Signature,\r
1968 IN OUT UINTN *SigSize\r
1969 )\r
1970{\r
1971 CALL_CRYPTO_SERVICE (RsaPssSign, (RsaContext, Message, MsgSize, DigestLen, SaltLen, Signature, SigSize), FALSE);\r
1972}\r
1973\r
cd70de1c
MK
1974/**\r
1975 Retrieve the RSA Private Key from the password-protected PEM key data.\r
1976\r
1977 If PemData is NULL, then return FALSE.\r
1978 If RsaContext is NULL, then return FALSE.\r
1979 If this interface is not supported, then return FALSE.\r
1980\r
1981 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
1982 @param[in] PemSize Size of the PEM key data in bytes.\r
1983 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
1984 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1985 RSA private key component. Use RsaFree() function to free the\r
1986 resource.\r
1987\r
1988 @retval TRUE RSA Private Key was retrieved successfully.\r
1989 @retval FALSE Invalid PEM key data or incorrect password.\r
1990 @retval FALSE This interface is not supported.\r
1991\r
1992**/\r
1993BOOLEAN\r
1994EFIAPI\r
1995RsaGetPrivateKeyFromPem (\r
1996 IN CONST UINT8 *PemData,\r
1997 IN UINTN PemSize,\r
1998 IN CONST CHAR8 *Password,\r
1999 OUT VOID **RsaContext\r
2000 )\r
2001{\r
2002 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem, (PemData, PemSize, Password, RsaContext), FALSE);\r
2003}\r
2004\r
2005/**\r
2006 Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r
2007\r
2008 If Cert is NULL, then return FALSE.\r
2009 If RsaContext is NULL, then return FALSE.\r
2010 If this interface is not supported, then return FALSE.\r
2011\r
2012 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2013 @param[in] CertSize Size of the X509 certificate in bytes.\r
2014 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
2015 RSA public key component. Use RsaFree() function to free the\r
2016 resource.\r
2017\r
2018 @retval TRUE RSA Public Key was retrieved successfully.\r
2019 @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r
2020 @retval FALSE This interface is not supported.\r
2021\r
2022**/\r
2023BOOLEAN\r
2024EFIAPI\r
2025RsaGetPublicKeyFromX509 (\r
2026 IN CONST UINT8 *Cert,\r
2027 IN UINTN CertSize,\r
2028 OUT VOID **RsaContext\r
2029 )\r
2030{\r
2031 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509, (Cert, CertSize, RsaContext), FALSE);\r
2032}\r
2033\r
2034/**\r
2035 Retrieve the subject bytes from one X.509 certificate.\r
2036\r
2037 If Cert is NULL, then return FALSE.\r
2038 If SubjectSize is NULL, then return FALSE.\r
2039 If this interface is not supported, then return FALSE.\r
2040\r
2041 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2042 @param[in] CertSize Size of the X509 certificate in bytes.\r
2043 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r
2044 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r
2045 and the size of buffer returned CertSubject on output.\r
2046\r
2047 @retval TRUE The certificate subject retrieved successfully.\r
2048 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r
2049 The SubjectSize will be updated with the required size.\r
2050 @retval FALSE This interface is not supported.\r
2051\r
2052**/\r
2053BOOLEAN\r
2054EFIAPI\r
2055X509GetSubjectName (\r
2056 IN CONST UINT8 *Cert,\r
2057 IN UINTN CertSize,\r
2058 OUT UINT8 *CertSubject,\r
2059 IN OUT UINTN *SubjectSize\r
2060 )\r
2061{\r
2062 CALL_CRYPTO_SERVICE (X509GetSubjectName, (Cert, CertSize, CertSubject, SubjectSize), FALSE);\r
2063}\r
2064\r
2065/**\r
2066 Retrieve the common name (CN) string from one X.509 certificate.\r
2067\r
2068 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2069 @param[in] CertSize Size of the X509 certificate in bytes.\r
2070 @param[out] CommonName Buffer to contain the retrieved certificate common\r
2071 name string (UTF8). At most CommonNameSize bytes will be\r
2072 written and the string will be null terminated. May be\r
2073 NULL in order to determine the size buffer needed.\r
2074 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
2075 and the size of buffer returned CommonName on output.\r
2076 If CommonName is NULL then the amount of space needed\r
2077 in buffer (including the final null) is returned.\r
2078\r
2079 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r
2080 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
2081 If CommonNameSize is NULL.\r
2082 If CommonName is not NULL and *CommonNameSize is 0.\r
2083 If Certificate is invalid.\r
2084 @retval RETURN_NOT_FOUND If no CommonName entry exists.\r
2085 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r
2086 (including the final null) is returned in the\r
2087 CommonNameSize parameter.\r
2088 @retval RETURN_UNSUPPORTED The operation is not supported.\r
2089\r
2090**/\r
2091RETURN_STATUS\r
2092EFIAPI\r
2093X509GetCommonName (\r
2094 IN CONST UINT8 *Cert,\r
2095 IN UINTN CertSize,\r
c8f46130 2096 OUT CHAR8 *CommonName OPTIONAL,\r
cd70de1c
MK
2097 IN OUT UINTN *CommonNameSize\r
2098 )\r
2099{\r
2100 CALL_CRYPTO_SERVICE (X509GetCommonName, (Cert, CertSize, CommonName, CommonNameSize), RETURN_UNSUPPORTED);\r
2101}\r
2102\r
2103/**\r
2104 Retrieve the organization name (O) string from one X.509 certificate.\r
2105\r
2106 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2107 @param[in] CertSize Size of the X509 certificate in bytes.\r
2108 @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r
2109 name string. At most NameBufferSize bytes will be\r
2110 written and the string will be null terminated. May be\r
2111 NULL in order to determine the size buffer needed.\r
2112 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r
2113 and the size of buffer returned Name on output.\r
2114 If NameBuffer is NULL then the amount of space needed\r
2115 in buffer (including the final null) is returned.\r
2116\r
2117 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r
2118 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
2119 If NameBufferSize is NULL.\r
2120 If NameBuffer is not NULL and *CommonNameSize is 0.\r
2121 If Certificate is invalid.\r
2122 @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r
2123 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r
2124 (including the final null) is returned in the\r
2125 CommonNameSize parameter.\r
2126 @retval RETURN_UNSUPPORTED The operation is not supported.\r
2127\r
2128**/\r
2129RETURN_STATUS\r
2130EFIAPI\r
2131X509GetOrganizationName (\r
7c342378
MK
2132 IN CONST UINT8 *Cert,\r
2133 IN UINTN CertSize,\r
2134 OUT CHAR8 *NameBuffer OPTIONAL,\r
2135 IN OUT UINTN *NameBufferSize\r
cd70de1c
MK
2136 )\r
2137{\r
2138 CALL_CRYPTO_SERVICE (X509GetOrganizationName, (Cert, CertSize, NameBuffer, NameBufferSize), RETURN_UNSUPPORTED);\r
2139}\r
2140\r
2141/**\r
2142 Verify one X509 certificate was issued by the trusted CA.\r
2143\r
2144 If Cert is NULL, then return FALSE.\r
2145 If CACert is NULL, then return FALSE.\r
2146 If this interface is not supported, then return FALSE.\r
2147\r
2148 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r
2149 @param[in] CertSize Size of the X509 certificate in bytes.\r
2150 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r
2151 @param[in] CACertSize Size of the CA Certificate in bytes.\r
2152\r
2153 @retval TRUE The certificate was issued by the trusted CA.\r
2154 @retval FALSE Invalid certificate or the certificate was not issued by the given\r
2155 trusted CA.\r
2156 @retval FALSE This interface is not supported.\r
2157\r
2158**/\r
2159BOOLEAN\r
2160EFIAPI\r
2161X509VerifyCert (\r
2162 IN CONST UINT8 *Cert,\r
2163 IN UINTN CertSize,\r
2164 IN CONST UINT8 *CACert,\r
2165 IN UINTN CACertSize\r
2166 )\r
2167{\r
2168 CALL_CRYPTO_SERVICE (X509VerifyCert, (Cert, CertSize, CACert, CACertSize), FALSE);\r
2169}\r
2170\r
2171/**\r
2172 Construct a X509 object from DER-encoded certificate data.\r
2173\r
2174 If Cert is NULL, then return FALSE.\r
2175 If SingleX509Cert is NULL, then return FALSE.\r
2176 If this interface is not supported, then return FALSE.\r
2177\r
2178 @param[in] Cert Pointer to the DER-encoded certificate data.\r
2179 @param[in] CertSize The size of certificate data in bytes.\r
2180 @param[out] SingleX509Cert The generated X509 object.\r
2181\r
2182 @retval TRUE The X509 object generation succeeded.\r
2183 @retval FALSE The operation failed.\r
2184 @retval FALSE This interface is not supported.\r
2185\r
2186**/\r
2187BOOLEAN\r
2188EFIAPI\r
2189X509ConstructCertificate (\r
2190 IN CONST UINT8 *Cert,\r
2191 IN UINTN CertSize,\r
2192 OUT UINT8 **SingleX509Cert\r
2193 )\r
2194{\r
2195 CALL_CRYPTO_SERVICE (X509ConstructCertificate, (Cert, CertSize, SingleX509Cert), FALSE);\r
2196}\r
2197\r
2198/**\r
2199 Construct a X509 stack object from a list of DER-encoded certificate data.\r
2200\r
2201 If X509Stack is NULL, then return FALSE.\r
2202 If this interface is not supported, then return FALSE.\r
2203\r
2204 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
2205 On output, pointer to the X509 stack object with new\r
2206 inserted X509 certificate.\r
2207 @param[in] Args VA_LIST marker for the variable argument list.\r
2208 ... A list of DER-encoded single certificate data followed\r
2209 by certificate size. A NULL terminates the list. The\r
2210 pairs are the arguments to X509ConstructCertificate().\r
2211\r
2212 @retval TRUE The X509 stack construction succeeded.\r
2213 @retval FALSE The construction operation failed.\r
2214 @retval FALSE This interface is not supported.\r
2215\r
2216**/\r
2217BOOLEAN\r
2218EFIAPI\r
2219X509ConstructCertificateStack (\r
2220 IN OUT UINT8 **X509Stack,\r
2221 ...\r
2222 )\r
2223{\r
2224 VA_LIST Args;\r
2225 BOOLEAN Result;\r
2226\r
2227 VA_START (Args, X509Stack);\r
2228 Result = X509ConstructCertificateStackV (X509Stack, Args);\r
2229 VA_END (Args);\r
2230 return Result;\r
2231}\r
2232\r
2233/**\r
2234 Construct a X509 stack object from a list of DER-encoded certificate data.\r
2235\r
2236 If X509Stack is NULL, then return FALSE.\r
2237 If this interface is not supported, then return FALSE.\r
2238\r
2239 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
2240 On output, pointer to the X509 stack object with new\r
2241 inserted X509 certificate.\r
2242 @param[in] Args VA_LIST marker for the variable argument list.\r
2243 A list of DER-encoded single certificate data followed\r
2244 by certificate size. A NULL terminates the list. The\r
2245 pairs are the arguments to X509ConstructCertificate().\r
2246\r
2247 @retval TRUE The X509 stack construction succeeded.\r
2248 @retval FALSE The construction operation failed.\r
2249 @retval FALSE This interface is not supported.\r
2250\r
2251**/\r
2252BOOLEAN\r
2253EFIAPI\r
2254X509ConstructCertificateStackV (\r
2255 IN OUT UINT8 **X509Stack,\r
2256 IN VA_LIST Args\r
2257 )\r
2258{\r
2259 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV, (X509Stack, Args), FALSE);\r
2260}\r
2261\r
2262/**\r
2263 Release the specified X509 object.\r
2264\r
2265 If the interface is not supported, then ASSERT().\r
2266\r
2267 @param[in] X509Cert Pointer to the X509 object to be released.\r
2268\r
2269**/\r
2270VOID\r
2271EFIAPI\r
2272X509Free (\r
2273 IN VOID *X509Cert\r
2274 )\r
2275{\r
2276 CALL_VOID_CRYPTO_SERVICE (X509Free, (X509Cert));\r
2277}\r
2278\r
2279/**\r
2280 Release the specified X509 stack object.\r
2281\r
2282 If the interface is not supported, then ASSERT().\r
2283\r
2284 @param[in] X509Stack Pointer to the X509 stack object to be released.\r
2285\r
2286**/\r
2287VOID\r
2288EFIAPI\r
2289X509StackFree (\r
2290 IN VOID *X509Stack\r
2291 )\r
2292{\r
2293 CALL_VOID_CRYPTO_SERVICE (X509StackFree, (X509Stack));\r
2294}\r
2295\r
2296/**\r
2297 Retrieve the TBSCertificate from one given X.509 certificate.\r
2298\r
2299 @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r
2300 @param[in] CertSize Size of the X509 certificate in bytes.\r
2301 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r
2302 @param[out] TBSCertSize Size of the TBS certificate in bytes.\r
2303\r
2304 If Cert is NULL, then return FALSE.\r
2305 If TBSCert is NULL, then return FALSE.\r
2306 If TBSCertSize is NULL, then return FALSE.\r
2307 If this interface is not supported, then return FALSE.\r
2308\r
2309 @retval TRUE The TBSCertificate was retrieved successfully.\r
2310 @retval FALSE Invalid X.509 certificate.\r
2311\r
2312**/\r
2313BOOLEAN\r
2314EFIAPI\r
2315X509GetTBSCert (\r
2316 IN CONST UINT8 *Cert,\r
2317 IN UINTN CertSize,\r
2318 OUT UINT8 **TBSCert,\r
2319 OUT UINTN *TBSCertSize\r
2320 )\r
2321{\r
2322 CALL_CRYPTO_SERVICE (X509GetTBSCert, (Cert, CertSize, TBSCert, TBSCertSize), FALSE);\r
2323}\r
2324\r
22745df6
QZ
2325/**\r
2326 Retrieve the version from one X.509 certificate.\r
2327\r
2328 If Cert is NULL, then return FALSE.\r
2329 If CertSize is 0, then return FALSE.\r
2330 If this interface is not supported, then return FALSE.\r
2331\r
2332 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2333 @param[in] CertSize Size of the X509 certificate in bytes.\r
2334 @param[out] Version Pointer to the retrieved version integer.\r
2335\r
2336 @retval TRUE The certificate version retrieved successfully.\r
2337 @retval FALSE If Cert is NULL or CertSize is Zero.\r
2338 @retval FALSE The operation is not supported.\r
2339\r
2340**/\r
2341BOOLEAN\r
2342EFIAPI\r
2343X509GetVersion (\r
2344 IN CONST UINT8 *Cert,\r
2345 IN UINTN CertSize,\r
2346 OUT UINTN *Version\r
2347 )\r
2348{\r
2349 CALL_CRYPTO_SERVICE (X509GetVersion, (Cert, CertSize, Version), FALSE);\r
2350}\r
2351\r
2352/**\r
2353 Retrieve the serialNumber from one X.509 certificate.\r
2354\r
2355 If Cert is NULL, then return FALSE.\r
2356 If CertSize is 0, then return FALSE.\r
2357 If this interface is not supported, then return FALSE.\r
2358\r
2359 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2360 @param[in] CertSize Size of the X509 certificate in bytes.\r
2361 @param[out] SerialNumber Pointer to the retrieved certificate SerialNumber bytes.\r
2362 @param[in, out] SerialNumberSize The size in bytes of the SerialNumber buffer on input,\r
2363 and the size of buffer returned SerialNumber on output.\r
2364\r
2365 @retval TRUE The certificate serialNumber retrieved successfully.\r
2366 @retval FALSE If Cert is NULL or CertSize is Zero.\r
2367 If SerialNumberSize is NULL.\r
2368 If Certificate is invalid.\r
2369 @retval FALSE If no SerialNumber exists.\r
2370 @retval FALSE If the SerialNumber is NULL. The required buffer size\r
2371 (including the final null) is returned in the\r
2372 SerialNumberSize parameter.\r
2373 @retval FALSE The operation is not supported.\r
2374**/\r
2375BOOLEAN\r
2376EFIAPI\r
2377X509GetSerialNumber (\r
2378 IN CONST UINT8 *Cert,\r
2379 IN UINTN CertSize,\r
2380 OUT UINT8 *SerialNumber, OPTIONAL\r
2381 IN OUT UINTN *SerialNumberSize\r
2382 )\r
2383{\r
2384 CALL_CRYPTO_SERVICE (X509GetSerialNumber, (Cert, CertSize, SerialNumber, SerialNumberSize), FALSE);\r
2385}\r
2386\r
2387/**\r
2388 Retrieve the issuer bytes from one X.509 certificate.\r
2389\r
2390 If Cert is NULL, then return FALSE.\r
2391 If CertIssuerSize is NULL, then return FALSE.\r
2392 If this interface is not supported, then return FALSE.\r
2393\r
2394 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2395 @param[in] CertSize Size of the X509 certificate in bytes.\r
2396 @param[out] CertIssuer Pointer to the retrieved certificate subject bytes.\r
2397 @param[in, out] CertIssuerSize The size in bytes of the CertIssuer buffer on input,\r
2398 and the size of buffer returned CertSubject on output.\r
2399\r
2400 @retval TRUE The certificate issuer retrieved successfully.\r
2401 @retval FALSE Invalid certificate, or the CertIssuerSize is too small for the result.\r
2402 The CertIssuerSize will be updated with the required size.\r
2403 @retval FALSE This interface is not supported.\r
2404\r
2405**/\r
2406BOOLEAN\r
2407EFIAPI\r
2408X509GetIssuerName (\r
2409 IN CONST UINT8 *Cert,\r
2410 IN UINTN CertSize,\r
2411 OUT UINT8 *CertIssuer,\r
2412 IN OUT UINTN *CertIssuerSize\r
2413 )\r
2414{\r
2415 CALL_CRYPTO_SERVICE (X509GetIssuerName, (Cert, CertSize, CertIssuer, CertIssuerSize), FALSE);\r
2416}\r
2417\r
2418/**\r
2419 Retrieve the Signature Algorithm from one X.509 certificate.\r
2420\r
2421 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2422 @param[in] CertSize Size of the X509 certificate in bytes.\r
2423 @param[out] Oid Signature Algorithm Object identifier buffer.\r
2424 @param[in,out] OidSize Signature Algorithm Object identifier buffer size\r
2425\r
2426 @retval TRUE The certificate Extension data retrieved successfully.\r
2427 @retval FALSE If Cert is NULL.\r
2428 If OidSize is NULL.\r
2429 If Oid is not NULL and *OidSize is 0.\r
2430 If Certificate is invalid.\r
2431 @retval FALSE If no SignatureType.\r
2432 @retval FALSE If the Oid is NULL. The required buffer size\r
2433 is returned in the OidSize.\r
2434 @retval FALSE The operation is not supported.\r
2435**/\r
2436BOOLEAN\r
2437EFIAPI\r
2438X509GetSignatureAlgorithm (\r
2439 IN CONST UINT8 *Cert,\r
2440 IN UINTN CertSize,\r
2441 OUT UINT8 *Oid, OPTIONAL\r
2442 IN OUT UINTN *OidSize\r
2443 )\r
2444{\r
2445 CALL_CRYPTO_SERVICE (X509GetSignatureAlgorithm, (Cert, CertSize, Oid, OidSize), FALSE);\r
2446}\r
2447\r
2448/**\r
2449 Retrieve Extension data from one X.509 certificate.\r
2450\r
2451 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2452 @param[in] CertSize Size of the X509 certificate in bytes.\r
2453 @param[in] Oid Object identifier buffer\r
2454 @param[in] OidSize Object identifier buffer size\r
2455 @param[out] ExtensionData Extension bytes.\r
2456 @param[in, out] ExtensionDataSize Extension bytes size.\r
2457\r
2458 @retval TRUE The certificate Extension data retrieved successfully.\r
2459 @retval FALSE If Cert is NULL.\r
2460 If ExtensionDataSize is NULL.\r
2461 If ExtensionData is not NULL and *ExtensionDataSize is 0.\r
2462 If Certificate is invalid.\r
2463 @retval FALSE If no Extension entry match Oid.\r
2464 @retval FALSE If the ExtensionData is NULL. The required buffer size\r
2465 is returned in the ExtensionDataSize parameter.\r
2466 @retval FALSE The operation is not supported.\r
2467**/\r
2468BOOLEAN\r
2469EFIAPI\r
2470X509GetExtensionData (\r
2471 IN CONST UINT8 *Cert,\r
2472 IN UINTN CertSize,\r
2473 IN CONST UINT8 *Oid,\r
2474 IN UINTN OidSize,\r
2475 OUT UINT8 *ExtensionData,\r
2476 IN OUT UINTN *ExtensionDataSize\r
2477 )\r
2478{\r
2479 CALL_CRYPTO_SERVICE (X509GetExtensionData, (Cert, CertSize, Oid, OidSize, ExtensionData, ExtensionDataSize), FALSE);\r
2480}\r
2481\r
2482/**\r
2483 Retrieve the Extended Key Usage from one X.509 certificate.\r
2484\r
2485 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2486 @param[in] CertSize Size of the X509 certificate in bytes.\r
2487 @param[out] Usage Key Usage bytes.\r
2488 @param[in, out] UsageSize Key Usage buffer sizs in bytes.\r
2489\r
2490 @retval TRUE The Usage bytes retrieve successfully.\r
2491 @retval FALSE If Cert is NULL.\r
2492 If CertSize is NULL.\r
2493 If Usage is not NULL and *UsageSize is 0.\r
2494 If Cert is invalid.\r
2495 @retval FALSE If the Usage is NULL. The required buffer size\r
2496 is returned in the UsageSize parameter.\r
2497 @retval FALSE The operation is not supported.\r
2498**/\r
2499BOOLEAN\r
2500EFIAPI\r
2501X509GetExtendedKeyUsage (\r
2502 IN CONST UINT8 *Cert,\r
2503 IN UINTN CertSize,\r
2504 OUT UINT8 *Usage,\r
2505 IN OUT UINTN *UsageSize\r
2506 )\r
2507{\r
2508 CALL_CRYPTO_SERVICE (X509GetExtendedKeyUsage, (Cert, CertSize, Usage, UsageSize), FALSE);\r
2509}\r
2510\r
2511/**\r
2512 Retrieve the Validity from one X.509 certificate\r
2513\r
2514 If Cert is NULL, then return FALSE.\r
2515 If CertIssuerSize is NULL, then return FALSE.\r
2516 If this interface is not supported, then return FALSE.\r
2517\r
2518 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2519 @param[in] CertSize Size of the X509 certificate in bytes.\r
2520 @param[in] From notBefore Pointer to DateTime object.\r
2521 @param[in,out] FromSize notBefore DateTime object size.\r
2522 @param[in] To notAfter Pointer to DateTime object.\r
2523 @param[in,out] ToSize notAfter DateTime object size.\r
2524\r
2525 Note: X509CompareDateTime to compare DateTime oject\r
2526 x509SetDateTime to get a DateTime object from a DateTimeStr\r
2527\r
2528 @retval TRUE The certificate Validity retrieved successfully.\r
2529 @retval FALSE Invalid certificate, or Validity retrieve failed.\r
2530 @retval FALSE This interface is not supported.\r
2531**/\r
2532BOOLEAN\r
2533EFIAPI\r
2534X509GetValidity (\r
2535 IN CONST UINT8 *Cert,\r
2536 IN UINTN CertSize,\r
2537 IN UINT8 *From,\r
2538 IN OUT UINTN *FromSize,\r
2539 IN UINT8 *To,\r
2540 IN OUT UINTN *ToSize\r
2541 )\r
2542{\r
2543 CALL_CRYPTO_SERVICE (X509GetValidity, (Cert, CertSize, From, FromSize, To, ToSize), FALSE);\r
2544}\r
2545\r
2546/**\r
2547 Format a DateTimeStr to DataTime object in DataTime Buffer\r
2548\r
2549 If DateTimeStr is NULL, then return FALSE.\r
2550 If DateTimeSize is NULL, then return FALSE.\r
2551 If this interface is not supported, then return FALSE.\r
2552\r
2553 @param[in] DateTimeStr DateTime string like YYYYMMDDhhmmssZ\r
2554 Ref: https://www.w3.org/TR/NOTE-datetime\r
2555 Z stand for UTC time\r
2556 @param[out] DateTime Pointer to a DateTime object.\r
2557 @param[in,out] DateTimeSize DateTime object buffer size.\r
2558\r
2559 @retval TRUE The DateTime object create successfully.\r
2560 @retval FALSE If DateTimeStr is NULL.\r
2561 If DateTimeSize is NULL.\r
2562 If DateTime is not NULL and *DateTimeSize is 0.\r
2563 If Year Month Day Hour Minute Second combination is invalid datetime.\r
2564 @retval FALSE If the DateTime is NULL. The required buffer size\r
2565 (including the final null) is returned in the\r
2566 DateTimeSize parameter.\r
2567 @retval FALSE The operation is not supported.\r
2568**/\r
2569BOOLEAN\r
2570EFIAPI\r
2571X509FormatDateTime (\r
2572 IN CONST CHAR8 *DateTimeStr,\r
2573 OUT VOID *DateTime,\r
2574 IN OUT UINTN *DateTimeSize\r
2575 )\r
2576{\r
2577 CALL_CRYPTO_SERVICE (X509FormatDateTime, (DateTimeStr, DateTime, DateTimeSize), FALSE);\r
2578}\r
2579\r
2580/**\r
2581 Compare DateTime1 object and DateTime2 object.\r
2582\r
2583 If DateTime1 is NULL, then return -2.\r
2584 If DateTime2 is NULL, then return -2.\r
2585 If DateTime1 == DateTime2, then return 0\r
2586 If DateTime1 > DateTime2, then return 1\r
2587 If DateTime1 < DateTime2, then return -1\r
2588\r
2589 @param[in] DateTime1 Pointer to a DateTime Ojbect\r
2590 @param[in] DateTime2 Pointer to a DateTime Object\r
2591\r
2592 @retval 0 If DateTime1 == DateTime2\r
2593 @retval 1 If DateTime1 > DateTime2\r
2594 @retval -1 If DateTime1 < DateTime2\r
2595**/\r
2596INT32\r
2597EFIAPI\r
2598X509CompareDateTime (\r
2599 IN CONST VOID *DateTime1,\r
2600 IN CONST VOID *DateTime2\r
2601 )\r
2602{\r
2603 CALL_CRYPTO_SERVICE (X509CompareDateTime, (DateTime1, DateTime2), FALSE);\r
2604}\r
2605\r
2606/**\r
2607 Retrieve the Key Usage from one X.509 certificate.\r
2608\r
2609 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2610 @param[in] CertSize Size of the X509 certificate in bytes.\r
2611 @param[out] Usage Key Usage (CRYPTO_X509_KU_*)\r
2612\r
2613 @retval TRUE The certificate Key Usage retrieved successfully.\r
2614 @retval FALSE Invalid certificate, or Usage is NULL\r
2615 @retval FALSE This interface is not supported.\r
2616**/\r
2617BOOLEAN\r
2618EFIAPI\r
2619X509GetKeyUsage (\r
2620 IN CONST UINT8 *Cert,\r
2621 IN UINTN CertSize,\r
2622 OUT UINTN *Usage\r
2623 )\r
2624{\r
2625 CALL_CRYPTO_SERVICE (X509GetKeyUsage, (Cert, CertSize, Usage), FALSE);\r
2626}\r
2627\r
2628/**\r
2629 Verify one X509 certificate was issued by the trusted CA.\r
2630 @param[in] RootCert Trusted Root Certificate buffer\r
2631\r
2632 @param[in] RootCertLength Trusted Root Certificate buffer length\r
2633 @param[in] CertChain One or more ASN.1 DER-encoded X.509 certificates\r
2634 where the first certificate is signed by the Root\r
2635 Certificate or is the Root Cerificate itself. and\r
2636 subsequent cerificate is signed by the preceding\r
2637 cerificate.\r
2638 @param[in] CertChainLength Total length of the certificate chain, in bytes.\r
2639\r
2640 @retval TRUE All cerificates was issued by the first certificate in X509Certchain.\r
2641 @retval FALSE Invalid certificate or the certificate was not issued by the given\r
2642 trusted CA.\r
2643**/\r
2644BOOLEAN\r
2645EFIAPI\r
2646X509VerifyCertChain (\r
2647 IN CONST UINT8 *RootCert,\r
2648 IN UINTN RootCertLength,\r
2649 IN CONST UINT8 *CertChain,\r
2650 IN UINTN CertChainLength\r
2651 )\r
2652{\r
2653 CALL_CRYPTO_SERVICE (X509VerifyCertChain, (RootCert, RootCertLength, CertChain, CertChainLength), FALSE);\r
2654}\r
2655\r
2656/**\r
2657 Get one X509 certificate from CertChain.\r
2658\r
2659 @param[in] CertChain One or more ASN.1 DER-encoded X.509 certificates\r
2660 where the first certificate is signed by the Root\r
2661 Certificate or is the Root Cerificate itself. and\r
2662 subsequent cerificate is signed by the preceding\r
2663 cerificate.\r
2664 @param[in] CertChainLength Total length of the certificate chain, in bytes.\r
2665\r
2666 @param[in] CertIndex Index of certificate.\r
2667\r
2668 @param[out] Cert The certificate at the index of CertChain.\r
2669 @param[out] CertLength The length certificate at the index of CertChain.\r
2670\r
2671 @retval TRUE Success.\r
2672 @retval FALSE Failed to get certificate from certificate chain.\r
2673**/\r
2674BOOLEAN\r
2675EFIAPI\r
2676X509GetCertFromCertChain (\r
2677 IN CONST UINT8 *CertChain,\r
2678 IN UINTN CertChainLength,\r
2679 IN CONST INT32 CertIndex,\r
2680 OUT CONST UINT8 **Cert,\r
2681 OUT UINTN *CertLength\r
2682 )\r
2683{\r
2684 CALL_CRYPTO_SERVICE (X509GetCertFromCertChain, (CertChain, CertChainLength, CertIndex, Cert, CertLength), FALSE);\r
2685}\r
2686\r
2687/**\r
2688 Retrieve the tag and length of the tag.\r
2689\r
2690 @param Ptr The position in the ASN.1 data\r
2691 @param End End of data\r
2692 @param Length The variable that will receive the length\r
2693 @param Tag The expected tag\r
2694\r
2695 @retval TRUE Get tag successful\r
2696 @retval FALSe Failed to get tag or tag not match\r
2697**/\r
2698BOOLEAN\r
2699EFIAPI\r
2700Asn1GetTag (\r
2701 IN OUT UINT8 **Ptr,\r
2702 IN CONST UINT8 *End,\r
2703 OUT UINTN *Length,\r
2704 IN UINT32 Tag\r
2705 )\r
2706{\r
2707 CALL_CRYPTO_SERVICE (Asn1GetTag, (Ptr, End, Length, Tag), FALSE);\r
2708}\r
2709\r
2710/**\r
2711 Retrieve the basic constraints from one X.509 certificate.\r
2712\r
2713 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2714 @param[in] CertSize size of the X509 certificate in bytes.\r
2715 @param[out] BasicConstraints basic constraints bytes.\r
2716 @param[in, out] BasicConstraintsSize basic constraints buffer sizs in bytes.\r
2717\r
2718 @retval TRUE The basic constraints retrieve successfully.\r
2719 @retval FALSE If cert is NULL.\r
2720 If cert_size is NULL.\r
2721 If basic_constraints is not NULL and *basic_constraints_size is 0.\r
2722 If cert is invalid.\r
2723 @retval FALSE The required buffer size is small.\r
2724 The return buffer size is basic_constraints_size parameter.\r
2725 @retval FALSE If no Extension entry match oid.\r
2726 @retval FALSE The operation is not supported.\r
2727 **/\r
2728BOOLEAN\r
2729EFIAPI\r
2730X509GetExtendedBasicConstraints (\r
2731 CONST UINT8 *Cert,\r
2732 UINTN CertSize,\r
2733 UINT8 *BasicConstraints,\r
2734 UINTN *BasicConstraintsSize\r
2735 )\r
2736{\r
2737 CALL_CRYPTO_SERVICE (X509GetExtendedBasicConstraints, (Cert, CertSize, BasicConstraints, BasicConstraintsSize), FALSE);\r
2738}\r
2739\r
cd70de1c
MK
2740/**\r
2741 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r
2742 password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r
2743\r
2744 If Password or Salt or OutKey is NULL, then return FALSE.\r
2745 If the hash algorithm could not be determined, then return FALSE.\r
2746 If this interface is not supported, then return FALSE.\r
2747\r
2748 @param[in] PasswordLength Length of input password in bytes.\r
2749 @param[in] Password Pointer to the array for the password.\r
2750 @param[in] SaltLength Size of the Salt in bytes.\r
2751 @param[in] Salt Pointer to the Salt.\r
2752 @param[in] IterationCount Number of iterations to perform. Its value should be\r
2753 greater than or equal to 1.\r
2754 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r
2755 NOTE: DigestSize will be used to determine the hash algorithm.\r
2756 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r
2757 @param[in] KeyLength Size of the derived key buffer in bytes.\r
2758 @param[out] OutKey Pointer to the output derived key buffer.\r
2759\r
2760 @retval TRUE A key was derived successfully.\r
2761 @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r
2762 @retval FALSE The hash algorithm could not be determined from the digest size.\r
2763 @retval FALSE The key derivation operation failed.\r
2764 @retval FALSE This interface is not supported.\r
2765\r
2766**/\r
2767BOOLEAN\r
2768EFIAPI\r
2769Pkcs5HashPassword (\r
2770 IN UINTN PasswordLength,\r
2771 IN CONST CHAR8 *Password,\r
2772 IN UINTN SaltLength,\r
2773 IN CONST UINT8 *Salt,\r
2774 IN UINTN IterationCount,\r
2775 IN UINTN DigestSize,\r
2776 IN UINTN KeyLength,\r
2777 OUT UINT8 *OutKey\r
2778 )\r
2779{\r
2780 CALL_CRYPTO_SERVICE (Pkcs5HashPassword, (PasswordLength, Password, SaltLength, Salt, IterationCount, DigestSize, KeyLength, OutKey), FALSE);\r
2781}\r
2782\r
2783/**\r
2784 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r
2785 encrypted message in a newly allocated buffer.\r
2786\r
2787 Things that can cause a failure include:\r
2788 - X509 key size does not match any known key size.\r
2789 - Fail to parse X509 certificate.\r
2790 - Fail to allocate an intermediate buffer.\r
2791 - Null pointer provided for a non-optional parameter.\r
2792 - Data size is too large for the provided key size (max size is a function of key size\r
2793 and hash digest size).\r
2794\r
2795 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r
2796 will be used to encrypt the data.\r
2797 @param[in] PublicKeySize Size of the X509 cert buffer.\r
2798 @param[in] InData Data to be encrypted.\r
2799 @param[in] InDataSize Size of the data buffer.\r
2800 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r
2801 to be used when initializing the PRNG. NULL otherwise.\r
2802 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r
2803 0 otherwise.\r
2804 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r
2805 message.\r
2806 @param[out] EncryptedDataSize Size of the encrypted message buffer.\r
2807\r
2808 @retval TRUE Encryption was successful.\r
2809 @retval FALSE Encryption failed.\r
2810\r
2811**/\r
2812BOOLEAN\r
2813EFIAPI\r
2814Pkcs1v2Encrypt (\r
2815 IN CONST UINT8 *PublicKey,\r
2816 IN UINTN PublicKeySize,\r
2817 IN UINT8 *InData,\r
2818 IN UINTN InDataSize,\r
c8f46130
MK
2819 IN CONST UINT8 *PrngSeed OPTIONAL,\r
2820 IN UINTN PrngSeedSize OPTIONAL,\r
cd70de1c
MK
2821 OUT UINT8 **EncryptedData,\r
2822 OUT UINTN *EncryptedDataSize\r
2823 )\r
2824{\r
2825 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);\r
2826}\r
2827\r
2828/**\r
2829 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r
2830 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2831 in a ContentInfo structure.\r
2832\r
2833 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r
2834 return FALSE. If P7Length overflow, then return FALSE.\r
2835 If this interface is not supported, then return FALSE.\r
2836\r
2837 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
2838 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2839 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r
2840 It's caller's responsibility to free the buffer with\r
2841 Pkcs7FreeSigners().\r
2842 This data structure is EFI_CERT_STACK type.\r
2843 @param[out] StackLength Length of signer's certificates in bytes.\r
2844 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r
2845 It's caller's responsibility to free the buffer with\r
2846 Pkcs7FreeSigners().\r
2847 @param[out] CertLength Length of the trusted certificate in bytes.\r
2848\r
2849 @retval TRUE The operation is finished successfully.\r
2850 @retval FALSE Error occurs during the operation.\r
2851 @retval FALSE This interface is not supported.\r
2852\r
2853**/\r
2854BOOLEAN\r
2855EFIAPI\r
2856Pkcs7GetSigners (\r
2857 IN CONST UINT8 *P7Data,\r
2858 IN UINTN P7Length,\r
2859 OUT UINT8 **CertStack,\r
2860 OUT UINTN *StackLength,\r
2861 OUT UINT8 **TrustedCert,\r
2862 OUT UINTN *CertLength\r
2863 )\r
2864{\r
2865 CALL_CRYPTO_SERVICE (Pkcs7GetSigners, (P7Data, P7Length, CertStack, StackLength, TrustedCert, CertLength), FALSE);\r
2866}\r
2867\r
2868/**\r
2869 Wrap function to use free() to free allocated memory for certificates.\r
2870\r
2871 If this interface is not supported, then ASSERT().\r
2872\r
2873 @param[in] Certs Pointer to the certificates to be freed.\r
2874\r
2875**/\r
2876VOID\r
2877EFIAPI\r
2878Pkcs7FreeSigners (\r
7c342378 2879 IN UINT8 *Certs\r
cd70de1c
MK
2880 )\r
2881{\r
2882 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners, (Certs));\r
2883}\r
2884\r
2885/**\r
2886 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r
2887 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r
2888 unchained to the signer's certificates.\r
2889 The input signed data could be wrapped in a ContentInfo structure.\r
2890\r
2891 @param[in] P7Data Pointer to the PKCS#7 message.\r
2892 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2893 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r
2894 certificate. It's caller's responsibility to free the buffer\r
2895 with Pkcs7FreeSigners().\r
2896 This data structure is EFI_CERT_STACK type.\r
2897 @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r
2898 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r
2899 responsibility to free the buffer with Pkcs7FreeSigners().\r
2900 This data structure is EFI_CERT_STACK type.\r
2901 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r
2902\r
2903 @retval TRUE The operation is finished successfully.\r
2904 @retval FALSE Error occurs during the operation.\r
2905\r
2906**/\r
2907BOOLEAN\r
2908EFIAPI\r
2909Pkcs7GetCertificatesList (\r
2910 IN CONST UINT8 *P7Data,\r
2911 IN UINTN P7Length,\r
2912 OUT UINT8 **SignerChainCerts,\r
2913 OUT UINTN *ChainLength,\r
2914 OUT UINT8 **UnchainCerts,\r
2915 OUT UINTN *UnchainLength\r
2916 )\r
2917{\r
2918 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList, (P7Data, P7Length, SignerChainCerts, ChainLength, UnchainCerts, UnchainLength), FALSE);\r
2919}\r
2920\r
2921/**\r
2922 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
2923 Syntax Standard, version 1.5". This interface is only intended to be used for\r
2924 application to perform PKCS#7 functionality validation.\r
2925\r
2926 If this interface is not supported, then return FALSE.\r
2927\r
2928 @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r
2929 data signing.\r
2930 @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r
2931 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r
2932 key data.\r
2933 @param[in] InData Pointer to the content to be signed.\r
2934 @param[in] InDataSize Size of InData in bytes.\r
2935 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r
2936 @param[in] OtherCerts Pointer to an optional additional set of certificates to\r
2937 include in the PKCS#7 signedData (e.g. any intermediate\r
2938 CAs in the chain).\r
2939 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r
2940 responsibility to free the buffer with FreePool().\r
2941 @param[out] SignedDataSize Size of SignedData in bytes.\r
2942\r
2943 @retval TRUE PKCS#7 data signing succeeded.\r
2944 @retval FALSE PKCS#7 data signing failed.\r
2945 @retval FALSE This interface is not supported.\r
2946\r
2947**/\r
2948BOOLEAN\r
2949EFIAPI\r
2950Pkcs7Sign (\r
2951 IN CONST UINT8 *PrivateKey,\r
2952 IN UINTN PrivateKeySize,\r
2953 IN CONST UINT8 *KeyPassword,\r
2954 IN UINT8 *InData,\r
2955 IN UINTN InDataSize,\r
2956 IN UINT8 *SignCert,\r
2957 IN UINT8 *OtherCerts OPTIONAL,\r
2958 OUT UINT8 **SignedData,\r
2959 OUT UINTN *SignedDataSize\r
2960 )\r
2961{\r
2962 CALL_CRYPTO_SERVICE (Pkcs7Sign, (PrivateKey, PrivateKeySize, KeyPassword, InData, InDataSize, SignCert, OtherCerts, SignedData, SignedDataSize), FALSE);\r
2963}\r
2964\r
2965/**\r
2966 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r
2967 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2968 in a ContentInfo structure.\r
2969\r
2970 If P7Data, TrustedCert or InData is NULL, then return FALSE.\r
2971 If P7Length, CertLength or DataLength overflow, then return FALSE.\r
2972 If this interface is not supported, then return FALSE.\r
2973\r
2974 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
2975 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2976 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2977 is used for certificate chain verification.\r
2978 @param[in] CertLength Length of the trusted certificate in bytes.\r
2979 @param[in] InData Pointer to the content to be verified.\r
2980 @param[in] DataLength Length of InData in bytes.\r
2981\r
2982 @retval TRUE The specified PKCS#7 signed data is valid.\r
2983 @retval FALSE Invalid PKCS#7 signed data.\r
2984 @retval FALSE This interface is not supported.\r
2985\r
2986**/\r
2987BOOLEAN\r
2988EFIAPI\r
2989Pkcs7Verify (\r
2990 IN CONST UINT8 *P7Data,\r
2991 IN UINTN P7Length,\r
2992 IN CONST UINT8 *TrustedCert,\r
2993 IN UINTN CertLength,\r
2994 IN CONST UINT8 *InData,\r
2995 IN UINTN DataLength\r
2996 )\r
2997{\r
2998 CALL_CRYPTO_SERVICE (Pkcs7Verify, (P7Data, P7Length, TrustedCert, CertLength, InData, DataLength), FALSE);\r
2999}\r
3000\r
3001/**\r
3002 This function receives a PKCS7 formatted signature, and then verifies that\r
3003 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r
3004 leaf signing certificate.\r
3005 Note that this function does not validate the certificate chain.\r
3006\r
3007 Applications for custom EKU's are quite flexible. For example, a policy EKU\r
3008 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r
3009 certificate issued might also contain this EKU, thus constraining the\r
3010 sub-ordinate certificate. Other applications might allow a certificate\r
3011 embedded in a device to specify that other Object Identifiers (OIDs) are\r
3012 present which contains binary data specifying custom capabilities that\r
3013 the device is able to do.\r
3014\r
3015 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r
3016 containing the content block with both the signature,\r
3017 the signer's certificate, and any necessary intermediate\r
3018 certificates.\r
3019 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r
3020 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r
3021 required EKUs that must be present in the signature.\r
3022 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r
3023 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r
3024 must be present in the leaf signer. If it is\r
3025 FALSE, then we will succeed if we find any\r
3026 of the specified EKU's.\r
3027\r
3028 @retval EFI_SUCCESS The required EKUs were found in the signature.\r
3029 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
3030 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r
3031\r
3032**/\r
3033RETURN_STATUS\r
3034EFIAPI\r
3035VerifyEKUsInPkcs7Signature (\r
3036 IN CONST UINT8 *Pkcs7Signature,\r
3037 IN CONST UINT32 SignatureSize,\r
3038 IN CONST CHAR8 *RequiredEKUs[],\r
3039 IN CONST UINT32 RequiredEKUsSize,\r
3040 IN BOOLEAN RequireAllPresent\r
3041 )\r
3042{\r
3043 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature, (Pkcs7Signature, SignatureSize, RequiredEKUs, RequiredEKUsSize, RequireAllPresent), FALSE);\r
3044}\r
3045\r
cd70de1c
MK
3046/**\r
3047 Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r
3048 data could be wrapped in a ContentInfo structure.\r
3049\r
3050 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r
3051 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r
3052\r
3053 Caution: This function may receive untrusted input. So this function will do\r
3054 basic check for PKCS#7 data structure.\r
3055\r
3056 @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r
3057 @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r
3058 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r
3059 It's caller's responsibility to free the buffer with FreePool().\r
3060 @param[out] ContentSize The size of the extracted content in bytes.\r
3061\r
3062 @retval TRUE The P7Data was correctly formatted for processing.\r
3063 @retval FALSE The P7Data was not correctly formatted for processing.\r
3064\r
3065**/\r
3066BOOLEAN\r
3067EFIAPI\r
3068Pkcs7GetAttachedContent (\r
3069 IN CONST UINT8 *P7Data,\r
3070 IN UINTN P7Length,\r
3071 OUT VOID **Content,\r
3072 OUT UINTN *ContentSize\r
3073 )\r
3074{\r
3075 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent, (P7Data, P7Length, Content, ContentSize), FALSE);\r
3076}\r
3077\r
3078/**\r
3079 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r
3080 Authenticode Portable Executable Signature Format".\r
3081\r
3082 If AuthData is NULL, then return FALSE.\r
3083 If ImageHash is NULL, then return FALSE.\r
3084 If this interface is not supported, then return FALSE.\r
3085\r
3086 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
3087 PE/COFF image to be verified.\r
3088 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
3089 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
3090 is used for certificate chain verification.\r
3091 @param[in] CertSize Size of the trusted certificate in bytes.\r
3092 @param[in] ImageHash Pointer to the original image file hash value. The procedure\r
3093 for calculating the image hash value is described in Authenticode\r
3094 specification.\r
3095 @param[in] HashSize Size of Image hash value in bytes.\r
3096\r
3097 @retval TRUE The specified Authenticode Signature is valid.\r
3098 @retval FALSE Invalid Authenticode Signature.\r
3099 @retval FALSE This interface is not supported.\r
3100\r
3101**/\r
3102BOOLEAN\r
3103EFIAPI\r
3104AuthenticodeVerify (\r
3105 IN CONST UINT8 *AuthData,\r
3106 IN UINTN DataSize,\r
3107 IN CONST UINT8 *TrustedCert,\r
3108 IN UINTN CertSize,\r
3109 IN CONST UINT8 *ImageHash,\r
3110 IN UINTN HashSize\r
3111 )\r
3112{\r
3113 CALL_CRYPTO_SERVICE (AuthenticodeVerify, (AuthData, DataSize, TrustedCert, CertSize, ImageHash, HashSize), FALSE);\r
3114}\r
3115\r
3116/**\r
3117 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r
3118 signature.\r
3119\r
3120 If AuthData is NULL, then return FALSE.\r
3121 If this interface is not supported, then return FALSE.\r
3122\r
3123 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
3124 PE/COFF image to be verified.\r
3125 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
3126 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r
3127 is used for TSA certificate chain verification.\r
3128 @param[in] CertSize Size of the trusted certificate in bytes.\r
3129 @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r
3130 signature is valid.\r
3131\r
3132 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r
3133 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r
3134\r
3135**/\r
3136BOOLEAN\r
3137EFIAPI\r
3138ImageTimestampVerify (\r
3139 IN CONST UINT8 *AuthData,\r
3140 IN UINTN DataSize,\r
3141 IN CONST UINT8 *TsaCert,\r
3142 IN UINTN CertSize,\r
3143 OUT EFI_TIME *SigningTime\r
3144 )\r
3145{\r
3146 CALL_CRYPTO_SERVICE (ImageTimestampVerify, (AuthData, DataSize, TsaCert, CertSize, SigningTime), FALSE);\r
3147}\r
3148\r
7c342378 3149// =====================================================================================\r
cd70de1c 3150// DH Key Exchange Primitive\r
7c342378 3151// =====================================================================================\r
cd70de1c
MK
3152\r
3153/**\r
3154 Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r
3155\r
3156 @return Pointer to the Diffie-Hellman Context that has been initialized.\r
3157 If the allocations fails, DhNew() returns NULL.\r
3158 If the interface is not supported, DhNew() returns NULL.\r
3159\r
3160**/\r
3161VOID *\r
3162EFIAPI\r
3163DhNew (\r
3164 VOID\r
3165 )\r
3166{\r
3167 CALL_CRYPTO_SERVICE (DhNew, (), NULL);\r
3168}\r
3169\r
3170/**\r
3171 Release the specified DH context.\r
3172\r
3173 If the interface is not supported, then ASSERT().\r
3174\r
3175 @param[in] DhContext Pointer to the DH context to be released.\r
3176\r
3177**/\r
3178VOID\r
3179EFIAPI\r
3180DhFree (\r
3181 IN VOID *DhContext\r
3182 )\r
3183{\r
3184 CALL_VOID_CRYPTO_SERVICE (DhFree, (DhContext));\r
3185}\r
3186\r
3187/**\r
3188 Generates DH parameter.\r
3189\r
3190 Given generator g, and length of prime number p in bits, this function generates p,\r
3191 and sets DH context according to value of g and p.\r
3192\r
3193 Before this function can be invoked, pseudorandom number generator must be correctly\r
3194 initialized by RandomSeed().\r
3195\r
3196 If DhContext is NULL, then return FALSE.\r
3197 If Prime is NULL, then return FALSE.\r
3198 If this interface is not supported, then return FALSE.\r
3199\r
3200 @param[in, out] DhContext Pointer to the DH context.\r
3201 @param[in] Generator Value of generator.\r
3202 @param[in] PrimeLength Length in bits of prime to be generated.\r
3203 @param[out] Prime Pointer to the buffer to receive the generated prime number.\r
3204\r
3205 @retval TRUE DH parameter generation succeeded.\r
3206 @retval FALSE Value of Generator is not supported.\r
3207 @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r
3208 @retval FALSE This interface is not supported.\r
3209\r
3210**/\r
3211BOOLEAN\r
3212EFIAPI\r
3213DhGenerateParameter (\r
3214 IN OUT VOID *DhContext,\r
3215 IN UINTN Generator,\r
3216 IN UINTN PrimeLength,\r
3217 OUT UINT8 *Prime\r
3218 )\r
3219{\r
3220 CALL_CRYPTO_SERVICE (DhGenerateParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);\r
3221}\r
3222\r
3223/**\r
3224 Sets generator and prime parameters for DH.\r
3225\r
3226 Given generator g, and prime number p, this function and sets DH\r
3227 context accordingly.\r
3228\r
3229 If DhContext is NULL, then return FALSE.\r
3230 If Prime is NULL, then return FALSE.\r
3231 If this interface is not supported, then return FALSE.\r
3232\r
3233 @param[in, out] DhContext Pointer to the DH context.\r
3234 @param[in] Generator Value of generator.\r
3235 @param[in] PrimeLength Length in bits of prime to be generated.\r
3236 @param[in] Prime Pointer to the prime number.\r
3237\r
3238 @retval TRUE DH parameter setting succeeded.\r
3239 @retval FALSE Value of Generator is not supported.\r
3240 @retval FALSE Value of Generator is not suitable for the Prime.\r
3241 @retval FALSE Value of Prime is not a prime number.\r
3242 @retval FALSE Value of Prime is not a safe prime number.\r
3243 @retval FALSE This interface is not supported.\r
3244\r
3245**/\r
3246BOOLEAN\r
3247EFIAPI\r
3248DhSetParameter (\r
3249 IN OUT VOID *DhContext,\r
3250 IN UINTN Generator,\r
3251 IN UINTN PrimeLength,\r
3252 IN CONST UINT8 *Prime\r
3253 )\r
3254{\r
3255 CALL_CRYPTO_SERVICE (DhSetParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);\r
3256}\r
3257\r
3258/**\r
3259 Generates DH public key.\r
3260\r
3261 This function generates random secret exponent, and computes the public key, which is\r
3262 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r
3263 If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r
3264 PublicKeySize is set to the required buffer size to obtain the public key.\r
3265\r
3266 If DhContext is NULL, then return FALSE.\r
3267 If PublicKeySize is NULL, then return FALSE.\r
3268 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r
3269 If this interface is not supported, then return FALSE.\r
3270\r
3271 @param[in, out] DhContext Pointer to the DH context.\r
3272 @param[out] PublicKey Pointer to the buffer to receive generated public key.\r
3273 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r
3274 On output, the size of data returned in PublicKey buffer in bytes.\r
3275\r
3276 @retval TRUE DH public key generation succeeded.\r
3277 @retval FALSE DH public key generation failed.\r
3278 @retval FALSE PublicKeySize is not large enough.\r
3279 @retval FALSE This interface is not supported.\r
3280\r
3281**/\r
3282BOOLEAN\r
3283EFIAPI\r
3284DhGenerateKey (\r
3285 IN OUT VOID *DhContext,\r
3286 OUT UINT8 *PublicKey,\r
3287 IN OUT UINTN *PublicKeySize\r
3288 )\r
3289{\r
3290 CALL_CRYPTO_SERVICE (DhGenerateKey, (DhContext, PublicKey, PublicKeySize), FALSE);\r
3291}\r
3292\r
3293/**\r
3294 Computes exchanged common key.\r
3295\r
3296 Given peer's public key, this function computes the exchanged common key, based on its own\r
3297 context including value of prime modulus and random secret exponent.\r
3298\r
3299 If DhContext is NULL, then return FALSE.\r
3300 If PeerPublicKey is NULL, then return FALSE.\r
3301 If KeySize is NULL, then return FALSE.\r
3302 If Key is NULL, then return FALSE.\r
3303 If KeySize is not large enough, then return FALSE.\r
3304 If this interface is not supported, then return FALSE.\r
3305\r
3306 @param[in, out] DhContext Pointer to the DH context.\r
3307 @param[in] PeerPublicKey Pointer to the peer's public key.\r
3308 @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r
3309 @param[out] Key Pointer to the buffer to receive generated key.\r
3310 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
3311 On output, the size of data returned in Key buffer in bytes.\r
3312\r
3313 @retval TRUE DH exchanged key generation succeeded.\r
3314 @retval FALSE DH exchanged key generation failed.\r
3315 @retval FALSE KeySize is not large enough.\r
3316 @retval FALSE This interface is not supported.\r
3317\r
3318**/\r
3319BOOLEAN\r
3320EFIAPI\r
3321DhComputeKey (\r
3322 IN OUT VOID *DhContext,\r
3323 IN CONST UINT8 *PeerPublicKey,\r
3324 IN UINTN PeerPublicKeySize,\r
3325 OUT UINT8 *Key,\r
3326 IN OUT UINTN *KeySize\r
3327 )\r
3328{\r
3329 CALL_CRYPTO_SERVICE (DhComputeKey, (DhContext, PeerPublicKey, PeerPublicKeySize, Key, KeySize), FALSE);\r
3330}\r
3331\r
7c342378 3332// =====================================================================================\r
cd70de1c 3333// Pseudo-Random Generation Primitive\r
7c342378 3334// =====================================================================================\r
cd70de1c
MK
3335\r
3336/**\r
3337 Sets up the seed value for the pseudorandom number generator.\r
3338\r
3339 This function sets up the seed value for the pseudorandom number generator.\r
3340 If Seed is not NULL, then the seed passed in is used.\r
3341 If Seed is NULL, then default seed is used.\r
3342 If this interface is not supported, then return FALSE.\r
3343\r
3344 @param[in] Seed Pointer to seed value.\r
3345 If NULL, default seed is used.\r
3346 @param[in] SeedSize Size of seed value.\r
3347 If Seed is NULL, this parameter is ignored.\r
3348\r
3349 @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r
3350 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r
3351 @retval FALSE This interface is not supported.\r
3352\r
3353**/\r
3354BOOLEAN\r
3355EFIAPI\r
3356RandomSeed (\r
3357 IN CONST UINT8 *Seed OPTIONAL,\r
3358 IN UINTN SeedSize\r
3359 )\r
3360{\r
3361 CALL_CRYPTO_SERVICE (RandomSeed, (Seed, SeedSize), FALSE);\r
3362}\r
3363\r
3364/**\r
3365 Generates a pseudorandom byte stream of the specified size.\r
3366\r
3367 If Output is NULL, then return FALSE.\r
3368 If this interface is not supported, then return FALSE.\r
3369\r
3370 @param[out] Output Pointer to buffer to receive random value.\r
3371 @param[in] Size Size of random bytes to generate.\r
3372\r
3373 @retval TRUE Pseudorandom byte stream generated successfully.\r
3374 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r
3375 @retval FALSE This interface is not supported.\r
3376\r
3377**/\r
3378BOOLEAN\r
3379EFIAPI\r
3380RandomBytes (\r
3381 OUT UINT8 *Output,\r
3382 IN UINTN Size\r
3383 )\r
3384{\r
3385 CALL_CRYPTO_SERVICE (RandomBytes, (Output, Size), FALSE);\r
3386}\r
3387\r
7c342378 3388// =====================================================================================\r
cd70de1c 3389// Key Derivation Function Primitive\r
7c342378 3390// =====================================================================================\r
cd70de1c
MK
3391\r
3392/**\r
3393 Derive key data using HMAC-SHA256 based KDF.\r
3394\r
3395 @param[in] Key Pointer to the user-supplied key.\r
3396 @param[in] KeySize Key size in bytes.\r
3397 @param[in] Salt Pointer to the salt(non-secret) value.\r
3398 @param[in] SaltSize Salt size in bytes.\r
3399 @param[in] Info Pointer to the application specific info.\r
3400 @param[in] InfoSize Info size in bytes.\r
3401 @param[out] Out Pointer to buffer to receive hkdf value.\r
3402 @param[in] OutSize Size of hkdf bytes to generate.\r
3403\r
3404 @retval TRUE Hkdf generated successfully.\r
3405 @retval FALSE Hkdf generation failed.\r
3406\r
3407**/\r
3408BOOLEAN\r
3409EFIAPI\r
3410HkdfSha256ExtractAndExpand (\r
3411 IN CONST UINT8 *Key,\r
3412 IN UINTN KeySize,\r
3413 IN CONST UINT8 *Salt,\r
3414 IN UINTN SaltSize,\r
3415 IN CONST UINT8 *Info,\r
3416 IN UINTN InfoSize,\r
3417 OUT UINT8 *Out,\r
3418 IN UINTN OutSize\r
3419 )\r
3420{\r
3421 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);\r
3422}\r
3423\r
e919c390
QZ
3424/**\r
3425 Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).\r
3426\r
3427 @param[in] Key Pointer to the user-supplied key.\r
3428 @param[in] KeySize key size in bytes.\r
3429 @param[in] Salt Pointer to the salt(non-secret) value.\r
3430 @param[in] SaltSize salt size in bytes.\r
3431 @param[out] PrkOut Pointer to buffer to receive hkdf value.\r
3432 @param[in] PrkOutSize size of hkdf bytes to generate.\r
3433\r
3434 @retval true Hkdf generated successfully.\r
3435 @retval false Hkdf generation failed.\r
3436\r
3437**/\r
3438BOOLEAN\r
3439EFIAPI\r
3440HkdfSha256Extract (\r
3441 IN CONST UINT8 *Key,\r
3442 IN UINTN KeySize,\r
3443 IN CONST UINT8 *Salt,\r
3444 IN UINTN SaltSize,\r
3445 OUT UINT8 *PrkOut,\r
3446 UINTN PrkOutSize\r
3447 )\r
3448{\r
3449 CALL_CRYPTO_SERVICE (HkdfSha256Extract, (Key, KeySize, Salt, SaltSize, PrkOut, PrkOutSize), FALSE);\r
3450}\r
3451\r
3452/**\r
3453 Derive SHA256 HMAC-based Expand Key Derivation Function (HKDF).\r
3454\r
3455 @param[in] Prk Pointer to the user-supplied key.\r
3456 @param[in] PrkSize Key size in bytes.\r
3457 @param[in] Info Pointer to the application specific info.\r
3458 @param[in] InfoSize Info size in bytes.\r
3459 @param[out] Out Pointer to buffer to receive hkdf value.\r
3460 @param[in] OutSize Size of hkdf bytes to generate.\r
3461\r
3462 @retval TRUE Hkdf generated successfully.\r
3463 @retval FALSE Hkdf generation failed.\r
3464\r
3465**/\r
3466BOOLEAN\r
3467EFIAPI\r
3468HkdfSha256Expand (\r
3469 IN CONST UINT8 *Prk,\r
3470 IN UINTN PrkSize,\r
3471 IN CONST UINT8 *Info,\r
3472 IN UINTN InfoSize,\r
3473 OUT UINT8 *Out,\r
3474 IN UINTN OutSize\r
3475 )\r
3476{\r
3477 CALL_CRYPTO_SERVICE (HkdfSha256Expand, (Prk, PrkSize, Info, InfoSize, Out, OutSize), FALSE);\r
3478}\r
3479\r
3480/**\r
3481 Derive SHA384 HMAC-based Extract-and-Expand Key Derivation Function (HKDF).\r
3482\r
3483 @param[in] Key Pointer to the user-supplied key.\r
3484 @param[in] KeySize Key size in bytes.\r
3485 @param[in] Salt Pointer to the salt(non-secret) value.\r
3486 @param[in] SaltSize Salt size in bytes.\r
3487 @param[in] Info Pointer to the application specific info.\r
3488 @param[in] InfoSize Info size in bytes.\r
3489 @param[out] Out Pointer to buffer to receive hkdf value.\r
3490 @param[in] OutSize Size of hkdf bytes to generate.\r
3491\r
3492 @retval TRUE Hkdf generated successfully.\r
3493 @retval FALSE Hkdf generation failed.\r
3494\r
3495**/\r
3496BOOLEAN\r
3497EFIAPI\r
3498HkdfSha384ExtractAndExpand (\r
3499 IN CONST UINT8 *Key,\r
3500 IN UINTN KeySize,\r
3501 IN CONST UINT8 *Salt,\r
3502 IN UINTN SaltSize,\r
3503 IN CONST UINT8 *Info,\r
3504 IN UINTN InfoSize,\r
3505 OUT UINT8 *Out,\r
3506 IN UINTN OutSize\r
3507 )\r
3508{\r
3509 CALL_CRYPTO_SERVICE (HkdfSha384ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);\r
3510}\r
3511\r
3512/**\r
3513 Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).\r
3514\r
3515 @param[in] Key Pointer to the user-supplied key.\r
3516 @param[in] KeySize key size in bytes.\r
3517 @param[in] Salt Pointer to the salt(non-secret) value.\r
3518 @param[in] SaltSize salt size in bytes.\r
3519 @param[out] PrkOut Pointer to buffer to receive hkdf value.\r
3520 @param[in] PrkOutSize size of hkdf bytes to generate.\r
3521\r
3522 @retval true Hkdf generated successfully.\r
3523 @retval false Hkdf generation failed.\r
3524\r
3525**/\r
3526BOOLEAN\r
3527EFIAPI\r
3528HkdfSha384Extract (\r
3529 IN CONST UINT8 *Key,\r
3530 IN UINTN KeySize,\r
3531 IN CONST UINT8 *Salt,\r
3532 IN UINTN SaltSize,\r
3533 OUT UINT8 *PrkOut,\r
3534 UINTN PrkOutSize\r
3535 )\r
3536{\r
3537 CALL_CRYPTO_SERVICE (HkdfSha384Extract, (Key, KeySize, Salt, SaltSize, PrkOut, PrkOutSize), FALSE);\r
3538}\r
3539\r
3540/**\r
3541 Derive SHA384 HMAC-based Expand Key Derivation Function (HKDF).\r
3542\r
3543 @param[in] Prk Pointer to the user-supplied key.\r
3544 @param[in] PrkSize Key size in bytes.\r
3545 @param[in] Info Pointer to the application specific info.\r
3546 @param[in] InfoSize Info size in bytes.\r
3547 @param[out] Out Pointer to buffer to receive hkdf value.\r
3548 @param[in] OutSize Size of hkdf bytes to generate.\r
3549\r
3550 @retval TRUE Hkdf generated successfully.\r
3551 @retval FALSE Hkdf generation failed.\r
3552\r
3553**/\r
3554BOOLEAN\r
3555EFIAPI\r
3556HkdfSha384Expand (\r
3557 IN CONST UINT8 *Prk,\r
3558 IN UINTN PrkSize,\r
3559 IN CONST UINT8 *Info,\r
3560 IN UINTN InfoSize,\r
3561 OUT UINT8 *Out,\r
3562 IN UINTN OutSize\r
3563 )\r
3564{\r
3565 CALL_CRYPTO_SERVICE (HkdfSha384Expand, (Prk, PrkSize, Info, InfoSize, Out, OutSize), FALSE);\r
3566}\r
3567\r
cd70de1c
MK
3568/**\r
3569 Initializes the OpenSSL library.\r
3570\r
3571 This function registers ciphers and digests used directly and indirectly\r
3572 by SSL/TLS, and initializes the readable error messages.\r
3573 This function must be called before any other action takes places.\r
3574\r
3575 @retval TRUE The OpenSSL library has been initialized.\r
3576 @retval FALSE Failed to initialize the OpenSSL library.\r
3577\r
3578**/\r
3579BOOLEAN\r
3580EFIAPI\r
3581TlsInitialize (\r
3582 VOID\r
3583 )\r
3584{\r
3585 CALL_CRYPTO_SERVICE (TlsInitialize, (), FALSE);\r
3586}\r
3587\r
3588/**\r
3589 Free an allocated SSL_CTX object.\r
3590\r
3591 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.\r
3592\r
3593**/\r
3594VOID\r
3595EFIAPI\r
3596TlsCtxFree (\r
7c342378 3597 IN VOID *TlsCtx\r
cd70de1c
MK
3598 )\r
3599{\r
3600 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree, (TlsCtx));\r
3601}\r
3602\r
3603/**\r
3604 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled\r
3605 connections.\r
3606\r
3607 @param[in] MajorVer Major Version of TLS/SSL Protocol.\r
3608 @param[in] MinorVer Minor Version of TLS/SSL Protocol.\r
3609\r
3610 @return Pointer to an allocated SSL_CTX object.\r
3611 If the creation failed, TlsCtxNew() returns NULL.\r
3612\r
3613**/\r
3614VOID *\r
3615EFIAPI\r
3616TlsCtxNew (\r
7c342378
MK
3617 IN UINT8 MajorVer,\r
3618 IN UINT8 MinorVer\r
cd70de1c
MK
3619 )\r
3620{\r
3621 CALL_CRYPTO_SERVICE (TlsCtxNew, (MajorVer, MinorVer), NULL);\r
3622}\r
3623\r
3624/**\r
3625 Free an allocated TLS object.\r
3626\r
3627 This function removes the TLS object pointed to by Tls and frees up the\r
3628 allocated memory. If Tls is NULL, nothing is done.\r
3629\r
3630 @param[in] Tls Pointer to the TLS object to be freed.\r
3631\r
3632**/\r
3633VOID\r
3634EFIAPI\r
3635TlsFree (\r
7c342378 3636 IN VOID *Tls\r
cd70de1c
MK
3637 )\r
3638{\r
3639 CALL_VOID_CRYPTO_SERVICE (TlsFree, (Tls));\r
3640}\r
3641\r
3642/**\r
3643 Create a new TLS object for a connection.\r
3644\r
3645 This function creates a new TLS object for a connection. The new object\r
3646 inherits the setting of the underlying context TlsCtx: connection method,\r
3647 options, verification setting.\r
3648\r
3649 @param[in] TlsCtx Pointer to the SSL_CTX object.\r
3650\r
3651 @return Pointer to an allocated SSL object.\r
3652 If the creation failed, TlsNew() returns NULL.\r
3653\r
3654**/\r
3655VOID *\r
3656EFIAPI\r
3657TlsNew (\r
7c342378 3658 IN VOID *TlsCtx\r
cd70de1c
MK
3659 )\r
3660{\r
3661 CALL_CRYPTO_SERVICE (TlsNew, (TlsCtx), NULL);\r
3662}\r
3663\r
3664/**\r
3665 Checks if the TLS handshake was done.\r
3666\r
3667 This function will check if the specified TLS handshake was done.\r
3668\r
3669 @param[in] Tls Pointer to the TLS object for handshake state checking.\r
3670\r
3671 @retval TRUE The TLS handshake was done.\r
3672 @retval FALSE The TLS handshake was not done.\r
3673\r
3674**/\r
3675BOOLEAN\r
3676EFIAPI\r
3677TlsInHandshake (\r
7c342378 3678 IN VOID *Tls\r
cd70de1c
MK
3679 )\r
3680{\r
3681 CALL_CRYPTO_SERVICE (TlsInHandshake, (Tls), FALSE);\r
3682}\r
3683\r
3684/**\r
3685 Perform a TLS/SSL handshake.\r
3686\r
3687 This function will perform a TLS/SSL handshake.\r
3688\r
3689 @param[in] Tls Pointer to the TLS object for handshake operation.\r
3690 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.\r
3691 @param[in] BufferInSize Packet size in bytes for the most recently received TLS\r
3692 Handshake packet.\r
3693 @param[out] BufferOut Pointer to the buffer to hold the built packet.\r
3694 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is\r
3695 the buffer size provided by the caller. On output, it\r
3696 is the buffer size in fact needed to contain the\r
3697 packet.\r
3698\r
3699 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
3700 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
3701 Tls is NULL.\r
3702 BufferIn is NULL but BufferInSize is NOT 0.\r
3703 BufferInSize is 0 but BufferIn is NOT NULL.\r
3704 BufferOutSize is NULL.\r
3705 BufferOut is NULL if *BufferOutSize is not zero.\r
3706 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.\r
3707 @retval EFI_ABORTED Something wrong during handshake.\r
3708\r
3709**/\r
3710EFI_STATUS\r
3711EFIAPI\r
3712TlsDoHandshake (\r
7c342378
MK
3713 IN VOID *Tls,\r
3714 IN UINT8 *BufferIn OPTIONAL,\r
3715 IN UINTN BufferInSize OPTIONAL,\r
3716 OUT UINT8 *BufferOut OPTIONAL,\r
3717 IN OUT UINTN *BufferOutSize\r
cd70de1c
MK
3718 )\r
3719{\r
3720 CALL_CRYPTO_SERVICE (TlsDoHandshake, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);\r
3721}\r
3722\r
3723/**\r
3724 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,\r
3725 TLS session has errors and the response packet needs to be Alert message based on error type.\r
3726\r
3727 @param[in] Tls Pointer to the TLS object for state checking.\r
3728 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.\r
3729 @param[in] BufferInSize Packet size in bytes for the most recently received TLS\r
3730 Alert packet.\r
3731 @param[out] BufferOut Pointer to the buffer to hold the built packet.\r
3732 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is\r
3733 the buffer size provided by the caller. On output, it\r
3734 is the buffer size in fact needed to contain the\r
3735 packet.\r
3736\r
3737 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
3738 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
3739 Tls is NULL.\r
3740 BufferIn is NULL but BufferInSize is NOT 0.\r
3741 BufferInSize is 0 but BufferIn is NOT NULL.\r
3742 BufferOutSize is NULL.\r
3743 BufferOut is NULL if *BufferOutSize is not zero.\r
3744 @retval EFI_ABORTED An error occurred.\r
3745 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.\r
3746\r
3747**/\r
3748EFI_STATUS\r
3749EFIAPI\r
3750TlsHandleAlert (\r
7c342378
MK
3751 IN VOID *Tls,\r
3752 IN UINT8 *BufferIn OPTIONAL,\r
3753 IN UINTN BufferInSize OPTIONAL,\r
3754 OUT UINT8 *BufferOut OPTIONAL,\r
3755 IN OUT UINTN *BufferOutSize\r
cd70de1c
MK
3756 )\r
3757{\r
3758 CALL_CRYPTO_SERVICE (TlsHandleAlert, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);\r
3759}\r
3760\r
3761/**\r
3762 Build the CloseNotify packet.\r
3763\r
3764 @param[in] Tls Pointer to the TLS object for state checking.\r
3765 @param[in, out] Buffer Pointer to the buffer to hold the built packet.\r
3766 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is\r
3767 the buffer size provided by the caller. On output, it\r
3768 is the buffer size in fact needed to contain the\r
3769 packet.\r
3770\r
3771 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
3772 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
3773 Tls is NULL.\r
3774 BufferSize is NULL.\r
3775 Buffer is NULL if *BufferSize is not zero.\r
3776 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.\r
3777\r
3778**/\r
3779EFI_STATUS\r
3780EFIAPI\r
3781TlsCloseNotify (\r
7c342378
MK
3782 IN VOID *Tls,\r
3783 IN OUT UINT8 *Buffer,\r
3784 IN OUT UINTN *BufferSize\r
cd70de1c
MK
3785 )\r
3786{\r
3787 CALL_CRYPTO_SERVICE (TlsCloseNotify, (Tls, Buffer, BufferSize), EFI_UNSUPPORTED);\r
3788}\r
3789\r
3790/**\r
3791 Attempts to read bytes from one TLS object and places the data in Buffer.\r
3792\r
3793 This function will attempt to read BufferSize bytes from the TLS object\r
3794 and places the data in Buffer.\r
3795\r
3796 @param[in] Tls Pointer to the TLS object.\r
3797 @param[in,out] Buffer Pointer to the buffer to store the data.\r
3798 @param[in] BufferSize The size of Buffer in bytes.\r
3799\r
3800 @retval >0 The amount of data successfully read from the TLS object.\r
3801 @retval <=0 No data was successfully read.\r
3802\r
3803**/\r
3804INTN\r
3805EFIAPI\r
3806TlsCtrlTrafficOut (\r
7c342378
MK
3807 IN VOID *Tls,\r
3808 IN OUT VOID *Buffer,\r
3809 IN UINTN BufferSize\r
cd70de1c
MK
3810 )\r
3811{\r
3812 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut, (Tls, Buffer, BufferSize), 0);\r
3813}\r
3814\r
3815/**\r
3816 Attempts to write data from the buffer to TLS object.\r
3817\r
3818 This function will attempt to write BufferSize bytes data from the Buffer\r
3819 to the TLS object.\r
3820\r
3821 @param[in] Tls Pointer to the TLS object.\r
3822 @param[in] Buffer Pointer to the data buffer.\r
3823 @param[in] BufferSize The size of Buffer in bytes.\r
3824\r
3825 @retval >0 The amount of data successfully written to the TLS object.\r
3826 @retval <=0 No data was successfully written.\r
3827\r
3828**/\r
3829INTN\r
3830EFIAPI\r
3831TlsCtrlTrafficIn (\r
7c342378
MK
3832 IN VOID *Tls,\r
3833 IN VOID *Buffer,\r
3834 IN UINTN BufferSize\r
cd70de1c
MK
3835 )\r
3836{\r
3837 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn, (Tls, Buffer, BufferSize), 0);\r
3838}\r
3839\r
3840/**\r
3841 Attempts to read bytes from the specified TLS connection into the buffer.\r
3842\r
3843 This function tries to read BufferSize bytes data from the specified TLS\r
3844 connection into the Buffer.\r
3845\r
3846 @param[in] Tls Pointer to the TLS connection for data reading.\r
3847 @param[in,out] Buffer Pointer to the data buffer.\r
3848 @param[in] BufferSize The size of Buffer in bytes.\r
3849\r
3850 @retval >0 The read operation was successful, and return value is the\r
3851 number of bytes actually read from the TLS connection.\r
3852 @retval <=0 The read operation was not successful.\r
3853\r
3854**/\r
3855INTN\r
3856EFIAPI\r
3857TlsRead (\r
7c342378
MK
3858 IN VOID *Tls,\r
3859 IN OUT VOID *Buffer,\r
3860 IN UINTN BufferSize\r
cd70de1c
MK
3861 )\r
3862{\r
3863 CALL_CRYPTO_SERVICE (TlsRead, (Tls, Buffer, BufferSize), 0);\r
3864}\r
3865\r
3866/**\r
3867 Attempts to write data to a TLS connection.\r
3868\r
3869 This function tries to write BufferSize bytes data from the Buffer into the\r
3870 specified TLS connection.\r
3871\r
3872 @param[in] Tls Pointer to the TLS connection for data writing.\r
3873 @param[in] Buffer Pointer to the data buffer.\r
3874 @param[in] BufferSize The size of Buffer in bytes.\r
3875\r
3876 @retval >0 The write operation was successful, and return value is the\r
3877 number of bytes actually written to the TLS connection.\r
3878 @retval <=0 The write operation was not successful.\r
3879\r
3880**/\r
3881INTN\r
3882EFIAPI\r
3883TlsWrite (\r
7c342378
MK
3884 IN VOID *Tls,\r
3885 IN VOID *Buffer,\r
3886 IN UINTN BufferSize\r
cd70de1c
MK
3887 )\r
3888{\r
3889 CALL_CRYPTO_SERVICE (TlsWrite, (Tls, Buffer, BufferSize), 0);\r
3890}\r
3891\r
8db4e9f9
YL
3892/**\r
3893 Shutdown a TLS connection.\r
3894\r
3895 Shutdown the TLS connection without releasing the resources, meaning a new\r
3896 connection can be started without calling TlsNew() and without setting\r
3897 certificates etc.\r
3898\r
3899 @param[in] Tls Pointer to the TLS object to shutdown.\r
3900\r
3901 @retval EFI_SUCCESS The TLS is shutdown successfully.\r
3902 @retval EFI_INVALID_PARAMETER Tls is NULL.\r
3903 @retval EFI_PROTOCOL_ERROR Some other error occurred.\r
3904**/\r
3905EFI_STATUS\r
3906EFIAPI\r
3907TlsShutdown (\r
3908 IN VOID *Tls\r
3909 )\r
3910{\r
3911 CALL_CRYPTO_SERVICE (TlsShutdown, (Tls), EFI_UNSUPPORTED);\r
3912}\r
3913\r
cd70de1c
MK
3914/**\r
3915 Set a new TLS/SSL method for a particular TLS object.\r
3916\r
3917 This function sets a new TLS/SSL method for a particular TLS object.\r
3918\r
3919 @param[in] Tls Pointer to a TLS object.\r
3920 @param[in] MajorVer Major Version of TLS/SSL Protocol.\r
3921 @param[in] MinorVer Minor Version of TLS/SSL Protocol.\r
3922\r
3923 @retval EFI_SUCCESS The TLS/SSL method was set successfully.\r
3924 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3925 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.\r
3926\r
3927**/\r
3928EFI_STATUS\r
3929EFIAPI\r
3930TlsSetVersion (\r
7c342378
MK
3931 IN VOID *Tls,\r
3932 IN UINT8 MajorVer,\r
3933 IN UINT8 MinorVer\r
cd70de1c
MK
3934 )\r
3935{\r
3936 CALL_CRYPTO_SERVICE (TlsSetVersion, (Tls, MajorVer, MinorVer), EFI_UNSUPPORTED);\r
3937}\r
3938\r
3939/**\r
3940 Set TLS object to work in client or server mode.\r
3941\r
3942 This function prepares a TLS object to work in client or server mode.\r
3943\r
3944 @param[in] Tls Pointer to a TLS object.\r
3945 @param[in] IsServer Work in server mode.\r
3946\r
3947 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.\r
3948 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3949 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.\r
3950\r
3951**/\r
3952EFI_STATUS\r
3953EFIAPI\r
3954TlsSetConnectionEnd (\r
7c342378
MK
3955 IN VOID *Tls,\r
3956 IN BOOLEAN IsServer\r
cd70de1c
MK
3957 )\r
3958{\r
3959 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd, (Tls, IsServer), EFI_UNSUPPORTED);\r
3960}\r
3961\r
3962/**\r
3963 Set the ciphers list to be used by the TLS object.\r
3964\r
3965 This function sets the ciphers for use by a specified TLS object.\r
3966\r
3967 @param[in] Tls Pointer to a TLS object.\r
3968 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16\r
3969 cipher identifier comes from the TLS Cipher Suite\r
3970 Registry of the IANA, interpreting Byte1 and Byte2\r
3971 in network (big endian) byte order.\r
3972 @param[in] CipherNum The number of cipher in the list.\r
3973\r
3974 @retval EFI_SUCCESS The ciphers list was set successfully.\r
3975 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3976 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.\r
3977 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
3978\r
3979**/\r
3980EFI_STATUS\r
3981EFIAPI\r
3982TlsSetCipherList (\r
7c342378
MK
3983 IN VOID *Tls,\r
3984 IN UINT16 *CipherId,\r
3985 IN UINTN CipherNum\r
cd70de1c
MK
3986 )\r
3987{\r
3988 CALL_CRYPTO_SERVICE (TlsSetCipherList, (Tls, CipherId, CipherNum), EFI_UNSUPPORTED);\r
3989}\r
3990\r
3991/**\r
3992 Set the compression method for TLS/SSL operations.\r
3993\r
3994 This function handles TLS/SSL integrated compression methods.\r
3995\r
3996 @param[in] CompMethod The compression method ID.\r
3997\r
3998 @retval EFI_SUCCESS The compression method for the communication was\r
3999 set successfully.\r
4000 @retval EFI_UNSUPPORTED Unsupported compression method.\r
4001\r
4002**/\r
4003EFI_STATUS\r
4004EFIAPI\r
4005TlsSetCompressionMethod (\r
7c342378 4006 IN UINT8 CompMethod\r
cd70de1c
MK
4007 )\r
4008{\r
4009 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod, (CompMethod), EFI_UNSUPPORTED);\r
4010}\r
4011\r
4012/**\r
4013 Set peer certificate verification mode for the TLS connection.\r
4014\r
4015 This function sets the verification mode flags for the TLS connection.\r
4016\r
4017 @param[in] Tls Pointer to the TLS object.\r
4018 @param[in] VerifyMode A set of logically or'ed verification mode flags.\r
4019\r
4020**/\r
4021VOID\r
4022EFIAPI\r
4023TlsSetVerify (\r
7c342378
MK
4024 IN VOID *Tls,\r
4025 IN UINT32 VerifyMode\r
cd70de1c
MK
4026 )\r
4027{\r
4028 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify, (Tls, VerifyMode));\r
4029}\r
4030\r
4031/**\r
4032 Set the specified host name to be verified.\r
4033\r
4034 @param[in] Tls Pointer to the TLS object.\r
4035 @param[in] Flags The setting flags during the validation.\r
4036 @param[in] HostName The specified host name to be verified.\r
4037\r
4038 @retval EFI_SUCCESS The HostName setting was set successfully.\r
4039 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4040 @retval EFI_ABORTED Invalid HostName setting.\r
4041\r
4042**/\r
4043EFI_STATUS\r
4044EFIAPI\r
4045TlsSetVerifyHost (\r
7c342378
MK
4046 IN VOID *Tls,\r
4047 IN UINT32 Flags,\r
4048 IN CHAR8 *HostName\r
cd70de1c
MK
4049 )\r
4050{\r
4051 CALL_CRYPTO_SERVICE (TlsSetVerifyHost, (Tls, Flags, HostName), EFI_UNSUPPORTED);\r
4052}\r
4053\r
4054/**\r
4055 Sets a TLS/SSL session ID to be used during TLS/SSL connect.\r
4056\r
4057 This function sets a session ID to be used when the TLS/SSL connection is\r
4058 to be established.\r
4059\r
4060 @param[in] Tls Pointer to the TLS object.\r
4061 @param[in] SessionId Session ID data used for session resumption.\r
4062 @param[in] SessionIdLen Length of Session ID in bytes.\r
4063\r
4064 @retval EFI_SUCCESS Session ID was set successfully.\r
4065 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4066 @retval EFI_UNSUPPORTED No available session for ID setting.\r
4067\r
4068**/\r
4069EFI_STATUS\r
4070EFIAPI\r
4071TlsSetSessionId (\r
7c342378
MK
4072 IN VOID *Tls,\r
4073 IN UINT8 *SessionId,\r
4074 IN UINT16 SessionIdLen\r
cd70de1c
MK
4075 )\r
4076{\r
4077 CALL_CRYPTO_SERVICE (TlsSetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);\r
4078}\r
4079\r
4080/**\r
4081 Adds the CA to the cert store when requesting Server or Client authentication.\r
4082\r
4083 This function adds the CA certificate to the list of CAs when requesting\r
4084 Server or Client authentication for the chosen TLS connection.\r
4085\r
4086 @param[in] Tls Pointer to the TLS object.\r
4087 @param[in] Data Pointer to the data buffer of a DER-encoded binary\r
4088 X.509 certificate or PEM-encoded X.509 certificate.\r
4089 @param[in] DataSize The size of data buffer in bytes.\r
4090\r
4091 @retval EFI_SUCCESS The operation succeeded.\r
4092 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4093 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.\r
4094 @retval EFI_ABORTED Invalid X.509 certificate.\r
4095\r
4096**/\r
4097EFI_STATUS\r
4098EFIAPI\r
4099TlsSetCaCertificate (\r
7c342378
MK
4100 IN VOID *Tls,\r
4101 IN VOID *Data,\r
4102 IN UINTN DataSize\r
cd70de1c
MK
4103 )\r
4104{\r
4105 CALL_CRYPTO_SERVICE (TlsSetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4106}\r
4107\r
4108/**\r
4109 Loads the local public certificate into the specified TLS object.\r
4110\r
4111 This function loads the X.509 certificate into the specified TLS object\r
4112 for TLS negotiation.\r
4113\r
4114 @param[in] Tls Pointer to the TLS object.\r
4115 @param[in] Data Pointer to the data buffer of a DER-encoded binary\r
4116 X.509 certificate or PEM-encoded X.509 certificate.\r
4117 @param[in] DataSize The size of data buffer in bytes.\r
4118\r
4119 @retval EFI_SUCCESS The operation succeeded.\r
4120 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4121 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.\r
4122 @retval EFI_ABORTED Invalid X.509 certificate.\r
4123\r
4124**/\r
4125EFI_STATUS\r
4126EFIAPI\r
4127TlsSetHostPublicCert (\r
7c342378
MK
4128 IN VOID *Tls,\r
4129 IN VOID *Data,\r
4130 IN UINTN DataSize\r
cd70de1c
MK
4131 )\r
4132{\r
4133 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4134}\r
4135\r
4136/**\r
4137 Adds the local private key to the specified TLS object.\r
4138\r
8db4e9f9 4139 This function adds the local private key (DER-encoded or PEM-encoded or PKCS#8 private\r
cd70de1c
MK
4140 key) into the specified TLS object for TLS negotiation.\r
4141\r
4142 @param[in] Tls Pointer to the TLS object.\r
8db4e9f9
YL
4143 @param[in] Data Pointer to the data buffer of a DER-encoded or PEM-encoded\r
4144 or PKCS#8 private key.\r
4145 @param[in] DataSize The size of data buffer in bytes.\r
4146 @param[in] Password Pointer to NULL-terminated private key password, set it to NULL\r
4147 if private key not encrypted.\r
4148\r
4149 @retval EFI_SUCCESS The operation succeeded.\r
4150 @retval EFI_UNSUPPORTED This function is not supported.\r
4151 @retval EFI_ABORTED Invalid private key data.\r
4152\r
4153**/\r
4154EFI_STATUS\r
4155EFIAPI\r
4156TlsSetHostPrivateKeyEx (\r
4157 IN VOID *Tls,\r
4158 IN VOID *Data,\r
4159 IN UINTN DataSize,\r
4160 IN VOID *Password OPTIONAL\r
4161 )\r
4162{\r
4163 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKeyEx, (Tls, Data, DataSize, Password), EFI_UNSUPPORTED);\r
4164}\r
4165\r
4166/**\r
4167 Adds the local private key to the specified TLS object.\r
4168\r
4169 This function adds the local private key (DER-encoded or PEM-encoded or PKCS#8 private\r
4170 key) into the specified TLS object for TLS negotiation.\r
4171\r
4172 @param[in] Tls Pointer to the TLS object.\r
4173 @param[in] Data Pointer to the data buffer of a DER-encoded or PEM-encoded\r
cd70de1c
MK
4174 or PKCS#8 private key.\r
4175 @param[in] DataSize The size of data buffer in bytes.\r
4176\r
4177 @retval EFI_SUCCESS The operation succeeded.\r
4178 @retval EFI_UNSUPPORTED This function is not supported.\r
4179 @retval EFI_ABORTED Invalid private key data.\r
4180\r
4181**/\r
4182EFI_STATUS\r
4183EFIAPI\r
4184TlsSetHostPrivateKey (\r
7c342378
MK
4185 IN VOID *Tls,\r
4186 IN VOID *Data,\r
4187 IN UINTN DataSize\r
cd70de1c
MK
4188 )\r
4189{\r
4190 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4191}\r
4192\r
4193/**\r
4194 Adds the CA-supplied certificate revocation list for certificate validation.\r
4195\r
4196 This function adds the CA-supplied certificate revocation list data for\r
4197 certificate validity checking.\r
4198\r
4199 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.\r
4200 @param[in] DataSize The size of data buffer in bytes.\r
4201\r
4202 @retval EFI_SUCCESS The operation succeeded.\r
4203 @retval EFI_UNSUPPORTED This function is not supported.\r
4204 @retval EFI_ABORTED Invalid CRL data.\r
4205\r
4206**/\r
4207EFI_STATUS\r
4208EFIAPI\r
4209TlsSetCertRevocationList (\r
7c342378
MK
4210 IN VOID *Data,\r
4211 IN UINTN DataSize\r
cd70de1c
MK
4212 )\r
4213{\r
4214 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);\r
4215}\r
4216\r
8db4e9f9
YL
4217/**\r
4218 Set the signature algorithm list to used by the TLS object.\r
4219\r
4220 This function sets the signature algorithms for use by a specified TLS object.\r
4221\r
4222 @param[in] Tls Pointer to a TLS object.\r
4223 @param[in] Data Array of UINT8 of signature algorithms. The array consists of\r
4224 pairs of the hash algorithm and the signature algorithm as defined\r
4225 in RFC 5246\r
4226 @param[in] DataSize The length the SignatureAlgoList. Must be divisible by 2.\r
4227\r
4228 @retval EFI_SUCCESS The signature algorithm list was set successfully.\r
4229 @retval EFI_INVALID_PARAMETER The parameters are invalid.\r
4230 @retval EFI_UNSUPPORTED No supported TLS signature algorithm was found in SignatureAlgoList\r
4231 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
4232\r
4233**/\r
4234EFI_STATUS\r
4235EFIAPI\r
4236TlsSetSignatureAlgoList (\r
4237 IN VOID *Tls,\r
4238 IN UINT8 *Data,\r
4239 IN UINTN DataSize\r
4240 )\r
4241{\r
4242 CALL_CRYPTO_SERVICE (TlsSetSignatureAlgoList, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4243}\r
4244\r
4245/**\r
4246 Set the EC curve to be used for TLS flows\r
4247\r
4248 This function sets the EC curve to be used for TLS flows.\r
4249\r
4250 @param[in] Tls Pointer to a TLS object.\r
4251 @param[in] Data An EC named curve as defined in section 5.1.1 of RFC 4492.\r
4252 @param[in] DataSize Size of Data, it should be sizeof (UINT32)\r
4253\r
4254 @retval EFI_SUCCESS The EC curve was set successfully.\r
4255 @retval EFI_INVALID_PARAMETER The parameters are invalid.\r
4256 @retval EFI_UNSUPPORTED The requested TLS EC curve is not supported\r
4257\r
4258**/\r
4259EFI_STATUS\r
4260EFIAPI\r
4261TlsSetEcCurve (\r
4262 IN VOID *Tls,\r
4263 IN UINT8 *Data,\r
4264 IN UINTN DataSize\r
4265 )\r
4266{\r
4267 CALL_CRYPTO_SERVICE (TlsSetSignatureAlgoList, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4268}\r
4269\r
cd70de1c
MK
4270/**\r
4271 Gets the protocol version used by the specified TLS connection.\r
4272\r
4273 This function returns the protocol version used by the specified TLS\r
4274 connection.\r
4275\r
4276 If Tls is NULL, then ASSERT().\r
4277\r
4278 @param[in] Tls Pointer to the TLS object.\r
4279\r
4280 @return The protocol version of the specified TLS connection.\r
4281\r
4282**/\r
4283UINT16\r
4284EFIAPI\r
4285TlsGetVersion (\r
7c342378 4286 IN VOID *Tls\r
cd70de1c
MK
4287 )\r
4288{\r
4289 CALL_CRYPTO_SERVICE (TlsGetVersion, (Tls), 0);\r
4290}\r
4291\r
4292/**\r
4293 Gets the connection end of the specified TLS connection.\r
4294\r
4295 This function returns the connection end (as client or as server) used by\r
4296 the specified TLS connection.\r
4297\r
4298 If Tls is NULL, then ASSERT().\r
4299\r
4300 @param[in] Tls Pointer to the TLS object.\r
4301\r
4302 @return The connection end used by the specified TLS connection.\r
4303\r
4304**/\r
4305UINT8\r
4306EFIAPI\r
4307TlsGetConnectionEnd (\r
7c342378 4308 IN VOID *Tls\r
cd70de1c
MK
4309 )\r
4310{\r
4311 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd, (Tls), 0);\r
4312}\r
4313\r
4314/**\r
4315 Gets the cipher suite used by the specified TLS connection.\r
4316\r
4317 This function returns current cipher suite used by the specified\r
4318 TLS connection.\r
4319\r
4320 @param[in] Tls Pointer to the TLS object.\r
4321 @param[in,out] CipherId The cipher suite used by the TLS object.\r
4322\r
4323 @retval EFI_SUCCESS The cipher suite was returned successfully.\r
4324 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4325 @retval EFI_UNSUPPORTED Unsupported cipher suite.\r
4326\r
4327**/\r
4328EFI_STATUS\r
4329EFIAPI\r
4330TlsGetCurrentCipher (\r
7c342378
MK
4331 IN VOID *Tls,\r
4332 IN OUT UINT16 *CipherId\r
cd70de1c
MK
4333 )\r
4334{\r
4335 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher, (Tls, CipherId), EFI_UNSUPPORTED);\r
4336}\r
4337\r
4338/**\r
4339 Gets the compression methods used by the specified TLS connection.\r
4340\r
4341 This function returns current integrated compression methods used by\r
4342 the specified TLS connection.\r
4343\r
4344 @param[in] Tls Pointer to the TLS object.\r
4345 @param[in,out] CompressionId The current compression method used by\r
4346 the TLS object.\r
4347\r
4348 @retval EFI_SUCCESS The compression method was returned successfully.\r
4349 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4350 @retval EFI_ABORTED Invalid Compression method.\r
4351 @retval EFI_UNSUPPORTED This function is not supported.\r
4352\r
4353**/\r
4354EFI_STATUS\r
4355EFIAPI\r
4356TlsGetCurrentCompressionId (\r
7c342378
MK
4357 IN VOID *Tls,\r
4358 IN OUT UINT8 *CompressionId\r
cd70de1c
MK
4359 )\r
4360{\r
4361 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId, (Tls, CompressionId), EFI_UNSUPPORTED);\r
4362}\r
4363\r
4364/**\r
4365 Gets the verification mode currently set in the TLS connection.\r
4366\r
4367 This function returns the peer verification mode currently set in the\r
4368 specified TLS connection.\r
4369\r
4370 If Tls is NULL, then ASSERT().\r
4371\r
4372 @param[in] Tls Pointer to the TLS object.\r
4373\r
4374 @return The verification mode set in the specified TLS connection.\r
4375\r
4376**/\r
4377UINT32\r
4378EFIAPI\r
4379TlsGetVerify (\r
7c342378 4380 IN VOID *Tls\r
cd70de1c
MK
4381 )\r
4382{\r
4383 CALL_CRYPTO_SERVICE (TlsGetVerify, (Tls), 0);\r
4384}\r
4385\r
4386/**\r
4387 Gets the session ID used by the specified TLS connection.\r
4388\r
4389 This function returns the TLS/SSL session ID currently used by the\r
4390 specified TLS connection.\r
4391\r
4392 @param[in] Tls Pointer to the TLS object.\r
4393 @param[in,out] SessionId Buffer to contain the returned session ID.\r
4394 @param[in,out] SessionIdLen The length of Session ID in bytes.\r
4395\r
4396 @retval EFI_SUCCESS The Session ID was returned successfully.\r
4397 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4398 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.\r
4399\r
4400**/\r
4401EFI_STATUS\r
4402EFIAPI\r
4403TlsGetSessionId (\r
7c342378
MK
4404 IN VOID *Tls,\r
4405 IN OUT UINT8 *SessionId,\r
4406 IN OUT UINT16 *SessionIdLen\r
cd70de1c
MK
4407 )\r
4408{\r
4409 CALL_CRYPTO_SERVICE (TlsGetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);\r
4410}\r
4411\r
4412/**\r
4413 Gets the client random data used in the specified TLS connection.\r
4414\r
4415 This function returns the TLS/SSL client random data currently used in\r
4416 the specified TLS connection.\r
4417\r
4418 @param[in] Tls Pointer to the TLS object.\r
4419 @param[in,out] ClientRandom Buffer to contain the returned client\r
4420 random data (32 bytes).\r
4421\r
4422**/\r
4423VOID\r
4424EFIAPI\r
4425TlsGetClientRandom (\r
7c342378
MK
4426 IN VOID *Tls,\r
4427 IN OUT UINT8 *ClientRandom\r
cd70de1c
MK
4428 )\r
4429{\r
4430 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom, (Tls, ClientRandom));\r
4431}\r
4432\r
4433/**\r
4434 Gets the server random data used in the specified TLS connection.\r
4435\r
4436 This function returns the TLS/SSL server random data currently used in\r
4437 the specified TLS connection.\r
4438\r
4439 @param[in] Tls Pointer to the TLS object.\r
4440 @param[in,out] ServerRandom Buffer to contain the returned server\r
4441 random data (32 bytes).\r
4442\r
4443**/\r
4444VOID\r
4445EFIAPI\r
4446TlsGetServerRandom (\r
7c342378
MK
4447 IN VOID *Tls,\r
4448 IN OUT UINT8 *ServerRandom\r
cd70de1c
MK
4449 )\r
4450{\r
4451 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom, (Tls, ServerRandom));\r
4452}\r
4453\r
4454/**\r
4455 Gets the master key data used in the specified TLS connection.\r
4456\r
4457 This function returns the TLS/SSL master key material currently used in\r
4458 the specified TLS connection.\r
4459\r
4460 @param[in] Tls Pointer to the TLS object.\r
4461 @param[in,out] KeyMaterial Buffer to contain the returned key material.\r
4462\r
4463 @retval EFI_SUCCESS Key material was returned successfully.\r
4464 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4465 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.\r
4466\r
4467**/\r
4468EFI_STATUS\r
4469EFIAPI\r
4470TlsGetKeyMaterial (\r
7c342378
MK
4471 IN VOID *Tls,\r
4472 IN OUT UINT8 *KeyMaterial\r
cd70de1c
MK
4473 )\r
4474{\r
4475 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial, (Tls, KeyMaterial), EFI_UNSUPPORTED);\r
4476}\r
4477\r
4478/**\r
4479 Gets the CA Certificate from the cert store.\r
4480\r
4481 This function returns the CA certificate for the chosen\r
4482 TLS connection.\r
4483\r
4484 @param[in] Tls Pointer to the TLS object.\r
4485 @param[out] Data Pointer to the data buffer to receive the CA\r
4486 certificate data sent to the client.\r
4487 @param[in,out] DataSize The size of data buffer in bytes.\r
4488\r
4489 @retval EFI_SUCCESS The operation succeeded.\r
4490 @retval EFI_UNSUPPORTED This function is not supported.\r
4491 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
4492\r
4493**/\r
4494EFI_STATUS\r
4495EFIAPI\r
4496TlsGetCaCertificate (\r
7c342378
MK
4497 IN VOID *Tls,\r
4498 OUT VOID *Data,\r
4499 IN OUT UINTN *DataSize\r
cd70de1c
MK
4500 )\r
4501{\r
4502 CALL_CRYPTO_SERVICE (TlsGetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4503}\r
4504\r
4505/**\r
4506 Gets the local public Certificate set in the specified TLS object.\r
4507\r
4508 This function returns the local public certificate which was currently set\r
4509 in the specified TLS object.\r
4510\r
4511 @param[in] Tls Pointer to the TLS object.\r
4512 @param[out] Data Pointer to the data buffer to receive the local\r
4513 public certificate.\r
4514 @param[in,out] DataSize The size of data buffer in bytes.\r
4515\r
4516 @retval EFI_SUCCESS The operation succeeded.\r
4517 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4518 @retval EFI_NOT_FOUND The certificate is not found.\r
4519 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
4520\r
4521**/\r
4522EFI_STATUS\r
4523EFIAPI\r
4524TlsGetHostPublicCert (\r
7c342378
MK
4525 IN VOID *Tls,\r
4526 OUT VOID *Data,\r
4527 IN OUT UINTN *DataSize\r
cd70de1c
MK
4528 )\r
4529{\r
4530 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4531}\r
4532\r
4533/**\r
4534 Gets the local private key set in the specified TLS object.\r
4535\r
4536 This function returns the local private key data which was currently set\r
4537 in the specified TLS object.\r
4538\r
4539 @param[in] Tls Pointer to the TLS object.\r
4540 @param[out] Data Pointer to the data buffer to receive the local\r
4541 private key data.\r
4542 @param[in,out] DataSize The size of data buffer in bytes.\r
4543\r
4544 @retval EFI_SUCCESS The operation succeeded.\r
4545 @retval EFI_UNSUPPORTED This function is not supported.\r
4546 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
4547\r
4548**/\r
4549EFI_STATUS\r
4550EFIAPI\r
4551TlsGetHostPrivateKey (\r
7c342378
MK
4552 IN VOID *Tls,\r
4553 OUT VOID *Data,\r
4554 IN OUT UINTN *DataSize\r
cd70de1c
MK
4555 )\r
4556{\r
4557 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4558}\r
4559\r
4560/**\r
4561 Gets the CA-supplied certificate revocation list data set in the specified\r
4562 TLS object.\r
4563\r
4564 This function returns the CA-supplied certificate revocation list data which\r
4565 was currently set in the specified TLS object.\r
4566\r
4567 @param[out] Data Pointer to the data buffer to receive the CRL data.\r
4568 @param[in,out] DataSize The size of data buffer in bytes.\r
4569\r
4570 @retval EFI_SUCCESS The operation succeeded.\r
4571 @retval EFI_UNSUPPORTED This function is not supported.\r
4572 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
4573\r
4574**/\r
4575EFI_STATUS\r
4576EFIAPI\r
4577TlsGetCertRevocationList (\r
7c342378
MK
4578 OUT VOID *Data,\r
4579 IN OUT UINTN *DataSize\r
cd70de1c
MK
4580 )\r
4581{\r
4582 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);\r
4583}\r
42951543 4584\r
8db4e9f9
YL
4585/**\r
4586 Derive keying material from a TLS connection.\r
4587\r
4588 This function exports keying material using the mechanism described in RFC\r
4589 5705.\r
4590\r
4591 @param[in] Tls Pointer to the TLS object\r
4592 @param[in] Label Description of the key for the PRF function\r
4593 @param[in] Context Optional context\r
4594 @param[in] ContextLen The length of the context value in bytes\r
4595 @param[out] KeyBuffer Buffer to hold the output of the TLS-PRF\r
4596 @param[in] KeyBufferLen The length of the KeyBuffer\r
4597\r
4598 @retval EFI_SUCCESS The operation succeeded.\r
4599 @retval EFI_INVALID_PARAMETER The TLS object is invalid.\r
4600 @retval EFI_PROTOCOL_ERROR Some other error occurred.\r
4601\r
4602**/\r
4603EFI_STATUS\r
4604EFIAPI\r
4605TlsGetExportKey (\r
4606 IN VOID *Tls,\r
4607 IN CONST VOID *Label,\r
4608 IN CONST VOID *Context,\r
4609 IN UINTN ContextLen,\r
4610 OUT VOID *KeyBuffer,\r
4611 IN UINTN KeyBufferLen\r
4612 )\r
4613{\r
4614 CALL_CRYPTO_SERVICE (\r
4615 TlsGetExportKey,\r
4616 (Tls, Label, Context, ContextLen,\r
4617 KeyBuffer, KeyBufferLen),\r
4618 EFI_UNSUPPORTED\r
4619 );\r
4620}\r
4621\r
42951543
YL
4622// =====================================================================================\r
4623// Big number primitive\r
4624// =====================================================================================\r
4625\r
4626/**\r
4627 Allocate new Big Number.\r
4628\r
4629 @retval New BigNum opaque structure or NULL on failure.\r
4630**/\r
4631VOID *\r
4632EFIAPI\r
4633BigNumInit (\r
4634 VOID\r
4635 )\r
4636{\r
4637 CALL_CRYPTO_SERVICE (BigNumInit, (), NULL);\r
4638}\r
4639\r
4640/**\r
4641 Allocate new Big Number and assign the provided value to it.\r
4642\r
4643 @param[in] Buf Big endian encoded buffer.\r
4644 @param[in] Len Buffer length.\r
4645\r
4646 @retval New BigNum opaque structure or NULL on failure.\r
4647**/\r
4648VOID *\r
4649EFIAPI\r
4650BigNumFromBin (\r
4651 IN CONST UINT8 *Buf,\r
4652 IN UINTN Len\r
4653 )\r
4654{\r
4655 CALL_CRYPTO_SERVICE (BigNumFromBin, (Buf, Len), NULL);\r
4656}\r
4657\r
4658/**\r
4659 Convert the absolute value of Bn into big-endian form and store it at Buf.\r
4660 The Buf array should have at least BigNumBytes() in it.\r
4661\r
4662 @param[in] Bn Big number to convert.\r
4663 @param[out] Buf Output buffer.\r
4664\r
4665 @retval The length of the big-endian number placed at Buf or -1 on error.\r
4666**/\r
4667INTN\r
4668EFIAPI\r
4669BigNumToBin (\r
4670 IN CONST VOID *Bn,\r
4671 OUT UINT8 *Buf\r
4672 )\r
4673{\r
4674 CALL_CRYPTO_SERVICE (BigNumToBin, (Bn, Buf), -1);\r
4675}\r
4676\r
4677/**\r
4678 Free the Big Number.\r
4679\r
4680 @param[in] Bn Big number to free.\r
4681 @param[in] Clear TRUE if the buffer should be cleared.\r
4682**/\r
4683VOID\r
4684EFIAPI\r
4685BigNumFree (\r
4686 IN VOID *Bn,\r
4687 IN BOOLEAN Clear\r
4688 )\r
4689{\r
4690 CALL_VOID_CRYPTO_SERVICE (BigNumFree, (Bn, Clear));\r
4691}\r
4692\r
4693/**\r
4694 Calculate the sum of two Big Numbers.\r
4695 Please note, all "out" Big number arguments should be properly initialized\r
4696 by calling to BigNumInit() or BigNumFromBin() functions.\r
4697\r
4698 @param[in] BnA Big number.\r
4699 @param[in] BnB Big number.\r
4700 @param[out] BnRes The result of BnA + BnB.\r
4701\r
4702 @retval TRUE On success.\r
4703 @retval FALSE Otherwise.\r
4704**/\r
4705BOOLEAN\r
4706EFIAPI\r
4707BigNumAdd (\r
4708 IN CONST VOID *BnA,\r
4709 IN CONST VOID *BnB,\r
4710 OUT VOID *BnRes\r
4711 )\r
4712{\r
4713 CALL_CRYPTO_SERVICE (BigNumAdd, (BnA, BnB, BnRes), FALSE);\r
4714}\r
4715\r
4716/**\r
4717 Subtract two Big Numbers.\r
4718 Please note, all "out" Big number arguments should be properly initialized\r
4719 by calling to BigNumInit() or BigNumFromBin() functions.\r
4720\r
4721 @param[in] BnA Big number.\r
4722 @param[in] BnB Big number.\r
4723 @param[out] BnRes The result of BnA - BnB.\r
4724\r
4725 @retval TRUE On success.\r
4726 @retval FALSE Otherwise.\r
4727**/\r
4728BOOLEAN\r
4729EFIAPI\r
4730BigNumSub (\r
4731 IN CONST VOID *BnA,\r
4732 IN CONST VOID *BnB,\r
4733 OUT VOID *BnRes\r
4734 )\r
4735{\r
4736 CALL_CRYPTO_SERVICE (BigNumSub, (BnA, BnB, BnRes), FALSE);\r
4737}\r
4738\r
4739/**\r
4740 Calculate remainder: BnRes = BnA % BnB\r
4741 Please note, all "out" Big number arguments should be properly initialized\r
4742 by calling to BigNumInit() or BigNumFromBin() functions.\r
4743\r
4744 @param[in] BnA Big number.\r
4745 @param[in] BnB Big number.\r
4746 @param[out] BnRes The result of BnA % BnB.\r
4747\r
4748 @retval TRUE On success.\r
4749 @retval FALSE Otherwise.\r
4750**/\r
4751BOOLEAN\r
4752EFIAPI\r
4753BigNumMod (\r
4754 IN CONST VOID *BnA,\r
4755 IN CONST VOID *BnB,\r
4756 OUT VOID *BnRes\r
4757 )\r
4758{\r
4759 CALL_CRYPTO_SERVICE (BigNumMod, (BnA, BnB, BnRes), FALSE);\r
4760}\r
4761\r
4762/**\r
4763 Compute BnA to the BnP-th power modulo BnM.\r
4764 Please note, all "out" Big number arguments should be properly initialized\r
4765 by calling to BigNumInit() or BigNumFromBin() functions.\r
4766\r
4767 @param[in] BnA Big number.\r
4768 @param[in] BnP Big number (power).\r
4769 @param[in] BnM Big number (modulo).\r
4770 @param[out] BnRes The result of (BnA ^ BnP) % BnM.\r
4771\r
4772 @retval TRUE On success.\r
4773 @retval FALSE Otherwise.\r
4774**/\r
4775BOOLEAN\r
4776EFIAPI\r
4777BigNumExpMod (\r
4778 IN CONST VOID *BnA,\r
4779 IN CONST VOID *BnP,\r
4780 IN CONST VOID *BnM,\r
4781 OUT VOID *BnRes\r
4782 )\r
4783{\r
4784 CALL_CRYPTO_SERVICE (BigNumExpMod, (BnA, BnP, BnM, BnRes), FALSE);\r
4785}\r
4786\r
4787/**\r
4788 Compute BnA inverse modulo BnM.\r
4789 Please note, all "out" Big number arguments should be properly initialized\r
4790 by calling to BigNumInit() or BigNumFromBin() functions.\r
4791\r
4792 @param[in] BnA Big number.\r
4793 @param[in] BnM Big number (modulo).\r
4794 @param[out] BnRes The result, such that (BnA * BnRes) % BnM == 1.\r
4795\r
4796 @retval TRUE On success.\r
4797 @retval FALSE Otherwise.\r
4798**/\r
4799BOOLEAN\r
4800EFIAPI\r
4801BigNumInverseMod (\r
4802 IN CONST VOID *BnA,\r
4803 IN CONST VOID *BnM,\r
4804 OUT VOID *BnRes\r
4805 )\r
4806{\r
4807 CALL_CRYPTO_SERVICE (BigNumInverseMod, (BnA, BnM, BnRes), FALSE);\r
4808}\r
4809\r
4810/**\r
4811 Divide two Big Numbers.\r
4812 Please note, all "out" Big number arguments should be properly initialized\r
4813 by calling to BigNumInit() or BigNumFromBin() functions.\r
4814\r
4815 @param[in] BnA Big number.\r
4816 @param[in] BnB Big number.\r
4817 @param[out] BnRes The result, such that BnA / BnB.\r
4818\r
4819 @retval TRUE On success.\r
4820 @retval FALSE Otherwise.\r
4821**/\r
4822BOOLEAN\r
4823EFIAPI\r
4824BigNumDiv (\r
4825 IN CONST VOID *BnA,\r
4826 IN CONST VOID *BnB,\r
4827 OUT VOID *BnRes\r
4828 )\r
4829{\r
4830 CALL_CRYPTO_SERVICE (BigNumDiv, (BnA, BnB, BnRes), FALSE);\r
4831}\r
4832\r
4833/**\r
4834 Multiply two Big Numbers modulo BnM.\r
4835 Please note, all "out" Big number arguments should be properly initialized\r
4836 by calling to BigNumInit() or BigNumFromBin() functions.\r
4837\r
4838 @param[in] BnA Big number.\r
4839 @param[in] BnB Big number.\r
4840 @param[in] BnM Big number (modulo).\r
4841 @param[out] BnRes The result, such that (BnA * BnB) % BnM.\r
4842\r
4843 @retval TRUE On success.\r
4844 @retval FALSE Otherwise.\r
4845**/\r
4846BOOLEAN\r
4847EFIAPI\r
4848BigNumMulMod (\r
4849 IN CONST VOID *BnA,\r
4850 IN CONST VOID *BnB,\r
4851 IN CONST VOID *BnM,\r
4852 OUT VOID *BnRes\r
4853 )\r
4854{\r
4855 CALL_CRYPTO_SERVICE (BigNumMulMod, (BnA, BnB, BnM, BnRes), FALSE);\r
4856}\r
4857\r
4858/**\r
4859 Compare two Big Numbers.\r
4860\r
4861 @param[in] BnA Big number.\r
4862 @param[in] BnB Big number.\r
4863\r
4864 @retval 0 BnA == BnB.\r
4865 @retval 1 BnA > BnB.\r
4866 @retval -1 BnA < BnB.\r
4867**/\r
4868INTN\r
4869EFIAPI\r
4870BigNumCmp (\r
4871 IN CONST VOID *BnA,\r
4872 IN CONST VOID *BnB\r
4873 )\r
4874{\r
4875 CALL_CRYPTO_SERVICE (BigNumCmp, (BnA, BnB), 0);\r
4876}\r
4877\r
4878/**\r
4879 Get number of bits in Bn.\r
4880\r
4881 @param[in] Bn Big number.\r
4882\r
4883 @retval Number of bits.\r
4884**/\r
4885UINTN\r
4886EFIAPI\r
4887BigNumBits (\r
4888 IN CONST VOID *Bn\r
4889 )\r
4890{\r
4891 CALL_CRYPTO_SERVICE (BigNumBits, (Bn), 0);\r
4892}\r
4893\r
4894/**\r
4895 Get number of bytes in Bn.\r
4896\r
4897 @param[in] Bn Big number.\r
4898\r
4899 @retval Number of bytes.\r
4900**/\r
4901UINTN\r
4902EFIAPI\r
4903BigNumBytes (\r
4904 IN CONST VOID *Bn\r
4905 )\r
4906{\r
4907 CALL_CRYPTO_SERVICE (BigNumBytes, (Bn), 0);\r
4908}\r
4909\r
4910/**\r
4911 Checks if Big Number equals to the given Num.\r
4912\r
4913 @param[in] Bn Big number.\r
4914 @param[in] Num Number.\r
4915\r
4916 @retval TRUE iff Bn == Num.\r
4917 @retval FALSE otherwise.\r
4918**/\r
4919BOOLEAN\r
4920EFIAPI\r
4921BigNumIsWord (\r
4922 IN CONST VOID *Bn,\r
4923 IN UINTN Num\r
4924 )\r
4925{\r
4926 CALL_CRYPTO_SERVICE (BigNumIsWord, (Bn, Num), FALSE);\r
4927}\r
4928\r
4929/**\r
4930 Checks if Big Number is odd.\r
4931\r
4932 @param[in] Bn Big number.\r
4933\r
4934 @retval TRUE Bn is odd (Bn % 2 == 1).\r
4935 @retval FALSE otherwise.\r
4936**/\r
4937BOOLEAN\r
4938EFIAPI\r
4939BigNumIsOdd (\r
4940 IN CONST VOID *Bn\r
4941 )\r
4942{\r
4943 CALL_CRYPTO_SERVICE (BigNumIsOdd, (Bn), FALSE);\r
4944}\r
4945\r
4946/**\r
4947 Copy Big number.\r
4948\r
4949 @param[out] BnDst Destination.\r
4950 @param[in] BnSrc Source.\r
4951\r
4952 @retval BnDst on success.\r
4953 @retval NULL otherwise.\r
4954**/\r
4955VOID *\r
4956EFIAPI\r
4957BigNumCopy (\r
4958 OUT VOID *BnDst,\r
4959 IN CONST VOID *BnSrc\r
4960 )\r
4961{\r
4962 CALL_CRYPTO_SERVICE (BigNumCopy, (BnDst, BnSrc), NULL);\r
4963}\r
4964\r
4965/**\r
4966 Get constant Big number with value of "1".\r
4967 This may be used to save expensive allocations.\r
4968\r
4969 @retval Big Number with value of 1.\r
4970**/\r
4971CONST VOID *\r
4972EFIAPI\r
4973BigNumValueOne (\r
4974 VOID\r
4975 )\r
4976{\r
4977 CALL_CRYPTO_SERVICE (BigNumValueOne, (), NULL);\r
4978}\r
4979\r
4980/**\r
4981 Shift right Big Number.\r
4982 Please note, all "out" Big number arguments should be properly initialized\r
4983 by calling to BigNumInit() or BigNumFromBin() functions.\r
4984\r
4985 @param[in] Bn Big number.\r
4986 @param[in] N Number of bits to shift.\r
4987 @param[out] BnRes The result.\r
4988\r
4989 @retval TRUE On success.\r
4990 @retval FALSE Otherwise.\r
4991**/\r
4992BOOLEAN\r
4993EFIAPI\r
4994BigNumRShift (\r
4995 IN CONST VOID *Bn,\r
4996 IN UINTN N,\r
4997 OUT VOID *BnRes\r
4998 )\r
4999{\r
5000 CALL_CRYPTO_SERVICE (BigNumRShift, (Bn, N, BnRes), FALSE);\r
5001}\r
5002\r
5003/**\r
5004 Mark Big Number for constant time computations.\r
5005 This function should be called before any constant time computations are\r
5006 performed on the given Big number.\r
5007\r
5008 @param[in] Bn Big number.\r
5009**/\r
5010VOID\r
5011EFIAPI\r
5012BigNumConstTime (\r
5013 IN VOID *Bn\r
5014 )\r
5015{\r
5016 CALL_VOID_CRYPTO_SERVICE (BigNumConstTime, (Bn));\r
5017}\r
5018\r
5019/**\r
5020 Calculate square modulo.\r
5021 Please note, all "out" Big number arguments should be properly initialized\r
5022 by calling to BigNumInit() or BigNumFromBin() functions.\r
5023\r
5024 @param[in] BnA Big number.\r
5025 @param[in] BnM Big number (modulo).\r
5026 @param[out] BnRes The result, such that (BnA ^ 2) % BnM.\r
5027\r
5028 @retval TRUE On success.\r
5029 @retval FALSE Otherwise.\r
5030**/\r
5031BOOLEAN\r
5032EFIAPI\r
5033BigNumSqrMod (\r
5034 IN CONST VOID *BnA,\r
5035 IN CONST VOID *BnM,\r
5036 OUT VOID *BnRes\r
5037 )\r
5038{\r
5039 CALL_CRYPTO_SERVICE (BigNumSqrMod, (BnA, BnM, BnRes), FALSE);\r
5040}\r
5041\r
5042/**\r
5043 Create new Big Number computation context. This is an opaque structure\r
5044 which should be passed to any function that requires it. The BN context is\r
5045 needed to optimize calculations and expensive allocations.\r
5046\r
5047 @retval Big Number context struct or NULL on failure.\r
5048**/\r
5049VOID *\r
5050EFIAPI\r
5051BigNumNewContext (\r
5052 VOID\r
5053 )\r
5054{\r
5055 CALL_CRYPTO_SERVICE (BigNumNewContext, (), NULL);\r
5056}\r
5057\r
5058/**\r
5059 Free Big Number context that was allocated with BigNumNewContext().\r
5060\r
5061 @param[in] BnCtx Big number context to free.\r
5062**/\r
5063VOID\r
5064EFIAPI\r
5065BigNumContextFree (\r
5066 IN VOID *BnCtx\r
5067 )\r
5068{\r
5069 CALL_VOID_CRYPTO_SERVICE (BigNumContextFree, (BnCtx));\r
5070}\r
5071\r
5072/**\r
5073 Set Big Number to a given value.\r
5074\r
5075 @param[in] Bn Big number to set.\r
5076 @param[in] Val Value to set.\r
5077\r
5078 @retval TRUE On success.\r
5079 @retval FALSE Otherwise.\r
5080**/\r
5081BOOLEAN\r
5082EFIAPI\r
5083BigNumSetUint (\r
5084 IN VOID *Bn,\r
5085 IN UINTN Val\r
5086 )\r
5087{\r
5088 CALL_CRYPTO_SERVICE (BigNumSetUint, (Bn, Val), FALSE);\r
5089}\r
5090\r
5091/**\r
5092 Add two Big Numbers modulo BnM.\r
5093\r
5094 @param[in] BnA Big number.\r
5095 @param[in] BnB Big number.\r
5096 @param[in] BnM Big number (modulo).\r
5097 @param[out] BnRes The result, such that (BnA + BnB) % BnM.\r
5098\r
5099 @retval TRUE On success.\r
5100 @retval FALSE Otherwise.\r
5101**/\r
5102BOOLEAN\r
5103EFIAPI\r
5104BigNumAddMod (\r
5105 IN CONST VOID *BnA,\r
5106 IN CONST VOID *BnB,\r
5107 IN CONST VOID *BnM,\r
5108 OUT VOID *BnRes\r
5109 )\r
5110{\r
5111 CALL_CRYPTO_SERVICE (BigNumAddMod, (BnA, BnB, BnM, BnRes), FALSE);\r
5112}\r
3b382f5b
YL
5113\r
5114/**\r
5115 Initialize new opaque EcGroup object. This object represents an EC curve and\r
5116 and is used for calculation within this group. This object should be freed\r
5117 using EcGroupFree() function.\r
5118\r
5119 @param[in] CryptoNid Identifying number for the ECC curve (Defined in\r
5120 BaseCryptLib.h).\r
5121\r
5122 @retval EcGroup object On success.\r
5123 @retval NULL On failure.\r
5124**/\r
5125VOID *\r
5126EFIAPI\r
5127EcGroupInit (\r
5128 IN UINTN CryptoNid\r
5129 )\r
5130{\r
5131 CALL_CRYPTO_SERVICE (EcGroupInit, (CryptoNid), NULL);\r
5132}\r
5133\r
5134/**\r
5135 Get EC curve parameters. While elliptic curve equation is Y^2 mod P = (X^3 + AX + B) Mod P.\r
5136 This function will set the provided Big Number objects to the corresponding\r
5137 values. The caller needs to make sure all the "out" BigNumber parameters\r
5138 are properly initialized.\r
5139\r
5140 @param[in] EcGroup EC group object.\r
5141 @param[out] BnPrime Group prime number.\r
5142 @param[out] BnA A coefficient.\r
5143 @param[out] BnB B coefficient.\r
5144 @param[in] BnCtx BN context.\r
5145\r
5146 @retval TRUE On success.\r
5147 @retval FALSE Otherwise.\r
5148**/\r
5149BOOLEAN\r
5150EFIAPI\r
5151EcGroupGetCurve (\r
5152 IN CONST VOID *EcGroup,\r
5153 OUT VOID *BnPrime,\r
5154 OUT VOID *BnA,\r
5155 OUT VOID *BnB,\r
5156 IN VOID *BnCtx\r
5157 )\r
5158{\r
5159 CALL_CRYPTO_SERVICE (EcGroupGetCurve, (EcGroup, BnPrime, BnA, BnB, BnCtx), FALSE);\r
5160}\r
5161\r
5162/**\r
5163 Get EC group order.\r
5164 This function will set the provided Big Number object to the corresponding\r
5165 value. The caller needs to make sure that the "out" BigNumber parameter\r
5166 is properly initialized.\r
5167\r
5168 @param[in] EcGroup EC group object.\r
5169 @param[out] BnOrder Group prime number.\r
5170\r
5171 @retval TRUE On success.\r
5172 @retval FALSE Otherwise.\r
5173**/\r
5174BOOLEAN\r
5175EFIAPI\r
5176EcGroupGetOrder (\r
5177 IN VOID *EcGroup,\r
5178 OUT VOID *BnOrder\r
5179 )\r
5180{\r
5181 CALL_CRYPTO_SERVICE (EcGroupGetOrder, (EcGroup, BnOrder), FALSE);\r
5182}\r
5183\r
5184/**\r
5185 Free previously allocated EC group object using EcGroupInit().\r
5186\r
5187 @param[in] EcGroup EC group object to free.\r
5188**/\r
5189VOID\r
5190EFIAPI\r
5191EcGroupFree (\r
5192 IN VOID *EcGroup\r
5193 )\r
5194{\r
5195 CALL_VOID_CRYPTO_SERVICE (EcGroupFree, (EcGroup));\r
5196}\r
5197\r
5198/**\r
5199 Initialize new opaque EC Point object. This object represents an EC point\r
5200 within the given EC group (curve).\r
5201\r
5202 @param[in] EC Group, properly initialized using EcGroupInit().\r
5203\r
5204 @retval EC Point object On success.\r
5205 @retval NULL On failure.\r
5206**/\r
5207VOID *\r
5208EFIAPI\r
5209EcPointInit (\r
5210 IN CONST VOID *EcGroup\r
5211 )\r
5212{\r
5213 CALL_CRYPTO_SERVICE (EcPointInit, (EcGroup), NULL);\r
5214}\r
5215\r
5216/**\r
5217 Free previously allocated EC Point object using EcPointInit().\r
5218\r
5219 @param[in] EcPoint EC Point to free.\r
5220 @param[in] Clear TRUE iff the memory should be cleared.\r
5221**/\r
5222VOID\r
5223EFIAPI\r
5224EcPointDeInit (\r
5225 IN VOID *EcPoint,\r
5226 IN BOOLEAN Clear\r
5227 )\r
5228{\r
5229 CALL_VOID_CRYPTO_SERVICE (EcPointDeInit, (EcPoint, Clear));\r
5230}\r
5231\r
5232/**\r
5233 Get EC point affine (x,y) coordinates.\r
5234 This function will set the provided Big Number objects to the corresponding\r
5235 values. The caller needs to make sure all the "out" BigNumber parameters\r
5236 are properly initialized.\r
5237\r
5238 @param[in] EcGroup EC group object.\r
5239 @param[in] EcPoint EC point object.\r
5240 @param[out] BnX X coordinate.\r
5241 @param[out] BnY Y coordinate.\r
5242 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5243\r
5244 @retval TRUE On success.\r
5245 @retval FALSE Otherwise.\r
5246**/\r
5247BOOLEAN\r
5248EFIAPI\r
5249EcPointGetAffineCoordinates (\r
5250 IN CONST VOID *EcGroup,\r
5251 IN CONST VOID *EcPoint,\r
5252 OUT VOID *BnX,\r
5253 OUT VOID *BnY,\r
5254 IN VOID *BnCtx\r
5255 )\r
5256{\r
5257 CALL_CRYPTO_SERVICE (EcPointGetAffineCoordinates, (EcGroup, EcPoint, BnX, BnY, BnCtx), FALSE);\r
5258}\r
5259\r
5260/**\r
5261 Set EC point affine (x,y) coordinates.\r
5262\r
5263 @param[in] EcGroup EC group object.\r
5264 @param[in] EcPoint EC point object.\r
5265 @param[in] BnX X coordinate.\r
5266 @param[in] BnY Y coordinate.\r
5267 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5268\r
5269 @retval TRUE On success.\r
5270 @retval FALSE Otherwise.\r
5271**/\r
5272BOOLEAN\r
5273EFIAPI\r
5274EcPointSetAffineCoordinates (\r
5275 IN CONST VOID *EcGroup,\r
5276 IN VOID *EcPoint,\r
5277 IN CONST VOID *BnX,\r
5278 IN CONST VOID *BnY,\r
5279 IN VOID *BnCtx\r
5280 )\r
5281{\r
5282 CALL_CRYPTO_SERVICE (EcPointSetAffineCoordinates, (EcGroup, EcPoint, BnX, BnY, BnCtx), FALSE);\r
5283}\r
5284\r
5285/**\r
5286 EC Point addition. EcPointResult = EcPointA + EcPointB.\r
5287\r
5288 @param[in] EcGroup EC group object.\r
5289 @param[out] EcPointResult EC point to hold the result. The point should\r
5290 be properly initialized.\r
5291 @param[in] EcPointA EC Point.\r
5292 @param[in] EcPointB EC Point.\r
5293 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5294\r
5295 @retval TRUE On success.\r
5296 @retval FALSE Otherwise.\r
5297**/\r
5298BOOLEAN\r
5299EFIAPI\r
5300EcPointAdd (\r
5301 IN CONST VOID *EcGroup,\r
5302 OUT VOID *EcPointResult,\r
5303 IN CONST VOID *EcPointA,\r
5304 IN CONST VOID *EcPointB,\r
5305 IN VOID *BnCtx\r
5306 )\r
5307{\r
5308 CALL_CRYPTO_SERVICE (EcPointAdd, (EcGroup, EcPointResult, EcPointA, EcPointB, BnCtx), FALSE);\r
5309}\r
5310\r
5311/**\r
5312 Variable EC point multiplication. EcPointResult = EcPoint * BnPScalar.\r
5313\r
5314 @param[in] EcGroup EC group object.\r
5315 @param[out] EcPointResult EC point to hold the result. The point should\r
5316 be properly initialized.\r
5317 @param[in] EcPoint EC Point.\r
5318 @param[in] BnPScalar P Scalar.\r
5319 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5320\r
5321 @retval TRUE On success.\r
5322 @retval FALSE Otherwise.\r
5323**/\r
5324BOOLEAN\r
5325EFIAPI\r
5326EcPointMul (\r
5327 IN CONST VOID *EcGroup,\r
5328 OUT VOID *EcPointResult,\r
5329 IN CONST VOID *EcPoint,\r
5330 IN CONST VOID *BnPScalar,\r
5331 IN VOID *BnCtx\r
5332 )\r
5333{\r
5334 CALL_CRYPTO_SERVICE (EcPointMul, (EcGroup, EcPointResult, EcPoint, BnPScalar, BnCtx), FALSE);\r
5335}\r
5336\r
5337/**\r
5338 Calculate the inverse of the supplied EC point.\r
5339\r
5340 @param[in] EcGroup EC group object.\r
5341 @param[in,out] EcPoint EC point to invert.\r
5342 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5343\r
5344 @retval TRUE On success.\r
5345 @retval FALSE Otherwise.\r
5346**/\r
5347BOOLEAN\r
5348EFIAPI\r
5349EcPointInvert (\r
5350 IN CONST VOID *EcGroup,\r
5351 IN OUT VOID *EcPoint,\r
5352 IN VOID *BnCtx\r
5353 )\r
5354{\r
5355 CALL_CRYPTO_SERVICE (EcPointInvert, (EcGroup, EcPoint, BnCtx), FALSE);\r
5356}\r
5357\r
5358/**\r
5359 Check if the supplied point is on EC curve.\r
5360\r
5361 @param[in] EcGroup EC group object.\r
5362 @param[in] EcPoint EC point to check.\r
5363 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5364\r
5365 @retval TRUE On curve.\r
5366 @retval FALSE Otherwise.\r
5367**/\r
5368BOOLEAN\r
5369EFIAPI\r
5370EcPointIsOnCurve (\r
5371 IN CONST VOID *EcGroup,\r
5372 IN CONST VOID *EcPoint,\r
5373 IN VOID *BnCtx\r
5374 )\r
5375{\r
5376 CALL_CRYPTO_SERVICE (EcPointIsOnCurve, (EcGroup, EcPoint, BnCtx), FALSE);\r
5377}\r
5378\r
5379/**\r
5380 Check if the supplied point is at infinity.\r
5381\r
5382 @param[in] EcGroup EC group object.\r
5383 @param[in] EcPoint EC point to check.\r
5384\r
5385 @retval TRUE At infinity.\r
5386 @retval FALSE Otherwise.\r
5387**/\r
5388BOOLEAN\r
5389EFIAPI\r
5390EcPointIsAtInfinity (\r
5391 IN CONST VOID *EcGroup,\r
5392 IN CONST VOID *EcPoint\r
5393 )\r
5394{\r
5395 CALL_CRYPTO_SERVICE (EcPointIsAtInfinity, (EcGroup, EcPoint), FALSE);\r
5396}\r
5397\r
5398/**\r
5399 Check if EC points are equal.\r
5400\r
5401 @param[in] EcGroup EC group object.\r
5402 @param[in] EcPointA EC point A.\r
5403 @param[in] EcPointB EC point B.\r
5404 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5405\r
5406 @retval TRUE A == B.\r
5407 @retval FALSE Otherwise.\r
5408**/\r
5409BOOLEAN\r
5410EFIAPI\r
5411EcPointEqual (\r
5412 IN CONST VOID *EcGroup,\r
5413 IN CONST VOID *EcPointA,\r
5414 IN CONST VOID *EcPointB,\r
5415 IN VOID *BnCtx\r
5416 )\r
5417{\r
5418 CALL_CRYPTO_SERVICE (EcPointEqual, (EcGroup, EcPointA, EcPointB, BnCtx), FALSE);\r
5419}\r
5420\r
5421/**\r
5422 Set EC point compressed coordinates. Points can be described in terms of\r
5423 their compressed coordinates. For a point (x, y), for any given value for x\r
5424 such that the point is on the curve there will only ever be two possible\r
5425 values for y. Therefore, a point can be set using this function where BnX is\r
5426 the x coordinate and YBit is a value 0 or 1 to identify which of the two\r
5427 possible values for y should be used.\r
5428\r
5429 @param[in] EcGroup EC group object.\r
5430 @param[in] EcPoint EC Point.\r
5431 @param[in] BnX X coordinate.\r
5432 @param[in] YBit 0 or 1 to identify which Y value is used.\r
5433 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5434\r
5435 @retval TRUE On success.\r
5436 @retval FALSE Otherwise.\r
5437**/\r
5438BOOLEAN\r
5439EFIAPI\r
5440EcPointSetCompressedCoordinates (\r
5441 IN CONST VOID *EcGroup,\r
5442 IN VOID *EcPoint,\r
5443 IN CONST VOID *BnX,\r
5444 IN UINT8 YBit,\r
5445 IN VOID *BnCtx\r
5446 )\r
5447{\r
5448 CALL_CRYPTO_SERVICE (EcPointSetCompressedCoordinates, (EcGroup, EcPoint, BnX, YBit, BnCtx), FALSE);\r
5449}\r
5450\r
5451/**\r
5452 Allocates and Initializes one Elliptic Curve Context for subsequent use\r
5453 with the NID.\r
5454\r
5455 @param[in] Nid cipher NID\r
5456 @return Pointer to the Elliptic Curve Context that has been initialized.\r
5457 If the allocations fails, EcNewByNid() returns NULL.\r
5458**/\r
5459VOID *\r
5460EFIAPI\r
5461EcNewByNid (\r
5462 IN UINTN Nid\r
5463 )\r
5464{\r
5465 CALL_CRYPTO_SERVICE (EcNewByNid, (Nid), NULL);\r
5466}\r
5467\r
5468/**\r
5469 Release the specified EC context.\r
5470\r
5471 @param[in] EcContext Pointer to the EC context to be released.\r
5472**/\r
5473VOID\r
5474EFIAPI\r
5475EcFree (\r
5476 IN VOID *EcContext\r
5477 )\r
5478{\r
5479 CALL_VOID_CRYPTO_SERVICE (EcFree, (EcContext));\r
5480}\r
5481\r
5482/**\r
5483 Generates EC key and returns EC public key (X, Y), Please note, this function uses\r
5484 pseudo random number generator. The caller must make sure RandomSeed()\r
5485 function was properly called before.\r
5486 The Ec context should be correctly initialized by EcNewByNid.\r
5487 This function generates random secret, and computes the public key (X, Y), which is\r
5488 returned via parameter Public, PublicSize.\r
5489 X is the first half of Public with size being PublicSize / 2,\r
5490 Y is the second half of Public with size being PublicSize / 2.\r
5491 EC context is updated accordingly.\r
5492 If the Public buffer is too small to hold the public X, Y, FALSE is returned and\r
5493 PublicSize is set to the required buffer size to obtain the public X, Y.\r
5494 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.\r
5495 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.\r
5496 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.\r
5497 If EcContext is NULL, then return FALSE.\r
5498 If PublicSize is NULL, then return FALSE.\r
5499 If PublicSize is large enough but Public is NULL, then return FALSE.\r
5500 @param[in, out] EcContext Pointer to the EC context.\r
5501 @param[out] PublicKey Pointer to the buffer to receive generated public X,Y.\r
5502 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.\r
5503 On output, the size of data returned in Public buffer in bytes.\r
5504 @retval TRUE EC public X,Y generation succeeded.\r
5505 @retval FALSE EC public X,Y generation failed.\r
5506 @retval FALSE PublicKeySize is not large enough.\r
5507**/\r
5508BOOLEAN\r
5509EFIAPI\r
5510EcGenerateKey (\r
5511 IN OUT VOID *EcContext,\r
5512 OUT UINT8 *PublicKey,\r
5513 IN OUT UINTN *PublicKeySize\r
5514 )\r
5515{\r
5516 CALL_CRYPTO_SERVICE (EcGenerateKey, (EcContext, PublicKey, PublicKeySize), FALSE);\r
5517}\r
5518\r
5519/**\r
5520 Gets the public key component from the established EC context.\r
5521 The Ec context should be correctly initialized by EcNewByNid, and successfully\r
5522 generate key pair from EcGenerateKey().\r
5523 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.\r
5524 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.\r
5525 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.\r
5526 @param[in, out] EcContext Pointer to EC context being set.\r
5527 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.\r
5528 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.\r
5529 On output, the size of data returned in Public buffer in bytes.\r
5530 @retval TRUE EC key component was retrieved successfully.\r
5531 @retval FALSE Invalid EC key component.\r
5532**/\r
5533BOOLEAN\r
5534EFIAPI\r
5535EcGetPubKey (\r
5536 IN OUT VOID *EcContext,\r
5537 OUT UINT8 *PublicKey,\r
5538 IN OUT UINTN *PublicKeySize\r
5539 )\r
5540{\r
5541 CALL_CRYPTO_SERVICE (EcGetPubKey, (EcContext, PublicKey, PublicKeySize), FALSE);\r
5542}\r
5543\r
5544/**\r
5545 Computes exchanged common key.\r
5546 Given peer's public key (X, Y), this function computes the exchanged common key,\r
5547 based on its own context including value of curve parameter and random secret.\r
5548 X is the first half of PeerPublic with size being PeerPublicSize / 2,\r
5549 Y is the second half of PeerPublic with size being PeerPublicSize / 2.\r
5550 If EcContext is NULL, then return FALSE.\r
5551 If PeerPublic is NULL, then return FALSE.\r
5552 If PeerPublicSize is 0, then return FALSE.\r
5553 If Key is NULL, then return FALSE.\r
5554 If KeySize is not large enough, then return FALSE.\r
5555 For P-256, the PeerPublicSize is 64. First 32-byte is X, Second 32-byte is Y.\r
5556 For P-384, the PeerPublicSize is 96. First 48-byte is X, Second 48-byte is Y.\r
5557 For P-521, the PeerPublicSize is 132. First 66-byte is X, Second 66-byte is Y.\r
5558 @param[in, out] EcContext Pointer to the EC context.\r
5559 @param[in] PeerPublic Pointer to the peer's public X,Y.\r
5560 @param[in] PeerPublicSize Size of peer's public X,Y in bytes.\r
5561 @param[in] CompressFlag Flag of PeerPublic is compressed or not.\r
5562 @param[out] Key Pointer to the buffer to receive generated key.\r
5563 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
5564 On output, the size of data returned in Key buffer in bytes.\r
5565 @retval TRUE EC exchanged key generation succeeded.\r
5566 @retval FALSE EC exchanged key generation failed.\r
5567 @retval FALSE KeySize is not large enough.\r
5568**/\r
5569BOOLEAN\r
5570EFIAPI\r
5571EcDhComputeKey (\r
5572 IN OUT VOID *EcContext,\r
5573 IN CONST UINT8 *PeerPublic,\r
5574 IN UINTN PeerPublicSize,\r
5575 IN CONST INT32 *CompressFlag,\r
5576 OUT UINT8 *Key,\r
5577 IN OUT UINTN *KeySize\r
5578 )\r
5579{\r
5580 CALL_CRYPTO_SERVICE (EcDhComputeKey, (EcContext, PeerPublic, PeerPublicSize, CompressFlag, Key, KeySize), FALSE);\r
5581}\r
69a50a24
QZ
5582\r
5583/**\r
5584 Retrieve the EC Public Key from one DER-encoded X509 certificate.\r
5585\r
5586 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
5587 @param[in] CertSize Size of the X509 certificate in bytes.\r
5588 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved\r
5589 EC public key component. Use EcFree() function to free the\r
5590 resource.\r
5591\r
5592 If Cert is NULL, then return FALSE.\r
5593 If EcContext is NULL, then return FALSE.\r
5594\r
5595 @retval TRUE EC Public Key was retrieved successfully.\r
5596 @retval FALSE Fail to retrieve EC public key from X509 certificate.\r
5597\r
5598**/\r
5599BOOLEAN\r
5600EFIAPI\r
5601EcGetPublicKeyFromX509 (\r
5602 IN CONST UINT8 *Cert,\r
5603 IN UINTN CertSize,\r
5604 OUT VOID **EcContext\r
5605 )\r
5606{\r
5607 CALL_CRYPTO_SERVICE (EcGetPublicKeyFromX509, (Cert, CertSize, EcContext), FALSE);\r
5608}\r
5609\r
5610/**\r
5611 Retrieve the EC Private Key from the password-protected PEM key data.\r
5612\r
5613 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
5614 @param[in] PemSize Size of the PEM key data in bytes.\r
5615 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
5616 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved\r
5617 EC private key component. Use EcFree() function to free the\r
5618 resource.\r
5619\r
5620 If PemData is NULL, then return FALSE.\r
5621 If EcContext is NULL, then return FALSE.\r
5622\r
5623 @retval TRUE EC Private Key was retrieved successfully.\r
5624 @retval FALSE Invalid PEM key data or incorrect password.\r
5625\r
5626**/\r
5627BOOLEAN\r
5628EFIAPI\r
5629EcGetPrivateKeyFromPem (\r
5630 IN CONST UINT8 *PemData,\r
5631 IN UINTN PemSize,\r
5632 IN CONST CHAR8 *Password,\r
5633 OUT VOID **EcContext\r
5634 )\r
5635{\r
5636 CALL_CRYPTO_SERVICE (EcGetPrivateKeyFromPem, (PemData, PemSize, Password, EcContext), FALSE);\r
5637}\r
5638\r
5639/**\r
5640 Carries out the EC-DSA signature.\r
5641\r
5642 This function carries out the EC-DSA signature.\r
5643 If the Signature buffer is too small to hold the contents of signature, FALSE\r
5644 is returned and SigSize is set to the required buffer size to obtain the signature.\r
5645\r
5646 If EcContext is NULL, then return FALSE.\r
5647 If MessageHash is NULL, then return FALSE.\r
5648 If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.\r
5649 If SigSize is large enough but Signature is NULL, then return FALSE.\r
5650\r
5651 For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.\r
5652 For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.\r
5653 For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.\r
5654\r
5655 @param[in] EcContext Pointer to EC context for signature generation.\r
5656 @param[in] HashNid hash NID\r
5657 @param[in] MessageHash Pointer to octet message hash to be signed.\r
5658 @param[in] HashSize Size of the message hash in bytes.\r
5659 @param[out] Signature Pointer to buffer to receive EC-DSA signature.\r
5660 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
5661 On output, the size of data returned in Signature buffer in bytes.\r
5662\r
5663 @retval TRUE Signature successfully generated in EC-DSA.\r
5664 @retval FALSE Signature generation failed.\r
5665 @retval FALSE SigSize is too small.\r
5666\r
5667**/\r
5668BOOLEAN\r
5669EFIAPI\r
5670EcDsaSign (\r
5671 IN VOID *EcContext,\r
5672 IN UINTN HashNid,\r
5673 IN CONST UINT8 *MessageHash,\r
5674 IN UINTN HashSize,\r
5675 OUT UINT8 *Signature,\r
5676 IN OUT UINTN *SigSize\r
5677 )\r
5678{\r
5679 CALL_CRYPTO_SERVICE (EcDsaSign, (EcContext, HashNid, MessageHash, HashSize, Signature, SigSize), FALSE);\r
5680}\r
5681\r
5682/**\r
5683 Verifies the EC-DSA signature.\r
5684\r
5685 If EcContext is NULL, then return FALSE.\r
5686 If MessageHash is NULL, then return FALSE.\r
5687 If Signature is NULL, then return FALSE.\r
5688 If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.\r
5689\r
5690 For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.\r
5691 For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.\r
5692 For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.\r
5693\r
5694 @param[in] EcContext Pointer to EC context for signature verification.\r
5695 @param[in] HashNid hash NID\r
5696 @param[in] MessageHash Pointer to octet message hash to be checked.\r
5697 @param[in] HashSize Size of the message hash in bytes.\r
5698 @param[in] Signature Pointer to EC-DSA signature to be verified.\r
5699 @param[in] SigSize Size of signature in bytes.\r
5700\r
5701 @retval TRUE Valid signature encoded in EC-DSA.\r
5702 @retval FALSE Invalid signature or invalid EC context.\r
5703\r
5704**/\r
5705BOOLEAN\r
5706EFIAPI\r
5707EcDsaVerify (\r
5708 IN VOID *EcContext,\r
5709 IN UINTN HashNid,\r
5710 IN CONST UINT8 *MessageHash,\r
5711 IN UINTN HashSize,\r
5712 IN CONST UINT8 *Signature,\r
5713 IN UINTN SigSize\r
5714 )\r
5715{\r
5716 CALL_CRYPTO_SERVICE (EcDsaVerify, (EcContext, HashNid, MessageHash, HashSize, Signature, SigSize), FALSE);\r
5717}\r