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