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