]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c
CryptoPkg: Change OPTIONAL keyword usage style
[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
6 Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>\r
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
98//=====================================================================================\r
99// One-Way Cryptographic Hash Primitives\r
100//=====================================================================================\r
101\r
e6a12a0f 102#ifdef ENABLE_MD5_DEPRECATED_INTERFACES\r
cd70de1c
MK
103/**\r
104 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
105\r
106 If this interface is not supported, then return zero.\r
107\r
108 @return The size, in bytes, of the context buffer required for MD5 hash operations.\r
109 @retval 0 This interface is not supported.\r
110\r
111**/\r
112UINTN\r
113EFIAPI\r
114Md5GetContextSize (\r
115 VOID\r
116 )\r
117{\r
118 CALL_CRYPTO_SERVICE (Md5GetContextSize, (), 0);\r
119}\r
120\r
121/**\r
122 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r
123 subsequent use.\r
124\r
125 If Md5Context is NULL, then return FALSE.\r
126 If this interface is not supported, then return FALSE.\r
127\r
128 @param[out] Md5Context Pointer to MD5 context being initialized.\r
129\r
130 @retval TRUE MD5 context initialization succeeded.\r
131 @retval FALSE MD5 context initialization failed.\r
132 @retval FALSE This interface is not supported.\r
133\r
134**/\r
135BOOLEAN\r
136EFIAPI\r
137Md5Init (\r
138 OUT VOID *Md5Context\r
139 )\r
140{\r
141 CALL_CRYPTO_SERVICE (Md5Init, (Md5Context), FALSE);\r
142}\r
143\r
144/**\r
145 Makes a copy of an existing MD5 context.\r
146\r
147 If Md5Context is NULL, then return FALSE.\r
148 If NewMd5Context is NULL, then return FALSE.\r
149 If this interface is not supported, then return FALSE.\r
150\r
151 @param[in] Md5Context Pointer to MD5 context being copied.\r
152 @param[out] NewMd5Context Pointer to new MD5 context.\r
153\r
154 @retval TRUE MD5 context copy succeeded.\r
155 @retval FALSE MD5 context copy failed.\r
156 @retval FALSE This interface is not supported.\r
157\r
158**/\r
159BOOLEAN\r
160EFIAPI\r
161Md5Duplicate (\r
162 IN CONST VOID *Md5Context,\r
163 OUT VOID *NewMd5Context\r
164 )\r
165{\r
166 CALL_CRYPTO_SERVICE (Md5Duplicate, (Md5Context, NewMd5Context), FALSE);\r
167}\r
168\r
169/**\r
170 Digests the input data and updates MD5 context.\r
171\r
172 This function performs MD5 digest on a data buffer of the specified size.\r
173 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
174 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized\r
175 by Md5Final(). Behavior with invalid context is undefined.\r
176\r
177 If Md5Context is NULL, then return FALSE.\r
178 If this interface is not supported, then return FALSE.\r
179\r
180 @param[in, out] Md5Context Pointer to the MD5 context.\r
181 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
182 @param[in] DataSize Size of Data buffer in bytes.\r
183\r
184 @retval TRUE MD5 data digest succeeded.\r
185 @retval FALSE MD5 data digest failed.\r
186 @retval FALSE This interface is not supported.\r
187\r
188**/\r
189BOOLEAN\r
190EFIAPI\r
191Md5Update (\r
192 IN OUT VOID *Md5Context,\r
193 IN CONST VOID *Data,\r
194 IN UINTN DataSize\r
195 )\r
196{\r
197 CALL_CRYPTO_SERVICE (Md5Update, (Md5Context, Data, DataSize), FALSE);\r
198}\r
199\r
200/**\r
201 Completes computation of the MD5 digest value.\r
202\r
203 This function completes MD5 hash computation and retrieves the digest value into\r
204 the specified memory. After this function has been called, the MD5 context cannot\r
205 be used again.\r
206 MD5 context should be already correctly initialized by Md5Init(), and should not be\r
207 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r
208\r
209 If Md5Context is NULL, then return FALSE.\r
210 If HashValue is NULL, then return FALSE.\r
211 If this interface is not supported, then return FALSE.\r
212\r
213 @param[in, out] Md5Context Pointer to the MD5 context.\r
214 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
215 value (16 bytes).\r
216\r
217 @retval TRUE MD5 digest computation succeeded.\r
218 @retval FALSE MD5 digest computation failed.\r
219 @retval FALSE This interface is not supported.\r
220\r
221**/\r
222BOOLEAN\r
223EFIAPI\r
224Md5Final (\r
225 IN OUT VOID *Md5Context,\r
226 OUT UINT8 *HashValue\r
227 )\r
228{\r
229 CALL_CRYPTO_SERVICE (Md5Final, (Md5Context, HashValue), FALSE);\r
230}\r
231\r
232/**\r
233 Computes the MD5 message digest of a input data buffer.\r
234\r
235 This function performs the MD5 message digest of a given data buffer, and places\r
236 the digest value into the specified memory.\r
237\r
238 If this interface is not supported, then return FALSE.\r
239\r
240 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
241 @param[in] DataSize Size of Data buffer in bytes.\r
242 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
243 value (16 bytes).\r
244\r
245 @retval TRUE MD5 digest computation succeeded.\r
246 @retval FALSE MD5 digest computation failed.\r
247 @retval FALSE This interface is not supported.\r
248\r
249**/\r
250BOOLEAN\r
251EFIAPI\r
252Md5HashAll (\r
253 IN CONST VOID *Data,\r
254 IN UINTN DataSize,\r
255 OUT UINT8 *HashValue\r
256 )\r
257{\r
258 CALL_CRYPTO_SERVICE (Md5HashAll, (Data, DataSize, HashValue), FALSE);\r
259}\r
acfd5557 260#endif\r
cd70de1c 261\r
0f01cec5 262#ifndef DISABLE_SHA1_DEPRECATED_INTERFACES\r
cd70de1c
MK
263/**\r
264 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
265\r
266 If this interface is not supported, then return zero.\r
267\r
268 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.\r
269 @retval 0 This interface is not supported.\r
270\r
271**/\r
272UINTN\r
273EFIAPI\r
274Sha1GetContextSize (\r
275 VOID\r
276 )\r
277{\r
278 CALL_CRYPTO_SERVICE (Sha1GetContextSize, (), 0);\r
279}\r
280\r
281/**\r
282 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for\r
283 subsequent use.\r
284\r
285 If Sha1Context is NULL, then return FALSE.\r
286 If this interface is not supported, then return FALSE.\r
287\r
288 @param[out] Sha1Context Pointer to SHA-1 context being initialized.\r
289\r
290 @retval TRUE SHA-1 context initialization succeeded.\r
291 @retval FALSE SHA-1 context initialization failed.\r
292 @retval FALSE This interface is not supported.\r
293\r
294**/\r
295BOOLEAN\r
296EFIAPI\r
297Sha1Init (\r
298 OUT VOID *Sha1Context\r
299 )\r
300{\r
301 CALL_CRYPTO_SERVICE (Sha1Init, (Sha1Context), FALSE);\r
302}\r
303\r
304/**\r
305 Makes a copy of an existing SHA-1 context.\r
306\r
307 If Sha1Context is NULL, then return FALSE.\r
308 If NewSha1Context is NULL, then return FALSE.\r
309 If this interface is not supported, then return FALSE.\r
310\r
311 @param[in] Sha1Context Pointer to SHA-1 context being copied.\r
312 @param[out] NewSha1Context Pointer to new SHA-1 context.\r
313\r
314 @retval TRUE SHA-1 context copy succeeded.\r
315 @retval FALSE SHA-1 context copy failed.\r
316 @retval FALSE This interface is not supported.\r
317\r
318**/\r
319BOOLEAN\r
320EFIAPI\r
321Sha1Duplicate (\r
322 IN CONST VOID *Sha1Context,\r
323 OUT VOID *NewSha1Context\r
324 )\r
325{\r
326 CALL_CRYPTO_SERVICE (Sha1Duplicate, (Sha1Context, NewSha1Context), FALSE);\r
327}\r
328\r
329/**\r
330 Digests the input data and updates SHA-1 context.\r
331\r
332 This function performs SHA-1 digest on a data buffer of the specified size.\r
333 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
334 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized\r
335 by Sha1Final(). Behavior with invalid context is undefined.\r
336\r
337 If Sha1Context is NULL, then return FALSE.\r
338 If this interface is not supported, then return FALSE.\r
339\r
340 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
341 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
342 @param[in] DataSize Size of Data buffer in bytes.\r
343\r
344 @retval TRUE SHA-1 data digest succeeded.\r
345 @retval FALSE SHA-1 data digest failed.\r
346 @retval FALSE This interface is not supported.\r
347\r
348**/\r
349BOOLEAN\r
350EFIAPI\r
351Sha1Update (\r
352 IN OUT VOID *Sha1Context,\r
353 IN CONST VOID *Data,\r
354 IN UINTN DataSize\r
355 )\r
356{\r
357 CALL_CRYPTO_SERVICE (Sha1Update, (Sha1Context, Data, DataSize), FALSE);\r
358}\r
359\r
360/**\r
361 Completes computation of the SHA-1 digest value.\r
362\r
363 This function completes SHA-1 hash computation and retrieves the digest value into\r
364 the specified memory. After this function has been called, the SHA-1 context cannot\r
365 be used again.\r
366 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be\r
367 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.\r
368\r
369 If Sha1Context is NULL, then return FALSE.\r
370 If HashValue is NULL, then return FALSE.\r
371 If this interface is not supported, then return FALSE.\r
372\r
373 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
374 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
375 value (20 bytes).\r
376\r
377 @retval TRUE SHA-1 digest computation succeeded.\r
378 @retval FALSE SHA-1 digest computation failed.\r
379 @retval FALSE This interface is not supported.\r
380\r
381**/\r
382BOOLEAN\r
383EFIAPI\r
384Sha1Final (\r
385 IN OUT VOID *Sha1Context,\r
386 OUT UINT8 *HashValue\r
387 )\r
388{\r
389 CALL_CRYPTO_SERVICE (Sha1Final, (Sha1Context, HashValue), FALSE);\r
390}\r
391\r
392/**\r
393 Computes the SHA-1 message digest of a input data buffer.\r
394\r
395 This function performs the SHA-1 message digest of a given data buffer, and places\r
396 the digest value into the specified memory.\r
397\r
398 If this interface is not supported, then return FALSE.\r
399\r
400 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
401 @param[in] DataSize Size of Data buffer in bytes.\r
402 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
403 value (20 bytes).\r
404\r
405 @retval TRUE SHA-1 digest computation succeeded.\r
406 @retval FALSE SHA-1 digest computation failed.\r
407 @retval FALSE This interface is not supported.\r
408\r
409**/\r
410BOOLEAN\r
411EFIAPI\r
412Sha1HashAll (\r
413 IN CONST VOID *Data,\r
414 IN UINTN DataSize,\r
415 OUT UINT8 *HashValue\r
416 )\r
417{\r
418 CALL_CRYPTO_SERVICE (Sha1HashAll, (Data, DataSize, HashValue), FALSE);\r
419}\r
0f01cec5 420#endif\r
cd70de1c
MK
421\r
422/**\r
423 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.\r
424\r
425 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.\r
426\r
427**/\r
428UINTN\r
429EFIAPI\r
430Sha256GetContextSize (\r
431 VOID\r
432 )\r
433{\r
434 CALL_CRYPTO_SERVICE (Sha256GetContextSize, (), 0);\r
435}\r
436\r
437/**\r
438 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for\r
439 subsequent use.\r
440\r
441 If Sha256Context is NULL, then return FALSE.\r
442\r
443 @param[out] Sha256Context Pointer to SHA-256 context being initialized.\r
444\r
445 @retval TRUE SHA-256 context initialization succeeded.\r
446 @retval FALSE SHA-256 context initialization failed.\r
447\r
448**/\r
449BOOLEAN\r
450EFIAPI\r
451Sha256Init (\r
452 OUT VOID *Sha256Context\r
453 )\r
454{\r
455 CALL_CRYPTO_SERVICE (Sha256Init, (Sha256Context), FALSE);\r
456}\r
457\r
458/**\r
459 Makes a copy of an existing SHA-256 context.\r
460\r
461 If Sha256Context is NULL, then return FALSE.\r
462 If NewSha256Context is NULL, then return FALSE.\r
463 If this interface is not supported, then return FALSE.\r
464\r
465 @param[in] Sha256Context Pointer to SHA-256 context being copied.\r
466 @param[out] NewSha256Context Pointer to new SHA-256 context.\r
467\r
468 @retval TRUE SHA-256 context copy succeeded.\r
469 @retval FALSE SHA-256 context copy failed.\r
470 @retval FALSE This interface is not supported.\r
471\r
472**/\r
473BOOLEAN\r
474EFIAPI\r
475Sha256Duplicate (\r
476 IN CONST VOID *Sha256Context,\r
477 OUT VOID *NewSha256Context\r
478 )\r
479{\r
480 CALL_CRYPTO_SERVICE (Sha256Duplicate, (Sha256Context, NewSha256Context), FALSE);\r
481}\r
482\r
483/**\r
484 Digests the input data and updates SHA-256 context.\r
485\r
486 This function performs SHA-256 digest on a data buffer of the specified size.\r
487 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
488 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized\r
489 by Sha256Final(). Behavior with invalid context is undefined.\r
490\r
491 If Sha256Context is NULL, then return FALSE.\r
492\r
493 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
494 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
495 @param[in] DataSize Size of Data buffer in bytes.\r
496\r
497 @retval TRUE SHA-256 data digest succeeded.\r
498 @retval FALSE SHA-256 data digest failed.\r
499\r
500**/\r
501BOOLEAN\r
502EFIAPI\r
503Sha256Update (\r
504 IN OUT VOID *Sha256Context,\r
505 IN CONST VOID *Data,\r
506 IN UINTN DataSize\r
507 )\r
508{\r
509 CALL_CRYPTO_SERVICE (Sha256Update, (Sha256Context, Data, DataSize), FALSE);\r
510}\r
511\r
512/**\r
513 Completes computation of the SHA-256 digest value.\r
514\r
515 This function completes SHA-256 hash computation and retrieves the digest value into\r
516 the specified memory. After this function has been called, the SHA-256 context cannot\r
517 be used again.\r
518 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be\r
519 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.\r
520\r
521 If Sha256Context is NULL, then return FALSE.\r
522 If HashValue is NULL, then return FALSE.\r
523\r
524 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
525 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
526 value (32 bytes).\r
527\r
528 @retval TRUE SHA-256 digest computation succeeded.\r
529 @retval FALSE SHA-256 digest computation failed.\r
530\r
531**/\r
532BOOLEAN\r
533EFIAPI\r
534Sha256Final (\r
535 IN OUT VOID *Sha256Context,\r
536 OUT UINT8 *HashValue\r
537 )\r
538{\r
539 CALL_CRYPTO_SERVICE (Sha256Final, (Sha256Context, HashValue), FALSE);\r
540}\r
541\r
542/**\r
543 Computes the SHA-256 message digest of a input data buffer.\r
544\r
545 This function performs the SHA-256 message digest of a given data buffer, and places\r
546 the digest value into the specified memory.\r
547\r
548 If this interface is not supported, then return FALSE.\r
549\r
550 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
551 @param[in] DataSize Size of Data buffer in bytes.\r
552 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
553 value (32 bytes).\r
554\r
555 @retval TRUE SHA-256 digest computation succeeded.\r
556 @retval FALSE SHA-256 digest computation failed.\r
557 @retval FALSE This interface is not supported.\r
558\r
559**/\r
560BOOLEAN\r
561EFIAPI\r
562Sha256HashAll (\r
563 IN CONST VOID *Data,\r
564 IN UINTN DataSize,\r
565 OUT UINT8 *HashValue\r
566 )\r
567{\r
568 CALL_CRYPTO_SERVICE (Sha256HashAll, (Data, DataSize, HashValue), FALSE);\r
569}\r
570\r
571/**\r
572 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.\r
573\r
574 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.\r
575\r
576**/\r
577UINTN\r
578EFIAPI\r
579Sha384GetContextSize (\r
580 VOID\r
581 )\r
582{\r
583 CALL_CRYPTO_SERVICE (Sha384GetContextSize, (), 0);\r
584}\r
585\r
586/**\r
587 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for\r
588 subsequent use.\r
589\r
590 If Sha384Context is NULL, then return FALSE.\r
591\r
592 @param[out] Sha384Context Pointer to SHA-384 context being initialized.\r
593\r
594 @retval TRUE SHA-384 context initialization succeeded.\r
595 @retval FALSE SHA-384 context initialization failed.\r
596\r
597**/\r
598BOOLEAN\r
599EFIAPI\r
600Sha384Init (\r
601 OUT VOID *Sha384Context\r
602 )\r
603{\r
604 CALL_CRYPTO_SERVICE (Sha384Init, (Sha384Context), FALSE);\r
605}\r
606\r
607/**\r
608 Makes a copy of an existing SHA-384 context.\r
609\r
610 If Sha384Context is NULL, then return FALSE.\r
611 If NewSha384Context is NULL, then return FALSE.\r
612 If this interface is not supported, then return FALSE.\r
613\r
614 @param[in] Sha384Context Pointer to SHA-384 context being copied.\r
615 @param[out] NewSha384Context Pointer to new SHA-384 context.\r
616\r
617 @retval TRUE SHA-384 context copy succeeded.\r
618 @retval FALSE SHA-384 context copy failed.\r
619 @retval FALSE This interface is not supported.\r
620\r
621**/\r
622BOOLEAN\r
623EFIAPI\r
624Sha384Duplicate (\r
625 IN CONST VOID *Sha384Context,\r
626 OUT VOID *NewSha384Context\r
627 )\r
628{\r
629 CALL_CRYPTO_SERVICE (Sha384Duplicate, (Sha384Context, NewSha384Context), FALSE);\r
630}\r
631\r
632/**\r
633 Digests the input data and updates SHA-384 context.\r
634\r
635 This function performs SHA-384 digest on a data buffer of the specified size.\r
636 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
637 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized\r
638 by Sha384Final(). Behavior with invalid context is undefined.\r
639\r
640 If Sha384Context is NULL, then return FALSE.\r
641\r
642 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
643 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
644 @param[in] DataSize Size of Data buffer in bytes.\r
645\r
646 @retval TRUE SHA-384 data digest succeeded.\r
647 @retval FALSE SHA-384 data digest failed.\r
648\r
649**/\r
650BOOLEAN\r
651EFIAPI\r
652Sha384Update (\r
653 IN OUT VOID *Sha384Context,\r
654 IN CONST VOID *Data,\r
655 IN UINTN DataSize\r
656 )\r
657{\r
658 CALL_CRYPTO_SERVICE (Sha384Update, (Sha384Context, Data, DataSize), FALSE);\r
659}\r
660\r
661/**\r
662 Completes computation of the SHA-384 digest value.\r
663\r
664 This function completes SHA-384 hash computation and retrieves the digest value into\r
665 the specified memory. After this function has been called, the SHA-384 context cannot\r
666 be used again.\r
667 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be\r
668 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.\r
669\r
670 If Sha384Context is NULL, then return FALSE.\r
671 If HashValue is NULL, then return FALSE.\r
672\r
673 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
674 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
675 value (48 bytes).\r
676\r
677 @retval TRUE SHA-384 digest computation succeeded.\r
678 @retval FALSE SHA-384 digest computation failed.\r
679\r
680**/\r
681BOOLEAN\r
682EFIAPI\r
683Sha384Final (\r
684 IN OUT VOID *Sha384Context,\r
685 OUT UINT8 *HashValue\r
686 )\r
687{\r
688 CALL_CRYPTO_SERVICE (Sha384Final, (Sha384Context, HashValue), FALSE);\r
689}\r
690\r
691/**\r
692 Computes the SHA-384 message digest of a input data buffer.\r
693\r
694 This function performs the SHA-384 message digest of a given data buffer, and places\r
695 the digest value into the specified memory.\r
696\r
697 If this interface is not supported, then return FALSE.\r
698\r
699 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
700 @param[in] DataSize Size of Data buffer in bytes.\r
701 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
702 value (48 bytes).\r
703\r
704 @retval TRUE SHA-384 digest computation succeeded.\r
705 @retval FALSE SHA-384 digest computation failed.\r
706 @retval FALSE This interface is not supported.\r
707\r
708**/\r
709BOOLEAN\r
710EFIAPI\r
711Sha384HashAll (\r
712 IN CONST VOID *Data,\r
713 IN UINTN DataSize,\r
714 OUT UINT8 *HashValue\r
715 )\r
716{\r
717 CALL_CRYPTO_SERVICE (Sha384HashAll, (Data, DataSize, HashValue), FALSE);\r
718}\r
719\r
720/**\r
721 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
722\r
723 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.\r
724\r
725**/\r
726UINTN\r
727EFIAPI\r
728Sha512GetContextSize (\r
729 VOID\r
730 )\r
731{\r
732 CALL_CRYPTO_SERVICE (Sha512GetContextSize, (), 0);\r
733}\r
734\r
735/**\r
736 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for\r
737 subsequent use.\r
738\r
739 If Sha512Context is NULL, then return FALSE.\r
740\r
741 @param[out] Sha512Context Pointer to SHA-512 context being initialized.\r
742\r
743 @retval TRUE SHA-512 context initialization succeeded.\r
744 @retval FALSE SHA-512 context initialization failed.\r
745\r
746**/\r
747BOOLEAN\r
748EFIAPI\r
749Sha512Init (\r
750 OUT VOID *Sha512Context\r
751 )\r
752{\r
753 CALL_CRYPTO_SERVICE (Sha512Init, (Sha512Context), FALSE);\r
754}\r
755\r
756/**\r
757 Makes a copy of an existing SHA-512 context.\r
758\r
759 If Sha512Context is NULL, then return FALSE.\r
760 If NewSha512Context is NULL, then return FALSE.\r
761 If this interface is not supported, then return FALSE.\r
762\r
763 @param[in] Sha512Context Pointer to SHA-512 context being copied.\r
764 @param[out] NewSha512Context Pointer to new SHA-512 context.\r
765\r
766 @retval TRUE SHA-512 context copy succeeded.\r
767 @retval FALSE SHA-512 context copy failed.\r
768 @retval FALSE This interface is not supported.\r
769\r
770**/\r
771BOOLEAN\r
772EFIAPI\r
773Sha512Duplicate (\r
774 IN CONST VOID *Sha512Context,\r
775 OUT VOID *NewSha512Context\r
776 )\r
777{\r
778 CALL_CRYPTO_SERVICE (Sha512Duplicate, (Sha512Context, NewSha512Context), FALSE);\r
779}\r
780\r
781/**\r
782 Digests the input data and updates SHA-512 context.\r
783\r
784 This function performs SHA-512 digest on a data buffer of the specified size.\r
785 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
786 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized\r
787 by Sha512Final(). Behavior with invalid context is undefined.\r
788\r
789 If Sha512Context is NULL, then return FALSE.\r
790\r
791 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
792 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
793 @param[in] DataSize Size of Data buffer in bytes.\r
794\r
795 @retval TRUE SHA-512 data digest succeeded.\r
796 @retval FALSE SHA-512 data digest failed.\r
797\r
798**/\r
799BOOLEAN\r
800EFIAPI\r
801Sha512Update (\r
802 IN OUT VOID *Sha512Context,\r
803 IN CONST VOID *Data,\r
804 IN UINTN DataSize\r
805 )\r
806{\r
807 CALL_CRYPTO_SERVICE (Sha512Update, (Sha512Context, Data, DataSize), FALSE);\r
808}\r
809\r
810/**\r
811 Completes computation of the SHA-512 digest value.\r
812\r
813 This function completes SHA-512 hash computation and retrieves the digest value into\r
814 the specified memory. After this function has been called, the SHA-512 context cannot\r
815 be used again.\r
816 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be\r
817 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.\r
818\r
819 If Sha512Context is NULL, then return FALSE.\r
820 If HashValue is NULL, then return FALSE.\r
821\r
822 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
823 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
824 value (64 bytes).\r
825\r
826 @retval TRUE SHA-512 digest computation succeeded.\r
827 @retval FALSE SHA-512 digest computation failed.\r
828\r
829**/\r
830BOOLEAN\r
831EFIAPI\r
832Sha512Final (\r
833 IN OUT VOID *Sha512Context,\r
834 OUT UINT8 *HashValue\r
835 )\r
836{\r
837 CALL_CRYPTO_SERVICE (Sha512Final, (Sha512Context, HashValue), FALSE);\r
838}\r
839\r
840/**\r
841 Computes the SHA-512 message digest of a input data buffer.\r
842\r
843 This function performs the SHA-512 message digest of a given data buffer, and places\r
844 the digest value into the specified memory.\r
845\r
846 If this interface is not supported, then return FALSE.\r
847\r
848 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
849 @param[in] DataSize Size of Data buffer in bytes.\r
850 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
851 value (64 bytes).\r
852\r
853 @retval TRUE SHA-512 digest computation succeeded.\r
854 @retval FALSE SHA-512 digest computation failed.\r
855 @retval FALSE This interface is not supported.\r
856\r
857**/\r
858BOOLEAN\r
859EFIAPI\r
860Sha512HashAll (\r
861 IN CONST VOID *Data,\r
862 IN UINTN DataSize,\r
863 OUT UINT8 *HashValue\r
864 )\r
865{\r
866 CALL_CRYPTO_SERVICE (Sha512HashAll, (Data, DataSize, HashValue), FALSE);\r
867}\r
868\r
869/**\r
870 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.\r
871\r
872 @return The size, in bytes, of the context buffer required for SM3 hash operations.\r
873\r
874**/\r
875UINTN\r
876EFIAPI\r
877Sm3GetContextSize (\r
878 VOID\r
879 )\r
880{\r
881 CALL_CRYPTO_SERVICE (Sm3GetContextSize, (), 0);\r
882}\r
883\r
884/**\r
885 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for\r
886 subsequent use.\r
887\r
888 If Sm3Context is NULL, then return FALSE.\r
889\r
890 @param[out] Sm3Context Pointer to SM3 context being initialized.\r
891\r
892 @retval TRUE SM3 context initialization succeeded.\r
893 @retval FALSE SM3 context initialization failed.\r
894\r
895**/\r
896BOOLEAN\r
897EFIAPI\r
898Sm3Init (\r
899 OUT VOID *Sm3Context\r
900 )\r
901{\r
902 CALL_CRYPTO_SERVICE (Sm3Init, (Sm3Context), FALSE);\r
903}\r
904\r
905/**\r
906 Makes a copy of an existing SM3 context.\r
907\r
908 If Sm3Context is NULL, then return FALSE.\r
909 If NewSm3Context is NULL, then return FALSE.\r
910 If this interface is not supported, then return FALSE.\r
911\r
912 @param[in] Sm3Context Pointer to SM3 context being copied.\r
913 @param[out] NewSm3Context Pointer to new SM3 context.\r
914\r
915 @retval TRUE SM3 context copy succeeded.\r
916 @retval FALSE SM3 context copy failed.\r
917 @retval FALSE This interface is not supported.\r
918\r
919**/\r
920BOOLEAN\r
921EFIAPI\r
922Sm3Duplicate (\r
923 IN CONST VOID *Sm3Context,\r
924 OUT VOID *NewSm3Context\r
925 )\r
926{\r
927 CALL_CRYPTO_SERVICE (Sm3Duplicate, (Sm3Context, NewSm3Context), FALSE);\r
928}\r
929\r
930/**\r
931 Digests the input data and updates SM3 context.\r
932\r
933 This function performs SM3 digest on a data buffer of the specified size.\r
934 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
935 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized\r
936 by Sm3Final(). Behavior with invalid context is undefined.\r
937\r
938 If Sm3Context is NULL, then return FALSE.\r
939\r
940 @param[in, out] Sm3Context Pointer to the SM3 context.\r
941 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
942 @param[in] DataSize Size of Data buffer in bytes.\r
943\r
944 @retval TRUE SM3 data digest succeeded.\r
945 @retval FALSE SM3 data digest failed.\r
946\r
947**/\r
948BOOLEAN\r
949EFIAPI\r
950Sm3Update (\r
951 IN OUT VOID *Sm3Context,\r
952 IN CONST VOID *Data,\r
953 IN UINTN DataSize\r
954 )\r
955{\r
956 CALL_CRYPTO_SERVICE (Sm3Update, (Sm3Context, Data, DataSize), FALSE);\r
957}\r
958\r
959/**\r
960 Completes computation of the SM3 digest value.\r
961\r
962 This function completes SM3 hash computation and retrieves the digest value into\r
963 the specified memory. After this function has been called, the SM3 context cannot\r
964 be used again.\r
965 SM3 context should be already correctly initialized by Sm3Init(), and should not be\r
966 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.\r
967\r
968 If Sm3Context is NULL, then return FALSE.\r
969 If HashValue is NULL, then return FALSE.\r
970\r
971 @param[in, out] Sm3Context Pointer to the SM3 context.\r
972 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
973 value (32 bytes).\r
974\r
975 @retval TRUE SM3 digest computation succeeded.\r
976 @retval FALSE SM3 digest computation failed.\r
977\r
978**/\r
979BOOLEAN\r
980EFIAPI\r
981Sm3Final (\r
982 IN OUT VOID *Sm3Context,\r
983 OUT UINT8 *HashValue\r
984 )\r
985{\r
986 CALL_CRYPTO_SERVICE (Sm3Final, (Sm3Context, HashValue), FALSE);\r
987}\r
988\r
989/**\r
990 Computes the SM3 message digest of a input data buffer.\r
991\r
992 This function performs the SM3 message digest of a given data buffer, and places\r
993 the digest value into the specified memory.\r
994\r
995 If this interface is not supported, then return FALSE.\r
996\r
997 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
998 @param[in] DataSize Size of Data buffer in bytes.\r
999 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
1000 value (32 bytes).\r
1001\r
1002 @retval TRUE SM3 digest computation succeeded.\r
1003 @retval FALSE SM3 digest computation failed.\r
1004 @retval FALSE This interface is not supported.\r
1005\r
1006**/\r
1007BOOLEAN\r
1008EFIAPI\r
1009Sm3HashAll (\r
1010 IN CONST VOID *Data,\r
1011 IN UINTN DataSize,\r
1012 OUT UINT8 *HashValue\r
1013 )\r
1014{\r
1015 CALL_CRYPTO_SERVICE (Sm3HashAll, (Data, DataSize, HashValue), FALSE);\r
1016}\r
1017\r
1018//=====================================================================================\r
1019// MAC (Message Authentication Code) Primitive\r
1020//=====================================================================================\r
1021\r
cd70de1c
MK
1022/**\r
1023 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.\r
1024\r
1025 @return Pointer to the HMAC_CTX context that has been initialized.\r
1026 If the allocations fails, HmacSha256New() returns NULL.\r
1027\r
1028**/\r
1029VOID *\r
1030EFIAPI\r
1031HmacSha256New (\r
1032 VOID\r
1033 )\r
1034{\r
1035 CALL_CRYPTO_SERVICE (HmacSha256New, (), NULL);\r
1036}\r
1037\r
1038/**\r
1039 Release the specified HMAC_CTX context.\r
1040\r
1041 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.\r
1042\r
1043**/\r
1044VOID\r
1045EFIAPI\r
1046HmacSha256Free (\r
1047 IN VOID *HmacSha256Ctx\r
1048 )\r
1049{\r
1050 CALL_VOID_CRYPTO_SERVICE (HmacSha256Free, (HmacSha256Ctx));\r
1051}\r
1052\r
1053/**\r
1054 Set user-supplied key for subsequent use. It must be done before any\r
1055 calling to HmacSha256Update().\r
1056\r
1057 If HmacSha256Context is NULL, then return FALSE.\r
1058 If this interface is not supported, then return FALSE.\r
1059\r
1060 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.\r
1061 @param[in] Key Pointer to the user-supplied key.\r
1062 @param[in] KeySize Key size in bytes.\r
1063\r
1064 @retval TRUE The Key is set successfully.\r
1065 @retval FALSE The Key is set unsuccessfully.\r
1066 @retval FALSE This interface is not supported.\r
1067\r
1068**/\r
1069BOOLEAN\r
1070EFIAPI\r
1071HmacSha256SetKey (\r
1072 OUT VOID *HmacSha256Context,\r
1073 IN CONST UINT8 *Key,\r
1074 IN UINTN KeySize\r
1075 )\r
1076{\r
1077 CALL_CRYPTO_SERVICE (HmacSha256SetKey, (HmacSha256Context, Key, KeySize), FALSE);\r
1078}\r
1079\r
1080/**\r
1081 Makes a copy of an existing HMAC-SHA256 context.\r
1082\r
1083 If HmacSha256Context is NULL, then return FALSE.\r
1084 If NewHmacSha256Context is NULL, then return FALSE.\r
1085 If this interface is not supported, then return FALSE.\r
1086\r
1087 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.\r
1088 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.\r
1089\r
1090 @retval TRUE HMAC-SHA256 context copy succeeded.\r
1091 @retval FALSE HMAC-SHA256 context copy failed.\r
1092 @retval FALSE This interface is not supported.\r
1093\r
1094**/\r
1095BOOLEAN\r
1096EFIAPI\r
1097HmacSha256Duplicate (\r
1098 IN CONST VOID *HmacSha256Context,\r
1099 OUT VOID *NewHmacSha256Context\r
1100 )\r
1101{\r
1102 CALL_CRYPTO_SERVICE (HmacSha256Duplicate, (HmacSha256Context, NewHmacSha256Context), FALSE);\r
1103}\r
1104\r
1105/**\r
1106 Digests the input data and updates HMAC-SHA256 context.\r
1107\r
1108 This function performs HMAC-SHA256 digest on a data buffer of the specified size.\r
1109 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1110 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1111 by HmacSha256Final(). Behavior with invalid context is undefined.\r
1112\r
1113 If HmacSha256Context is NULL, then return FALSE.\r
1114 If this interface is not supported, then return FALSE.\r
1115\r
1116 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
1117 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1118 @param[in] DataSize Size of Data buffer in bytes.\r
1119\r
1120 @retval TRUE HMAC-SHA256 data digest succeeded.\r
1121 @retval FALSE HMAC-SHA256 data digest failed.\r
1122 @retval FALSE This interface is not supported.\r
1123\r
1124**/\r
1125BOOLEAN\r
1126EFIAPI\r
1127HmacSha256Update (\r
1128 IN OUT VOID *HmacSha256Context,\r
1129 IN CONST VOID *Data,\r
1130 IN UINTN DataSize\r
1131 )\r
1132{\r
1133 CALL_CRYPTO_SERVICE (HmacSha256Update, (HmacSha256Context, Data, DataSize), FALSE);\r
1134}\r
1135\r
1136/**\r
1137 Completes computation of the HMAC-SHA256 digest value.\r
1138\r
1139 This function completes HMAC-SHA256 hash computation and retrieves the digest value into\r
1140 the specified memory. After this function has been called, the HMAC-SHA256 context cannot\r
1141 be used again.\r
1142 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1143 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.\r
1144\r
1145 If HmacSha256Context is NULL, then return FALSE.\r
1146 If HmacValue is NULL, then return FALSE.\r
1147 If this interface is not supported, then return FALSE.\r
1148\r
1149 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
1150 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
1151 value (32 bytes).\r
1152\r
1153 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1154 @retval FALSE HMAC-SHA256 digest computation failed.\r
1155 @retval FALSE This interface is not supported.\r
1156\r
1157**/\r
1158BOOLEAN\r
1159EFIAPI\r
1160HmacSha256Final (\r
1161 IN OUT VOID *HmacSha256Context,\r
1162 OUT UINT8 *HmacValue\r
1163 )\r
1164{\r
1165 CALL_CRYPTO_SERVICE (HmacSha256Final, (HmacSha256Context, HmacValue), FALSE);\r
1166}\r
1167\r
1168//=====================================================================================\r
1169// Symmetric Cryptography Primitive\r
1170//=====================================================================================\r
1171\r
cd70de1c
MK
1172/**\r
1173 Retrieves the size, in bytes, of the context buffer required for AES operations.\r
1174\r
1175 If this interface is not supported, then return zero.\r
1176\r
1177 @return The size, in bytes, of the context buffer required for AES operations.\r
1178 @retval 0 This interface is not supported.\r
1179\r
1180**/\r
1181UINTN\r
1182EFIAPI\r
1183AesGetContextSize (\r
1184 VOID\r
1185 )\r
1186{\r
1187 CALL_CRYPTO_SERVICE (AesGetContextSize, (), 0);\r
1188}\r
1189\r
1190/**\r
1191 Initializes user-supplied memory as AES context for subsequent use.\r
1192\r
1193 This function initializes user-supplied memory pointed by AesContext as AES context.\r
1194 In addition, it sets up all AES key materials for subsequent encryption and decryption\r
1195 operations.\r
1196 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r
1197\r
1198 If AesContext is NULL, then return FALSE.\r
1199 If Key is NULL, then return FALSE.\r
1200 If KeyLength is not valid, then return FALSE.\r
1201 If this interface is not supported, then return FALSE.\r
1202\r
1203 @param[out] AesContext Pointer to AES context being initialized.\r
1204 @param[in] Key Pointer to the user-supplied AES key.\r
1205 @param[in] KeyLength Length of AES key in bits.\r
1206\r
1207 @retval TRUE AES context initialization succeeded.\r
1208 @retval FALSE AES context initialization failed.\r
1209 @retval FALSE This interface is not supported.\r
1210\r
1211**/\r
1212BOOLEAN\r
1213EFIAPI\r
1214AesInit (\r
1215 OUT VOID *AesContext,\r
1216 IN CONST UINT8 *Key,\r
1217 IN UINTN KeyLength\r
1218 )\r
1219{\r
1220 CALL_CRYPTO_SERVICE (AesInit, (AesContext, Key, KeyLength), FALSE);\r
1221}\r
1222\r
cd70de1c
MK
1223/**\r
1224 Performs AES encryption on a data buffer of the specified size in CBC mode.\r
1225\r
1226 This function performs AES encryption on data buffer pointed by Input, of specified\r
1227 size of InputSize, in CBC mode.\r
1228 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1229 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1230 Initialization vector should be one block size (16 bytes).\r
1231 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1232 invalid AES context is undefined.\r
1233\r
1234 If AesContext is NULL, then return FALSE.\r
1235 If Input is NULL, then return FALSE.\r
1236 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1237 If Ivec is NULL, then return FALSE.\r
1238 If Output is NULL, then return FALSE.\r
1239 If this interface is not supported, then return FALSE.\r
1240\r
1241 @param[in] AesContext Pointer to the AES context.\r
1242 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1243 @param[in] InputSize Size of the Input buffer in bytes.\r
1244 @param[in] Ivec Pointer to initialization vector.\r
1245 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1246\r
1247 @retval TRUE AES encryption succeeded.\r
1248 @retval FALSE AES encryption failed.\r
1249 @retval FALSE This interface is not supported.\r
1250\r
1251**/\r
1252BOOLEAN\r
1253EFIAPI\r
1254AesCbcEncrypt (\r
1255 IN VOID *AesContext,\r
1256 IN CONST UINT8 *Input,\r
1257 IN UINTN InputSize,\r
1258 IN CONST UINT8 *Ivec,\r
1259 OUT UINT8 *Output\r
1260 )\r
1261{\r
1262 CALL_CRYPTO_SERVICE (AesCbcEncrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);\r
1263}\r
1264\r
1265/**\r
1266 Performs AES decryption on a data buffer of the specified size in CBC mode.\r
1267\r
1268 This function performs AES decryption on data buffer pointed by Input, of specified\r
1269 size of InputSize, in CBC mode.\r
1270 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1271 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1272 Initialization vector should be one block size (16 bytes).\r
1273 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1274 invalid AES context is undefined.\r
1275\r
1276 If AesContext is NULL, then return FALSE.\r
1277 If Input is NULL, then return FALSE.\r
1278 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1279 If Ivec is NULL, then return FALSE.\r
1280 If Output is NULL, then return FALSE.\r
1281 If this interface is not supported, then return FALSE.\r
1282\r
1283 @param[in] AesContext Pointer to the AES context.\r
1284 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1285 @param[in] InputSize Size of the Input buffer in bytes.\r
1286 @param[in] Ivec Pointer to initialization vector.\r
1287 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1288\r
1289 @retval TRUE AES decryption succeeded.\r
1290 @retval FALSE AES decryption failed.\r
1291 @retval FALSE This interface is not supported.\r
1292\r
1293**/\r
1294BOOLEAN\r
1295EFIAPI\r
1296AesCbcDecrypt (\r
1297 IN VOID *AesContext,\r
1298 IN CONST UINT8 *Input,\r
1299 IN UINTN InputSize,\r
1300 IN CONST UINT8 *Ivec,\r
1301 OUT UINT8 *Output\r
1302 )\r
1303{\r
1304 CALL_CRYPTO_SERVICE (AesCbcDecrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);\r
1305}\r
1306\r
cd70de1c
MK
1307//=====================================================================================\r
1308// Asymmetric Cryptography Primitive\r
1309//=====================================================================================\r
1310\r
1311/**\r
1312 Allocates and initializes one RSA context for subsequent use.\r
1313\r
1314 @return Pointer to the RSA context that has been initialized.\r
1315 If the allocations fails, RsaNew() returns NULL.\r
1316\r
1317**/\r
1318VOID *\r
1319EFIAPI\r
1320RsaNew (\r
1321 VOID\r
1322 )\r
1323{\r
1324 CALL_CRYPTO_SERVICE (RsaNew, (), NULL);\r
1325}\r
1326\r
1327/**\r
1328 Release the specified RSA context.\r
1329\r
1330 If RsaContext is NULL, then return FALSE.\r
1331\r
1332 @param[in] RsaContext Pointer to the RSA context to be released.\r
1333\r
1334**/\r
1335VOID\r
1336EFIAPI\r
1337RsaFree (\r
1338 IN VOID *RsaContext\r
1339 )\r
1340{\r
1341 CALL_VOID_CRYPTO_SERVICE (RsaFree, (RsaContext));\r
1342}\r
1343\r
1344/**\r
1345 Sets the tag-designated key component into the established RSA context.\r
1346\r
1347 This function sets the tag-designated RSA key component into the established\r
1348 RSA context from the user-specified non-negative integer (octet string format\r
1349 represented in RSA PKCS#1).\r
1350 If BigNumber is NULL, then the specified key component in RSA context is cleared.\r
1351\r
1352 If RsaContext is NULL, then return FALSE.\r
1353\r
1354 @param[in, out] RsaContext Pointer to RSA context being set.\r
1355 @param[in] KeyTag Tag of RSA key component being set.\r
1356 @param[in] BigNumber Pointer to octet integer buffer.\r
1357 If NULL, then the specified key component in RSA\r
1358 context is cleared.\r
1359 @param[in] BnSize Size of big number buffer in bytes.\r
1360 If BigNumber is NULL, then it is ignored.\r
1361\r
1362 @retval TRUE RSA key component was set successfully.\r
1363 @retval FALSE Invalid RSA key component tag.\r
1364\r
1365**/\r
1366BOOLEAN\r
1367EFIAPI\r
1368RsaSetKey (\r
1369 IN OUT VOID *RsaContext,\r
1370 IN RSA_KEY_TAG KeyTag,\r
1371 IN CONST UINT8 *BigNumber,\r
1372 IN UINTN BnSize\r
1373 )\r
1374{\r
1375 CALL_CRYPTO_SERVICE (RsaSetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);\r
1376}\r
1377\r
1378/**\r
1379 Gets the tag-designated RSA key component from the established RSA context.\r
1380\r
1381 This function retrieves the tag-designated RSA key component from the\r
1382 established RSA context as a non-negative integer (octet string format\r
1383 represented in RSA PKCS#1).\r
1384 If specified key component has not been set or has been cleared, then returned\r
1385 BnSize is set to 0.\r
1386 If the BigNumber buffer is too small to hold the contents of the key, FALSE\r
1387 is returned and BnSize is set to the required buffer size to obtain the key.\r
1388\r
1389 If RsaContext is NULL, then return FALSE.\r
1390 If BnSize is NULL, then return FALSE.\r
1391 If BnSize is large enough but BigNumber is NULL, then return FALSE.\r
1392 If this interface is not supported, then return FALSE.\r
1393\r
1394 @param[in, out] RsaContext Pointer to RSA context being set.\r
1395 @param[in] KeyTag Tag of RSA key component being set.\r
1396 @param[out] BigNumber Pointer to octet integer buffer.\r
1397 @param[in, out] BnSize On input, the size of big number buffer in bytes.\r
1398 On output, the size of data returned in big number buffer in bytes.\r
1399\r
1400 @retval TRUE RSA key component was retrieved successfully.\r
1401 @retval FALSE Invalid RSA key component tag.\r
1402 @retval FALSE BnSize is too small.\r
1403 @retval FALSE This interface is not supported.\r
1404\r
1405**/\r
1406BOOLEAN\r
1407EFIAPI\r
1408RsaGetKey (\r
1409 IN OUT VOID *RsaContext,\r
1410 IN RSA_KEY_TAG KeyTag,\r
1411 OUT UINT8 *BigNumber,\r
1412 IN OUT UINTN *BnSize\r
1413 )\r
1414{\r
1415 CALL_CRYPTO_SERVICE (RsaGetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);\r
1416}\r
1417\r
1418/**\r
1419 Generates RSA key components.\r
1420\r
1421 This function generates RSA key components. It takes RSA public exponent E and\r
1422 length in bits of RSA modulus N as input, and generates all key components.\r
1423 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r
1424\r
1425 Before this function can be invoked, pseudorandom number generator must be correctly\r
1426 initialized by RandomSeed().\r
1427\r
1428 If RsaContext is NULL, then return FALSE.\r
1429 If this interface is not supported, then return FALSE.\r
1430\r
1431 @param[in, out] RsaContext Pointer to RSA context being set.\r
1432 @param[in] ModulusLength Length of RSA modulus N in bits.\r
1433 @param[in] PublicExponent Pointer to RSA public exponent.\r
1434 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r
1435\r
1436 @retval TRUE RSA key component was generated successfully.\r
1437 @retval FALSE Invalid RSA key component tag.\r
1438 @retval FALSE This interface is not supported.\r
1439\r
1440**/\r
1441BOOLEAN\r
1442EFIAPI\r
1443RsaGenerateKey (\r
1444 IN OUT VOID *RsaContext,\r
1445 IN UINTN ModulusLength,\r
1446 IN CONST UINT8 *PublicExponent,\r
1447 IN UINTN PublicExponentSize\r
1448 )\r
1449{\r
1450 CALL_CRYPTO_SERVICE (RsaGenerateKey, (RsaContext, ModulusLength, PublicExponent, PublicExponentSize), FALSE);\r
1451}\r
1452\r
1453/**\r
1454 Validates key components of RSA context.\r
1455 NOTE: This function performs integrity checks on all the RSA key material, so\r
1456 the RSA key structure must contain all the private key data.\r
1457\r
1458 This function validates key components of RSA context in following aspects:\r
1459 - Whether p is a prime\r
1460 - Whether q is a prime\r
1461 - Whether n = p * q\r
1462 - Whether d*e = 1 mod lcm(p-1,q-1)\r
1463\r
1464 If RsaContext is NULL, then return FALSE.\r
1465 If this interface is not supported, then return FALSE.\r
1466\r
1467 @param[in] RsaContext Pointer to RSA context to check.\r
1468\r
1469 @retval TRUE RSA key components are valid.\r
1470 @retval FALSE RSA key components are not valid.\r
1471 @retval FALSE This interface is not supported.\r
1472\r
1473**/\r
1474BOOLEAN\r
1475EFIAPI\r
1476RsaCheckKey (\r
1477 IN VOID *RsaContext\r
1478 )\r
1479{\r
1480 CALL_CRYPTO_SERVICE (RsaCheckKey, (RsaContext), FALSE);\r
1481}\r
1482\r
1483/**\r
1484 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r
1485\r
1486 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1487 RSA PKCS#1.\r
1488 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1489 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1490\r
1491 If RsaContext is NULL, then return FALSE.\r
1492 If MessageHash is NULL, then return FALSE.\r
1493 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r
1494 If SigSize is large enough but Signature is NULL, then return FALSE.\r
1495 If this interface is not supported, then return FALSE.\r
1496\r
1497 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1498 @param[in] MessageHash Pointer to octet message hash to be signed.\r
1499 @param[in] HashSize Size of the message hash in bytes.\r
1500 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
1501 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
1502 On output, the size of data returned in Signature buffer in bytes.\r
1503\r
1504 @retval TRUE Signature successfully generated in PKCS1-v1_5.\r
1505 @retval FALSE Signature generation failed.\r
1506 @retval FALSE SigSize is too small.\r
1507 @retval FALSE This interface is not supported.\r
1508\r
1509**/\r
1510BOOLEAN\r
1511EFIAPI\r
1512RsaPkcs1Sign (\r
1513 IN VOID *RsaContext,\r
1514 IN CONST UINT8 *MessageHash,\r
1515 IN UINTN HashSize,\r
1516 OUT UINT8 *Signature,\r
1517 IN OUT UINTN *SigSize\r
1518 )\r
1519{\r
1520 CALL_CRYPTO_SERVICE (RsaPkcs1Sign, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);\r
1521}\r
1522\r
1523/**\r
1524 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1525 RSA PKCS#1.\r
1526\r
1527 If RsaContext is NULL, then return FALSE.\r
1528 If MessageHash is NULL, then return FALSE.\r
1529 If Signature is NULL, then return FALSE.\r
1530 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r
1531\r
1532 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1533 @param[in] MessageHash Pointer to octet message hash to be checked.\r
1534 @param[in] HashSize Size of the message hash in bytes.\r
1535 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r
1536 @param[in] SigSize Size of signature in bytes.\r
1537\r
1538 @retval TRUE Valid signature encoded in PKCS1-v1_5.\r
1539 @retval FALSE Invalid signature or invalid RSA context.\r
1540\r
1541**/\r
1542BOOLEAN\r
1543EFIAPI\r
1544RsaPkcs1Verify (\r
1545 IN VOID *RsaContext,\r
1546 IN CONST UINT8 *MessageHash,\r
1547 IN UINTN HashSize,\r
1548 IN CONST UINT8 *Signature,\r
1549 IN UINTN SigSize\r
1550 )\r
1551{\r
1552 CALL_CRYPTO_SERVICE (RsaPkcs1Verify, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);\r
1553}\r
1554\r
22ac5cc9
SA
1555/**\r
1556 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.\r
1557 Implementation determines salt length automatically from the signature encoding.\r
1558 Mask generation function is the same as the message digest algorithm.\r
20ca5288 1559 Salt length should be equal to digest length.\r
22ac5cc9
SA
1560\r
1561 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1562 @param[in] Message Pointer to octet message to be verified.\r
1563 @param[in] MsgSize Size of the message in bytes.\r
1564 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.\r
1565 @param[in] SigSize Size of signature in bytes.\r
1566 @param[in] DigestLen Length of digest for RSA operation.\r
1567 @param[in] SaltLen Salt length for PSS encoding.\r
1568\r
1569 @retval TRUE Valid signature encoded in RSASSA-PSS.\r
1570 @retval FALSE Invalid signature or invalid RSA context.\r
1571\r
1572**/\r
1573BOOLEAN\r
1574EFIAPI\r
1575RsaPssVerify (\r
1576 IN VOID *RsaContext,\r
1577 IN CONST UINT8 *Message,\r
1578 IN UINTN MsgSize,\r
1579 IN CONST UINT8 *Signature,\r
1580 IN UINTN SigSize,\r
1581 IN UINT16 DigestLen,\r
1582 IN UINT16 SaltLen\r
1583 )\r
1584{\r
1585 CALL_CRYPTO_SERVICE (RsaPssVerify, (RsaContext, Message, MsgSize, Signature, SigSize, DigestLen, SaltLen), FALSE);\r
1586}\r
1587\r
1588/**\r
1589 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in\r
1590 RFC 8017.\r
1591 Mask generation function is the same as the message digest algorithm.\r
1592 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1593 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1594\r
20ca5288
AS
1595 If RsaContext is NULL, then return FALSE.\r
1596 If Message is NULL, then return FALSE.\r
1597 If MsgSize is zero or > INT_MAX, then return FALSE.\r
1598 If DigestLen is NOT 32, 48 or 64, return FALSE.\r
1599 If SaltLen is not equal to DigestLen, then return FALSE.\r
1600 If SigSize is large enough but Signature is NULL, then return FALSE.\r
1601 If this interface is not supported, then return FALSE.\r
1602\r
22ac5cc9
SA
1603 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1604 @param[in] Message Pointer to octet message to be signed.\r
1605 @param[in] MsgSize Size of the message in bytes.\r
1606 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.\r
1607 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.\r
1608 @param[out] Signature Pointer to buffer to receive RSA PSS signature.\r
1609 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
1610 On output, the size of data returned in Signature buffer in bytes.\r
1611\r
1612 @retval TRUE Signature successfully generated in RSASSA-PSS.\r
1613 @retval FALSE Signature generation failed.\r
1614 @retval FALSE SigSize is too small.\r
1615 @retval FALSE This interface is not supported.\r
1616\r
1617**/\r
1618BOOLEAN\r
1619EFIAPI\r
1620RsaPssSign (\r
1621 IN VOID *RsaContext,\r
1622 IN CONST UINT8 *Message,\r
1623 IN UINTN MsgSize,\r
1624 IN UINT16 DigestLen,\r
1625 IN UINT16 SaltLen,\r
1626 OUT UINT8 *Signature,\r
1627 IN OUT UINTN *SigSize\r
1628 )\r
1629{\r
1630 CALL_CRYPTO_SERVICE (RsaPssSign, (RsaContext, Message, MsgSize, DigestLen, SaltLen, Signature, SigSize), FALSE);\r
1631}\r
1632\r
cd70de1c
MK
1633/**\r
1634 Retrieve the RSA Private Key from the password-protected PEM key data.\r
1635\r
1636 If PemData is NULL, then return FALSE.\r
1637 If RsaContext is NULL, then return FALSE.\r
1638 If this interface is not supported, then return FALSE.\r
1639\r
1640 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
1641 @param[in] PemSize Size of the PEM key data in bytes.\r
1642 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
1643 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1644 RSA private key component. Use RsaFree() function to free the\r
1645 resource.\r
1646\r
1647 @retval TRUE RSA Private Key was retrieved successfully.\r
1648 @retval FALSE Invalid PEM key data or incorrect password.\r
1649 @retval FALSE This interface is not supported.\r
1650\r
1651**/\r
1652BOOLEAN\r
1653EFIAPI\r
1654RsaGetPrivateKeyFromPem (\r
1655 IN CONST UINT8 *PemData,\r
1656 IN UINTN PemSize,\r
1657 IN CONST CHAR8 *Password,\r
1658 OUT VOID **RsaContext\r
1659 )\r
1660{\r
1661 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem, (PemData, PemSize, Password, RsaContext), FALSE);\r
1662}\r
1663\r
1664/**\r
1665 Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r
1666\r
1667 If Cert is NULL, then return FALSE.\r
1668 If RsaContext is NULL, then return FALSE.\r
1669 If this interface is not supported, then return FALSE.\r
1670\r
1671 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1672 @param[in] CertSize Size of the X509 certificate in bytes.\r
1673 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1674 RSA public key component. Use RsaFree() function to free the\r
1675 resource.\r
1676\r
1677 @retval TRUE RSA Public Key was retrieved successfully.\r
1678 @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r
1679 @retval FALSE This interface is not supported.\r
1680\r
1681**/\r
1682BOOLEAN\r
1683EFIAPI\r
1684RsaGetPublicKeyFromX509 (\r
1685 IN CONST UINT8 *Cert,\r
1686 IN UINTN CertSize,\r
1687 OUT VOID **RsaContext\r
1688 )\r
1689{\r
1690 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509, (Cert, CertSize, RsaContext), FALSE);\r
1691}\r
1692\r
1693/**\r
1694 Retrieve the subject bytes from one X.509 certificate.\r
1695\r
1696 If Cert is NULL, then return FALSE.\r
1697 If SubjectSize is NULL, then return FALSE.\r
1698 If this interface is not supported, then return FALSE.\r
1699\r
1700 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1701 @param[in] CertSize Size of the X509 certificate in bytes.\r
1702 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r
1703 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r
1704 and the size of buffer returned CertSubject on output.\r
1705\r
1706 @retval TRUE The certificate subject retrieved successfully.\r
1707 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r
1708 The SubjectSize will be updated with the required size.\r
1709 @retval FALSE This interface is not supported.\r
1710\r
1711**/\r
1712BOOLEAN\r
1713EFIAPI\r
1714X509GetSubjectName (\r
1715 IN CONST UINT8 *Cert,\r
1716 IN UINTN CertSize,\r
1717 OUT UINT8 *CertSubject,\r
1718 IN OUT UINTN *SubjectSize\r
1719 )\r
1720{\r
1721 CALL_CRYPTO_SERVICE (X509GetSubjectName, (Cert, CertSize, CertSubject, SubjectSize), FALSE);\r
1722}\r
1723\r
1724/**\r
1725 Retrieve the common name (CN) string from one X.509 certificate.\r
1726\r
1727 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1728 @param[in] CertSize Size of the X509 certificate in bytes.\r
1729 @param[out] CommonName Buffer to contain the retrieved certificate common\r
1730 name string (UTF8). At most CommonNameSize bytes will be\r
1731 written and the string will be null terminated. May be\r
1732 NULL in order to determine the size buffer needed.\r
1733 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
1734 and the size of buffer returned CommonName on output.\r
1735 If CommonName is NULL then the amount of space needed\r
1736 in buffer (including the final null) is returned.\r
1737\r
1738 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r
1739 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1740 If CommonNameSize is NULL.\r
1741 If CommonName is not NULL and *CommonNameSize is 0.\r
1742 If Certificate is invalid.\r
1743 @retval RETURN_NOT_FOUND If no CommonName entry exists.\r
1744 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r
1745 (including the final null) is returned in the\r
1746 CommonNameSize parameter.\r
1747 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1748\r
1749**/\r
1750RETURN_STATUS\r
1751EFIAPI\r
1752X509GetCommonName (\r
1753 IN CONST UINT8 *Cert,\r
1754 IN UINTN CertSize,\r
c8f46130 1755 OUT CHAR8 *CommonName OPTIONAL,\r
cd70de1c
MK
1756 IN OUT UINTN *CommonNameSize\r
1757 )\r
1758{\r
1759 CALL_CRYPTO_SERVICE (X509GetCommonName, (Cert, CertSize, CommonName, CommonNameSize), RETURN_UNSUPPORTED);\r
1760}\r
1761\r
1762/**\r
1763 Retrieve the organization name (O) string from one X.509 certificate.\r
1764\r
1765 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1766 @param[in] CertSize Size of the X509 certificate in bytes.\r
1767 @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r
1768 name string. At most NameBufferSize bytes will be\r
1769 written and the string will be null terminated. May be\r
1770 NULL in order to determine the size buffer needed.\r
1771 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r
1772 and the size of buffer returned Name on output.\r
1773 If NameBuffer is NULL then the amount of space needed\r
1774 in buffer (including the final null) is returned.\r
1775\r
1776 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r
1777 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1778 If NameBufferSize is NULL.\r
1779 If NameBuffer is not NULL and *CommonNameSize is 0.\r
1780 If Certificate is invalid.\r
1781 @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r
1782 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r
1783 (including the final null) is returned in the\r
1784 CommonNameSize parameter.\r
1785 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1786\r
1787**/\r
1788RETURN_STATUS\r
1789EFIAPI\r
1790X509GetOrganizationName (\r
1791 IN CONST UINT8 *Cert,\r
1792 IN UINTN CertSize,\r
c8f46130 1793 OUT CHAR8 *NameBuffer OPTIONAL,\r
cd70de1c
MK
1794 IN OUT UINTN *NameBufferSize\r
1795 )\r
1796{\r
1797 CALL_CRYPTO_SERVICE (X509GetOrganizationName, (Cert, CertSize, NameBuffer, NameBufferSize), RETURN_UNSUPPORTED);\r
1798}\r
1799\r
1800/**\r
1801 Verify one X509 certificate was issued by the trusted CA.\r
1802\r
1803 If Cert is NULL, then return FALSE.\r
1804 If CACert is NULL, then return FALSE.\r
1805 If this interface is not supported, then return FALSE.\r
1806\r
1807 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r
1808 @param[in] CertSize Size of the X509 certificate in bytes.\r
1809 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r
1810 @param[in] CACertSize Size of the CA Certificate in bytes.\r
1811\r
1812 @retval TRUE The certificate was issued by the trusted CA.\r
1813 @retval FALSE Invalid certificate or the certificate was not issued by the given\r
1814 trusted CA.\r
1815 @retval FALSE This interface is not supported.\r
1816\r
1817**/\r
1818BOOLEAN\r
1819EFIAPI\r
1820X509VerifyCert (\r
1821 IN CONST UINT8 *Cert,\r
1822 IN UINTN CertSize,\r
1823 IN CONST UINT8 *CACert,\r
1824 IN UINTN CACertSize\r
1825 )\r
1826{\r
1827 CALL_CRYPTO_SERVICE (X509VerifyCert, (Cert, CertSize, CACert, CACertSize), FALSE);\r
1828}\r
1829\r
1830/**\r
1831 Construct a X509 object from DER-encoded certificate data.\r
1832\r
1833 If Cert is NULL, then return FALSE.\r
1834 If SingleX509Cert is NULL, then return FALSE.\r
1835 If this interface is not supported, then return FALSE.\r
1836\r
1837 @param[in] Cert Pointer to the DER-encoded certificate data.\r
1838 @param[in] CertSize The size of certificate data in bytes.\r
1839 @param[out] SingleX509Cert The generated X509 object.\r
1840\r
1841 @retval TRUE The X509 object generation succeeded.\r
1842 @retval FALSE The operation failed.\r
1843 @retval FALSE This interface is not supported.\r
1844\r
1845**/\r
1846BOOLEAN\r
1847EFIAPI\r
1848X509ConstructCertificate (\r
1849 IN CONST UINT8 *Cert,\r
1850 IN UINTN CertSize,\r
1851 OUT UINT8 **SingleX509Cert\r
1852 )\r
1853{\r
1854 CALL_CRYPTO_SERVICE (X509ConstructCertificate, (Cert, CertSize, SingleX509Cert), FALSE);\r
1855}\r
1856\r
1857/**\r
1858 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1859\r
1860 If X509Stack is NULL, then return FALSE.\r
1861 If this interface is not supported, then return FALSE.\r
1862\r
1863 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
1864 On output, pointer to the X509 stack object with new\r
1865 inserted X509 certificate.\r
1866 @param[in] Args VA_LIST marker for the variable argument list.\r
1867 ... A list of DER-encoded single certificate data followed\r
1868 by certificate size. A NULL terminates the list. The\r
1869 pairs are the arguments to X509ConstructCertificate().\r
1870\r
1871 @retval TRUE The X509 stack construction succeeded.\r
1872 @retval FALSE The construction operation failed.\r
1873 @retval FALSE This interface is not supported.\r
1874\r
1875**/\r
1876BOOLEAN\r
1877EFIAPI\r
1878X509ConstructCertificateStack (\r
1879 IN OUT UINT8 **X509Stack,\r
1880 ...\r
1881 )\r
1882{\r
1883 VA_LIST Args;\r
1884 BOOLEAN Result;\r
1885\r
1886 VA_START (Args, X509Stack);\r
1887 Result = X509ConstructCertificateStackV (X509Stack, Args);\r
1888 VA_END (Args);\r
1889 return Result;\r
1890}\r
1891\r
1892/**\r
1893 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1894\r
1895 If X509Stack is NULL, then return FALSE.\r
1896 If this interface is not supported, then return FALSE.\r
1897\r
1898 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
1899 On output, pointer to the X509 stack object with new\r
1900 inserted X509 certificate.\r
1901 @param[in] Args VA_LIST marker for the variable argument list.\r
1902 A list of DER-encoded single certificate data followed\r
1903 by certificate size. A NULL terminates the list. The\r
1904 pairs are the arguments to X509ConstructCertificate().\r
1905\r
1906 @retval TRUE The X509 stack construction succeeded.\r
1907 @retval FALSE The construction operation failed.\r
1908 @retval FALSE This interface is not supported.\r
1909\r
1910**/\r
1911BOOLEAN\r
1912EFIAPI\r
1913X509ConstructCertificateStackV (\r
1914 IN OUT UINT8 **X509Stack,\r
1915 IN VA_LIST Args\r
1916 )\r
1917{\r
1918 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV, (X509Stack, Args), FALSE);\r
1919}\r
1920\r
1921/**\r
1922 Release the specified X509 object.\r
1923\r
1924 If the interface is not supported, then ASSERT().\r
1925\r
1926 @param[in] X509Cert Pointer to the X509 object to be released.\r
1927\r
1928**/\r
1929VOID\r
1930EFIAPI\r
1931X509Free (\r
1932 IN VOID *X509Cert\r
1933 )\r
1934{\r
1935 CALL_VOID_CRYPTO_SERVICE (X509Free, (X509Cert));\r
1936}\r
1937\r
1938/**\r
1939 Release the specified X509 stack object.\r
1940\r
1941 If the interface is not supported, then ASSERT().\r
1942\r
1943 @param[in] X509Stack Pointer to the X509 stack object to be released.\r
1944\r
1945**/\r
1946VOID\r
1947EFIAPI\r
1948X509StackFree (\r
1949 IN VOID *X509Stack\r
1950 )\r
1951{\r
1952 CALL_VOID_CRYPTO_SERVICE (X509StackFree, (X509Stack));\r
1953}\r
1954\r
1955/**\r
1956 Retrieve the TBSCertificate from one given X.509 certificate.\r
1957\r
1958 @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r
1959 @param[in] CertSize Size of the X509 certificate in bytes.\r
1960 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r
1961 @param[out] TBSCertSize Size of the TBS certificate in bytes.\r
1962\r
1963 If Cert is NULL, then return FALSE.\r
1964 If TBSCert is NULL, then return FALSE.\r
1965 If TBSCertSize is NULL, then return FALSE.\r
1966 If this interface is not supported, then return FALSE.\r
1967\r
1968 @retval TRUE The TBSCertificate was retrieved successfully.\r
1969 @retval FALSE Invalid X.509 certificate.\r
1970\r
1971**/\r
1972BOOLEAN\r
1973EFIAPI\r
1974X509GetTBSCert (\r
1975 IN CONST UINT8 *Cert,\r
1976 IN UINTN CertSize,\r
1977 OUT UINT8 **TBSCert,\r
1978 OUT UINTN *TBSCertSize\r
1979 )\r
1980{\r
1981 CALL_CRYPTO_SERVICE (X509GetTBSCert, (Cert, CertSize, TBSCert, TBSCertSize), FALSE);\r
1982}\r
1983\r
1984/**\r
1985 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r
1986 password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r
1987\r
1988 If Password or Salt or OutKey is NULL, then return FALSE.\r
1989 If the hash algorithm could not be determined, then return FALSE.\r
1990 If this interface is not supported, then return FALSE.\r
1991\r
1992 @param[in] PasswordLength Length of input password in bytes.\r
1993 @param[in] Password Pointer to the array for the password.\r
1994 @param[in] SaltLength Size of the Salt in bytes.\r
1995 @param[in] Salt Pointer to the Salt.\r
1996 @param[in] IterationCount Number of iterations to perform. Its value should be\r
1997 greater than or equal to 1.\r
1998 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r
1999 NOTE: DigestSize will be used to determine the hash algorithm.\r
2000 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r
2001 @param[in] KeyLength Size of the derived key buffer in bytes.\r
2002 @param[out] OutKey Pointer to the output derived key buffer.\r
2003\r
2004 @retval TRUE A key was derived successfully.\r
2005 @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r
2006 @retval FALSE The hash algorithm could not be determined from the digest size.\r
2007 @retval FALSE The key derivation operation failed.\r
2008 @retval FALSE This interface is not supported.\r
2009\r
2010**/\r
2011BOOLEAN\r
2012EFIAPI\r
2013Pkcs5HashPassword (\r
2014 IN UINTN PasswordLength,\r
2015 IN CONST CHAR8 *Password,\r
2016 IN UINTN SaltLength,\r
2017 IN CONST UINT8 *Salt,\r
2018 IN UINTN IterationCount,\r
2019 IN UINTN DigestSize,\r
2020 IN UINTN KeyLength,\r
2021 OUT UINT8 *OutKey\r
2022 )\r
2023{\r
2024 CALL_CRYPTO_SERVICE (Pkcs5HashPassword, (PasswordLength, Password, SaltLength, Salt, IterationCount, DigestSize, KeyLength, OutKey), FALSE);\r
2025}\r
2026\r
2027/**\r
2028 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r
2029 encrypted message in a newly allocated buffer.\r
2030\r
2031 Things that can cause a failure include:\r
2032 - X509 key size does not match any known key size.\r
2033 - Fail to parse X509 certificate.\r
2034 - Fail to allocate an intermediate buffer.\r
2035 - Null pointer provided for a non-optional parameter.\r
2036 - Data size is too large for the provided key size (max size is a function of key size\r
2037 and hash digest size).\r
2038\r
2039 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r
2040 will be used to encrypt the data.\r
2041 @param[in] PublicKeySize Size of the X509 cert buffer.\r
2042 @param[in] InData Data to be encrypted.\r
2043 @param[in] InDataSize Size of the data buffer.\r
2044 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r
2045 to be used when initializing the PRNG. NULL otherwise.\r
2046 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r
2047 0 otherwise.\r
2048 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r
2049 message.\r
2050 @param[out] EncryptedDataSize Size of the encrypted message buffer.\r
2051\r
2052 @retval TRUE Encryption was successful.\r
2053 @retval FALSE Encryption failed.\r
2054\r
2055**/\r
2056BOOLEAN\r
2057EFIAPI\r
2058Pkcs1v2Encrypt (\r
2059 IN CONST UINT8 *PublicKey,\r
2060 IN UINTN PublicKeySize,\r
2061 IN UINT8 *InData,\r
2062 IN UINTN InDataSize,\r
c8f46130
MK
2063 IN CONST UINT8 *PrngSeed OPTIONAL,\r
2064 IN UINTN PrngSeedSize OPTIONAL,\r
cd70de1c
MK
2065 OUT UINT8 **EncryptedData,\r
2066 OUT UINTN *EncryptedDataSize\r
2067 )\r
2068{\r
2069 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);\r
2070}\r
2071\r
2072/**\r
2073 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r
2074 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2075 in a ContentInfo structure.\r
2076\r
2077 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r
2078 return FALSE. If P7Length overflow, then return FALSE.\r
2079 If this interface is not supported, then return FALSE.\r
2080\r
2081 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
2082 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2083 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r
2084 It's caller's responsibility to free the buffer with\r
2085 Pkcs7FreeSigners().\r
2086 This data structure is EFI_CERT_STACK type.\r
2087 @param[out] StackLength Length of signer's certificates in bytes.\r
2088 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r
2089 It's caller's responsibility to free the buffer with\r
2090 Pkcs7FreeSigners().\r
2091 @param[out] CertLength Length of the trusted certificate in bytes.\r
2092\r
2093 @retval TRUE The operation is finished successfully.\r
2094 @retval FALSE Error occurs during the operation.\r
2095 @retval FALSE This interface is not supported.\r
2096\r
2097**/\r
2098BOOLEAN\r
2099EFIAPI\r
2100Pkcs7GetSigners (\r
2101 IN CONST UINT8 *P7Data,\r
2102 IN UINTN P7Length,\r
2103 OUT UINT8 **CertStack,\r
2104 OUT UINTN *StackLength,\r
2105 OUT UINT8 **TrustedCert,\r
2106 OUT UINTN *CertLength\r
2107 )\r
2108{\r
2109 CALL_CRYPTO_SERVICE (Pkcs7GetSigners, (P7Data, P7Length, CertStack, StackLength, TrustedCert, CertLength), FALSE);\r
2110}\r
2111\r
2112/**\r
2113 Wrap function to use free() to free allocated memory for certificates.\r
2114\r
2115 If this interface is not supported, then ASSERT().\r
2116\r
2117 @param[in] Certs Pointer to the certificates to be freed.\r
2118\r
2119**/\r
2120VOID\r
2121EFIAPI\r
2122Pkcs7FreeSigners (\r
2123 IN UINT8 *Certs\r
2124 )\r
2125{\r
2126 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners, (Certs));\r
2127}\r
2128\r
2129/**\r
2130 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r
2131 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r
2132 unchained to the signer's certificates.\r
2133 The input signed data could be wrapped in a ContentInfo structure.\r
2134\r
2135 @param[in] P7Data Pointer to the PKCS#7 message.\r
2136 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2137 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r
2138 certificate. It's caller's responsibility to free the buffer\r
2139 with Pkcs7FreeSigners().\r
2140 This data structure is EFI_CERT_STACK type.\r
2141 @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r
2142 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r
2143 responsibility to free the buffer with Pkcs7FreeSigners().\r
2144 This data structure is EFI_CERT_STACK type.\r
2145 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r
2146\r
2147 @retval TRUE The operation is finished successfully.\r
2148 @retval FALSE Error occurs during the operation.\r
2149\r
2150**/\r
2151BOOLEAN\r
2152EFIAPI\r
2153Pkcs7GetCertificatesList (\r
2154 IN CONST UINT8 *P7Data,\r
2155 IN UINTN P7Length,\r
2156 OUT UINT8 **SignerChainCerts,\r
2157 OUT UINTN *ChainLength,\r
2158 OUT UINT8 **UnchainCerts,\r
2159 OUT UINTN *UnchainLength\r
2160 )\r
2161{\r
2162 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList, (P7Data, P7Length, SignerChainCerts, ChainLength, UnchainCerts, UnchainLength), FALSE);\r
2163}\r
2164\r
2165/**\r
2166 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
2167 Syntax Standard, version 1.5". This interface is only intended to be used for\r
2168 application to perform PKCS#7 functionality validation.\r
2169\r
2170 If this interface is not supported, then return FALSE.\r
2171\r
2172 @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r
2173 data signing.\r
2174 @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r
2175 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r
2176 key data.\r
2177 @param[in] InData Pointer to the content to be signed.\r
2178 @param[in] InDataSize Size of InData in bytes.\r
2179 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r
2180 @param[in] OtherCerts Pointer to an optional additional set of certificates to\r
2181 include in the PKCS#7 signedData (e.g. any intermediate\r
2182 CAs in the chain).\r
2183 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r
2184 responsibility to free the buffer with FreePool().\r
2185 @param[out] SignedDataSize Size of SignedData in bytes.\r
2186\r
2187 @retval TRUE PKCS#7 data signing succeeded.\r
2188 @retval FALSE PKCS#7 data signing failed.\r
2189 @retval FALSE This interface is not supported.\r
2190\r
2191**/\r
2192BOOLEAN\r
2193EFIAPI\r
2194Pkcs7Sign (\r
2195 IN CONST UINT8 *PrivateKey,\r
2196 IN UINTN PrivateKeySize,\r
2197 IN CONST UINT8 *KeyPassword,\r
2198 IN UINT8 *InData,\r
2199 IN UINTN InDataSize,\r
2200 IN UINT8 *SignCert,\r
2201 IN UINT8 *OtherCerts OPTIONAL,\r
2202 OUT UINT8 **SignedData,\r
2203 OUT UINTN *SignedDataSize\r
2204 )\r
2205{\r
2206 CALL_CRYPTO_SERVICE (Pkcs7Sign, (PrivateKey, PrivateKeySize, KeyPassword, InData, InDataSize, SignCert, OtherCerts, SignedData, SignedDataSize), FALSE);\r
2207}\r
2208\r
2209/**\r
2210 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r
2211 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2212 in a ContentInfo structure.\r
2213\r
2214 If P7Data, TrustedCert or InData is NULL, then return FALSE.\r
2215 If P7Length, CertLength or DataLength overflow, then return FALSE.\r
2216 If this interface is not supported, then return FALSE.\r
2217\r
2218 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
2219 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2220 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2221 is used for certificate chain verification.\r
2222 @param[in] CertLength Length of the trusted certificate in bytes.\r
2223 @param[in] InData Pointer to the content to be verified.\r
2224 @param[in] DataLength Length of InData in bytes.\r
2225\r
2226 @retval TRUE The specified PKCS#7 signed data is valid.\r
2227 @retval FALSE Invalid PKCS#7 signed data.\r
2228 @retval FALSE This interface is not supported.\r
2229\r
2230**/\r
2231BOOLEAN\r
2232EFIAPI\r
2233Pkcs7Verify (\r
2234 IN CONST UINT8 *P7Data,\r
2235 IN UINTN P7Length,\r
2236 IN CONST UINT8 *TrustedCert,\r
2237 IN UINTN CertLength,\r
2238 IN CONST UINT8 *InData,\r
2239 IN UINTN DataLength\r
2240 )\r
2241{\r
2242 CALL_CRYPTO_SERVICE (Pkcs7Verify, (P7Data, P7Length, TrustedCert, CertLength, InData, DataLength), FALSE);\r
2243}\r
2244\r
2245/**\r
2246 This function receives a PKCS7 formatted signature, and then verifies that\r
2247 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r
2248 leaf signing certificate.\r
2249 Note that this function does not validate the certificate chain.\r
2250\r
2251 Applications for custom EKU's are quite flexible. For example, a policy EKU\r
2252 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r
2253 certificate issued might also contain this EKU, thus constraining the\r
2254 sub-ordinate certificate. Other applications might allow a certificate\r
2255 embedded in a device to specify that other Object Identifiers (OIDs) are\r
2256 present which contains binary data specifying custom capabilities that\r
2257 the device is able to do.\r
2258\r
2259 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r
2260 containing the content block with both the signature,\r
2261 the signer's certificate, and any necessary intermediate\r
2262 certificates.\r
2263 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r
2264 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r
2265 required EKUs that must be present in the signature.\r
2266 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r
2267 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r
2268 must be present in the leaf signer. If it is\r
2269 FALSE, then we will succeed if we find any\r
2270 of the specified EKU's.\r
2271\r
2272 @retval EFI_SUCCESS The required EKUs were found in the signature.\r
2273 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
2274 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r
2275\r
2276**/\r
2277RETURN_STATUS\r
2278EFIAPI\r
2279VerifyEKUsInPkcs7Signature (\r
2280 IN CONST UINT8 *Pkcs7Signature,\r
2281 IN CONST UINT32 SignatureSize,\r
2282 IN CONST CHAR8 *RequiredEKUs[],\r
2283 IN CONST UINT32 RequiredEKUsSize,\r
2284 IN BOOLEAN RequireAllPresent\r
2285 )\r
2286{\r
2287 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature, (Pkcs7Signature, SignatureSize, RequiredEKUs, RequiredEKUsSize, RequireAllPresent), FALSE);\r
2288}\r
2289\r
2290\r
2291/**\r
2292 Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r
2293 data could be wrapped in a ContentInfo structure.\r
2294\r
2295 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r
2296 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r
2297\r
2298 Caution: This function may receive untrusted input. So this function will do\r
2299 basic check for PKCS#7 data structure.\r
2300\r
2301 @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r
2302 @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r
2303 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r
2304 It's caller's responsibility to free the buffer with FreePool().\r
2305 @param[out] ContentSize The size of the extracted content in bytes.\r
2306\r
2307 @retval TRUE The P7Data was correctly formatted for processing.\r
2308 @retval FALSE The P7Data was not correctly formatted for processing.\r
2309\r
2310**/\r
2311BOOLEAN\r
2312EFIAPI\r
2313Pkcs7GetAttachedContent (\r
2314 IN CONST UINT8 *P7Data,\r
2315 IN UINTN P7Length,\r
2316 OUT VOID **Content,\r
2317 OUT UINTN *ContentSize\r
2318 )\r
2319{\r
2320 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent, (P7Data, P7Length, Content, ContentSize), FALSE);\r
2321}\r
2322\r
2323/**\r
2324 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r
2325 Authenticode Portable Executable Signature Format".\r
2326\r
2327 If AuthData is NULL, then return FALSE.\r
2328 If ImageHash is NULL, then return FALSE.\r
2329 If this interface is not supported, then return FALSE.\r
2330\r
2331 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2332 PE/COFF image to be verified.\r
2333 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2334 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2335 is used for certificate chain verification.\r
2336 @param[in] CertSize Size of the trusted certificate in bytes.\r
2337 @param[in] ImageHash Pointer to the original image file hash value. The procedure\r
2338 for calculating the image hash value is described in Authenticode\r
2339 specification.\r
2340 @param[in] HashSize Size of Image hash value in bytes.\r
2341\r
2342 @retval TRUE The specified Authenticode Signature is valid.\r
2343 @retval FALSE Invalid Authenticode Signature.\r
2344 @retval FALSE This interface is not supported.\r
2345\r
2346**/\r
2347BOOLEAN\r
2348EFIAPI\r
2349AuthenticodeVerify (\r
2350 IN CONST UINT8 *AuthData,\r
2351 IN UINTN DataSize,\r
2352 IN CONST UINT8 *TrustedCert,\r
2353 IN UINTN CertSize,\r
2354 IN CONST UINT8 *ImageHash,\r
2355 IN UINTN HashSize\r
2356 )\r
2357{\r
2358 CALL_CRYPTO_SERVICE (AuthenticodeVerify, (AuthData, DataSize, TrustedCert, CertSize, ImageHash, HashSize), FALSE);\r
2359}\r
2360\r
2361/**\r
2362 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r
2363 signature.\r
2364\r
2365 If AuthData is NULL, then return FALSE.\r
2366 If this interface is not supported, then return FALSE.\r
2367\r
2368 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2369 PE/COFF image to be verified.\r
2370 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2371 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r
2372 is used for TSA certificate chain verification.\r
2373 @param[in] CertSize Size of the trusted certificate in bytes.\r
2374 @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r
2375 signature is valid.\r
2376\r
2377 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r
2378 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r
2379\r
2380**/\r
2381BOOLEAN\r
2382EFIAPI\r
2383ImageTimestampVerify (\r
2384 IN CONST UINT8 *AuthData,\r
2385 IN UINTN DataSize,\r
2386 IN CONST UINT8 *TsaCert,\r
2387 IN UINTN CertSize,\r
2388 OUT EFI_TIME *SigningTime\r
2389 )\r
2390{\r
2391 CALL_CRYPTO_SERVICE (ImageTimestampVerify, (AuthData, DataSize, TsaCert, CertSize, SigningTime), FALSE);\r
2392}\r
2393\r
2394//=====================================================================================\r
2395// DH Key Exchange Primitive\r
2396//=====================================================================================\r
2397\r
2398/**\r
2399 Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r
2400\r
2401 @return Pointer to the Diffie-Hellman Context that has been initialized.\r
2402 If the allocations fails, DhNew() returns NULL.\r
2403 If the interface is not supported, DhNew() returns NULL.\r
2404\r
2405**/\r
2406VOID *\r
2407EFIAPI\r
2408DhNew (\r
2409 VOID\r
2410 )\r
2411{\r
2412 CALL_CRYPTO_SERVICE (DhNew, (), NULL);\r
2413}\r
2414\r
2415/**\r
2416 Release the specified DH context.\r
2417\r
2418 If the interface is not supported, then ASSERT().\r
2419\r
2420 @param[in] DhContext Pointer to the DH context to be released.\r
2421\r
2422**/\r
2423VOID\r
2424EFIAPI\r
2425DhFree (\r
2426 IN VOID *DhContext\r
2427 )\r
2428{\r
2429 CALL_VOID_CRYPTO_SERVICE (DhFree, (DhContext));\r
2430}\r
2431\r
2432/**\r
2433 Generates DH parameter.\r
2434\r
2435 Given generator g, and length of prime number p in bits, this function generates p,\r
2436 and sets DH context according to value of g and p.\r
2437\r
2438 Before this function can be invoked, pseudorandom number generator must be correctly\r
2439 initialized by RandomSeed().\r
2440\r
2441 If DhContext is NULL, then return FALSE.\r
2442 If Prime is NULL, then return FALSE.\r
2443 If this interface is not supported, then return FALSE.\r
2444\r
2445 @param[in, out] DhContext Pointer to the DH context.\r
2446 @param[in] Generator Value of generator.\r
2447 @param[in] PrimeLength Length in bits of prime to be generated.\r
2448 @param[out] Prime Pointer to the buffer to receive the generated prime number.\r
2449\r
2450 @retval TRUE DH parameter generation succeeded.\r
2451 @retval FALSE Value of Generator is not supported.\r
2452 @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r
2453 @retval FALSE This interface is not supported.\r
2454\r
2455**/\r
2456BOOLEAN\r
2457EFIAPI\r
2458DhGenerateParameter (\r
2459 IN OUT VOID *DhContext,\r
2460 IN UINTN Generator,\r
2461 IN UINTN PrimeLength,\r
2462 OUT UINT8 *Prime\r
2463 )\r
2464{\r
2465 CALL_CRYPTO_SERVICE (DhGenerateParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);\r
2466}\r
2467\r
2468/**\r
2469 Sets generator and prime parameters for DH.\r
2470\r
2471 Given generator g, and prime number p, this function and sets DH\r
2472 context accordingly.\r
2473\r
2474 If DhContext is NULL, then return FALSE.\r
2475 If Prime is NULL, then return FALSE.\r
2476 If this interface is not supported, then return FALSE.\r
2477\r
2478 @param[in, out] DhContext Pointer to the DH context.\r
2479 @param[in] Generator Value of generator.\r
2480 @param[in] PrimeLength Length in bits of prime to be generated.\r
2481 @param[in] Prime Pointer to the prime number.\r
2482\r
2483 @retval TRUE DH parameter setting succeeded.\r
2484 @retval FALSE Value of Generator is not supported.\r
2485 @retval FALSE Value of Generator is not suitable for the Prime.\r
2486 @retval FALSE Value of Prime is not a prime number.\r
2487 @retval FALSE Value of Prime is not a safe prime number.\r
2488 @retval FALSE This interface is not supported.\r
2489\r
2490**/\r
2491BOOLEAN\r
2492EFIAPI\r
2493DhSetParameter (\r
2494 IN OUT VOID *DhContext,\r
2495 IN UINTN Generator,\r
2496 IN UINTN PrimeLength,\r
2497 IN CONST UINT8 *Prime\r
2498 )\r
2499{\r
2500 CALL_CRYPTO_SERVICE (DhSetParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);\r
2501}\r
2502\r
2503/**\r
2504 Generates DH public key.\r
2505\r
2506 This function generates random secret exponent, and computes the public key, which is\r
2507 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r
2508 If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r
2509 PublicKeySize is set to the required buffer size to obtain the public key.\r
2510\r
2511 If DhContext is NULL, then return FALSE.\r
2512 If PublicKeySize is NULL, then return FALSE.\r
2513 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r
2514 If this interface is not supported, then return FALSE.\r
2515\r
2516 @param[in, out] DhContext Pointer to the DH context.\r
2517 @param[out] PublicKey Pointer to the buffer to receive generated public key.\r
2518 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r
2519 On output, the size of data returned in PublicKey buffer in bytes.\r
2520\r
2521 @retval TRUE DH public key generation succeeded.\r
2522 @retval FALSE DH public key generation failed.\r
2523 @retval FALSE PublicKeySize is not large enough.\r
2524 @retval FALSE This interface is not supported.\r
2525\r
2526**/\r
2527BOOLEAN\r
2528EFIAPI\r
2529DhGenerateKey (\r
2530 IN OUT VOID *DhContext,\r
2531 OUT UINT8 *PublicKey,\r
2532 IN OUT UINTN *PublicKeySize\r
2533 )\r
2534{\r
2535 CALL_CRYPTO_SERVICE (DhGenerateKey, (DhContext, PublicKey, PublicKeySize), FALSE);\r
2536}\r
2537\r
2538/**\r
2539 Computes exchanged common key.\r
2540\r
2541 Given peer's public key, this function computes the exchanged common key, based on its own\r
2542 context including value of prime modulus and random secret exponent.\r
2543\r
2544 If DhContext is NULL, then return FALSE.\r
2545 If PeerPublicKey is NULL, then return FALSE.\r
2546 If KeySize is NULL, then return FALSE.\r
2547 If Key is NULL, then return FALSE.\r
2548 If KeySize is not large enough, then return FALSE.\r
2549 If this interface is not supported, then return FALSE.\r
2550\r
2551 @param[in, out] DhContext Pointer to the DH context.\r
2552 @param[in] PeerPublicKey Pointer to the peer's public key.\r
2553 @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r
2554 @param[out] Key Pointer to the buffer to receive generated key.\r
2555 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
2556 On output, the size of data returned in Key buffer in bytes.\r
2557\r
2558 @retval TRUE DH exchanged key generation succeeded.\r
2559 @retval FALSE DH exchanged key generation failed.\r
2560 @retval FALSE KeySize is not large enough.\r
2561 @retval FALSE This interface is not supported.\r
2562\r
2563**/\r
2564BOOLEAN\r
2565EFIAPI\r
2566DhComputeKey (\r
2567 IN OUT VOID *DhContext,\r
2568 IN CONST UINT8 *PeerPublicKey,\r
2569 IN UINTN PeerPublicKeySize,\r
2570 OUT UINT8 *Key,\r
2571 IN OUT UINTN *KeySize\r
2572 )\r
2573{\r
2574 CALL_CRYPTO_SERVICE (DhComputeKey, (DhContext, PeerPublicKey, PeerPublicKeySize, Key, KeySize), FALSE);\r
2575}\r
2576\r
2577//=====================================================================================\r
2578// Pseudo-Random Generation Primitive\r
2579//=====================================================================================\r
2580\r
2581/**\r
2582 Sets up the seed value for the pseudorandom number generator.\r
2583\r
2584 This function sets up the seed value for the pseudorandom number generator.\r
2585 If Seed is not NULL, then the seed passed in is used.\r
2586 If Seed is NULL, then default seed is used.\r
2587 If this interface is not supported, then return FALSE.\r
2588\r
2589 @param[in] Seed Pointer to seed value.\r
2590 If NULL, default seed is used.\r
2591 @param[in] SeedSize Size of seed value.\r
2592 If Seed is NULL, this parameter is ignored.\r
2593\r
2594 @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r
2595 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r
2596 @retval FALSE This interface is not supported.\r
2597\r
2598**/\r
2599BOOLEAN\r
2600EFIAPI\r
2601RandomSeed (\r
2602 IN CONST UINT8 *Seed OPTIONAL,\r
2603 IN UINTN SeedSize\r
2604 )\r
2605{\r
2606 CALL_CRYPTO_SERVICE (RandomSeed, (Seed, SeedSize), FALSE);\r
2607}\r
2608\r
2609/**\r
2610 Generates a pseudorandom byte stream of the specified size.\r
2611\r
2612 If Output is NULL, then return FALSE.\r
2613 If this interface is not supported, then return FALSE.\r
2614\r
2615 @param[out] Output Pointer to buffer to receive random value.\r
2616 @param[in] Size Size of random bytes to generate.\r
2617\r
2618 @retval TRUE Pseudorandom byte stream generated successfully.\r
2619 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r
2620 @retval FALSE This interface is not supported.\r
2621\r
2622**/\r
2623BOOLEAN\r
2624EFIAPI\r
2625RandomBytes (\r
2626 OUT UINT8 *Output,\r
2627 IN UINTN Size\r
2628 )\r
2629{\r
2630 CALL_CRYPTO_SERVICE (RandomBytes, (Output, Size), FALSE);\r
2631}\r
2632\r
2633//=====================================================================================\r
2634// Key Derivation Function Primitive\r
2635//=====================================================================================\r
2636\r
2637/**\r
2638 Derive key data using HMAC-SHA256 based KDF.\r
2639\r
2640 @param[in] Key Pointer to the user-supplied key.\r
2641 @param[in] KeySize Key size in bytes.\r
2642 @param[in] Salt Pointer to the salt(non-secret) value.\r
2643 @param[in] SaltSize Salt size in bytes.\r
2644 @param[in] Info Pointer to the application specific info.\r
2645 @param[in] InfoSize Info size in bytes.\r
2646 @param[out] Out Pointer to buffer to receive hkdf value.\r
2647 @param[in] OutSize Size of hkdf bytes to generate.\r
2648\r
2649 @retval TRUE Hkdf generated successfully.\r
2650 @retval FALSE Hkdf generation failed.\r
2651\r
2652**/\r
2653BOOLEAN\r
2654EFIAPI\r
2655HkdfSha256ExtractAndExpand (\r
2656 IN CONST UINT8 *Key,\r
2657 IN UINTN KeySize,\r
2658 IN CONST UINT8 *Salt,\r
2659 IN UINTN SaltSize,\r
2660 IN CONST UINT8 *Info,\r
2661 IN UINTN InfoSize,\r
2662 OUT UINT8 *Out,\r
2663 IN UINTN OutSize\r
2664 )\r
2665{\r
2666 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);\r
2667}\r
2668\r
2669/**\r
2670 Initializes the OpenSSL library.\r
2671\r
2672 This function registers ciphers and digests used directly and indirectly\r
2673 by SSL/TLS, and initializes the readable error messages.\r
2674 This function must be called before any other action takes places.\r
2675\r
2676 @retval TRUE The OpenSSL library has been initialized.\r
2677 @retval FALSE Failed to initialize the OpenSSL library.\r
2678\r
2679**/\r
2680BOOLEAN\r
2681EFIAPI\r
2682TlsInitialize (\r
2683 VOID\r
2684 )\r
2685{\r
2686 CALL_CRYPTO_SERVICE (TlsInitialize, (), FALSE);\r
2687}\r
2688\r
2689/**\r
2690 Free an allocated SSL_CTX object.\r
2691\r
2692 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.\r
2693\r
2694**/\r
2695VOID\r
2696EFIAPI\r
2697TlsCtxFree (\r
2698 IN VOID *TlsCtx\r
2699 )\r
2700{\r
2701 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree, (TlsCtx));\r
2702}\r
2703\r
2704/**\r
2705 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled\r
2706 connections.\r
2707\r
2708 @param[in] MajorVer Major Version of TLS/SSL Protocol.\r
2709 @param[in] MinorVer Minor Version of TLS/SSL Protocol.\r
2710\r
2711 @return Pointer to an allocated SSL_CTX object.\r
2712 If the creation failed, TlsCtxNew() returns NULL.\r
2713\r
2714**/\r
2715VOID *\r
2716EFIAPI\r
2717TlsCtxNew (\r
2718 IN UINT8 MajorVer,\r
2719 IN UINT8 MinorVer\r
2720 )\r
2721{\r
2722 CALL_CRYPTO_SERVICE (TlsCtxNew, (MajorVer, MinorVer), NULL);\r
2723}\r
2724\r
2725/**\r
2726 Free an allocated TLS object.\r
2727\r
2728 This function removes the TLS object pointed to by Tls and frees up the\r
2729 allocated memory. If Tls is NULL, nothing is done.\r
2730\r
2731 @param[in] Tls Pointer to the TLS object to be freed.\r
2732\r
2733**/\r
2734VOID\r
2735EFIAPI\r
2736TlsFree (\r
2737 IN VOID *Tls\r
2738 )\r
2739{\r
2740 CALL_VOID_CRYPTO_SERVICE (TlsFree, (Tls));\r
2741}\r
2742\r
2743/**\r
2744 Create a new TLS object for a connection.\r
2745\r
2746 This function creates a new TLS object for a connection. The new object\r
2747 inherits the setting of the underlying context TlsCtx: connection method,\r
2748 options, verification setting.\r
2749\r
2750 @param[in] TlsCtx Pointer to the SSL_CTX object.\r
2751\r
2752 @return Pointer to an allocated SSL object.\r
2753 If the creation failed, TlsNew() returns NULL.\r
2754\r
2755**/\r
2756VOID *\r
2757EFIAPI\r
2758TlsNew (\r
2759 IN VOID *TlsCtx\r
2760 )\r
2761{\r
2762 CALL_CRYPTO_SERVICE (TlsNew, (TlsCtx), NULL);\r
2763}\r
2764\r
2765/**\r
2766 Checks if the TLS handshake was done.\r
2767\r
2768 This function will check if the specified TLS handshake was done.\r
2769\r
2770 @param[in] Tls Pointer to the TLS object for handshake state checking.\r
2771\r
2772 @retval TRUE The TLS handshake was done.\r
2773 @retval FALSE The TLS handshake was not done.\r
2774\r
2775**/\r
2776BOOLEAN\r
2777EFIAPI\r
2778TlsInHandshake (\r
2779 IN VOID *Tls\r
2780 )\r
2781{\r
2782 CALL_CRYPTO_SERVICE (TlsInHandshake, (Tls), FALSE);\r
2783}\r
2784\r
2785/**\r
2786 Perform a TLS/SSL handshake.\r
2787\r
2788 This function will perform a TLS/SSL handshake.\r
2789\r
2790 @param[in] Tls Pointer to the TLS object for handshake operation.\r
2791 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.\r
2792 @param[in] BufferInSize Packet size in bytes for the most recently received TLS\r
2793 Handshake packet.\r
2794 @param[out] BufferOut Pointer to the buffer to hold the built packet.\r
2795 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is\r
2796 the buffer size provided by the caller. On output, it\r
2797 is the buffer size in fact needed to contain the\r
2798 packet.\r
2799\r
2800 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
2801 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
2802 Tls is NULL.\r
2803 BufferIn is NULL but BufferInSize is NOT 0.\r
2804 BufferInSize is 0 but BufferIn is NOT NULL.\r
2805 BufferOutSize is NULL.\r
2806 BufferOut is NULL if *BufferOutSize is not zero.\r
2807 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.\r
2808 @retval EFI_ABORTED Something wrong during handshake.\r
2809\r
2810**/\r
2811EFI_STATUS\r
2812EFIAPI\r
2813TlsDoHandshake (\r
2814 IN VOID *Tls,\r
c8f46130
MK
2815 IN UINT8 *BufferIn OPTIONAL,\r
2816 IN UINTN BufferInSize OPTIONAL,\r
2817 OUT UINT8 *BufferOut OPTIONAL,\r
cd70de1c
MK
2818 IN OUT UINTN *BufferOutSize\r
2819 )\r
2820{\r
2821 CALL_CRYPTO_SERVICE (TlsDoHandshake, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);\r
2822}\r
2823\r
2824/**\r
2825 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,\r
2826 TLS session has errors and the response packet needs to be Alert message based on error type.\r
2827\r
2828 @param[in] Tls Pointer to the TLS object for state checking.\r
2829 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.\r
2830 @param[in] BufferInSize Packet size in bytes for the most recently received TLS\r
2831 Alert packet.\r
2832 @param[out] BufferOut Pointer to the buffer to hold the built packet.\r
2833 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is\r
2834 the buffer size provided by the caller. On output, it\r
2835 is the buffer size in fact needed to contain the\r
2836 packet.\r
2837\r
2838 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
2839 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
2840 Tls is NULL.\r
2841 BufferIn is NULL but BufferInSize is NOT 0.\r
2842 BufferInSize is 0 but BufferIn is NOT NULL.\r
2843 BufferOutSize is NULL.\r
2844 BufferOut is NULL if *BufferOutSize is not zero.\r
2845 @retval EFI_ABORTED An error occurred.\r
2846 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.\r
2847\r
2848**/\r
2849EFI_STATUS\r
2850EFIAPI\r
2851TlsHandleAlert (\r
2852 IN VOID *Tls,\r
c8f46130
MK
2853 IN UINT8 *BufferIn OPTIONAL,\r
2854 IN UINTN BufferInSize OPTIONAL,\r
2855 OUT UINT8 *BufferOut OPTIONAL,\r
cd70de1c
MK
2856 IN OUT UINTN *BufferOutSize\r
2857 )\r
2858{\r
2859 CALL_CRYPTO_SERVICE (TlsHandleAlert, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);\r
2860}\r
2861\r
2862/**\r
2863 Build the CloseNotify packet.\r
2864\r
2865 @param[in] Tls Pointer to the TLS object for state checking.\r
2866 @param[in, out] Buffer Pointer to the buffer to hold the built packet.\r
2867 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is\r
2868 the buffer size provided by the caller. On output, it\r
2869 is the buffer size in fact needed to contain the\r
2870 packet.\r
2871\r
2872 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
2873 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
2874 Tls is NULL.\r
2875 BufferSize is NULL.\r
2876 Buffer is NULL if *BufferSize is not zero.\r
2877 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.\r
2878\r
2879**/\r
2880EFI_STATUS\r
2881EFIAPI\r
2882TlsCloseNotify (\r
2883 IN VOID *Tls,\r
2884 IN OUT UINT8 *Buffer,\r
2885 IN OUT UINTN *BufferSize\r
2886 )\r
2887{\r
2888 CALL_CRYPTO_SERVICE (TlsCloseNotify, (Tls, Buffer, BufferSize), EFI_UNSUPPORTED);\r
2889}\r
2890\r
2891/**\r
2892 Attempts to read bytes from one TLS object and places the data in Buffer.\r
2893\r
2894 This function will attempt to read BufferSize bytes from the TLS object\r
2895 and places the data in Buffer.\r
2896\r
2897 @param[in] Tls Pointer to the TLS object.\r
2898 @param[in,out] Buffer Pointer to the buffer to store the data.\r
2899 @param[in] BufferSize The size of Buffer in bytes.\r
2900\r
2901 @retval >0 The amount of data successfully read from the TLS object.\r
2902 @retval <=0 No data was successfully read.\r
2903\r
2904**/\r
2905INTN\r
2906EFIAPI\r
2907TlsCtrlTrafficOut (\r
2908 IN VOID *Tls,\r
2909 IN OUT VOID *Buffer,\r
2910 IN UINTN BufferSize\r
2911 )\r
2912{\r
2913 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut, (Tls, Buffer, BufferSize), 0);\r
2914}\r
2915\r
2916/**\r
2917 Attempts to write data from the buffer to TLS object.\r
2918\r
2919 This function will attempt to write BufferSize bytes data from the Buffer\r
2920 to the TLS object.\r
2921\r
2922 @param[in] Tls Pointer to the TLS object.\r
2923 @param[in] Buffer Pointer to the data buffer.\r
2924 @param[in] BufferSize The size of Buffer in bytes.\r
2925\r
2926 @retval >0 The amount of data successfully written to the TLS object.\r
2927 @retval <=0 No data was successfully written.\r
2928\r
2929**/\r
2930INTN\r
2931EFIAPI\r
2932TlsCtrlTrafficIn (\r
2933 IN VOID *Tls,\r
2934 IN VOID *Buffer,\r
2935 IN UINTN BufferSize\r
2936 )\r
2937{\r
2938 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn, (Tls, Buffer, BufferSize), 0);\r
2939}\r
2940\r
2941/**\r
2942 Attempts to read bytes from the specified TLS connection into the buffer.\r
2943\r
2944 This function tries to read BufferSize bytes data from the specified TLS\r
2945 connection into the Buffer.\r
2946\r
2947 @param[in] Tls Pointer to the TLS connection for data reading.\r
2948 @param[in,out] Buffer Pointer to the data buffer.\r
2949 @param[in] BufferSize The size of Buffer in bytes.\r
2950\r
2951 @retval >0 The read operation was successful, and return value is the\r
2952 number of bytes actually read from the TLS connection.\r
2953 @retval <=0 The read operation was not successful.\r
2954\r
2955**/\r
2956INTN\r
2957EFIAPI\r
2958TlsRead (\r
2959 IN VOID *Tls,\r
2960 IN OUT VOID *Buffer,\r
2961 IN UINTN BufferSize\r
2962 )\r
2963{\r
2964 CALL_CRYPTO_SERVICE (TlsRead, (Tls, Buffer, BufferSize), 0);\r
2965}\r
2966\r
2967/**\r
2968 Attempts to write data to a TLS connection.\r
2969\r
2970 This function tries to write BufferSize bytes data from the Buffer into the\r
2971 specified TLS connection.\r
2972\r
2973 @param[in] Tls Pointer to the TLS connection for data writing.\r
2974 @param[in] Buffer Pointer to the data buffer.\r
2975 @param[in] BufferSize The size of Buffer in bytes.\r
2976\r
2977 @retval >0 The write operation was successful, and return value is the\r
2978 number of bytes actually written to the TLS connection.\r
2979 @retval <=0 The write operation was not successful.\r
2980\r
2981**/\r
2982INTN\r
2983EFIAPI\r
2984TlsWrite (\r
2985 IN VOID *Tls,\r
2986 IN VOID *Buffer,\r
2987 IN UINTN BufferSize\r
2988 )\r
2989{\r
2990 CALL_CRYPTO_SERVICE (TlsWrite, (Tls, Buffer, BufferSize), 0);\r
2991}\r
2992\r
2993/**\r
2994 Set a new TLS/SSL method for a particular TLS object.\r
2995\r
2996 This function sets a new TLS/SSL method for a particular TLS object.\r
2997\r
2998 @param[in] Tls Pointer to a TLS object.\r
2999 @param[in] MajorVer Major Version of TLS/SSL Protocol.\r
3000 @param[in] MinorVer Minor Version of TLS/SSL Protocol.\r
3001\r
3002 @retval EFI_SUCCESS The TLS/SSL method was set successfully.\r
3003 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3004 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.\r
3005\r
3006**/\r
3007EFI_STATUS\r
3008EFIAPI\r
3009TlsSetVersion (\r
3010 IN VOID *Tls,\r
3011 IN UINT8 MajorVer,\r
3012 IN UINT8 MinorVer\r
3013 )\r
3014{\r
3015 CALL_CRYPTO_SERVICE (TlsSetVersion, (Tls, MajorVer, MinorVer), EFI_UNSUPPORTED);\r
3016}\r
3017\r
3018/**\r
3019 Set TLS object to work in client or server mode.\r
3020\r
3021 This function prepares a TLS object to work in client or server mode.\r
3022\r
3023 @param[in] Tls Pointer to a TLS object.\r
3024 @param[in] IsServer Work in server mode.\r
3025\r
3026 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.\r
3027 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3028 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.\r
3029\r
3030**/\r
3031EFI_STATUS\r
3032EFIAPI\r
3033TlsSetConnectionEnd (\r
3034 IN VOID *Tls,\r
3035 IN BOOLEAN IsServer\r
3036 )\r
3037{\r
3038 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd, (Tls, IsServer), EFI_UNSUPPORTED);\r
3039}\r
3040\r
3041/**\r
3042 Set the ciphers list to be used by the TLS object.\r
3043\r
3044 This function sets the ciphers for use by a specified TLS object.\r
3045\r
3046 @param[in] Tls Pointer to a TLS object.\r
3047 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16\r
3048 cipher identifier comes from the TLS Cipher Suite\r
3049 Registry of the IANA, interpreting Byte1 and Byte2\r
3050 in network (big endian) byte order.\r
3051 @param[in] CipherNum The number of cipher in the list.\r
3052\r
3053 @retval EFI_SUCCESS The ciphers list was set successfully.\r
3054 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3055 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.\r
3056 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
3057\r
3058**/\r
3059EFI_STATUS\r
3060EFIAPI\r
3061TlsSetCipherList (\r
3062 IN VOID *Tls,\r
3063 IN UINT16 *CipherId,\r
3064 IN UINTN CipherNum\r
3065 )\r
3066{\r
3067 CALL_CRYPTO_SERVICE (TlsSetCipherList, (Tls, CipherId, CipherNum), EFI_UNSUPPORTED);\r
3068}\r
3069\r
3070/**\r
3071 Set the compression method for TLS/SSL operations.\r
3072\r
3073 This function handles TLS/SSL integrated compression methods.\r
3074\r
3075 @param[in] CompMethod The compression method ID.\r
3076\r
3077 @retval EFI_SUCCESS The compression method for the communication was\r
3078 set successfully.\r
3079 @retval EFI_UNSUPPORTED Unsupported compression method.\r
3080\r
3081**/\r
3082EFI_STATUS\r
3083EFIAPI\r
3084TlsSetCompressionMethod (\r
3085 IN UINT8 CompMethod\r
3086 )\r
3087{\r
3088 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod, (CompMethod), EFI_UNSUPPORTED);\r
3089}\r
3090\r
3091/**\r
3092 Set peer certificate verification mode for the TLS connection.\r
3093\r
3094 This function sets the verification mode flags for the TLS connection.\r
3095\r
3096 @param[in] Tls Pointer to the TLS object.\r
3097 @param[in] VerifyMode A set of logically or'ed verification mode flags.\r
3098\r
3099**/\r
3100VOID\r
3101EFIAPI\r
3102TlsSetVerify (\r
3103 IN VOID *Tls,\r
3104 IN UINT32 VerifyMode\r
3105 )\r
3106{\r
3107 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify, (Tls, VerifyMode));\r
3108}\r
3109\r
3110/**\r
3111 Set the specified host name to be verified.\r
3112\r
3113 @param[in] Tls Pointer to the TLS object.\r
3114 @param[in] Flags The setting flags during the validation.\r
3115 @param[in] HostName The specified host name to be verified.\r
3116\r
3117 @retval EFI_SUCCESS The HostName setting was set successfully.\r
3118 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3119 @retval EFI_ABORTED Invalid HostName setting.\r
3120\r
3121**/\r
3122EFI_STATUS\r
3123EFIAPI\r
3124TlsSetVerifyHost (\r
3125 IN VOID *Tls,\r
3126 IN UINT32 Flags,\r
3127 IN CHAR8 *HostName\r
3128 )\r
3129{\r
3130 CALL_CRYPTO_SERVICE (TlsSetVerifyHost, (Tls, Flags, HostName), EFI_UNSUPPORTED);\r
3131}\r
3132\r
3133/**\r
3134 Sets a TLS/SSL session ID to be used during TLS/SSL connect.\r
3135\r
3136 This function sets a session ID to be used when the TLS/SSL connection is\r
3137 to be established.\r
3138\r
3139 @param[in] Tls Pointer to the TLS object.\r
3140 @param[in] SessionId Session ID data used for session resumption.\r
3141 @param[in] SessionIdLen Length of Session ID in bytes.\r
3142\r
3143 @retval EFI_SUCCESS Session ID was set successfully.\r
3144 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3145 @retval EFI_UNSUPPORTED No available session for ID setting.\r
3146\r
3147**/\r
3148EFI_STATUS\r
3149EFIAPI\r
3150TlsSetSessionId (\r
3151 IN VOID *Tls,\r
3152 IN UINT8 *SessionId,\r
3153 IN UINT16 SessionIdLen\r
3154 )\r
3155{\r
3156 CALL_CRYPTO_SERVICE (TlsSetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);\r
3157}\r
3158\r
3159/**\r
3160 Adds the CA to the cert store when requesting Server or Client authentication.\r
3161\r
3162 This function adds the CA certificate to the list of CAs when requesting\r
3163 Server or Client authentication for the chosen TLS connection.\r
3164\r
3165 @param[in] Tls Pointer to the TLS object.\r
3166 @param[in] Data Pointer to the data buffer of a DER-encoded binary\r
3167 X.509 certificate or PEM-encoded X.509 certificate.\r
3168 @param[in] DataSize The size of data buffer in bytes.\r
3169\r
3170 @retval EFI_SUCCESS The operation succeeded.\r
3171 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3172 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.\r
3173 @retval EFI_ABORTED Invalid X.509 certificate.\r
3174\r
3175**/\r
3176EFI_STATUS\r
3177EFIAPI\r
3178TlsSetCaCertificate (\r
3179 IN VOID *Tls,\r
3180 IN VOID *Data,\r
3181 IN UINTN DataSize\r
3182 )\r
3183{\r
3184 CALL_CRYPTO_SERVICE (TlsSetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3185}\r
3186\r
3187/**\r
3188 Loads the local public certificate into the specified TLS object.\r
3189\r
3190 This function loads the X.509 certificate into the specified TLS object\r
3191 for TLS negotiation.\r
3192\r
3193 @param[in] Tls Pointer to the TLS object.\r
3194 @param[in] Data Pointer to the data buffer of a DER-encoded binary\r
3195 X.509 certificate or PEM-encoded X.509 certificate.\r
3196 @param[in] DataSize The size of data buffer in bytes.\r
3197\r
3198 @retval EFI_SUCCESS The operation succeeded.\r
3199 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3200 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.\r
3201 @retval EFI_ABORTED Invalid X.509 certificate.\r
3202\r
3203**/\r
3204EFI_STATUS\r
3205EFIAPI\r
3206TlsSetHostPublicCert (\r
3207 IN VOID *Tls,\r
3208 IN VOID *Data,\r
3209 IN UINTN DataSize\r
3210 )\r
3211{\r
3212 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3213}\r
3214\r
3215/**\r
3216 Adds the local private key to the specified TLS object.\r
3217\r
3218 This function adds the local private key (PEM-encoded RSA or PKCS#8 private\r
3219 key) into the specified TLS object for TLS negotiation.\r
3220\r
3221 @param[in] Tls Pointer to the TLS object.\r
3222 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA\r
3223 or PKCS#8 private key.\r
3224 @param[in] DataSize The size of data buffer in bytes.\r
3225\r
3226 @retval EFI_SUCCESS The operation succeeded.\r
3227 @retval EFI_UNSUPPORTED This function is not supported.\r
3228 @retval EFI_ABORTED Invalid private key data.\r
3229\r
3230**/\r
3231EFI_STATUS\r
3232EFIAPI\r
3233TlsSetHostPrivateKey (\r
3234 IN VOID *Tls,\r
3235 IN VOID *Data,\r
3236 IN UINTN DataSize\r
3237 )\r
3238{\r
3239 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3240}\r
3241\r
3242/**\r
3243 Adds the CA-supplied certificate revocation list for certificate validation.\r
3244\r
3245 This function adds the CA-supplied certificate revocation list data for\r
3246 certificate validity checking.\r
3247\r
3248 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.\r
3249 @param[in] DataSize The size of data buffer in bytes.\r
3250\r
3251 @retval EFI_SUCCESS The operation succeeded.\r
3252 @retval EFI_UNSUPPORTED This function is not supported.\r
3253 @retval EFI_ABORTED Invalid CRL data.\r
3254\r
3255**/\r
3256EFI_STATUS\r
3257EFIAPI\r
3258TlsSetCertRevocationList (\r
3259 IN VOID *Data,\r
3260 IN UINTN DataSize\r
3261 )\r
3262{\r
3263 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);\r
3264}\r
3265\r
3266/**\r
3267 Gets the protocol version used by the specified TLS connection.\r
3268\r
3269 This function returns the protocol version used by the specified TLS\r
3270 connection.\r
3271\r
3272 If Tls is NULL, then ASSERT().\r
3273\r
3274 @param[in] Tls Pointer to the TLS object.\r
3275\r
3276 @return The protocol version of the specified TLS connection.\r
3277\r
3278**/\r
3279UINT16\r
3280EFIAPI\r
3281TlsGetVersion (\r
3282 IN VOID *Tls\r
3283 )\r
3284{\r
3285 CALL_CRYPTO_SERVICE (TlsGetVersion, (Tls), 0);\r
3286}\r
3287\r
3288/**\r
3289 Gets the connection end of the specified TLS connection.\r
3290\r
3291 This function returns the connection end (as client or as server) used by\r
3292 the specified TLS connection.\r
3293\r
3294 If Tls is NULL, then ASSERT().\r
3295\r
3296 @param[in] Tls Pointer to the TLS object.\r
3297\r
3298 @return The connection end used by the specified TLS connection.\r
3299\r
3300**/\r
3301UINT8\r
3302EFIAPI\r
3303TlsGetConnectionEnd (\r
3304 IN VOID *Tls\r
3305 )\r
3306{\r
3307 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd, (Tls), 0);\r
3308}\r
3309\r
3310/**\r
3311 Gets the cipher suite used by the specified TLS connection.\r
3312\r
3313 This function returns current cipher suite used by the specified\r
3314 TLS connection.\r
3315\r
3316 @param[in] Tls Pointer to the TLS object.\r
3317 @param[in,out] CipherId The cipher suite used by the TLS object.\r
3318\r
3319 @retval EFI_SUCCESS The cipher suite was returned successfully.\r
3320 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3321 @retval EFI_UNSUPPORTED Unsupported cipher suite.\r
3322\r
3323**/\r
3324EFI_STATUS\r
3325EFIAPI\r
3326TlsGetCurrentCipher (\r
3327 IN VOID *Tls,\r
3328 IN OUT UINT16 *CipherId\r
3329 )\r
3330{\r
3331 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher, (Tls, CipherId), EFI_UNSUPPORTED);\r
3332}\r
3333\r
3334/**\r
3335 Gets the compression methods used by the specified TLS connection.\r
3336\r
3337 This function returns current integrated compression methods used by\r
3338 the specified TLS connection.\r
3339\r
3340 @param[in] Tls Pointer to the TLS object.\r
3341 @param[in,out] CompressionId The current compression method used by\r
3342 the TLS object.\r
3343\r
3344 @retval EFI_SUCCESS The compression method was returned successfully.\r
3345 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3346 @retval EFI_ABORTED Invalid Compression method.\r
3347 @retval EFI_UNSUPPORTED This function is not supported.\r
3348\r
3349**/\r
3350EFI_STATUS\r
3351EFIAPI\r
3352TlsGetCurrentCompressionId (\r
3353 IN VOID *Tls,\r
3354 IN OUT UINT8 *CompressionId\r
3355 )\r
3356{\r
3357 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId, (Tls, CompressionId), EFI_UNSUPPORTED);\r
3358}\r
3359\r
3360/**\r
3361 Gets the verification mode currently set in the TLS connection.\r
3362\r
3363 This function returns the peer verification mode currently set in the\r
3364 specified TLS connection.\r
3365\r
3366 If Tls is NULL, then ASSERT().\r
3367\r
3368 @param[in] Tls Pointer to the TLS object.\r
3369\r
3370 @return The verification mode set in the specified TLS connection.\r
3371\r
3372**/\r
3373UINT32\r
3374EFIAPI\r
3375TlsGetVerify (\r
3376 IN VOID *Tls\r
3377 )\r
3378{\r
3379 CALL_CRYPTO_SERVICE (TlsGetVerify, (Tls), 0);\r
3380}\r
3381\r
3382/**\r
3383 Gets the session ID used by the specified TLS connection.\r
3384\r
3385 This function returns the TLS/SSL session ID currently used by the\r
3386 specified TLS connection.\r
3387\r
3388 @param[in] Tls Pointer to the TLS object.\r
3389 @param[in,out] SessionId Buffer to contain the returned session ID.\r
3390 @param[in,out] SessionIdLen The length of Session ID in bytes.\r
3391\r
3392 @retval EFI_SUCCESS The Session ID was returned successfully.\r
3393 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3394 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.\r
3395\r
3396**/\r
3397EFI_STATUS\r
3398EFIAPI\r
3399TlsGetSessionId (\r
3400 IN VOID *Tls,\r
3401 IN OUT UINT8 *SessionId,\r
3402 IN OUT UINT16 *SessionIdLen\r
3403 )\r
3404{\r
3405 CALL_CRYPTO_SERVICE (TlsGetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);\r
3406}\r
3407\r
3408/**\r
3409 Gets the client random data used in the specified TLS connection.\r
3410\r
3411 This function returns the TLS/SSL client random data currently used in\r
3412 the specified TLS connection.\r
3413\r
3414 @param[in] Tls Pointer to the TLS object.\r
3415 @param[in,out] ClientRandom Buffer to contain the returned client\r
3416 random data (32 bytes).\r
3417\r
3418**/\r
3419VOID\r
3420EFIAPI\r
3421TlsGetClientRandom (\r
3422 IN VOID *Tls,\r
3423 IN OUT UINT8 *ClientRandom\r
3424 )\r
3425{\r
3426 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom, (Tls, ClientRandom));\r
3427}\r
3428\r
3429/**\r
3430 Gets the server random data used in the specified TLS connection.\r
3431\r
3432 This function returns the TLS/SSL server random data currently used in\r
3433 the specified TLS connection.\r
3434\r
3435 @param[in] Tls Pointer to the TLS object.\r
3436 @param[in,out] ServerRandom Buffer to contain the returned server\r
3437 random data (32 bytes).\r
3438\r
3439**/\r
3440VOID\r
3441EFIAPI\r
3442TlsGetServerRandom (\r
3443 IN VOID *Tls,\r
3444 IN OUT UINT8 *ServerRandom\r
3445 )\r
3446{\r
3447 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom, (Tls, ServerRandom));\r
3448}\r
3449\r
3450/**\r
3451 Gets the master key data used in the specified TLS connection.\r
3452\r
3453 This function returns the TLS/SSL master key material currently used in\r
3454 the specified TLS connection.\r
3455\r
3456 @param[in] Tls Pointer to the TLS object.\r
3457 @param[in,out] KeyMaterial Buffer to contain the returned key material.\r
3458\r
3459 @retval EFI_SUCCESS Key material was returned successfully.\r
3460 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3461 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.\r
3462\r
3463**/\r
3464EFI_STATUS\r
3465EFIAPI\r
3466TlsGetKeyMaterial (\r
3467 IN VOID *Tls,\r
3468 IN OUT UINT8 *KeyMaterial\r
3469 )\r
3470{\r
3471 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial, (Tls, KeyMaterial), EFI_UNSUPPORTED);\r
3472}\r
3473\r
3474/**\r
3475 Gets the CA Certificate from the cert store.\r
3476\r
3477 This function returns the CA certificate for the chosen\r
3478 TLS connection.\r
3479\r
3480 @param[in] Tls Pointer to the TLS object.\r
3481 @param[out] Data Pointer to the data buffer to receive the CA\r
3482 certificate data sent to the client.\r
3483 @param[in,out] DataSize The size of data buffer in bytes.\r
3484\r
3485 @retval EFI_SUCCESS The operation succeeded.\r
3486 @retval EFI_UNSUPPORTED This function is not supported.\r
3487 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3488\r
3489**/\r
3490EFI_STATUS\r
3491EFIAPI\r
3492TlsGetCaCertificate (\r
3493 IN VOID *Tls,\r
3494 OUT VOID *Data,\r
3495 IN OUT UINTN *DataSize\r
3496 )\r
3497{\r
3498 CALL_CRYPTO_SERVICE (TlsGetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3499}\r
3500\r
3501/**\r
3502 Gets the local public Certificate set in the specified TLS object.\r
3503\r
3504 This function returns the local public certificate which was currently set\r
3505 in the specified TLS object.\r
3506\r
3507 @param[in] Tls Pointer to the TLS object.\r
3508 @param[out] Data Pointer to the data buffer to receive the local\r
3509 public certificate.\r
3510 @param[in,out] DataSize The size of data buffer in bytes.\r
3511\r
3512 @retval EFI_SUCCESS The operation succeeded.\r
3513 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3514 @retval EFI_NOT_FOUND The certificate is not found.\r
3515 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3516\r
3517**/\r
3518EFI_STATUS\r
3519EFIAPI\r
3520TlsGetHostPublicCert (\r
3521 IN VOID *Tls,\r
3522 OUT VOID *Data,\r
3523 IN OUT UINTN *DataSize\r
3524 )\r
3525{\r
3526 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3527}\r
3528\r
3529/**\r
3530 Gets the local private key set in the specified TLS object.\r
3531\r
3532 This function returns the local private key data which was currently set\r
3533 in the specified TLS object.\r
3534\r
3535 @param[in] Tls Pointer to the TLS object.\r
3536 @param[out] Data Pointer to the data buffer to receive the local\r
3537 private key data.\r
3538 @param[in,out] DataSize The size of data buffer in bytes.\r
3539\r
3540 @retval EFI_SUCCESS The operation succeeded.\r
3541 @retval EFI_UNSUPPORTED This function is not supported.\r
3542 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3543\r
3544**/\r
3545EFI_STATUS\r
3546EFIAPI\r
3547TlsGetHostPrivateKey (\r
3548 IN VOID *Tls,\r
3549 OUT VOID *Data,\r
3550 IN OUT UINTN *DataSize\r
3551 )\r
3552{\r
3553 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3554}\r
3555\r
3556/**\r
3557 Gets the CA-supplied certificate revocation list data set in the specified\r
3558 TLS object.\r
3559\r
3560 This function returns the CA-supplied certificate revocation list data which\r
3561 was currently set in the specified TLS object.\r
3562\r
3563 @param[out] Data Pointer to the data buffer to receive the CRL data.\r
3564 @param[in,out] DataSize The size of data buffer in bytes.\r
3565\r
3566 @retval EFI_SUCCESS The operation succeeded.\r
3567 @retval EFI_UNSUPPORTED This function is not supported.\r
3568 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3569\r
3570**/\r
3571EFI_STATUS\r
3572EFIAPI\r
3573TlsGetCertRevocationList (\r
3574 OUT VOID *Data,\r
3575 IN OUT UINTN *DataSize\r
3576 )\r
3577{\r
3578 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);\r
3579}\r