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