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