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