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