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