]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Driver/Crypto.c
1cd5923ce228d1cda3a87ee9c5a5f27b3aff8532
[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 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use.
1281
1282 If this interface is not supported, then return NULL.
1283
1284 @return Pointer to the HMAC_CTX context that has been initialized.
1285 If the allocations fails, HmacSha1New() returns NULL.
1286 @return NULL This interface is not supported.
1287
1288 **/
1289 VOID *
1290 EFIAPI
1291 CryptoServiceHmacSha1New (
1292 VOID
1293 )
1294 {
1295 return CALL_BASECRYPTLIB (HmacSha1.Services.New, HmacSha1New, (), NULL);
1296 }
1297
1298 /**
1299 Release the specified HMAC_CTX context.
1300
1301 If this interface is not supported, then do nothing.
1302
1303 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.
1304
1305 **/
1306 VOID
1307 EFIAPI
1308 CryptoServiceHmacSha1Free (
1309 IN VOID *HmacSha1Ctx
1310 )
1311 {
1312 CALL_VOID_BASECRYPTLIB (HmacSha1.Services.Free, HmacSha1Free, (HmacSha1Ctx));
1313 }
1314
1315 /**
1316 Set user-supplied key for subsequent use. It must be done before any
1317 calling to HmacSha1Update().
1318
1319 If HmacSha1Context is NULL, then return FALSE.
1320 If this interface is not supported, then return FALSE.
1321
1322 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context.
1323 @param[in] Key Pointer to the user-supplied key.
1324 @param[in] KeySize Key size in bytes.
1325
1326 @retval TRUE The Key is set successfully.
1327 @retval FALSE The Key is set unsuccessfully.
1328 @retval FALSE This interface is not supported.
1329
1330 **/
1331 BOOLEAN
1332 EFIAPI
1333 CryptoServiceHmacSha1SetKey (
1334 OUT VOID *HmacSha1Context,
1335 IN CONST UINT8 *Key,
1336 IN UINTN KeySize
1337 )
1338 {
1339 return CALL_BASECRYPTLIB (HmacSha1.Services.SetKey, HmacSha1SetKey, (HmacSha1Context, Key, KeySize), FALSE);
1340 }
1341
1342 /**
1343 Makes a copy of an existing HMAC-SHA1 context.
1344
1345 If HmacSha1Context is NULL, then return FALSE.
1346 If NewHmacSha1Context is NULL, then return FALSE.
1347 If this interface is not supported, then return FALSE.
1348
1349 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.
1350 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.
1351
1352 @retval TRUE HMAC-SHA1 context copy succeeded.
1353 @retval FALSE HMAC-SHA1 context copy failed.
1354 @retval FALSE This interface is not supported.
1355
1356 **/
1357 BOOLEAN
1358 EFIAPI
1359 CryptoServiceHmacSha1Duplicate (
1360 IN CONST VOID *HmacSha1Context,
1361 OUT VOID *NewHmacSha1Context
1362 )
1363 {
1364 return CALL_BASECRYPTLIB (HmacSha1.Services.Duplicate, HmacSha1Duplicate, (HmacSha1Context, NewHmacSha1Context), FALSE);
1365 }
1366
1367 /**
1368 Digests the input data and updates HMAC-SHA1 context.
1369
1370 This function performs HMAC-SHA1 digest on a data buffer of the specified size.
1371 It can be called multiple times to compute the digest of long or discontinuous data streams.
1372 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized by
1373 HmacSha1Final(). Behavior with invalid context is undefined.
1374
1375 If HmacSha1Context is NULL, then return FALSE.
1376 If this interface is not supported, then return FALSE.
1377
1378 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1379 @param[in] Data Pointer to the buffer containing the data to be digested.
1380 @param[in] DataSize Size of Data buffer in bytes.
1381
1382 @retval TRUE HMAC-SHA1 data digest succeeded.
1383 @retval FALSE HMAC-SHA1 data digest failed.
1384 @retval FALSE This interface is not supported.
1385
1386 **/
1387 BOOLEAN
1388 EFIAPI
1389 CryptoServiceHmacSha1Update (
1390 IN OUT VOID *HmacSha1Context,
1391 IN CONST VOID *Data,
1392 IN UINTN DataSize
1393 )
1394 {
1395 return CALL_BASECRYPTLIB (HmacSha1.Services.Update, HmacSha1Update, (HmacSha1Context, Data, DataSize), FALSE);
1396 }
1397
1398 /**
1399 Completes computation of the HMAC-SHA1 digest value.
1400
1401 This function completes HMAC-SHA1 hash computation and retrieves the digest value into
1402 the specified memory. After this function has been called, the HMAC-SHA1 context cannot
1403 be used again.
1404 HMAC-SHA1 context should be initialized by HmacSha1New(), and should not be finalized
1405 by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.
1406
1407 If HmacSha1Context is NULL, then return FALSE.
1408 If HmacValue is NULL, then return FALSE.
1409 If this interface is not supported, then return FALSE.
1410
1411 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.
1412 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest
1413 value (20 bytes).
1414
1415 @retval TRUE HMAC-SHA1 digest computation succeeded.
1416 @retval FALSE HMAC-SHA1 digest computation failed.
1417 @retval FALSE This interface is not supported.
1418
1419 **/
1420 BOOLEAN
1421 EFIAPI
1422 CryptoServiceHmacSha1Final (
1423 IN OUT VOID *HmacSha1Context,
1424 OUT UINT8 *HmacValue
1425 )
1426 {
1427 return CALL_BASECRYPTLIB (HmacSha1.Services.Final, HmacSha1Final, (HmacSha1Context, HmacValue), FALSE);
1428 }
1429
1430 /**
1431 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.
1432
1433 @return Pointer to the HMAC_CTX context that has been initialized.
1434 If the allocations fails, HmacSha256New() returns NULL.
1435
1436 **/
1437 VOID *
1438 EFIAPI
1439 CryptoServiceHmacSha256New (
1440 VOID
1441 )
1442 {
1443 return CALL_BASECRYPTLIB (HmacSha256.Services.New, HmacSha256New, (), NULL);
1444 }
1445
1446 /**
1447 Release the specified HMAC_CTX context.
1448
1449 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.
1450
1451 **/
1452 VOID
1453 EFIAPI
1454 CryptoServiceHmacSha256Free (
1455 IN VOID *HmacSha256Ctx
1456 )
1457 {
1458 CALL_VOID_BASECRYPTLIB (HmacSha256.Services.Free, HmacSha256Free, (HmacSha256Ctx));
1459 }
1460
1461 /**
1462 Set user-supplied key for subsequent use. It must be done before any
1463 calling to HmacSha256Update().
1464
1465 If HmacSha256Context is NULL, then return FALSE.
1466 If this interface is not supported, then return FALSE.
1467
1468 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.
1469 @param[in] Key Pointer to the user-supplied key.
1470 @param[in] KeySize Key size in bytes.
1471
1472 @retval TRUE The Key is set successfully.
1473 @retval FALSE The Key is set unsuccessfully.
1474 @retval FALSE This interface is not supported.
1475
1476 **/
1477 BOOLEAN
1478 EFIAPI
1479 CryptoServiceHmacSha256SetKey (
1480 OUT VOID *HmacSha256Context,
1481 IN CONST UINT8 *Key,
1482 IN UINTN KeySize
1483 )
1484 {
1485 return CALL_BASECRYPTLIB (HmacSha256.Services.SetKey, HmacSha256SetKey, (HmacSha256Context, Key, KeySize), FALSE);
1486 }
1487
1488 /**
1489 Makes a copy of an existing HMAC-SHA256 context.
1490
1491 If HmacSha256Context is NULL, then return FALSE.
1492 If NewHmacSha256Context is NULL, then return FALSE.
1493 If this interface is not supported, then return FALSE.
1494
1495 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.
1496 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.
1497
1498 @retval TRUE HMAC-SHA256 context copy succeeded.
1499 @retval FALSE HMAC-SHA256 context copy failed.
1500 @retval FALSE This interface is not supported.
1501
1502 **/
1503 BOOLEAN
1504 EFIAPI
1505 CryptoServiceHmacSha256Duplicate (
1506 IN CONST VOID *HmacSha256Context,
1507 OUT VOID *NewHmacSha256Context
1508 )
1509 {
1510 return CALL_BASECRYPTLIB (HmacSha256.Services.Duplicate, HmacSha256Duplicate, (HmacSha256Context, NewHmacSha256Context), FALSE);
1511 }
1512
1513 /**
1514 Digests the input data and updates HMAC-SHA256 context.
1515
1516 This function performs HMAC-SHA256 digest on a data buffer of the specified size.
1517 It can be called multiple times to compute the digest of long or discontinuous data streams.
1518 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1519 by HmacSha256Final(). Behavior with invalid context is undefined.
1520
1521 If HmacSha256Context is NULL, then return FALSE.
1522 If this interface is not supported, then return FALSE.
1523
1524 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1525 @param[in] Data Pointer to the buffer containing the data to be digested.
1526 @param[in] DataSize Size of Data buffer in bytes.
1527
1528 @retval TRUE HMAC-SHA256 data digest succeeded.
1529 @retval FALSE HMAC-SHA256 data digest failed.
1530 @retval FALSE This interface is not supported.
1531
1532 **/
1533 BOOLEAN
1534 EFIAPI
1535 CryptoServiceHmacSha256Update (
1536 IN OUT VOID *HmacSha256Context,
1537 IN CONST VOID *Data,
1538 IN UINTN DataSize
1539 )
1540 {
1541 return CALL_BASECRYPTLIB (HmacSha256.Services.Update, HmacSha256Update, (HmacSha256Context, Data, DataSize), FALSE);
1542 }
1543
1544 /**
1545 Completes computation of the HMAC-SHA256 digest value.
1546
1547 This function completes HMAC-SHA256 hash computation and retrieves the digest value into
1548 the specified memory. After this function has been called, the HMAC-SHA256 context cannot
1549 be used again.
1550 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized
1551 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.
1552
1553 If HmacSha256Context is NULL, then return FALSE.
1554 If HmacValue is NULL, then return FALSE.
1555 If this interface is not supported, then return FALSE.
1556
1557 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.
1558 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest
1559 value (32 bytes).
1560
1561 @retval TRUE HMAC-SHA256 digest computation succeeded.
1562 @retval FALSE HMAC-SHA256 digest computation failed.
1563 @retval FALSE This interface is not supported.
1564
1565 **/
1566 BOOLEAN
1567 EFIAPI
1568 CryptoServiceHmacSha256Final (
1569 IN OUT VOID *HmacSha256Context,
1570 OUT UINT8 *HmacValue
1571 )
1572 {
1573 return CALL_BASECRYPTLIB (HmacSha256.Services.Final, HmacSha256Final, (HmacSha256Context, HmacValue), FALSE);
1574 }
1575
1576 //=====================================================================================
1577 // Symmetric Cryptography Primitive
1578 //=====================================================================================
1579
1580 /**
1581 TDES is deprecated and unsupported any longer.
1582 Keep the function field for binary compability.
1583
1584 @retval 0 This interface is not supported.
1585
1586 **/
1587 UINTN
1588 EFIAPI
1589 DeprecatedCryptoServiceTdesGetContextSize (
1590 VOID
1591 )
1592 {
1593 return BaseCryptLibServiceDeprecated ("TdesGetContextSize"), 0;
1594 }
1595
1596 /**
1597 TDES is deprecated and unsupported any longer.
1598 Keep the function field for binary compability.
1599
1600 @param[out] TdesContext Pointer to TDES context being initialized.
1601 @param[in] Key Pointer to the user-supplied TDES key.
1602 @param[in] KeyLength Length of TDES key in bits.
1603
1604 @retval FALSE This interface is not supported.
1605
1606 **/
1607 BOOLEAN
1608 EFIAPI
1609 DeprecatedCryptoServiceTdesInit (
1610 OUT VOID *TdesContext,
1611 IN CONST UINT8 *Key,
1612 IN UINTN KeyLength
1613 )
1614 {
1615 return BaseCryptLibServiceDeprecated ("TdesInit"), FALSE;
1616 }
1617
1618 /**
1619 TDES is deprecated and unsupported any longer.
1620 Keep the function field for binary compability.
1621
1622 @param[in] TdesContext Pointer to the TDES context.
1623 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1624 @param[in] InputSize Size of the Input buffer in bytes.
1625 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1626
1627 @retval FALSE This interface is not supported.
1628
1629 **/
1630 BOOLEAN
1631 EFIAPI
1632 DeprecatedCryptoServiceTdesEcbEncrypt (
1633 IN VOID *TdesContext,
1634 IN CONST UINT8 *Input,
1635 IN UINTN InputSize,
1636 OUT UINT8 *Output
1637 )
1638 {
1639 return BaseCryptLibServiceDeprecated ("TdesEcbEncrypt"), FALSE;
1640 }
1641
1642 /**
1643 TDES is deprecated and unsupported any longer.
1644 Keep the function field for binary compability.
1645
1646 @param[in] TdesContext Pointer to the TDES context.
1647 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1648 @param[in] InputSize Size of the Input buffer in bytes.
1649 @param[out] Output Pointer to a buffer that receives the TDES decryption output.
1650
1651 @retval FALSE This interface is not supported.
1652
1653 **/
1654 BOOLEAN
1655 EFIAPI
1656 DeprecatedCryptoServiceTdesEcbDecrypt (
1657 IN VOID *TdesContext,
1658 IN CONST UINT8 *Input,
1659 IN UINTN InputSize,
1660 OUT UINT8 *Output
1661 )
1662 {
1663 return BaseCryptLibServiceDeprecated ("TdesEcbDecrypt"), FALSE;
1664 }
1665
1666 /**
1667 TDES is deprecated and unsupported any longer.
1668 Keep the function field for binary compability.
1669
1670 @param[in] TdesContext Pointer to the TDES context.
1671 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1672 @param[in] InputSize Size of the Input buffer in bytes.
1673 @param[in] Ivec Pointer to initialization vector.
1674 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1675
1676 @retval FALSE This interface is not supported.
1677
1678 **/
1679 BOOLEAN
1680 EFIAPI
1681 DeprecatedCryptoServiceTdesCbcEncrypt (
1682 IN VOID *TdesContext,
1683 IN CONST UINT8 *Input,
1684 IN UINTN InputSize,
1685 IN CONST UINT8 *Ivec,
1686 OUT UINT8 *Output
1687 )
1688 {
1689 return BaseCryptLibServiceDeprecated ("TdesCbcEncrypt"), FALSE;
1690 }
1691
1692 /**
1693 TDES is deprecated and unsupported any longer.
1694 Keep the function field for binary compability.
1695
1696 @param[in] TdesContext Pointer to the TDES context.
1697 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1698 @param[in] InputSize Size of the Input buffer in bytes.
1699 @param[in] Ivec Pointer to initialization vector.
1700 @param[out] Output Pointer to a buffer that receives the TDES encryption output.
1701
1702 @retval FALSE This interface is not supported.
1703
1704 **/
1705 BOOLEAN
1706 EFIAPI
1707 DeprecatedCryptoServiceTdesCbcDecrypt (
1708 IN VOID *TdesContext,
1709 IN CONST UINT8 *Input,
1710 IN UINTN InputSize,
1711 IN CONST UINT8 *Ivec,
1712 OUT UINT8 *Output
1713 )
1714 {
1715 return BaseCryptLibServiceDeprecated ("TdesCbcDecrypt"), FALSE;
1716 }
1717
1718 /**
1719 Retrieves the size, in bytes, of the context buffer required for AES operations.
1720
1721 If this interface is not supported, then return zero.
1722
1723 @return The size, in bytes, of the context buffer required for AES operations.
1724 @retval 0 This interface is not supported.
1725
1726 **/
1727 UINTN
1728 EFIAPI
1729 CryptoServiceAesGetContextSize (
1730 VOID
1731 )
1732 {
1733 return CALL_BASECRYPTLIB (Aes.Services.GetContextSize, AesGetContextSize, (), 0);
1734 }
1735
1736 /**
1737 Initializes user-supplied memory as AES context for subsequent use.
1738
1739 This function initializes user-supplied memory pointed by AesContext as AES context.
1740 In addition, it sets up all AES key materials for subsequent encryption and decryption
1741 operations.
1742 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.
1743
1744 If AesContext is NULL, then return FALSE.
1745 If Key is NULL, then return FALSE.
1746 If KeyLength is not valid, then return FALSE.
1747 If this interface is not supported, then return FALSE.
1748
1749 @param[out] AesContext Pointer to AES context being initialized.
1750 @param[in] Key Pointer to the user-supplied AES key.
1751 @param[in] KeyLength Length of AES key in bits.
1752
1753 @retval TRUE AES context initialization succeeded.
1754 @retval FALSE AES context initialization failed.
1755 @retval FALSE This interface is not supported.
1756
1757 **/
1758 BOOLEAN
1759 EFIAPI
1760 CryptoServiceAesInit (
1761 OUT VOID *AesContext,
1762 IN CONST UINT8 *Key,
1763 IN UINTN KeyLength
1764 )
1765 {
1766 return CALL_BASECRYPTLIB (Aes.Services.Init, AesInit, (AesContext, Key, KeyLength), FALSE);
1767 }
1768
1769 /**
1770 AES ECB Mode is deprecated and unsupported any longer.
1771 Keep the function field for binary compability.
1772
1773 @param[in] AesContext Pointer to the AES context.
1774 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1775 @param[in] InputSize Size of the Input buffer in bytes.
1776 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1777
1778 @retval FALSE This interface is not supported.
1779
1780 **/
1781 BOOLEAN
1782 EFIAPI
1783 DeprecatedCryptoServiceAesEcbEncrypt (
1784 IN VOID *AesContext,
1785 IN CONST UINT8 *Input,
1786 IN UINTN InputSize,
1787 OUT UINT8 *Output
1788 )
1789 {
1790 return BaseCryptLibServiceDeprecated ("AesEcbEncrypt"), FALSE;
1791 }
1792
1793 /**
1794 AES ECB Mode is deprecated and unsupported any longer.
1795 Keep the function field for binary compability.
1796
1797 @param[in] AesContext Pointer to the AES context.
1798 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1799 @param[in] InputSize Size of the Input buffer in bytes.
1800 @param[out] Output Pointer to a buffer that receives the AES decryption output.
1801
1802 @retval FALSE This interface is not supported.
1803
1804 **/
1805 BOOLEAN
1806 EFIAPI
1807 DeprecatedCryptoServiceAesEcbDecrypt (
1808 IN VOID *AesContext,
1809 IN CONST UINT8 *Input,
1810 IN UINTN InputSize,
1811 OUT UINT8 *Output
1812 )
1813 {
1814 return BaseCryptLibServiceDeprecated ("AesEcbDecrypt"), FALSE;
1815 }
1816
1817 /**
1818 Performs AES encryption on a data buffer of the specified size in CBC mode.
1819
1820 This function performs AES encryption on data buffer pointed by Input, of specified
1821 size of InputSize, in CBC mode.
1822 InputSize must be multiple of block size (16 bytes). This function does not perform
1823 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1824 Initialization vector should be one block size (16 bytes).
1825 AesContext should be already correctly initialized by AesInit(). Behavior with
1826 invalid AES context is undefined.
1827
1828 If AesContext is NULL, then return FALSE.
1829 If Input is NULL, then return FALSE.
1830 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1831 If Ivec is NULL, then return FALSE.
1832 If Output is NULL, then return FALSE.
1833 If this interface is not supported, then return FALSE.
1834
1835 @param[in] AesContext Pointer to the AES context.
1836 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1837 @param[in] InputSize Size of the Input buffer in bytes.
1838 @param[in] Ivec Pointer to initialization vector.
1839 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1840
1841 @retval TRUE AES encryption succeeded.
1842 @retval FALSE AES encryption failed.
1843 @retval FALSE This interface is not supported.
1844
1845 **/
1846 BOOLEAN
1847 EFIAPI
1848 CryptoServiceAesCbcEncrypt (
1849 IN VOID *AesContext,
1850 IN CONST UINT8 *Input,
1851 IN UINTN InputSize,
1852 IN CONST UINT8 *Ivec,
1853 OUT UINT8 *Output
1854 )
1855 {
1856 return CALL_BASECRYPTLIB (Aes.Services.CbcEncrypt, AesCbcEncrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);
1857 }
1858
1859 /**
1860 Performs AES decryption on a data buffer of the specified size in CBC mode.
1861
1862 This function performs AES decryption on data buffer pointed by Input, of specified
1863 size of InputSize, in CBC mode.
1864 InputSize must be multiple of block size (16 bytes). This function does not perform
1865 padding. Caller must perform padding, if necessary, to ensure valid input data size.
1866 Initialization vector should be one block size (16 bytes).
1867 AesContext should be already correctly initialized by AesInit(). Behavior with
1868 invalid AES context is undefined.
1869
1870 If AesContext is NULL, then return FALSE.
1871 If Input is NULL, then return FALSE.
1872 If InputSize is not multiple of block size (16 bytes), then return FALSE.
1873 If Ivec is NULL, then return FALSE.
1874 If Output is NULL, then return FALSE.
1875 If this interface is not supported, then return FALSE.
1876
1877 @param[in] AesContext Pointer to the AES context.
1878 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1879 @param[in] InputSize Size of the Input buffer in bytes.
1880 @param[in] Ivec Pointer to initialization vector.
1881 @param[out] Output Pointer to a buffer that receives the AES encryption output.
1882
1883 @retval TRUE AES decryption succeeded.
1884 @retval FALSE AES decryption failed.
1885 @retval FALSE This interface is not supported.
1886
1887 **/
1888 BOOLEAN
1889 EFIAPI
1890 CryptoServiceAesCbcDecrypt (
1891 IN VOID *AesContext,
1892 IN CONST UINT8 *Input,
1893 IN UINTN InputSize,
1894 IN CONST UINT8 *Ivec,
1895 OUT UINT8 *Output
1896 )
1897 {
1898 return CALL_BASECRYPTLIB (Aes.Services.CbcDecrypt, AesCbcDecrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);
1899 }
1900
1901 /**
1902 ARC4 is deprecated and unsupported any longer.
1903 Keep the function field for binary compability.
1904
1905 @retval 0 This interface is not supported.
1906
1907 **/
1908 UINTN
1909 EFIAPI
1910 DeprecatedCryptoServiceArc4GetContextSize (
1911 VOID
1912 )
1913 {
1914 return BaseCryptLibServiceDeprecated ("Arc4GetContextSize"), 0;
1915 }
1916
1917 /**
1918 ARC4 is deprecated and unsupported any longer.
1919 Keep the function field for binary compability.
1920
1921 @param[out] Arc4Context Pointer to ARC4 context being initialized.
1922 @param[in] Key Pointer to the user-supplied ARC4 key.
1923 @param[in] KeySize Size of ARC4 key in bytes.
1924
1925 @retval FALSE This interface is not supported.
1926
1927 **/
1928 BOOLEAN
1929 EFIAPI
1930 DeprecatedCryptoServiceArc4Init (
1931 OUT VOID *Arc4Context,
1932 IN CONST UINT8 *Key,
1933 IN UINTN KeySize
1934 )
1935 {
1936 return BaseCryptLibServiceDeprecated ("Arc4Init"), FALSE;
1937 }
1938
1939 /**
1940 ARC4 is deprecated and unsupported any longer.
1941 Keep the function field for binary compability.
1942
1943 @param[in, out] Arc4Context Pointer to the ARC4 context.
1944 @param[in] Input Pointer to the buffer containing the data to be encrypted.
1945 @param[in] InputSize Size of the Input buffer in bytes.
1946 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.
1947
1948 @retval FALSE This interface is not supported.
1949
1950 **/
1951 BOOLEAN
1952 EFIAPI
1953 DeprecatedCryptoServiceArc4Encrypt (
1954 IN OUT VOID *Arc4Context,
1955 IN CONST UINT8 *Input,
1956 IN UINTN InputSize,
1957 OUT UINT8 *Output
1958 )
1959 {
1960 return BaseCryptLibServiceDeprecated ("Arc4Encrypt"), FALSE;
1961 }
1962
1963 /**
1964 ARC4 is deprecated and unsupported any longer.
1965 Keep the function field for binary compability.
1966
1967 @param[in, out] Arc4Context Pointer to the ARC4 context.
1968 @param[in] Input Pointer to the buffer containing the data to be decrypted.
1969 @param[in] InputSize Size of the Input buffer in bytes.
1970 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.
1971
1972 @retval FALSE This interface is not supported.
1973
1974 **/
1975 BOOLEAN
1976 EFIAPI
1977 DeprecatedCryptoServiceArc4Decrypt (
1978 IN OUT VOID *Arc4Context,
1979 IN UINT8 *Input,
1980 IN UINTN InputSize,
1981 OUT UINT8 *Output
1982 )
1983 {
1984 return BaseCryptLibServiceDeprecated ("Arc4Decrypt"), FALSE;
1985 }
1986
1987 /**
1988 ARC4 is deprecated and unsupported any longer.
1989 Keep the function field for binary compability.
1990
1991 @param[in, out] Arc4Context Pointer to the ARC4 context.
1992
1993 @retval FALSE This interface is not supported.
1994
1995 **/
1996 BOOLEAN
1997 EFIAPI
1998 DeprecatedCryptoServiceArc4Reset (
1999 IN OUT VOID *Arc4Context
2000 )
2001 {
2002 return BaseCryptLibServiceDeprecated ("Arc4Reset"), FALSE;
2003 }
2004
2005 //=====================================================================================
2006 // Asymmetric Cryptography Primitive
2007 //=====================================================================================
2008
2009 /**
2010 Allocates and initializes one RSA context for subsequent use.
2011
2012 @return Pointer to the RSA context that has been initialized.
2013 If the allocations fails, RsaNew() returns NULL.
2014
2015 **/
2016 VOID *
2017 EFIAPI
2018 CryptoServiceRsaNew (
2019 VOID
2020 )
2021 {
2022 return CALL_BASECRYPTLIB (Rsa.Services.New, RsaNew, (), NULL);
2023 }
2024
2025 /**
2026 Release the specified RSA context.
2027
2028 If RsaContext is NULL, then return FALSE.
2029
2030 @param[in] RsaContext Pointer to the RSA context to be released.
2031
2032 **/
2033 VOID
2034 EFIAPI
2035 CryptoServiceRsaFree (
2036 IN VOID *RsaContext
2037 )
2038 {
2039 CALL_VOID_BASECRYPTLIB (Rsa.Services.Free, RsaFree, (RsaContext));
2040 }
2041
2042 /**
2043 Sets the tag-designated key component into the established RSA context.
2044
2045 This function sets the tag-designated RSA key component into the established
2046 RSA context from the user-specified non-negative integer (octet string format
2047 represented in RSA PKCS#1).
2048 If BigNumber is NULL, then the specified key component in RSA context is cleared.
2049
2050 If RsaContext is NULL, then return FALSE.
2051
2052 @param[in, out] RsaContext Pointer to RSA context being set.
2053 @param[in] KeyTag Tag of RSA key component being set.
2054 @param[in] BigNumber Pointer to octet integer buffer.
2055 If NULL, then the specified key component in RSA
2056 context is cleared.
2057 @param[in] BnSize Size of big number buffer in bytes.
2058 If BigNumber is NULL, then it is ignored.
2059
2060 @retval TRUE RSA key component was set successfully.
2061 @retval FALSE Invalid RSA key component tag.
2062
2063 **/
2064 BOOLEAN
2065 EFIAPI
2066 CryptoServiceRsaSetKey (
2067 IN OUT VOID *RsaContext,
2068 IN RSA_KEY_TAG KeyTag,
2069 IN CONST UINT8 *BigNumber,
2070 IN UINTN BnSize
2071 )
2072 {
2073 return CALL_BASECRYPTLIB (Rsa.Services.SetKey, RsaSetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);
2074 }
2075
2076 /**
2077 Gets the tag-designated RSA key component from the established RSA context.
2078
2079 This function retrieves the tag-designated RSA key component from the
2080 established RSA context as a non-negative integer (octet string format
2081 represented in RSA PKCS#1).
2082 If specified key component has not been set or has been cleared, then returned
2083 BnSize is set to 0.
2084 If the BigNumber buffer is too small to hold the contents of the key, FALSE
2085 is returned and BnSize is set to the required buffer size to obtain the key.
2086
2087 If RsaContext is NULL, then return FALSE.
2088 If BnSize is NULL, then return FALSE.
2089 If BnSize is large enough but BigNumber is NULL, then return FALSE.
2090 If this interface is not supported, then return FALSE.
2091
2092 @param[in, out] RsaContext Pointer to RSA context being set.
2093 @param[in] KeyTag Tag of RSA key component being set.
2094 @param[out] BigNumber Pointer to octet integer buffer.
2095 @param[in, out] BnSize On input, the size of big number buffer in bytes.
2096 On output, the size of data returned in big number buffer in bytes.
2097
2098 @retval TRUE RSA key component was retrieved successfully.
2099 @retval FALSE Invalid RSA key component tag.
2100 @retval FALSE BnSize is too small.
2101 @retval FALSE This interface is not supported.
2102
2103 **/
2104 BOOLEAN
2105 EFIAPI
2106 CryptoServiceRsaGetKey (
2107 IN OUT VOID *RsaContext,
2108 IN RSA_KEY_TAG KeyTag,
2109 OUT UINT8 *BigNumber,
2110 IN OUT UINTN *BnSize
2111 )
2112 {
2113 return CALL_BASECRYPTLIB (Rsa.Services.GetKey, RsaGetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);
2114 }
2115
2116 /**
2117 Generates RSA key components.
2118
2119 This function generates RSA key components. It takes RSA public exponent E and
2120 length in bits of RSA modulus N as input, and generates all key components.
2121 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.
2122
2123 Before this function can be invoked, pseudorandom number generator must be correctly
2124 initialized by RandomSeed().
2125
2126 If RsaContext is NULL, then return FALSE.
2127 If this interface is not supported, then return FALSE.
2128
2129 @param[in, out] RsaContext Pointer to RSA context being set.
2130 @param[in] ModulusLength Length of RSA modulus N in bits.
2131 @param[in] PublicExponent Pointer to RSA public exponent.
2132 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.
2133
2134 @retval TRUE RSA key component was generated successfully.
2135 @retval FALSE Invalid RSA key component tag.
2136 @retval FALSE This interface is not supported.
2137
2138 **/
2139 BOOLEAN
2140 EFIAPI
2141 CryptoServiceRsaGenerateKey (
2142 IN OUT VOID *RsaContext,
2143 IN UINTN ModulusLength,
2144 IN CONST UINT8 *PublicExponent,
2145 IN UINTN PublicExponentSize
2146 )
2147 {
2148 return CALL_BASECRYPTLIB (Rsa.Services.GenerateKey, RsaGenerateKey, (RsaContext, ModulusLength, PublicExponent, PublicExponentSize), FALSE);
2149 }
2150
2151 /**
2152 Validates key components of RSA context.
2153 NOTE: This function performs integrity checks on all the RSA key material, so
2154 the RSA key structure must contain all the private key data.
2155
2156 This function validates key components of RSA context in following aspects:
2157 - Whether p is a prime
2158 - Whether q is a prime
2159 - Whether n = p * q
2160 - Whether d*e = 1 mod lcm(p-1,q-1)
2161
2162 If RsaContext is NULL, then return FALSE.
2163 If this interface is not supported, then return FALSE.
2164
2165 @param[in] RsaContext Pointer to RSA context to check.
2166
2167 @retval TRUE RSA key components are valid.
2168 @retval FALSE RSA key components are not valid.
2169 @retval FALSE This interface is not supported.
2170
2171 **/
2172 BOOLEAN
2173 EFIAPI
2174 CryptoServiceRsaCheckKey (
2175 IN VOID *RsaContext
2176 )
2177 {
2178 return CALL_BASECRYPTLIB (Rsa.Services.CheckKey, RsaCheckKey, (RsaContext), FALSE);
2179 }
2180
2181 /**
2182 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.
2183
2184 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in
2185 RSA PKCS#1.
2186 If the Signature buffer is too small to hold the contents of signature, FALSE
2187 is returned and SigSize is set to the required buffer size to obtain the signature.
2188
2189 If RsaContext is NULL, then return FALSE.
2190 If MessageHash is NULL, then return FALSE.
2191 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.
2192 If SigSize is large enough but Signature is NULL, then return FALSE.
2193 If this interface is not supported, then return FALSE.
2194
2195 @param[in] RsaContext Pointer to RSA context for signature generation.
2196 @param[in] MessageHash Pointer to octet message hash to be signed.
2197 @param[in] HashSize Size of the message hash in bytes.
2198 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.
2199 @param[in, out] SigSize On input, the size of Signature buffer in bytes.
2200 On output, the size of data returned in Signature buffer in bytes.
2201
2202 @retval TRUE Signature successfully generated in PKCS1-v1_5.
2203 @retval FALSE Signature generation failed.
2204 @retval FALSE SigSize is too small.
2205 @retval FALSE This interface is not supported.
2206
2207 **/
2208 BOOLEAN
2209 EFIAPI
2210 CryptoServiceRsaPkcs1Sign (
2211 IN VOID *RsaContext,
2212 IN CONST UINT8 *MessageHash,
2213 IN UINTN HashSize,
2214 OUT UINT8 *Signature,
2215 IN OUT UINTN *SigSize
2216 )
2217 {
2218 return CALL_BASECRYPTLIB (Rsa.Services.Pkcs1Sign, RsaPkcs1Sign, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);
2219 }
2220
2221 /**
2222 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in
2223 RSA PKCS#1.
2224
2225 If RsaContext is NULL, then return FALSE.
2226 If MessageHash is NULL, then return FALSE.
2227 If Signature is NULL, then return FALSE.
2228 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.
2229
2230 @param[in] RsaContext Pointer to RSA context for signature verification.
2231 @param[in] MessageHash Pointer to octet message hash to be checked.
2232 @param[in] HashSize Size of the message hash in bytes.
2233 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.
2234 @param[in] SigSize Size of signature in bytes.
2235
2236 @retval TRUE Valid signature encoded in PKCS1-v1_5.
2237 @retval FALSE Invalid signature or invalid RSA context.
2238
2239 **/
2240 BOOLEAN
2241 EFIAPI
2242 CryptoServiceRsaPkcs1Verify (
2243 IN VOID *RsaContext,
2244 IN CONST UINT8 *MessageHash,
2245 IN UINTN HashSize,
2246 IN CONST UINT8 *Signature,
2247 IN UINTN SigSize
2248 )
2249 {
2250 return CALL_BASECRYPTLIB (Rsa.Services.Pkcs1Verify, RsaPkcs1Verify, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);
2251 }
2252
2253 /**
2254 Retrieve the RSA Private Key from the password-protected PEM key data.
2255
2256 If PemData is NULL, then return FALSE.
2257 If RsaContext is NULL, then return FALSE.
2258 If this interface is not supported, then return FALSE.
2259
2260 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.
2261 @param[in] PemSize Size of the PEM key data in bytes.
2262 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.
2263 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2264 RSA private key component. Use RsaFree() function to free the
2265 resource.
2266
2267 @retval TRUE RSA Private Key was retrieved successfully.
2268 @retval FALSE Invalid PEM key data or incorrect password.
2269 @retval FALSE This interface is not supported.
2270
2271 **/
2272 BOOLEAN
2273 EFIAPI
2274 CryptoServiceRsaGetPrivateKeyFromPem (
2275 IN CONST UINT8 *PemData,
2276 IN UINTN PemSize,
2277 IN CONST CHAR8 *Password,
2278 OUT VOID **RsaContext
2279 )
2280 {
2281 return CALL_BASECRYPTLIB (Rsa.Services.GetPrivateKeyFromPem, RsaGetPrivateKeyFromPem, (PemData, PemSize, Password, RsaContext), FALSE);
2282 }
2283
2284 /**
2285 Retrieve the RSA Public Key from one DER-encoded X509 certificate.
2286
2287 If Cert is NULL, then return FALSE.
2288 If RsaContext is NULL, then return FALSE.
2289 If this interface is not supported, then return FALSE.
2290
2291 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2292 @param[in] CertSize Size of the X509 certificate in bytes.
2293 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved
2294 RSA public key component. Use RsaFree() function to free the
2295 resource.
2296
2297 @retval TRUE RSA Public Key was retrieved successfully.
2298 @retval FALSE Fail to retrieve RSA public key from X509 certificate.
2299 @retval FALSE This interface is not supported.
2300
2301 **/
2302 BOOLEAN
2303 EFIAPI
2304 CryptoServiceRsaGetPublicKeyFromX509 (
2305 IN CONST UINT8 *Cert,
2306 IN UINTN CertSize,
2307 OUT VOID **RsaContext
2308 )
2309 {
2310 return CALL_BASECRYPTLIB (Rsa.Services.GetPublicKeyFromX509, RsaGetPublicKeyFromX509, (Cert, CertSize, RsaContext), FALSE);
2311 }
2312
2313 /**
2314 Retrieve the subject bytes from one X.509 certificate.
2315
2316 If Cert is NULL, then return FALSE.
2317 If SubjectSize is NULL, then return FALSE.
2318 If this interface is not supported, then return FALSE.
2319
2320 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2321 @param[in] CertSize Size of the X509 certificate in bytes.
2322 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.
2323 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,
2324 and the size of buffer returned CertSubject on output.
2325
2326 @retval TRUE The certificate subject retrieved successfully.
2327 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.
2328 The SubjectSize will be updated with the required size.
2329 @retval FALSE This interface is not supported.
2330
2331 **/
2332 BOOLEAN
2333 EFIAPI
2334 CryptoServiceX509GetSubjectName (
2335 IN CONST UINT8 *Cert,
2336 IN UINTN CertSize,
2337 OUT UINT8 *CertSubject,
2338 IN OUT UINTN *SubjectSize
2339 )
2340 {
2341 return CALL_BASECRYPTLIB (X509.Services.GetSubjectName, X509GetSubjectName, (Cert, CertSize, CertSubject, SubjectSize), FALSE);
2342 }
2343
2344 /**
2345 Retrieve the common name (CN) string from one X.509 certificate.
2346
2347 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2348 @param[in] CertSize Size of the X509 certificate in bytes.
2349 @param[out] CommonName Buffer to contain the retrieved certificate common
2350 name string (UTF8). At most CommonNameSize bytes will be
2351 written and the string will be null terminated. May be
2352 NULL in order to determine the size buffer needed.
2353 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,
2354 and the size of buffer returned CommonName on output.
2355 If CommonName is NULL then the amount of space needed
2356 in buffer (including the final null) is returned.
2357
2358 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.
2359 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2360 If CommonNameSize is NULL.
2361 If CommonName is not NULL and *CommonNameSize is 0.
2362 If Certificate is invalid.
2363 @retval RETURN_NOT_FOUND If no CommonName entry exists.
2364 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size
2365 (including the final null) is returned in the
2366 CommonNameSize parameter.
2367 @retval RETURN_UNSUPPORTED The operation is not supported.
2368
2369 **/
2370 RETURN_STATUS
2371 EFIAPI
2372 CryptoServiceX509GetCommonName (
2373 IN CONST UINT8 *Cert,
2374 IN UINTN CertSize,
2375 OUT CHAR8 *CommonName, OPTIONAL
2376 IN OUT UINTN *CommonNameSize
2377 )
2378 {
2379 return CALL_BASECRYPTLIB (X509.Services.GetCommonName, X509GetCommonName, (Cert, CertSize, CommonName, CommonNameSize), RETURN_UNSUPPORTED);
2380 }
2381
2382 /**
2383 Retrieve the organization name (O) string from one X.509 certificate.
2384
2385 @param[in] Cert Pointer to the DER-encoded X509 certificate.
2386 @param[in] CertSize Size of the X509 certificate in bytes.
2387 @param[out] NameBuffer Buffer to contain the retrieved certificate organization
2388 name string. At most NameBufferSize bytes will be
2389 written and the string will be null terminated. May be
2390 NULL in order to determine the size buffer needed.
2391 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,
2392 and the size of buffer returned Name on output.
2393 If NameBuffer is NULL then the amount of space needed
2394 in buffer (including the final null) is returned.
2395
2396 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.
2397 @retval RETURN_INVALID_PARAMETER If Cert is NULL.
2398 If NameBufferSize is NULL.
2399 If NameBuffer is not NULL and *CommonNameSize is 0.
2400 If Certificate is invalid.
2401 @retval RETURN_NOT_FOUND If no Organization Name entry exists.
2402 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size
2403 (including the final null) is returned in the
2404 CommonNameSize parameter.
2405 @retval RETURN_UNSUPPORTED The operation is not supported.
2406
2407 **/
2408 RETURN_STATUS
2409 EFIAPI
2410 CryptoServiceX509GetOrganizationName (
2411 IN CONST UINT8 *Cert,
2412 IN UINTN CertSize,
2413 OUT CHAR8 *NameBuffer, OPTIONAL
2414 IN OUT UINTN *NameBufferSize
2415 )
2416 {
2417 return CALL_BASECRYPTLIB (X509.Services.GetOrganizationName, X509GetOrganizationName, (Cert, CertSize, NameBuffer, NameBufferSize), RETURN_UNSUPPORTED);
2418 }
2419
2420 /**
2421 Verify one X509 certificate was issued by the trusted CA.
2422
2423 If Cert is NULL, then return FALSE.
2424 If CACert is NULL, then return FALSE.
2425 If this interface is not supported, then return FALSE.
2426
2427 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.
2428 @param[in] CertSize Size of the X509 certificate in bytes.
2429 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.
2430 @param[in] CACertSize Size of the CA Certificate in bytes.
2431
2432 @retval TRUE The certificate was issued by the trusted CA.
2433 @retval FALSE Invalid certificate or the certificate was not issued by the given
2434 trusted CA.
2435 @retval FALSE This interface is not supported.
2436
2437 **/
2438 BOOLEAN
2439 EFIAPI
2440 CryptoServiceX509VerifyCert (
2441 IN CONST UINT8 *Cert,
2442 IN UINTN CertSize,
2443 IN CONST UINT8 *CACert,
2444 IN UINTN CACertSize
2445 )
2446 {
2447 return CALL_BASECRYPTLIB (X509.Services.VerifyCert, X509VerifyCert, (Cert, CertSize, CACert, CACertSize), FALSE);
2448 }
2449
2450 /**
2451 Construct a X509 object from DER-encoded certificate data.
2452
2453 If Cert is NULL, then return FALSE.
2454 If SingleX509Cert is NULL, then return FALSE.
2455 If this interface is not supported, then return FALSE.
2456
2457 @param[in] Cert Pointer to the DER-encoded certificate data.
2458 @param[in] CertSize The size of certificate data in bytes.
2459 @param[out] SingleX509Cert The generated X509 object.
2460
2461 @retval TRUE The X509 object generation succeeded.
2462 @retval FALSE The operation failed.
2463 @retval FALSE This interface is not supported.
2464
2465 **/
2466 BOOLEAN
2467 EFIAPI
2468 CryptoServiceX509ConstructCertificate (
2469 IN CONST UINT8 *Cert,
2470 IN UINTN CertSize,
2471 OUT UINT8 **SingleX509Cert
2472 )
2473 {
2474 return CALL_BASECRYPTLIB (X509.Services.ConstructCertificate, X509ConstructCertificate, (Cert, CertSize, SingleX509Cert), FALSE);
2475 }
2476
2477 /**
2478 Construct a X509 stack object from a list of DER-encoded certificate data.
2479
2480 If X509Stack is NULL, then return FALSE.
2481 If this interface is not supported, then return FALSE.
2482
2483 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2484 On output, pointer to the X509 stack object with new
2485 inserted X509 certificate.
2486 @param[in] Args VA_LIST marker for the variable argument list.
2487 A list of DER-encoded single certificate data followed
2488 by certificate size. A NULL terminates the list. The
2489 pairs are the arguments to X509ConstructCertificate().
2490
2491 @retval TRUE The X509 stack construction succeeded.
2492 @retval FALSE The construction operation failed.
2493 @retval FALSE This interface is not supported.
2494
2495 **/
2496 BOOLEAN
2497 EFIAPI
2498 CryptoServiceX509ConstructCertificateStackV (
2499 IN OUT UINT8 **X509Stack,
2500 IN VA_LIST Args
2501 )
2502 {
2503 return CALL_BASECRYPTLIB (X509.Services.ConstructCertificateStackV, X509ConstructCertificateStackV, (X509Stack, Args), FALSE);
2504 }
2505
2506 /**
2507 Construct a X509 stack object from a list of DER-encoded certificate data.
2508
2509 If X509Stack is NULL, then return FALSE.
2510 If this interface is not supported, then return FALSE.
2511
2512 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.
2513 On output, pointer to the X509 stack object with new
2514 inserted X509 certificate.
2515 @param ... A list of DER-encoded single certificate data followed
2516 by certificate size. A NULL terminates the list. The
2517 pairs are the arguments to X509ConstructCertificate().
2518
2519 @retval TRUE The X509 stack construction succeeded.
2520 @retval FALSE The construction operation failed.
2521 @retval FALSE This interface is not supported.
2522
2523 **/
2524 BOOLEAN
2525 EFIAPI
2526 CryptoServiceX509ConstructCertificateStack (
2527 IN OUT UINT8 **X509Stack,
2528 ...
2529 )
2530 {
2531 VA_LIST Args;
2532 BOOLEAN Result;
2533
2534 VA_START (Args, X509Stack);
2535 Result = CryptoServiceX509ConstructCertificateStackV (X509Stack, Args);
2536 VA_END (Args);
2537 return Result;
2538 }
2539
2540 /**
2541 Release the specified X509 object.
2542
2543 If the interface is not supported, then ASSERT().
2544
2545 @param[in] X509Cert Pointer to the X509 object to be released.
2546
2547 **/
2548 VOID
2549 EFIAPI
2550 CryptoServiceX509Free (
2551 IN VOID *X509Cert
2552 )
2553 {
2554 CALL_VOID_BASECRYPTLIB (X509.Services.Free, X509Free, (X509Cert));
2555 }
2556
2557 /**
2558 Release the specified X509 stack object.
2559
2560 If the interface is not supported, then ASSERT().
2561
2562 @param[in] X509Stack Pointer to the X509 stack object to be released.
2563
2564 **/
2565 VOID
2566 EFIAPI
2567 CryptoServiceX509StackFree (
2568 IN VOID *X509Stack
2569 )
2570 {
2571 CALL_VOID_BASECRYPTLIB (X509.Services.StackFree, X509StackFree, (X509Stack));
2572 }
2573
2574 /**
2575 Retrieve the TBSCertificate from one given X.509 certificate.
2576
2577 @param[in] Cert Pointer to the given DER-encoded X509 certificate.
2578 @param[in] CertSize Size of the X509 certificate in bytes.
2579 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.
2580 @param[out] TBSCertSize Size of the TBS certificate in bytes.
2581
2582 If Cert is NULL, then return FALSE.
2583 If TBSCert is NULL, then return FALSE.
2584 If TBSCertSize is NULL, then return FALSE.
2585 If this interface is not supported, then return FALSE.
2586
2587 @retval TRUE The TBSCertificate was retrieved successfully.
2588 @retval FALSE Invalid X.509 certificate.
2589
2590 **/
2591 BOOLEAN
2592 EFIAPI
2593 CryptoServiceX509GetTBSCert (
2594 IN CONST UINT8 *Cert,
2595 IN UINTN CertSize,
2596 OUT UINT8 **TBSCert,
2597 OUT UINTN *TBSCertSize
2598 )
2599 {
2600 return CALL_BASECRYPTLIB (X509.Services.GetTBSCert, X509GetTBSCert, (Cert, CertSize, TBSCert, TBSCertSize), FALSE);
2601 }
2602
2603 /**
2604 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0
2605 password based encryption key derivation function PBKDF2, as specified in RFC 2898.
2606
2607 If Password or Salt or OutKey is NULL, then return FALSE.
2608 If the hash algorithm could not be determined, then return FALSE.
2609 If this interface is not supported, then return FALSE.
2610
2611 @param[in] PasswordLength Length of input password in bytes.
2612 @param[in] Password Pointer to the array for the password.
2613 @param[in] SaltLength Size of the Salt in bytes.
2614 @param[in] Salt Pointer to the Salt.
2615 @param[in] IterationCount Number of iterations to perform. Its value should be
2616 greater than or equal to 1.
2617 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).
2618 NOTE: DigestSize will be used to determine the hash algorithm.
2619 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.
2620 @param[in] KeyLength Size of the derived key buffer in bytes.
2621 @param[out] OutKey Pointer to the output derived key buffer.
2622
2623 @retval TRUE A key was derived successfully.
2624 @retval FALSE One of the pointers was NULL or one of the sizes was too large.
2625 @retval FALSE The hash algorithm could not be determined from the digest size.
2626 @retval FALSE The key derivation operation failed.
2627 @retval FALSE This interface is not supported.
2628
2629 **/
2630 BOOLEAN
2631 EFIAPI
2632 CryptoServicePkcs5HashPassword (
2633 IN UINTN PasswordLength,
2634 IN CONST CHAR8 *Password,
2635 IN UINTN SaltLength,
2636 IN CONST UINT8 *Salt,
2637 IN UINTN IterationCount,
2638 IN UINTN DigestSize,
2639 IN UINTN KeyLength,
2640 OUT UINT8 *OutKey
2641 )
2642 {
2643 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs5HashPassword, Pkcs5HashPassword, (PasswordLength, Password, SaltLength, Salt, IterationCount, DigestSize, KeyLength, OutKey), FALSE);
2644 }
2645
2646 /**
2647 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the
2648 encrypted message in a newly allocated buffer.
2649
2650 Things that can cause a failure include:
2651 - X509 key size does not match any known key size.
2652 - Fail to parse X509 certificate.
2653 - Fail to allocate an intermediate buffer.
2654 - Null pointer provided for a non-optional parameter.
2655 - Data size is too large for the provided key size (max size is a function of key size
2656 and hash digest size).
2657
2658 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that
2659 will be used to encrypt the data.
2660 @param[in] PublicKeySize Size of the X509 cert buffer.
2661 @param[in] InData Data to be encrypted.
2662 @param[in] InDataSize Size of the data buffer.
2663 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer
2664 to be used when initializing the PRNG. NULL otherwise.
2665 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.
2666 0 otherwise.
2667 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted
2668 message.
2669 @param[out] EncryptedDataSize Size of the encrypted message buffer.
2670
2671 @retval TRUE Encryption was successful.
2672 @retval FALSE Encryption failed.
2673
2674 **/
2675 BOOLEAN
2676 EFIAPI
2677 CryptoServicePkcs1v2Encrypt (
2678 IN CONST UINT8 *PublicKey,
2679 IN UINTN PublicKeySize,
2680 IN UINT8 *InData,
2681 IN UINTN InDataSize,
2682 IN CONST UINT8 *PrngSeed, OPTIONAL
2683 IN UINTN PrngSeedSize, OPTIONAL
2684 OUT UINT8 **EncryptedData,
2685 OUT UINTN *EncryptedDataSize
2686 )
2687 {
2688 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs1v2Encrypt, Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);
2689 }
2690
2691 /**
2692 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:
2693 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2694 in a ContentInfo structure.
2695
2696 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then
2697 return FALSE. If P7Length overflow, then return FALSE.
2698 If this interface is not supported, then return FALSE.
2699
2700 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2701 @param[in] P7Length Length of the PKCS#7 message in bytes.
2702 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.
2703 It's caller's responsibility to free the buffer with
2704 Pkcs7FreeSigners().
2705 This data structure is EFI_CERT_STACK type.
2706 @param[out] StackLength Length of signer's certificates in bytes.
2707 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.
2708 It's caller's responsibility to free the buffer with
2709 Pkcs7FreeSigners().
2710 @param[out] CertLength Length of the trusted certificate in bytes.
2711
2712 @retval TRUE The operation is finished successfully.
2713 @retval FALSE Error occurs during the operation.
2714 @retval FALSE This interface is not supported.
2715
2716 **/
2717 BOOLEAN
2718 EFIAPI
2719 CryptoServicePkcs7GetSigners (
2720 IN CONST UINT8 *P7Data,
2721 IN UINTN P7Length,
2722 OUT UINT8 **CertStack,
2723 OUT UINTN *StackLength,
2724 OUT UINT8 **TrustedCert,
2725 OUT UINTN *CertLength
2726 )
2727 {
2728 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7GetSigners, Pkcs7GetSigners, (P7Data, P7Length, CertStack, StackLength, TrustedCert, CertLength), FALSE);
2729 }
2730
2731 /**
2732 Wrap function to use free() to free allocated memory for certificates.
2733
2734 If this interface is not supported, then ASSERT().
2735
2736 @param[in] Certs Pointer to the certificates to be freed.
2737
2738 **/
2739 VOID
2740 EFIAPI
2741 CryptoServicePkcs7FreeSigners (
2742 IN UINT8 *Certs
2743 )
2744 {
2745 CALL_VOID_BASECRYPTLIB (Pkcs.Services.Pkcs7FreeSigners, Pkcs7FreeSigners, (Certs));
2746 }
2747
2748 /**
2749 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:
2750 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and
2751 unchained to the signer's certificates.
2752 The input signed data could be wrapped in a ContentInfo structure.
2753
2754 @param[in] P7Data Pointer to the PKCS#7 message.
2755 @param[in] P7Length Length of the PKCS#7 message in bytes.
2756 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's
2757 certificate. It's caller's responsibility to free the buffer
2758 with Pkcs7FreeSigners().
2759 This data structure is EFI_CERT_STACK type.
2760 @param[out] ChainLength Length of the chained certificates list buffer in bytes.
2761 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's
2762 responsibility to free the buffer with Pkcs7FreeSigners().
2763 This data structure is EFI_CERT_STACK type.
2764 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.
2765
2766 @retval TRUE The operation is finished successfully.
2767 @retval FALSE Error occurs during the operation.
2768
2769 **/
2770 BOOLEAN
2771 EFIAPI
2772 CryptoServicePkcs7GetCertificatesList (
2773 IN CONST UINT8 *P7Data,
2774 IN UINTN P7Length,
2775 OUT UINT8 **SignerChainCerts,
2776 OUT UINTN *ChainLength,
2777 OUT UINT8 **UnchainCerts,
2778 OUT UINTN *UnchainLength
2779 )
2780 {
2781 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7GetCertificatesList, Pkcs7GetCertificatesList, (P7Data, P7Length, SignerChainCerts, ChainLength, UnchainCerts, UnchainLength), FALSE);
2782 }
2783
2784 /**
2785 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message
2786 Syntax Standard, version 1.5". This interface is only intended to be used for
2787 application to perform PKCS#7 functionality validation.
2788
2789 If this interface is not supported, then return FALSE.
2790
2791 @param[in] PrivateKey Pointer to the PEM-formatted private key data for
2792 data signing.
2793 @param[in] PrivateKeySize Size of the PEM private key data in bytes.
2794 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM
2795 key data.
2796 @param[in] InData Pointer to the content to be signed.
2797 @param[in] InDataSize Size of InData in bytes.
2798 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.
2799 @param[in] OtherCerts Pointer to an optional additional set of certificates to
2800 include in the PKCS#7 signedData (e.g. any intermediate
2801 CAs in the chain).
2802 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's
2803 responsibility to free the buffer with FreePool().
2804 @param[out] SignedDataSize Size of SignedData in bytes.
2805
2806 @retval TRUE PKCS#7 data signing succeeded.
2807 @retval FALSE PKCS#7 data signing failed.
2808 @retval FALSE This interface is not supported.
2809
2810 **/
2811 BOOLEAN
2812 EFIAPI
2813 CryptoServicePkcs7Sign (
2814 IN CONST UINT8 *PrivateKey,
2815 IN UINTN PrivateKeySize,
2816 IN CONST UINT8 *KeyPassword,
2817 IN UINT8 *InData,
2818 IN UINTN InDataSize,
2819 IN UINT8 *SignCert,
2820 IN UINT8 *OtherCerts OPTIONAL,
2821 OUT UINT8 **SignedData,
2822 OUT UINTN *SignedDataSize
2823 )
2824 {
2825 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7Sign, Pkcs7Sign, (PrivateKey, PrivateKeySize, KeyPassword, InData, InDataSize, SignCert, OtherCerts, SignedData, SignedDataSize), FALSE);
2826 }
2827
2828 /**
2829 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:
2830 Cryptographic Message Syntax Standard". The input signed data could be wrapped
2831 in a ContentInfo structure.
2832
2833 If P7Data, TrustedCert or InData is NULL, then return FALSE.
2834 If P7Length, CertLength or DataLength overflow, then return FALSE.
2835 If this interface is not supported, then return FALSE.
2836
2837 @param[in] P7Data Pointer to the PKCS#7 message to verify.
2838 @param[in] P7Length Length of the PKCS#7 message in bytes.
2839 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2840 is used for certificate chain verification.
2841 @param[in] CertLength Length of the trusted certificate in bytes.
2842 @param[in] InData Pointer to the content to be verified.
2843 @param[in] DataLength Length of InData in bytes.
2844
2845 @retval TRUE The specified PKCS#7 signed data is valid.
2846 @retval FALSE Invalid PKCS#7 signed data.
2847 @retval FALSE This interface is not supported.
2848
2849 **/
2850 BOOLEAN
2851 EFIAPI
2852 CryptoServicePkcs7Verify (
2853 IN CONST UINT8 *P7Data,
2854 IN UINTN P7Length,
2855 IN CONST UINT8 *TrustedCert,
2856 IN UINTN CertLength,
2857 IN CONST UINT8 *InData,
2858 IN UINTN DataLength
2859 )
2860 {
2861 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7Verify, Pkcs7Verify, (P7Data, P7Length, TrustedCert, CertLength, InData, DataLength), FALSE);
2862 }
2863
2864 /**
2865 This function receives a PKCS7 formatted signature, and then verifies that
2866 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity
2867 leaf signing certificate.
2868 Note that this function does not validate the certificate chain.
2869
2870 Applications for custom EKU's are quite flexible. For example, a policy EKU
2871 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate
2872 certificate issued might also contain this EKU, thus constraining the
2873 sub-ordinate certificate. Other applications might allow a certificate
2874 embedded in a device to specify that other Object Identifiers (OIDs) are
2875 present which contains binary data specifying custom capabilities that
2876 the device is able to do.
2877
2878 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array
2879 containing the content block with both the signature,
2880 the signer's certificate, and any necessary intermediate
2881 certificates.
2882 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.
2883 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of
2884 required EKUs that must be present in the signature.
2885 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.
2886 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's
2887 must be present in the leaf signer. If it is
2888 FALSE, then we will succeed if we find any
2889 of the specified EKU's.
2890
2891 @retval EFI_SUCCESS The required EKUs were found in the signature.
2892 @retval EFI_INVALID_PARAMETER A parameter was invalid.
2893 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.
2894
2895 **/
2896 RETURN_STATUS
2897 EFIAPI
2898 CryptoServiceVerifyEKUsInPkcs7Signature (
2899 IN CONST UINT8 *Pkcs7Signature,
2900 IN CONST UINT32 SignatureSize,
2901 IN CONST CHAR8 *RequiredEKUs[],
2902 IN CONST UINT32 RequiredEKUsSize,
2903 IN BOOLEAN RequireAllPresent
2904 )
2905 {
2906 return CALL_BASECRYPTLIB (Pkcs.Services.VerifyEKUsInPkcs7Signature, VerifyEKUsInPkcs7Signature, (Pkcs7Signature, SignatureSize, RequiredEKUs, RequiredEKUsSize, RequireAllPresent), FALSE);
2907 }
2908
2909
2910 /**
2911 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
2912 data could be wrapped in a ContentInfo structure.
2913
2914 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
2915 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
2916
2917 Caution: This function may receive untrusted input. So this function will do
2918 basic check for PKCS#7 data structure.
2919
2920 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
2921 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
2922 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
2923 It's caller's responsibility to free the buffer with FreePool().
2924 @param[out] ContentSize The size of the extracted content in bytes.
2925
2926 @retval TRUE The P7Data was correctly formatted for processing.
2927 @retval FALSE The P7Data was not correctly formatted for processing.
2928
2929 **/
2930 BOOLEAN
2931 EFIAPI
2932 CryptoServicePkcs7GetAttachedContent (
2933 IN CONST UINT8 *P7Data,
2934 IN UINTN P7Length,
2935 OUT VOID **Content,
2936 OUT UINTN *ContentSize
2937 )
2938 {
2939 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7GetAttachedContent, Pkcs7GetAttachedContent, (P7Data, P7Length, Content, ContentSize), FALSE);
2940 }
2941
2942 /**
2943 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows
2944 Authenticode Portable Executable Signature Format".
2945
2946 If AuthData is NULL, then return FALSE.
2947 If ImageHash is NULL, then return FALSE.
2948 If this interface is not supported, then return FALSE.
2949
2950 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2951 PE/COFF image to be verified.
2952 @param[in] DataSize Size of the Authenticode Signature in bytes.
2953 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which
2954 is used for certificate chain verification.
2955 @param[in] CertSize Size of the trusted certificate in bytes.
2956 @param[in] ImageHash Pointer to the original image file hash value. The procedure
2957 for calculating the image hash value is described in Authenticode
2958 specification.
2959 @param[in] HashSize Size of Image hash value in bytes.
2960
2961 @retval TRUE The specified Authenticode Signature is valid.
2962 @retval FALSE Invalid Authenticode Signature.
2963 @retval FALSE This interface is not supported.
2964
2965 **/
2966 BOOLEAN
2967 EFIAPI
2968 CryptoServiceAuthenticodeVerify (
2969 IN CONST UINT8 *AuthData,
2970 IN UINTN DataSize,
2971 IN CONST UINT8 *TrustedCert,
2972 IN UINTN CertSize,
2973 IN CONST UINT8 *ImageHash,
2974 IN UINTN HashSize
2975 )
2976 {
2977 return CALL_BASECRYPTLIB (Pkcs.Services.AuthenticodeVerify, AuthenticodeVerify, (AuthData, DataSize, TrustedCert, CertSize, ImageHash, HashSize), FALSE);
2978 }
2979
2980 /**
2981 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode
2982 signature.
2983
2984 If AuthData is NULL, then return FALSE.
2985 If this interface is not supported, then return FALSE.
2986
2987 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed
2988 PE/COFF image to be verified.
2989 @param[in] DataSize Size of the Authenticode Signature in bytes.
2990 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which
2991 is used for TSA certificate chain verification.
2992 @param[in] CertSize Size of the trusted certificate in bytes.
2993 @param[out] SigningTime Return the time of timestamp generation time if the timestamp
2994 signature is valid.
2995
2996 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.
2997 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.
2998
2999 **/
3000 BOOLEAN
3001 EFIAPI
3002 CryptoServiceImageTimestampVerify (
3003 IN CONST UINT8 *AuthData,
3004 IN UINTN DataSize,
3005 IN CONST UINT8 *TsaCert,
3006 IN UINTN CertSize,
3007 OUT EFI_TIME *SigningTime
3008 )
3009 {
3010 return CALL_BASECRYPTLIB (Pkcs.Services.ImageTimestampVerify, ImageTimestampVerify, (AuthData, DataSize, TsaCert, CertSize, SigningTime), FALSE);
3011 }
3012
3013 //=====================================================================================
3014 // DH Key Exchange Primitive
3015 //=====================================================================================
3016
3017 /**
3018 Allocates and Initializes one Diffie-Hellman Context for subsequent use.
3019
3020 @return Pointer to the Diffie-Hellman Context that has been initialized.
3021 If the allocations fails, DhNew() returns NULL.
3022 If the interface is not supported, DhNew() returns NULL.
3023
3024 **/
3025 VOID *
3026 EFIAPI
3027 CryptoServiceDhNew (
3028 VOID
3029 )
3030 {
3031 return CALL_BASECRYPTLIB (Dh.Services.New, DhNew, (), NULL);
3032 }
3033
3034 /**
3035 Release the specified DH context.
3036
3037 If the interface is not supported, then ASSERT().
3038
3039 @param[in] DhContext Pointer to the DH context to be released.
3040
3041 **/
3042 VOID
3043 EFIAPI
3044 CryptoServiceDhFree (
3045 IN VOID *DhContext
3046 )
3047 {
3048 CALL_VOID_BASECRYPTLIB (Dh.Services.Free, DhFree, (DhContext));
3049 }
3050
3051 /**
3052 Generates DH parameter.
3053
3054 Given generator g, and length of prime number p in bits, this function generates p,
3055 and sets DH context according to value of g and p.
3056
3057 Before this function can be invoked, pseudorandom number generator must be correctly
3058 initialized by RandomSeed().
3059
3060 If DhContext is NULL, then return FALSE.
3061 If Prime is NULL, then return FALSE.
3062 If this interface is not supported, then return FALSE.
3063
3064 @param[in, out] DhContext Pointer to the DH context.
3065 @param[in] Generator Value of generator.
3066 @param[in] PrimeLength Length in bits of prime to be generated.
3067 @param[out] Prime Pointer to the buffer to receive the generated prime number.
3068
3069 @retval TRUE DH parameter generation succeeded.
3070 @retval FALSE Value of Generator is not supported.
3071 @retval FALSE PRNG fails to generate random prime number with PrimeLength.
3072 @retval FALSE This interface is not supported.
3073
3074 **/
3075 BOOLEAN
3076 EFIAPI
3077 CryptoServiceDhGenerateParameter (
3078 IN OUT VOID *DhContext,
3079 IN UINTN Generator,
3080 IN UINTN PrimeLength,
3081 OUT UINT8 *Prime
3082 )
3083 {
3084 return CALL_BASECRYPTLIB (Dh.Services.GenerateParameter, DhGenerateParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);
3085 }
3086
3087 /**
3088 Sets generator and prime parameters for DH.
3089
3090 Given generator g, and prime number p, this function and sets DH
3091 context accordingly.
3092
3093 If DhContext is NULL, then return FALSE.
3094 If Prime is NULL, then return FALSE.
3095 If this interface is not supported, then return FALSE.
3096
3097 @param[in, out] DhContext Pointer to the DH context.
3098 @param[in] Generator Value of generator.
3099 @param[in] PrimeLength Length in bits of prime to be generated.
3100 @param[in] Prime Pointer to the prime number.
3101
3102 @retval TRUE DH parameter setting succeeded.
3103 @retval FALSE Value of Generator is not supported.
3104 @retval FALSE Value of Generator is not suitable for the Prime.
3105 @retval FALSE Value of Prime is not a prime number.
3106 @retval FALSE Value of Prime is not a safe prime number.
3107 @retval FALSE This interface is not supported.
3108
3109 **/
3110 BOOLEAN
3111 EFIAPI
3112 CryptoServiceDhSetParameter (
3113 IN OUT VOID *DhContext,
3114 IN UINTN Generator,
3115 IN UINTN PrimeLength,
3116 IN CONST UINT8 *Prime
3117 )
3118 {
3119 return CALL_BASECRYPTLIB (Dh.Services.SetParameter, DhSetParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);
3120 }
3121
3122 /**
3123 Generates DH public key.
3124
3125 This function generates random secret exponent, and computes the public key, which is
3126 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.
3127 If the PublicKey buffer is too small to hold the public key, FALSE is returned and
3128 PublicKeySize is set to the required buffer size to obtain the public key.
3129
3130 If DhContext is NULL, then return FALSE.
3131 If PublicKeySize is NULL, then return FALSE.
3132 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.
3133 If this interface is not supported, then return FALSE.
3134
3135 @param[in, out] DhContext Pointer to the DH context.
3136 @param[out] PublicKey Pointer to the buffer to receive generated public key.
3137 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.
3138 On output, the size of data returned in PublicKey buffer in bytes.
3139
3140 @retval TRUE DH public key generation succeeded.
3141 @retval FALSE DH public key generation failed.
3142 @retval FALSE PublicKeySize is not large enough.
3143 @retval FALSE This interface is not supported.
3144
3145 **/
3146 BOOLEAN
3147 EFIAPI
3148 CryptoServiceDhGenerateKey (
3149 IN OUT VOID *DhContext,
3150 OUT UINT8 *PublicKey,
3151 IN OUT UINTN *PublicKeySize
3152 )
3153 {
3154 return CALL_BASECRYPTLIB (Dh.Services.GenerateKey, DhGenerateKey, (DhContext, PublicKey, PublicKeySize), FALSE);
3155 }
3156
3157 /**
3158 Computes exchanged common key.
3159
3160 Given peer's public key, this function computes the exchanged common key, based on its own
3161 context including value of prime modulus and random secret exponent.
3162
3163 If DhContext is NULL, then return FALSE.
3164 If PeerPublicKey is NULL, then return FALSE.
3165 If KeySize is NULL, then return FALSE.
3166 If Key is NULL, then return FALSE.
3167 If KeySize is not large enough, then return FALSE.
3168 If this interface is not supported, then return FALSE.
3169
3170 @param[in, out] DhContext Pointer to the DH context.
3171 @param[in] PeerPublicKey Pointer to the peer's public key.
3172 @param[in] PeerPublicKeySize Size of peer's public key in bytes.
3173 @param[out] Key Pointer to the buffer to receive generated key.
3174 @param[in, out] KeySize On input, the size of Key buffer in bytes.
3175 On output, the size of data returned in Key buffer in bytes.
3176
3177 @retval TRUE DH exchanged key generation succeeded.
3178 @retval FALSE DH exchanged key generation failed.
3179 @retval FALSE KeySize is not large enough.
3180 @retval FALSE This interface is not supported.
3181
3182 **/
3183 BOOLEAN
3184 EFIAPI
3185 CryptoServiceDhComputeKey (
3186 IN OUT VOID *DhContext,
3187 IN CONST UINT8 *PeerPublicKey,
3188 IN UINTN PeerPublicKeySize,
3189 OUT UINT8 *Key,
3190 IN OUT UINTN *KeySize
3191 )
3192 {
3193 return CALL_BASECRYPTLIB (Dh.Services.ComputeKey, DhComputeKey, (DhContext, PeerPublicKey, PeerPublicKeySize, Key, KeySize), FALSE);
3194 }
3195
3196 //=====================================================================================
3197 // Pseudo-Random Generation Primitive
3198 //=====================================================================================
3199
3200 /**
3201 Sets up the seed value for the pseudorandom number generator.
3202
3203 This function sets up the seed value for the pseudorandom number generator.
3204 If Seed is not NULL, then the seed passed in is used.
3205 If Seed is NULL, then default seed is used.
3206 If this interface is not supported, then return FALSE.
3207
3208 @param[in] Seed Pointer to seed value.
3209 If NULL, default seed is used.
3210 @param[in] SeedSize Size of seed value.
3211 If Seed is NULL, this parameter is ignored.
3212
3213 @retval TRUE Pseudorandom number generator has enough entropy for random generation.
3214 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.
3215 @retval FALSE This interface is not supported.
3216
3217 **/
3218 BOOLEAN
3219 EFIAPI
3220 CryptoServiceRandomSeed (
3221 IN CONST UINT8 *Seed OPTIONAL,
3222 IN UINTN SeedSize
3223 )
3224 {
3225 return CALL_BASECRYPTLIB (Random.Services.Seed, RandomSeed, (Seed, SeedSize), FALSE);
3226 }
3227
3228 /**
3229 Generates a pseudorandom byte stream of the specified size.
3230
3231 If Output is NULL, then return FALSE.
3232 If this interface is not supported, then return FALSE.
3233
3234 @param[out] Output Pointer to buffer to receive random value.
3235 @param[in] Size Size of random bytes to generate.
3236
3237 @retval TRUE Pseudorandom byte stream generated successfully.
3238 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.
3239 @retval FALSE This interface is not supported.
3240
3241 **/
3242 BOOLEAN
3243 EFIAPI
3244 CryptoServiceRandomBytes (
3245 OUT UINT8 *Output,
3246 IN UINTN Size
3247 )
3248 {
3249 return CALL_BASECRYPTLIB (Random.Services.Bytes, RandomBytes, (Output, Size), FALSE);
3250 }
3251
3252 //=====================================================================================
3253 // Key Derivation Function Primitive
3254 //=====================================================================================
3255
3256 /**
3257 Derive key data using HMAC-SHA256 based KDF.
3258
3259 @param[in] Key Pointer to the user-supplied key.
3260 @param[in] KeySize Key size in bytes.
3261 @param[in] Salt Pointer to the salt(non-secret) value.
3262 @param[in] SaltSize Salt size in bytes.
3263 @param[in] Info Pointer to the application specific info.
3264 @param[in] InfoSize Info size in bytes.
3265 @param[out] Out Pointer to buffer to receive hkdf value.
3266 @param[in] OutSize Size of hkdf bytes to generate.
3267
3268 @retval TRUE Hkdf generated successfully.
3269 @retval FALSE Hkdf generation failed.
3270
3271 **/
3272 BOOLEAN
3273 EFIAPI
3274 CryptoServiceHkdfSha256ExtractAndExpand (
3275 IN CONST UINT8 *Key,
3276 IN UINTN KeySize,
3277 IN CONST UINT8 *Salt,
3278 IN UINTN SaltSize,
3279 IN CONST UINT8 *Info,
3280 IN UINTN InfoSize,
3281 OUT UINT8 *Out,
3282 IN UINTN OutSize
3283 )
3284 {
3285 return CALL_BASECRYPTLIB (Hkdf.Services.Sha256ExtractAndExpand, HkdfSha256ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);
3286 }
3287
3288 /**
3289 Initializes the OpenSSL library.
3290
3291 This function registers ciphers and digests used directly and indirectly
3292 by SSL/TLS, and initializes the readable error messages.
3293 This function must be called before any other action takes places.
3294
3295 @retval TRUE The OpenSSL library has been initialized.
3296 @retval FALSE Failed to initialize the OpenSSL library.
3297
3298 **/
3299 BOOLEAN
3300 EFIAPI
3301 CryptoServiceTlsInitialize (
3302 VOID
3303 )
3304 {
3305 return CALL_BASECRYPTLIB (Tls.Services.Initialize, TlsInitialize, (), FALSE);
3306 }
3307
3308 /**
3309 Free an allocated SSL_CTX object.
3310
3311 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.
3312
3313 **/
3314 VOID
3315 EFIAPI
3316 CryptoServiceTlsCtxFree (
3317 IN VOID *TlsCtx
3318 )
3319 {
3320 CALL_VOID_BASECRYPTLIB (Tls.Services.CtxFree, TlsCtxFree, (TlsCtx));
3321 }
3322
3323 /**
3324 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled
3325 connections.
3326
3327 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3328 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3329
3330 @return Pointer to an allocated SSL_CTX object.
3331 If the creation failed, TlsCtxNew() returns NULL.
3332
3333 **/
3334 VOID *
3335 EFIAPI
3336 CryptoServiceTlsCtxNew (
3337 IN UINT8 MajorVer,
3338 IN UINT8 MinorVer
3339 )
3340 {
3341 return CALL_BASECRYPTLIB (Tls.Services.CtxNew, TlsCtxNew, (MajorVer, MinorVer), NULL);
3342 }
3343
3344 /**
3345 Free an allocated TLS object.
3346
3347 This function removes the TLS object pointed to by Tls and frees up the
3348 allocated memory. If Tls is NULL, nothing is done.
3349
3350 @param[in] Tls Pointer to the TLS object to be freed.
3351
3352 **/
3353 VOID
3354 EFIAPI
3355 CryptoServiceTlsFree (
3356 IN VOID *Tls
3357 )
3358 {
3359 CALL_VOID_BASECRYPTLIB (Tls.Services.Free, TlsFree, (Tls));
3360 }
3361
3362 /**
3363 Create a new TLS object for a connection.
3364
3365 This function creates a new TLS object for a connection. The new object
3366 inherits the setting of the underlying context TlsCtx: connection method,
3367 options, verification setting.
3368
3369 @param[in] TlsCtx Pointer to the SSL_CTX object.
3370
3371 @return Pointer to an allocated SSL object.
3372 If the creation failed, TlsNew() returns NULL.
3373
3374 **/
3375 VOID *
3376 EFIAPI
3377 CryptoServiceTlsNew (
3378 IN VOID *TlsCtx
3379 )
3380 {
3381 return CALL_BASECRYPTLIB (Tls.Services.New, TlsNew, (TlsCtx), NULL);
3382 }
3383
3384 /**
3385 Checks if the TLS handshake was done.
3386
3387 This function will check if the specified TLS handshake was done.
3388
3389 @param[in] Tls Pointer to the TLS object for handshake state checking.
3390
3391 @retval TRUE The TLS handshake was done.
3392 @retval FALSE The TLS handshake was not done.
3393
3394 **/
3395 BOOLEAN
3396 EFIAPI
3397 CryptoServiceTlsInHandshake (
3398 IN VOID *Tls
3399 )
3400 {
3401 return CALL_BASECRYPTLIB (Tls.Services.InHandshake, TlsInHandshake, (Tls), FALSE);
3402 }
3403
3404 /**
3405 Perform a TLS/SSL handshake.
3406
3407 This function will perform a TLS/SSL handshake.
3408
3409 @param[in] Tls Pointer to the TLS object for handshake operation.
3410 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.
3411 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3412 Handshake packet.
3413 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3414 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is
3415 the buffer size provided by the caller. On output, it
3416 is the buffer size in fact needed to contain the
3417 packet.
3418
3419 @retval EFI_SUCCESS The required TLS packet is built successfully.
3420 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3421 Tls is NULL.
3422 BufferIn is NULL but BufferInSize is NOT 0.
3423 BufferInSize is 0 but BufferIn is NOT NULL.
3424 BufferOutSize is NULL.
3425 BufferOut is NULL if *BufferOutSize is not zero.
3426 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3427 @retval EFI_ABORTED Something wrong during handshake.
3428
3429 **/
3430 EFI_STATUS
3431 EFIAPI
3432 CryptoServiceTlsDoHandshake (
3433 IN VOID *Tls,
3434 IN UINT8 *BufferIn, OPTIONAL
3435 IN UINTN BufferInSize, OPTIONAL
3436 OUT UINT8 *BufferOut, OPTIONAL
3437 IN OUT UINTN *BufferOutSize
3438 )
3439 {
3440 return CALL_BASECRYPTLIB (Tls.Services.DoHandshake, TlsDoHandshake, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);
3441 }
3442
3443 /**
3444 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,
3445 TLS session has errors and the response packet needs to be Alert message based on error type.
3446
3447 @param[in] Tls Pointer to the TLS object for state checking.
3448 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.
3449 @param[in] BufferInSize Packet size in bytes for the most recently received TLS
3450 Alert packet.
3451 @param[out] BufferOut Pointer to the buffer to hold the built packet.
3452 @param[in, out] BufferOutSize 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 BufferIn is NULL but BufferInSize is NOT 0.
3461 BufferInSize is 0 but BufferIn is NOT NULL.
3462 BufferOutSize is NULL.
3463 BufferOut is NULL if *BufferOutSize is not zero.
3464 @retval EFI_ABORTED An error occurred.
3465 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.
3466
3467 **/
3468 EFI_STATUS
3469 EFIAPI
3470 CryptoServiceTlsHandleAlert (
3471 IN VOID *Tls,
3472 IN UINT8 *BufferIn, OPTIONAL
3473 IN UINTN BufferInSize, OPTIONAL
3474 OUT UINT8 *BufferOut, OPTIONAL
3475 IN OUT UINTN *BufferOutSize
3476 )
3477 {
3478 return CALL_BASECRYPTLIB (Tls.Services.HandleAlert, TlsHandleAlert, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);
3479 }
3480
3481 /**
3482 Build the CloseNotify packet.
3483
3484 @param[in] Tls Pointer to the TLS object for state checking.
3485 @param[in, out] Buffer Pointer to the buffer to hold the built packet.
3486 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is
3487 the buffer size provided by the caller. On output, it
3488 is the buffer size in fact needed to contain the
3489 packet.
3490
3491 @retval EFI_SUCCESS The required TLS packet is built successfully.
3492 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
3493 Tls is NULL.
3494 BufferSize is NULL.
3495 Buffer is NULL if *BufferSize is not zero.
3496 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.
3497
3498 **/
3499 EFI_STATUS
3500 EFIAPI
3501 CryptoServiceTlsCloseNotify (
3502 IN VOID *Tls,
3503 IN OUT UINT8 *Buffer,
3504 IN OUT UINTN *BufferSize
3505 )
3506 {
3507 return CALL_BASECRYPTLIB (Tls.Services.CloseNotify, TlsCloseNotify, (Tls, Buffer, BufferSize), EFI_UNSUPPORTED);
3508 }
3509
3510 /**
3511 Attempts to read bytes from one TLS object and places the data in Buffer.
3512
3513 This function will attempt to read BufferSize bytes from the TLS object
3514 and places the data in Buffer.
3515
3516 @param[in] Tls Pointer to the TLS object.
3517 @param[in,out] Buffer Pointer to the buffer to store the data.
3518 @param[in] BufferSize The size of Buffer in bytes.
3519
3520 @retval >0 The amount of data successfully read from the TLS object.
3521 @retval <=0 No data was successfully read.
3522
3523 **/
3524 INTN
3525 EFIAPI
3526 CryptoServiceTlsCtrlTrafficOut (
3527 IN VOID *Tls,
3528 IN OUT VOID *Buffer,
3529 IN UINTN BufferSize
3530 )
3531 {
3532 return CALL_BASECRYPTLIB (Tls.Services.CtrlTrafficOut, TlsCtrlTrafficOut, (Tls, Buffer, BufferSize), 0);
3533 }
3534
3535 /**
3536 Attempts to write data from the buffer to TLS object.
3537
3538 This function will attempt to write BufferSize bytes data from the Buffer
3539 to the TLS object.
3540
3541 @param[in] Tls Pointer to the TLS object.
3542 @param[in] Buffer Pointer to the data buffer.
3543 @param[in] BufferSize The size of Buffer in bytes.
3544
3545 @retval >0 The amount of data successfully written to the TLS object.
3546 @retval <=0 No data was successfully written.
3547
3548 **/
3549 INTN
3550 EFIAPI
3551 CryptoServiceTlsCtrlTrafficIn (
3552 IN VOID *Tls,
3553 IN VOID *Buffer,
3554 IN UINTN BufferSize
3555 )
3556 {
3557 return CALL_BASECRYPTLIB (Tls.Services.CtrlTrafficIn, TlsCtrlTrafficIn, (Tls, Buffer, BufferSize), 0);
3558 }
3559
3560 /**
3561 Attempts to read bytes from the specified TLS connection into the buffer.
3562
3563 This function tries to read BufferSize bytes data from the specified TLS
3564 connection into the Buffer.
3565
3566 @param[in] Tls Pointer to the TLS connection for data reading.
3567 @param[in,out] Buffer Pointer to the data buffer.
3568 @param[in] BufferSize The size of Buffer in bytes.
3569
3570 @retval >0 The read operation was successful, and return value is the
3571 number of bytes actually read from the TLS connection.
3572 @retval <=0 The read operation was not successful.
3573
3574 **/
3575 INTN
3576 EFIAPI
3577 CryptoServiceTlsRead (
3578 IN VOID *Tls,
3579 IN OUT VOID *Buffer,
3580 IN UINTN BufferSize
3581 )
3582 {
3583 return CALL_BASECRYPTLIB (Tls.Services.Read, TlsRead, (Tls, Buffer, BufferSize), 0);
3584 }
3585
3586 /**
3587 Attempts to write data to a TLS connection.
3588
3589 This function tries to write BufferSize bytes data from the Buffer into the
3590 specified TLS connection.
3591
3592 @param[in] Tls Pointer to the TLS connection for data writing.
3593 @param[in] Buffer Pointer to the data buffer.
3594 @param[in] BufferSize The size of Buffer in bytes.
3595
3596 @retval >0 The write operation was successful, and return value is the
3597 number of bytes actually written to the TLS connection.
3598 @retval <=0 The write operation was not successful.
3599
3600 **/
3601 INTN
3602 EFIAPI
3603 CryptoServiceTlsWrite (
3604 IN VOID *Tls,
3605 IN VOID *Buffer,
3606 IN UINTN BufferSize
3607 )
3608 {
3609 return CALL_BASECRYPTLIB (Tls.Services.Write, TlsWrite, (Tls, Buffer, BufferSize), 0);
3610 }
3611
3612 /**
3613 Set a new TLS/SSL method for a particular TLS object.
3614
3615 This function sets a new TLS/SSL method for a particular TLS object.
3616
3617 @param[in] Tls Pointer to a TLS object.
3618 @param[in] MajorVer Major Version of TLS/SSL Protocol.
3619 @param[in] MinorVer Minor Version of TLS/SSL Protocol.
3620
3621 @retval EFI_SUCCESS The TLS/SSL method was set successfully.
3622 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3623 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.
3624
3625 **/
3626 EFI_STATUS
3627 EFIAPI
3628 CryptoServiceTlsSetVersion (
3629 IN VOID *Tls,
3630 IN UINT8 MajorVer,
3631 IN UINT8 MinorVer
3632 )
3633 {
3634 return CALL_BASECRYPTLIB (TlsSet.Services.Version, TlsSetVersion, (Tls, MajorVer, MinorVer), EFI_UNSUPPORTED);
3635 }
3636
3637 /**
3638 Set TLS object to work in client or server mode.
3639
3640 This function prepares a TLS object to work in client or server mode.
3641
3642 @param[in] Tls Pointer to a TLS object.
3643 @param[in] IsServer Work in server mode.
3644
3645 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.
3646 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3647 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.
3648
3649 **/
3650 EFI_STATUS
3651 EFIAPI
3652 CryptoServiceTlsSetConnectionEnd (
3653 IN VOID *Tls,
3654 IN BOOLEAN IsServer
3655 )
3656 {
3657 return CALL_BASECRYPTLIB (TlsSet.Services.ConnectionEnd, TlsSetConnectionEnd, (Tls, IsServer), EFI_UNSUPPORTED);
3658 }
3659
3660 /**
3661 Set the ciphers list to be used by the TLS object.
3662
3663 This function sets the ciphers for use by a specified TLS object.
3664
3665 @param[in] Tls Pointer to a TLS object.
3666 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16
3667 cipher identifier comes from the TLS Cipher Suite
3668 Registry of the IANA, interpreting Byte1 and Byte2
3669 in network (big endian) byte order.
3670 @param[in] CipherNum The number of cipher in the list.
3671
3672 @retval EFI_SUCCESS The ciphers list was set successfully.
3673 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3674 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.
3675 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
3676
3677 **/
3678 EFI_STATUS
3679 EFIAPI
3680 CryptoServiceTlsSetCipherList (
3681 IN VOID *Tls,
3682 IN UINT16 *CipherId,
3683 IN UINTN CipherNum
3684 )
3685 {
3686 return CALL_BASECRYPTLIB (TlsSet.Services.CipherList, TlsSetCipherList, (Tls, CipherId, CipherNum), EFI_UNSUPPORTED);
3687 }
3688
3689 /**
3690 Set the compression method for TLS/SSL operations.
3691
3692 This function handles TLS/SSL integrated compression methods.
3693
3694 @param[in] CompMethod The compression method ID.
3695
3696 @retval EFI_SUCCESS The compression method for the communication was
3697 set successfully.
3698 @retval EFI_UNSUPPORTED Unsupported compression method.
3699
3700 **/
3701 EFI_STATUS
3702 EFIAPI
3703 CryptoServiceTlsSetCompressionMethod (
3704 IN UINT8 CompMethod
3705 )
3706 {
3707 return CALL_BASECRYPTLIB (TlsSet.Services.CompressionMethod, TlsSetCompressionMethod, (CompMethod), EFI_UNSUPPORTED);
3708 }
3709
3710 /**
3711 Set peer certificate verification mode for the TLS connection.
3712
3713 This function sets the verification mode flags for the TLS connection.
3714
3715 @param[in] Tls Pointer to the TLS object.
3716 @param[in] VerifyMode A set of logically or'ed verification mode flags.
3717
3718 **/
3719 VOID
3720 EFIAPI
3721 CryptoServiceTlsSetVerify (
3722 IN VOID *Tls,
3723 IN UINT32 VerifyMode
3724 )
3725 {
3726 CALL_VOID_BASECRYPTLIB (TlsSet.Services.Verify, TlsSetVerify, (Tls, VerifyMode));
3727 }
3728
3729 /**
3730 Set the specified host name to be verified.
3731
3732 @param[in] Tls Pointer to the TLS object.
3733 @param[in] Flags The setting flags during the validation.
3734 @param[in] HostName The specified host name to be verified.
3735
3736 @retval EFI_SUCCESS The HostName setting was set successfully.
3737 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3738 @retval EFI_ABORTED Invalid HostName setting.
3739
3740 **/
3741 EFI_STATUS
3742 EFIAPI
3743 CryptoServiceTlsSetVerifyHost (
3744 IN VOID *Tls,
3745 IN UINT32 Flags,
3746 IN CHAR8 *HostName
3747 )
3748 {
3749 return CALL_BASECRYPTLIB (TlsSet.Services.VerifyHost, TlsSetVerifyHost, (Tls, Flags, HostName), EFI_UNSUPPORTED);
3750 }
3751
3752 /**
3753 Sets a TLS/SSL session ID to be used during TLS/SSL connect.
3754
3755 This function sets a session ID to be used when the TLS/SSL connection is
3756 to be established.
3757
3758 @param[in] Tls Pointer to the TLS object.
3759 @param[in] SessionId Session ID data used for session resumption.
3760 @param[in] SessionIdLen Length of Session ID in bytes.
3761
3762 @retval EFI_SUCCESS Session ID was set successfully.
3763 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3764 @retval EFI_UNSUPPORTED No available session for ID setting.
3765
3766 **/
3767 EFI_STATUS
3768 EFIAPI
3769 CryptoServiceTlsSetSessionId (
3770 IN VOID *Tls,
3771 IN UINT8 *SessionId,
3772 IN UINT16 SessionIdLen
3773 )
3774 {
3775 return CALL_BASECRYPTLIB (TlsSet.Services.SessionId, TlsSetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);
3776 }
3777
3778 /**
3779 Adds the CA to the cert store when requesting Server or Client authentication.
3780
3781 This function adds the CA certificate to the list of CAs when requesting
3782 Server or Client authentication for the chosen TLS connection.
3783
3784 @param[in] Tls Pointer to the TLS object.
3785 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3786 X.509 certificate or PEM-encoded X.509 certificate.
3787 @param[in] DataSize The size of data buffer in bytes.
3788
3789 @retval EFI_SUCCESS The operation succeeded.
3790 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3791 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3792 @retval EFI_ABORTED Invalid X.509 certificate.
3793
3794 **/
3795 EFI_STATUS
3796 EFIAPI
3797 CryptoServiceTlsSetCaCertificate (
3798 IN VOID *Tls,
3799 IN VOID *Data,
3800 IN UINTN DataSize
3801 )
3802 {
3803 return CALL_BASECRYPTLIB (TlsSet.Services.CaCertificate, TlsSetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);
3804 }
3805
3806 /**
3807 Loads the local public certificate into the specified TLS object.
3808
3809 This function loads the X.509 certificate into the specified TLS object
3810 for TLS negotiation.
3811
3812 @param[in] Tls Pointer to the TLS object.
3813 @param[in] Data Pointer to the data buffer of a DER-encoded binary
3814 X.509 certificate or PEM-encoded X.509 certificate.
3815 @param[in] DataSize The size of data buffer in bytes.
3816
3817 @retval EFI_SUCCESS The operation succeeded.
3818 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3819 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.
3820 @retval EFI_ABORTED Invalid X.509 certificate.
3821
3822 **/
3823 EFI_STATUS
3824 EFIAPI
3825 CryptoServiceTlsSetHostPublicCert (
3826 IN VOID *Tls,
3827 IN VOID *Data,
3828 IN UINTN DataSize
3829 )
3830 {
3831 return CALL_BASECRYPTLIB (TlsSet.Services.HostPublicCert, TlsSetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);
3832 }
3833
3834 /**
3835 Adds the local private key to the specified TLS object.
3836
3837 This function adds the local private key (PEM-encoded RSA or PKCS#8 private
3838 key) into the specified TLS object for TLS negotiation.
3839
3840 @param[in] Tls Pointer to the TLS object.
3841 @param[in] Data Pointer to the data buffer of a PEM-encoded RSA
3842 or PKCS#8 private key.
3843 @param[in] DataSize The size of data buffer in bytes.
3844
3845 @retval EFI_SUCCESS The operation succeeded.
3846 @retval EFI_UNSUPPORTED This function is not supported.
3847 @retval EFI_ABORTED Invalid private key data.
3848
3849 **/
3850 EFI_STATUS
3851 EFIAPI
3852 CryptoServiceTlsSetHostPrivateKey (
3853 IN VOID *Tls,
3854 IN VOID *Data,
3855 IN UINTN DataSize
3856 )
3857 {
3858 return CALL_BASECRYPTLIB (TlsSet.Services.HostPrivateKey, TlsSetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);
3859 }
3860
3861 /**
3862 Adds the CA-supplied certificate revocation list for certificate validation.
3863
3864 This function adds the CA-supplied certificate revocation list data for
3865 certificate validity checking.
3866
3867 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.
3868 @param[in] DataSize The size of data buffer in bytes.
3869
3870 @retval EFI_SUCCESS The operation succeeded.
3871 @retval EFI_UNSUPPORTED This function is not supported.
3872 @retval EFI_ABORTED Invalid CRL data.
3873
3874 **/
3875 EFI_STATUS
3876 EFIAPI
3877 CryptoServiceTlsSetCertRevocationList (
3878 IN VOID *Data,
3879 IN UINTN DataSize
3880 )
3881 {
3882 return CALL_BASECRYPTLIB (TlsSet.Services.CertRevocationList, TlsSetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);
3883 }
3884
3885 /**
3886 Gets the protocol version used by the specified TLS connection.
3887
3888 This function returns the protocol version used by the specified TLS
3889 connection.
3890
3891 If Tls is NULL, then ASSERT().
3892
3893 @param[in] Tls Pointer to the TLS object.
3894
3895 @return The protocol version of the specified TLS connection.
3896
3897 **/
3898 UINT16
3899 EFIAPI
3900 CryptoServiceTlsGetVersion (
3901 IN VOID *Tls
3902 )
3903 {
3904 return CALL_BASECRYPTLIB (TlsGet.Services.Version, TlsGetVersion, (Tls), 0);
3905 }
3906
3907 /**
3908 Gets the connection end of the specified TLS connection.
3909
3910 This function returns the connection end (as client or as server) used by
3911 the specified TLS connection.
3912
3913 If Tls is NULL, then ASSERT().
3914
3915 @param[in] Tls Pointer to the TLS object.
3916
3917 @return The connection end used by the specified TLS connection.
3918
3919 **/
3920 UINT8
3921 EFIAPI
3922 CryptoServiceTlsGetConnectionEnd (
3923 IN VOID *Tls
3924 )
3925 {
3926 return CALL_BASECRYPTLIB (TlsGet.Services.ConnectionEnd, TlsGetConnectionEnd, (Tls), 0);
3927 }
3928
3929 /**
3930 Gets the cipher suite used by the specified TLS connection.
3931
3932 This function returns current cipher suite used by the specified
3933 TLS connection.
3934
3935 @param[in] Tls Pointer to the TLS object.
3936 @param[in,out] CipherId The cipher suite used by the TLS object.
3937
3938 @retval EFI_SUCCESS The cipher suite was returned successfully.
3939 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3940 @retval EFI_UNSUPPORTED Unsupported cipher suite.
3941
3942 **/
3943 EFI_STATUS
3944 EFIAPI
3945 CryptoServiceTlsGetCurrentCipher (
3946 IN VOID *Tls,
3947 IN OUT UINT16 *CipherId
3948 )
3949 {
3950 return CALL_BASECRYPTLIB (TlsGet.Services.CurrentCipher, TlsGetCurrentCipher, (Tls, CipherId), EFI_UNSUPPORTED);
3951 }
3952
3953 /**
3954 Gets the compression methods used by the specified TLS connection.
3955
3956 This function returns current integrated compression methods used by
3957 the specified TLS connection.
3958
3959 @param[in] Tls Pointer to the TLS object.
3960 @param[in,out] CompressionId The current compression method used by
3961 the TLS object.
3962
3963 @retval EFI_SUCCESS The compression method was returned successfully.
3964 @retval EFI_INVALID_PARAMETER The parameter is invalid.
3965 @retval EFI_ABORTED Invalid Compression method.
3966 @retval EFI_UNSUPPORTED This function is not supported.
3967
3968 **/
3969 EFI_STATUS
3970 EFIAPI
3971 CryptoServiceTlsGetCurrentCompressionId (
3972 IN VOID *Tls,
3973 IN OUT UINT8 *CompressionId
3974 )
3975 {
3976 return CALL_BASECRYPTLIB (TlsGet.Services.CurrentCompressionId, TlsGetCurrentCompressionId, (Tls, CompressionId), EFI_UNSUPPORTED);
3977 }
3978
3979 /**
3980 Gets the verification mode currently set in the TLS connection.
3981
3982 This function returns the peer verification mode currently set in the
3983 specified TLS connection.
3984
3985 If Tls is NULL, then ASSERT().
3986
3987 @param[in] Tls Pointer to the TLS object.
3988
3989 @return The verification mode set in the specified TLS connection.
3990
3991 **/
3992 UINT32
3993 EFIAPI
3994 CryptoServiceTlsGetVerify (
3995 IN VOID *Tls
3996 )
3997 {
3998 return CALL_BASECRYPTLIB (TlsGet.Services.Verify, TlsGetVerify, (Tls), 0);
3999 }
4000
4001 /**
4002 Gets the session ID used by the specified TLS connection.
4003
4004 This function returns the TLS/SSL session ID currently used by the
4005 specified TLS connection.
4006
4007 @param[in] Tls Pointer to the TLS object.
4008 @param[in,out] SessionId Buffer to contain the returned session ID.
4009 @param[in,out] SessionIdLen The length of Session ID in bytes.
4010
4011 @retval EFI_SUCCESS The Session ID was returned successfully.
4012 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4013 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4014
4015 **/
4016 EFI_STATUS
4017 EFIAPI
4018 CryptoServiceTlsGetSessionId (
4019 IN VOID *Tls,
4020 IN OUT UINT8 *SessionId,
4021 IN OUT UINT16 *SessionIdLen
4022 )
4023 {
4024 return CALL_BASECRYPTLIB (TlsGet.Services.SessionId, TlsGetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);
4025 }
4026
4027 /**
4028 Gets the client random data used in the specified TLS connection.
4029
4030 This function returns the TLS/SSL client random data currently used in
4031 the specified TLS connection.
4032
4033 @param[in] Tls Pointer to the TLS object.
4034 @param[in,out] ClientRandom Buffer to contain the returned client
4035 random data (32 bytes).
4036
4037 **/
4038 VOID
4039 EFIAPI
4040 CryptoServiceTlsGetClientRandom (
4041 IN VOID *Tls,
4042 IN OUT UINT8 *ClientRandom
4043 )
4044 {
4045 CALL_VOID_BASECRYPTLIB (TlsGet.Services.ClientRandom, TlsGetClientRandom, (Tls, ClientRandom));
4046 }
4047
4048 /**
4049 Gets the server random data used in the specified TLS connection.
4050
4051 This function returns the TLS/SSL server random data currently used in
4052 the specified TLS connection.
4053
4054 @param[in] Tls Pointer to the TLS object.
4055 @param[in,out] ServerRandom Buffer to contain the returned server
4056 random data (32 bytes).
4057
4058 **/
4059 VOID
4060 EFIAPI
4061 CryptoServiceTlsGetServerRandom (
4062 IN VOID *Tls,
4063 IN OUT UINT8 *ServerRandom
4064 )
4065 {
4066 CALL_VOID_BASECRYPTLIB (TlsGet.Services.ServerRandom, TlsGetServerRandom, (Tls, ServerRandom));
4067 }
4068
4069 /**
4070 Gets the master key data used in the specified TLS connection.
4071
4072 This function returns the TLS/SSL master key material currently used in
4073 the specified TLS connection.
4074
4075 @param[in] Tls Pointer to the TLS object.
4076 @param[in,out] KeyMaterial Buffer to contain the returned key material.
4077
4078 @retval EFI_SUCCESS Key material was returned successfully.
4079 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4080 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.
4081
4082 **/
4083 EFI_STATUS
4084 EFIAPI
4085 CryptoServiceTlsGetKeyMaterial (
4086 IN VOID *Tls,
4087 IN OUT UINT8 *KeyMaterial
4088 )
4089 {
4090 return CALL_BASECRYPTLIB (TlsGet.Services.KeyMaterial, TlsGetKeyMaterial, (Tls, KeyMaterial), EFI_UNSUPPORTED);
4091 }
4092
4093 /**
4094 Gets the CA Certificate from the cert store.
4095
4096 This function returns the CA certificate for the chosen
4097 TLS connection.
4098
4099 @param[in] Tls Pointer to the TLS object.
4100 @param[out] Data Pointer to the data buffer to receive the CA
4101 certificate data sent to the client.
4102 @param[in,out] DataSize The size of data buffer in bytes.
4103
4104 @retval EFI_SUCCESS The operation succeeded.
4105 @retval EFI_UNSUPPORTED This function is not supported.
4106 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4107
4108 **/
4109 EFI_STATUS
4110 EFIAPI
4111 CryptoServiceTlsGetCaCertificate (
4112 IN VOID *Tls,
4113 OUT VOID *Data,
4114 IN OUT UINTN *DataSize
4115 )
4116 {
4117 return CALL_BASECRYPTLIB (TlsGet.Services.CaCertificate, TlsGetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4118 }
4119
4120 /**
4121 Gets the local public Certificate set in the specified TLS object.
4122
4123 This function returns the local public certificate which was currently set
4124 in the specified TLS object.
4125
4126 @param[in] Tls Pointer to the TLS object.
4127 @param[out] Data Pointer to the data buffer to receive the local
4128 public certificate.
4129 @param[in,out] DataSize The size of data buffer in bytes.
4130
4131 @retval EFI_SUCCESS The operation succeeded.
4132 @retval EFI_INVALID_PARAMETER The parameter is invalid.
4133 @retval EFI_NOT_FOUND The certificate is not found.
4134 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4135
4136 **/
4137 EFI_STATUS
4138 EFIAPI
4139 CryptoServiceTlsGetHostPublicCert (
4140 IN VOID *Tls,
4141 OUT VOID *Data,
4142 IN OUT UINTN *DataSize
4143 )
4144 {
4145 return CALL_BASECRYPTLIB (TlsGet.Services.HostPublicCert, TlsGetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4146 }
4147
4148 /**
4149 Gets the local private key set in the specified TLS object.
4150
4151 This function returns the local private key data which was currently set
4152 in the specified TLS object.
4153
4154 @param[in] Tls Pointer to the TLS object.
4155 @param[out] Data Pointer to the data buffer to receive the local
4156 private key data.
4157 @param[in,out] DataSize The size of data buffer in bytes.
4158
4159 @retval EFI_SUCCESS The operation succeeded.
4160 @retval EFI_UNSUPPORTED This function is not supported.
4161 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4162
4163 **/
4164 EFI_STATUS
4165 EFIAPI
4166 CryptoServiceTlsGetHostPrivateKey (
4167 IN VOID *Tls,
4168 OUT VOID *Data,
4169 IN OUT UINTN *DataSize
4170 )
4171 {
4172 return CALL_BASECRYPTLIB (TlsGet.Services.HostPrivateKey, TlsGetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);
4173 }
4174
4175 /**
4176 Gets the CA-supplied certificate revocation list data set in the specified
4177 TLS object.
4178
4179 This function returns the CA-supplied certificate revocation list data which
4180 was currently set in the specified TLS object.
4181
4182 @param[out] Data Pointer to the data buffer to receive the CRL data.
4183 @param[in,out] DataSize The size of data buffer in bytes.
4184
4185 @retval EFI_SUCCESS The operation succeeded.
4186 @retval EFI_UNSUPPORTED This function is not supported.
4187 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.
4188
4189 **/
4190 EFI_STATUS
4191 EFIAPI
4192 CryptoServiceTlsGetCertRevocationList (
4193 OUT VOID *Data,
4194 IN OUT UINTN *DataSize
4195 )
4196 {
4197 return CALL_BASECRYPTLIB (TlsGet.Services.CertRevocationList, TlsGetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);
4198 }
4199
4200 const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = {
4201 /// Version
4202 CryptoServiceGetCryptoVersion,
4203 /// HMAC MD5 - deprecated and unsupported
4204 DeprecatedCryptoServiceHmacMd5New,
4205 DeprecatedCryptoServiceHmacMd5Free,
4206 DeprecatedCryptoServiceHmacMd5SetKey,
4207 DeprecatedCryptoServiceHmacMd5Duplicate,
4208 DeprecatedCryptoServiceHmacMd5Update,
4209 DeprecatedCryptoServiceHmacMd5Final,
4210 /// HMAC SHA1
4211 CryptoServiceHmacSha1New,
4212 CryptoServiceHmacSha1Free,
4213 CryptoServiceHmacSha1SetKey,
4214 CryptoServiceHmacSha1Duplicate,
4215 CryptoServiceHmacSha1Update,
4216 CryptoServiceHmacSha1Final,
4217 /// HMAC SHA256
4218 CryptoServiceHmacSha256New,
4219 CryptoServiceHmacSha256Free,
4220 CryptoServiceHmacSha256SetKey,
4221 CryptoServiceHmacSha256Duplicate,
4222 CryptoServiceHmacSha256Update,
4223 CryptoServiceHmacSha256Final,
4224 /// Md4 - deprecated and unsupported
4225 DeprecatedCryptoServiceMd4GetContextSize,
4226 DeprecatedCryptoServiceMd4Init,
4227 DeprecatedCryptoServiceMd4Duplicate,
4228 DeprecatedCryptoServiceMd4Update,
4229 DeprecatedCryptoServiceMd4Final,
4230 DeprecatedCryptoServiceMd4HashAll,
4231 /// Md5
4232 CryptoServiceMd5GetContextSize,
4233 CryptoServiceMd5Init,
4234 CryptoServiceMd5Duplicate,
4235 CryptoServiceMd5Update,
4236 CryptoServiceMd5Final,
4237 CryptoServiceMd5HashAll,
4238 /// Pkcs
4239 CryptoServicePkcs1v2Encrypt,
4240 CryptoServicePkcs5HashPassword,
4241 CryptoServicePkcs7Verify,
4242 CryptoServiceVerifyEKUsInPkcs7Signature,
4243 CryptoServicePkcs7GetSigners,
4244 CryptoServicePkcs7FreeSigners,
4245 CryptoServicePkcs7Sign,
4246 CryptoServicePkcs7GetAttachedContent,
4247 CryptoServicePkcs7GetCertificatesList,
4248 CryptoServiceAuthenticodeVerify,
4249 CryptoServiceImageTimestampVerify,
4250 /// DH
4251 CryptoServiceDhNew,
4252 CryptoServiceDhFree,
4253 CryptoServiceDhGenerateParameter,
4254 CryptoServiceDhSetParameter,
4255 CryptoServiceDhGenerateKey,
4256 CryptoServiceDhComputeKey,
4257 /// Random
4258 CryptoServiceRandomSeed,
4259 CryptoServiceRandomBytes,
4260 /// RSA
4261 CryptoServiceRsaPkcs1Verify,
4262 CryptoServiceRsaNew,
4263 CryptoServiceRsaFree,
4264 CryptoServiceRsaSetKey,
4265 CryptoServiceRsaGetKey,
4266 CryptoServiceRsaGenerateKey,
4267 CryptoServiceRsaCheckKey,
4268 CryptoServiceRsaPkcs1Sign,
4269 CryptoServiceRsaPkcs1Verify,
4270 CryptoServiceRsaGetPrivateKeyFromPem,
4271 CryptoServiceRsaGetPublicKeyFromX509,
4272 /// Sha1
4273 CryptoServiceSha1GetContextSize,
4274 CryptoServiceSha1Init,
4275 CryptoServiceSha1Duplicate,
4276 CryptoServiceSha1Update,
4277 CryptoServiceSha1Final,
4278 CryptoServiceSha1HashAll,
4279 /// Sha256
4280 CryptoServiceSha256GetContextSize,
4281 CryptoServiceSha256Init,
4282 CryptoServiceSha256Duplicate,
4283 CryptoServiceSha256Update,
4284 CryptoServiceSha256Final,
4285 CryptoServiceSha256HashAll,
4286 /// Sha384
4287 CryptoServiceSha384GetContextSize,
4288 CryptoServiceSha384Init,
4289 CryptoServiceSha384Duplicate,
4290 CryptoServiceSha384Update,
4291 CryptoServiceSha384Final,
4292 CryptoServiceSha384HashAll,
4293 /// Sha512
4294 CryptoServiceSha512GetContextSize,
4295 CryptoServiceSha512Init,
4296 CryptoServiceSha512Duplicate,
4297 CryptoServiceSha512Update,
4298 CryptoServiceSha512Final,
4299 CryptoServiceSha512HashAll,
4300 /// X509
4301 CryptoServiceX509GetSubjectName,
4302 CryptoServiceX509GetCommonName,
4303 CryptoServiceX509GetOrganizationName,
4304 CryptoServiceX509VerifyCert,
4305 CryptoServiceX509ConstructCertificate,
4306 CryptoServiceX509ConstructCertificateStack,
4307 CryptoServiceX509Free,
4308 CryptoServiceX509StackFree,
4309 CryptoServiceX509GetTBSCert,
4310 /// TDES - deprecated and unsupported
4311 DeprecatedCryptoServiceTdesGetContextSize,
4312 DeprecatedCryptoServiceTdesInit,
4313 DeprecatedCryptoServiceTdesEcbEncrypt,
4314 DeprecatedCryptoServiceTdesEcbDecrypt,
4315 DeprecatedCryptoServiceTdesCbcEncrypt,
4316 DeprecatedCryptoServiceTdesCbcDecrypt,
4317 /// AES - ECB mode is deprecated and unsupported
4318 CryptoServiceAesGetContextSize,
4319 CryptoServiceAesInit,
4320 DeprecatedCryptoServiceAesEcbEncrypt,
4321 DeprecatedCryptoServiceAesEcbDecrypt,
4322 CryptoServiceAesCbcEncrypt,
4323 CryptoServiceAesCbcDecrypt,
4324 /// Arc4 - deprecated and unsupported
4325 DeprecatedCryptoServiceArc4GetContextSize,
4326 DeprecatedCryptoServiceArc4Init,
4327 DeprecatedCryptoServiceArc4Encrypt,
4328 DeprecatedCryptoServiceArc4Decrypt,
4329 DeprecatedCryptoServiceArc4Reset,
4330 /// SM3
4331 CryptoServiceSm3GetContextSize,
4332 CryptoServiceSm3Init,
4333 CryptoServiceSm3Duplicate,
4334 CryptoServiceSm3Update,
4335 CryptoServiceSm3Final,
4336 CryptoServiceSm3HashAll,
4337 /// HKDF
4338 CryptoServiceHkdfSha256ExtractAndExpand,
4339 /// X509 (Continued)
4340 CryptoServiceX509ConstructCertificateStackV,
4341 /// TLS
4342 CryptoServiceTlsInitialize,
4343 CryptoServiceTlsCtxFree,
4344 CryptoServiceTlsCtxNew,
4345 CryptoServiceTlsFree,
4346 CryptoServiceTlsNew,
4347 CryptoServiceTlsInHandshake,
4348 CryptoServiceTlsDoHandshake,
4349 CryptoServiceTlsHandleAlert,
4350 CryptoServiceTlsCloseNotify,
4351 CryptoServiceTlsCtrlTrafficOut,
4352 CryptoServiceTlsCtrlTrafficIn,
4353 CryptoServiceTlsRead,
4354 CryptoServiceTlsWrite,
4355 /// TLS Set
4356 CryptoServiceTlsSetVersion,
4357 CryptoServiceTlsSetConnectionEnd,
4358 CryptoServiceTlsSetCipherList,
4359 CryptoServiceTlsSetCompressionMethod,
4360 CryptoServiceTlsSetVerify,
4361 CryptoServiceTlsSetVerifyHost,
4362 CryptoServiceTlsSetSessionId,
4363 CryptoServiceTlsSetCaCertificate,
4364 CryptoServiceTlsSetHostPublicCert,
4365 CryptoServiceTlsSetHostPrivateKey,
4366 CryptoServiceTlsSetCertRevocationList,
4367 /// TLS Get
4368 CryptoServiceTlsGetVersion,
4369 CryptoServiceTlsGetConnectionEnd,
4370 CryptoServiceTlsGetCurrentCipher,
4371 CryptoServiceTlsGetCurrentCompressionId,
4372 CryptoServiceTlsGetVerify,
4373 CryptoServiceTlsGetSessionId,
4374 CryptoServiceTlsGetClientRandom,
4375 CryptoServiceTlsGetServerRandom,
4376 CryptoServiceTlsGetKeyMaterial,
4377 CryptoServiceTlsGetCaCertificate,
4378 CryptoServiceTlsGetHostPublicCert,
4379 CryptoServiceTlsGetHostPrivateKey,
4380 CryptoServiceTlsGetCertRevocationList
4381 };