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