]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/BaseCryptLibOnProtocolPpi/CryptLib.c
NetworkPkg/Defines: Make iSCSI disable as default
[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
acfd5557 102#ifndef DISABLE_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
1555/**\r
1556 Retrieve the RSA Private Key from the password-protected PEM key data.\r
1557\r
1558 If PemData is NULL, then return FALSE.\r
1559 If RsaContext is NULL, then return FALSE.\r
1560 If this interface is not supported, then return FALSE.\r
1561\r
1562 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
1563 @param[in] PemSize Size of the PEM key data in bytes.\r
1564 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
1565 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1566 RSA private key component. Use RsaFree() function to free the\r
1567 resource.\r
1568\r
1569 @retval TRUE RSA Private Key was retrieved successfully.\r
1570 @retval FALSE Invalid PEM key data or incorrect password.\r
1571 @retval FALSE This interface is not supported.\r
1572\r
1573**/\r
1574BOOLEAN\r
1575EFIAPI\r
1576RsaGetPrivateKeyFromPem (\r
1577 IN CONST UINT8 *PemData,\r
1578 IN UINTN PemSize,\r
1579 IN CONST CHAR8 *Password,\r
1580 OUT VOID **RsaContext\r
1581 )\r
1582{\r
1583 CALL_CRYPTO_SERVICE (RsaGetPrivateKeyFromPem, (PemData, PemSize, Password, RsaContext), FALSE);\r
1584}\r
1585\r
1586/**\r
1587 Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r
1588\r
1589 If Cert is NULL, then return FALSE.\r
1590 If RsaContext is NULL, then return FALSE.\r
1591 If this interface is not supported, then return FALSE.\r
1592\r
1593 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1594 @param[in] CertSize Size of the X509 certificate in bytes.\r
1595 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1596 RSA public key component. Use RsaFree() function to free the\r
1597 resource.\r
1598\r
1599 @retval TRUE RSA Public Key was retrieved successfully.\r
1600 @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r
1601 @retval FALSE This interface is not supported.\r
1602\r
1603**/\r
1604BOOLEAN\r
1605EFIAPI\r
1606RsaGetPublicKeyFromX509 (\r
1607 IN CONST UINT8 *Cert,\r
1608 IN UINTN CertSize,\r
1609 OUT VOID **RsaContext\r
1610 )\r
1611{\r
1612 CALL_CRYPTO_SERVICE (RsaGetPublicKeyFromX509, (Cert, CertSize, RsaContext), FALSE);\r
1613}\r
1614\r
1615/**\r
1616 Retrieve the subject bytes from one X.509 certificate.\r
1617\r
1618 If Cert is NULL, then return FALSE.\r
1619 If SubjectSize is NULL, then return FALSE.\r
1620 If this interface is not supported, then return FALSE.\r
1621\r
1622 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1623 @param[in] CertSize Size of the X509 certificate in bytes.\r
1624 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r
1625 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r
1626 and the size of buffer returned CertSubject on output.\r
1627\r
1628 @retval TRUE The certificate subject retrieved successfully.\r
1629 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r
1630 The SubjectSize will be updated with the required size.\r
1631 @retval FALSE This interface is not supported.\r
1632\r
1633**/\r
1634BOOLEAN\r
1635EFIAPI\r
1636X509GetSubjectName (\r
1637 IN CONST UINT8 *Cert,\r
1638 IN UINTN CertSize,\r
1639 OUT UINT8 *CertSubject,\r
1640 IN OUT UINTN *SubjectSize\r
1641 )\r
1642{\r
1643 CALL_CRYPTO_SERVICE (X509GetSubjectName, (Cert, CertSize, CertSubject, SubjectSize), FALSE);\r
1644}\r
1645\r
1646/**\r
1647 Retrieve the common name (CN) string from one X.509 certificate.\r
1648\r
1649 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1650 @param[in] CertSize Size of the X509 certificate in bytes.\r
1651 @param[out] CommonName Buffer to contain the retrieved certificate common\r
1652 name string (UTF8). At most CommonNameSize bytes will be\r
1653 written and the string will be null terminated. May be\r
1654 NULL in order to determine the size buffer needed.\r
1655 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
1656 and the size of buffer returned CommonName on output.\r
1657 If CommonName is NULL then the amount of space needed\r
1658 in buffer (including the final null) is returned.\r
1659\r
1660 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r
1661 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1662 If CommonNameSize is NULL.\r
1663 If CommonName is not NULL and *CommonNameSize is 0.\r
1664 If Certificate is invalid.\r
1665 @retval RETURN_NOT_FOUND If no CommonName entry exists.\r
1666 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r
1667 (including the final null) is returned in the\r
1668 CommonNameSize parameter.\r
1669 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1670\r
1671**/\r
1672RETURN_STATUS\r
1673EFIAPI\r
1674X509GetCommonName (\r
1675 IN CONST UINT8 *Cert,\r
1676 IN UINTN CertSize,\r
1677 OUT CHAR8 *CommonName, OPTIONAL\r
1678 IN OUT UINTN *CommonNameSize\r
1679 )\r
1680{\r
1681 CALL_CRYPTO_SERVICE (X509GetCommonName, (Cert, CertSize, CommonName, CommonNameSize), RETURN_UNSUPPORTED);\r
1682}\r
1683\r
1684/**\r
1685 Retrieve the organization name (O) string from one X.509 certificate.\r
1686\r
1687 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1688 @param[in] CertSize Size of the X509 certificate in bytes.\r
1689 @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r
1690 name string. At most NameBufferSize bytes will be\r
1691 written and the string will be null terminated. May be\r
1692 NULL in order to determine the size buffer needed.\r
1693 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r
1694 and the size of buffer returned Name on output.\r
1695 If NameBuffer is NULL then the amount of space needed\r
1696 in buffer (including the final null) is returned.\r
1697\r
1698 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r
1699 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1700 If NameBufferSize is NULL.\r
1701 If NameBuffer is not NULL and *CommonNameSize is 0.\r
1702 If Certificate is invalid.\r
1703 @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r
1704 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r
1705 (including the final null) is returned in the\r
1706 CommonNameSize parameter.\r
1707 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1708\r
1709**/\r
1710RETURN_STATUS\r
1711EFIAPI\r
1712X509GetOrganizationName (\r
1713 IN CONST UINT8 *Cert,\r
1714 IN UINTN CertSize,\r
1715 OUT CHAR8 *NameBuffer, OPTIONAL\r
1716 IN OUT UINTN *NameBufferSize\r
1717 )\r
1718{\r
1719 CALL_CRYPTO_SERVICE (X509GetOrganizationName, (Cert, CertSize, NameBuffer, NameBufferSize), RETURN_UNSUPPORTED);\r
1720}\r
1721\r
1722/**\r
1723 Verify one X509 certificate was issued by the trusted CA.\r
1724\r
1725 If Cert is NULL, then return FALSE.\r
1726 If CACert is NULL, then return FALSE.\r
1727 If this interface is not supported, then return FALSE.\r
1728\r
1729 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r
1730 @param[in] CertSize Size of the X509 certificate in bytes.\r
1731 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r
1732 @param[in] CACertSize Size of the CA Certificate in bytes.\r
1733\r
1734 @retval TRUE The certificate was issued by the trusted CA.\r
1735 @retval FALSE Invalid certificate or the certificate was not issued by the given\r
1736 trusted CA.\r
1737 @retval FALSE This interface is not supported.\r
1738\r
1739**/\r
1740BOOLEAN\r
1741EFIAPI\r
1742X509VerifyCert (\r
1743 IN CONST UINT8 *Cert,\r
1744 IN UINTN CertSize,\r
1745 IN CONST UINT8 *CACert,\r
1746 IN UINTN CACertSize\r
1747 )\r
1748{\r
1749 CALL_CRYPTO_SERVICE (X509VerifyCert, (Cert, CertSize, CACert, CACertSize), FALSE);\r
1750}\r
1751\r
1752/**\r
1753 Construct a X509 object from DER-encoded certificate data.\r
1754\r
1755 If Cert is NULL, then return FALSE.\r
1756 If SingleX509Cert is NULL, then return FALSE.\r
1757 If this interface is not supported, then return FALSE.\r
1758\r
1759 @param[in] Cert Pointer to the DER-encoded certificate data.\r
1760 @param[in] CertSize The size of certificate data in bytes.\r
1761 @param[out] SingleX509Cert The generated X509 object.\r
1762\r
1763 @retval TRUE The X509 object generation succeeded.\r
1764 @retval FALSE The operation failed.\r
1765 @retval FALSE This interface is not supported.\r
1766\r
1767**/\r
1768BOOLEAN\r
1769EFIAPI\r
1770X509ConstructCertificate (\r
1771 IN CONST UINT8 *Cert,\r
1772 IN UINTN CertSize,\r
1773 OUT UINT8 **SingleX509Cert\r
1774 )\r
1775{\r
1776 CALL_CRYPTO_SERVICE (X509ConstructCertificate, (Cert, CertSize, SingleX509Cert), FALSE);\r
1777}\r
1778\r
1779/**\r
1780 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1781\r
1782 If X509Stack is NULL, then return FALSE.\r
1783 If this interface is not supported, then return FALSE.\r
1784\r
1785 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
1786 On output, pointer to the X509 stack object with new\r
1787 inserted X509 certificate.\r
1788 @param[in] Args VA_LIST marker for the variable argument list.\r
1789 ... A list of DER-encoded single certificate data followed\r
1790 by certificate size. A NULL terminates the list. The\r
1791 pairs are the arguments to X509ConstructCertificate().\r
1792\r
1793 @retval TRUE The X509 stack construction succeeded.\r
1794 @retval FALSE The construction operation failed.\r
1795 @retval FALSE This interface is not supported.\r
1796\r
1797**/\r
1798BOOLEAN\r
1799EFIAPI\r
1800X509ConstructCertificateStack (\r
1801 IN OUT UINT8 **X509Stack,\r
1802 ...\r
1803 )\r
1804{\r
1805 VA_LIST Args;\r
1806 BOOLEAN Result;\r
1807\r
1808 VA_START (Args, X509Stack);\r
1809 Result = X509ConstructCertificateStackV (X509Stack, Args);\r
1810 VA_END (Args);\r
1811 return Result;\r
1812}\r
1813\r
1814/**\r
1815 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1816\r
1817 If X509Stack is NULL, then return FALSE.\r
1818 If this interface is not supported, then return FALSE.\r
1819\r
1820 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
1821 On output, pointer to the X509 stack object with new\r
1822 inserted X509 certificate.\r
1823 @param[in] Args VA_LIST marker for the variable argument list.\r
1824 A list of DER-encoded single certificate data followed\r
1825 by certificate size. A NULL terminates the list. The\r
1826 pairs are the arguments to X509ConstructCertificate().\r
1827\r
1828 @retval TRUE The X509 stack construction succeeded.\r
1829 @retval FALSE The construction operation failed.\r
1830 @retval FALSE This interface is not supported.\r
1831\r
1832**/\r
1833BOOLEAN\r
1834EFIAPI\r
1835X509ConstructCertificateStackV (\r
1836 IN OUT UINT8 **X509Stack,\r
1837 IN VA_LIST Args\r
1838 )\r
1839{\r
1840 CALL_CRYPTO_SERVICE (X509ConstructCertificateStackV, (X509Stack, Args), FALSE);\r
1841}\r
1842\r
1843/**\r
1844 Release the specified X509 object.\r
1845\r
1846 If the interface is not supported, then ASSERT().\r
1847\r
1848 @param[in] X509Cert Pointer to the X509 object to be released.\r
1849\r
1850**/\r
1851VOID\r
1852EFIAPI\r
1853X509Free (\r
1854 IN VOID *X509Cert\r
1855 )\r
1856{\r
1857 CALL_VOID_CRYPTO_SERVICE (X509Free, (X509Cert));\r
1858}\r
1859\r
1860/**\r
1861 Release the specified X509 stack object.\r
1862\r
1863 If the interface is not supported, then ASSERT().\r
1864\r
1865 @param[in] X509Stack Pointer to the X509 stack object to be released.\r
1866\r
1867**/\r
1868VOID\r
1869EFIAPI\r
1870X509StackFree (\r
1871 IN VOID *X509Stack\r
1872 )\r
1873{\r
1874 CALL_VOID_CRYPTO_SERVICE (X509StackFree, (X509Stack));\r
1875}\r
1876\r
1877/**\r
1878 Retrieve the TBSCertificate from one given X.509 certificate.\r
1879\r
1880 @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r
1881 @param[in] CertSize Size of the X509 certificate in bytes.\r
1882 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r
1883 @param[out] TBSCertSize Size of the TBS certificate in bytes.\r
1884\r
1885 If Cert is NULL, then return FALSE.\r
1886 If TBSCert is NULL, then return FALSE.\r
1887 If TBSCertSize is NULL, then return FALSE.\r
1888 If this interface is not supported, then return FALSE.\r
1889\r
1890 @retval TRUE The TBSCertificate was retrieved successfully.\r
1891 @retval FALSE Invalid X.509 certificate.\r
1892\r
1893**/\r
1894BOOLEAN\r
1895EFIAPI\r
1896X509GetTBSCert (\r
1897 IN CONST UINT8 *Cert,\r
1898 IN UINTN CertSize,\r
1899 OUT UINT8 **TBSCert,\r
1900 OUT UINTN *TBSCertSize\r
1901 )\r
1902{\r
1903 CALL_CRYPTO_SERVICE (X509GetTBSCert, (Cert, CertSize, TBSCert, TBSCertSize), FALSE);\r
1904}\r
1905\r
1906/**\r
1907 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r
1908 password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r
1909\r
1910 If Password or Salt or OutKey is NULL, then return FALSE.\r
1911 If the hash algorithm could not be determined, then return FALSE.\r
1912 If this interface is not supported, then return FALSE.\r
1913\r
1914 @param[in] PasswordLength Length of input password in bytes.\r
1915 @param[in] Password Pointer to the array for the password.\r
1916 @param[in] SaltLength Size of the Salt in bytes.\r
1917 @param[in] Salt Pointer to the Salt.\r
1918 @param[in] IterationCount Number of iterations to perform. Its value should be\r
1919 greater than or equal to 1.\r
1920 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r
1921 NOTE: DigestSize will be used to determine the hash algorithm.\r
1922 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r
1923 @param[in] KeyLength Size of the derived key buffer in bytes.\r
1924 @param[out] OutKey Pointer to the output derived key buffer.\r
1925\r
1926 @retval TRUE A key was derived successfully.\r
1927 @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r
1928 @retval FALSE The hash algorithm could not be determined from the digest size.\r
1929 @retval FALSE The key derivation operation failed.\r
1930 @retval FALSE This interface is not supported.\r
1931\r
1932**/\r
1933BOOLEAN\r
1934EFIAPI\r
1935Pkcs5HashPassword (\r
1936 IN UINTN PasswordLength,\r
1937 IN CONST CHAR8 *Password,\r
1938 IN UINTN SaltLength,\r
1939 IN CONST UINT8 *Salt,\r
1940 IN UINTN IterationCount,\r
1941 IN UINTN DigestSize,\r
1942 IN UINTN KeyLength,\r
1943 OUT UINT8 *OutKey\r
1944 )\r
1945{\r
1946 CALL_CRYPTO_SERVICE (Pkcs5HashPassword, (PasswordLength, Password, SaltLength, Salt, IterationCount, DigestSize, KeyLength, OutKey), FALSE);\r
1947}\r
1948\r
1949/**\r
1950 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r
1951 encrypted message in a newly allocated buffer.\r
1952\r
1953 Things that can cause a failure include:\r
1954 - X509 key size does not match any known key size.\r
1955 - Fail to parse X509 certificate.\r
1956 - Fail to allocate an intermediate buffer.\r
1957 - Null pointer provided for a non-optional parameter.\r
1958 - Data size is too large for the provided key size (max size is a function of key size\r
1959 and hash digest size).\r
1960\r
1961 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r
1962 will be used to encrypt the data.\r
1963 @param[in] PublicKeySize Size of the X509 cert buffer.\r
1964 @param[in] InData Data to be encrypted.\r
1965 @param[in] InDataSize Size of the data buffer.\r
1966 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r
1967 to be used when initializing the PRNG. NULL otherwise.\r
1968 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r
1969 0 otherwise.\r
1970 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r
1971 message.\r
1972 @param[out] EncryptedDataSize Size of the encrypted message buffer.\r
1973\r
1974 @retval TRUE Encryption was successful.\r
1975 @retval FALSE Encryption failed.\r
1976\r
1977**/\r
1978BOOLEAN\r
1979EFIAPI\r
1980Pkcs1v2Encrypt (\r
1981 IN CONST UINT8 *PublicKey,\r
1982 IN UINTN PublicKeySize,\r
1983 IN UINT8 *InData,\r
1984 IN UINTN InDataSize,\r
1985 IN CONST UINT8 *PrngSeed, OPTIONAL\r
1986 IN UINTN PrngSeedSize, OPTIONAL\r
1987 OUT UINT8 **EncryptedData,\r
1988 OUT UINTN *EncryptedDataSize\r
1989 )\r
1990{\r
1991 CALL_CRYPTO_SERVICE (Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);\r
1992}\r
1993\r
1994/**\r
1995 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r
1996 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
1997 in a ContentInfo structure.\r
1998\r
1999 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r
2000 return FALSE. If P7Length overflow, then return FALSE.\r
2001 If this interface is not supported, then return FALSE.\r
2002\r
2003 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
2004 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2005 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r
2006 It's caller's responsibility to free the buffer with\r
2007 Pkcs7FreeSigners().\r
2008 This data structure is EFI_CERT_STACK type.\r
2009 @param[out] StackLength Length of signer's certificates in bytes.\r
2010 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r
2011 It's caller's responsibility to free the buffer with\r
2012 Pkcs7FreeSigners().\r
2013 @param[out] CertLength Length of the trusted certificate in bytes.\r
2014\r
2015 @retval TRUE The operation is finished successfully.\r
2016 @retval FALSE Error occurs during the operation.\r
2017 @retval FALSE This interface is not supported.\r
2018\r
2019**/\r
2020BOOLEAN\r
2021EFIAPI\r
2022Pkcs7GetSigners (\r
2023 IN CONST UINT8 *P7Data,\r
2024 IN UINTN P7Length,\r
2025 OUT UINT8 **CertStack,\r
2026 OUT UINTN *StackLength,\r
2027 OUT UINT8 **TrustedCert,\r
2028 OUT UINTN *CertLength\r
2029 )\r
2030{\r
2031 CALL_CRYPTO_SERVICE (Pkcs7GetSigners, (P7Data, P7Length, CertStack, StackLength, TrustedCert, CertLength), FALSE);\r
2032}\r
2033\r
2034/**\r
2035 Wrap function to use free() to free allocated memory for certificates.\r
2036\r
2037 If this interface is not supported, then ASSERT().\r
2038\r
2039 @param[in] Certs Pointer to the certificates to be freed.\r
2040\r
2041**/\r
2042VOID\r
2043EFIAPI\r
2044Pkcs7FreeSigners (\r
2045 IN UINT8 *Certs\r
2046 )\r
2047{\r
2048 CALL_VOID_CRYPTO_SERVICE (Pkcs7FreeSigners, (Certs));\r
2049}\r
2050\r
2051/**\r
2052 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r
2053 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r
2054 unchained to the signer's certificates.\r
2055 The input signed data could be wrapped in a ContentInfo structure.\r
2056\r
2057 @param[in] P7Data Pointer to the PKCS#7 message.\r
2058 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2059 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r
2060 certificate. It's caller's responsibility to free the buffer\r
2061 with Pkcs7FreeSigners().\r
2062 This data structure is EFI_CERT_STACK type.\r
2063 @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r
2064 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r
2065 responsibility to free the buffer with Pkcs7FreeSigners().\r
2066 This data structure is EFI_CERT_STACK type.\r
2067 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r
2068\r
2069 @retval TRUE The operation is finished successfully.\r
2070 @retval FALSE Error occurs during the operation.\r
2071\r
2072**/\r
2073BOOLEAN\r
2074EFIAPI\r
2075Pkcs7GetCertificatesList (\r
2076 IN CONST UINT8 *P7Data,\r
2077 IN UINTN P7Length,\r
2078 OUT UINT8 **SignerChainCerts,\r
2079 OUT UINTN *ChainLength,\r
2080 OUT UINT8 **UnchainCerts,\r
2081 OUT UINTN *UnchainLength\r
2082 )\r
2083{\r
2084 CALL_CRYPTO_SERVICE (Pkcs7GetCertificatesList, (P7Data, P7Length, SignerChainCerts, ChainLength, UnchainCerts, UnchainLength), FALSE);\r
2085}\r
2086\r
2087/**\r
2088 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
2089 Syntax Standard, version 1.5". This interface is only intended to be used for\r
2090 application to perform PKCS#7 functionality validation.\r
2091\r
2092 If this interface is not supported, then return FALSE.\r
2093\r
2094 @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r
2095 data signing.\r
2096 @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r
2097 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r
2098 key data.\r
2099 @param[in] InData Pointer to the content to be signed.\r
2100 @param[in] InDataSize Size of InData in bytes.\r
2101 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r
2102 @param[in] OtherCerts Pointer to an optional additional set of certificates to\r
2103 include in the PKCS#7 signedData (e.g. any intermediate\r
2104 CAs in the chain).\r
2105 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r
2106 responsibility to free the buffer with FreePool().\r
2107 @param[out] SignedDataSize Size of SignedData in bytes.\r
2108\r
2109 @retval TRUE PKCS#7 data signing succeeded.\r
2110 @retval FALSE PKCS#7 data signing failed.\r
2111 @retval FALSE This interface is not supported.\r
2112\r
2113**/\r
2114BOOLEAN\r
2115EFIAPI\r
2116Pkcs7Sign (\r
2117 IN CONST UINT8 *PrivateKey,\r
2118 IN UINTN PrivateKeySize,\r
2119 IN CONST UINT8 *KeyPassword,\r
2120 IN UINT8 *InData,\r
2121 IN UINTN InDataSize,\r
2122 IN UINT8 *SignCert,\r
2123 IN UINT8 *OtherCerts OPTIONAL,\r
2124 OUT UINT8 **SignedData,\r
2125 OUT UINTN *SignedDataSize\r
2126 )\r
2127{\r
2128 CALL_CRYPTO_SERVICE (Pkcs7Sign, (PrivateKey, PrivateKeySize, KeyPassword, InData, InDataSize, SignCert, OtherCerts, SignedData, SignedDataSize), FALSE);\r
2129}\r
2130\r
2131/**\r
2132 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r
2133 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2134 in a ContentInfo structure.\r
2135\r
2136 If P7Data, TrustedCert or InData is NULL, then return FALSE.\r
2137 If P7Length, CertLength or DataLength overflow, then return FALSE.\r
2138 If this interface is not supported, then return FALSE.\r
2139\r
2140 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
2141 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
2142 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2143 is used for certificate chain verification.\r
2144 @param[in] CertLength Length of the trusted certificate in bytes.\r
2145 @param[in] InData Pointer to the content to be verified.\r
2146 @param[in] DataLength Length of InData in bytes.\r
2147\r
2148 @retval TRUE The specified PKCS#7 signed data is valid.\r
2149 @retval FALSE Invalid PKCS#7 signed data.\r
2150 @retval FALSE This interface is not supported.\r
2151\r
2152**/\r
2153BOOLEAN\r
2154EFIAPI\r
2155Pkcs7Verify (\r
2156 IN CONST UINT8 *P7Data,\r
2157 IN UINTN P7Length,\r
2158 IN CONST UINT8 *TrustedCert,\r
2159 IN UINTN CertLength,\r
2160 IN CONST UINT8 *InData,\r
2161 IN UINTN DataLength\r
2162 )\r
2163{\r
2164 CALL_CRYPTO_SERVICE (Pkcs7Verify, (P7Data, P7Length, TrustedCert, CertLength, InData, DataLength), FALSE);\r
2165}\r
2166\r
2167/**\r
2168 This function receives a PKCS7 formatted signature, and then verifies that\r
2169 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r
2170 leaf signing certificate.\r
2171 Note that this function does not validate the certificate chain.\r
2172\r
2173 Applications for custom EKU's are quite flexible. For example, a policy EKU\r
2174 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r
2175 certificate issued might also contain this EKU, thus constraining the\r
2176 sub-ordinate certificate. Other applications might allow a certificate\r
2177 embedded in a device to specify that other Object Identifiers (OIDs) are\r
2178 present which contains binary data specifying custom capabilities that\r
2179 the device is able to do.\r
2180\r
2181 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r
2182 containing the content block with both the signature,\r
2183 the signer's certificate, and any necessary intermediate\r
2184 certificates.\r
2185 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r
2186 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r
2187 required EKUs that must be present in the signature.\r
2188 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r
2189 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r
2190 must be present in the leaf signer. If it is\r
2191 FALSE, then we will succeed if we find any\r
2192 of the specified EKU's.\r
2193\r
2194 @retval EFI_SUCCESS The required EKUs were found in the signature.\r
2195 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
2196 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r
2197\r
2198**/\r
2199RETURN_STATUS\r
2200EFIAPI\r
2201VerifyEKUsInPkcs7Signature (\r
2202 IN CONST UINT8 *Pkcs7Signature,\r
2203 IN CONST UINT32 SignatureSize,\r
2204 IN CONST CHAR8 *RequiredEKUs[],\r
2205 IN CONST UINT32 RequiredEKUsSize,\r
2206 IN BOOLEAN RequireAllPresent\r
2207 )\r
2208{\r
2209 CALL_CRYPTO_SERVICE (VerifyEKUsInPkcs7Signature, (Pkcs7Signature, SignatureSize, RequiredEKUs, RequiredEKUsSize, RequireAllPresent), FALSE);\r
2210}\r
2211\r
2212\r
2213/**\r
2214 Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r
2215 data could be wrapped in a ContentInfo structure.\r
2216\r
2217 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r
2218 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r
2219\r
2220 Caution: This function may receive untrusted input. So this function will do\r
2221 basic check for PKCS#7 data structure.\r
2222\r
2223 @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r
2224 @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r
2225 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r
2226 It's caller's responsibility to free the buffer with FreePool().\r
2227 @param[out] ContentSize The size of the extracted content in bytes.\r
2228\r
2229 @retval TRUE The P7Data was correctly formatted for processing.\r
2230 @retval FALSE The P7Data was not correctly formatted for processing.\r
2231\r
2232**/\r
2233BOOLEAN\r
2234EFIAPI\r
2235Pkcs7GetAttachedContent (\r
2236 IN CONST UINT8 *P7Data,\r
2237 IN UINTN P7Length,\r
2238 OUT VOID **Content,\r
2239 OUT UINTN *ContentSize\r
2240 )\r
2241{\r
2242 CALL_CRYPTO_SERVICE (Pkcs7GetAttachedContent, (P7Data, P7Length, Content, ContentSize), FALSE);\r
2243}\r
2244\r
2245/**\r
2246 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r
2247 Authenticode Portable Executable Signature Format".\r
2248\r
2249 If AuthData is NULL, then return FALSE.\r
2250 If ImageHash is NULL, then return FALSE.\r
2251 If this interface is not supported, then return FALSE.\r
2252\r
2253 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2254 PE/COFF image to be verified.\r
2255 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2256 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2257 is used for certificate chain verification.\r
2258 @param[in] CertSize Size of the trusted certificate in bytes.\r
2259 @param[in] ImageHash Pointer to the original image file hash value. The procedure\r
2260 for calculating the image hash value is described in Authenticode\r
2261 specification.\r
2262 @param[in] HashSize Size of Image hash value in bytes.\r
2263\r
2264 @retval TRUE The specified Authenticode Signature is valid.\r
2265 @retval FALSE Invalid Authenticode Signature.\r
2266 @retval FALSE This interface is not supported.\r
2267\r
2268**/\r
2269BOOLEAN\r
2270EFIAPI\r
2271AuthenticodeVerify (\r
2272 IN CONST UINT8 *AuthData,\r
2273 IN UINTN DataSize,\r
2274 IN CONST UINT8 *TrustedCert,\r
2275 IN UINTN CertSize,\r
2276 IN CONST UINT8 *ImageHash,\r
2277 IN UINTN HashSize\r
2278 )\r
2279{\r
2280 CALL_CRYPTO_SERVICE (AuthenticodeVerify, (AuthData, DataSize, TrustedCert, CertSize, ImageHash, HashSize), FALSE);\r
2281}\r
2282\r
2283/**\r
2284 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r
2285 signature.\r
2286\r
2287 If AuthData is NULL, then return FALSE.\r
2288 If this interface is not supported, then return FALSE.\r
2289\r
2290 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2291 PE/COFF image to be verified.\r
2292 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2293 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r
2294 is used for TSA certificate chain verification.\r
2295 @param[in] CertSize Size of the trusted certificate in bytes.\r
2296 @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r
2297 signature is valid.\r
2298\r
2299 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r
2300 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r
2301\r
2302**/\r
2303BOOLEAN\r
2304EFIAPI\r
2305ImageTimestampVerify (\r
2306 IN CONST UINT8 *AuthData,\r
2307 IN UINTN DataSize,\r
2308 IN CONST UINT8 *TsaCert,\r
2309 IN UINTN CertSize,\r
2310 OUT EFI_TIME *SigningTime\r
2311 )\r
2312{\r
2313 CALL_CRYPTO_SERVICE (ImageTimestampVerify, (AuthData, DataSize, TsaCert, CertSize, SigningTime), FALSE);\r
2314}\r
2315\r
2316//=====================================================================================\r
2317// DH Key Exchange Primitive\r
2318//=====================================================================================\r
2319\r
2320/**\r
2321 Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r
2322\r
2323 @return Pointer to the Diffie-Hellman Context that has been initialized.\r
2324 If the allocations fails, DhNew() returns NULL.\r
2325 If the interface is not supported, DhNew() returns NULL.\r
2326\r
2327**/\r
2328VOID *\r
2329EFIAPI\r
2330DhNew (\r
2331 VOID\r
2332 )\r
2333{\r
2334 CALL_CRYPTO_SERVICE (DhNew, (), NULL);\r
2335}\r
2336\r
2337/**\r
2338 Release the specified DH context.\r
2339\r
2340 If the interface is not supported, then ASSERT().\r
2341\r
2342 @param[in] DhContext Pointer to the DH context to be released.\r
2343\r
2344**/\r
2345VOID\r
2346EFIAPI\r
2347DhFree (\r
2348 IN VOID *DhContext\r
2349 )\r
2350{\r
2351 CALL_VOID_CRYPTO_SERVICE (DhFree, (DhContext));\r
2352}\r
2353\r
2354/**\r
2355 Generates DH parameter.\r
2356\r
2357 Given generator g, and length of prime number p in bits, this function generates p,\r
2358 and sets DH context according to value of g and p.\r
2359\r
2360 Before this function can be invoked, pseudorandom number generator must be correctly\r
2361 initialized by RandomSeed().\r
2362\r
2363 If DhContext is NULL, then return FALSE.\r
2364 If Prime is NULL, then return FALSE.\r
2365 If this interface is not supported, then return FALSE.\r
2366\r
2367 @param[in, out] DhContext Pointer to the DH context.\r
2368 @param[in] Generator Value of generator.\r
2369 @param[in] PrimeLength Length in bits of prime to be generated.\r
2370 @param[out] Prime Pointer to the buffer to receive the generated prime number.\r
2371\r
2372 @retval TRUE DH parameter generation succeeded.\r
2373 @retval FALSE Value of Generator is not supported.\r
2374 @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r
2375 @retval FALSE This interface is not supported.\r
2376\r
2377**/\r
2378BOOLEAN\r
2379EFIAPI\r
2380DhGenerateParameter (\r
2381 IN OUT VOID *DhContext,\r
2382 IN UINTN Generator,\r
2383 IN UINTN PrimeLength,\r
2384 OUT UINT8 *Prime\r
2385 )\r
2386{\r
2387 CALL_CRYPTO_SERVICE (DhGenerateParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);\r
2388}\r
2389\r
2390/**\r
2391 Sets generator and prime parameters for DH.\r
2392\r
2393 Given generator g, and prime number p, this function and sets DH\r
2394 context accordingly.\r
2395\r
2396 If DhContext is NULL, then return FALSE.\r
2397 If Prime is NULL, then return FALSE.\r
2398 If this interface is not supported, then return FALSE.\r
2399\r
2400 @param[in, out] DhContext Pointer to the DH context.\r
2401 @param[in] Generator Value of generator.\r
2402 @param[in] PrimeLength Length in bits of prime to be generated.\r
2403 @param[in] Prime Pointer to the prime number.\r
2404\r
2405 @retval TRUE DH parameter setting succeeded.\r
2406 @retval FALSE Value of Generator is not supported.\r
2407 @retval FALSE Value of Generator is not suitable for the Prime.\r
2408 @retval FALSE Value of Prime is not a prime number.\r
2409 @retval FALSE Value of Prime is not a safe prime number.\r
2410 @retval FALSE This interface is not supported.\r
2411\r
2412**/\r
2413BOOLEAN\r
2414EFIAPI\r
2415DhSetParameter (\r
2416 IN OUT VOID *DhContext,\r
2417 IN UINTN Generator,\r
2418 IN UINTN PrimeLength,\r
2419 IN CONST UINT8 *Prime\r
2420 )\r
2421{\r
2422 CALL_CRYPTO_SERVICE (DhSetParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);\r
2423}\r
2424\r
2425/**\r
2426 Generates DH public key.\r
2427\r
2428 This function generates random secret exponent, and computes the public key, which is\r
2429 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r
2430 If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r
2431 PublicKeySize is set to the required buffer size to obtain the public key.\r
2432\r
2433 If DhContext is NULL, then return FALSE.\r
2434 If PublicKeySize is NULL, then return FALSE.\r
2435 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r
2436 If this interface is not supported, then return FALSE.\r
2437\r
2438 @param[in, out] DhContext Pointer to the DH context.\r
2439 @param[out] PublicKey Pointer to the buffer to receive generated public key.\r
2440 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r
2441 On output, the size of data returned in PublicKey buffer in bytes.\r
2442\r
2443 @retval TRUE DH public key generation succeeded.\r
2444 @retval FALSE DH public key generation failed.\r
2445 @retval FALSE PublicKeySize is not large enough.\r
2446 @retval FALSE This interface is not supported.\r
2447\r
2448**/\r
2449BOOLEAN\r
2450EFIAPI\r
2451DhGenerateKey (\r
2452 IN OUT VOID *DhContext,\r
2453 OUT UINT8 *PublicKey,\r
2454 IN OUT UINTN *PublicKeySize\r
2455 )\r
2456{\r
2457 CALL_CRYPTO_SERVICE (DhGenerateKey, (DhContext, PublicKey, PublicKeySize), FALSE);\r
2458}\r
2459\r
2460/**\r
2461 Computes exchanged common key.\r
2462\r
2463 Given peer's public key, this function computes the exchanged common key, based on its own\r
2464 context including value of prime modulus and random secret exponent.\r
2465\r
2466 If DhContext is NULL, then return FALSE.\r
2467 If PeerPublicKey is NULL, then return FALSE.\r
2468 If KeySize is NULL, then return FALSE.\r
2469 If Key is NULL, then return FALSE.\r
2470 If KeySize is not large enough, then return FALSE.\r
2471 If this interface is not supported, then return FALSE.\r
2472\r
2473 @param[in, out] DhContext Pointer to the DH context.\r
2474 @param[in] PeerPublicKey Pointer to the peer's public key.\r
2475 @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r
2476 @param[out] Key Pointer to the buffer to receive generated key.\r
2477 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
2478 On output, the size of data returned in Key buffer in bytes.\r
2479\r
2480 @retval TRUE DH exchanged key generation succeeded.\r
2481 @retval FALSE DH exchanged key generation failed.\r
2482 @retval FALSE KeySize is not large enough.\r
2483 @retval FALSE This interface is not supported.\r
2484\r
2485**/\r
2486BOOLEAN\r
2487EFIAPI\r
2488DhComputeKey (\r
2489 IN OUT VOID *DhContext,\r
2490 IN CONST UINT8 *PeerPublicKey,\r
2491 IN UINTN PeerPublicKeySize,\r
2492 OUT UINT8 *Key,\r
2493 IN OUT UINTN *KeySize\r
2494 )\r
2495{\r
2496 CALL_CRYPTO_SERVICE (DhComputeKey, (DhContext, PeerPublicKey, PeerPublicKeySize, Key, KeySize), FALSE);\r
2497}\r
2498\r
2499//=====================================================================================\r
2500// Pseudo-Random Generation Primitive\r
2501//=====================================================================================\r
2502\r
2503/**\r
2504 Sets up the seed value for the pseudorandom number generator.\r
2505\r
2506 This function sets up the seed value for the pseudorandom number generator.\r
2507 If Seed is not NULL, then the seed passed in is used.\r
2508 If Seed is NULL, then default seed is used.\r
2509 If this interface is not supported, then return FALSE.\r
2510\r
2511 @param[in] Seed Pointer to seed value.\r
2512 If NULL, default seed is used.\r
2513 @param[in] SeedSize Size of seed value.\r
2514 If Seed is NULL, this parameter is ignored.\r
2515\r
2516 @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r
2517 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r
2518 @retval FALSE This interface is not supported.\r
2519\r
2520**/\r
2521BOOLEAN\r
2522EFIAPI\r
2523RandomSeed (\r
2524 IN CONST UINT8 *Seed OPTIONAL,\r
2525 IN UINTN SeedSize\r
2526 )\r
2527{\r
2528 CALL_CRYPTO_SERVICE (RandomSeed, (Seed, SeedSize), FALSE);\r
2529}\r
2530\r
2531/**\r
2532 Generates a pseudorandom byte stream of the specified size.\r
2533\r
2534 If Output is NULL, then return FALSE.\r
2535 If this interface is not supported, then return FALSE.\r
2536\r
2537 @param[out] Output Pointer to buffer to receive random value.\r
2538 @param[in] Size Size of random bytes to generate.\r
2539\r
2540 @retval TRUE Pseudorandom byte stream generated successfully.\r
2541 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r
2542 @retval FALSE This interface is not supported.\r
2543\r
2544**/\r
2545BOOLEAN\r
2546EFIAPI\r
2547RandomBytes (\r
2548 OUT UINT8 *Output,\r
2549 IN UINTN Size\r
2550 )\r
2551{\r
2552 CALL_CRYPTO_SERVICE (RandomBytes, (Output, Size), FALSE);\r
2553}\r
2554\r
2555//=====================================================================================\r
2556// Key Derivation Function Primitive\r
2557//=====================================================================================\r
2558\r
2559/**\r
2560 Derive key data using HMAC-SHA256 based KDF.\r
2561\r
2562 @param[in] Key Pointer to the user-supplied key.\r
2563 @param[in] KeySize Key size in bytes.\r
2564 @param[in] Salt Pointer to the salt(non-secret) value.\r
2565 @param[in] SaltSize Salt size in bytes.\r
2566 @param[in] Info Pointer to the application specific info.\r
2567 @param[in] InfoSize Info size in bytes.\r
2568 @param[out] Out Pointer to buffer to receive hkdf value.\r
2569 @param[in] OutSize Size of hkdf bytes to generate.\r
2570\r
2571 @retval TRUE Hkdf generated successfully.\r
2572 @retval FALSE Hkdf generation failed.\r
2573\r
2574**/\r
2575BOOLEAN\r
2576EFIAPI\r
2577HkdfSha256ExtractAndExpand (\r
2578 IN CONST UINT8 *Key,\r
2579 IN UINTN KeySize,\r
2580 IN CONST UINT8 *Salt,\r
2581 IN UINTN SaltSize,\r
2582 IN CONST UINT8 *Info,\r
2583 IN UINTN InfoSize,\r
2584 OUT UINT8 *Out,\r
2585 IN UINTN OutSize\r
2586 )\r
2587{\r
2588 CALL_CRYPTO_SERVICE (HkdfSha256ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);\r
2589}\r
2590\r
2591/**\r
2592 Initializes the OpenSSL library.\r
2593\r
2594 This function registers ciphers and digests used directly and indirectly\r
2595 by SSL/TLS, and initializes the readable error messages.\r
2596 This function must be called before any other action takes places.\r
2597\r
2598 @retval TRUE The OpenSSL library has been initialized.\r
2599 @retval FALSE Failed to initialize the OpenSSL library.\r
2600\r
2601**/\r
2602BOOLEAN\r
2603EFIAPI\r
2604TlsInitialize (\r
2605 VOID\r
2606 )\r
2607{\r
2608 CALL_CRYPTO_SERVICE (TlsInitialize, (), FALSE);\r
2609}\r
2610\r
2611/**\r
2612 Free an allocated SSL_CTX object.\r
2613\r
2614 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.\r
2615\r
2616**/\r
2617VOID\r
2618EFIAPI\r
2619TlsCtxFree (\r
2620 IN VOID *TlsCtx\r
2621 )\r
2622{\r
2623 CALL_VOID_CRYPTO_SERVICE (TlsCtxFree, (TlsCtx));\r
2624}\r
2625\r
2626/**\r
2627 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled\r
2628 connections.\r
2629\r
2630 @param[in] MajorVer Major Version of TLS/SSL Protocol.\r
2631 @param[in] MinorVer Minor Version of TLS/SSL Protocol.\r
2632\r
2633 @return Pointer to an allocated SSL_CTX object.\r
2634 If the creation failed, TlsCtxNew() returns NULL.\r
2635\r
2636**/\r
2637VOID *\r
2638EFIAPI\r
2639TlsCtxNew (\r
2640 IN UINT8 MajorVer,\r
2641 IN UINT8 MinorVer\r
2642 )\r
2643{\r
2644 CALL_CRYPTO_SERVICE (TlsCtxNew, (MajorVer, MinorVer), NULL);\r
2645}\r
2646\r
2647/**\r
2648 Free an allocated TLS object.\r
2649\r
2650 This function removes the TLS object pointed to by Tls and frees up the\r
2651 allocated memory. If Tls is NULL, nothing is done.\r
2652\r
2653 @param[in] Tls Pointer to the TLS object to be freed.\r
2654\r
2655**/\r
2656VOID\r
2657EFIAPI\r
2658TlsFree (\r
2659 IN VOID *Tls\r
2660 )\r
2661{\r
2662 CALL_VOID_CRYPTO_SERVICE (TlsFree, (Tls));\r
2663}\r
2664\r
2665/**\r
2666 Create a new TLS object for a connection.\r
2667\r
2668 This function creates a new TLS object for a connection. The new object\r
2669 inherits the setting of the underlying context TlsCtx: connection method,\r
2670 options, verification setting.\r
2671\r
2672 @param[in] TlsCtx Pointer to the SSL_CTX object.\r
2673\r
2674 @return Pointer to an allocated SSL object.\r
2675 If the creation failed, TlsNew() returns NULL.\r
2676\r
2677**/\r
2678VOID *\r
2679EFIAPI\r
2680TlsNew (\r
2681 IN VOID *TlsCtx\r
2682 )\r
2683{\r
2684 CALL_CRYPTO_SERVICE (TlsNew, (TlsCtx), NULL);\r
2685}\r
2686\r
2687/**\r
2688 Checks if the TLS handshake was done.\r
2689\r
2690 This function will check if the specified TLS handshake was done.\r
2691\r
2692 @param[in] Tls Pointer to the TLS object for handshake state checking.\r
2693\r
2694 @retval TRUE The TLS handshake was done.\r
2695 @retval FALSE The TLS handshake was not done.\r
2696\r
2697**/\r
2698BOOLEAN\r
2699EFIAPI\r
2700TlsInHandshake (\r
2701 IN VOID *Tls\r
2702 )\r
2703{\r
2704 CALL_CRYPTO_SERVICE (TlsInHandshake, (Tls), FALSE);\r
2705}\r
2706\r
2707/**\r
2708 Perform a TLS/SSL handshake.\r
2709\r
2710 This function will perform a TLS/SSL handshake.\r
2711\r
2712 @param[in] Tls Pointer to the TLS object for handshake operation.\r
2713 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.\r
2714 @param[in] BufferInSize Packet size in bytes for the most recently received TLS\r
2715 Handshake packet.\r
2716 @param[out] BufferOut Pointer to the buffer to hold the built packet.\r
2717 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is\r
2718 the buffer size provided by the caller. On output, it\r
2719 is the buffer size in fact needed to contain the\r
2720 packet.\r
2721\r
2722 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
2723 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
2724 Tls is NULL.\r
2725 BufferIn is NULL but BufferInSize is NOT 0.\r
2726 BufferInSize is 0 but BufferIn is NOT NULL.\r
2727 BufferOutSize is NULL.\r
2728 BufferOut is NULL if *BufferOutSize is not zero.\r
2729 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.\r
2730 @retval EFI_ABORTED Something wrong during handshake.\r
2731\r
2732**/\r
2733EFI_STATUS\r
2734EFIAPI\r
2735TlsDoHandshake (\r
2736 IN VOID *Tls,\r
2737 IN UINT8 *BufferIn, OPTIONAL\r
2738 IN UINTN BufferInSize, OPTIONAL\r
2739 OUT UINT8 *BufferOut, OPTIONAL\r
2740 IN OUT UINTN *BufferOutSize\r
2741 )\r
2742{\r
2743 CALL_CRYPTO_SERVICE (TlsDoHandshake, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);\r
2744}\r
2745\r
2746/**\r
2747 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,\r
2748 TLS session has errors and the response packet needs to be Alert message based on error type.\r
2749\r
2750 @param[in] Tls Pointer to the TLS object for state checking.\r
2751 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.\r
2752 @param[in] BufferInSize Packet size in bytes for the most recently received TLS\r
2753 Alert packet.\r
2754 @param[out] BufferOut Pointer to the buffer to hold the built packet.\r
2755 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is\r
2756 the buffer size provided by the caller. On output, it\r
2757 is the buffer size in fact needed to contain the\r
2758 packet.\r
2759\r
2760 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
2761 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
2762 Tls is NULL.\r
2763 BufferIn is NULL but BufferInSize is NOT 0.\r
2764 BufferInSize is 0 but BufferIn is NOT NULL.\r
2765 BufferOutSize is NULL.\r
2766 BufferOut is NULL if *BufferOutSize is not zero.\r
2767 @retval EFI_ABORTED An error occurred.\r
2768 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.\r
2769\r
2770**/\r
2771EFI_STATUS\r
2772EFIAPI\r
2773TlsHandleAlert (\r
2774 IN VOID *Tls,\r
2775 IN UINT8 *BufferIn, OPTIONAL\r
2776 IN UINTN BufferInSize, OPTIONAL\r
2777 OUT UINT8 *BufferOut, OPTIONAL\r
2778 IN OUT UINTN *BufferOutSize\r
2779 )\r
2780{\r
2781 CALL_CRYPTO_SERVICE (TlsHandleAlert, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);\r
2782}\r
2783\r
2784/**\r
2785 Build the CloseNotify packet.\r
2786\r
2787 @param[in] Tls Pointer to the TLS object for state checking.\r
2788 @param[in, out] Buffer Pointer to the buffer to hold the built packet.\r
2789 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is\r
2790 the buffer size provided by the caller. On output, it\r
2791 is the buffer size in fact needed to contain the\r
2792 packet.\r
2793\r
2794 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
2795 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
2796 Tls is NULL.\r
2797 BufferSize is NULL.\r
2798 Buffer is NULL if *BufferSize is not zero.\r
2799 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.\r
2800\r
2801**/\r
2802EFI_STATUS\r
2803EFIAPI\r
2804TlsCloseNotify (\r
2805 IN VOID *Tls,\r
2806 IN OUT UINT8 *Buffer,\r
2807 IN OUT UINTN *BufferSize\r
2808 )\r
2809{\r
2810 CALL_CRYPTO_SERVICE (TlsCloseNotify, (Tls, Buffer, BufferSize), EFI_UNSUPPORTED);\r
2811}\r
2812\r
2813/**\r
2814 Attempts to read bytes from one TLS object and places the data in Buffer.\r
2815\r
2816 This function will attempt to read BufferSize bytes from the TLS object\r
2817 and places the data in Buffer.\r
2818\r
2819 @param[in] Tls Pointer to the TLS object.\r
2820 @param[in,out] Buffer Pointer to the buffer to store the data.\r
2821 @param[in] BufferSize The size of Buffer in bytes.\r
2822\r
2823 @retval >0 The amount of data successfully read from the TLS object.\r
2824 @retval <=0 No data was successfully read.\r
2825\r
2826**/\r
2827INTN\r
2828EFIAPI\r
2829TlsCtrlTrafficOut (\r
2830 IN VOID *Tls,\r
2831 IN OUT VOID *Buffer,\r
2832 IN UINTN BufferSize\r
2833 )\r
2834{\r
2835 CALL_CRYPTO_SERVICE (TlsCtrlTrafficOut, (Tls, Buffer, BufferSize), 0);\r
2836}\r
2837\r
2838/**\r
2839 Attempts to write data from the buffer to TLS object.\r
2840\r
2841 This function will attempt to write BufferSize bytes data from the Buffer\r
2842 to the TLS object.\r
2843\r
2844 @param[in] Tls Pointer to the TLS object.\r
2845 @param[in] Buffer Pointer to the data buffer.\r
2846 @param[in] BufferSize The size of Buffer in bytes.\r
2847\r
2848 @retval >0 The amount of data successfully written to the TLS object.\r
2849 @retval <=0 No data was successfully written.\r
2850\r
2851**/\r
2852INTN\r
2853EFIAPI\r
2854TlsCtrlTrafficIn (\r
2855 IN VOID *Tls,\r
2856 IN VOID *Buffer,\r
2857 IN UINTN BufferSize\r
2858 )\r
2859{\r
2860 CALL_CRYPTO_SERVICE (TlsCtrlTrafficIn, (Tls, Buffer, BufferSize), 0);\r
2861}\r
2862\r
2863/**\r
2864 Attempts to read bytes from the specified TLS connection into the buffer.\r
2865\r
2866 This function tries to read BufferSize bytes data from the specified TLS\r
2867 connection into the Buffer.\r
2868\r
2869 @param[in] Tls Pointer to the TLS connection for data reading.\r
2870 @param[in,out] Buffer Pointer to the data buffer.\r
2871 @param[in] BufferSize The size of Buffer in bytes.\r
2872\r
2873 @retval >0 The read operation was successful, and return value is the\r
2874 number of bytes actually read from the TLS connection.\r
2875 @retval <=0 The read operation was not successful.\r
2876\r
2877**/\r
2878INTN\r
2879EFIAPI\r
2880TlsRead (\r
2881 IN VOID *Tls,\r
2882 IN OUT VOID *Buffer,\r
2883 IN UINTN BufferSize\r
2884 )\r
2885{\r
2886 CALL_CRYPTO_SERVICE (TlsRead, (Tls, Buffer, BufferSize), 0);\r
2887}\r
2888\r
2889/**\r
2890 Attempts to write data to a TLS connection.\r
2891\r
2892 This function tries to write BufferSize bytes data from the Buffer into the\r
2893 specified TLS connection.\r
2894\r
2895 @param[in] Tls Pointer to the TLS connection for data writing.\r
2896 @param[in] Buffer Pointer to the data buffer.\r
2897 @param[in] BufferSize The size of Buffer in bytes.\r
2898\r
2899 @retval >0 The write operation was successful, and return value is the\r
2900 number of bytes actually written to the TLS connection.\r
2901 @retval <=0 The write operation was not successful.\r
2902\r
2903**/\r
2904INTN\r
2905EFIAPI\r
2906TlsWrite (\r
2907 IN VOID *Tls,\r
2908 IN VOID *Buffer,\r
2909 IN UINTN BufferSize\r
2910 )\r
2911{\r
2912 CALL_CRYPTO_SERVICE (TlsWrite, (Tls, Buffer, BufferSize), 0);\r
2913}\r
2914\r
2915/**\r
2916 Set a new TLS/SSL method for a particular TLS object.\r
2917\r
2918 This function sets a new TLS/SSL method for a particular TLS object.\r
2919\r
2920 @param[in] Tls Pointer to a TLS object.\r
2921 @param[in] MajorVer Major Version of TLS/SSL Protocol.\r
2922 @param[in] MinorVer Minor Version of TLS/SSL Protocol.\r
2923\r
2924 @retval EFI_SUCCESS The TLS/SSL method was set successfully.\r
2925 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
2926 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.\r
2927\r
2928**/\r
2929EFI_STATUS\r
2930EFIAPI\r
2931TlsSetVersion (\r
2932 IN VOID *Tls,\r
2933 IN UINT8 MajorVer,\r
2934 IN UINT8 MinorVer\r
2935 )\r
2936{\r
2937 CALL_CRYPTO_SERVICE (TlsSetVersion, (Tls, MajorVer, MinorVer), EFI_UNSUPPORTED);\r
2938}\r
2939\r
2940/**\r
2941 Set TLS object to work in client or server mode.\r
2942\r
2943 This function prepares a TLS object to work in client or server mode.\r
2944\r
2945 @param[in] Tls Pointer to a TLS object.\r
2946 @param[in] IsServer Work in server mode.\r
2947\r
2948 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.\r
2949 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
2950 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.\r
2951\r
2952**/\r
2953EFI_STATUS\r
2954EFIAPI\r
2955TlsSetConnectionEnd (\r
2956 IN VOID *Tls,\r
2957 IN BOOLEAN IsServer\r
2958 )\r
2959{\r
2960 CALL_CRYPTO_SERVICE (TlsSetConnectionEnd, (Tls, IsServer), EFI_UNSUPPORTED);\r
2961}\r
2962\r
2963/**\r
2964 Set the ciphers list to be used by the TLS object.\r
2965\r
2966 This function sets the ciphers for use by a specified TLS object.\r
2967\r
2968 @param[in] Tls Pointer to a TLS object.\r
2969 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16\r
2970 cipher identifier comes from the TLS Cipher Suite\r
2971 Registry of the IANA, interpreting Byte1 and Byte2\r
2972 in network (big endian) byte order.\r
2973 @param[in] CipherNum The number of cipher in the list.\r
2974\r
2975 @retval EFI_SUCCESS The ciphers list was set successfully.\r
2976 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
2977 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.\r
2978 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
2979\r
2980**/\r
2981EFI_STATUS\r
2982EFIAPI\r
2983TlsSetCipherList (\r
2984 IN VOID *Tls,\r
2985 IN UINT16 *CipherId,\r
2986 IN UINTN CipherNum\r
2987 )\r
2988{\r
2989 CALL_CRYPTO_SERVICE (TlsSetCipherList, (Tls, CipherId, CipherNum), EFI_UNSUPPORTED);\r
2990}\r
2991\r
2992/**\r
2993 Set the compression method for TLS/SSL operations.\r
2994\r
2995 This function handles TLS/SSL integrated compression methods.\r
2996\r
2997 @param[in] CompMethod The compression method ID.\r
2998\r
2999 @retval EFI_SUCCESS The compression method for the communication was\r
3000 set successfully.\r
3001 @retval EFI_UNSUPPORTED Unsupported compression method.\r
3002\r
3003**/\r
3004EFI_STATUS\r
3005EFIAPI\r
3006TlsSetCompressionMethod (\r
3007 IN UINT8 CompMethod\r
3008 )\r
3009{\r
3010 CALL_CRYPTO_SERVICE (TlsSetCompressionMethod, (CompMethod), EFI_UNSUPPORTED);\r
3011}\r
3012\r
3013/**\r
3014 Set peer certificate verification mode for the TLS connection.\r
3015\r
3016 This function sets the verification mode flags for the TLS connection.\r
3017\r
3018 @param[in] Tls Pointer to the TLS object.\r
3019 @param[in] VerifyMode A set of logically or'ed verification mode flags.\r
3020\r
3021**/\r
3022VOID\r
3023EFIAPI\r
3024TlsSetVerify (\r
3025 IN VOID *Tls,\r
3026 IN UINT32 VerifyMode\r
3027 )\r
3028{\r
3029 CALL_VOID_CRYPTO_SERVICE (TlsSetVerify, (Tls, VerifyMode));\r
3030}\r
3031\r
3032/**\r
3033 Set the specified host name to be verified.\r
3034\r
3035 @param[in] Tls Pointer to the TLS object.\r
3036 @param[in] Flags The setting flags during the validation.\r
3037 @param[in] HostName The specified host name to be verified.\r
3038\r
3039 @retval EFI_SUCCESS The HostName setting was set successfully.\r
3040 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3041 @retval EFI_ABORTED Invalid HostName setting.\r
3042\r
3043**/\r
3044EFI_STATUS\r
3045EFIAPI\r
3046TlsSetVerifyHost (\r
3047 IN VOID *Tls,\r
3048 IN UINT32 Flags,\r
3049 IN CHAR8 *HostName\r
3050 )\r
3051{\r
3052 CALL_CRYPTO_SERVICE (TlsSetVerifyHost, (Tls, Flags, HostName), EFI_UNSUPPORTED);\r
3053}\r
3054\r
3055/**\r
3056 Sets a TLS/SSL session ID to be used during TLS/SSL connect.\r
3057\r
3058 This function sets a session ID to be used when the TLS/SSL connection is\r
3059 to be established.\r
3060\r
3061 @param[in] Tls Pointer to the TLS object.\r
3062 @param[in] SessionId Session ID data used for session resumption.\r
3063 @param[in] SessionIdLen Length of Session ID in bytes.\r
3064\r
3065 @retval EFI_SUCCESS Session ID was set successfully.\r
3066 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3067 @retval EFI_UNSUPPORTED No available session for ID setting.\r
3068\r
3069**/\r
3070EFI_STATUS\r
3071EFIAPI\r
3072TlsSetSessionId (\r
3073 IN VOID *Tls,\r
3074 IN UINT8 *SessionId,\r
3075 IN UINT16 SessionIdLen\r
3076 )\r
3077{\r
3078 CALL_CRYPTO_SERVICE (TlsSetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);\r
3079}\r
3080\r
3081/**\r
3082 Adds the CA to the cert store when requesting Server or Client authentication.\r
3083\r
3084 This function adds the CA certificate to the list of CAs when requesting\r
3085 Server or Client authentication for the chosen TLS connection.\r
3086\r
3087 @param[in] Tls Pointer to the TLS object.\r
3088 @param[in] Data Pointer to the data buffer of a DER-encoded binary\r
3089 X.509 certificate or PEM-encoded X.509 certificate.\r
3090 @param[in] DataSize The size of data buffer in bytes.\r
3091\r
3092 @retval EFI_SUCCESS The operation succeeded.\r
3093 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3094 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.\r
3095 @retval EFI_ABORTED Invalid X.509 certificate.\r
3096\r
3097**/\r
3098EFI_STATUS\r
3099EFIAPI\r
3100TlsSetCaCertificate (\r
3101 IN VOID *Tls,\r
3102 IN VOID *Data,\r
3103 IN UINTN DataSize\r
3104 )\r
3105{\r
3106 CALL_CRYPTO_SERVICE (TlsSetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3107}\r
3108\r
3109/**\r
3110 Loads the local public certificate into the specified TLS object.\r
3111\r
3112 This function loads the X.509 certificate into the specified TLS object\r
3113 for TLS negotiation.\r
3114\r
3115 @param[in] Tls Pointer to the TLS object.\r
3116 @param[in] Data Pointer to the data buffer of a DER-encoded binary\r
3117 X.509 certificate or PEM-encoded X.509 certificate.\r
3118 @param[in] DataSize The size of data buffer in bytes.\r
3119\r
3120 @retval EFI_SUCCESS The operation succeeded.\r
3121 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3122 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.\r
3123 @retval EFI_ABORTED Invalid X.509 certificate.\r
3124\r
3125**/\r
3126EFI_STATUS\r
3127EFIAPI\r
3128TlsSetHostPublicCert (\r
3129 IN VOID *Tls,\r
3130 IN VOID *Data,\r
3131 IN UINTN DataSize\r
3132 )\r
3133{\r
3134 CALL_CRYPTO_SERVICE (TlsSetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3135}\r
3136\r
3137/**\r
3138 Adds the local private key to the specified TLS object.\r
3139\r
3140 This function adds the local private key (PEM-encoded RSA or PKCS#8 private\r
3141 key) into the specified TLS object for TLS negotiation.\r
3142\r
3143 @param[in] Tls Pointer to the TLS object.\r
3144 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA\r
3145 or PKCS#8 private key.\r
3146 @param[in] DataSize The size of data buffer in bytes.\r
3147\r
3148 @retval EFI_SUCCESS The operation succeeded.\r
3149 @retval EFI_UNSUPPORTED This function is not supported.\r
3150 @retval EFI_ABORTED Invalid private key data.\r
3151\r
3152**/\r
3153EFI_STATUS\r
3154EFIAPI\r
3155TlsSetHostPrivateKey (\r
3156 IN VOID *Tls,\r
3157 IN VOID *Data,\r
3158 IN UINTN DataSize\r
3159 )\r
3160{\r
3161 CALL_CRYPTO_SERVICE (TlsSetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3162}\r
3163\r
3164/**\r
3165 Adds the CA-supplied certificate revocation list for certificate validation.\r
3166\r
3167 This function adds the CA-supplied certificate revocation list data for\r
3168 certificate validity checking.\r
3169\r
3170 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.\r
3171 @param[in] DataSize The size of data buffer in bytes.\r
3172\r
3173 @retval EFI_SUCCESS The operation succeeded.\r
3174 @retval EFI_UNSUPPORTED This function is not supported.\r
3175 @retval EFI_ABORTED Invalid CRL data.\r
3176\r
3177**/\r
3178EFI_STATUS\r
3179EFIAPI\r
3180TlsSetCertRevocationList (\r
3181 IN VOID *Data,\r
3182 IN UINTN DataSize\r
3183 )\r
3184{\r
3185 CALL_CRYPTO_SERVICE (TlsSetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);\r
3186}\r
3187\r
3188/**\r
3189 Gets the protocol version used by the specified TLS connection.\r
3190\r
3191 This function returns the protocol version used by the specified TLS\r
3192 connection.\r
3193\r
3194 If Tls is NULL, then ASSERT().\r
3195\r
3196 @param[in] Tls Pointer to the TLS object.\r
3197\r
3198 @return The protocol version of the specified TLS connection.\r
3199\r
3200**/\r
3201UINT16\r
3202EFIAPI\r
3203TlsGetVersion (\r
3204 IN VOID *Tls\r
3205 )\r
3206{\r
3207 CALL_CRYPTO_SERVICE (TlsGetVersion, (Tls), 0);\r
3208}\r
3209\r
3210/**\r
3211 Gets the connection end of the specified TLS connection.\r
3212\r
3213 This function returns the connection end (as client or as server) used by\r
3214 the specified TLS connection.\r
3215\r
3216 If Tls is NULL, then ASSERT().\r
3217\r
3218 @param[in] Tls Pointer to the TLS object.\r
3219\r
3220 @return The connection end used by the specified TLS connection.\r
3221\r
3222**/\r
3223UINT8\r
3224EFIAPI\r
3225TlsGetConnectionEnd (\r
3226 IN VOID *Tls\r
3227 )\r
3228{\r
3229 CALL_CRYPTO_SERVICE (TlsGetConnectionEnd, (Tls), 0);\r
3230}\r
3231\r
3232/**\r
3233 Gets the cipher suite used by the specified TLS connection.\r
3234\r
3235 This function returns current cipher suite used by the specified\r
3236 TLS connection.\r
3237\r
3238 @param[in] Tls Pointer to the TLS object.\r
3239 @param[in,out] CipherId The cipher suite used by the TLS object.\r
3240\r
3241 @retval EFI_SUCCESS The cipher suite was returned successfully.\r
3242 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3243 @retval EFI_UNSUPPORTED Unsupported cipher suite.\r
3244\r
3245**/\r
3246EFI_STATUS\r
3247EFIAPI\r
3248TlsGetCurrentCipher (\r
3249 IN VOID *Tls,\r
3250 IN OUT UINT16 *CipherId\r
3251 )\r
3252{\r
3253 CALL_CRYPTO_SERVICE (TlsGetCurrentCipher, (Tls, CipherId), EFI_UNSUPPORTED);\r
3254}\r
3255\r
3256/**\r
3257 Gets the compression methods used by the specified TLS connection.\r
3258\r
3259 This function returns current integrated compression methods used by\r
3260 the specified TLS connection.\r
3261\r
3262 @param[in] Tls Pointer to the TLS object.\r
3263 @param[in,out] CompressionId The current compression method used by\r
3264 the TLS object.\r
3265\r
3266 @retval EFI_SUCCESS The compression method was returned successfully.\r
3267 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3268 @retval EFI_ABORTED Invalid Compression method.\r
3269 @retval EFI_UNSUPPORTED This function is not supported.\r
3270\r
3271**/\r
3272EFI_STATUS\r
3273EFIAPI\r
3274TlsGetCurrentCompressionId (\r
3275 IN VOID *Tls,\r
3276 IN OUT UINT8 *CompressionId\r
3277 )\r
3278{\r
3279 CALL_CRYPTO_SERVICE (TlsGetCurrentCompressionId, (Tls, CompressionId), EFI_UNSUPPORTED);\r
3280}\r
3281\r
3282/**\r
3283 Gets the verification mode currently set in the TLS connection.\r
3284\r
3285 This function returns the peer verification mode currently set in the\r
3286 specified TLS connection.\r
3287\r
3288 If Tls is NULL, then ASSERT().\r
3289\r
3290 @param[in] Tls Pointer to the TLS object.\r
3291\r
3292 @return The verification mode set in the specified TLS connection.\r
3293\r
3294**/\r
3295UINT32\r
3296EFIAPI\r
3297TlsGetVerify (\r
3298 IN VOID *Tls\r
3299 )\r
3300{\r
3301 CALL_CRYPTO_SERVICE (TlsGetVerify, (Tls), 0);\r
3302}\r
3303\r
3304/**\r
3305 Gets the session ID used by the specified TLS connection.\r
3306\r
3307 This function returns the TLS/SSL session ID currently used by the\r
3308 specified TLS connection.\r
3309\r
3310 @param[in] Tls Pointer to the TLS object.\r
3311 @param[in,out] SessionId Buffer to contain the returned session ID.\r
3312 @param[in,out] SessionIdLen The length of Session ID in bytes.\r
3313\r
3314 @retval EFI_SUCCESS The Session ID was returned successfully.\r
3315 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3316 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.\r
3317\r
3318**/\r
3319EFI_STATUS\r
3320EFIAPI\r
3321TlsGetSessionId (\r
3322 IN VOID *Tls,\r
3323 IN OUT UINT8 *SessionId,\r
3324 IN OUT UINT16 *SessionIdLen\r
3325 )\r
3326{\r
3327 CALL_CRYPTO_SERVICE (TlsGetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);\r
3328}\r
3329\r
3330/**\r
3331 Gets the client random data used in the specified TLS connection.\r
3332\r
3333 This function returns the TLS/SSL client random data currently used in\r
3334 the specified TLS connection.\r
3335\r
3336 @param[in] Tls Pointer to the TLS object.\r
3337 @param[in,out] ClientRandom Buffer to contain the returned client\r
3338 random data (32 bytes).\r
3339\r
3340**/\r
3341VOID\r
3342EFIAPI\r
3343TlsGetClientRandom (\r
3344 IN VOID *Tls,\r
3345 IN OUT UINT8 *ClientRandom\r
3346 )\r
3347{\r
3348 CALL_VOID_CRYPTO_SERVICE (TlsGetClientRandom, (Tls, ClientRandom));\r
3349}\r
3350\r
3351/**\r
3352 Gets the server random data used in the specified TLS connection.\r
3353\r
3354 This function returns the TLS/SSL server random data currently used in\r
3355 the specified TLS connection.\r
3356\r
3357 @param[in] Tls Pointer to the TLS object.\r
3358 @param[in,out] ServerRandom Buffer to contain the returned server\r
3359 random data (32 bytes).\r
3360\r
3361**/\r
3362VOID\r
3363EFIAPI\r
3364TlsGetServerRandom (\r
3365 IN VOID *Tls,\r
3366 IN OUT UINT8 *ServerRandom\r
3367 )\r
3368{\r
3369 CALL_VOID_CRYPTO_SERVICE (TlsGetServerRandom, (Tls, ServerRandom));\r
3370}\r
3371\r
3372/**\r
3373 Gets the master key data used in the specified TLS connection.\r
3374\r
3375 This function returns the TLS/SSL master key material currently used in\r
3376 the specified TLS connection.\r
3377\r
3378 @param[in] Tls Pointer to the TLS object.\r
3379 @param[in,out] KeyMaterial Buffer to contain the returned key material.\r
3380\r
3381 @retval EFI_SUCCESS Key material was returned successfully.\r
3382 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3383 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.\r
3384\r
3385**/\r
3386EFI_STATUS\r
3387EFIAPI\r
3388TlsGetKeyMaterial (\r
3389 IN VOID *Tls,\r
3390 IN OUT UINT8 *KeyMaterial\r
3391 )\r
3392{\r
3393 CALL_CRYPTO_SERVICE (TlsGetKeyMaterial, (Tls, KeyMaterial), EFI_UNSUPPORTED);\r
3394}\r
3395\r
3396/**\r
3397 Gets the CA Certificate from the cert store.\r
3398\r
3399 This function returns the CA certificate for the chosen\r
3400 TLS connection.\r
3401\r
3402 @param[in] Tls Pointer to the TLS object.\r
3403 @param[out] Data Pointer to the data buffer to receive the CA\r
3404 certificate data sent to the client.\r
3405 @param[in,out] DataSize The size of data buffer in bytes.\r
3406\r
3407 @retval EFI_SUCCESS The operation succeeded.\r
3408 @retval EFI_UNSUPPORTED This function is not supported.\r
3409 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3410\r
3411**/\r
3412EFI_STATUS\r
3413EFIAPI\r
3414TlsGetCaCertificate (\r
3415 IN VOID *Tls,\r
3416 OUT VOID *Data,\r
3417 IN OUT UINTN *DataSize\r
3418 )\r
3419{\r
3420 CALL_CRYPTO_SERVICE (TlsGetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3421}\r
3422\r
3423/**\r
3424 Gets the local public Certificate set in the specified TLS object.\r
3425\r
3426 This function returns the local public certificate which was currently set\r
3427 in the specified TLS object.\r
3428\r
3429 @param[in] Tls Pointer to the TLS object.\r
3430 @param[out] Data Pointer to the data buffer to receive the local\r
3431 public certificate.\r
3432 @param[in,out] DataSize The size of data buffer in bytes.\r
3433\r
3434 @retval EFI_SUCCESS The operation succeeded.\r
3435 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
3436 @retval EFI_NOT_FOUND The certificate is not found.\r
3437 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3438\r
3439**/\r
3440EFI_STATUS\r
3441EFIAPI\r
3442TlsGetHostPublicCert (\r
3443 IN VOID *Tls,\r
3444 OUT VOID *Data,\r
3445 IN OUT UINTN *DataSize\r
3446 )\r
3447{\r
3448 CALL_CRYPTO_SERVICE (TlsGetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3449}\r
3450\r
3451/**\r
3452 Gets the local private key set in the specified TLS object.\r
3453\r
3454 This function returns the local private key data which was currently set\r
3455 in the specified TLS object.\r
3456\r
3457 @param[in] Tls Pointer to the TLS object.\r
3458 @param[out] Data Pointer to the data buffer to receive the local\r
3459 private key data.\r
3460 @param[in,out] DataSize The size of data buffer in bytes.\r
3461\r
3462 @retval EFI_SUCCESS The operation succeeded.\r
3463 @retval EFI_UNSUPPORTED This function is not supported.\r
3464 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3465\r
3466**/\r
3467EFI_STATUS\r
3468EFIAPI\r
3469TlsGetHostPrivateKey (\r
3470 IN VOID *Tls,\r
3471 OUT VOID *Data,\r
3472 IN OUT UINTN *DataSize\r
3473 )\r
3474{\r
3475 CALL_CRYPTO_SERVICE (TlsGetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
3476}\r
3477\r
3478/**\r
3479 Gets the CA-supplied certificate revocation list data set in the specified\r
3480 TLS object.\r
3481\r
3482 This function returns the CA-supplied certificate revocation list data which\r
3483 was currently set in the specified TLS object.\r
3484\r
3485 @param[out] Data Pointer to the data buffer to receive the CRL data.\r
3486 @param[in,out] DataSize The size of data buffer in bytes.\r
3487\r
3488 @retval EFI_SUCCESS The operation succeeded.\r
3489 @retval EFI_UNSUPPORTED This function is not supported.\r
3490 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
3491\r
3492**/\r
3493EFI_STATUS\r
3494EFIAPI\r
3495TlsGetCertRevocationList (\r
3496 OUT VOID *Data,\r
3497 IN OUT UINTN *DataSize\r
3498 )\r
3499{\r
3500 CALL_CRYPTO_SERVICE (TlsGetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);\r
3501}\r