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