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