]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Include/Library/BaseCryptLib.h
RedfishPkg/JsonLib: Fix JsonLib build failure
[mirror_edk2.git] / CryptoPkg / Include / Library / BaseCryptLib.h
CommitLineData
97f98500
HT
1/** @file\r
2 Defines base cryptographic library APIs.\r
3 The Base Cryptographic Library provides implementations of basic cryptography\r
a8c44645 4 primitives (Hash Serials, HMAC, RSA, Diffie-Hellman, etc) for UEFI security\r
5 functionality enabling.\r
97f98500 6\r
c1e66210 7Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR>\r
2009f6b4 8SPDX-License-Identifier: BSD-2-Clause-Patent\r
97f98500
HT
9\r
10**/\r
11\r
12#ifndef __BASE_CRYPT_LIB_H__\r
13#define __BASE_CRYPT_LIB_H__\r
14\r
9e8841b4
QL
15#include <Uefi/UefiBaseType.h>\r
16\r
97f98500
HT
17///\r
18/// MD5 digest size in bytes\r
19///\r
7c342378 20#define MD5_DIGEST_SIZE 16\r
97f98500
HT
21\r
22///\r
23/// SHA-1 digest size in bytes.\r
24///\r
7c342378 25#define SHA1_DIGEST_SIZE 20\r
97f98500
HT
26\r
27///\r
28/// SHA-256 digest size in bytes\r
29///\r
30#define SHA256_DIGEST_SIZE 32\r
31\r
2ac68e8b
QL
32///\r
33/// SHA-384 digest size in bytes\r
34///\r
35#define SHA384_DIGEST_SIZE 48\r
36\r
37///\r
38/// SHA-512 digest size in bytes\r
39///\r
40#define SHA512_DIGEST_SIZE 64\r
41\r
f0718d1d
LX
42///\r
43/// SM3 digest size in bytes\r
44///\r
7c342378 45#define SM3_256_DIGEST_SIZE 32\r
f0718d1d 46\r
a8c44645 47///\r
48/// TDES block size in bytes\r
49///\r
7c342378 50#define TDES_BLOCK_SIZE 8\r
a8c44645 51\r
52///\r
53/// AES block size in bytes\r
54///\r
7c342378 55#define AES_BLOCK_SIZE 16\r
a8c44645 56\r
97f98500
HT
57///\r
58/// RSA Key Tags Definition used in RsaSetKey() function for key component identification.\r
59///\r
60typedef enum {\r
61 RsaKeyN, ///< RSA public Modulus (N)\r
62 RsaKeyE, ///< RSA Public exponent (e)\r
63 RsaKeyD, ///< RSA Private exponent (d)\r
64 RsaKeyP, ///< RSA secret prime factor of Modulus (p)\r
65 RsaKeyQ, ///< RSA secret prime factor of Modules (q)\r
66 RsaKeyDp, ///< p's CRT exponent (== d mod (p - 1))\r
67 RsaKeyDq, ///< q's CRT exponent (== d mod (q - 1))\r
68 RsaKeyQInv ///< The CRT coefficient (== 1/q mod p)\r
69} RSA_KEY_TAG;\r
70\r
7c342378 71// =====================================================================================\r
97f98500 72// One-Way Cryptographic Hash Primitives\r
7c342378 73// =====================================================================================\r
97f98500 74\r
e6a12a0f 75#ifdef ENABLE_MD5_DEPRECATED_INTERFACES\r
7c342378 76\r
97f98500
HT
77/**\r
78 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
79\r
532616bb 80 If this interface is not supported, then return zero.\r
81\r
97f98500 82 @return The size, in bytes, of the context buffer required for MD5 hash operations.\r
532616bb 83 @retval 0 This interface is not supported.\r
97f98500
HT
84\r
85**/\r
86UINTN\r
87EFIAPI\r
88Md5GetContextSize (\r
89 VOID\r
90 );\r
91\r
97f98500
HT
92/**\r
93 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r
94 subsequent use.\r
95\r
16d2c32c 96 If Md5Context is NULL, then return FALSE.\r
532616bb 97 If this interface is not supported, then return FALSE.\r
97f98500 98\r
a8c44645 99 @param[out] Md5Context Pointer to MD5 context being initialized.\r
97f98500
HT
100\r
101 @retval TRUE MD5 context initialization succeeded.\r
102 @retval FALSE MD5 context initialization failed.\r
532616bb 103 @retval FALSE This interface is not supported.\r
97f98500
HT
104\r
105**/\r
106BOOLEAN\r
107EFIAPI\r
108Md5Init (\r
a8c44645 109 OUT VOID *Md5Context\r
97f98500
HT
110 );\r
111\r
a8c44645 112/**\r
113 Makes a copy of an existing MD5 context.\r
114\r
16d2c32c 115 If Md5Context is NULL, then return FALSE.\r
116 If NewMd5Context is NULL, then return FALSE.\r
532616bb 117 If this interface is not supported, then return FALSE.\r
a8c44645 118\r
119 @param[in] Md5Context Pointer to MD5 context being copied.\r
120 @param[out] NewMd5Context Pointer to new MD5 context.\r
121\r
122 @retval TRUE MD5 context copy succeeded.\r
123 @retval FALSE MD5 context copy failed.\r
532616bb 124 @retval FALSE This interface is not supported.\r
a8c44645 125\r
126**/\r
127BOOLEAN\r
128EFIAPI\r
129Md5Duplicate (\r
130 IN CONST VOID *Md5Context,\r
131 OUT VOID *NewMd5Context\r
132 );\r
97f98500
HT
133\r
134/**\r
a8c44645 135 Digests the input data and updates MD5 context.\r
136\r
137 This function performs MD5 digest on a data buffer of the specified size.\r
138 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
2998af86 139 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized\r
a8c44645 140 by Md5Final(). Behavior with invalid context is undefined.\r
97f98500 141\r
16d2c32c 142 If Md5Context is NULL, then return FALSE.\r
532616bb 143 If this interface is not supported, then return FALSE.\r
97f98500
HT
144\r
145 @param[in, out] Md5Context Pointer to the MD5 context.\r
146 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
a8c44645 147 @param[in] DataSize Size of Data buffer in bytes.\r
97f98500
HT
148\r
149 @retval TRUE MD5 data digest succeeded.\r
a8c44645 150 @retval FALSE MD5 data digest failed.\r
532616bb 151 @retval FALSE This interface is not supported.\r
97f98500
HT
152\r
153**/\r
154BOOLEAN\r
155EFIAPI\r
156Md5Update (\r
157 IN OUT VOID *Md5Context,\r
158 IN CONST VOID *Data,\r
a8c44645 159 IN UINTN DataSize\r
97f98500
HT
160 );\r
161\r
97f98500 162/**\r
a8c44645 163 Completes computation of the MD5 digest value.\r
164\r
165 This function completes MD5 hash computation and retrieves the digest value into\r
166 the specified memory. After this function has been called, the MD5 context cannot\r
167 be used again.\r
2998af86 168 MD5 context should be already correctly initialized by Md5Init(), and should not be\r
a8c44645 169 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r
97f98500 170\r
16d2c32c 171 If Md5Context is NULL, then return FALSE.\r
172 If HashValue is NULL, then return FALSE.\r
532616bb 173 If this interface is not supported, then return FALSE.\r
97f98500 174\r
a8c44645 175 @param[in, out] Md5Context Pointer to the MD5 context.\r
97f98500
HT
176 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
177 value (16 bytes).\r
178\r
179 @retval TRUE MD5 digest computation succeeded.\r
180 @retval FALSE MD5 digest computation failed.\r
532616bb 181 @retval FALSE This interface is not supported.\r
97f98500
HT
182\r
183**/\r
184BOOLEAN\r
185EFIAPI\r
186Md5Final (\r
187 IN OUT VOID *Md5Context,\r
188 OUT UINT8 *HashValue\r
189 );\r
190\r
b7d1ba0a
QL
191/**\r
192 Computes the MD5 message digest of a input data buffer.\r
193\r
194 This function performs the MD5 message digest of a given data buffer, and places\r
195 the digest value into the specified memory.\r
196\r
197 If this interface is not supported, then return FALSE.\r
198\r
199 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
200 @param[in] DataSize Size of Data buffer in bytes.\r
201 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
202 value (16 bytes).\r
203\r
204 @retval TRUE MD5 digest computation succeeded.\r
205 @retval FALSE MD5 digest computation failed.\r
206 @retval FALSE This interface is not supported.\r
207\r
208**/\r
209BOOLEAN\r
210EFIAPI\r
211Md5HashAll (\r
212 IN CONST VOID *Data,\r
213 IN UINTN DataSize,\r
214 OUT UINT8 *HashValue\r
215 );\r
7c342378 216\r
acfd5557 217#endif\r
b7d1ba0a 218\r
0f01cec5 219#ifndef DISABLE_SHA1_DEPRECATED_INTERFACES\r
7c342378 220\r
97f98500
HT
221/**\r
222 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
223\r
532616bb 224 If this interface is not supported, then return zero.\r
225\r
97f98500 226 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.\r
532616bb 227 @retval 0 This interface is not supported.\r
97f98500
HT
228\r
229**/\r
230UINTN\r
231EFIAPI\r
232Sha1GetContextSize (\r
233 VOID\r
234 );\r
235\r
97f98500 236/**\r
a8c44645 237 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for\r
97f98500
HT
238 subsequent use.\r
239\r
16d2c32c 240 If Sha1Context is NULL, then return FALSE.\r
532616bb 241 If this interface is not supported, then return FALSE.\r
97f98500 242\r
a8c44645 243 @param[out] Sha1Context Pointer to SHA-1 context being initialized.\r
97f98500 244\r
a8c44645 245 @retval TRUE SHA-1 context initialization succeeded.\r
246 @retval FALSE SHA-1 context initialization failed.\r
532616bb 247 @retval FALSE This interface is not supported.\r
97f98500
HT
248\r
249**/\r
250BOOLEAN\r
251EFIAPI\r
252Sha1Init (\r
a8c44645 253 OUT VOID *Sha1Context\r
97f98500
HT
254 );\r
255\r
a8c44645 256/**\r
257 Makes a copy of an existing SHA-1 context.\r
258\r
16d2c32c 259 If Sha1Context is NULL, then return FALSE.\r
260 If NewSha1Context is NULL, then return FALSE.\r
532616bb 261 If this interface is not supported, then return FALSE.\r
a8c44645 262\r
263 @param[in] Sha1Context Pointer to SHA-1 context being copied.\r
264 @param[out] NewSha1Context Pointer to new SHA-1 context.\r
265\r
266 @retval TRUE SHA-1 context copy succeeded.\r
267 @retval FALSE SHA-1 context copy failed.\r
532616bb 268 @retval FALSE This interface is not supported.\r
a8c44645 269\r
270**/\r
271BOOLEAN\r
272EFIAPI\r
273Sha1Duplicate (\r
274 IN CONST VOID *Sha1Context,\r
275 OUT VOID *NewSha1Context\r
276 );\r
97f98500
HT
277\r
278/**\r
a8c44645 279 Digests the input data and updates SHA-1 context.\r
280\r
281 This function performs SHA-1 digest on a data buffer of the specified size.\r
282 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
2998af86 283 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized\r
a8c44645 284 by Sha1Final(). Behavior with invalid context is undefined.\r
97f98500 285\r
16d2c32c 286 If Sha1Context is NULL, then return FALSE.\r
532616bb 287 If this interface is not supported, then return FALSE.\r
97f98500
HT
288\r
289 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
290 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
a8c44645 291 @param[in] DataSize Size of Data buffer in bytes.\r
97f98500
HT
292\r
293 @retval TRUE SHA-1 data digest succeeded.\r
a8c44645 294 @retval FALSE SHA-1 data digest failed.\r
532616bb 295 @retval FALSE This interface is not supported.\r
97f98500
HT
296\r
297**/\r
298BOOLEAN\r
299EFIAPI\r
300Sha1Update (\r
301 IN OUT VOID *Sha1Context,\r
302 IN CONST VOID *Data,\r
a8c44645 303 IN UINTN DataSize\r
97f98500
HT
304 );\r
305\r
97f98500 306/**\r
a8c44645 307 Completes computation of the SHA-1 digest value.\r
308\r
309 This function completes SHA-1 hash computation and retrieves the digest value into\r
310 the specified memory. After this function has been called, the SHA-1 context cannot\r
311 be used again.\r
2998af86 312 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be\r
a8c44645 313 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.\r
97f98500 314\r
16d2c32c 315 If Sha1Context is NULL, then return FALSE.\r
316 If HashValue is NULL, then return FALSE.\r
532616bb 317 If this interface is not supported, then return FALSE.\r
97f98500 318\r
a8c44645 319 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
97f98500
HT
320 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
321 value (20 bytes).\r
322\r
323 @retval TRUE SHA-1 digest computation succeeded.\r
324 @retval FALSE SHA-1 digest computation failed.\r
532616bb 325 @retval FALSE This interface is not supported.\r
97f98500
HT
326\r
327**/\r
328BOOLEAN\r
329EFIAPI\r
330Sha1Final (\r
331 IN OUT VOID *Sha1Context,\r
332 OUT UINT8 *HashValue\r
333 );\r
334\r
b7d1ba0a
QL
335/**\r
336 Computes the SHA-1 message digest of a input data buffer.\r
337\r
338 This function performs the SHA-1 message digest of a given data buffer, and places\r
339 the digest value into the specified memory.\r
340\r
341 If this interface is not supported, then return FALSE.\r
342\r
343 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
344 @param[in] DataSize Size of Data buffer in bytes.\r
345 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
346 value (20 bytes).\r
347\r
348 @retval TRUE SHA-1 digest computation succeeded.\r
349 @retval FALSE SHA-1 digest computation failed.\r
350 @retval FALSE This interface is not supported.\r
351\r
352**/\r
353BOOLEAN\r
354EFIAPI\r
355Sha1HashAll (\r
356 IN CONST VOID *Data,\r
357 IN UINTN DataSize,\r
358 OUT UINT8 *HashValue\r
359 );\r
7c342378 360\r
0f01cec5 361#endif\r
b7d1ba0a 362\r
97f98500 363/**\r
a8c44645 364 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.\r
97f98500 365\r
a8c44645 366 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.\r
97f98500
HT
367\r
368**/\r
369UINTN\r
370EFIAPI\r
371Sha256GetContextSize (\r
372 VOID\r
373 );\r
374\r
97f98500
HT
375/**\r
376 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for\r
377 subsequent use.\r
378\r
16d2c32c 379 If Sha256Context is NULL, then return FALSE.\r
97f98500 380\r
a8c44645 381 @param[out] Sha256Context Pointer to SHA-256 context being initialized.\r
97f98500
HT
382\r
383 @retval TRUE SHA-256 context initialization succeeded.\r
384 @retval FALSE SHA-256 context initialization failed.\r
385\r
386**/\r
387BOOLEAN\r
388EFIAPI\r
389Sha256Init (\r
a8c44645 390 OUT VOID *Sha256Context\r
97f98500
HT
391 );\r
392\r
a8c44645 393/**\r
394 Makes a copy of an existing SHA-256 context.\r
395\r
16d2c32c 396 If Sha256Context is NULL, then return FALSE.\r
397 If NewSha256Context is NULL, then return FALSE.\r
532616bb 398 If this interface is not supported, then return FALSE.\r
a8c44645 399\r
400 @param[in] Sha256Context Pointer to SHA-256 context being copied.\r
401 @param[out] NewSha256Context Pointer to new SHA-256 context.\r
402\r
403 @retval TRUE SHA-256 context copy succeeded.\r
404 @retval FALSE SHA-256 context copy failed.\r
532616bb 405 @retval FALSE This interface is not supported.\r
a8c44645 406\r
407**/\r
408BOOLEAN\r
409EFIAPI\r
410Sha256Duplicate (\r
411 IN CONST VOID *Sha256Context,\r
412 OUT VOID *NewSha256Context\r
413 );\r
97f98500
HT
414\r
415/**\r
a8c44645 416 Digests the input data and updates SHA-256 context.\r
417\r
418 This function performs SHA-256 digest on a data buffer of the specified size.\r
419 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
2998af86 420 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized\r
a8c44645 421 by Sha256Final(). Behavior with invalid context is undefined.\r
97f98500 422\r
16d2c32c 423 If Sha256Context is NULL, then return FALSE.\r
97f98500
HT
424\r
425 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
426 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
a8c44645 427 @param[in] DataSize Size of Data buffer in bytes.\r
97f98500
HT
428\r
429 @retval TRUE SHA-256 data digest succeeded.\r
a8c44645 430 @retval FALSE SHA-256 data digest failed.\r
97f98500
HT
431\r
432**/\r
433BOOLEAN\r
434EFIAPI\r
435Sha256Update (\r
436 IN OUT VOID *Sha256Context,\r
437 IN CONST VOID *Data,\r
a8c44645 438 IN UINTN DataSize\r
97f98500
HT
439 );\r
440\r
97f98500 441/**\r
a8c44645 442 Completes computation of the SHA-256 digest value.\r
443\r
444 This function completes SHA-256 hash computation and retrieves the digest value into\r
445 the specified memory. After this function has been called, the SHA-256 context cannot\r
446 be used again.\r
2998af86 447 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be\r
a8c44645 448 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.\r
97f98500 449\r
16d2c32c 450 If Sha256Context is NULL, then return FALSE.\r
451 If HashValue is NULL, then return FALSE.\r
97f98500 452\r
a8c44645 453 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
97f98500
HT
454 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
455 value (32 bytes).\r
456\r
457 @retval TRUE SHA-256 digest computation succeeded.\r
458 @retval FALSE SHA-256 digest computation failed.\r
459\r
460**/\r
461BOOLEAN\r
462EFIAPI\r
463Sha256Final (\r
464 IN OUT VOID *Sha256Context,\r
465 OUT UINT8 *HashValue\r
466 );\r
467\r
b7d1ba0a
QL
468/**\r
469 Computes the SHA-256 message digest of a input data buffer.\r
470\r
471 This function performs the SHA-256 message digest of a given data buffer, and places\r
472 the digest value into the specified memory.\r
473\r
474 If this interface is not supported, then return FALSE.\r
475\r
476 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
477 @param[in] DataSize Size of Data buffer in bytes.\r
478 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
479 value (32 bytes).\r
480\r
481 @retval TRUE SHA-256 digest computation succeeded.\r
482 @retval FALSE SHA-256 digest computation failed.\r
483 @retval FALSE This interface is not supported.\r
484\r
485**/\r
486BOOLEAN\r
487EFIAPI\r
488Sha256HashAll (\r
489 IN CONST VOID *Data,\r
490 IN UINTN DataSize,\r
491 OUT UINT8 *HashValue\r
492 );\r
493\r
2ac68e8b
QL
494/**\r
495 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.\r
496\r
497 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.\r
498\r
499**/\r
500UINTN\r
501EFIAPI\r
502Sha384GetContextSize (\r
503 VOID\r
504 );\r
505\r
506/**\r
507 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for\r
508 subsequent use.\r
509\r
510 If Sha384Context is NULL, then return FALSE.\r
511\r
512 @param[out] Sha384Context Pointer to SHA-384 context being initialized.\r
513\r
514 @retval TRUE SHA-384 context initialization succeeded.\r
515 @retval FALSE SHA-384 context initialization failed.\r
516\r
517**/\r
518BOOLEAN\r
519EFIAPI\r
520Sha384Init (\r
521 OUT VOID *Sha384Context\r
522 );\r
523\r
524/**\r
525 Makes a copy of an existing SHA-384 context.\r
526\r
527 If Sha384Context is NULL, then return FALSE.\r
528 If NewSha384Context is NULL, then return FALSE.\r
529 If this interface is not supported, then return FALSE.\r
530\r
531 @param[in] Sha384Context Pointer to SHA-384 context being copied.\r
532 @param[out] NewSha384Context Pointer to new SHA-384 context.\r
533\r
534 @retval TRUE SHA-384 context copy succeeded.\r
535 @retval FALSE SHA-384 context copy failed.\r
536 @retval FALSE This interface is not supported.\r
537\r
538**/\r
539BOOLEAN\r
540EFIAPI\r
541Sha384Duplicate (\r
542 IN CONST VOID *Sha384Context,\r
543 OUT VOID *NewSha384Context\r
544 );\r
545\r
546/**\r
547 Digests the input data and updates SHA-384 context.\r
548\r
549 This function performs SHA-384 digest on a data buffer of the specified size.\r
550 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
2998af86 551 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized\r
2ac68e8b
QL
552 by Sha384Final(). Behavior with invalid context is undefined.\r
553\r
554 If Sha384Context is NULL, then return FALSE.\r
555\r
556 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
557 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
558 @param[in] DataSize Size of Data buffer in bytes.\r
559\r
560 @retval TRUE SHA-384 data digest succeeded.\r
561 @retval FALSE SHA-384 data digest failed.\r
562\r
563**/\r
564BOOLEAN\r
565EFIAPI\r
566Sha384Update (\r
567 IN OUT VOID *Sha384Context,\r
568 IN CONST VOID *Data,\r
569 IN UINTN DataSize\r
570 );\r
571\r
572/**\r
573 Completes computation of the SHA-384 digest value.\r
574\r
575 This function completes SHA-384 hash computation and retrieves the digest value into\r
576 the specified memory. After this function has been called, the SHA-384 context cannot\r
577 be used again.\r
2998af86 578 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be\r
2ac68e8b
QL
579 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.\r
580\r
581 If Sha384Context is NULL, then return FALSE.\r
582 If HashValue is NULL, then return FALSE.\r
583\r
584 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
585 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
586 value (48 bytes).\r
587\r
588 @retval TRUE SHA-384 digest computation succeeded.\r
589 @retval FALSE SHA-384 digest computation failed.\r
590\r
591**/\r
592BOOLEAN\r
593EFIAPI\r
594Sha384Final (\r
595 IN OUT VOID *Sha384Context,\r
596 OUT UINT8 *HashValue\r
597 );\r
598\r
b7d1ba0a
QL
599/**\r
600 Computes the SHA-384 message digest of a input data buffer.\r
601\r
602 This function performs the SHA-384 message digest of a given data buffer, and places\r
603 the digest value into the specified memory.\r
604\r
605 If this interface is not supported, then return FALSE.\r
606\r
607 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
608 @param[in] DataSize Size of Data buffer in bytes.\r
609 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
610 value (48 bytes).\r
611\r
612 @retval TRUE SHA-384 digest computation succeeded.\r
613 @retval FALSE SHA-384 digest computation failed.\r
614 @retval FALSE This interface is not supported.\r
615\r
616**/\r
617BOOLEAN\r
618EFIAPI\r
619Sha384HashAll (\r
620 IN CONST VOID *Data,\r
621 IN UINTN DataSize,\r
622 OUT UINT8 *HashValue\r
623 );\r
624\r
2ac68e8b
QL
625/**\r
626 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
627\r
628 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.\r
629\r
630**/\r
631UINTN\r
632EFIAPI\r
633Sha512GetContextSize (\r
634 VOID\r
635 );\r
636\r
637/**\r
638 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for\r
639 subsequent use.\r
640\r
641 If Sha512Context is NULL, then return FALSE.\r
642\r
643 @param[out] Sha512Context Pointer to SHA-512 context being initialized.\r
644\r
645 @retval TRUE SHA-512 context initialization succeeded.\r
646 @retval FALSE SHA-512 context initialization failed.\r
647\r
648**/\r
649BOOLEAN\r
650EFIAPI\r
651Sha512Init (\r
652 OUT VOID *Sha512Context\r
653 );\r
654\r
655/**\r
656 Makes a copy of an existing SHA-512 context.\r
657\r
658 If Sha512Context is NULL, then return FALSE.\r
659 If NewSha512Context is NULL, then return FALSE.\r
660 If this interface is not supported, then return FALSE.\r
661\r
662 @param[in] Sha512Context Pointer to SHA-512 context being copied.\r
663 @param[out] NewSha512Context Pointer to new SHA-512 context.\r
664\r
665 @retval TRUE SHA-512 context copy succeeded.\r
666 @retval FALSE SHA-512 context copy failed.\r
667 @retval FALSE This interface is not supported.\r
668\r
669**/\r
670BOOLEAN\r
671EFIAPI\r
672Sha512Duplicate (\r
673 IN CONST VOID *Sha512Context,\r
674 OUT VOID *NewSha512Context\r
675 );\r
676\r
677/**\r
678 Digests the input data and updates SHA-512 context.\r
679\r
680 This function performs SHA-512 digest on a data buffer of the specified size.\r
681 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
2998af86 682 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized\r
2ac68e8b
QL
683 by Sha512Final(). Behavior with invalid context is undefined.\r
684\r
685 If Sha512Context is NULL, then return FALSE.\r
686\r
687 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
688 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
689 @param[in] DataSize Size of Data buffer in bytes.\r
690\r
691 @retval TRUE SHA-512 data digest succeeded.\r
692 @retval FALSE SHA-512 data digest failed.\r
693\r
694**/\r
695BOOLEAN\r
696EFIAPI\r
697Sha512Update (\r
698 IN OUT VOID *Sha512Context,\r
699 IN CONST VOID *Data,\r
700 IN UINTN DataSize\r
701 );\r
702\r
703/**\r
704 Completes computation of the SHA-512 digest value.\r
705\r
706 This function completes SHA-512 hash computation and retrieves the digest value into\r
707 the specified memory. After this function has been called, the SHA-512 context cannot\r
708 be used again.\r
2998af86 709 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be\r
2ac68e8b
QL
710 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.\r
711\r
712 If Sha512Context is NULL, then return FALSE.\r
713 If HashValue is NULL, then return FALSE.\r
714\r
715 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
716 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
717 value (64 bytes).\r
718\r
719 @retval TRUE SHA-512 digest computation succeeded.\r
720 @retval FALSE SHA-512 digest computation failed.\r
721\r
722**/\r
723BOOLEAN\r
724EFIAPI\r
725Sha512Final (\r
726 IN OUT VOID *Sha512Context,\r
727 OUT UINT8 *HashValue\r
728 );\r
97f98500 729\r
b7d1ba0a
QL
730/**\r
731 Computes the SHA-512 message digest of a input data buffer.\r
732\r
733 This function performs the SHA-512 message digest of a given data buffer, and places\r
734 the digest value into the specified memory.\r
735\r
736 If this interface is not supported, then return FALSE.\r
737\r
738 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
739 @param[in] DataSize Size of Data buffer in bytes.\r
740 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
741 value (64 bytes).\r
742\r
743 @retval TRUE SHA-512 digest computation succeeded.\r
744 @retval FALSE SHA-512 digest computation failed.\r
745 @retval FALSE This interface is not supported.\r
746\r
747**/\r
748BOOLEAN\r
749EFIAPI\r
750Sha512HashAll (\r
751 IN CONST VOID *Data,\r
752 IN UINTN DataSize,\r
753 OUT UINT8 *HashValue\r
754 );\r
755\r
c1e66210
ZL
756/**\r
757 Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,\r
758 published December 2016.\r
759\r
760 @param[in] Input Pointer to the input message (X).\r
761 @param[in] InputByteLen The number(>0) of input bytes provided for the input data.\r
762 @param[in] BlockSize The size of each block (B).\r
763 @param[out] Output Pointer to the output buffer.\r
764 @param[in] OutputByteLen The desired number of output bytes (L).\r
765 @param[in] Customization Pointer to the customization string (S).\r
766 @param[in] CustomByteLen The length of the customization string in bytes.\r
767\r
768 @retval TRUE ParallelHash256 digest computation succeeded.\r
769 @retval FALSE ParallelHash256 digest computation failed.\r
770 @retval FALSE This interface is not supported.\r
771\r
772**/\r
773BOOLEAN\r
774EFIAPI\r
775ParallelHash256HashAll (\r
776 IN CONST VOID *Input,\r
777 IN UINTN InputByteLen,\r
778 IN UINTN BlockSize,\r
779 OUT VOID *Output,\r
780 IN UINTN OutputByteLen,\r
781 IN CONST VOID *Customization,\r
782 IN UINTN CustomByteLen\r
783 );\r
784\r
f0718d1d
LX
785/**\r
786 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.\r
787\r
788 @return The size, in bytes, of the context buffer required for SM3 hash operations.\r
789\r
790**/\r
791UINTN\r
792EFIAPI\r
793Sm3GetContextSize (\r
794 VOID\r
795 );\r
796\r
797/**\r
798 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for\r
799 subsequent use.\r
800\r
801 If Sm3Context is NULL, then return FALSE.\r
802\r
803 @param[out] Sm3Context Pointer to SM3 context being initialized.\r
804\r
805 @retval TRUE SM3 context initialization succeeded.\r
806 @retval FALSE SM3 context initialization failed.\r
807\r
808**/\r
809BOOLEAN\r
810EFIAPI\r
811Sm3Init (\r
812 OUT VOID *Sm3Context\r
813 );\r
814\r
815/**\r
816 Makes a copy of an existing SM3 context.\r
817\r
818 If Sm3Context is NULL, then return FALSE.\r
819 If NewSm3Context is NULL, then return FALSE.\r
820 If this interface is not supported, then return FALSE.\r
821\r
822 @param[in] Sm3Context Pointer to SM3 context being copied.\r
823 @param[out] NewSm3Context Pointer to new SM3 context.\r
824\r
825 @retval TRUE SM3 context copy succeeded.\r
826 @retval FALSE SM3 context copy failed.\r
827 @retval FALSE This interface is not supported.\r
828\r
829**/\r
830BOOLEAN\r
831EFIAPI\r
832Sm3Duplicate (\r
833 IN CONST VOID *Sm3Context,\r
834 OUT VOID *NewSm3Context\r
835 );\r
836\r
837/**\r
838 Digests the input data and updates SM3 context.\r
839\r
840 This function performs SM3 digest on a data buffer of the specified size.\r
841 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
842 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized\r
843 by Sm3Final(). Behavior with invalid context is undefined.\r
844\r
845 If Sm3Context is NULL, then return FALSE.\r
846\r
847 @param[in, out] Sm3Context Pointer to the SM3 context.\r
848 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
849 @param[in] DataSize Size of Data buffer in bytes.\r
850\r
851 @retval TRUE SM3 data digest succeeded.\r
852 @retval FALSE SM3 data digest failed.\r
853\r
854**/\r
855BOOLEAN\r
856EFIAPI\r
857Sm3Update (\r
858 IN OUT VOID *Sm3Context,\r
859 IN CONST VOID *Data,\r
860 IN UINTN DataSize\r
861 );\r
862\r
863/**\r
864 Completes computation of the SM3 digest value.\r
865\r
866 This function completes SM3 hash computation and retrieves the digest value into\r
867 the specified memory. After this function has been called, the SM3 context cannot\r
868 be used again.\r
869 SM3 context should be already correctly initialized by Sm3Init(), and should not be\r
870 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.\r
871\r
872 If Sm3Context is NULL, then return FALSE.\r
873 If HashValue is NULL, then return FALSE.\r
874\r
875 @param[in, out] Sm3Context Pointer to the SM3 context.\r
876 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
877 value (32 bytes).\r
878\r
879 @retval TRUE SM3 digest computation succeeded.\r
880 @retval FALSE SM3 digest computation failed.\r
881\r
882**/\r
883BOOLEAN\r
884EFIAPI\r
885Sm3Final (\r
886 IN OUT VOID *Sm3Context,\r
887 OUT UINT8 *HashValue\r
888 );\r
889\r
890/**\r
891 Computes the SM3 message digest of a input data buffer.\r
892\r
893 This function performs the SM3 message digest of a given data buffer, and places\r
894 the digest value into the specified memory.\r
895\r
896 If this interface is not supported, then return FALSE.\r
897\r
898 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
899 @param[in] DataSize Size of Data buffer in bytes.\r
900 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
901 value (32 bytes).\r
902\r
903 @retval TRUE SM3 digest computation succeeded.\r
904 @retval FALSE SM3 digest computation failed.\r
905 @retval FALSE This interface is not supported.\r
906\r
907**/\r
908BOOLEAN\r
909EFIAPI\r
910Sm3HashAll (\r
911 IN CONST VOID *Data,\r
912 IN UINTN DataSize,\r
913 OUT UINT8 *HashValue\r
914 );\r
915\r
7c342378 916// =====================================================================================\r
97f98500 917// MAC (Message Authentication Code) Primitive\r
7c342378 918// =====================================================================================\r
97f98500 919\r
4c270243
QL
920/**\r
921 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.\r
922\r
923 @return Pointer to the HMAC_CTX context that has been initialized.\r
924 If the allocations fails, HmacSha256New() returns NULL.\r
925\r
926**/\r
927VOID *\r
928EFIAPI\r
929HmacSha256New (\r
930 VOID\r
931 );\r
932\r
933/**\r
934 Release the specified HMAC_CTX context.\r
935\r
936 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.\r
937\r
938**/\r
939VOID\r
940EFIAPI\r
941HmacSha256Free (\r
942 IN VOID *HmacSha256Ctx\r
943 );\r
944\r
72009c62 945/**\r
a23fdff6
JW
946 Set user-supplied key for subsequent use. It must be done before any\r
947 calling to HmacSha256Update().\r
72009c62
QL
948\r
949 If HmacSha256Context is NULL, then return FALSE.\r
950 If this interface is not supported, then return FALSE.\r
951\r
a23fdff6 952 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.\r
72009c62
QL
953 @param[in] Key Pointer to the user-supplied key.\r
954 @param[in] KeySize Key size in bytes.\r
955\r
a23fdff6
JW
956 @retval TRUE The Key is set successfully.\r
957 @retval FALSE The Key is set unsuccessfully.\r
72009c62
QL
958 @retval FALSE This interface is not supported.\r
959\r
960**/\r
961BOOLEAN\r
962EFIAPI\r
a23fdff6 963HmacSha256SetKey (\r
72009c62
QL
964 OUT VOID *HmacSha256Context,\r
965 IN CONST UINT8 *Key,\r
966 IN UINTN KeySize\r
967 );\r
968\r
969/**\r
970 Makes a copy of an existing HMAC-SHA256 context.\r
971\r
972 If HmacSha256Context is NULL, then return FALSE.\r
973 If NewHmacSha256Context is NULL, then return FALSE.\r
974 If this interface is not supported, then return FALSE.\r
975\r
976 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.\r
977 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.\r
978\r
979 @retval TRUE HMAC-SHA256 context copy succeeded.\r
980 @retval FALSE HMAC-SHA256 context copy failed.\r
981 @retval FALSE This interface is not supported.\r
982\r
983**/\r
984BOOLEAN\r
985EFIAPI\r
986HmacSha256Duplicate (\r
987 IN CONST VOID *HmacSha256Context,\r
988 OUT VOID *NewHmacSha256Context\r
989 );\r
990\r
991/**\r
992 Digests the input data and updates HMAC-SHA256 context.\r
993\r
994 This function performs HMAC-SHA256 digest on a data buffer of the specified size.\r
995 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
a23fdff6
JW
996 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
997 by HmacSha256Final(). Behavior with invalid context is undefined.\r
72009c62
QL
998\r
999 If HmacSha256Context is NULL, then return FALSE.\r
1000 If this interface is not supported, then return FALSE.\r
1001\r
1002 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
1003 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1004 @param[in] DataSize Size of Data buffer in bytes.\r
1005\r
1006 @retval TRUE HMAC-SHA256 data digest succeeded.\r
1007 @retval FALSE HMAC-SHA256 data digest failed.\r
1008 @retval FALSE This interface is not supported.\r
1009\r
1010**/\r
1011BOOLEAN\r
1012EFIAPI\r
1013HmacSha256Update (\r
1014 IN OUT VOID *HmacSha256Context,\r
1015 IN CONST VOID *Data,\r
1016 IN UINTN DataSize\r
1017 );\r
1018\r
1019/**\r
1020 Completes computation of the HMAC-SHA256 digest value.\r
1021\r
1022 This function completes HMAC-SHA256 hash computation and retrieves the digest value into\r
1023 the specified memory. After this function has been called, the HMAC-SHA256 context cannot\r
1024 be used again.\r
a23fdff6
JW
1025 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1026 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.\r
72009c62
QL
1027\r
1028 If HmacSha256Context is NULL, then return FALSE.\r
68ae7cd6 1029 If HmacValue is NULL, then return FALSE.\r
72009c62
QL
1030 If this interface is not supported, then return FALSE.\r
1031\r
1032 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
68ae7cd6 1033 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
72009c62
QL
1034 value (32 bytes).\r
1035\r
1036 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1037 @retval FALSE HMAC-SHA256 digest computation failed.\r
1038 @retval FALSE This interface is not supported.\r
1039\r
1040**/\r
1041BOOLEAN\r
1042EFIAPI\r
1043HmacSha256Final (\r
1044 IN OUT VOID *HmacSha256Context,\r
1045 OUT UINT8 *HmacValue\r
1046 );\r
1047\r
7c342378 1048// =====================================================================================\r
97f98500 1049// Symmetric Cryptography Primitive\r
7c342378 1050// =====================================================================================\r
97f98500 1051\r
a8c44645 1052/**\r
1053 Retrieves the size, in bytes, of the context buffer required for AES operations.\r
1054\r
532616bb 1055 If this interface is not supported, then return zero.\r
1056\r
a8c44645 1057 @return The size, in bytes, of the context buffer required for AES operations.\r
532616bb 1058 @retval 0 This interface is not supported.\r
a8c44645 1059\r
1060**/\r
1061UINTN\r
1062EFIAPI\r
1063AesGetContextSize (\r
1064 VOID\r
1065 );\r
1066\r
1067/**\r
1068 Initializes user-supplied memory as AES context for subsequent use.\r
1069\r
1070 This function initializes user-supplied memory pointed by AesContext as AES context.\r
6b8ebcb8 1071 In addition, it sets up all AES key materials for subsequent encryption and decryption\r
a8c44645 1072 operations.\r
1073 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r
1074\r
16d2c32c 1075 If AesContext is NULL, then return FALSE.\r
1076 If Key is NULL, then return FALSE.\r
1077 If KeyLength is not valid, then return FALSE.\r
532616bb 1078 If this interface is not supported, then return FALSE.\r
a8c44645 1079\r
1080 @param[out] AesContext Pointer to AES context being initialized.\r
1081 @param[in] Key Pointer to the user-supplied AES key.\r
1082 @param[in] KeyLength Length of AES key in bits.\r
1083\r
1084 @retval TRUE AES context initialization succeeded.\r
1085 @retval FALSE AES context initialization failed.\r
532616bb 1086 @retval FALSE This interface is not supported.\r
a8c44645 1087\r
1088**/\r
1089BOOLEAN\r
1090EFIAPI\r
1091AesInit (\r
1092 OUT VOID *AesContext,\r
1093 IN CONST UINT8 *Key,\r
1094 IN UINTN KeyLength\r
1095 );\r
1096\r
a8c44645 1097/**\r
1098 Performs AES encryption on a data buffer of the specified size in CBC mode.\r
1099\r
1100 This function performs AES encryption on data buffer pointed by Input, of specified\r
1101 size of InputSize, in CBC mode.\r
1102 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1103 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1104 Initialization vector should be one block size (16 bytes).\r
1105 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1106 invalid AES context is undefined.\r
1107\r
16d2c32c 1108 If AesContext is NULL, then return FALSE.\r
1109 If Input is NULL, then return FALSE.\r
1110 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1111 If Ivec is NULL, then return FALSE.\r
1112 If Output is NULL, then return FALSE.\r
532616bb 1113 If this interface is not supported, then return FALSE.\r
a8c44645 1114\r
1115 @param[in] AesContext Pointer to the AES context.\r
1116 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1117 @param[in] InputSize Size of the Input buffer in bytes.\r
1118 @param[in] Ivec Pointer to initialization vector.\r
1119 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1120\r
1121 @retval TRUE AES encryption succeeded.\r
1122 @retval FALSE AES encryption failed.\r
532616bb 1123 @retval FALSE This interface is not supported.\r
a8c44645 1124\r
1125**/\r
1126BOOLEAN\r
1127EFIAPI\r
1128AesCbcEncrypt (\r
1129 IN VOID *AesContext,\r
1130 IN CONST UINT8 *Input,\r
1131 IN UINTN InputSize,\r
1132 IN CONST UINT8 *Ivec,\r
1133 OUT UINT8 *Output\r
1134 );\r
1135\r
1136/**\r
1137 Performs AES decryption on a data buffer of the specified size in CBC mode.\r
1138\r
1139 This function performs AES decryption on data buffer pointed by Input, of specified\r
1140 size of InputSize, in CBC mode.\r
1141 InputSize must be multiple of block size (16 bytes). This function does not perform\r
1142 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
1143 Initialization vector should be one block size (16 bytes).\r
1144 AesContext should be already correctly initialized by AesInit(). Behavior with\r
1145 invalid AES context is undefined.\r
1146\r
16d2c32c 1147 If AesContext is NULL, then return FALSE.\r
1148 If Input is NULL, then return FALSE.\r
1149 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
1150 If Ivec is NULL, then return FALSE.\r
1151 If Output is NULL, then return FALSE.\r
532616bb 1152 If this interface is not supported, then return FALSE.\r
a8c44645 1153\r
1154 @param[in] AesContext Pointer to the AES context.\r
1155 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
1156 @param[in] InputSize Size of the Input buffer in bytes.\r
1157 @param[in] Ivec Pointer to initialization vector.\r
1158 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
1159\r
1160 @retval TRUE AES decryption succeeded.\r
1161 @retval FALSE AES decryption failed.\r
532616bb 1162 @retval FALSE This interface is not supported.\r
a8c44645 1163\r
1164**/\r
1165BOOLEAN\r
1166EFIAPI\r
1167AesCbcDecrypt (\r
1168 IN VOID *AesContext,\r
1169 IN CONST UINT8 *Input,\r
1170 IN UINTN InputSize,\r
1171 IN CONST UINT8 *Ivec,\r
1172 OUT UINT8 *Output\r
1173 );\r
1174\r
7c342378 1175// =====================================================================================\r
97f98500 1176// Asymmetric Cryptography Primitive\r
7c342378 1177// =====================================================================================\r
97f98500
HT
1178\r
1179/**\r
a8c44645 1180 Allocates and initializes one RSA context for subsequent use.\r
97f98500 1181\r
a8c44645 1182 @return Pointer to the RSA context that has been initialized.\r
97f98500
HT
1183 If the allocations fails, RsaNew() returns NULL.\r
1184\r
1185**/\r
1186VOID *\r
1187EFIAPI\r
1188RsaNew (\r
1189 VOID\r
1190 );\r
1191\r
97f98500 1192/**\r
a8c44645 1193 Release the specified RSA context.\r
1194\r
16d2c32c 1195 If RsaContext is NULL, then return FALSE.\r
97f98500
HT
1196\r
1197 @param[in] RsaContext Pointer to the RSA context to be released.\r
1198\r
1199**/\r
1200VOID\r
1201EFIAPI\r
1202RsaFree (\r
1203 IN VOID *RsaContext\r
1204 );\r
1205\r
97f98500 1206/**\r
a8c44645 1207 Sets the tag-designated key component into the established RSA context.\r
1208\r
1209 This function sets the tag-designated RSA key component into the established\r
1210 RSA context from the user-specified non-negative integer (octet string format\r
1211 represented in RSA PKCS#1).\r
2998af86 1212 If BigNumber is NULL, then the specified key component in RSA context is cleared.\r
97f98500 1213\r
16d2c32c 1214 If RsaContext is NULL, then return FALSE.\r
97f98500
HT
1215\r
1216 @param[in, out] RsaContext Pointer to RSA context being set.\r
1217 @param[in] KeyTag Tag of RSA key component being set.\r
1218 @param[in] BigNumber Pointer to octet integer buffer.\r
2998af86 1219 If NULL, then the specified key component in RSA\r
a8c44645 1220 context is cleared.\r
1221 @param[in] BnSize Size of big number buffer in bytes.\r
1222 If BigNumber is NULL, then it is ignored.\r
97f98500 1223\r
a8c44645 1224 @retval TRUE RSA key component was set successfully.\r
1225 @retval FALSE Invalid RSA key component tag.\r
97f98500
HT
1226\r
1227**/\r
1228BOOLEAN\r
1229EFIAPI\r
1230RsaSetKey (\r
a8c44645 1231 IN OUT VOID *RsaContext,\r
1232 IN RSA_KEY_TAG KeyTag,\r
1233 IN CONST UINT8 *BigNumber,\r
1234 IN UINTN BnSize\r
1235 );\r
1236\r
1237/**\r
1238 Gets the tag-designated RSA key component from the established RSA context.\r
1239\r
1240 This function retrieves the tag-designated RSA key component from the\r
1241 established RSA context as a non-negative integer (octet string format\r
1242 represented in RSA PKCS#1).\r
1243 If specified key component has not been set or has been cleared, then returned\r
1244 BnSize is set to 0.\r
1245 If the BigNumber buffer is too small to hold the contents of the key, FALSE\r
1246 is returned and BnSize is set to the required buffer size to obtain the key.\r
1247\r
16d2c32c 1248 If RsaContext is NULL, then return FALSE.\r
1249 If BnSize is NULL, then return FALSE.\r
1250 If BnSize is large enough but BigNumber is NULL, then return FALSE.\r
532616bb 1251 If this interface is not supported, then return FALSE.\r
a8c44645 1252\r
1253 @param[in, out] RsaContext Pointer to RSA context being set.\r
1254 @param[in] KeyTag Tag of RSA key component being set.\r
1255 @param[out] BigNumber Pointer to octet integer buffer.\r
1256 @param[in, out] BnSize On input, the size of big number buffer in bytes.\r
1257 On output, the size of data returned in big number buffer in bytes.\r
1258\r
1259 @retval TRUE RSA key component was retrieved successfully.\r
1260 @retval FALSE Invalid RSA key component tag.\r
1261 @retval FALSE BnSize is too small.\r
532616bb 1262 @retval FALSE This interface is not supported.\r
a8c44645 1263\r
1264**/\r
1265BOOLEAN\r
1266EFIAPI\r
1267RsaGetKey (\r
1268 IN OUT VOID *RsaContext,\r
1269 IN RSA_KEY_TAG KeyTag,\r
1270 OUT UINT8 *BigNumber,\r
1271 IN OUT UINTN *BnSize\r
1272 );\r
1273\r
1274/**\r
1275 Generates RSA key components.\r
1276\r
1277 This function generates RSA key components. It takes RSA public exponent E and\r
1278 length in bits of RSA modulus N as input, and generates all key components.\r
1279 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r
1280\r
1281 Before this function can be invoked, pseudorandom number generator must be correctly\r
1282 initialized by RandomSeed().\r
1283\r
16d2c32c 1284 If RsaContext is NULL, then return FALSE.\r
532616bb 1285 If this interface is not supported, then return FALSE.\r
a8c44645 1286\r
1287 @param[in, out] RsaContext Pointer to RSA context being set.\r
1288 @param[in] ModulusLength Length of RSA modulus N in bits.\r
1289 @param[in] PublicExponent Pointer to RSA public exponent.\r
2ac68e8b 1290 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r
a8c44645 1291\r
1292 @retval TRUE RSA key component was generated successfully.\r
1293 @retval FALSE Invalid RSA key component tag.\r
532616bb 1294 @retval FALSE This interface is not supported.\r
a8c44645 1295\r
1296**/\r
1297BOOLEAN\r
1298EFIAPI\r
1299RsaGenerateKey (\r
1300 IN OUT VOID *RsaContext,\r
1301 IN UINTN ModulusLength,\r
1302 IN CONST UINT8 *PublicExponent,\r
1303 IN UINTN PublicExponentSize\r
1304 );\r
1305\r
1306/**\r
1307 Validates key components of RSA context.\r
952bd229
QL
1308 NOTE: This function performs integrity checks on all the RSA key material, so\r
1309 the RSA key structure must contain all the private key data.\r
a8c44645 1310\r
2998af86 1311 This function validates key components of RSA context in following aspects:\r
a8c44645 1312 - Whether p is a prime\r
1313 - Whether q is a prime\r
1314 - Whether n = p * q\r
1315 - Whether d*e = 1 mod lcm(p-1,q-1)\r
1316\r
16d2c32c 1317 If RsaContext is NULL, then return FALSE.\r
532616bb 1318 If this interface is not supported, then return FALSE.\r
a8c44645 1319\r
1320 @param[in] RsaContext Pointer to RSA context to check.\r
1321\r
1322 @retval TRUE RSA key components are valid.\r
1323 @retval FALSE RSA key components are not valid.\r
532616bb 1324 @retval FALSE This interface is not supported.\r
a8c44645 1325\r
1326**/\r
1327BOOLEAN\r
1328EFIAPI\r
1329RsaCheckKey (\r
1330 IN VOID *RsaContext\r
97f98500
HT
1331 );\r
1332\r
a8c44645 1333/**\r
1334 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r
1335\r
1336 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1337 RSA PKCS#1.\r
1338 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1339 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1340\r
16d2c32c 1341 If RsaContext is NULL, then return FALSE.\r
1342 If MessageHash is NULL, then return FALSE.\r
1343 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r
1344 If SigSize is large enough but Signature is NULL, then return FALSE.\r
532616bb 1345 If this interface is not supported, then return FALSE.\r
a8c44645 1346\r
1347 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1348 @param[in] MessageHash Pointer to octet message hash to be signed.\r
1349 @param[in] HashSize Size of the message hash in bytes.\r
1350 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
1351 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
b7d320f8 1352 On output, the size of data returned in Signature buffer in bytes.\r
a8c44645 1353\r
1354 @retval TRUE Signature successfully generated in PKCS1-v1_5.\r
1355 @retval FALSE Signature generation failed.\r
1356 @retval FALSE SigSize is too small.\r
532616bb 1357 @retval FALSE This interface is not supported.\r
a8c44645 1358\r
1359**/\r
1360BOOLEAN\r
1361EFIAPI\r
1362RsaPkcs1Sign (\r
1363 IN VOID *RsaContext,\r
1364 IN CONST UINT8 *MessageHash,\r
1365 IN UINTN HashSize,\r
1366 OUT UINT8 *Signature,\r
1367 IN OUT UINTN *SigSize\r
1368 );\r
97f98500
HT
1369\r
1370/**\r
1371 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r
1372 RSA PKCS#1.\r
1373\r
16d2c32c 1374 If RsaContext is NULL, then return FALSE.\r
1375 If MessageHash is NULL, then return FALSE.\r
1376 If Signature is NULL, then return FALSE.\r
1377 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r
97f98500
HT
1378\r
1379 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1380 @param[in] MessageHash Pointer to octet message hash to be checked.\r
a8c44645 1381 @param[in] HashSize Size of the message hash in bytes.\r
97f98500 1382 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r
a8c44645 1383 @param[in] SigSize Size of signature in bytes.\r
97f98500 1384\r
a8c44645 1385 @retval TRUE Valid signature encoded in PKCS1-v1_5.\r
1386 @retval FALSE Invalid signature or invalid RSA context.\r
97f98500
HT
1387\r
1388**/\r
1389BOOLEAN\r
1390EFIAPI\r
1391RsaPkcs1Verify (\r
1392 IN VOID *RsaContext,\r
1393 IN CONST UINT8 *MessageHash,\r
a8c44645 1394 IN UINTN HashSize,\r
8c5720b4 1395 IN CONST UINT8 *Signature,\r
a8c44645 1396 IN UINTN SigSize\r
97f98500
HT
1397 );\r
1398\r
22ac5cc9
SA
1399/**\r
1400 Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme.\r
1401\r
1402 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in\r
1403 RFC 8017.\r
1404 Mask generation function is the same as the message digest algorithm.\r
1405 If the Signature buffer is too small to hold the contents of signature, FALSE\r
1406 is returned and SigSize is set to the required buffer size to obtain the signature.\r
1407\r
1408 If RsaContext is NULL, then return FALSE.\r
1409 If Message is NULL, then return FALSE.\r
1410 If MsgSize is zero or > INT_MAX, then return FALSE.\r
1411 If DigestLen is NOT 32, 48 or 64, return FALSE.\r
20ca5288 1412 If SaltLen is not equal to DigestLen, then return FALSE.\r
22ac5cc9
SA
1413 If SigSize is large enough but Signature is NULL, then return FALSE.\r
1414 If this interface is not supported, then return FALSE.\r
1415\r
1416 @param[in] RsaContext Pointer to RSA context for signature generation.\r
1417 @param[in] Message Pointer to octet message to be signed.\r
1418 @param[in] MsgSize Size of the message in bytes.\r
1419 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.\r
1420 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.\r
1421 @param[out] Signature Pointer to buffer to receive RSA PSS signature.\r
1422 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
1423 On output, the size of data returned in Signature buffer in bytes.\r
1424\r
1425 @retval TRUE Signature successfully generated in RSASSA-PSS.\r
1426 @retval FALSE Signature generation failed.\r
1427 @retval FALSE SigSize is too small.\r
1428 @retval FALSE This interface is not supported.\r
1429\r
1430**/\r
1431BOOLEAN\r
1432EFIAPI\r
1433RsaPssSign (\r
1434 IN VOID *RsaContext,\r
1435 IN CONST UINT8 *Message,\r
1436 IN UINTN MsgSize,\r
1437 IN UINT16 DigestLen,\r
1438 IN UINT16 SaltLen,\r
1439 OUT UINT8 *Signature,\r
1440 IN OUT UINTN *SigSize\r
1441 );\r
1442\r
1443/**\r
1444 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.\r
1445 Implementation determines salt length automatically from the signature encoding.\r
1446 Mask generation function is the same as the message digest algorithm.\r
20ca5288 1447 Salt length should be equal to digest length.\r
22ac5cc9
SA
1448\r
1449 @param[in] RsaContext Pointer to RSA context for signature verification.\r
1450 @param[in] Message Pointer to octet message to be verified.\r
1451 @param[in] MsgSize Size of the message in bytes.\r
1452 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.\r
1453 @param[in] SigSize Size of signature in bytes.\r
1454 @param[in] DigestLen Length of digest for RSA operation.\r
1455 @param[in] SaltLen Salt length for PSS encoding.\r
1456\r
1457 @retval TRUE Valid signature encoded in RSASSA-PSS.\r
1458 @retval FALSE Invalid signature or invalid RSA context.\r
1459\r
1460**/\r
1461BOOLEAN\r
1462EFIAPI\r
1463RsaPssVerify (\r
1464 IN VOID *RsaContext,\r
1465 IN CONST UINT8 *Message,\r
1466 IN UINTN MsgSize,\r
1467 IN CONST UINT8 *Signature,\r
1468 IN UINTN SigSize,\r
1469 IN UINT16 DigestLen,\r
1470 IN UINT16 SaltLen\r
1471 );\r
1472\r
4a567c96 1473/**\r
1474 Retrieve the RSA Private Key from the password-protected PEM key data.\r
1475\r
532616bb 1476 If PemData is NULL, then return FALSE.\r
1477 If RsaContext is NULL, then return FALSE.\r
1478 If this interface is not supported, then return FALSE.\r
1479\r
4a567c96 1480 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
1481 @param[in] PemSize Size of the PEM key data in bytes.\r
1482 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
1483 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1484 RSA private key component. Use RsaFree() function to free the\r
1485 resource.\r
1486\r
4a567c96 1487 @retval TRUE RSA Private Key was retrieved successfully.\r
1488 @retval FALSE Invalid PEM key data or incorrect password.\r
532616bb 1489 @retval FALSE This interface is not supported.\r
4a567c96 1490\r
1491**/\r
1492BOOLEAN\r
1493EFIAPI\r
1494RsaGetPrivateKeyFromPem (\r
1495 IN CONST UINT8 *PemData,\r
1496 IN UINTN PemSize,\r
1497 IN CONST CHAR8 *Password,\r
1498 OUT VOID **RsaContext\r
1499 );\r
1500\r
1501/**\r
1502 Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r
1503\r
532616bb 1504 If Cert is NULL, then return FALSE.\r
1505 If RsaContext is NULL, then return FALSE.\r
1506 If this interface is not supported, then return FALSE.\r
1507\r
4a567c96 1508 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1509 @param[in] CertSize Size of the X509 certificate in bytes.\r
1510 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
1511 RSA public key component. Use RsaFree() function to free the\r
1512 resource.\r
1513\r
4a567c96 1514 @retval TRUE RSA Public Key was retrieved successfully.\r
1515 @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r
532616bb 1516 @retval FALSE This interface is not supported.\r
4a567c96 1517\r
1518**/\r
1519BOOLEAN\r
1520EFIAPI\r
1521RsaGetPublicKeyFromX509 (\r
1522 IN CONST UINT8 *Cert,\r
1523 IN UINTN CertSize,\r
1524 OUT VOID **RsaContext\r
1525 );\r
1526\r
1527/**\r
1528 Retrieve the subject bytes from one X.509 certificate.\r
1529\r
532616bb 1530 If Cert is NULL, then return FALSE.\r
1531 If SubjectSize is NULL, then return FALSE.\r
1532 If this interface is not supported, then return FALSE.\r
1533\r
4a567c96 1534 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1535 @param[in] CertSize Size of the X509 certificate in bytes.\r
1536 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r
1537 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r
1538 and the size of buffer returned CertSubject on output.\r
1539\r
4a567c96 1540 @retval TRUE The certificate subject retrieved successfully.\r
1541 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r
1542 The SubjectSize will be updated with the required size.\r
532616bb 1543 @retval FALSE This interface is not supported.\r
4a567c96 1544\r
1545**/\r
1546BOOLEAN\r
1547EFIAPI\r
1548X509GetSubjectName (\r
1549 IN CONST UINT8 *Cert,\r
1550 IN UINTN CertSize,\r
1551 OUT UINT8 *CertSubject,\r
1552 IN OUT UINTN *SubjectSize\r
1553 );\r
1554\r
5b7c2245
QL
1555/**\r
1556 Retrieve the common name (CN) string from one X.509 certificate.\r
1557\r
1558 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1559 @param[in] CertSize Size of the X509 certificate in bytes.\r
1560 @param[out] CommonName Buffer to contain the retrieved certificate common\r
0b6457ef 1561 name string (UTF8). At most CommonNameSize bytes will be\r
5b7c2245
QL
1562 written and the string will be null terminated. May be\r
1563 NULL in order to determine the size buffer needed.\r
1564 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
1565 and the size of buffer returned CommonName on output.\r
1566 If CommonName is NULL then the amount of space needed\r
1567 in buffer (including the final null) is returned.\r
1568\r
1569 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r
1570 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1571 If CommonNameSize is NULL.\r
1572 If CommonName is not NULL and *CommonNameSize is 0.\r
1573 If Certificate is invalid.\r
1574 @retval RETURN_NOT_FOUND If no CommonName entry exists.\r
1575 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r
630f67dd 1576 (including the final null) is returned in the\r
5b7c2245
QL
1577 CommonNameSize parameter.\r
1578 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1579\r
1580**/\r
1581RETURN_STATUS\r
1582EFIAPI\r
1583X509GetCommonName (\r
1584 IN CONST UINT8 *Cert,\r
1585 IN UINTN CertSize,\r
c8f46130 1586 OUT CHAR8 *CommonName OPTIONAL,\r
5b7c2245
QL
1587 IN OUT UINTN *CommonNameSize\r
1588 );\r
1589\r
e2a673b8
BB
1590/**\r
1591 Retrieve the organization name (O) string from one X.509 certificate.\r
1592\r
1593 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
1594 @param[in] CertSize Size of the X509 certificate in bytes.\r
1595 @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r
1596 name string. At most NameBufferSize bytes will be\r
1597 written and the string will be null terminated. May be\r
1598 NULL in order to determine the size buffer needed.\r
1599 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r
1600 and the size of buffer returned Name on output.\r
1601 If NameBuffer is NULL then the amount of space needed\r
1602 in buffer (including the final null) is returned.\r
1603\r
1604 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r
1605 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
1606 If NameBufferSize is NULL.\r
1607 If NameBuffer is not NULL and *CommonNameSize is 0.\r
1608 If Certificate is invalid.\r
1609 @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r
1610 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r
1611 (including the final null) is returned in the\r
1612 CommonNameSize parameter.\r
1613 @retval RETURN_UNSUPPORTED The operation is not supported.\r
1614\r
1615**/\r
1616RETURN_STATUS\r
1617EFIAPI\r
1618X509GetOrganizationName (\r
7c342378
MK
1619 IN CONST UINT8 *Cert,\r
1620 IN UINTN CertSize,\r
1621 OUT CHAR8 *NameBuffer OPTIONAL,\r
1622 IN OUT UINTN *NameBufferSize\r
e2a673b8
BB
1623 );\r
1624\r
4a567c96 1625/**\r
1626 Verify one X509 certificate was issued by the trusted CA.\r
1627\r
532616bb 1628 If Cert is NULL, then return FALSE.\r
1629 If CACert is NULL, then return FALSE.\r
1630 If this interface is not supported, then return FALSE.\r
1631\r
4a567c96 1632 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r
1633 @param[in] CertSize Size of the X509 certificate in bytes.\r
1634 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r
1635 @param[in] CACertSize Size of the CA Certificate in bytes.\r
1636\r
4a567c96 1637 @retval TRUE The certificate was issued by the trusted CA.\r
1638 @retval FALSE Invalid certificate or the certificate was not issued by the given\r
1639 trusted CA.\r
532616bb 1640 @retval FALSE This interface is not supported.\r
4a567c96 1641\r
1642**/\r
1643BOOLEAN\r
1644EFIAPI\r
1645X509VerifyCert (\r
1646 IN CONST UINT8 *Cert,\r
1647 IN UINTN CertSize,\r
1648 IN CONST UINT8 *CACert,\r
1649 IN UINTN CACertSize\r
1650 );\r
1651\r
b7d320f8 1652/**\r
1653 Construct a X509 object from DER-encoded certificate data.\r
1654\r
16d2c32c 1655 If Cert is NULL, then return FALSE.\r
1656 If SingleX509Cert is NULL, then return FALSE.\r
532616bb 1657 If this interface is not supported, then return FALSE.\r
b7d320f8 1658\r
1659 @param[in] Cert Pointer to the DER-encoded certificate data.\r
1660 @param[in] CertSize The size of certificate data in bytes.\r
1661 @param[out] SingleX509Cert The generated X509 object.\r
1662\r
1663 @retval TRUE The X509 object generation succeeded.\r
1664 @retval FALSE The operation failed.\r
532616bb 1665 @retval FALSE This interface is not supported.\r
b7d320f8 1666\r
1667**/\r
1668BOOLEAN\r
1669EFIAPI\r
1670X509ConstructCertificate (\r
1671 IN CONST UINT8 *Cert,\r
1672 IN UINTN CertSize,\r
1673 OUT UINT8 **SingleX509Cert\r
1674 );\r
1675\r
66862136
MK
1676/**\r
1677 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1678\r
1679 If X509Stack is NULL, then return FALSE.\r
1680 If this interface is not supported, then return FALSE.\r
1681\r
1682 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
1683 On output, pointer to the X509 stack object with new\r
1684 inserted X509 certificate.\r
1685 @param[in] Args VA_LIST marker for the variable argument list.\r
1686 A list of DER-encoded single certificate data followed\r
1687 by certificate size. A NULL terminates the list. The\r
1688 pairs are the arguments to X509ConstructCertificate().\r
1689\r
1690 @retval TRUE The X509 stack construction succeeded.\r
1691 @retval FALSE The construction operation failed.\r
1692 @retval FALSE This interface is not supported.\r
1693\r
1694**/\r
1695BOOLEAN\r
1696EFIAPI\r
1697X509ConstructCertificateStackV (\r
1698 IN OUT UINT8 **X509Stack,\r
1699 IN VA_LIST Args\r
1700 );\r
1701\r
b7d320f8 1702/**\r
1703 Construct a X509 stack object from a list of DER-encoded certificate data.\r
1704\r
16d2c32c 1705 If X509Stack is NULL, then return FALSE.\r
532616bb 1706 If this interface is not supported, then return FALSE.\r
b7d320f8 1707\r
952bd229 1708 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
b7d320f8 1709 On output, pointer to the X509 stack object with new\r
1710 inserted X509 certificate.\r
1711 @param ... A list of DER-encoded single certificate data followed\r
1712 by certificate size. A NULL terminates the list. The\r
1713 pairs are the arguments to X509ConstructCertificate().\r
2ac68e8b 1714\r
b7d320f8 1715 @retval TRUE The X509 stack construction succeeded.\r
1716 @retval FALSE The construction operation failed.\r
532616bb 1717 @retval FALSE This interface is not supported.\r
b7d320f8 1718\r
1719**/\r
1720BOOLEAN\r
1721EFIAPI\r
1722X509ConstructCertificateStack (\r
1723 IN OUT UINT8 **X509Stack,\r
2ac68e8b 1724 ...\r
b7d320f8 1725 );\r
1726\r
1727/**\r
1728 Release the specified X509 object.\r
1729\r
532616bb 1730 If the interface is not supported, then ASSERT().\r
b7d320f8 1731\r
1732 @param[in] X509Cert Pointer to the X509 object to be released.\r
1733\r
1734**/\r
1735VOID\r
1736EFIAPI\r
1737X509Free (\r
1738 IN VOID *X509Cert\r
1739 );\r
1740\r
1741/**\r
1742 Release the specified X509 stack object.\r
1743\r
532616bb 1744 If the interface is not supported, then ASSERT().\r
b7d320f8 1745\r
1746 @param[in] X509Stack Pointer to the X509 stack object to be released.\r
1747\r
1748**/\r
1749VOID\r
1750EFIAPI\r
1751X509StackFree (\r
1752 IN VOID *X509Stack\r
1753 );\r
1754\r
12d95665
LQ
1755/**\r
1756 Retrieve the TBSCertificate from one given X.509 certificate.\r
1757\r
1758 @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r
1759 @param[in] CertSize Size of the X509 certificate in bytes.\r
1760 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r
1761 @param[out] TBSCertSize Size of the TBS certificate in bytes.\r
1762\r
1763 If Cert is NULL, then return FALSE.\r
1764 If TBSCert is NULL, then return FALSE.\r
1765 If TBSCertSize is NULL, then return FALSE.\r
1766 If this interface is not supported, then return FALSE.\r
1767\r
1768 @retval TRUE The TBSCertificate was retrieved successfully.\r
1769 @retval FALSE Invalid X.509 certificate.\r
1770\r
1771**/\r
1772BOOLEAN\r
1773EFIAPI\r
1774X509GetTBSCert (\r
1775 IN CONST UINT8 *Cert,\r
1776 IN UINTN CertSize,\r
1777 OUT UINT8 **TBSCert,\r
1778 OUT UINTN *TBSCertSize\r
1779 );\r
1780\r
a8f37449
QL
1781/**\r
1782 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r
1783 password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r
1784\r
1785 If Password or Salt or OutKey is NULL, then return FALSE.\r
1786 If the hash algorithm could not be determined, then return FALSE.\r
1787 If this interface is not supported, then return FALSE.\r
1788\r
1789 @param[in] PasswordLength Length of input password in bytes.\r
1790 @param[in] Password Pointer to the array for the password.\r
1791 @param[in] SaltLength Size of the Salt in bytes.\r
1792 @param[in] Salt Pointer to the Salt.\r
1793 @param[in] IterationCount Number of iterations to perform. Its value should be\r
1794 greater than or equal to 1.\r
1795 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r
1796 NOTE: DigestSize will be used to determine the hash algorithm.\r
1797 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r
1798 @param[in] KeyLength Size of the derived key buffer in bytes.\r
1799 @param[out] OutKey Pointer to the output derived key buffer.\r
1800\r
1801 @retval TRUE A key was derived successfully.\r
1802 @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r
1803 @retval FALSE The hash algorithm could not be determined from the digest size.\r
1804 @retval FALSE The key derivation operation failed.\r
1805 @retval FALSE This interface is not supported.\r
1806\r
1807**/\r
1808BOOLEAN\r
1809EFIAPI\r
1810Pkcs5HashPassword (\r
1811 IN UINTN PasswordLength,\r
1812 IN CONST CHAR8 *Password,\r
1813 IN UINTN SaltLength,\r
1814 IN CONST UINT8 *Salt,\r
1815 IN UINTN IterationCount,\r
1816 IN UINTN DigestSize,\r
1817 IN UINTN KeyLength,\r
1818 OUT UINT8 *OutKey\r
1819 );\r
1820\r
aed90bee
BB
1821/**\r
1822 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r
1823 encrypted message in a newly allocated buffer.\r
1824\r
1825 Things that can cause a failure include:\r
1826 - X509 key size does not match any known key size.\r
1827 - Fail to parse X509 certificate.\r
1828 - Fail to allocate an intermediate buffer.\r
1829 - Null pointer provided for a non-optional parameter.\r
1830 - Data size is too large for the provided key size (max size is a function of key size\r
1831 and hash digest size).\r
1832\r
1833 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r
1834 will be used to encrypt the data.\r
1835 @param[in] PublicKeySize Size of the X509 cert buffer.\r
1836 @param[in] InData Data to be encrypted.\r
1837 @param[in] InDataSize Size of the data buffer.\r
1838 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r
1839 to be used when initializing the PRNG. NULL otherwise.\r
1840 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r
1841 0 otherwise.\r
1842 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r
1843 message.\r
1844 @param[out] EncryptedDataSize Size of the encrypted message buffer.\r
1845\r
1846 @retval TRUE Encryption was successful.\r
1847 @retval FALSE Encryption failed.\r
1848\r
1849**/\r
1850BOOLEAN\r
1851EFIAPI\r
1852Pkcs1v2Encrypt (\r
1853 IN CONST UINT8 *PublicKey,\r
1854 IN UINTN PublicKeySize,\r
1855 IN UINT8 *InData,\r
1856 IN UINTN InDataSize,\r
c8f46130
MK
1857 IN CONST UINT8 *PrngSeed OPTIONAL,\r
1858 IN UINTN PrngSeedSize OPTIONAL,\r
aed90bee
BB
1859 OUT UINT8 **EncryptedData,\r
1860 OUT UINTN *EncryptedDataSize\r
1861 );\r
1862\r
3702637a 1863/**\r
1864 The 3rd parameter of Pkcs7GetSigners will return all embedded\r
1865 X.509 certificate in one given PKCS7 signature. The format is:\r
1866 //\r
1867 // UINT8 CertNumber;\r
1868 // UINT32 Cert1Length;\r
1869 // UINT8 Cert1[];\r
1870 // UINT32 Cert2Length;\r
1871 // UINT8 Cert2[];\r
1872 // ...\r
1873 // UINT32 CertnLength;\r
1874 // UINT8 Certn[];\r
1875 //\r
1876\r
1877 The two following C-structure are used for parsing CertStack more clearly.\r
1878**/\r
1879#pragma pack(1)\r
1880\r
1881typedef struct {\r
1882 UINT32 CertDataLength; // The length in bytes of X.509 certificate.\r
1883 UINT8 CertDataBuffer[0]; // The X.509 certificate content (DER).\r
1884} EFI_CERT_DATA;\r
1885\r
1886typedef struct {\r
7c342378
MK
1887 UINT8 CertNumber; // Number of X.509 certificate.\r
1888 // EFI_CERT_DATA CertArray[]; // An array of X.509 certificate.\r
3702637a 1889} EFI_CERT_STACK;\r
1890\r
1891#pragma pack()\r
1892\r
e8b4eb04 1893/**\r
1894 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r
1895 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
1896 in a ContentInfo structure.\r
1897\r
1898 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r
2998af86 1899 return FALSE. If P7Length overflow, then return FALSE.\r
532616bb 1900 If this interface is not supported, then return FALSE.\r
e8b4eb04 1901\r
1902 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
1903 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
1904 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r
6fe575d0
LQ
1905 It's caller's responsibility to free the buffer with\r
1906 Pkcs7FreeSigners().\r
3702637a 1907 This data structure is EFI_CERT_STACK type.\r
e8b4eb04 1908 @param[out] StackLength Length of signer's certificates in bytes.\r
1909 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r
6fe575d0
LQ
1910 It's caller's responsibility to free the buffer with\r
1911 Pkcs7FreeSigners().\r
e8b4eb04 1912 @param[out] CertLength Length of the trusted certificate in bytes.\r
1913\r
1914 @retval TRUE The operation is finished successfully.\r
1915 @retval FALSE Error occurs during the operation.\r
532616bb 1916 @retval FALSE This interface is not supported.\r
e8b4eb04 1917\r
1918**/\r
1919BOOLEAN\r
1920EFIAPI\r
1921Pkcs7GetSigners (\r
1922 IN CONST UINT8 *P7Data,\r
1923 IN UINTN P7Length,\r
1924 OUT UINT8 **CertStack,\r
1925 OUT UINTN *StackLength,\r
1926 OUT UINT8 **TrustedCert,\r
1927 OUT UINTN *CertLength\r
1928 );\r
1929\r
1930/**\r
1931 Wrap function to use free() to free allocated memory for certificates.\r
1932\r
532616bb 1933 If this interface is not supported, then ASSERT().\r
1934\r
e8b4eb04 1935 @param[in] Certs Pointer to the certificates to be freed.\r
1936\r
1937**/\r
1938VOID\r
1939EFIAPI\r
1940Pkcs7FreeSigners (\r
7c342378 1941 IN UINT8 *Certs\r
45419de6
QL
1942 );\r
1943\r
1944/**\r
1945 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r
1946 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r
1947 unchained to the signer's certificates.\r
1948 The input signed data could be wrapped in a ContentInfo structure.\r
1949\r
1950 @param[in] P7Data Pointer to the PKCS#7 message.\r
1951 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
0f5f6b3d 1952 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r
6fe575d0
LQ
1953 certificate. It's caller's responsibility to free the buffer\r
1954 with Pkcs7FreeSigners().\r
3702637a 1955 This data structure is EFI_CERT_STACK type.\r
45419de6
QL
1956 @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r
1957 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r
6fe575d0 1958 responsibility to free the buffer with Pkcs7FreeSigners().\r
3702637a 1959 This data structure is EFI_CERT_STACK type.\r
45419de6
QL
1960 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r
1961\r
1962 @retval TRUE The operation is finished successfully.\r
1963 @retval FALSE Error occurs during the operation.\r
1964\r
1965**/\r
1966BOOLEAN\r
1967EFIAPI\r
1968Pkcs7GetCertificatesList (\r
1969 IN CONST UINT8 *P7Data,\r
1970 IN UINTN P7Length,\r
1971 OUT UINT8 **SignerChainCerts,\r
1972 OUT UINTN *ChainLength,\r
1973 OUT UINT8 **UnchainCerts,\r
1974 OUT UINTN *UnchainLength\r
e8b4eb04 1975 );\r
1976\r
b7d320f8 1977/**\r
1978 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
1979 Syntax Standard, version 1.5". This interface is only intended to be used for\r
1980 application to perform PKCS#7 functionality validation.\r
1981\r
532616bb 1982 If this interface is not supported, then return FALSE.\r
1983\r
b7d320f8 1984 @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r
1985 data signing.\r
1986 @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r
1987 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r
1988 key data.\r
1989 @param[in] InData Pointer to the content to be signed.\r
1990 @param[in] InDataSize Size of InData in bytes.\r
1991 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r
1992 @param[in] OtherCerts Pointer to an optional additional set of certificates to\r
1993 include in the PKCS#7 signedData (e.g. any intermediate\r
1994 CAs in the chain).\r
6fe575d0
LQ
1995 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r
1996 responsibility to free the buffer with FreePool().\r
b7d320f8 1997 @param[out] SignedDataSize Size of SignedData in bytes.\r
1998\r
1999 @retval TRUE PKCS#7 data signing succeeded.\r
2000 @retval FALSE PKCS#7 data signing failed.\r
532616bb 2001 @retval FALSE This interface is not supported.\r
b7d320f8 2002\r
2003**/\r
2004BOOLEAN\r
2005EFIAPI\r
2006Pkcs7Sign (\r
2007 IN CONST UINT8 *PrivateKey,\r
2008 IN UINTN PrivateKeySize,\r
2009 IN CONST UINT8 *KeyPassword,\r
2010 IN UINT8 *InData,\r
2011 IN UINTN InDataSize,\r
2012 IN UINT8 *SignCert,\r
2013 IN UINT8 *OtherCerts OPTIONAL,\r
2014 OUT UINT8 **SignedData,\r
2015 OUT UINTN *SignedDataSize\r
2016 );\r
2017\r
97f98500 2018/**\r
2998af86 2019 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r
e8b4eb04 2020 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
2021 in a ContentInfo structure.\r
97f98500 2022\r
e8b4eb04 2023 If P7Data, TrustedCert or InData is NULL, then return FALSE.\r
2998af86 2024 If P7Length, CertLength or DataLength overflow, then return FALSE.\r
532616bb 2025 If this interface is not supported, then return FALSE.\r
97f98500
HT
2026\r
2027 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
e8b4eb04 2028 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
97f98500
HT
2029 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2030 is used for certificate chain verification.\r
e8b4eb04 2031 @param[in] CertLength Length of the trusted certificate in bytes.\r
97f98500 2032 @param[in] InData Pointer to the content to be verified.\r
e8b4eb04 2033 @param[in] DataLength Length of InData in bytes.\r
97f98500 2034\r
a8c44645 2035 @retval TRUE The specified PKCS#7 signed data is valid.\r
2036 @retval FALSE Invalid PKCS#7 signed data.\r
532616bb 2037 @retval FALSE This interface is not supported.\r
97f98500
HT
2038\r
2039**/\r
2040BOOLEAN\r
2041EFIAPI\r
2042Pkcs7Verify (\r
2043 IN CONST UINT8 *P7Data,\r
e8b4eb04 2044 IN UINTN P7Length,\r
97f98500 2045 IN CONST UINT8 *TrustedCert,\r
e8b4eb04 2046 IN UINTN CertLength,\r
97f98500 2047 IN CONST UINT8 *InData,\r
e8b4eb04 2048 IN UINTN DataLength\r
a8c44645 2049 );\r
2050\r
1796a394
BB
2051/**\r
2052 This function receives a PKCS7 formatted signature, and then verifies that\r
2053 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r
2054 leaf signing certificate.\r
2055 Note that this function does not validate the certificate chain.\r
2056\r
2057 Applications for custom EKU's are quite flexible. For example, a policy EKU\r
2058 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r
2059 certificate issued might also contain this EKU, thus constraining the\r
2060 sub-ordinate certificate. Other applications might allow a certificate\r
2061 embedded in a device to specify that other Object Identifiers (OIDs) are\r
2062 present which contains binary data specifying custom capabilities that\r
2063 the device is able to do.\r
2064\r
2065 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r
2066 containing the content block with both the signature,\r
2067 the signer's certificate, and any necessary intermediate\r
2068 certificates.\r
2069 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r
2070 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r
2071 required EKUs that must be present in the signature.\r
2072 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r
2073 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r
2074 must be present in the leaf signer. If it is\r
2075 FALSE, then we will succeed if we find any\r
2076 of the specified EKU's.\r
2077\r
2078 @retval EFI_SUCCESS The required EKUs were found in the signature.\r
2079 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
2080 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r
2081\r
2082**/\r
2083RETURN_STATUS\r
2084EFIAPI\r
2085VerifyEKUsInPkcs7Signature (\r
2086 IN CONST UINT8 *Pkcs7Signature,\r
2087 IN CONST UINT32 SignatureSize,\r
2088 IN CONST CHAR8 *RequiredEKUs[],\r
2089 IN CONST UINT32 RequiredEKUsSize,\r
2090 IN BOOLEAN RequireAllPresent\r
2091 );\r
2092\r
afeb55e4
QL
2093/**\r
2094 Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r
2095 data could be wrapped in a ContentInfo structure.\r
2096\r
2097 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r
2998af86 2098 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r
afeb55e4
QL
2099\r
2100 Caution: This function may receive untrusted input. So this function will do\r
2101 basic check for PKCS#7 data structure.\r
2102\r
2103 @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r
2104 @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r
2105 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r
6fe575d0 2106 It's caller's responsibility to free the buffer with FreePool().\r
afeb55e4
QL
2107 @param[out] ContentSize The size of the extracted content in bytes.\r
2108\r
2109 @retval TRUE The P7Data was correctly formatted for processing.\r
2110 @retval FALSE The P7Data was not correctly formatted for processing.\r
2111\r
0c9fc4b1 2112**/\r
afeb55e4
QL
2113BOOLEAN\r
2114EFIAPI\r
2115Pkcs7GetAttachedContent (\r
2116 IN CONST UINT8 *P7Data,\r
2117 IN UINTN P7Length,\r
2118 OUT VOID **Content,\r
2119 OUT UINTN *ContentSize\r
2120 );\r
2121\r
b7d320f8 2122/**\r
2998af86 2123 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r
b7d320f8 2124 Authenticode Portable Executable Signature Format".\r
2125\r
16d2c32c 2126 If AuthData is NULL, then return FALSE.\r
2127 If ImageHash is NULL, then return FALSE.\r
532616bb 2128 If this interface is not supported, then return FALSE.\r
b7d320f8 2129\r
2130 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2131 PE/COFF image to be verified.\r
2132 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2133 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
2134 is used for certificate chain verification.\r
2135 @param[in] CertSize Size of the trusted certificate in bytes.\r
2998af86 2136 @param[in] ImageHash Pointer to the original image file hash value. The procedure\r
b7d320f8 2137 for calculating the image hash value is described in Authenticode\r
2138 specification.\r
2139 @param[in] HashSize Size of Image hash value in bytes.\r
2140\r
2141 @retval TRUE The specified Authenticode Signature is valid.\r
2142 @retval FALSE Invalid Authenticode Signature.\r
532616bb 2143 @retval FALSE This interface is not supported.\r
b7d320f8 2144\r
2145**/\r
2146BOOLEAN\r
2147EFIAPI\r
2148AuthenticodeVerify (\r
2149 IN CONST UINT8 *AuthData,\r
2150 IN UINTN DataSize,\r
2151 IN CONST UINT8 *TrustedCert,\r
2152 IN UINTN CertSize,\r
2153 IN CONST UINT8 *ImageHash,\r
2154 IN UINTN HashSize\r
2155 );\r
2156\r
2ac68e8b 2157/**\r
2998af86 2158 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r
2ac68e8b
QL
2159 signature.\r
2160\r
2161 If AuthData is NULL, then return FALSE.\r
12d95665 2162 If this interface is not supported, then return FALSE.\r
2ac68e8b
QL
2163\r
2164 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
2165 PE/COFF image to be verified.\r
2166 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
2167 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r
2168 is used for TSA certificate chain verification.\r
2169 @param[in] CertSize Size of the trusted certificate in bytes.\r
2170 @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r
2171 signature is valid.\r
2172\r
2173 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r
2174 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r
2175\r
2176**/\r
2177BOOLEAN\r
2178EFIAPI\r
2179ImageTimestampVerify (\r
2180 IN CONST UINT8 *AuthData,\r
2181 IN UINTN DataSize,\r
2182 IN CONST UINT8 *TsaCert,\r
2183 IN UINTN CertSize,\r
2184 OUT EFI_TIME *SigningTime\r
2185 );\r
2186\r
7c342378 2187// =====================================================================================\r
a8c44645 2188// DH Key Exchange Primitive\r
7c342378 2189// =====================================================================================\r
a8c44645 2190\r
2191/**\r
2192 Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r
2193\r
2194 @return Pointer to the Diffie-Hellman Context that has been initialized.\r
2195 If the allocations fails, DhNew() returns NULL.\r
532616bb 2196 If the interface is not supported, DhNew() returns NULL.\r
a8c44645 2197\r
2198**/\r
2199VOID *\r
2200EFIAPI\r
2201DhNew (\r
2202 VOID\r
2203 );\r
2204\r
2205/**\r
2206 Release the specified DH context.\r
2207\r
532616bb 2208 If the interface is not supported, then ASSERT().\r
a8c44645 2209\r
2210 @param[in] DhContext Pointer to the DH context to be released.\r
2211\r
2212**/\r
2213VOID\r
2214EFIAPI\r
2215DhFree (\r
2216 IN VOID *DhContext\r
2217 );\r
2218\r
2219/**\r
2220 Generates DH parameter.\r
2221\r
2222 Given generator g, and length of prime number p in bits, this function generates p,\r
2223 and sets DH context according to value of g and p.\r
2ac68e8b 2224\r
a8c44645 2225 Before this function can be invoked, pseudorandom number generator must be correctly\r
2226 initialized by RandomSeed().\r
2227\r
16d2c32c 2228 If DhContext is NULL, then return FALSE.\r
2229 If Prime is NULL, then return FALSE.\r
532616bb 2230 If this interface is not supported, then return FALSE.\r
a8c44645 2231\r
2232 @param[in, out] DhContext Pointer to the DH context.\r
2233 @param[in] Generator Value of generator.\r
2234 @param[in] PrimeLength Length in bits of prime to be generated.\r
2235 @param[out] Prime Pointer to the buffer to receive the generated prime number.\r
2236\r
2998af86 2237 @retval TRUE DH parameter generation succeeded.\r
a8c44645 2238 @retval FALSE Value of Generator is not supported.\r
2239 @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r
532616bb 2240 @retval FALSE This interface is not supported.\r
a8c44645 2241\r
2242**/\r
2243BOOLEAN\r
2244EFIAPI\r
2245DhGenerateParameter (\r
2246 IN OUT VOID *DhContext,\r
2247 IN UINTN Generator,\r
2248 IN UINTN PrimeLength,\r
2249 OUT UINT8 *Prime\r
2250 );\r
2251\r
2252/**\r
2253 Sets generator and prime parameters for DH.\r
2254\r
2255 Given generator g, and prime number p, this function and sets DH\r
2256 context accordingly.\r
2257\r
16d2c32c 2258 If DhContext is NULL, then return FALSE.\r
2259 If Prime is NULL, then return FALSE.\r
532616bb 2260 If this interface is not supported, then return FALSE.\r
a8c44645 2261\r
2262 @param[in, out] DhContext Pointer to the DH context.\r
2263 @param[in] Generator Value of generator.\r
2264 @param[in] PrimeLength Length in bits of prime to be generated.\r
2265 @param[in] Prime Pointer to the prime number.\r
2266\r
2998af86 2267 @retval TRUE DH parameter setting succeeded.\r
a8c44645 2268 @retval FALSE Value of Generator is not supported.\r
2269 @retval FALSE Value of Generator is not suitable for the Prime.\r
2270 @retval FALSE Value of Prime is not a prime number.\r
2271 @retval FALSE Value of Prime is not a safe prime number.\r
532616bb 2272 @retval FALSE This interface is not supported.\r
a8c44645 2273\r
2274**/\r
2275BOOLEAN\r
2276EFIAPI\r
2277DhSetParameter (\r
2278 IN OUT VOID *DhContext,\r
2279 IN UINTN Generator,\r
2280 IN UINTN PrimeLength,\r
2281 IN CONST UINT8 *Prime\r
97f98500
HT
2282 );\r
2283\r
a8c44645 2284/**\r
2285 Generates DH public key.\r
2286\r
2ac68e8b 2287 This function generates random secret exponent, and computes the public key, which is\r
a8c44645 2288 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r
2289 If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r
2290 PublicKeySize is set to the required buffer size to obtain the public key.\r
2291\r
16d2c32c 2292 If DhContext is NULL, then return FALSE.\r
2293 If PublicKeySize is NULL, then return FALSE.\r
2294 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r
532616bb 2295 If this interface is not supported, then return FALSE.\r
a8c44645 2296\r
2297 @param[in, out] DhContext Pointer to the DH context.\r
2298 @param[out] PublicKey Pointer to the buffer to receive generated public key.\r
2299 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r
2300 On output, the size of data returned in PublicKey buffer in bytes.\r
2301\r
2302 @retval TRUE DH public key generation succeeded.\r
2303 @retval FALSE DH public key generation failed.\r
2304 @retval FALSE PublicKeySize is not large enough.\r
532616bb 2305 @retval FALSE This interface is not supported.\r
a8c44645 2306\r
2307**/\r
2308BOOLEAN\r
2309EFIAPI\r
2310DhGenerateKey (\r
2311 IN OUT VOID *DhContext,\r
2312 OUT UINT8 *PublicKey,\r
2313 IN OUT UINTN *PublicKeySize\r
2314 );\r
2315\r
2316/**\r
2317 Computes exchanged common key.\r
2318\r
2319 Given peer's public key, this function computes the exchanged common key, based on its own\r
dda39f3a 2320 context including value of prime modulus and random secret exponent.\r
a8c44645 2321\r
16d2c32c 2322 If DhContext is NULL, then return FALSE.\r
2323 If PeerPublicKey is NULL, then return FALSE.\r
2324 If KeySize is NULL, then return FALSE.\r
dda39f3a 2325 If Key is NULL, then return FALSE.\r
2326 If KeySize is not large enough, then return FALSE.\r
532616bb 2327 If this interface is not supported, then return FALSE.\r
a8c44645 2328\r
2329 @param[in, out] DhContext Pointer to the DH context.\r
2330 @param[in] PeerPublicKey Pointer to the peer's public key.\r
2331 @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r
2332 @param[out] Key Pointer to the buffer to receive generated key.\r
2333 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
2334 On output, the size of data returned in Key buffer in bytes.\r
2335\r
2336 @retval TRUE DH exchanged key generation succeeded.\r
2337 @retval FALSE DH exchanged key generation failed.\r
2338 @retval FALSE KeySize is not large enough.\r
532616bb 2339 @retval FALSE This interface is not supported.\r
a8c44645 2340\r
2341**/\r
2342BOOLEAN\r
2343EFIAPI\r
2344DhComputeKey (\r
2345 IN OUT VOID *DhContext,\r
2346 IN CONST UINT8 *PeerPublicKey,\r
2347 IN UINTN PeerPublicKeySize,\r
2348 OUT UINT8 *Key,\r
2349 IN OUT UINTN *KeySize\r
2350 );\r
2351\r
7c342378 2352// =====================================================================================\r
a8c44645 2353// Pseudo-Random Generation Primitive\r
7c342378 2354// =====================================================================================\r
a8c44645 2355\r
2356/**\r
2357 Sets up the seed value for the pseudorandom number generator.\r
2358\r
2359 This function sets up the seed value for the pseudorandom number generator.\r
2360 If Seed is not NULL, then the seed passed in is used.\r
2361 If Seed is NULL, then default seed is used.\r
532616bb 2362 If this interface is not supported, then return FALSE.\r
a8c44645 2363\r
2364 @param[in] Seed Pointer to seed value.\r
2365 If NULL, default seed is used.\r
2366 @param[in] SeedSize Size of seed value.\r
2367 If Seed is NULL, this parameter is ignored.\r
2368\r
2369 @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r
2370 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r
532616bb 2371 @retval FALSE This interface is not supported.\r
a8c44645 2372\r
2373**/\r
2374BOOLEAN\r
2375EFIAPI\r
2376RandomSeed (\r
2377 IN CONST UINT8 *Seed OPTIONAL,\r
2378 IN UINTN SeedSize\r
2379 );\r
2380\r
2381/**\r
2382 Generates a pseudorandom byte stream of the specified size.\r
2383\r
16d2c32c 2384 If Output is NULL, then return FALSE.\r
532616bb 2385 If this interface is not supported, then return FALSE.\r
a8c44645 2386\r
2387 @param[out] Output Pointer to buffer to receive random value.\r
2998af86 2388 @param[in] Size Size of random bytes to generate.\r
a8c44645 2389\r
2390 @retval TRUE Pseudorandom byte stream generated successfully.\r
2391 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r
532616bb 2392 @retval FALSE This interface is not supported.\r
a8c44645 2393\r
2394**/\r
2395BOOLEAN\r
2396EFIAPI\r
2397RandomBytes (\r
2398 OUT UINT8 *Output,\r
2399 IN UINTN Size\r
2400 );\r
97f98500 2401\r
7c342378 2402// =====================================================================================\r
4b1b7c19 2403// Key Derivation Function Primitive\r
7c342378 2404// =====================================================================================\r
4b1b7c19
GW
2405\r
2406/**\r
2407 Derive key data using HMAC-SHA256 based KDF.\r
2408\r
2409 @param[in] Key Pointer to the user-supplied key.\r
2410 @param[in] KeySize Key size in bytes.\r
2411 @param[in] Salt Pointer to the salt(non-secret) value.\r
2412 @param[in] SaltSize Salt size in bytes.\r
2413 @param[in] Info Pointer to the application specific info.\r
2414 @param[in] InfoSize Info size in bytes.\r
944bd5cf 2415 @param[out] Out Pointer to buffer to receive hkdf value.\r
4b1b7c19
GW
2416 @param[in] OutSize Size of hkdf bytes to generate.\r
2417\r
2418 @retval TRUE Hkdf generated successfully.\r
2419 @retval FALSE Hkdf generation failed.\r
2420\r
2421**/\r
2422BOOLEAN\r
2423EFIAPI\r
2424HkdfSha256ExtractAndExpand (\r
2425 IN CONST UINT8 *Key,\r
2426 IN UINTN KeySize,\r
2427 IN CONST UINT8 *Salt,\r
2428 IN UINTN SaltSize,\r
2429 IN CONST UINT8 *Info,\r
2430 IN UINTN InfoSize,\r
2431 OUT UINT8 *Out,\r
2432 IN UINTN OutSize\r
2433 );\r
2434\r
afeb55e4 2435#endif // __BASE_CRYPT_LIB_H__\r