]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Driver/Crypto.c
CryptoPkg: Add EC key interface to DXE and protocol
[mirror_edk2.git] / CryptoPkg / Driver / Crypto.c
CommitLineData
cc1d13c9
MK
1/** @file\r
2 Implements the EDK II Crypto Protocol/PPI services using the library services\r
3 from BaseCryptLib and TlsLib.\r
4\r
5 Copyright (C) Microsoft Corporation. All rights reserved.\r
c1e66210 6 Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>\r
cc1d13c9
MK
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10#include <Base.h>\r
11#include <Library/DebugLib.h>\r
12#include <Library/BaseCryptLib.h>\r
13#include <Library/TlsLib.h>\r
14#include <Protocol/Crypto.h>\r
15#include <Pcd/PcdCryptoServiceFamilyEnable.h>\r
16\r
17/**\r
18 A macro used to retrieve the FixedAtBuild PcdCryptoServiceFamilyEnable with a\r
19 typecast to its associcted structure type PCD_CRYPTO_SERVICE_FAMILY_ENABLE.\r
20**/\r
7c342378 21#define EDKII_CRYPTO_PCD ((const PCD_CRYPTO_SERVICE_FAMILY_ENABLE *)\\r
cc1d13c9
MK
22 (FixedPcdGetPtr (PcdCryptoServiceFamilyEnable)))\r
23\r
24/**\r
25 A macro used to call a non-void BaseCryptLib function if it is enabled.\r
26\r
27 If a BaseCryptLib function is not enabled, there will be no references to it\r
28 from this module and will be optimized away reducing the size of this module.\r
29\r
30 @param Enable The name of the enable field in PCD\r
31 PcdCryptoServiceFamilyEnable for the BaseCryptLib\r
32 function being called. If the value of this field\r
33 is non-zero, then the BaseCryptLib function is\r
34 enabled.\r
35 @param Function The name of the BaseCryptLib function.\r
36 @param Args The argument list to pass to Function.\r
37 @param ErrorReturnValue The value to return if the BaseCryptLib function is\r
38 not enabled.\r
39\r
40**/\r
41#define CALL_BASECRYPTLIB(Enable, Function, Args, ErrorReturnValue) \\r
42 EDKII_CRYPTO_PCD->Enable \\r
43 ? Function Args \\r
aaa90aac 44 : (BaseCryptLibServiceNotEnabled (#Function), ErrorReturnValue)\r
cc1d13c9
MK
45\r
46/**\r
47 A macro used to call a void BaseCryptLib function if it is enabled.\r
48\r
49 If a BaseCryptLib function is not enabled, there will be no references to it\r
50 from this module and will be optimized away reducing the size of this module.\r
51\r
52 @param Enable The name of the enable field in PCD\r
53 PcdCryptoServiceFamilyEnable for the BaseCryptLib\r
54 function being called. If the value of this field\r
55 is non-zero, then the BaseCryptLib function is\r
56 enabled.\r
57 @param Function The name of the BaseCryptLib function.\r
58 @param Args The argument list to pass to Function.\r
59\r
60**/\r
61#define CALL_VOID_BASECRYPTLIB(Enable, Function, Args) \\r
62 EDKII_CRYPTO_PCD->Enable \\r
63 ? Function Args \\r
aaa90aac 64 : BaseCryptLibServiceNotEnabled (#Function)\r
cc1d13c9
MK
65\r
66/**\r
67 Internal worker function that prints a debug message and asserts if a call is\r
68 made to a BaseCryptLib function that is not enabled in the EDK II Crypto\r
69 Protocol/PPI.\r
70\r
71 If this debug message and assert are observed, then a module is using\r
72 BaseCryptLib function that is not enabled in a Crypto driver. The\r
73 PcdCryptoServiceFamilyEnable should be updated to enable the missing service.\r
74\r
75 @param[in] FunctionName Null-terminated ASCII string that is the name of an\r
76 EDK II Crypto service.\r
77\r
78**/\r
79static\r
80VOID\r
aaa90aac 81BaseCryptLibServiceNotEnabled (\r
cc1d13c9
MK
82 IN CONST CHAR8 *FunctionName\r
83 )\r
84{\r
85 DEBUG ((DEBUG_ERROR, "[%a] Function %a() is not enabled\n", gEfiCallerBaseName, FunctionName));\r
86 ASSERT_EFI_ERROR (EFI_UNSUPPORTED);\r
87}\r
88\r
aaa90aac
ZG
89/**\r
90 Internal worker function that prints a debug message and asserts if a call is\r
91 made to a BaseCryptLib function that is deprecated and unsupported any longer.\r
92\r
93 @param[in] FunctionName Null-terminated ASCII string that is the name of an\r
94 EDK II Crypto service.\r
95\r
96**/\r
97static\r
98VOID\r
99BaseCryptLibServiceDeprecated (\r
100 IN CONST CHAR8 *FunctionName\r
101 )\r
102{\r
103 DEBUG ((DEBUG_ERROR, "[%a] Function %a() is deprecated and unsupported any longer\n", gEfiCallerBaseName, FunctionName));\r
104 ASSERT_EFI_ERROR (EFI_UNSUPPORTED);\r
105}\r
106\r
cc1d13c9
MK
107/**\r
108 Returns the version of the EDK II Crypto Protocol.\r
109\r
110 @return The version of the EDK II Crypto Protocol.\r
111\r
112**/\r
113UINTN\r
114EFIAPI\r
115CryptoServiceGetCryptoVersion (\r
116 VOID\r
117 )\r
118{\r
119 return EDKII_CRYPTO_VERSION;\r
120}\r
121\r
7c342378 122// =====================================================================================\r
cc1d13c9 123// One-Way Cryptographic Hash Primitives\r
7c342378 124// =====================================================================================\r
cc1d13c9
MK
125\r
126/**\r
0a6fc3d0
ZG
127 MD4 is deprecated and unsupported any longer.\r
128 Keep the function field for binary compability.\r
cc1d13c9 129\r
cc1d13c9
MK
130 @retval 0 This interface is not supported.\r
131\r
132**/\r
133UINTN\r
134EFIAPI\r
0a6fc3d0 135DeprecatedCryptoServiceMd4GetContextSize (\r
cc1d13c9
MK
136 VOID\r
137 )\r
138{\r
0a6fc3d0 139 return BaseCryptLibServiceDeprecated ("Md4GetContextSize"), 0;\r
cc1d13c9
MK
140}\r
141\r
142/**\r
0a6fc3d0
ZG
143 MD4 is deprecated and unsupported any longer.\r
144 Keep the function field for binary compability.\r
cc1d13c9
MK
145\r
146 @param[out] Md4Context Pointer to MD4 context being initialized.\r
147\r
cc1d13c9
MK
148 @retval FALSE This interface is not supported.\r
149\r
150**/\r
151BOOLEAN\r
152EFIAPI\r
0a6fc3d0 153DeprecatedCryptoServiceMd4Init (\r
cc1d13c9
MK
154 OUT VOID *Md4Context\r
155 )\r
156{\r
0a6fc3d0 157 return BaseCryptLibServiceDeprecated ("Md4Init"), FALSE;\r
cc1d13c9
MK
158}\r
159\r
160/**\r
0a6fc3d0
ZG
161 MD4 is deprecated and unsupported any longer.\r
162 Keep the function field for binary compability.\r
cc1d13c9
MK
163\r
164 @param[in] Md4Context Pointer to MD4 context being copied.\r
165 @param[out] NewMd4Context Pointer to new MD4 context.\r
166\r
cc1d13c9
MK
167 @retval FALSE This interface is not supported.\r
168\r
169**/\r
170BOOLEAN\r
171EFIAPI\r
0a6fc3d0 172DeprecatedCryptoServiceMd4Duplicate (\r
cc1d13c9
MK
173 IN CONST VOID *Md4Context,\r
174 OUT VOID *NewMd4Context\r
175 )\r
176{\r
0a6fc3d0 177 return BaseCryptLibServiceDeprecated ("Md4Duplicate"), FALSE;\r
cc1d13c9
MK
178}\r
179\r
180/**\r
0a6fc3d0
ZG
181 MD4 is deprecated and unsupported any longer.\r
182 Keep the function field for binary compability.\r
cc1d13c9
MK
183\r
184 @param[in, out] Md4Context Pointer to the MD4 context.\r
185 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
186 @param[in] DataSize Size of Data buffer in bytes.\r
187\r
cc1d13c9
MK
188 @retval FALSE This interface is not supported.\r
189\r
190**/\r
191BOOLEAN\r
192EFIAPI\r
0a6fc3d0 193DeprecatedCryptoServiceMd4Update (\r
cc1d13c9
MK
194 IN OUT VOID *Md4Context,\r
195 IN CONST VOID *Data,\r
196 IN UINTN DataSize\r
197 )\r
198{\r
0a6fc3d0 199 return BaseCryptLibServiceDeprecated ("Md4Update"), FALSE;\r
cc1d13c9
MK
200}\r
201\r
202/**\r
0a6fc3d0
ZG
203 MD4 is deprecated and unsupported any longer.\r
204 Keep the function field for binary compability.\r
cc1d13c9
MK
205\r
206 @param[in, out] Md4Context Pointer to the MD4 context.\r
207 @param[out] HashValue Pointer to a buffer that receives the MD4 digest\r
208 value (16 bytes).\r
209\r
cc1d13c9
MK
210 @retval FALSE This interface is not supported.\r
211\r
212**/\r
213BOOLEAN\r
214EFIAPI\r
0a6fc3d0 215DeprecatedCryptoServiceMd4Final (\r
cc1d13c9
MK
216 IN OUT VOID *Md4Context,\r
217 OUT UINT8 *HashValue\r
218 )\r
219{\r
0a6fc3d0 220 return BaseCryptLibServiceDeprecated ("Md4Final"), FALSE;\r
cc1d13c9
MK
221}\r
222\r
223/**\r
0a6fc3d0
ZG
224 MD4 is deprecated and unsupported any longer.\r
225 Keep the function field for binary compability.\r
cc1d13c9
MK
226\r
227 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
228 @param[in] DataSize Size of Data buffer in bytes.\r
229 @param[out] HashValue Pointer to a buffer that receives the MD4 digest\r
230 value (16 bytes).\r
231\r
cc1d13c9
MK
232 @retval FALSE This interface is not supported.\r
233\r
234**/\r
235BOOLEAN\r
236EFIAPI\r
0a6fc3d0 237DeprecatedCryptoServiceMd4HashAll (\r
cc1d13c9
MK
238 IN CONST VOID *Data,\r
239 IN UINTN DataSize,\r
240 OUT UINT8 *HashValue\r
241 )\r
242{\r
0a6fc3d0 243 return BaseCryptLibServiceDeprecated ("Md4HashAll"), FALSE;\r
cc1d13c9
MK
244}\r
245\r
e6a12a0f 246#ifndef ENABLE_MD5_DEPRECATED_INTERFACES\r
7c342378 247\r
acfd5557
ZG
248/**\r
249 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
250\r
251 If this interface is not supported, then return zero.\r
252\r
253 @retval 0 This interface is not supported.\r
254\r
255**/\r
256UINTN\r
257EFIAPI\r
258DeprecatedCryptoServiceMd5GetContextSize (\r
259 VOID\r
260 )\r
261{\r
262 return BaseCryptLibServiceDeprecated ("Md5GetContextSize"), 0;\r
263}\r
264\r
265/**\r
266 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r
267 subsequent use.\r
268\r
269 If Md5Context is NULL, then return FALSE.\r
270 If this interface is not supported, then return FALSE.\r
271\r
272 @param[out] Md5Context Pointer to MD5 context being initialized.\r
273\r
274 @retval FALSE This interface is not supported.\r
275\r
276**/\r
277BOOLEAN\r
278EFIAPI\r
279DeprecatedCryptoServiceMd5Init (\r
280 OUT VOID *Md5Context\r
281 )\r
282{\r
283 return BaseCryptLibServiceDeprecated ("Md5Init"), FALSE;\r
284}\r
285\r
286/**\r
287 Makes a copy of an existing MD5 context.\r
288\r
289 If Md5Context is NULL, then return FALSE.\r
290 If NewMd5Context is NULL, then return FALSE.\r
291 If this interface is not supported, then return FALSE.\r
292\r
293 @param[in] Md5Context Pointer to MD5 context being copied.\r
294 @param[out] NewMd5Context Pointer to new MD5 context.\r
295\r
296 @retval FALSE This interface is not supported.\r
297\r
298**/\r
299BOOLEAN\r
300EFIAPI\r
301DeprecatedCryptoServiceMd5Duplicate (\r
302 IN CONST VOID *Md5Context,\r
303 OUT VOID *NewMd5Context\r
304 )\r
305{\r
306 return BaseCryptLibServiceDeprecated ("Md5Init"), FALSE;\r
307}\r
308\r
309/**\r
310 Digests the input data and updates MD5 context.\r
311\r
312 This function performs MD5 digest on a data buffer of the specified size.\r
313 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
314 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized\r
315 by Md5Final(). Behavior with invalid context is undefined.\r
316\r
317 If Md5Context is NULL, then return FALSE.\r
318 If this interface is not supported, then return FALSE.\r
319\r
320 @param[in, out] Md5Context Pointer to the MD5 context.\r
321 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
322 @param[in] DataSize Size of Data buffer in bytes.\r
323\r
324 @retval FALSE This interface is not supported.\r
325\r
326**/\r
327BOOLEAN\r
328EFIAPI\r
329DeprecatedCryptoServiceMd5Update (\r
330 IN OUT VOID *Md5Context,\r
331 IN CONST VOID *Data,\r
332 IN UINTN DataSize\r
333 )\r
334{\r
335 return BaseCryptLibServiceDeprecated ("Md5Init"), FALSE;\r
336}\r
337\r
338/**\r
339 Completes computation of the MD5 digest value.\r
340\r
341 This function completes MD5 hash computation and retrieves the digest value into\r
342 the specified memory. After this function has been called, the MD5 context cannot\r
343 be used again.\r
344 MD5 context should be already correctly initialized by Md5Init(), and should not be\r
345 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r
346\r
347 If Md5Context is NULL, then return FALSE.\r
348 If HashValue is NULL, then return FALSE.\r
349 If this interface is not supported, then return FALSE.\r
350\r
351 @param[in, out] Md5Context Pointer to the MD5 context.\r
352 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
353 value (16 bytes).\r
354\r
355 @retval FALSE This interface is not supported.\r
356\r
357**/\r
358BOOLEAN\r
359EFIAPI\r
360DeprecatedCryptoServiceMd5Final (\r
361 IN OUT VOID *Md5Context,\r
362 OUT UINT8 *HashValue\r
363 )\r
364{\r
365 return BaseCryptLibServiceDeprecated ("Md5Final"), FALSE;\r
366}\r
367\r
368/**\r
369 Computes the MD5 message digest of a input data buffer.\r
370\r
371 This function performs the MD5 message digest of a given data buffer, and places\r
372 the digest value into the specified memory.\r
373\r
374 If this interface is not supported, then return FALSE.\r
375\r
376 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
377 @param[in] DataSize Size of Data buffer in bytes.\r
378 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
379 value (16 bytes).\r
380\r
381 @retval FALSE This interface is not supported.\r
382\r
383**/\r
384BOOLEAN\r
385EFIAPI\r
386DeprecatedCryptoServiceMd5HashAll (\r
387 IN CONST VOID *Data,\r
388 IN UINTN DataSize,\r
389 OUT UINT8 *HashValue\r
390 )\r
391{\r
392 return BaseCryptLibServiceDeprecated ("Md5HashAll"), FALSE;\r
393}\r
7c342378 394\r
acfd5557 395#else\r
7c342378 396\r
cc1d13c9
MK
397/**\r
398 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
399\r
400 If this interface is not supported, then return zero.\r
401\r
402 @return The size, in bytes, of the context buffer required for MD5 hash operations.\r
403 @retval 0 This interface is not supported.\r
404\r
405**/\r
406UINTN\r
407EFIAPI\r
408CryptoServiceMd5GetContextSize (\r
409 VOID\r
410 )\r
411{\r
412 return CALL_BASECRYPTLIB (Md5.Services.GetContextSize, Md5GetContextSize, (), 0);\r
413}\r
414\r
415/**\r
416 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r
417 subsequent use.\r
418\r
419 If Md5Context is NULL, then return FALSE.\r
420 If this interface is not supported, then return FALSE.\r
421\r
422 @param[out] Md5Context Pointer to MD5 context being initialized.\r
423\r
424 @retval TRUE MD5 context initialization succeeded.\r
425 @retval FALSE MD5 context initialization failed.\r
426 @retval FALSE This interface is not supported.\r
427\r
428**/\r
429BOOLEAN\r
430EFIAPI\r
431CryptoServiceMd5Init (\r
432 OUT VOID *Md5Context\r
433 )\r
434{\r
435 return CALL_BASECRYPTLIB (Md5.Services.Init, Md5Init, (Md5Context), FALSE);\r
436}\r
437\r
438/**\r
439 Makes a copy of an existing MD5 context.\r
440\r
441 If Md5Context is NULL, then return FALSE.\r
442 If NewMd5Context is NULL, then return FALSE.\r
443 If this interface is not supported, then return FALSE.\r
444\r
445 @param[in] Md5Context Pointer to MD5 context being copied.\r
446 @param[out] NewMd5Context Pointer to new MD5 context.\r
447\r
448 @retval TRUE MD5 context copy succeeded.\r
449 @retval FALSE MD5 context copy failed.\r
450 @retval FALSE This interface is not supported.\r
451\r
452**/\r
453BOOLEAN\r
454EFIAPI\r
455CryptoServiceMd5Duplicate (\r
456 IN CONST VOID *Md5Context,\r
457 OUT VOID *NewMd5Context\r
458 )\r
459{\r
460 return CALL_BASECRYPTLIB (Md5.Services.Duplicate, Md5Duplicate, (Md5Context, NewMd5Context), FALSE);\r
461}\r
462\r
463/**\r
464 Digests the input data and updates MD5 context.\r
465\r
466 This function performs MD5 digest on a data buffer of the specified size.\r
467 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
468 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized\r
469 by Md5Final(). Behavior with invalid context is undefined.\r
470\r
471 If Md5Context is NULL, then return FALSE.\r
472 If this interface is not supported, then return FALSE.\r
473\r
474 @param[in, out] Md5Context Pointer to the MD5 context.\r
475 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
476 @param[in] DataSize Size of Data buffer in bytes.\r
477\r
478 @retval TRUE MD5 data digest succeeded.\r
479 @retval FALSE MD5 data digest failed.\r
480 @retval FALSE This interface is not supported.\r
481\r
482**/\r
483BOOLEAN\r
484EFIAPI\r
485CryptoServiceMd5Update (\r
486 IN OUT VOID *Md5Context,\r
487 IN CONST VOID *Data,\r
488 IN UINTN DataSize\r
489 )\r
490{\r
491 return CALL_BASECRYPTLIB (Md5.Services.Update, Md5Update, (Md5Context, Data, DataSize), FALSE);\r
492}\r
493\r
494/**\r
495 Completes computation of the MD5 digest value.\r
496\r
497 This function completes MD5 hash computation and retrieves the digest value into\r
498 the specified memory. After this function has been called, the MD5 context cannot\r
499 be used again.\r
500 MD5 context should be already correctly initialized by Md5Init(), and should not be\r
501 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r
502\r
503 If Md5Context is NULL, then return FALSE.\r
504 If HashValue is NULL, then return FALSE.\r
505 If this interface is not supported, then return FALSE.\r
506\r
507 @param[in, out] Md5Context Pointer to the MD5 context.\r
508 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
509 value (16 bytes).\r
510\r
511 @retval TRUE MD5 digest computation succeeded.\r
512 @retval FALSE MD5 digest computation failed.\r
513 @retval FALSE This interface is not supported.\r
514\r
515**/\r
516BOOLEAN\r
517EFIAPI\r
518CryptoServiceMd5Final (\r
519 IN OUT VOID *Md5Context,\r
520 OUT UINT8 *HashValue\r
521 )\r
522{\r
523 return CALL_BASECRYPTLIB (Md5.Services.Final, Md5Final, (Md5Context, HashValue), FALSE);\r
524}\r
525\r
526/**\r
527 Computes the MD5 message digest of a input data buffer.\r
528\r
529 This function performs the MD5 message digest of a given data buffer, and places\r
530 the digest value into the specified memory.\r
531\r
532 If this interface is not supported, then return FALSE.\r
533\r
534 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
535 @param[in] DataSize Size of Data buffer in bytes.\r
536 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
537 value (16 bytes).\r
538\r
539 @retval TRUE MD5 digest computation succeeded.\r
540 @retval FALSE MD5 digest computation failed.\r
541 @retval FALSE This interface is not supported.\r
542\r
543**/\r
544BOOLEAN\r
545EFIAPI\r
546CryptoServiceMd5HashAll (\r
547 IN CONST VOID *Data,\r
548 IN UINTN DataSize,\r
549 OUT UINT8 *HashValue\r
550 )\r
551{\r
552 return CALL_BASECRYPTLIB (Md5.Services.HashAll, Md5HashAll, (Data, DataSize, HashValue), FALSE);\r
553}\r
7c342378 554\r
acfd5557 555#endif\r
cc1d13c9 556\r
0f01cec5 557#ifdef DISABLE_SHA1_DEPRECATED_INTERFACES\r
7c342378 558\r
0f01cec5
ZG
559/**\r
560 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
561\r
562 If this interface is not supported, then return zero.\r
563\r
564 @retval 0 This interface is not supported.\r
565\r
566**/\r
567UINTN\r
568EFIAPI\r
569DeprecatedCryptoServiceSha1GetContextSize (\r
570 VOID\r
571 )\r
572{\r
573 return BaseCryptLibServiceDeprecated ("Sha1GetContextSize"), 0;\r
574}\r
575\r
576/**\r
577 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for\r
578 subsequent use.\r
579\r
580 If Sha1Context is NULL, then return FALSE.\r
581 If this interface is not supported, then return FALSE.\r
582\r
583 @param[out] Sha1Context Pointer to SHA-1 context being initialized.\r
584\r
585 @retval TRUE SHA-1 context initialization succeeded.\r
586 @retval FALSE SHA-1 context initialization failed.\r
587 @retval FALSE This interface is not supported.\r
588\r
589**/\r
590BOOLEAN\r
591EFIAPI\r
592DeprecatedCryptoServiceSha1Init (\r
593 OUT VOID *Sha1Context\r
594 )\r
595{\r
596 return BaseCryptLibServiceDeprecated ("Sha1Init"), FALSE;\r
597}\r
598\r
599/**\r
600 Makes a copy of an existing SHA-1 context.\r
601\r
602 If Sha1Context is NULL, then return FALSE.\r
603 If NewSha1Context is NULL, then return FALSE.\r
604 If this interface is not supported, then return FALSE.\r
605\r
606 @param[in] Sha1Context Pointer to SHA-1 context being copied.\r
607 @param[out] NewSha1Context Pointer to new SHA-1 context.\r
608\r
609 @retval FALSE This interface is not supported.\r
610\r
611**/\r
612BOOLEAN\r
613EFIAPI\r
614DeprecatedCryptoServiceSha1Duplicate (\r
615 IN CONST VOID *Sha1Context,\r
616 OUT VOID *NewSha1Context\r
617 )\r
618{\r
619 return BaseCryptLibServiceDeprecated ("Sha1Duplicate"), FALSE;\r
620}\r
621\r
622/**\r
623 Digests the input data and updates SHA-1 context.\r
624\r
625 This function performs SHA-1 digest on a data buffer of the specified size.\r
626 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
627 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized\r
628 by Sha1Final(). Behavior with invalid context is undefined.\r
629\r
630 If Sha1Context is NULL, then return FALSE.\r
631 If this interface is not supported, then return FALSE.\r
632\r
633 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
634 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
635 @param[in] DataSize Size of Data buffer in bytes.\r
636\r
637 @retval FALSE This interface is not supported.\r
638\r
639**/\r
640BOOLEAN\r
641EFIAPI\r
642DeprecatedCryptoServiceSha1Update (\r
643 IN OUT VOID *Sha1Context,\r
644 IN CONST VOID *Data,\r
645 IN UINTN DataSize\r
646 )\r
647{\r
648 return BaseCryptLibServiceDeprecated ("Sha1Update"), FALSE;\r
649}\r
650\r
651/**\r
652 Completes computation of the SHA-1 digest value.\r
653\r
654 This function completes SHA-1 hash computation and retrieves the digest value into\r
655 the specified memory. After this function has been called, the SHA-1 context cannot\r
656 be used again.\r
657 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be\r
658 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.\r
659\r
660 If Sha1Context is NULL, then return FALSE.\r
661 If HashValue is NULL, then return FALSE.\r
662 If this interface is not supported, then return FALSE.\r
663\r
664 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
665 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
666 value (20 bytes).\r
667\r
668 @retval FALSE This interface is not supported.\r
669\r
670**/\r
671BOOLEAN\r
672EFIAPI\r
673DeprecatedCryptoServiceSha1Final (\r
674 IN OUT VOID *Sha1Context,\r
675 OUT UINT8 *HashValue\r
676 )\r
677{\r
678 return BaseCryptLibServiceDeprecated ("Sha1Final"), FALSE;\r
679}\r
680\r
681/**\r
682 Computes the SHA-1 message digest of a input data buffer.\r
683\r
684 This function performs the SHA-1 message digest of a given data buffer, and places\r
685 the digest value into the specified memory.\r
686\r
687 If this interface is not supported, then return FALSE.\r
688\r
689 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
690 @param[in] DataSize Size of Data buffer in bytes.\r
691 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
692 value (20 bytes).\r
693\r
694 @retval FALSE This interface is not supported.\r
695\r
696**/\r
697BOOLEAN\r
698EFIAPI\r
699DeprecatedCryptoServiceSha1HashAll (\r
700 IN CONST VOID *Data,\r
701 IN UINTN DataSize,\r
702 OUT UINT8 *HashValue\r
703 )\r
704{\r
705 return BaseCryptLibServiceDeprecated ("Sha1HashAll"), FALSE;\r
706}\r
7c342378 707\r
0f01cec5 708#else\r
7c342378 709\r
cc1d13c9
MK
710/**\r
711 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.\r
712\r
713 If this interface is not supported, then return zero.\r
714\r
715 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.\r
716 @retval 0 This interface is not supported.\r
717\r
718**/\r
719UINTN\r
720EFIAPI\r
721CryptoServiceSha1GetContextSize (\r
722 VOID\r
723 )\r
724{\r
725 return CALL_BASECRYPTLIB (Sha1.Services.GetContextSize, Sha1GetContextSize, (), 0);\r
726}\r
727\r
728/**\r
729 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for\r
730 subsequent use.\r
731\r
732 If Sha1Context is NULL, then return FALSE.\r
733 If this interface is not supported, then return FALSE.\r
734\r
735 @param[out] Sha1Context Pointer to SHA-1 context being initialized.\r
736\r
737 @retval TRUE SHA-1 context initialization succeeded.\r
738 @retval FALSE SHA-1 context initialization failed.\r
739 @retval FALSE This interface is not supported.\r
740\r
741**/\r
742BOOLEAN\r
743EFIAPI\r
744CryptoServiceSha1Init (\r
745 OUT VOID *Sha1Context\r
746 )\r
747{\r
748 return CALL_BASECRYPTLIB (Sha1.Services.Init, Sha1Init, (Sha1Context), FALSE);\r
749}\r
750\r
751/**\r
752 Makes a copy of an existing SHA-1 context.\r
753\r
754 If Sha1Context is NULL, then return FALSE.\r
755 If NewSha1Context is NULL, then return FALSE.\r
756 If this interface is not supported, then return FALSE.\r
757\r
758 @param[in] Sha1Context Pointer to SHA-1 context being copied.\r
759 @param[out] NewSha1Context Pointer to new SHA-1 context.\r
760\r
761 @retval TRUE SHA-1 context copy succeeded.\r
762 @retval FALSE SHA-1 context copy failed.\r
763 @retval FALSE This interface is not supported.\r
764\r
765**/\r
766BOOLEAN\r
767EFIAPI\r
768CryptoServiceSha1Duplicate (\r
769 IN CONST VOID *Sha1Context,\r
770 OUT VOID *NewSha1Context\r
771 )\r
772{\r
773 return CALL_BASECRYPTLIB (Sha1.Services.Duplicate, Sha1Duplicate, (Sha1Context, NewSha1Context), FALSE);\r
774}\r
775\r
776/**\r
777 Digests the input data and updates SHA-1 context.\r
778\r
779 This function performs SHA-1 digest on a data buffer of the specified size.\r
780 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
781 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized\r
782 by Sha1Final(). Behavior with invalid context is undefined.\r
783\r
784 If Sha1Context is NULL, then return FALSE.\r
785 If this interface is not supported, then return FALSE.\r
786\r
787 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
788 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
789 @param[in] DataSize Size of Data buffer in bytes.\r
790\r
791 @retval TRUE SHA-1 data digest succeeded.\r
792 @retval FALSE SHA-1 data digest failed.\r
793 @retval FALSE This interface is not supported.\r
794\r
795**/\r
796BOOLEAN\r
797EFIAPI\r
798CryptoServiceSha1Update (\r
799 IN OUT VOID *Sha1Context,\r
800 IN CONST VOID *Data,\r
801 IN UINTN DataSize\r
802 )\r
803{\r
804 return CALL_BASECRYPTLIB (Sha1.Services.Update, Sha1Update, (Sha1Context, Data, DataSize), FALSE);\r
805}\r
806\r
807/**\r
808 Completes computation of the SHA-1 digest value.\r
809\r
810 This function completes SHA-1 hash computation and retrieves the digest value into\r
811 the specified memory. After this function has been called, the SHA-1 context cannot\r
812 be used again.\r
813 SHA-1 context should be already correctly initialized by Sha1Init(), and should not be\r
814 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.\r
815\r
816 If Sha1Context is NULL, then return FALSE.\r
817 If HashValue is NULL, then return FALSE.\r
818 If this interface is not supported, then return FALSE.\r
819\r
820 @param[in, out] Sha1Context Pointer to the SHA-1 context.\r
821 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
822 value (20 bytes).\r
823\r
824 @retval TRUE SHA-1 digest computation succeeded.\r
825 @retval FALSE SHA-1 digest computation failed.\r
826 @retval FALSE This interface is not supported.\r
827\r
828**/\r
829BOOLEAN\r
830EFIAPI\r
831CryptoServiceSha1Final (\r
832 IN OUT VOID *Sha1Context,\r
833 OUT UINT8 *HashValue\r
834 )\r
835{\r
836 return CALL_BASECRYPTLIB (Sha1.Services.Final, Sha1Final, (Sha1Context, HashValue), FALSE);\r
837}\r
838\r
839/**\r
840 Computes the SHA-1 message digest of a input data buffer.\r
841\r
842 This function performs the SHA-1 message digest of a given data buffer, and places\r
843 the digest value into the specified memory.\r
844\r
845 If this interface is not supported, then return FALSE.\r
846\r
847 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
848 @param[in] DataSize Size of Data buffer in bytes.\r
849 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest\r
850 value (20 bytes).\r
851\r
852 @retval TRUE SHA-1 digest computation succeeded.\r
853 @retval FALSE SHA-1 digest computation failed.\r
854 @retval FALSE This interface is not supported.\r
855\r
856**/\r
857BOOLEAN\r
858EFIAPI\r
859CryptoServiceSha1HashAll (\r
860 IN CONST VOID *Data,\r
861 IN UINTN DataSize,\r
862 OUT UINT8 *HashValue\r
863 )\r
864{\r
865 return CALL_BASECRYPTLIB (Sha1.Services.HashAll, Sha1HashAll, (Data, DataSize, HashValue), FALSE);\r
866}\r
7c342378 867\r
0f01cec5 868#endif\r
cc1d13c9
MK
869\r
870/**\r
871 Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations.\r
872\r
873 @return The size, in bytes, of the context buffer required for SHA-256 hash operations.\r
874\r
875**/\r
876UINTN\r
877EFIAPI\r
878CryptoServiceSha256GetContextSize (\r
879 VOID\r
880 )\r
881{\r
882 return CALL_BASECRYPTLIB (Sha256.Services.GetContextSize, Sha256GetContextSize, (), 0);\r
883}\r
884\r
885/**\r
886 Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for\r
887 subsequent use.\r
888\r
889 If Sha256Context is NULL, then return FALSE.\r
890\r
891 @param[out] Sha256Context Pointer to SHA-256 context being initialized.\r
892\r
893 @retval TRUE SHA-256 context initialization succeeded.\r
894 @retval FALSE SHA-256 context initialization failed.\r
895\r
896**/\r
897BOOLEAN\r
898EFIAPI\r
899CryptoServiceSha256Init (\r
900 OUT VOID *Sha256Context\r
901 )\r
902{\r
903 return CALL_BASECRYPTLIB (Sha256.Services.Init, Sha256Init, (Sha256Context), FALSE);\r
904}\r
905\r
906/**\r
907 Makes a copy of an existing SHA-256 context.\r
908\r
909 If Sha256Context is NULL, then return FALSE.\r
910 If NewSha256Context is NULL, then return FALSE.\r
911 If this interface is not supported, then return FALSE.\r
912\r
913 @param[in] Sha256Context Pointer to SHA-256 context being copied.\r
914 @param[out] NewSha256Context Pointer to new SHA-256 context.\r
915\r
916 @retval TRUE SHA-256 context copy succeeded.\r
917 @retval FALSE SHA-256 context copy failed.\r
918 @retval FALSE This interface is not supported.\r
919\r
920**/\r
921BOOLEAN\r
922EFIAPI\r
923CryptoServiceSha256Duplicate (\r
924 IN CONST VOID *Sha256Context,\r
925 OUT VOID *NewSha256Context\r
926 )\r
927{\r
928 return CALL_BASECRYPTLIB (Sha256.Services.Duplicate, Sha256Duplicate, (Sha256Context, NewSha256Context), FALSE);\r
929}\r
930\r
931/**\r
932 Digests the input data and updates SHA-256 context.\r
933\r
934 This function performs SHA-256 digest on a data buffer of the specified size.\r
935 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
936 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized\r
937 by Sha256Final(). Behavior with invalid context is undefined.\r
938\r
939 If Sha256Context is NULL, then return FALSE.\r
940\r
941 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
942 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
943 @param[in] DataSize Size of Data buffer in bytes.\r
944\r
945 @retval TRUE SHA-256 data digest succeeded.\r
946 @retval FALSE SHA-256 data digest failed.\r
947\r
948**/\r
949BOOLEAN\r
950EFIAPI\r
951CryptoServiceSha256Update (\r
952 IN OUT VOID *Sha256Context,\r
953 IN CONST VOID *Data,\r
954 IN UINTN DataSize\r
955 )\r
956{\r
957 return CALL_BASECRYPTLIB (Sha256.Services.Update, Sha256Update, (Sha256Context, Data, DataSize), FALSE);\r
958}\r
959\r
960/**\r
961 Completes computation of the SHA-256 digest value.\r
962\r
963 This function completes SHA-256 hash computation and retrieves the digest value into\r
964 the specified memory. After this function has been called, the SHA-256 context cannot\r
965 be used again.\r
966 SHA-256 context should be already correctly initialized by Sha256Init(), and should not be\r
967 finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined.\r
968\r
969 If Sha256Context is NULL, then return FALSE.\r
970 If HashValue is NULL, then return FALSE.\r
971\r
972 @param[in, out] Sha256Context Pointer to the SHA-256 context.\r
973 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
974 value (32 bytes).\r
975\r
976 @retval TRUE SHA-256 digest computation succeeded.\r
977 @retval FALSE SHA-256 digest computation failed.\r
978\r
979**/\r
980BOOLEAN\r
981EFIAPI\r
982CryptoServiceSha256Final (\r
983 IN OUT VOID *Sha256Context,\r
984 OUT UINT8 *HashValue\r
985 )\r
986{\r
987 return CALL_BASECRYPTLIB (Sha256.Services.Final, Sha256Final, (Sha256Context, HashValue), FALSE);\r
988}\r
989\r
990/**\r
991 Computes the SHA-256 message digest of a input data buffer.\r
992\r
993 This function performs the SHA-256 message digest of a given data buffer, and places\r
994 the digest value into the specified memory.\r
995\r
996 If this interface is not supported, then return FALSE.\r
997\r
998 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
999 @param[in] DataSize Size of Data buffer in bytes.\r
1000 @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r
1001 value (32 bytes).\r
1002\r
1003 @retval TRUE SHA-256 digest computation succeeded.\r
1004 @retval FALSE SHA-256 digest computation failed.\r
1005 @retval FALSE This interface is not supported.\r
1006\r
1007**/\r
1008BOOLEAN\r
1009EFIAPI\r
1010CryptoServiceSha256HashAll (\r
1011 IN CONST VOID *Data,\r
1012 IN UINTN DataSize,\r
1013 OUT UINT8 *HashValue\r
1014 )\r
1015{\r
1016 return CALL_BASECRYPTLIB (Sha256.Services.HashAll, Sha256HashAll, (Data, DataSize, HashValue), FALSE);\r
1017}\r
1018\r
1019/**\r
1020 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.\r
1021\r
1022 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.\r
1023\r
1024**/\r
1025UINTN\r
1026EFIAPI\r
1027CryptoServiceSha384GetContextSize (\r
1028 VOID\r
1029 )\r
1030{\r
1031 return CALL_BASECRYPTLIB (Sha384.Services.GetContextSize, Sha384GetContextSize, (), 0);\r
1032}\r
1033\r
1034/**\r
1035 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for\r
1036 subsequent use.\r
1037\r
1038 If Sha384Context is NULL, then return FALSE.\r
1039\r
1040 @param[out] Sha384Context Pointer to SHA-384 context being initialized.\r
1041\r
1042 @retval TRUE SHA-384 context initialization succeeded.\r
1043 @retval FALSE SHA-384 context initialization failed.\r
1044\r
1045**/\r
1046BOOLEAN\r
1047EFIAPI\r
1048CryptoServiceSha384Init (\r
1049 OUT VOID *Sha384Context\r
1050 )\r
1051{\r
1052 return CALL_BASECRYPTLIB (Sha384.Services.Init, Sha384Init, (Sha384Context), FALSE);\r
1053}\r
1054\r
1055/**\r
1056 Makes a copy of an existing SHA-384 context.\r
1057\r
1058 If Sha384Context is NULL, then return FALSE.\r
1059 If NewSha384Context is NULL, then return FALSE.\r
1060 If this interface is not supported, then return FALSE.\r
1061\r
1062 @param[in] Sha384Context Pointer to SHA-384 context being copied.\r
1063 @param[out] NewSha384Context Pointer to new SHA-384 context.\r
1064\r
1065 @retval TRUE SHA-384 context copy succeeded.\r
1066 @retval FALSE SHA-384 context copy failed.\r
1067 @retval FALSE This interface is not supported.\r
1068\r
1069**/\r
1070BOOLEAN\r
1071EFIAPI\r
1072CryptoServiceSha384Duplicate (\r
1073 IN CONST VOID *Sha384Context,\r
1074 OUT VOID *NewSha384Context\r
1075 )\r
1076{\r
1077 return CALL_BASECRYPTLIB (Sha384.Services.Duplicate, Sha384Duplicate, (Sha384Context, NewSha384Context), FALSE);\r
1078}\r
1079\r
1080/**\r
1081 Digests the input data and updates SHA-384 context.\r
1082\r
1083 This function performs SHA-384 digest on a data buffer of the specified size.\r
1084 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1085 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized\r
1086 by Sha384Final(). Behavior with invalid context is undefined.\r
1087\r
1088 If Sha384Context is NULL, then return FALSE.\r
1089\r
1090 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
1091 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
1092 @param[in] DataSize Size of Data buffer in bytes.\r
1093\r
1094 @retval TRUE SHA-384 data digest succeeded.\r
1095 @retval FALSE SHA-384 data digest failed.\r
1096\r
1097**/\r
1098BOOLEAN\r
1099EFIAPI\r
1100CryptoServiceSha384Update (\r
1101 IN OUT VOID *Sha384Context,\r
1102 IN CONST VOID *Data,\r
1103 IN UINTN DataSize\r
1104 )\r
1105{\r
1106 return CALL_BASECRYPTLIB (Sha384.Services.Update, Sha384Update, (Sha384Context, Data, DataSize), FALSE);\r
1107}\r
1108\r
1109/**\r
1110 Completes computation of the SHA-384 digest value.\r
1111\r
1112 This function completes SHA-384 hash computation and retrieves the digest value into\r
1113 the specified memory. After this function has been called, the SHA-384 context cannot\r
1114 be used again.\r
1115 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be\r
1116 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.\r
1117\r
1118 If Sha384Context is NULL, then return FALSE.\r
1119 If HashValue is NULL, then return FALSE.\r
1120\r
1121 @param[in, out] Sha384Context Pointer to the SHA-384 context.\r
1122 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
1123 value (48 bytes).\r
1124\r
1125 @retval TRUE SHA-384 digest computation succeeded.\r
1126 @retval FALSE SHA-384 digest computation failed.\r
1127\r
1128**/\r
1129BOOLEAN\r
1130EFIAPI\r
1131CryptoServiceSha384Final (\r
1132 IN OUT VOID *Sha384Context,\r
1133 OUT UINT8 *HashValue\r
1134 )\r
1135{\r
1136 return CALL_BASECRYPTLIB (Sha384.Services.Final, Sha384Final, (Sha384Context, HashValue), FALSE);\r
1137}\r
1138\r
1139/**\r
1140 Computes the SHA-384 message digest of a input data buffer.\r
1141\r
1142 This function performs the SHA-384 message digest of a given data buffer, and places\r
1143 the digest value into the specified memory.\r
1144\r
1145 If this interface is not supported, then return FALSE.\r
1146\r
1147 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
1148 @param[in] DataSize Size of Data buffer in bytes.\r
1149 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest\r
1150 value (48 bytes).\r
1151\r
1152 @retval TRUE SHA-384 digest computation succeeded.\r
1153 @retval FALSE SHA-384 digest computation failed.\r
1154 @retval FALSE This interface is not supported.\r
1155\r
1156**/\r
1157BOOLEAN\r
1158EFIAPI\r
1159CryptoServiceSha384HashAll (\r
1160 IN CONST VOID *Data,\r
1161 IN UINTN DataSize,\r
1162 OUT UINT8 *HashValue\r
1163 )\r
1164{\r
1165 return CALL_BASECRYPTLIB (Sha384.Services.HashAll, Sha384HashAll, (Data, DataSize, HashValue), FALSE);\r
1166}\r
1167\r
1168/**\r
1169 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.\r
1170\r
1171 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.\r
1172\r
1173**/\r
1174UINTN\r
1175EFIAPI\r
1176CryptoServiceSha512GetContextSize (\r
1177 VOID\r
1178 )\r
1179{\r
1180 return CALL_BASECRYPTLIB (Sha512.Services.GetContextSize, Sha512GetContextSize, (), 0);\r
1181}\r
1182\r
1183/**\r
1184 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for\r
1185 subsequent use.\r
1186\r
1187 If Sha512Context is NULL, then return FALSE.\r
1188\r
1189 @param[out] Sha512Context Pointer to SHA-512 context being initialized.\r
1190\r
1191 @retval TRUE SHA-512 context initialization succeeded.\r
1192 @retval FALSE SHA-512 context initialization failed.\r
1193\r
1194**/\r
1195BOOLEAN\r
1196EFIAPI\r
1197CryptoServiceSha512Init (\r
1198 OUT VOID *Sha512Context\r
1199 )\r
1200{\r
1201 return CALL_BASECRYPTLIB (Sha512.Services.Init, Sha512Init, (Sha512Context), FALSE);\r
1202}\r
1203\r
1204/**\r
1205 Makes a copy of an existing SHA-512 context.\r
1206\r
1207 If Sha512Context is NULL, then return FALSE.\r
1208 If NewSha512Context is NULL, then return FALSE.\r
1209 If this interface is not supported, then return FALSE.\r
1210\r
1211 @param[in] Sha512Context Pointer to SHA-512 context being copied.\r
1212 @param[out] NewSha512Context Pointer to new SHA-512 context.\r
1213\r
1214 @retval TRUE SHA-512 context copy succeeded.\r
1215 @retval FALSE SHA-512 context copy failed.\r
1216 @retval FALSE This interface is not supported.\r
1217\r
1218**/\r
1219BOOLEAN\r
1220EFIAPI\r
1221CryptoServiceSha512Duplicate (\r
1222 IN CONST VOID *Sha512Context,\r
1223 OUT VOID *NewSha512Context\r
1224 )\r
1225{\r
1226 return CALL_BASECRYPTLIB (Sha512.Services.Duplicate, Sha512Duplicate, (Sha512Context, NewSha512Context), FALSE);\r
1227}\r
1228\r
1229/**\r
1230 Digests the input data and updates SHA-512 context.\r
1231\r
1232 This function performs SHA-512 digest on a data buffer of the specified size.\r
1233 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1234 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized\r
1235 by Sha512Final(). Behavior with invalid context is undefined.\r
1236\r
1237 If Sha512Context is NULL, then return FALSE.\r
1238\r
1239 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
1240 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
1241 @param[in] DataSize Size of Data buffer in bytes.\r
1242\r
1243 @retval TRUE SHA-512 data digest succeeded.\r
1244 @retval FALSE SHA-512 data digest failed.\r
1245\r
1246**/\r
1247BOOLEAN\r
1248EFIAPI\r
1249CryptoServiceSha512Update (\r
1250 IN OUT VOID *Sha512Context,\r
1251 IN CONST VOID *Data,\r
1252 IN UINTN DataSize\r
1253 )\r
1254{\r
1255 return CALL_BASECRYPTLIB (Sha512.Services.Update, Sha512Update, (Sha512Context, Data, DataSize), FALSE);\r
1256}\r
1257\r
1258/**\r
1259 Completes computation of the SHA-512 digest value.\r
1260\r
1261 This function completes SHA-512 hash computation and retrieves the digest value into\r
1262 the specified memory. After this function has been called, the SHA-512 context cannot\r
1263 be used again.\r
1264 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be\r
1265 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.\r
1266\r
1267 If Sha512Context is NULL, then return FALSE.\r
1268 If HashValue is NULL, then return FALSE.\r
1269\r
1270 @param[in, out] Sha512Context Pointer to the SHA-512 context.\r
1271 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
1272 value (64 bytes).\r
1273\r
1274 @retval TRUE SHA-512 digest computation succeeded.\r
1275 @retval FALSE SHA-512 digest computation failed.\r
1276\r
1277**/\r
1278BOOLEAN\r
1279EFIAPI\r
1280CryptoServiceSha512Final (\r
1281 IN OUT VOID *Sha512Context,\r
1282 OUT UINT8 *HashValue\r
1283 )\r
1284{\r
1285 return CALL_BASECRYPTLIB (Sha512.Services.Final, Sha512Final, (Sha512Context, HashValue), FALSE);\r
1286}\r
1287\r
1288/**\r
1289 Computes the SHA-512 message digest of a input data buffer.\r
1290\r
1291 This function performs the SHA-512 message digest of a given data buffer, and places\r
1292 the digest value into the specified memory.\r
1293\r
1294 If this interface is not supported, then return FALSE.\r
1295\r
1296 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
1297 @param[in] DataSize Size of Data buffer in bytes.\r
1298 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest\r
1299 value (64 bytes).\r
1300\r
1301 @retval TRUE SHA-512 digest computation succeeded.\r
1302 @retval FALSE SHA-512 digest computation failed.\r
1303 @retval FALSE This interface is not supported.\r
1304\r
1305**/\r
1306BOOLEAN\r
1307EFIAPI\r
1308CryptoServiceSha512HashAll (\r
1309 IN CONST VOID *Data,\r
1310 IN UINTN DataSize,\r
1311 OUT UINT8 *HashValue\r
1312 )\r
1313{\r
1314 return CALL_BASECRYPTLIB (Sha512.Services.HashAll, Sha512HashAll, (Data, DataSize, HashValue), FALSE);\r
1315}\r
1316\r
1317/**\r
1318 Retrieves the size, in bytes, of the context buffer required for SM3 hash operations.\r
1319\r
1320 @return The size, in bytes, of the context buffer required for SM3 hash operations.\r
1321\r
1322**/\r
1323UINTN\r
1324EFIAPI\r
1325CryptoServiceSm3GetContextSize (\r
1326 VOID\r
1327 )\r
1328{\r
1329 return CALL_BASECRYPTLIB (Sm3.Services.GetContextSize, Sm3GetContextSize, (), 0);\r
1330}\r
1331\r
1332/**\r
1333 Initializes user-supplied memory pointed by Sm3Context as SM3 hash context for\r
1334 subsequent use.\r
1335\r
1336 If Sm3Context is NULL, then return FALSE.\r
1337\r
1338 @param[out] Sm3Context Pointer to SM3 context being initialized.\r
1339\r
1340 @retval TRUE SM3 context initialization succeeded.\r
1341 @retval FALSE SM3 context initialization failed.\r
1342\r
1343**/\r
1344BOOLEAN\r
1345EFIAPI\r
1346CryptoServiceSm3Init (\r
1347 OUT VOID *Sm3Context\r
1348 )\r
1349{\r
1350 return CALL_BASECRYPTLIB (Sm3.Services.Init, Sm3Init, (Sm3Context), FALSE);\r
1351}\r
1352\r
1353/**\r
1354 Makes a copy of an existing SM3 context.\r
1355\r
1356 If Sm3Context is NULL, then return FALSE.\r
1357 If NewSm3Context is NULL, then return FALSE.\r
1358 If this interface is not supported, then return FALSE.\r
1359\r
1360 @param[in] Sm3Context Pointer to SM3 context being copied.\r
1361 @param[out] NewSm3Context Pointer to new SM3 context.\r
1362\r
1363 @retval TRUE SM3 context copy succeeded.\r
1364 @retval FALSE SM3 context copy failed.\r
1365 @retval FALSE This interface is not supported.\r
1366\r
1367**/\r
1368BOOLEAN\r
1369EFIAPI\r
1370CryptoServiceSm3Duplicate (\r
1371 IN CONST VOID *Sm3Context,\r
1372 OUT VOID *NewSm3Context\r
1373 )\r
1374{\r
1375 return CALL_BASECRYPTLIB (Sm3.Services.Duplicate, Sm3Duplicate, (Sm3Context, NewSm3Context), FALSE);\r
1376}\r
1377\r
1378/**\r
1379 Digests the input data and updates SM3 context.\r
1380\r
1381 This function performs SM3 digest on a data buffer of the specified size.\r
1382 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1383 SM3 context should be already correctly initialized by Sm3Init(), and should not be finalized\r
1384 by Sm3Final(). Behavior with invalid context is undefined.\r
1385\r
1386 If Sm3Context is NULL, then return FALSE.\r
1387\r
1388 @param[in, out] Sm3Context Pointer to the SM3 context.\r
1389 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
1390 @param[in] DataSize Size of Data buffer in bytes.\r
1391\r
1392 @retval TRUE SM3 data digest succeeded.\r
1393 @retval FALSE SM3 data digest failed.\r
1394\r
1395**/\r
1396BOOLEAN\r
1397EFIAPI\r
1398CryptoServiceSm3Update (\r
1399 IN OUT VOID *Sm3Context,\r
1400 IN CONST VOID *Data,\r
1401 IN UINTN DataSize\r
1402 )\r
1403{\r
1404 return CALL_BASECRYPTLIB (Sm3.Services.Update, Sm3Update, (Sm3Context, Data, DataSize), FALSE);\r
1405}\r
1406\r
1407/**\r
1408 Completes computation of the SM3 digest value.\r
1409\r
1410 This function completes SM3 hash computation and retrieves the digest value into\r
1411 the specified memory. After this function has been called, the SM3 context cannot\r
1412 be used again.\r
1413 SM3 context should be already correctly initialized by Sm3Init(), and should not be\r
1414 finalized by Sm3Final(). Behavior with invalid SM3 context is undefined.\r
1415\r
1416 If Sm3Context is NULL, then return FALSE.\r
1417 If HashValue is NULL, then return FALSE.\r
1418\r
1419 @param[in, out] Sm3Context Pointer to the SM3 context.\r
1420 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
1421 value (32 bytes).\r
1422\r
1423 @retval TRUE SM3 digest computation succeeded.\r
1424 @retval FALSE SM3 digest computation failed.\r
1425\r
1426**/\r
1427BOOLEAN\r
1428EFIAPI\r
1429CryptoServiceSm3Final (\r
1430 IN OUT VOID *Sm3Context,\r
1431 OUT UINT8 *HashValue\r
1432 )\r
1433{\r
1434 return CALL_BASECRYPTLIB (Sm3.Services.Final, Sm3Final, (Sm3Context, HashValue), FALSE);\r
1435}\r
1436\r
1437/**\r
1438 Computes the SM3 message digest of a input data buffer.\r
1439\r
1440 This function performs the SM3 message digest of a given data buffer, and places\r
1441 the digest value into the specified memory.\r
1442\r
1443 If this interface is not supported, then return FALSE.\r
1444\r
1445 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
1446 @param[in] DataSize Size of Data buffer in bytes.\r
1447 @param[out] HashValue Pointer to a buffer that receives the SM3 digest\r
1448 value (32 bytes).\r
1449\r
1450 @retval TRUE SM3 digest computation succeeded.\r
1451 @retval FALSE SM3 digest computation failed.\r
1452 @retval FALSE This interface is not supported.\r
1453\r
1454**/\r
1455BOOLEAN\r
1456EFIAPI\r
1457CryptoServiceSm3HashAll (\r
1458 IN CONST VOID *Data,\r
1459 IN UINTN DataSize,\r
1460 OUT UINT8 *HashValue\r
1461 )\r
1462{\r
1463 return CALL_BASECRYPTLIB (Sm3.Services.HashAll, Sm3HashAll, (Data, DataSize, HashValue), FALSE);\r
1464}\r
1465\r
7c342378 1466// =====================================================================================\r
cc1d13c9 1467// MAC (Message Authentication Code) Primitive\r
7c342378 1468// =====================================================================================\r
cc1d13c9
MK
1469\r
1470/**\r
b6174e2d
ZG
1471 HMAC MD5 is deprecated and unsupported any longer.\r
1472 Keep the function field for binary compability.\r
cc1d13c9 1473\r
cc1d13c9
MK
1474 @retval NULL This interface is not supported.\r
1475\r
1476**/\r
1477VOID *\r
1478EFIAPI\r
b6174e2d 1479DeprecatedCryptoServiceHmacMd5New (\r
cc1d13c9
MK
1480 VOID\r
1481 )\r
1482{\r
b6174e2d 1483 return BaseCryptLibServiceDeprecated ("HmacMd5New"), NULL;\r
cc1d13c9
MK
1484}\r
1485\r
1486/**\r
b6174e2d
ZG
1487 HMAC MD5 is deprecated and unsupported any longer.\r
1488 Keep the function field for binary compability.\r
cc1d13c9
MK
1489\r
1490 @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released.\r
1491\r
1492**/\r
1493VOID\r
1494EFIAPI\r
b6174e2d 1495DeprecatedCryptoServiceHmacMd5Free (\r
cc1d13c9
MK
1496 IN VOID *HmacMd5Ctx\r
1497 )\r
1498{\r
b6174e2d 1499 BaseCryptLibServiceDeprecated ("HmacMd5Free");\r
cc1d13c9
MK
1500}\r
1501\r
1502/**\r
b6174e2d
ZG
1503 HMAC MD5 is deprecated and unsupported any longer.\r
1504 Keep the function field for binary compability.\r
cc1d13c9
MK
1505\r
1506 @param[out] HmacMd5Context Pointer to HMAC-MD5 context.\r
1507 @param[in] Key Pointer to the user-supplied key.\r
1508 @param[in] KeySize Key size in bytes.\r
1509\r
cc1d13c9
MK
1510 @retval FALSE This interface is not supported.\r
1511\r
1512**/\r
1513BOOLEAN\r
1514EFIAPI\r
b6174e2d 1515DeprecatedCryptoServiceHmacMd5SetKey (\r
cc1d13c9
MK
1516 OUT VOID *HmacMd5Context,\r
1517 IN CONST UINT8 *Key,\r
1518 IN UINTN KeySize\r
1519 )\r
1520{\r
b6174e2d 1521 return BaseCryptLibServiceDeprecated ("HmacMd5SetKey"), FALSE;\r
cc1d13c9
MK
1522}\r
1523\r
1524/**\r
b6174e2d
ZG
1525 HMAC MD5 is deprecated and unsupported any longer.\r
1526 Keep the function field for binary compability.\r
cc1d13c9
MK
1527\r
1528 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.\r
1529 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.\r
1530\r
cc1d13c9
MK
1531 @retval FALSE This interface is not supported.\r
1532\r
1533**/\r
1534BOOLEAN\r
1535EFIAPI\r
b6174e2d 1536DeprecatedCryptoServiceHmacMd5Duplicate (\r
cc1d13c9
MK
1537 IN CONST VOID *HmacMd5Context,\r
1538 OUT VOID *NewHmacMd5Context\r
1539 )\r
1540{\r
b6174e2d 1541 return BaseCryptLibServiceDeprecated ("HmacMd5Duplicate"), FALSE;\r
cc1d13c9
MK
1542}\r
1543\r
1544/**\r
b6174e2d
ZG
1545 HMAC MD5 is deprecated and unsupported any longer.\r
1546 Keep the function field for binary compability.\r
cc1d13c9
MK
1547\r
1548 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.\r
1549 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1550 @param[in] DataSize Size of Data buffer in bytes.\r
1551\r
cc1d13c9
MK
1552 @retval FALSE This interface is not supported.\r
1553\r
1554**/\r
1555BOOLEAN\r
1556EFIAPI\r
b6174e2d 1557DeprecatedCryptoServiceHmacMd5Update (\r
cc1d13c9
MK
1558 IN OUT VOID *HmacMd5Context,\r
1559 IN CONST VOID *Data,\r
1560 IN UINTN DataSize\r
1561 )\r
1562{\r
b6174e2d 1563 return BaseCryptLibServiceDeprecated ("HmacMd5Update"), FALSE;\r
cc1d13c9
MK
1564}\r
1565\r
1566/**\r
b6174e2d
ZG
1567 HMAC MD5 is deprecated and unsupported any longer.\r
1568 Keep the function field for binary compability.\r
cc1d13c9
MK
1569\r
1570 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.\r
1571 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest\r
1572 value (16 bytes).\r
1573\r
cc1d13c9
MK
1574 @retval FALSE This interface is not supported.\r
1575\r
1576**/\r
1577BOOLEAN\r
1578EFIAPI\r
b6174e2d 1579DeprecatedCryptoServiceHmacMd5Final (\r
cc1d13c9
MK
1580 IN OUT VOID *HmacMd5Context,\r
1581 OUT UINT8 *HmacValue\r
1582 )\r
1583{\r
b6174e2d 1584 return BaseCryptLibServiceDeprecated ("HmacMd5Final"), FALSE;\r
cc1d13c9
MK
1585}\r
1586\r
1587/**\r
c812d320
ZG
1588 HMAC SHA1 is deprecated and unsupported any longer.\r
1589 Keep the function field for binary compability.\r
cc1d13c9 1590\r
cc1d13c9
MK
1591 @return NULL This interface is not supported.\r
1592\r
1593**/\r
1594VOID *\r
1595EFIAPI\r
c812d320 1596DeprecatedCryptoServiceHmacSha1New (\r
cc1d13c9
MK
1597 VOID\r
1598 )\r
1599{\r
c812d320 1600 return BaseCryptLibServiceDeprecated ("HmacSha1New"), NULL;\r
cc1d13c9
MK
1601}\r
1602\r
1603/**\r
c812d320
ZG
1604 HMAC SHA1 is deprecated and unsupported any longer.\r
1605 Keep the function field for binary compability.\r
cc1d13c9
MK
1606\r
1607 @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released.\r
1608\r
1609**/\r
1610VOID\r
1611EFIAPI\r
c812d320 1612DeprecatedCryptoServiceHmacSha1Free (\r
cc1d13c9
MK
1613 IN VOID *HmacSha1Ctx\r
1614 )\r
1615{\r
c812d320 1616 BaseCryptLibServiceDeprecated ("HmacSha1Free");\r
cc1d13c9
MK
1617}\r
1618\r
1619/**\r
c812d320
ZG
1620 HMAC SHA1 is deprecated and unsupported any longer.\r
1621 Keep the function field for binary compability.\r
cc1d13c9
MK
1622\r
1623 @param[out] HmacSha1Context Pointer to HMAC-SHA1 context.\r
1624 @param[in] Key Pointer to the user-supplied key.\r
1625 @param[in] KeySize Key size in bytes.\r
1626\r
cc1d13c9
MK
1627 @retval FALSE This interface is not supported.\r
1628\r
1629**/\r
1630BOOLEAN\r
1631EFIAPI\r
c812d320 1632DeprecatedCryptoServiceHmacSha1SetKey (\r
cc1d13c9
MK
1633 OUT VOID *HmacSha1Context,\r
1634 IN CONST UINT8 *Key,\r
1635 IN UINTN KeySize\r
1636 )\r
1637{\r
c812d320 1638 return BaseCryptLibServiceDeprecated ("HmacSha1SetKey"), FALSE;\r
cc1d13c9
MK
1639}\r
1640\r
1641/**\r
c812d320
ZG
1642 HMAC SHA1 is deprecated and unsupported any longer.\r
1643 Keep the function field for binary compability.\r
cc1d13c9
MK
1644\r
1645 @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.\r
1646 @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.\r
1647\r
cc1d13c9
MK
1648 @retval FALSE This interface is not supported.\r
1649\r
1650**/\r
1651BOOLEAN\r
1652EFIAPI\r
c812d320 1653DeprecatedCryptoServiceHmacSha1Duplicate (\r
cc1d13c9
MK
1654 IN CONST VOID *HmacSha1Context,\r
1655 OUT VOID *NewHmacSha1Context\r
1656 )\r
1657{\r
c812d320 1658 return BaseCryptLibServiceDeprecated ("HmacSha1Duplicate"), FALSE;\r
cc1d13c9
MK
1659}\r
1660\r
1661/**\r
c812d320
ZG
1662 HMAC SHA1 is deprecated and unsupported any longer.\r
1663 Keep the function field for binary compability.\r
cc1d13c9
MK
1664\r
1665 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.\r
1666 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1667 @param[in] DataSize Size of Data buffer in bytes.\r
1668\r
cc1d13c9
MK
1669 @retval FALSE This interface is not supported.\r
1670\r
1671**/\r
1672BOOLEAN\r
1673EFIAPI\r
c812d320 1674DeprecatedCryptoServiceHmacSha1Update (\r
cc1d13c9
MK
1675 IN OUT VOID *HmacSha1Context,\r
1676 IN CONST VOID *Data,\r
1677 IN UINTN DataSize\r
1678 )\r
1679{\r
c812d320 1680 return BaseCryptLibServiceDeprecated ("HmacSha1Update"), FALSE;\r
cc1d13c9
MK
1681}\r
1682\r
1683/**\r
c812d320
ZG
1684 HMAC SHA1 is deprecated and unsupported any longer.\r
1685 Keep the function field for binary compability.\r
cc1d13c9
MK
1686\r
1687 @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.\r
1688 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest\r
1689 value (20 bytes).\r
1690\r
cc1d13c9
MK
1691 @retval FALSE This interface is not supported.\r
1692\r
1693**/\r
1694BOOLEAN\r
1695EFIAPI\r
c812d320 1696DeprecatedCryptoServiceHmacSha1Final (\r
cc1d13c9
MK
1697 IN OUT VOID *HmacSha1Context,\r
1698 OUT UINT8 *HmacValue\r
1699 )\r
1700{\r
c812d320 1701 return BaseCryptLibServiceDeprecated ("HmacSha1Final"), FALSE;\r
cc1d13c9
MK
1702}\r
1703\r
1704/**\r
1705 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use.\r
1706\r
1707 @return Pointer to the HMAC_CTX context that has been initialized.\r
1708 If the allocations fails, HmacSha256New() returns NULL.\r
1709\r
1710**/\r
1711VOID *\r
1712EFIAPI\r
1713CryptoServiceHmacSha256New (\r
1714 VOID\r
1715 )\r
1716{\r
1717 return CALL_BASECRYPTLIB (HmacSha256.Services.New, HmacSha256New, (), NULL);\r
1718}\r
1719\r
1720/**\r
1721 Release the specified HMAC_CTX context.\r
1722\r
1723 @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released.\r
1724\r
1725**/\r
1726VOID\r
1727EFIAPI\r
1728CryptoServiceHmacSha256Free (\r
1729 IN VOID *HmacSha256Ctx\r
1730 )\r
1731{\r
1732 CALL_VOID_BASECRYPTLIB (HmacSha256.Services.Free, HmacSha256Free, (HmacSha256Ctx));\r
1733}\r
1734\r
1735/**\r
1736 Set user-supplied key for subsequent use. It must be done before any\r
1737 calling to HmacSha256Update().\r
1738\r
1739 If HmacSha256Context is NULL, then return FALSE.\r
1740 If this interface is not supported, then return FALSE.\r
1741\r
1742 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context.\r
1743 @param[in] Key Pointer to the user-supplied key.\r
1744 @param[in] KeySize Key size in bytes.\r
1745\r
1746 @retval TRUE The Key is set successfully.\r
1747 @retval FALSE The Key is set unsuccessfully.\r
1748 @retval FALSE This interface is not supported.\r
1749\r
1750**/\r
1751BOOLEAN\r
1752EFIAPI\r
1753CryptoServiceHmacSha256SetKey (\r
1754 OUT VOID *HmacSha256Context,\r
1755 IN CONST UINT8 *Key,\r
1756 IN UINTN KeySize\r
1757 )\r
1758{\r
1759 return CALL_BASECRYPTLIB (HmacSha256.Services.SetKey, HmacSha256SetKey, (HmacSha256Context, Key, KeySize), FALSE);\r
1760}\r
1761\r
1762/**\r
1763 Makes a copy of an existing HMAC-SHA256 context.\r
1764\r
1765 If HmacSha256Context is NULL, then return FALSE.\r
1766 If NewHmacSha256Context is NULL, then return FALSE.\r
1767 If this interface is not supported, then return FALSE.\r
1768\r
1769 @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied.\r
1770 @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context.\r
1771\r
1772 @retval TRUE HMAC-SHA256 context copy succeeded.\r
1773 @retval FALSE HMAC-SHA256 context copy failed.\r
1774 @retval FALSE This interface is not supported.\r
1775\r
1776**/\r
1777BOOLEAN\r
1778EFIAPI\r
1779CryptoServiceHmacSha256Duplicate (\r
1780 IN CONST VOID *HmacSha256Context,\r
1781 OUT VOID *NewHmacSha256Context\r
1782 )\r
1783{\r
1784 return CALL_BASECRYPTLIB (HmacSha256.Services.Duplicate, HmacSha256Duplicate, (HmacSha256Context, NewHmacSha256Context), FALSE);\r
1785}\r
1786\r
1787/**\r
1788 Digests the input data and updates HMAC-SHA256 context.\r
1789\r
1790 This function performs HMAC-SHA256 digest on a data buffer of the specified size.\r
1791 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1792 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1793 by HmacSha256Final(). Behavior with invalid context is undefined.\r
1794\r
1795 If HmacSha256Context is NULL, then return FALSE.\r
1796 If this interface is not supported, then return FALSE.\r
1797\r
1798 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
1799 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1800 @param[in] DataSize Size of Data buffer in bytes.\r
1801\r
1802 @retval TRUE HMAC-SHA256 data digest succeeded.\r
1803 @retval FALSE HMAC-SHA256 data digest failed.\r
1804 @retval FALSE This interface is not supported.\r
1805\r
1806**/\r
1807BOOLEAN\r
1808EFIAPI\r
1809CryptoServiceHmacSha256Update (\r
1810 IN OUT VOID *HmacSha256Context,\r
1811 IN CONST VOID *Data,\r
1812 IN UINTN DataSize\r
1813 )\r
1814{\r
1815 return CALL_BASECRYPTLIB (HmacSha256.Services.Update, HmacSha256Update, (HmacSha256Context, Data, DataSize), FALSE);\r
1816}\r
1817\r
1818/**\r
1819 Completes computation of the HMAC-SHA256 digest value.\r
1820\r
1821 This function completes HMAC-SHA256 hash computation and retrieves the digest value into\r
1822 the specified memory. After this function has been called, the HMAC-SHA256 context cannot\r
1823 be used again.\r
1824 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized\r
1825 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.\r
1826\r
1827 If HmacSha256Context is NULL, then return FALSE.\r
1828 If HmacValue is NULL, then return FALSE.\r
1829 If this interface is not supported, then return FALSE.\r
1830\r
1831 @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context.\r
1832 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
1833 value (32 bytes).\r
1834\r
1835 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1836 @retval FALSE HMAC-SHA256 digest computation failed.\r
1837 @retval FALSE This interface is not supported.\r
1838\r
1839**/\r
1840BOOLEAN\r
1841EFIAPI\r
1842CryptoServiceHmacSha256Final (\r
1843 IN OUT VOID *HmacSha256Context,\r
1844 OUT UINT8 *HmacValue\r
1845 )\r
1846{\r
1847 return CALL_BASECRYPTLIB (HmacSha256.Services.Final, HmacSha256Final, (HmacSha256Context, HmacValue), FALSE);\r
1848}\r
1849\r
3f77ccb9
QZ
1850/**\r
1851 Computes the HMAC-SHA256 digest of a input data buffer.\r
1852\r
1853 This function performs the HMAC-SHA256 digest of a given data buffer, and places\r
1854 the digest value into the specified memory.\r
1855\r
1856 If this interface is not supported, then return FALSE.\r
1857\r
1858 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1859 @param[in] DataSize Size of Data buffer in bytes.\r
1860 @param[in] Key Pointer to the user-supplied key.\r
1861 @param[in] KeySize Key size in bytes.\r
1862 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest\r
1863 value (32 bytes).\r
1864\r
1865 @retval TRUE HMAC-SHA256 digest computation succeeded.\r
1866 @retval FALSE HMAC-SHA256 digest computation failed.\r
1867 @retval FALSE This interface is not supported.\r
1868\r
1869**/\r
1870BOOLEAN\r
1871EFIAPI\r
1872CryptoServiceHmacSha256All (\r
1873 IN CONST VOID *Data,\r
1874 IN UINTN DataSize,\r
1875 IN CONST UINT8 *Key,\r
1876 IN UINTN KeySize,\r
1877 OUT UINT8 *HmacValue\r
1878 )\r
1879{\r
1880 return CALL_BASECRYPTLIB (HmacSha256.Services.All, HmacSha256All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);\r
1881}\r
1882\r
1883/**\r
1884 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA384 use.\r
1885\r
1886 @return Pointer to the HMAC_CTX context that has been initialized.\r
1887 If the allocations fails, HmacSha384New() returns NULL.\r
1888\r
1889**/\r
1890VOID *\r
1891EFIAPI\r
1892CryptoServiceHmacSha384New (\r
1893 VOID\r
1894 )\r
1895{\r
1896 return CALL_BASECRYPTLIB (HmacSha384.Services.New, HmacSha384New, (), NULL);\r
1897}\r
1898\r
1899/**\r
1900 Release the specified HMAC_CTX context.\r
1901\r
1902 @param[in] HmacSha384Ctx Pointer to the HMAC_CTX context to be released.\r
1903\r
1904**/\r
1905VOID\r
1906EFIAPI\r
1907CryptoServiceHmacSha384Free (\r
1908 IN VOID *HmacSha384Ctx\r
1909 )\r
1910{\r
1911 CALL_VOID_BASECRYPTLIB (HmacSha384.Services.Free, HmacSha384Free, (HmacSha384Ctx));\r
1912}\r
1913\r
1914/**\r
1915 Set user-supplied key for subsequent use. It must be done before any\r
1916 calling to HmacSha384Update().\r
1917\r
1918 If HmacSha384Context is NULL, then return FALSE.\r
1919 If this interface is not supported, then return FALSE.\r
1920\r
1921 @param[out] HmacSha384Context Pointer to HMAC-SHA384 context.\r
1922 @param[in] Key Pointer to the user-supplied key.\r
1923 @param[in] KeySize Key size in bytes.\r
1924\r
1925 @retval TRUE The Key is set successfully.\r
1926 @retval FALSE The Key is set unsuccessfully.\r
1927 @retval FALSE This interface is not supported.\r
1928\r
1929**/\r
1930BOOLEAN\r
1931EFIAPI\r
1932CryptoServiceHmacSha384SetKey (\r
1933 OUT VOID *HmacSha384Context,\r
1934 IN CONST UINT8 *Key,\r
1935 IN UINTN KeySize\r
1936 )\r
1937{\r
1938 return CALL_BASECRYPTLIB (HmacSha384.Services.SetKey, HmacSha384SetKey, (HmacSha384Context, Key, KeySize), FALSE);\r
1939}\r
1940\r
1941/**\r
1942 Makes a copy of an existing HMAC-SHA384 context.\r
1943\r
1944 If HmacSha384Context is NULL, then return FALSE.\r
1945 If NewHmacSha384Context is NULL, then return FALSE.\r
1946 If this interface is not supported, then return FALSE.\r
1947\r
1948 @param[in] HmacSha384Context Pointer to HMAC-SHA384 context being copied.\r
1949 @param[out] NewHmacSha384Context Pointer to new HMAC-SHA384 context.\r
1950\r
1951 @retval TRUE HMAC-SHA384 context copy succeeded.\r
1952 @retval FALSE HMAC-SHA384 context copy failed.\r
1953 @retval FALSE This interface is not supported.\r
1954\r
1955**/\r
1956BOOLEAN\r
1957EFIAPI\r
1958CryptoServiceHmacSha384Duplicate (\r
1959 IN CONST VOID *HmacSha384Context,\r
1960 OUT VOID *NewHmacSha384Context\r
1961 )\r
1962{\r
1963 return CALL_BASECRYPTLIB (HmacSha384.Services.Duplicate, HmacSha256Duplicate, (HmacSha384Context, NewHmacSha384Context), FALSE);\r
1964}\r
1965\r
1966/**\r
1967 Digests the input data and updates HMAC-SHA384 context.\r
1968\r
1969 This function performs HMAC-SHA384 digest on a data buffer of the specified size.\r
1970 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
1971 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
1972 by HmacSha384Final(). Behavior with invalid context is undefined.\r
1973\r
1974 If HmacSha384Context is NULL, then return FALSE.\r
1975 If this interface is not supported, then return FALSE.\r
1976\r
1977 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.\r
1978 @param[in] Data Pointer to the buffer containing the data to be digested.\r
1979 @param[in] DataSize Size of Data buffer in bytes.\r
1980\r
1981 @retval TRUE HMAC-SHA384 data digest succeeded.\r
1982 @retval FALSE HMAC-SHA384 data digest failed.\r
1983 @retval FALSE This interface is not supported.\r
1984\r
1985**/\r
1986BOOLEAN\r
1987EFIAPI\r
1988CryptoServiceHmacSha384Update (\r
1989 IN OUT VOID *HmacSha384Context,\r
1990 IN CONST VOID *Data,\r
1991 IN UINTN DataSize\r
1992 )\r
1993{\r
1994 return CALL_BASECRYPTLIB (HmacSha384.Services.Update, HmacSha384Update, (HmacSha384Context, Data, DataSize), FALSE);\r
1995}\r
1996\r
1997/**\r
1998 Completes computation of the HMAC-SHA384 digest value.\r
1999\r
2000 This function completes HMAC-SHA384 hash computation and retrieves the digest value into\r
2001 the specified memory. After this function has been called, the HMAC-SHA384 context cannot\r
2002 be used again.\r
2003 HMAC-SHA384 context should be initialized by HmacSha384New(), and should not be finalized\r
2004 by HmacSha384Final(). Behavior with invalid HMAC-SHA384 context is undefined.\r
2005\r
2006 If HmacSha384Context is NULL, then return FALSE.\r
2007 If HmacValue is NULL, then return FALSE.\r
2008 If this interface is not supported, then return FALSE.\r
2009\r
2010 @param[in, out] HmacSha384Context Pointer to the HMAC-SHA384 context.\r
2011 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest\r
2012 value (48 bytes).\r
2013\r
2014 @retval TRUE HMAC-SHA384 digest computation succeeded.\r
2015 @retval FALSE HMAC-SHA384 digest computation failed.\r
2016 @retval FALSE This interface is not supported.\r
2017\r
2018**/\r
2019BOOLEAN\r
2020EFIAPI\r
2021CryptoServiceHmacSha384Final (\r
2022 IN OUT VOID *HmacSha384Context,\r
2023 OUT UINT8 *HmacValue\r
2024 )\r
2025{\r
2026 return CALL_BASECRYPTLIB (HmacSha384.Services.Final, HmacSha384Final, (HmacSha384Context, HmacValue), FALSE);\r
2027}\r
2028\r
2029/**\r
2030 Computes the HMAC-SHA384 digest of a input data buffer.\r
2031\r
2032 This function performs the HMAC-SHA384 digest of a given data buffer, and places\r
2033 the digest value into the specified memory.\r
2034\r
2035 If this interface is not supported, then return FALSE.\r
2036\r
2037 @param[in] Data Pointer to the buffer containing the data to be digested.\r
2038 @param[in] DataSize Size of Data buffer in bytes.\r
2039 @param[in] Key Pointer to the user-supplied key.\r
2040 @param[in] KeySize Key size in bytes.\r
2041 @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA384 digest\r
2042 value (48 bytes).\r
2043\r
2044 @retval TRUE HMAC-SHA384 digest computation succeeded.\r
2045 @retval FALSE HMAC-SHA384 digest computation failed.\r
2046 @retval FALSE This interface is not supported.\r
2047\r
2048**/\r
2049BOOLEAN\r
2050EFIAPI\r
2051CryptoServiceHmacSha384All (\r
2052 IN CONST VOID *Data,\r
2053 IN UINTN DataSize,\r
2054 IN CONST UINT8 *Key,\r
2055 IN UINTN KeySize,\r
2056 OUT UINT8 *HmacValue\r
2057 )\r
2058{\r
2059 return CALL_BASECRYPTLIB (HmacSha384.Services.All, HmacSha384All, (Data, DataSize, Key, KeySize, HmacValue), FALSE);\r
2060}\r
2061\r
7c342378 2062// =====================================================================================\r
cc1d13c9 2063// Symmetric Cryptography Primitive\r
7c342378 2064// =====================================================================================\r
cc1d13c9
MK
2065\r
2066/**\r
b8af2c9e
ZG
2067 TDES is deprecated and unsupported any longer.\r
2068 Keep the function field for binary compability.\r
cc1d13c9 2069\r
cc1d13c9
MK
2070 @retval 0 This interface is not supported.\r
2071\r
2072**/\r
2073UINTN\r
2074EFIAPI\r
b8af2c9e 2075DeprecatedCryptoServiceTdesGetContextSize (\r
cc1d13c9
MK
2076 VOID\r
2077 )\r
2078{\r
b8af2c9e 2079 return BaseCryptLibServiceDeprecated ("TdesGetContextSize"), 0;\r
cc1d13c9
MK
2080}\r
2081\r
2082/**\r
b8af2c9e
ZG
2083 TDES is deprecated and unsupported any longer.\r
2084 Keep the function field for binary compability.\r
cc1d13c9
MK
2085\r
2086 @param[out] TdesContext Pointer to TDES context being initialized.\r
2087 @param[in] Key Pointer to the user-supplied TDES key.\r
2088 @param[in] KeyLength Length of TDES key in bits.\r
2089\r
cc1d13c9
MK
2090 @retval FALSE This interface is not supported.\r
2091\r
2092**/\r
2093BOOLEAN\r
2094EFIAPI\r
b8af2c9e 2095DeprecatedCryptoServiceTdesInit (\r
cc1d13c9
MK
2096 OUT VOID *TdesContext,\r
2097 IN CONST UINT8 *Key,\r
2098 IN UINTN KeyLength\r
2099 )\r
2100{\r
b8af2c9e 2101 return BaseCryptLibServiceDeprecated ("TdesInit"), FALSE;\r
cc1d13c9
MK
2102}\r
2103\r
2104/**\r
b8af2c9e
ZG
2105 TDES is deprecated and unsupported any longer.\r
2106 Keep the function field for binary compability.\r
cc1d13c9
MK
2107\r
2108 @param[in] TdesContext Pointer to the TDES context.\r
2109 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
2110 @param[in] InputSize Size of the Input buffer in bytes.\r
2111 @param[out] Output Pointer to a buffer that receives the TDES encryption output.\r
2112\r
cc1d13c9
MK
2113 @retval FALSE This interface is not supported.\r
2114\r
2115**/\r
2116BOOLEAN\r
2117EFIAPI\r
b8af2c9e 2118DeprecatedCryptoServiceTdesEcbEncrypt (\r
cc1d13c9
MK
2119 IN VOID *TdesContext,\r
2120 IN CONST UINT8 *Input,\r
2121 IN UINTN InputSize,\r
2122 OUT UINT8 *Output\r
2123 )\r
2124{\r
b8af2c9e 2125 return BaseCryptLibServiceDeprecated ("TdesEcbEncrypt"), FALSE;\r
cc1d13c9
MK
2126}\r
2127\r
2128/**\r
b8af2c9e
ZG
2129 TDES is deprecated and unsupported any longer.\r
2130 Keep the function field for binary compability.\r
cc1d13c9
MK
2131\r
2132 @param[in] TdesContext Pointer to the TDES context.\r
2133 @param[in] Input Pointer to the buffer containing the data to be decrypted.\r
2134 @param[in] InputSize Size of the Input buffer in bytes.\r
2135 @param[out] Output Pointer to a buffer that receives the TDES decryption output.\r
2136\r
cc1d13c9
MK
2137 @retval FALSE This interface is not supported.\r
2138\r
2139**/\r
2140BOOLEAN\r
2141EFIAPI\r
b8af2c9e 2142DeprecatedCryptoServiceTdesEcbDecrypt (\r
cc1d13c9
MK
2143 IN VOID *TdesContext,\r
2144 IN CONST UINT8 *Input,\r
2145 IN UINTN InputSize,\r
2146 OUT UINT8 *Output\r
2147 )\r
2148{\r
b8af2c9e 2149 return BaseCryptLibServiceDeprecated ("TdesEcbDecrypt"), FALSE;\r
cc1d13c9
MK
2150}\r
2151\r
2152/**\r
b8af2c9e
ZG
2153 TDES is deprecated and unsupported any longer.\r
2154 Keep the function field for binary compability.\r
cc1d13c9
MK
2155\r
2156 @param[in] TdesContext Pointer to the TDES context.\r
2157 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
2158 @param[in] InputSize Size of the Input buffer in bytes.\r
2159 @param[in] Ivec Pointer to initialization vector.\r
2160 @param[out] Output Pointer to a buffer that receives the TDES encryption output.\r
2161\r
cc1d13c9
MK
2162 @retval FALSE This interface is not supported.\r
2163\r
2164**/\r
2165BOOLEAN\r
2166EFIAPI\r
b8af2c9e 2167DeprecatedCryptoServiceTdesCbcEncrypt (\r
cc1d13c9
MK
2168 IN VOID *TdesContext,\r
2169 IN CONST UINT8 *Input,\r
2170 IN UINTN InputSize,\r
2171 IN CONST UINT8 *Ivec,\r
2172 OUT UINT8 *Output\r
2173 )\r
2174{\r
b8af2c9e 2175 return BaseCryptLibServiceDeprecated ("TdesCbcEncrypt"), FALSE;\r
cc1d13c9
MK
2176}\r
2177\r
2178/**\r
b8af2c9e
ZG
2179 TDES is deprecated and unsupported any longer.\r
2180 Keep the function field for binary compability.\r
cc1d13c9
MK
2181\r
2182 @param[in] TdesContext Pointer to the TDES context.\r
2183 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
2184 @param[in] InputSize Size of the Input buffer in bytes.\r
2185 @param[in] Ivec Pointer to initialization vector.\r
2186 @param[out] Output Pointer to a buffer that receives the TDES encryption output.\r
2187\r
cc1d13c9
MK
2188 @retval FALSE This interface is not supported.\r
2189\r
2190**/\r
2191BOOLEAN\r
2192EFIAPI\r
b8af2c9e 2193DeprecatedCryptoServiceTdesCbcDecrypt (\r
cc1d13c9
MK
2194 IN VOID *TdesContext,\r
2195 IN CONST UINT8 *Input,\r
2196 IN UINTN InputSize,\r
2197 IN CONST UINT8 *Ivec,\r
2198 OUT UINT8 *Output\r
2199 )\r
2200{\r
b8af2c9e 2201 return BaseCryptLibServiceDeprecated ("TdesCbcDecrypt"), FALSE;\r
cc1d13c9
MK
2202}\r
2203\r
2204/**\r
2205 Retrieves the size, in bytes, of the context buffer required for AES operations.\r
2206\r
2207 If this interface is not supported, then return zero.\r
2208\r
2209 @return The size, in bytes, of the context buffer required for AES operations.\r
2210 @retval 0 This interface is not supported.\r
2211\r
2212**/\r
2213UINTN\r
2214EFIAPI\r
2215CryptoServiceAesGetContextSize (\r
2216 VOID\r
2217 )\r
2218{\r
2219 return CALL_BASECRYPTLIB (Aes.Services.GetContextSize, AesGetContextSize, (), 0);\r
2220}\r
2221\r
2222/**\r
2223 Initializes user-supplied memory as AES context for subsequent use.\r
2224\r
2225 This function initializes user-supplied memory pointed by AesContext as AES context.\r
2226 In addition, it sets up all AES key materials for subsequent encryption and decryption\r
2227 operations.\r
2228 There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r
2229\r
2230 If AesContext is NULL, then return FALSE.\r
2231 If Key is NULL, then return FALSE.\r
2232 If KeyLength is not valid, then return FALSE.\r
2233 If this interface is not supported, then return FALSE.\r
2234\r
2235 @param[out] AesContext Pointer to AES context being initialized.\r
2236 @param[in] Key Pointer to the user-supplied AES key.\r
2237 @param[in] KeyLength Length of AES key in bits.\r
2238\r
2239 @retval TRUE AES context initialization succeeded.\r
2240 @retval FALSE AES context initialization failed.\r
2241 @retval FALSE This interface is not supported.\r
2242\r
2243**/\r
2244BOOLEAN\r
2245EFIAPI\r
2246CryptoServiceAesInit (\r
2247 OUT VOID *AesContext,\r
2248 IN CONST UINT8 *Key,\r
2249 IN UINTN KeyLength\r
2250 )\r
2251{\r
2252 return CALL_BASECRYPTLIB (Aes.Services.Init, AesInit, (AesContext, Key, KeyLength), FALSE);\r
2253}\r
2254\r
2255/**\r
80e28dce
ZG
2256 AES ECB Mode is deprecated and unsupported any longer.\r
2257 Keep the function field for binary compability.\r
cc1d13c9
MK
2258\r
2259 @param[in] AesContext Pointer to the AES context.\r
2260 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
2261 @param[in] InputSize Size of the Input buffer in bytes.\r
2262 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
2263\r
cc1d13c9
MK
2264 @retval FALSE This interface is not supported.\r
2265\r
2266**/\r
2267BOOLEAN\r
2268EFIAPI\r
80e28dce 2269DeprecatedCryptoServiceAesEcbEncrypt (\r
cc1d13c9
MK
2270 IN VOID *AesContext,\r
2271 IN CONST UINT8 *Input,\r
2272 IN UINTN InputSize,\r
2273 OUT UINT8 *Output\r
2274 )\r
2275{\r
80e28dce 2276 return BaseCryptLibServiceDeprecated ("AesEcbEncrypt"), FALSE;\r
cc1d13c9
MK
2277}\r
2278\r
2279/**\r
80e28dce
ZG
2280 AES ECB Mode is deprecated and unsupported any longer.\r
2281 Keep the function field for binary compability.\r
cc1d13c9
MK
2282\r
2283 @param[in] AesContext Pointer to the AES context.\r
2284 @param[in] Input Pointer to the buffer containing the data to be decrypted.\r
2285 @param[in] InputSize Size of the Input buffer in bytes.\r
2286 @param[out] Output Pointer to a buffer that receives the AES decryption output.\r
2287\r
cc1d13c9
MK
2288 @retval FALSE This interface is not supported.\r
2289\r
2290**/\r
2291BOOLEAN\r
2292EFIAPI\r
80e28dce 2293DeprecatedCryptoServiceAesEcbDecrypt (\r
cc1d13c9
MK
2294 IN VOID *AesContext,\r
2295 IN CONST UINT8 *Input,\r
2296 IN UINTN InputSize,\r
2297 OUT UINT8 *Output\r
2298 )\r
2299{\r
80e28dce 2300 return BaseCryptLibServiceDeprecated ("AesEcbDecrypt"), FALSE;\r
cc1d13c9
MK
2301}\r
2302\r
2303/**\r
2304 Performs AES encryption on a data buffer of the specified size in CBC mode.\r
2305\r
2306 This function performs AES encryption on data buffer pointed by Input, of specified\r
2307 size of InputSize, in CBC mode.\r
2308 InputSize must be multiple of block size (16 bytes). This function does not perform\r
2309 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
2310 Initialization vector should be one block size (16 bytes).\r
2311 AesContext should be already correctly initialized by AesInit(). Behavior with\r
2312 invalid AES context is undefined.\r
2313\r
2314 If AesContext is NULL, then return FALSE.\r
2315 If Input is NULL, then return FALSE.\r
2316 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
2317 If Ivec is NULL, then return FALSE.\r
2318 If Output is NULL, then return FALSE.\r
2319 If this interface is not supported, then return FALSE.\r
2320\r
2321 @param[in] AesContext Pointer to the AES context.\r
2322 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
2323 @param[in] InputSize Size of the Input buffer in bytes.\r
2324 @param[in] Ivec Pointer to initialization vector.\r
2325 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
2326\r
2327 @retval TRUE AES encryption succeeded.\r
2328 @retval FALSE AES encryption failed.\r
2329 @retval FALSE This interface is not supported.\r
2330\r
2331**/\r
2332BOOLEAN\r
2333EFIAPI\r
2334CryptoServiceAesCbcEncrypt (\r
2335 IN VOID *AesContext,\r
2336 IN CONST UINT8 *Input,\r
2337 IN UINTN InputSize,\r
2338 IN CONST UINT8 *Ivec,\r
2339 OUT UINT8 *Output\r
2340 )\r
2341{\r
2342 return CALL_BASECRYPTLIB (Aes.Services.CbcEncrypt, AesCbcEncrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);\r
2343}\r
2344\r
2345/**\r
2346 Performs AES decryption on a data buffer of the specified size in CBC mode.\r
2347\r
2348 This function performs AES decryption on data buffer pointed by Input, of specified\r
2349 size of InputSize, in CBC mode.\r
2350 InputSize must be multiple of block size (16 bytes). This function does not perform\r
2351 padding. Caller must perform padding, if necessary, to ensure valid input data size.\r
2352 Initialization vector should be one block size (16 bytes).\r
2353 AesContext should be already correctly initialized by AesInit(). Behavior with\r
2354 invalid AES context is undefined.\r
2355\r
2356 If AesContext is NULL, then return FALSE.\r
2357 If Input is NULL, then return FALSE.\r
2358 If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
2359 If Ivec is NULL, then return FALSE.\r
2360 If Output is NULL, then return FALSE.\r
2361 If this interface is not supported, then return FALSE.\r
2362\r
2363 @param[in] AesContext Pointer to the AES context.\r
2364 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
2365 @param[in] InputSize Size of the Input buffer in bytes.\r
2366 @param[in] Ivec Pointer to initialization vector.\r
2367 @param[out] Output Pointer to a buffer that receives the AES encryption output.\r
2368\r
2369 @retval TRUE AES decryption succeeded.\r
2370 @retval FALSE AES decryption failed.\r
2371 @retval FALSE This interface is not supported.\r
2372\r
2373**/\r
2374BOOLEAN\r
2375EFIAPI\r
2376CryptoServiceAesCbcDecrypt (\r
2377 IN VOID *AesContext,\r
2378 IN CONST UINT8 *Input,\r
2379 IN UINTN InputSize,\r
2380 IN CONST UINT8 *Ivec,\r
2381 OUT UINT8 *Output\r
2382 )\r
2383{\r
2384 return CALL_BASECRYPTLIB (Aes.Services.CbcDecrypt, AesCbcDecrypt, (AesContext, Input, InputSize, Ivec, Output), FALSE);\r
2385}\r
2386\r
2387/**\r
c22a32e1
ZG
2388 ARC4 is deprecated and unsupported any longer.\r
2389 Keep the function field for binary compability.\r
cc1d13c9 2390\r
cc1d13c9
MK
2391 @retval 0 This interface is not supported.\r
2392\r
2393**/\r
2394UINTN\r
2395EFIAPI\r
c22a32e1 2396DeprecatedCryptoServiceArc4GetContextSize (\r
cc1d13c9
MK
2397 VOID\r
2398 )\r
2399{\r
c22a32e1 2400 return BaseCryptLibServiceDeprecated ("Arc4GetContextSize"), 0;\r
cc1d13c9
MK
2401}\r
2402\r
2403/**\r
c22a32e1
ZG
2404 ARC4 is deprecated and unsupported any longer.\r
2405 Keep the function field for binary compability.\r
cc1d13c9
MK
2406\r
2407 @param[out] Arc4Context Pointer to ARC4 context being initialized.\r
2408 @param[in] Key Pointer to the user-supplied ARC4 key.\r
2409 @param[in] KeySize Size of ARC4 key in bytes.\r
2410\r
cc1d13c9
MK
2411 @retval FALSE This interface is not supported.\r
2412\r
2413**/\r
2414BOOLEAN\r
2415EFIAPI\r
c22a32e1 2416DeprecatedCryptoServiceArc4Init (\r
cc1d13c9
MK
2417 OUT VOID *Arc4Context,\r
2418 IN CONST UINT8 *Key,\r
2419 IN UINTN KeySize\r
2420 )\r
2421{\r
c22a32e1 2422 return BaseCryptLibServiceDeprecated ("Arc4Init"), FALSE;\r
cc1d13c9
MK
2423}\r
2424\r
2425/**\r
c22a32e1
ZG
2426 ARC4 is deprecated and unsupported any longer.\r
2427 Keep the function field for binary compability.\r
cc1d13c9
MK
2428\r
2429 @param[in, out] Arc4Context Pointer to the ARC4 context.\r
2430 @param[in] Input Pointer to the buffer containing the data to be encrypted.\r
2431 @param[in] InputSize Size of the Input buffer in bytes.\r
2432 @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.\r
2433\r
cc1d13c9
MK
2434 @retval FALSE This interface is not supported.\r
2435\r
2436**/\r
2437BOOLEAN\r
2438EFIAPI\r
c22a32e1 2439DeprecatedCryptoServiceArc4Encrypt (\r
cc1d13c9
MK
2440 IN OUT VOID *Arc4Context,\r
2441 IN CONST UINT8 *Input,\r
2442 IN UINTN InputSize,\r
2443 OUT UINT8 *Output\r
2444 )\r
2445{\r
c22a32e1 2446 return BaseCryptLibServiceDeprecated ("Arc4Encrypt"), FALSE;\r
cc1d13c9
MK
2447}\r
2448\r
2449/**\r
c22a32e1
ZG
2450 ARC4 is deprecated and unsupported any longer.\r
2451 Keep the function field for binary compability.\r
cc1d13c9
MK
2452\r
2453 @param[in, out] Arc4Context Pointer to the ARC4 context.\r
2454 @param[in] Input Pointer to the buffer containing the data to be decrypted.\r
2455 @param[in] InputSize Size of the Input buffer in bytes.\r
2456 @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.\r
2457\r
cc1d13c9
MK
2458 @retval FALSE This interface is not supported.\r
2459\r
2460**/\r
2461BOOLEAN\r
2462EFIAPI\r
c22a32e1 2463DeprecatedCryptoServiceArc4Decrypt (\r
cc1d13c9
MK
2464 IN OUT VOID *Arc4Context,\r
2465 IN UINT8 *Input,\r
2466 IN UINTN InputSize,\r
2467 OUT UINT8 *Output\r
2468 )\r
2469{\r
c22a32e1 2470 return BaseCryptLibServiceDeprecated ("Arc4Decrypt"), FALSE;\r
cc1d13c9
MK
2471}\r
2472\r
2473/**\r
c22a32e1
ZG
2474 ARC4 is deprecated and unsupported any longer.\r
2475 Keep the function field for binary compability.\r
cc1d13c9
MK
2476\r
2477 @param[in, out] Arc4Context Pointer to the ARC4 context.\r
2478\r
cc1d13c9
MK
2479 @retval FALSE This interface is not supported.\r
2480\r
2481**/\r
2482BOOLEAN\r
2483EFIAPI\r
c22a32e1 2484DeprecatedCryptoServiceArc4Reset (\r
cc1d13c9
MK
2485 IN OUT VOID *Arc4Context\r
2486 )\r
2487{\r
c22a32e1 2488 return BaseCryptLibServiceDeprecated ("Arc4Reset"), FALSE;\r
cc1d13c9
MK
2489}\r
2490\r
7c342378 2491// =====================================================================================\r
cc1d13c9 2492// Asymmetric Cryptography Primitive\r
7c342378 2493// =====================================================================================\r
cc1d13c9
MK
2494\r
2495/**\r
2496 Allocates and initializes one RSA context for subsequent use.\r
2497\r
2498 @return Pointer to the RSA context that has been initialized.\r
2499 If the allocations fails, RsaNew() returns NULL.\r
2500\r
2501**/\r
2502VOID *\r
2503EFIAPI\r
2504CryptoServiceRsaNew (\r
2505 VOID\r
2506 )\r
2507{\r
2508 return CALL_BASECRYPTLIB (Rsa.Services.New, RsaNew, (), NULL);\r
2509}\r
2510\r
2511/**\r
2512 Release the specified RSA context.\r
2513\r
2514 If RsaContext is NULL, then return FALSE.\r
2515\r
2516 @param[in] RsaContext Pointer to the RSA context to be released.\r
2517\r
2518**/\r
2519VOID\r
2520EFIAPI\r
2521CryptoServiceRsaFree (\r
2522 IN VOID *RsaContext\r
2523 )\r
2524{\r
2525 CALL_VOID_BASECRYPTLIB (Rsa.Services.Free, RsaFree, (RsaContext));\r
2526}\r
2527\r
2528/**\r
2529 Sets the tag-designated key component into the established RSA context.\r
2530\r
2531 This function sets the tag-designated RSA key component into the established\r
2532 RSA context from the user-specified non-negative integer (octet string format\r
2533 represented in RSA PKCS#1).\r
2534 If BigNumber is NULL, then the specified key component in RSA context is cleared.\r
2535\r
2536 If RsaContext is NULL, then return FALSE.\r
2537\r
2538 @param[in, out] RsaContext Pointer to RSA context being set.\r
2539 @param[in] KeyTag Tag of RSA key component being set.\r
2540 @param[in] BigNumber Pointer to octet integer buffer.\r
2541 If NULL, then the specified key component in RSA\r
2542 context is cleared.\r
2543 @param[in] BnSize Size of big number buffer in bytes.\r
2544 If BigNumber is NULL, then it is ignored.\r
2545\r
2546 @retval TRUE RSA key component was set successfully.\r
2547 @retval FALSE Invalid RSA key component tag.\r
2548\r
2549**/\r
2550BOOLEAN\r
2551EFIAPI\r
2552CryptoServiceRsaSetKey (\r
2553 IN OUT VOID *RsaContext,\r
2554 IN RSA_KEY_TAG KeyTag,\r
2555 IN CONST UINT8 *BigNumber,\r
2556 IN UINTN BnSize\r
2557 )\r
2558{\r
2559 return CALL_BASECRYPTLIB (Rsa.Services.SetKey, RsaSetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);\r
2560}\r
2561\r
2562/**\r
2563 Gets the tag-designated RSA key component from the established RSA context.\r
2564\r
2565 This function retrieves the tag-designated RSA key component from the\r
2566 established RSA context as a non-negative integer (octet string format\r
2567 represented in RSA PKCS#1).\r
2568 If specified key component has not been set or has been cleared, then returned\r
2569 BnSize is set to 0.\r
2570 If the BigNumber buffer is too small to hold the contents of the key, FALSE\r
2571 is returned and BnSize is set to the required buffer size to obtain the key.\r
2572\r
2573 If RsaContext is NULL, then return FALSE.\r
2574 If BnSize is NULL, then return FALSE.\r
2575 If BnSize is large enough but BigNumber is NULL, then return FALSE.\r
2576 If this interface is not supported, then return FALSE.\r
2577\r
2578 @param[in, out] RsaContext Pointer to RSA context being set.\r
2579 @param[in] KeyTag Tag of RSA key component being set.\r
2580 @param[out] BigNumber Pointer to octet integer buffer.\r
2581 @param[in, out] BnSize On input, the size of big number buffer in bytes.\r
2582 On output, the size of data returned in big number buffer in bytes.\r
2583\r
2584 @retval TRUE RSA key component was retrieved successfully.\r
2585 @retval FALSE Invalid RSA key component tag.\r
2586 @retval FALSE BnSize is too small.\r
2587 @retval FALSE This interface is not supported.\r
2588\r
2589**/\r
2590BOOLEAN\r
2591EFIAPI\r
2592CryptoServiceRsaGetKey (\r
2593 IN OUT VOID *RsaContext,\r
2594 IN RSA_KEY_TAG KeyTag,\r
2595 OUT UINT8 *BigNumber,\r
2596 IN OUT UINTN *BnSize\r
2597 )\r
2598{\r
2599 return CALL_BASECRYPTLIB (Rsa.Services.GetKey, RsaGetKey, (RsaContext, KeyTag, BigNumber, BnSize), FALSE);\r
2600}\r
2601\r
2602/**\r
2603 Generates RSA key components.\r
2604\r
2605 This function generates RSA key components. It takes RSA public exponent E and\r
2606 length in bits of RSA modulus N as input, and generates all key components.\r
2607 If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r
2608\r
2609 Before this function can be invoked, pseudorandom number generator must be correctly\r
2610 initialized by RandomSeed().\r
2611\r
2612 If RsaContext is NULL, then return FALSE.\r
2613 If this interface is not supported, then return FALSE.\r
2614\r
2615 @param[in, out] RsaContext Pointer to RSA context being set.\r
2616 @param[in] ModulusLength Length of RSA modulus N in bits.\r
2617 @param[in] PublicExponent Pointer to RSA public exponent.\r
2618 @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r
2619\r
2620 @retval TRUE RSA key component was generated successfully.\r
2621 @retval FALSE Invalid RSA key component tag.\r
2622 @retval FALSE This interface is not supported.\r
2623\r
2624**/\r
2625BOOLEAN\r
2626EFIAPI\r
2627CryptoServiceRsaGenerateKey (\r
2628 IN OUT VOID *RsaContext,\r
2629 IN UINTN ModulusLength,\r
2630 IN CONST UINT8 *PublicExponent,\r
2631 IN UINTN PublicExponentSize\r
2632 )\r
2633{\r
2634 return CALL_BASECRYPTLIB (Rsa.Services.GenerateKey, RsaGenerateKey, (RsaContext, ModulusLength, PublicExponent, PublicExponentSize), FALSE);\r
2635}\r
2636\r
2637/**\r
2638 Validates key components of RSA context.\r
2639 NOTE: This function performs integrity checks on all the RSA key material, so\r
2640 the RSA key structure must contain all the private key data.\r
2641\r
2642 This function validates key components of RSA context in following aspects:\r
2643 - Whether p is a prime\r
2644 - Whether q is a prime\r
2645 - Whether n = p * q\r
2646 - Whether d*e = 1 mod lcm(p-1,q-1)\r
2647\r
2648 If RsaContext is NULL, then return FALSE.\r
2649 If this interface is not supported, then return FALSE.\r
2650\r
2651 @param[in] RsaContext Pointer to RSA context to check.\r
2652\r
2653 @retval TRUE RSA key components are valid.\r
2654 @retval FALSE RSA key components are not valid.\r
2655 @retval FALSE This interface is not supported.\r
2656\r
2657**/\r
2658BOOLEAN\r
2659EFIAPI\r
2660CryptoServiceRsaCheckKey (\r
2661 IN VOID *RsaContext\r
2662 )\r
2663{\r
2664 return CALL_BASECRYPTLIB (Rsa.Services.CheckKey, RsaCheckKey, (RsaContext), FALSE);\r
2665}\r
2666\r
2667/**\r
2668 Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r
2669\r
2670 This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r
2671 RSA PKCS#1.\r
2672 If the Signature buffer is too small to hold the contents of signature, FALSE\r
2673 is returned and SigSize is set to the required buffer size to obtain the signature.\r
2674\r
2675 If RsaContext is NULL, then return FALSE.\r
2676 If MessageHash is NULL, then return FALSE.\r
2677 If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r
2678 If SigSize is large enough but Signature is NULL, then return FALSE.\r
2679 If this interface is not supported, then return FALSE.\r
2680\r
2681 @param[in] RsaContext Pointer to RSA context for signature generation.\r
2682 @param[in] MessageHash Pointer to octet message hash to be signed.\r
2683 @param[in] HashSize Size of the message hash in bytes.\r
2684 @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r
2685 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
2686 On output, the size of data returned in Signature buffer in bytes.\r
2687\r
2688 @retval TRUE Signature successfully generated in PKCS1-v1_5.\r
2689 @retval FALSE Signature generation failed.\r
2690 @retval FALSE SigSize is too small.\r
2691 @retval FALSE This interface is not supported.\r
2692\r
2693**/\r
2694BOOLEAN\r
2695EFIAPI\r
2696CryptoServiceRsaPkcs1Sign (\r
2697 IN VOID *RsaContext,\r
2698 IN CONST UINT8 *MessageHash,\r
2699 IN UINTN HashSize,\r
2700 OUT UINT8 *Signature,\r
2701 IN OUT UINTN *SigSize\r
2702 )\r
2703{\r
2704 return CALL_BASECRYPTLIB (Rsa.Services.Pkcs1Sign, RsaPkcs1Sign, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);\r
2705}\r
2706\r
2707/**\r
2708 Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r
2709 RSA PKCS#1.\r
2710\r
2711 If RsaContext is NULL, then return FALSE.\r
2712 If MessageHash is NULL, then return FALSE.\r
2713 If Signature is NULL, then return FALSE.\r
2714 If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r
2715\r
2716 @param[in] RsaContext Pointer to RSA context for signature verification.\r
2717 @param[in] MessageHash Pointer to octet message hash to be checked.\r
2718 @param[in] HashSize Size of the message hash in bytes.\r
2719 @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r
2720 @param[in] SigSize Size of signature in bytes.\r
2721\r
2722 @retval TRUE Valid signature encoded in PKCS1-v1_5.\r
2723 @retval FALSE Invalid signature or invalid RSA context.\r
2724\r
2725**/\r
2726BOOLEAN\r
2727EFIAPI\r
2728CryptoServiceRsaPkcs1Verify (\r
2729 IN VOID *RsaContext,\r
2730 IN CONST UINT8 *MessageHash,\r
2731 IN UINTN HashSize,\r
2732 IN CONST UINT8 *Signature,\r
2733 IN UINTN SigSize\r
2734 )\r
2735{\r
2736 return CALL_BASECRYPTLIB (Rsa.Services.Pkcs1Verify, RsaPkcs1Verify, (RsaContext, MessageHash, HashSize, Signature, SigSize), FALSE);\r
2737}\r
2738\r
2739/**\r
2740 Retrieve the RSA Private Key from the password-protected PEM key data.\r
2741\r
2742 If PemData is NULL, then return FALSE.\r
2743 If RsaContext is NULL, then return FALSE.\r
2744 If this interface is not supported, then return FALSE.\r
2745\r
2746 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
2747 @param[in] PemSize Size of the PEM key data in bytes.\r
2748 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
2749 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
2750 RSA private key component. Use RsaFree() function to free the\r
2751 resource.\r
2752\r
2753 @retval TRUE RSA Private Key was retrieved successfully.\r
2754 @retval FALSE Invalid PEM key data or incorrect password.\r
2755 @retval FALSE This interface is not supported.\r
2756\r
2757**/\r
2758BOOLEAN\r
2759EFIAPI\r
2760CryptoServiceRsaGetPrivateKeyFromPem (\r
2761 IN CONST UINT8 *PemData,\r
2762 IN UINTN PemSize,\r
2763 IN CONST CHAR8 *Password,\r
2764 OUT VOID **RsaContext\r
2765 )\r
2766{\r
2767 return CALL_BASECRYPTLIB (Rsa.Services.GetPrivateKeyFromPem, RsaGetPrivateKeyFromPem, (PemData, PemSize, Password, RsaContext), FALSE);\r
2768}\r
2769\r
2770/**\r
2771 Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r
2772\r
2773 If Cert is NULL, then return FALSE.\r
2774 If RsaContext is NULL, then return FALSE.\r
2775 If this interface is not supported, then return FALSE.\r
2776\r
2777 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2778 @param[in] CertSize Size of the X509 certificate in bytes.\r
2779 @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r
2780 RSA public key component. Use RsaFree() function to free the\r
2781 resource.\r
2782\r
2783 @retval TRUE RSA Public Key was retrieved successfully.\r
2784 @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r
2785 @retval FALSE This interface is not supported.\r
2786\r
2787**/\r
2788BOOLEAN\r
2789EFIAPI\r
2790CryptoServiceRsaGetPublicKeyFromX509 (\r
2791 IN CONST UINT8 *Cert,\r
2792 IN UINTN CertSize,\r
2793 OUT VOID **RsaContext\r
2794 )\r
2795{\r
2796 return CALL_BASECRYPTLIB (Rsa.Services.GetPublicKeyFromX509, RsaGetPublicKeyFromX509, (Cert, CertSize, RsaContext), FALSE);\r
2797}\r
2798\r
2799/**\r
2800 Retrieve the subject bytes from one X.509 certificate.\r
2801\r
2802 If Cert is NULL, then return FALSE.\r
2803 If SubjectSize is NULL, then return FALSE.\r
2804 If this interface is not supported, then return FALSE.\r
2805\r
2806 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2807 @param[in] CertSize Size of the X509 certificate in bytes.\r
2808 @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r
2809 @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r
2810 and the size of buffer returned CertSubject on output.\r
2811\r
2812 @retval TRUE The certificate subject retrieved successfully.\r
2813 @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r
2814 The SubjectSize will be updated with the required size.\r
2815 @retval FALSE This interface is not supported.\r
2816\r
2817**/\r
2818BOOLEAN\r
2819EFIAPI\r
2820CryptoServiceX509GetSubjectName (\r
2821 IN CONST UINT8 *Cert,\r
2822 IN UINTN CertSize,\r
2823 OUT UINT8 *CertSubject,\r
2824 IN OUT UINTN *SubjectSize\r
2825 )\r
2826{\r
2827 return CALL_BASECRYPTLIB (X509.Services.GetSubjectName, X509GetSubjectName, (Cert, CertSize, CertSubject, SubjectSize), FALSE);\r
2828}\r
2829\r
2830/**\r
2831 Retrieve the common name (CN) string from one X.509 certificate.\r
2832\r
2833 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2834 @param[in] CertSize Size of the X509 certificate in bytes.\r
2835 @param[out] CommonName Buffer to contain the retrieved certificate common\r
2836 name string (UTF8). At most CommonNameSize bytes will be\r
2837 written and the string will be null terminated. May be\r
2838 NULL in order to determine the size buffer needed.\r
2839 @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input,\r
2840 and the size of buffer returned CommonName on output.\r
2841 If CommonName is NULL then the amount of space needed\r
2842 in buffer (including the final null) is returned.\r
2843\r
2844 @retval RETURN_SUCCESS The certificate CommonName retrieved successfully.\r
2845 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
2846 If CommonNameSize is NULL.\r
2847 If CommonName is not NULL and *CommonNameSize is 0.\r
2848 If Certificate is invalid.\r
2849 @retval RETURN_NOT_FOUND If no CommonName entry exists.\r
2850 @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size\r
2851 (including the final null) is returned in the\r
2852 CommonNameSize parameter.\r
2853 @retval RETURN_UNSUPPORTED The operation is not supported.\r
2854\r
2855**/\r
2856RETURN_STATUS\r
2857EFIAPI\r
2858CryptoServiceX509GetCommonName (\r
2859 IN CONST UINT8 *Cert,\r
2860 IN UINTN CertSize,\r
c8f46130 2861 OUT CHAR8 *CommonName OPTIONAL,\r
cc1d13c9
MK
2862 IN OUT UINTN *CommonNameSize\r
2863 )\r
2864{\r
2865 return CALL_BASECRYPTLIB (X509.Services.GetCommonName, X509GetCommonName, (Cert, CertSize, CommonName, CommonNameSize), RETURN_UNSUPPORTED);\r
2866}\r
2867\r
2868/**\r
2869 Retrieve the organization name (O) string from one X.509 certificate.\r
2870\r
2871 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
2872 @param[in] CertSize Size of the X509 certificate in bytes.\r
2873 @param[out] NameBuffer Buffer to contain the retrieved certificate organization\r
2874 name string. At most NameBufferSize bytes will be\r
2875 written and the string will be null terminated. May be\r
2876 NULL in order to determine the size buffer needed.\r
2877 @param[in,out] NameBufferSize The size in bytes of the Name buffer on input,\r
2878 and the size of buffer returned Name on output.\r
2879 If NameBuffer is NULL then the amount of space needed\r
2880 in buffer (including the final null) is returned.\r
2881\r
2882 @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully.\r
2883 @retval RETURN_INVALID_PARAMETER If Cert is NULL.\r
2884 If NameBufferSize is NULL.\r
2885 If NameBuffer is not NULL and *CommonNameSize is 0.\r
2886 If Certificate is invalid.\r
2887 @retval RETURN_NOT_FOUND If no Organization Name entry exists.\r
2888 @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size\r
2889 (including the final null) is returned in the\r
2890 CommonNameSize parameter.\r
2891 @retval RETURN_UNSUPPORTED The operation is not supported.\r
2892\r
2893**/\r
2894RETURN_STATUS\r
2895EFIAPI\r
2896CryptoServiceX509GetOrganizationName (\r
7c342378
MK
2897 IN CONST UINT8 *Cert,\r
2898 IN UINTN CertSize,\r
2899 OUT CHAR8 *NameBuffer OPTIONAL,\r
2900 IN OUT UINTN *NameBufferSize\r
cc1d13c9
MK
2901 )\r
2902{\r
2903 return CALL_BASECRYPTLIB (X509.Services.GetOrganizationName, X509GetOrganizationName, (Cert, CertSize, NameBuffer, NameBufferSize), RETURN_UNSUPPORTED);\r
2904}\r
2905\r
2906/**\r
2907 Verify one X509 certificate was issued by the trusted CA.\r
2908\r
2909 If Cert is NULL, then return FALSE.\r
2910 If CACert is NULL, then return FALSE.\r
2911 If this interface is not supported, then return FALSE.\r
2912\r
2913 @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r
2914 @param[in] CertSize Size of the X509 certificate in bytes.\r
2915 @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r
2916 @param[in] CACertSize Size of the CA Certificate in bytes.\r
2917\r
2918 @retval TRUE The certificate was issued by the trusted CA.\r
2919 @retval FALSE Invalid certificate or the certificate was not issued by the given\r
2920 trusted CA.\r
2921 @retval FALSE This interface is not supported.\r
2922\r
2923**/\r
2924BOOLEAN\r
2925EFIAPI\r
2926CryptoServiceX509VerifyCert (\r
2927 IN CONST UINT8 *Cert,\r
2928 IN UINTN CertSize,\r
2929 IN CONST UINT8 *CACert,\r
2930 IN UINTN CACertSize\r
2931 )\r
2932{\r
2933 return CALL_BASECRYPTLIB (X509.Services.VerifyCert, X509VerifyCert, (Cert, CertSize, CACert, CACertSize), FALSE);\r
2934}\r
2935\r
2936/**\r
2937 Construct a X509 object from DER-encoded certificate data.\r
2938\r
2939 If Cert is NULL, then return FALSE.\r
2940 If SingleX509Cert is NULL, then return FALSE.\r
2941 If this interface is not supported, then return FALSE.\r
2942\r
2943 @param[in] Cert Pointer to the DER-encoded certificate data.\r
2944 @param[in] CertSize The size of certificate data in bytes.\r
2945 @param[out] SingleX509Cert The generated X509 object.\r
2946\r
2947 @retval TRUE The X509 object generation succeeded.\r
2948 @retval FALSE The operation failed.\r
2949 @retval FALSE This interface is not supported.\r
2950\r
2951**/\r
2952BOOLEAN\r
2953EFIAPI\r
2954CryptoServiceX509ConstructCertificate (\r
2955 IN CONST UINT8 *Cert,\r
2956 IN UINTN CertSize,\r
2957 OUT UINT8 **SingleX509Cert\r
2958 )\r
2959{\r
2960 return CALL_BASECRYPTLIB (X509.Services.ConstructCertificate, X509ConstructCertificate, (Cert, CertSize, SingleX509Cert), FALSE);\r
2961}\r
2962\r
2963/**\r
2964 Construct a X509 stack object from a list of DER-encoded certificate data.\r
2965\r
2966 If X509Stack is NULL, then return FALSE.\r
2967 If this interface is not supported, then return FALSE.\r
2968\r
2969 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
2970 On output, pointer to the X509 stack object with new\r
2971 inserted X509 certificate.\r
2972 @param[in] Args VA_LIST marker for the variable argument list.\r
2973 A list of DER-encoded single certificate data followed\r
2974 by certificate size. A NULL terminates the list. The\r
2975 pairs are the arguments to X509ConstructCertificate().\r
2976\r
2977 @retval TRUE The X509 stack construction succeeded.\r
2978 @retval FALSE The construction operation failed.\r
2979 @retval FALSE This interface is not supported.\r
2980\r
2981**/\r
2982BOOLEAN\r
2983EFIAPI\r
2984CryptoServiceX509ConstructCertificateStackV (\r
2985 IN OUT UINT8 **X509Stack,\r
2986 IN VA_LIST Args\r
2987 )\r
2988{\r
2989 return CALL_BASECRYPTLIB (X509.Services.ConstructCertificateStackV, X509ConstructCertificateStackV, (X509Stack, Args), FALSE);\r
2990}\r
2991\r
2992/**\r
2993 Construct a X509 stack object from a list of DER-encoded certificate data.\r
2994\r
2995 If X509Stack is NULL, then return FALSE.\r
2996 If this interface is not supported, then return FALSE.\r
2997\r
2998 @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r
2999 On output, pointer to the X509 stack object with new\r
3000 inserted X509 certificate.\r
3001 @param ... A list of DER-encoded single certificate data followed\r
3002 by certificate size. A NULL terminates the list. The\r
3003 pairs are the arguments to X509ConstructCertificate().\r
3004\r
3005 @retval TRUE The X509 stack construction succeeded.\r
3006 @retval FALSE The construction operation failed.\r
3007 @retval FALSE This interface is not supported.\r
3008\r
3009**/\r
3010BOOLEAN\r
3011EFIAPI\r
3012CryptoServiceX509ConstructCertificateStack (\r
3013 IN OUT UINT8 **X509Stack,\r
3014 ...\r
3015 )\r
3016{\r
3017 VA_LIST Args;\r
3018 BOOLEAN Result;\r
3019\r
3020 VA_START (Args, X509Stack);\r
3021 Result = CryptoServiceX509ConstructCertificateStackV (X509Stack, Args);\r
3022 VA_END (Args);\r
3023 return Result;\r
3024}\r
3025\r
3026/**\r
3027 Release the specified X509 object.\r
3028\r
3029 If the interface is not supported, then ASSERT().\r
3030\r
3031 @param[in] X509Cert Pointer to the X509 object to be released.\r
3032\r
3033**/\r
3034VOID\r
3035EFIAPI\r
3036CryptoServiceX509Free (\r
3037 IN VOID *X509Cert\r
3038 )\r
3039{\r
3040 CALL_VOID_BASECRYPTLIB (X509.Services.Free, X509Free, (X509Cert));\r
3041}\r
3042\r
3043/**\r
3044 Release the specified X509 stack object.\r
3045\r
3046 If the interface is not supported, then ASSERT().\r
3047\r
3048 @param[in] X509Stack Pointer to the X509 stack object to be released.\r
3049\r
3050**/\r
3051VOID\r
3052EFIAPI\r
3053CryptoServiceX509StackFree (\r
3054 IN VOID *X509Stack\r
3055 )\r
3056{\r
3057 CALL_VOID_BASECRYPTLIB (X509.Services.StackFree, X509StackFree, (X509Stack));\r
3058}\r
3059\r
3060/**\r
3061 Retrieve the TBSCertificate from one given X.509 certificate.\r
3062\r
3063 @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r
3064 @param[in] CertSize Size of the X509 certificate in bytes.\r
3065 @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r
3066 @param[out] TBSCertSize Size of the TBS certificate in bytes.\r
3067\r
3068 If Cert is NULL, then return FALSE.\r
3069 If TBSCert is NULL, then return FALSE.\r
3070 If TBSCertSize is NULL, then return FALSE.\r
3071 If this interface is not supported, then return FALSE.\r
3072\r
3073 @retval TRUE The TBSCertificate was retrieved successfully.\r
3074 @retval FALSE Invalid X.509 certificate.\r
3075\r
3076**/\r
3077BOOLEAN\r
3078EFIAPI\r
3079CryptoServiceX509GetTBSCert (\r
3080 IN CONST UINT8 *Cert,\r
3081 IN UINTN CertSize,\r
3082 OUT UINT8 **TBSCert,\r
3083 OUT UINTN *TBSCertSize\r
3084 )\r
3085{\r
3086 return CALL_BASECRYPTLIB (X509.Services.GetTBSCert, X509GetTBSCert, (Cert, CertSize, TBSCert, TBSCertSize), FALSE);\r
3087}\r
3088\r
3089/**\r
3090 Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0\r
3091 password based encryption key derivation function PBKDF2, as specified in RFC 2898.\r
3092\r
3093 If Password or Salt or OutKey is NULL, then return FALSE.\r
3094 If the hash algorithm could not be determined, then return FALSE.\r
3095 If this interface is not supported, then return FALSE.\r
3096\r
3097 @param[in] PasswordLength Length of input password in bytes.\r
3098 @param[in] Password Pointer to the array for the password.\r
3099 @param[in] SaltLength Size of the Salt in bytes.\r
3100 @param[in] Salt Pointer to the Salt.\r
3101 @param[in] IterationCount Number of iterations to perform. Its value should be\r
3102 greater than or equal to 1.\r
3103 @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE).\r
3104 NOTE: DigestSize will be used to determine the hash algorithm.\r
3105 Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported.\r
3106 @param[in] KeyLength Size of the derived key buffer in bytes.\r
3107 @param[out] OutKey Pointer to the output derived key buffer.\r
3108\r
3109 @retval TRUE A key was derived successfully.\r
3110 @retval FALSE One of the pointers was NULL or one of the sizes was too large.\r
3111 @retval FALSE The hash algorithm could not be determined from the digest size.\r
3112 @retval FALSE The key derivation operation failed.\r
3113 @retval FALSE This interface is not supported.\r
3114\r
3115**/\r
3116BOOLEAN\r
3117EFIAPI\r
3118CryptoServicePkcs5HashPassword (\r
3119 IN UINTN PasswordLength,\r
3120 IN CONST CHAR8 *Password,\r
3121 IN UINTN SaltLength,\r
3122 IN CONST UINT8 *Salt,\r
3123 IN UINTN IterationCount,\r
3124 IN UINTN DigestSize,\r
3125 IN UINTN KeyLength,\r
3126 OUT UINT8 *OutKey\r
3127 )\r
3128{\r
3129 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs5HashPassword, Pkcs5HashPassword, (PasswordLength, Password, SaltLength, Salt, IterationCount, DigestSize, KeyLength, OutKey), FALSE);\r
3130}\r
3131\r
3132/**\r
3133 Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the\r
3134 encrypted message in a newly allocated buffer.\r
3135\r
3136 Things that can cause a failure include:\r
3137 - X509 key size does not match any known key size.\r
3138 - Fail to parse X509 certificate.\r
3139 - Fail to allocate an intermediate buffer.\r
3140 - Null pointer provided for a non-optional parameter.\r
3141 - Data size is too large for the provided key size (max size is a function of key size\r
3142 and hash digest size).\r
3143\r
3144 @param[in] PublicKey A pointer to the DER-encoded X509 certificate that\r
3145 will be used to encrypt the data.\r
3146 @param[in] PublicKeySize Size of the X509 cert buffer.\r
3147 @param[in] InData Data to be encrypted.\r
3148 @param[in] InDataSize Size of the data buffer.\r
3149 @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer\r
3150 to be used when initializing the PRNG. NULL otherwise.\r
3151 @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer.\r
3152 0 otherwise.\r
3153 @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted\r
3154 message.\r
3155 @param[out] EncryptedDataSize Size of the encrypted message buffer.\r
3156\r
3157 @retval TRUE Encryption was successful.\r
3158 @retval FALSE Encryption failed.\r
3159\r
3160**/\r
3161BOOLEAN\r
3162EFIAPI\r
3163CryptoServicePkcs1v2Encrypt (\r
3164 IN CONST UINT8 *PublicKey,\r
3165 IN UINTN PublicKeySize,\r
3166 IN UINT8 *InData,\r
3167 IN UINTN InDataSize,\r
c8f46130
MK
3168 IN CONST UINT8 *PrngSeed OPTIONAL,\r
3169 IN UINTN PrngSeedSize OPTIONAL,\r
cc1d13c9
MK
3170 OUT UINT8 **EncryptedData,\r
3171 OUT UINTN *EncryptedDataSize\r
3172 )\r
3173{\r
3174 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs1v2Encrypt, Pkcs1v2Encrypt, (PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize), FALSE);\r
3175}\r
3176\r
3177/**\r
3178 Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r
3179 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
3180 in a ContentInfo structure.\r
3181\r
3182 If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r
3183 return FALSE. If P7Length overflow, then return FALSE.\r
3184 If this interface is not supported, then return FALSE.\r
3185\r
3186 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
3187 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
3188 @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r
3189 It's caller's responsibility to free the buffer with\r
3190 Pkcs7FreeSigners().\r
3191 This data structure is EFI_CERT_STACK type.\r
3192 @param[out] StackLength Length of signer's certificates in bytes.\r
3193 @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r
3194 It's caller's responsibility to free the buffer with\r
3195 Pkcs7FreeSigners().\r
3196 @param[out] CertLength Length of the trusted certificate in bytes.\r
3197\r
3198 @retval TRUE The operation is finished successfully.\r
3199 @retval FALSE Error occurs during the operation.\r
3200 @retval FALSE This interface is not supported.\r
3201\r
3202**/\r
3203BOOLEAN\r
3204EFIAPI\r
3205CryptoServicePkcs7GetSigners (\r
3206 IN CONST UINT8 *P7Data,\r
3207 IN UINTN P7Length,\r
3208 OUT UINT8 **CertStack,\r
3209 OUT UINTN *StackLength,\r
3210 OUT UINT8 **TrustedCert,\r
3211 OUT UINTN *CertLength\r
3212 )\r
3213{\r
3214 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7GetSigners, Pkcs7GetSigners, (P7Data, P7Length, CertStack, StackLength, TrustedCert, CertLength), FALSE);\r
3215}\r
3216\r
3217/**\r
3218 Wrap function to use free() to free allocated memory for certificates.\r
3219\r
3220 If this interface is not supported, then ASSERT().\r
3221\r
3222 @param[in] Certs Pointer to the certificates to be freed.\r
3223\r
3224**/\r
3225VOID\r
3226EFIAPI\r
3227CryptoServicePkcs7FreeSigners (\r
7c342378 3228 IN UINT8 *Certs\r
cc1d13c9
MK
3229 )\r
3230{\r
3231 CALL_VOID_BASECRYPTLIB (Pkcs.Services.Pkcs7FreeSigners, Pkcs7FreeSigners, (Certs));\r
3232}\r
3233\r
3234/**\r
3235 Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r
3236 Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r
3237 unchained to the signer's certificates.\r
3238 The input signed data could be wrapped in a ContentInfo structure.\r
3239\r
3240 @param[in] P7Data Pointer to the PKCS#7 message.\r
3241 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
3242 @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r
3243 certificate. It's caller's responsibility to free the buffer\r
3244 with Pkcs7FreeSigners().\r
3245 This data structure is EFI_CERT_STACK type.\r
3246 @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r
3247 @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r
3248 responsibility to free the buffer with Pkcs7FreeSigners().\r
3249 This data structure is EFI_CERT_STACK type.\r
3250 @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r
3251\r
3252 @retval TRUE The operation is finished successfully.\r
3253 @retval FALSE Error occurs during the operation.\r
3254\r
3255**/\r
3256BOOLEAN\r
3257EFIAPI\r
3258CryptoServicePkcs7GetCertificatesList (\r
3259 IN CONST UINT8 *P7Data,\r
3260 IN UINTN P7Length,\r
3261 OUT UINT8 **SignerChainCerts,\r
3262 OUT UINTN *ChainLength,\r
3263 OUT UINT8 **UnchainCerts,\r
3264 OUT UINTN *UnchainLength\r
3265 )\r
3266{\r
3267 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7GetCertificatesList, Pkcs7GetCertificatesList, (P7Data, P7Length, SignerChainCerts, ChainLength, UnchainCerts, UnchainLength), FALSE);\r
3268}\r
3269\r
3270/**\r
3271 Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r
3272 Syntax Standard, version 1.5". This interface is only intended to be used for\r
3273 application to perform PKCS#7 functionality validation.\r
3274\r
3275 If this interface is not supported, then return FALSE.\r
3276\r
3277 @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r
3278 data signing.\r
3279 @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r
3280 @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r
3281 key data.\r
3282 @param[in] InData Pointer to the content to be signed.\r
3283 @param[in] InDataSize Size of InData in bytes.\r
3284 @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r
3285 @param[in] OtherCerts Pointer to an optional additional set of certificates to\r
3286 include in the PKCS#7 signedData (e.g. any intermediate\r
3287 CAs in the chain).\r
3288 @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's\r
3289 responsibility to free the buffer with FreePool().\r
3290 @param[out] SignedDataSize Size of SignedData in bytes.\r
3291\r
3292 @retval TRUE PKCS#7 data signing succeeded.\r
3293 @retval FALSE PKCS#7 data signing failed.\r
3294 @retval FALSE This interface is not supported.\r
3295\r
3296**/\r
3297BOOLEAN\r
3298EFIAPI\r
3299CryptoServicePkcs7Sign (\r
3300 IN CONST UINT8 *PrivateKey,\r
3301 IN UINTN PrivateKeySize,\r
3302 IN CONST UINT8 *KeyPassword,\r
3303 IN UINT8 *InData,\r
3304 IN UINTN InDataSize,\r
3305 IN UINT8 *SignCert,\r
3306 IN UINT8 *OtherCerts OPTIONAL,\r
3307 OUT UINT8 **SignedData,\r
3308 OUT UINTN *SignedDataSize\r
3309 )\r
3310{\r
3311 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7Sign, Pkcs7Sign, (PrivateKey, PrivateKeySize, KeyPassword, InData, InDataSize, SignCert, OtherCerts, SignedData, SignedDataSize), FALSE);\r
3312}\r
3313\r
3314/**\r
3315 Verifies the validity of a PKCS#7 signed data as described in "PKCS #7:\r
3316 Cryptographic Message Syntax Standard". The input signed data could be wrapped\r
3317 in a ContentInfo structure.\r
3318\r
3319 If P7Data, TrustedCert or InData is NULL, then return FALSE.\r
3320 If P7Length, CertLength or DataLength overflow, then return FALSE.\r
3321 If this interface is not supported, then return FALSE.\r
3322\r
3323 @param[in] P7Data Pointer to the PKCS#7 message to verify.\r
3324 @param[in] P7Length Length of the PKCS#7 message in bytes.\r
3325 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
3326 is used for certificate chain verification.\r
3327 @param[in] CertLength Length of the trusted certificate in bytes.\r
3328 @param[in] InData Pointer to the content to be verified.\r
3329 @param[in] DataLength Length of InData in bytes.\r
3330\r
3331 @retval TRUE The specified PKCS#7 signed data is valid.\r
3332 @retval FALSE Invalid PKCS#7 signed data.\r
3333 @retval FALSE This interface is not supported.\r
3334\r
3335**/\r
3336BOOLEAN\r
3337EFIAPI\r
3338CryptoServicePkcs7Verify (\r
3339 IN CONST UINT8 *P7Data,\r
3340 IN UINTN P7Length,\r
3341 IN CONST UINT8 *TrustedCert,\r
3342 IN UINTN CertLength,\r
3343 IN CONST UINT8 *InData,\r
3344 IN UINTN DataLength\r
3345 )\r
3346{\r
3347 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7Verify, Pkcs7Verify, (P7Data, P7Length, TrustedCert, CertLength, InData, DataLength), FALSE);\r
3348}\r
3349\r
3350/**\r
3351 This function receives a PKCS7 formatted signature, and then verifies that\r
3352 the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity\r
3353 leaf signing certificate.\r
3354 Note that this function does not validate the certificate chain.\r
3355\r
3356 Applications for custom EKU's are quite flexible. For example, a policy EKU\r
3357 may be present in an Issuing Certificate Authority (CA), and any sub-ordinate\r
3358 certificate issued might also contain this EKU, thus constraining the\r
3359 sub-ordinate certificate. Other applications might allow a certificate\r
3360 embedded in a device to specify that other Object Identifiers (OIDs) are\r
3361 present which contains binary data specifying custom capabilities that\r
3362 the device is able to do.\r
3363\r
3364 @param[in] Pkcs7Signature The PKCS#7 signed information content block. An array\r
3365 containing the content block with both the signature,\r
3366 the signer's certificate, and any necessary intermediate\r
3367 certificates.\r
3368 @param[in] Pkcs7SignatureSize Number of bytes in Pkcs7Signature.\r
3369 @param[in] RequiredEKUs Array of null-terminated strings listing OIDs of\r
3370 required EKUs that must be present in the signature.\r
3371 @param[in] RequiredEKUsSize Number of elements in the RequiredEKUs string array.\r
3372 @param[in] RequireAllPresent If this is TRUE, then all of the specified EKU's\r
3373 must be present in the leaf signer. If it is\r
3374 FALSE, then we will succeed if we find any\r
3375 of the specified EKU's.\r
3376\r
3377 @retval EFI_SUCCESS The required EKUs were found in the signature.\r
3378 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
3379 @retval EFI_NOT_FOUND One or more EKU's were not found in the signature.\r
3380\r
3381**/\r
3382RETURN_STATUS\r
3383EFIAPI\r
3384CryptoServiceVerifyEKUsInPkcs7Signature (\r
3385 IN CONST UINT8 *Pkcs7Signature,\r
3386 IN CONST UINT32 SignatureSize,\r
3387 IN CONST CHAR8 *RequiredEKUs[],\r
3388 IN CONST UINT32 RequiredEKUsSize,\r
3389 IN BOOLEAN RequireAllPresent\r
3390 )\r
3391{\r
3392 return CALL_BASECRYPTLIB (Pkcs.Services.VerifyEKUsInPkcs7Signature, VerifyEKUsInPkcs7Signature, (Pkcs7Signature, SignatureSize, RequiredEKUs, RequiredEKUsSize, RequireAllPresent), FALSE);\r
3393}\r
3394\r
cc1d13c9
MK
3395/**\r
3396 Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r
3397 data could be wrapped in a ContentInfo structure.\r
3398\r
3399 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r
3400 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.\r
3401\r
3402 Caution: This function may receive untrusted input. So this function will do\r
3403 basic check for PKCS#7 data structure.\r
3404\r
3405 @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r
3406 @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r
3407 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r
3408 It's caller's responsibility to free the buffer with FreePool().\r
3409 @param[out] ContentSize The size of the extracted content in bytes.\r
3410\r
3411 @retval TRUE The P7Data was correctly formatted for processing.\r
3412 @retval FALSE The P7Data was not correctly formatted for processing.\r
3413\r
3414**/\r
3415BOOLEAN\r
3416EFIAPI\r
3417CryptoServicePkcs7GetAttachedContent (\r
3418 IN CONST UINT8 *P7Data,\r
3419 IN UINTN P7Length,\r
3420 OUT VOID **Content,\r
3421 OUT UINTN *ContentSize\r
3422 )\r
3423{\r
3424 return CALL_BASECRYPTLIB (Pkcs.Services.Pkcs7GetAttachedContent, Pkcs7GetAttachedContent, (P7Data, P7Length, Content, ContentSize), FALSE);\r
3425}\r
3426\r
3427/**\r
3428 Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows\r
3429 Authenticode Portable Executable Signature Format".\r
3430\r
3431 If AuthData is NULL, then return FALSE.\r
3432 If ImageHash is NULL, then return FALSE.\r
3433 If this interface is not supported, then return FALSE.\r
3434\r
3435 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
3436 PE/COFF image to be verified.\r
3437 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
3438 @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r
3439 is used for certificate chain verification.\r
3440 @param[in] CertSize Size of the trusted certificate in bytes.\r
3441 @param[in] ImageHash Pointer to the original image file hash value. The procedure\r
3442 for calculating the image hash value is described in Authenticode\r
3443 specification.\r
3444 @param[in] HashSize Size of Image hash value in bytes.\r
3445\r
3446 @retval TRUE The specified Authenticode Signature is valid.\r
3447 @retval FALSE Invalid Authenticode Signature.\r
3448 @retval FALSE This interface is not supported.\r
3449\r
3450**/\r
3451BOOLEAN\r
3452EFIAPI\r
3453CryptoServiceAuthenticodeVerify (\r
3454 IN CONST UINT8 *AuthData,\r
3455 IN UINTN DataSize,\r
3456 IN CONST UINT8 *TrustedCert,\r
3457 IN UINTN CertSize,\r
3458 IN CONST UINT8 *ImageHash,\r
3459 IN UINTN HashSize\r
3460 )\r
3461{\r
3462 return CALL_BASECRYPTLIB (Pkcs.Services.AuthenticodeVerify, AuthenticodeVerify, (AuthData, DataSize, TrustedCert, CertSize, ImageHash, HashSize), FALSE);\r
3463}\r
3464\r
3465/**\r
3466 Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r
3467 signature.\r
3468\r
3469 If AuthData is NULL, then return FALSE.\r
3470 If this interface is not supported, then return FALSE.\r
3471\r
3472 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r
3473 PE/COFF image to be verified.\r
3474 @param[in] DataSize Size of the Authenticode Signature in bytes.\r
3475 @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r
3476 is used for TSA certificate chain verification.\r
3477 @param[in] CertSize Size of the trusted certificate in bytes.\r
3478 @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r
3479 signature is valid.\r
3480\r
3481 @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r
3482 @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r
3483\r
3484**/\r
3485BOOLEAN\r
3486EFIAPI\r
3487CryptoServiceImageTimestampVerify (\r
3488 IN CONST UINT8 *AuthData,\r
3489 IN UINTN DataSize,\r
3490 IN CONST UINT8 *TsaCert,\r
3491 IN UINTN CertSize,\r
3492 OUT EFI_TIME *SigningTime\r
3493 )\r
3494{\r
3495 return CALL_BASECRYPTLIB (Pkcs.Services.ImageTimestampVerify, ImageTimestampVerify, (AuthData, DataSize, TsaCert, CertSize, SigningTime), FALSE);\r
3496}\r
3497\r
7c342378 3498// =====================================================================================\r
cc1d13c9 3499// DH Key Exchange Primitive\r
7c342378 3500// =====================================================================================\r
cc1d13c9
MK
3501\r
3502/**\r
3503 Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r
3504\r
3505 @return Pointer to the Diffie-Hellman Context that has been initialized.\r
3506 If the allocations fails, DhNew() returns NULL.\r
3507 If the interface is not supported, DhNew() returns NULL.\r
3508\r
3509**/\r
3510VOID *\r
3511EFIAPI\r
3512CryptoServiceDhNew (\r
3513 VOID\r
3514 )\r
3515{\r
3516 return CALL_BASECRYPTLIB (Dh.Services.New, DhNew, (), NULL);\r
3517}\r
3518\r
3519/**\r
3520 Release the specified DH context.\r
3521\r
3522 If the interface is not supported, then ASSERT().\r
3523\r
3524 @param[in] DhContext Pointer to the DH context to be released.\r
3525\r
3526**/\r
3527VOID\r
3528EFIAPI\r
3529CryptoServiceDhFree (\r
3530 IN VOID *DhContext\r
3531 )\r
3532{\r
3533 CALL_VOID_BASECRYPTLIB (Dh.Services.Free, DhFree, (DhContext));\r
3534}\r
3535\r
3536/**\r
3537 Generates DH parameter.\r
3538\r
3539 Given generator g, and length of prime number p in bits, this function generates p,\r
3540 and sets DH context according to value of g and p.\r
3541\r
3542 Before this function can be invoked, pseudorandom number generator must be correctly\r
3543 initialized by RandomSeed().\r
3544\r
3545 If DhContext is NULL, then return FALSE.\r
3546 If Prime is NULL, then return FALSE.\r
3547 If this interface is not supported, then return FALSE.\r
3548\r
3549 @param[in, out] DhContext Pointer to the DH context.\r
3550 @param[in] Generator Value of generator.\r
3551 @param[in] PrimeLength Length in bits of prime to be generated.\r
3552 @param[out] Prime Pointer to the buffer to receive the generated prime number.\r
3553\r
3554 @retval TRUE DH parameter generation succeeded.\r
3555 @retval FALSE Value of Generator is not supported.\r
3556 @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r
3557 @retval FALSE This interface is not supported.\r
3558\r
3559**/\r
3560BOOLEAN\r
3561EFIAPI\r
3562CryptoServiceDhGenerateParameter (\r
3563 IN OUT VOID *DhContext,\r
3564 IN UINTN Generator,\r
3565 IN UINTN PrimeLength,\r
3566 OUT UINT8 *Prime\r
3567 )\r
3568{\r
3569 return CALL_BASECRYPTLIB (Dh.Services.GenerateParameter, DhGenerateParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);\r
3570}\r
3571\r
3572/**\r
3573 Sets generator and prime parameters for DH.\r
3574\r
3575 Given generator g, and prime number p, this function and sets DH\r
3576 context accordingly.\r
3577\r
3578 If DhContext is NULL, then return FALSE.\r
3579 If Prime is NULL, then return FALSE.\r
3580 If this interface is not supported, then return FALSE.\r
3581\r
3582 @param[in, out] DhContext Pointer to the DH context.\r
3583 @param[in] Generator Value of generator.\r
3584 @param[in] PrimeLength Length in bits of prime to be generated.\r
3585 @param[in] Prime Pointer to the prime number.\r
3586\r
3587 @retval TRUE DH parameter setting succeeded.\r
3588 @retval FALSE Value of Generator is not supported.\r
3589 @retval FALSE Value of Generator is not suitable for the Prime.\r
3590 @retval FALSE Value of Prime is not a prime number.\r
3591 @retval FALSE Value of Prime is not a safe prime number.\r
3592 @retval FALSE This interface is not supported.\r
3593\r
3594**/\r
3595BOOLEAN\r
3596EFIAPI\r
3597CryptoServiceDhSetParameter (\r
3598 IN OUT VOID *DhContext,\r
3599 IN UINTN Generator,\r
3600 IN UINTN PrimeLength,\r
3601 IN CONST UINT8 *Prime\r
3602 )\r
3603{\r
3604 return CALL_BASECRYPTLIB (Dh.Services.SetParameter, DhSetParameter, (DhContext, Generator, PrimeLength, Prime), FALSE);\r
3605}\r
3606\r
3607/**\r
3608 Generates DH public key.\r
3609\r
3610 This function generates random secret exponent, and computes the public key, which is\r
3611 returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r
3612 If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r
3613 PublicKeySize is set to the required buffer size to obtain the public key.\r
3614\r
3615 If DhContext is NULL, then return FALSE.\r
3616 If PublicKeySize is NULL, then return FALSE.\r
3617 If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r
3618 If this interface is not supported, then return FALSE.\r
3619\r
3620 @param[in, out] DhContext Pointer to the DH context.\r
3621 @param[out] PublicKey Pointer to the buffer to receive generated public key.\r
3622 @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r
3623 On output, the size of data returned in PublicKey buffer in bytes.\r
3624\r
3625 @retval TRUE DH public key generation succeeded.\r
3626 @retval FALSE DH public key generation failed.\r
3627 @retval FALSE PublicKeySize is not large enough.\r
3628 @retval FALSE This interface is not supported.\r
3629\r
3630**/\r
3631BOOLEAN\r
3632EFIAPI\r
3633CryptoServiceDhGenerateKey (\r
3634 IN OUT VOID *DhContext,\r
3635 OUT UINT8 *PublicKey,\r
3636 IN OUT UINTN *PublicKeySize\r
3637 )\r
3638{\r
3639 return CALL_BASECRYPTLIB (Dh.Services.GenerateKey, DhGenerateKey, (DhContext, PublicKey, PublicKeySize), FALSE);\r
3640}\r
3641\r
3642/**\r
3643 Computes exchanged common key.\r
3644\r
3645 Given peer's public key, this function computes the exchanged common key, based on its own\r
3646 context including value of prime modulus and random secret exponent.\r
3647\r
3648 If DhContext is NULL, then return FALSE.\r
3649 If PeerPublicKey is NULL, then return FALSE.\r
3650 If KeySize is NULL, then return FALSE.\r
3651 If Key is NULL, then return FALSE.\r
3652 If KeySize is not large enough, then return FALSE.\r
3653 If this interface is not supported, then return FALSE.\r
3654\r
3655 @param[in, out] DhContext Pointer to the DH context.\r
3656 @param[in] PeerPublicKey Pointer to the peer's public key.\r
3657 @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r
3658 @param[out] Key Pointer to the buffer to receive generated key.\r
3659 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
3660 On output, the size of data returned in Key buffer in bytes.\r
3661\r
3662 @retval TRUE DH exchanged key generation succeeded.\r
3663 @retval FALSE DH exchanged key generation failed.\r
3664 @retval FALSE KeySize is not large enough.\r
3665 @retval FALSE This interface is not supported.\r
3666\r
3667**/\r
3668BOOLEAN\r
3669EFIAPI\r
3670CryptoServiceDhComputeKey (\r
3671 IN OUT VOID *DhContext,\r
3672 IN CONST UINT8 *PeerPublicKey,\r
3673 IN UINTN PeerPublicKeySize,\r
3674 OUT UINT8 *Key,\r
3675 IN OUT UINTN *KeySize\r
3676 )\r
3677{\r
3678 return CALL_BASECRYPTLIB (Dh.Services.ComputeKey, DhComputeKey, (DhContext, PeerPublicKey, PeerPublicKeySize, Key, KeySize), FALSE);\r
3679}\r
3680\r
7c342378 3681// =====================================================================================\r
cc1d13c9 3682// Pseudo-Random Generation Primitive\r
7c342378 3683// =====================================================================================\r
cc1d13c9
MK
3684\r
3685/**\r
3686 Sets up the seed value for the pseudorandom number generator.\r
3687\r
3688 This function sets up the seed value for the pseudorandom number generator.\r
3689 If Seed is not NULL, then the seed passed in is used.\r
3690 If Seed is NULL, then default seed is used.\r
3691 If this interface is not supported, then return FALSE.\r
3692\r
3693 @param[in] Seed Pointer to seed value.\r
3694 If NULL, default seed is used.\r
3695 @param[in] SeedSize Size of seed value.\r
3696 If Seed is NULL, this parameter is ignored.\r
3697\r
3698 @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r
3699 @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r
3700 @retval FALSE This interface is not supported.\r
3701\r
3702**/\r
3703BOOLEAN\r
3704EFIAPI\r
3705CryptoServiceRandomSeed (\r
3706 IN CONST UINT8 *Seed OPTIONAL,\r
3707 IN UINTN SeedSize\r
3708 )\r
3709{\r
3710 return CALL_BASECRYPTLIB (Random.Services.Seed, RandomSeed, (Seed, SeedSize), FALSE);\r
3711}\r
3712\r
3713/**\r
3714 Generates a pseudorandom byte stream of the specified size.\r
3715\r
3716 If Output is NULL, then return FALSE.\r
3717 If this interface is not supported, then return FALSE.\r
3718\r
3719 @param[out] Output Pointer to buffer to receive random value.\r
3720 @param[in] Size Size of random bytes to generate.\r
3721\r
3722 @retval TRUE Pseudorandom byte stream generated successfully.\r
3723 @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r
3724 @retval FALSE This interface is not supported.\r
3725\r
3726**/\r
3727BOOLEAN\r
3728EFIAPI\r
3729CryptoServiceRandomBytes (\r
3730 OUT UINT8 *Output,\r
3731 IN UINTN Size\r
3732 )\r
3733{\r
3734 return CALL_BASECRYPTLIB (Random.Services.Bytes, RandomBytes, (Output, Size), FALSE);\r
3735}\r
3736\r
7c342378 3737// =====================================================================================\r
cc1d13c9 3738// Key Derivation Function Primitive\r
7c342378 3739// =====================================================================================\r
cc1d13c9
MK
3740\r
3741/**\r
3742 Derive key data using HMAC-SHA256 based KDF.\r
3743\r
3744 @param[in] Key Pointer to the user-supplied key.\r
3745 @param[in] KeySize Key size in bytes.\r
3746 @param[in] Salt Pointer to the salt(non-secret) value.\r
3747 @param[in] SaltSize Salt size in bytes.\r
3748 @param[in] Info Pointer to the application specific info.\r
3749 @param[in] InfoSize Info size in bytes.\r
3750 @param[out] Out Pointer to buffer to receive hkdf value.\r
3751 @param[in] OutSize Size of hkdf bytes to generate.\r
3752\r
3753 @retval TRUE Hkdf generated successfully.\r
3754 @retval FALSE Hkdf generation failed.\r
3755\r
3756**/\r
3757BOOLEAN\r
3758EFIAPI\r
3759CryptoServiceHkdfSha256ExtractAndExpand (\r
3760 IN CONST UINT8 *Key,\r
3761 IN UINTN KeySize,\r
3762 IN CONST UINT8 *Salt,\r
3763 IN UINTN SaltSize,\r
3764 IN CONST UINT8 *Info,\r
3765 IN UINTN InfoSize,\r
3766 OUT UINT8 *Out,\r
3767 IN UINTN OutSize\r
3768 )\r
3769{\r
3770 return CALL_BASECRYPTLIB (Hkdf.Services.Sha256ExtractAndExpand, HkdfSha256ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);\r
3771}\r
3772\r
e919c390
QZ
3773/**\r
3774 Derive SHA256 HMAC-based Extract key Derivation Function (HKDF).\r
3775\r
3776 @param[in] Key Pointer to the user-supplied key.\r
3777 @param[in] KeySize key size in bytes.\r
3778 @param[in] Salt Pointer to the salt(non-secret) value.\r
3779 @param[in] SaltSize salt size in bytes.\r
3780 @param[out] PrkOut Pointer to buffer to receive hkdf value.\r
3781 @param[in] PrkOutSize size of hkdf bytes to generate.\r
3782\r
3783 @retval true Hkdf generated successfully.\r
3784 @retval false Hkdf generation failed.\r
3785\r
3786**/\r
3787BOOLEAN\r
3788EFIAPI\r
3789CryptoServiceHkdfSha256Extract (\r
3790 IN CONST UINT8 *Key,\r
3791 IN UINTN KeySize,\r
3792 IN CONST UINT8 *Salt,\r
3793 IN UINTN SaltSize,\r
3794 OUT UINT8 *PrkOut,\r
3795 UINTN PrkOutSize\r
3796 )\r
3797{\r
3798 return CALL_BASECRYPTLIB (Hkdf.Services.Sha256Extract, HkdfSha256Extract, (Key, KeySize, Salt, SaltSize, PrkOut, PrkOutSize), FALSE);\r
3799}\r
3800\r
3801/**\r
3802 Derive SHA256 HMAC-based Expand Key Derivation Function (HKDF).\r
3803\r
3804 @param[in] Prk Pointer to the user-supplied key.\r
3805 @param[in] PrkSize Key size in bytes.\r
3806 @param[in] Info Pointer to the application specific info.\r
3807 @param[in] InfoSize Info size in bytes.\r
3808 @param[out] Out Pointer to buffer to receive hkdf value.\r
3809 @param[in] OutSize Size of hkdf bytes to generate.\r
3810\r
3811 @retval TRUE Hkdf generated successfully.\r
3812 @retval FALSE Hkdf generation failed.\r
3813\r
3814**/\r
3815BOOLEAN\r
3816EFIAPI\r
3817CryptoServiceHkdfSha256Expand (\r
3818 IN CONST UINT8 *Prk,\r
3819 IN UINTN PrkSize,\r
3820 IN CONST UINT8 *Info,\r
3821 IN UINTN InfoSize,\r
3822 OUT UINT8 *Out,\r
3823 IN UINTN OutSize\r
3824 )\r
3825{\r
3826 return CALL_BASECRYPTLIB (Hkdf.Services.Sha256Expand, HkdfSha256Expand, (Prk, PrkSize, Info, InfoSize, Out, OutSize), FALSE);\r
3827}\r
3828\r
3829/**\r
3830 Derive SHA384 HMAC-based Extract-and-Expand Key Derivation Function (HKDF).\r
3831\r
3832 @param[in] Key Pointer to the user-supplied key.\r
3833 @param[in] KeySize Key size in bytes.\r
3834 @param[in] Salt Pointer to the salt(non-secret) value.\r
3835 @param[in] SaltSize Salt size in bytes.\r
3836 @param[in] Info Pointer to the application specific info.\r
3837 @param[in] InfoSize Info size in bytes.\r
3838 @param[out] Out Pointer to buffer to receive hkdf value.\r
3839 @param[in] OutSize Size of hkdf bytes to generate.\r
3840\r
3841 @retval TRUE Hkdf generated successfully.\r
3842 @retval FALSE Hkdf generation failed.\r
3843\r
3844**/\r
3845BOOLEAN\r
3846EFIAPI\r
3847CryptoServiceHkdfSha384ExtractAndExpand (\r
3848 IN CONST UINT8 *Key,\r
3849 IN UINTN KeySize,\r
3850 IN CONST UINT8 *Salt,\r
3851 IN UINTN SaltSize,\r
3852 IN CONST UINT8 *Info,\r
3853 IN UINTN InfoSize,\r
3854 OUT UINT8 *Out,\r
3855 IN UINTN OutSize\r
3856 )\r
3857{\r
3858 return CALL_BASECRYPTLIB (Hkdf.Services.Sha384ExtractAndExpand, HkdfSha384ExtractAndExpand, (Key, KeySize, Salt, SaltSize, Info, InfoSize, Out, OutSize), FALSE);\r
3859}\r
3860\r
3861/**\r
3862 Derive SHA384 HMAC-based Extract key Derivation Function (HKDF).\r
3863\r
3864 @param[in] Key Pointer to the user-supplied key.\r
3865 @param[in] KeySize key size in bytes.\r
3866 @param[in] Salt Pointer to the salt(non-secret) value.\r
3867 @param[in] SaltSize salt size in bytes.\r
3868 @param[out] PrkOut Pointer to buffer to receive hkdf value.\r
3869 @param[in] PrkOutSize size of hkdf bytes to generate.\r
3870\r
3871 @retval true Hkdf generated successfully.\r
3872 @retval false Hkdf generation failed.\r
3873\r
3874**/\r
3875BOOLEAN\r
3876EFIAPI\r
3877CryptoServiceHkdfSha384Extract (\r
3878 IN CONST UINT8 *Key,\r
3879 IN UINTN KeySize,\r
3880 IN CONST UINT8 *Salt,\r
3881 IN UINTN SaltSize,\r
3882 OUT UINT8 *PrkOut,\r
3883 UINTN PrkOutSize\r
3884 )\r
3885{\r
3886 return CALL_BASECRYPTLIB (Hkdf.Services.Sha384Extract, HkdfSha384Extract, (Key, KeySize, Salt, SaltSize, PrkOut, PrkOutSize), FALSE);\r
3887}\r
3888\r
3889/**\r
3890 Derive SHA384 HMAC-based Expand Key Derivation Function (HKDF).\r
3891\r
3892 @param[in] Prk Pointer to the user-supplied key.\r
3893 @param[in] PrkSize Key size in bytes.\r
3894 @param[in] Info Pointer to the application specific info.\r
3895 @param[in] InfoSize Info size in bytes.\r
3896 @param[out] Out Pointer to buffer to receive hkdf value.\r
3897 @param[in] OutSize Size of hkdf bytes to generate.\r
3898\r
3899 @retval TRUE Hkdf generated successfully.\r
3900 @retval FALSE Hkdf generation failed.\r
3901\r
3902**/\r
3903BOOLEAN\r
3904EFIAPI\r
3905CryptoServiceHkdfSha384Expand (\r
3906 IN CONST UINT8 *Prk,\r
3907 IN UINTN PrkSize,\r
3908 IN CONST UINT8 *Info,\r
3909 IN UINTN InfoSize,\r
3910 OUT UINT8 *Out,\r
3911 IN UINTN OutSize\r
3912 )\r
3913{\r
3914 return CALL_BASECRYPTLIB (Hkdf.Services.Sha384Expand, HkdfSha384Expand, (Prk, PrkSize, Info, InfoSize, Out, OutSize), FALSE);\r
3915}\r
3916\r
cc1d13c9
MK
3917/**\r
3918 Initializes the OpenSSL library.\r
3919\r
3920 This function registers ciphers and digests used directly and indirectly\r
3921 by SSL/TLS, and initializes the readable error messages.\r
3922 This function must be called before any other action takes places.\r
3923\r
3924 @retval TRUE The OpenSSL library has been initialized.\r
3925 @retval FALSE Failed to initialize the OpenSSL library.\r
3926\r
3927**/\r
3928BOOLEAN\r
3929EFIAPI\r
3930CryptoServiceTlsInitialize (\r
3931 VOID\r
3932 )\r
3933{\r
3934 return CALL_BASECRYPTLIB (Tls.Services.Initialize, TlsInitialize, (), FALSE);\r
3935}\r
3936\r
3937/**\r
3938 Free an allocated SSL_CTX object.\r
3939\r
3940 @param[in] TlsCtx Pointer to the SSL_CTX object to be released.\r
3941\r
3942**/\r
3943VOID\r
3944EFIAPI\r
3945CryptoServiceTlsCtxFree (\r
7c342378 3946 IN VOID *TlsCtx\r
cc1d13c9
MK
3947 )\r
3948{\r
3949 CALL_VOID_BASECRYPTLIB (Tls.Services.CtxFree, TlsCtxFree, (TlsCtx));\r
3950}\r
3951\r
3952/**\r
3953 Creates a new SSL_CTX object as framework to establish TLS/SSL enabled\r
3954 connections.\r
3955\r
3956 @param[in] MajorVer Major Version of TLS/SSL Protocol.\r
3957 @param[in] MinorVer Minor Version of TLS/SSL Protocol.\r
3958\r
3959 @return Pointer to an allocated SSL_CTX object.\r
3960 If the creation failed, TlsCtxNew() returns NULL.\r
3961\r
3962**/\r
3963VOID *\r
3964EFIAPI\r
3965CryptoServiceTlsCtxNew (\r
7c342378
MK
3966 IN UINT8 MajorVer,\r
3967 IN UINT8 MinorVer\r
cc1d13c9
MK
3968 )\r
3969{\r
3970 return CALL_BASECRYPTLIB (Tls.Services.CtxNew, TlsCtxNew, (MajorVer, MinorVer), NULL);\r
3971}\r
3972\r
3973/**\r
3974 Free an allocated TLS object.\r
3975\r
3976 This function removes the TLS object pointed to by Tls and frees up the\r
3977 allocated memory. If Tls is NULL, nothing is done.\r
3978\r
3979 @param[in] Tls Pointer to the TLS object to be freed.\r
3980\r
3981**/\r
3982VOID\r
3983EFIAPI\r
3984CryptoServiceTlsFree (\r
7c342378 3985 IN VOID *Tls\r
cc1d13c9
MK
3986 )\r
3987{\r
3988 CALL_VOID_BASECRYPTLIB (Tls.Services.Free, TlsFree, (Tls));\r
3989}\r
3990\r
3991/**\r
3992 Create a new TLS object for a connection.\r
3993\r
3994 This function creates a new TLS object for a connection. The new object\r
3995 inherits the setting of the underlying context TlsCtx: connection method,\r
3996 options, verification setting.\r
3997\r
3998 @param[in] TlsCtx Pointer to the SSL_CTX object.\r
3999\r
4000 @return Pointer to an allocated SSL object.\r
4001 If the creation failed, TlsNew() returns NULL.\r
4002\r
4003**/\r
4004VOID *\r
4005EFIAPI\r
4006CryptoServiceTlsNew (\r
7c342378 4007 IN VOID *TlsCtx\r
cc1d13c9
MK
4008 )\r
4009{\r
4010 return CALL_BASECRYPTLIB (Tls.Services.New, TlsNew, (TlsCtx), NULL);\r
4011}\r
4012\r
4013/**\r
4014 Checks if the TLS handshake was done.\r
4015\r
4016 This function will check if the specified TLS handshake was done.\r
4017\r
4018 @param[in] Tls Pointer to the TLS object for handshake state checking.\r
4019\r
4020 @retval TRUE The TLS handshake was done.\r
4021 @retval FALSE The TLS handshake was not done.\r
4022\r
4023**/\r
4024BOOLEAN\r
4025EFIAPI\r
4026CryptoServiceTlsInHandshake (\r
7c342378 4027 IN VOID *Tls\r
cc1d13c9
MK
4028 )\r
4029{\r
4030 return CALL_BASECRYPTLIB (Tls.Services.InHandshake, TlsInHandshake, (Tls), FALSE);\r
4031}\r
4032\r
4033/**\r
4034 Perform a TLS/SSL handshake.\r
4035\r
4036 This function will perform a TLS/SSL handshake.\r
4037\r
4038 @param[in] Tls Pointer to the TLS object for handshake operation.\r
4039 @param[in] BufferIn Pointer to the most recently received TLS Handshake packet.\r
4040 @param[in] BufferInSize Packet size in bytes for the most recently received TLS\r
4041 Handshake packet.\r
4042 @param[out] BufferOut Pointer to the buffer to hold the built packet.\r
4043 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is\r
4044 the buffer size provided by the caller. On output, it\r
4045 is the buffer size in fact needed to contain the\r
4046 packet.\r
4047\r
4048 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
4049 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
4050 Tls is NULL.\r
4051 BufferIn is NULL but BufferInSize is NOT 0.\r
4052 BufferInSize is 0 but BufferIn is NOT NULL.\r
4053 BufferOutSize is NULL.\r
4054 BufferOut is NULL if *BufferOutSize is not zero.\r
4055 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.\r
4056 @retval EFI_ABORTED Something wrong during handshake.\r
4057\r
4058**/\r
4059EFI_STATUS\r
4060EFIAPI\r
4061CryptoServiceTlsDoHandshake (\r
7c342378
MK
4062 IN VOID *Tls,\r
4063 IN UINT8 *BufferIn OPTIONAL,\r
4064 IN UINTN BufferInSize OPTIONAL,\r
4065 OUT UINT8 *BufferOut OPTIONAL,\r
4066 IN OUT UINTN *BufferOutSize\r
cc1d13c9
MK
4067 )\r
4068{\r
4069 return CALL_BASECRYPTLIB (Tls.Services.DoHandshake, TlsDoHandshake, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);\r
4070}\r
4071\r
4072/**\r
4073 Handle Alert message recorded in BufferIn. If BufferIn is NULL and BufferInSize is zero,\r
4074 TLS session has errors and the response packet needs to be Alert message based on error type.\r
4075\r
4076 @param[in] Tls Pointer to the TLS object for state checking.\r
4077 @param[in] BufferIn Pointer to the most recently received TLS Alert packet.\r
4078 @param[in] BufferInSize Packet size in bytes for the most recently received TLS\r
4079 Alert packet.\r
4080 @param[out] BufferOut Pointer to the buffer to hold the built packet.\r
4081 @param[in, out] BufferOutSize Pointer to the buffer size in bytes. On input, it is\r
4082 the buffer size provided by the caller. On output, it\r
4083 is the buffer size in fact needed to contain the\r
4084 packet.\r
4085\r
4086 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
4087 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
4088 Tls is NULL.\r
4089 BufferIn is NULL but BufferInSize is NOT 0.\r
4090 BufferInSize is 0 but BufferIn is NOT NULL.\r
4091 BufferOutSize is NULL.\r
4092 BufferOut is NULL if *BufferOutSize is not zero.\r
4093 @retval EFI_ABORTED An error occurred.\r
4094 @retval EFI_BUFFER_TOO_SMALL BufferOutSize is too small to hold the response packet.\r
4095\r
4096**/\r
4097EFI_STATUS\r
4098EFIAPI\r
4099CryptoServiceTlsHandleAlert (\r
7c342378
MK
4100 IN VOID *Tls,\r
4101 IN UINT8 *BufferIn OPTIONAL,\r
4102 IN UINTN BufferInSize OPTIONAL,\r
4103 OUT UINT8 *BufferOut OPTIONAL,\r
4104 IN OUT UINTN *BufferOutSize\r
cc1d13c9
MK
4105 )\r
4106{\r
4107 return CALL_BASECRYPTLIB (Tls.Services.HandleAlert, TlsHandleAlert, (Tls, BufferIn, BufferInSize, BufferOut, BufferOutSize), EFI_UNSUPPORTED);\r
4108}\r
4109\r
4110/**\r
4111 Build the CloseNotify packet.\r
4112\r
4113 @param[in] Tls Pointer to the TLS object for state checking.\r
4114 @param[in, out] Buffer Pointer to the buffer to hold the built packet.\r
4115 @param[in, out] BufferSize Pointer to the buffer size in bytes. On input, it is\r
4116 the buffer size provided by the caller. On output, it\r
4117 is the buffer size in fact needed to contain the\r
4118 packet.\r
4119\r
4120 @retval EFI_SUCCESS The required TLS packet is built successfully.\r
4121 @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
4122 Tls is NULL.\r
4123 BufferSize is NULL.\r
4124 Buffer is NULL if *BufferSize is not zero.\r
4125 @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to hold the response packet.\r
4126\r
4127**/\r
4128EFI_STATUS\r
4129EFIAPI\r
4130CryptoServiceTlsCloseNotify (\r
7c342378
MK
4131 IN VOID *Tls,\r
4132 IN OUT UINT8 *Buffer,\r
4133 IN OUT UINTN *BufferSize\r
cc1d13c9
MK
4134 )\r
4135{\r
4136 return CALL_BASECRYPTLIB (Tls.Services.CloseNotify, TlsCloseNotify, (Tls, Buffer, BufferSize), EFI_UNSUPPORTED);\r
4137}\r
4138\r
4139/**\r
4140 Attempts to read bytes from one TLS object and places the data in Buffer.\r
4141\r
4142 This function will attempt to read BufferSize bytes from the TLS object\r
4143 and places the data in Buffer.\r
4144\r
4145 @param[in] Tls Pointer to the TLS object.\r
4146 @param[in,out] Buffer Pointer to the buffer to store the data.\r
4147 @param[in] BufferSize The size of Buffer in bytes.\r
4148\r
4149 @retval >0 The amount of data successfully read from the TLS object.\r
4150 @retval <=0 No data was successfully read.\r
4151\r
4152**/\r
4153INTN\r
4154EFIAPI\r
4155CryptoServiceTlsCtrlTrafficOut (\r
7c342378
MK
4156 IN VOID *Tls,\r
4157 IN OUT VOID *Buffer,\r
4158 IN UINTN BufferSize\r
cc1d13c9
MK
4159 )\r
4160{\r
4161 return CALL_BASECRYPTLIB (Tls.Services.CtrlTrafficOut, TlsCtrlTrafficOut, (Tls, Buffer, BufferSize), 0);\r
4162}\r
4163\r
4164/**\r
4165 Attempts to write data from the buffer to TLS object.\r
4166\r
4167 This function will attempt to write BufferSize bytes data from the Buffer\r
4168 to the TLS object.\r
4169\r
4170 @param[in] Tls Pointer to the TLS object.\r
4171 @param[in] Buffer Pointer to the data buffer.\r
4172 @param[in] BufferSize The size of Buffer in bytes.\r
4173\r
4174 @retval >0 The amount of data successfully written to the TLS object.\r
4175 @retval <=0 No data was successfully written.\r
4176\r
4177**/\r
4178INTN\r
4179EFIAPI\r
4180CryptoServiceTlsCtrlTrafficIn (\r
7c342378
MK
4181 IN VOID *Tls,\r
4182 IN VOID *Buffer,\r
4183 IN UINTN BufferSize\r
cc1d13c9
MK
4184 )\r
4185{\r
4186 return CALL_BASECRYPTLIB (Tls.Services.CtrlTrafficIn, TlsCtrlTrafficIn, (Tls, Buffer, BufferSize), 0);\r
4187}\r
4188\r
4189/**\r
4190 Attempts to read bytes from the specified TLS connection into the buffer.\r
4191\r
4192 This function tries to read BufferSize bytes data from the specified TLS\r
4193 connection into the Buffer.\r
4194\r
4195 @param[in] Tls Pointer to the TLS connection for data reading.\r
4196 @param[in,out] Buffer Pointer to the data buffer.\r
4197 @param[in] BufferSize The size of Buffer in bytes.\r
4198\r
4199 @retval >0 The read operation was successful, and return value is the\r
4200 number of bytes actually read from the TLS connection.\r
4201 @retval <=0 The read operation was not successful.\r
4202\r
4203**/\r
4204INTN\r
4205EFIAPI\r
4206CryptoServiceTlsRead (\r
7c342378
MK
4207 IN VOID *Tls,\r
4208 IN OUT VOID *Buffer,\r
4209 IN UINTN BufferSize\r
cc1d13c9
MK
4210 )\r
4211{\r
4212 return CALL_BASECRYPTLIB (Tls.Services.Read, TlsRead, (Tls, Buffer, BufferSize), 0);\r
4213}\r
4214\r
4215/**\r
4216 Attempts to write data to a TLS connection.\r
4217\r
4218 This function tries to write BufferSize bytes data from the Buffer into the\r
4219 specified TLS connection.\r
4220\r
4221 @param[in] Tls Pointer to the TLS connection for data writing.\r
4222 @param[in] Buffer Pointer to the data buffer.\r
4223 @param[in] BufferSize The size of Buffer in bytes.\r
4224\r
4225 @retval >0 The write operation was successful, and return value is the\r
4226 number of bytes actually written to the TLS connection.\r
4227 @retval <=0 The write operation was not successful.\r
4228\r
4229**/\r
4230INTN\r
4231EFIAPI\r
4232CryptoServiceTlsWrite (\r
7c342378
MK
4233 IN VOID *Tls,\r
4234 IN VOID *Buffer,\r
4235 IN UINTN BufferSize\r
cc1d13c9
MK
4236 )\r
4237{\r
4238 return CALL_BASECRYPTLIB (Tls.Services.Write, TlsWrite, (Tls, Buffer, BufferSize), 0);\r
4239}\r
4240\r
8db4e9f9
YL
4241/**\r
4242 Shutdown a TLS connection.\r
4243\r
4244 Shutdown the TLS connection without releasing the resources, meaning a new\r
4245 connection can be started without calling TlsNew() and without setting\r
4246 certificates etc.\r
4247\r
4248 @param[in] Tls Pointer to the TLS object to shutdown.\r
4249\r
4250 @retval EFI_SUCCESS The TLS is shutdown successfully.\r
4251 @retval EFI_INVALID_PARAMETER Tls is NULL.\r
4252 @retval EFI_PROTOCOL_ERROR Some other error occurred.\r
4253**/\r
4254EFI_STATUS\r
4255EFIAPI\r
4256CryptoServiceTlsShutdown (\r
4257 IN VOID *Tls\r
4258 )\r
4259{\r
4260 return CALL_BASECRYPTLIB (Tls.Services.Shutdown, TlsShutdown, (Tls), EFI_UNSUPPORTED);\r
4261}\r
4262\r
cc1d13c9
MK
4263/**\r
4264 Set a new TLS/SSL method for a particular TLS object.\r
4265\r
4266 This function sets a new TLS/SSL method for a particular TLS object.\r
4267\r
4268 @param[in] Tls Pointer to a TLS object.\r
4269 @param[in] MajorVer Major Version of TLS/SSL Protocol.\r
4270 @param[in] MinorVer Minor Version of TLS/SSL Protocol.\r
4271\r
4272 @retval EFI_SUCCESS The TLS/SSL method was set successfully.\r
4273 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4274 @retval EFI_UNSUPPORTED Unsupported TLS/SSL method.\r
4275\r
4276**/\r
4277EFI_STATUS\r
4278EFIAPI\r
4279CryptoServiceTlsSetVersion (\r
7c342378
MK
4280 IN VOID *Tls,\r
4281 IN UINT8 MajorVer,\r
4282 IN UINT8 MinorVer\r
cc1d13c9
MK
4283 )\r
4284{\r
4285 return CALL_BASECRYPTLIB (TlsSet.Services.Version, TlsSetVersion, (Tls, MajorVer, MinorVer), EFI_UNSUPPORTED);\r
4286}\r
4287\r
4288/**\r
4289 Set TLS object to work in client or server mode.\r
4290\r
4291 This function prepares a TLS object to work in client or server mode.\r
4292\r
4293 @param[in] Tls Pointer to a TLS object.\r
4294 @param[in] IsServer Work in server mode.\r
4295\r
4296 @retval EFI_SUCCESS The TLS/SSL work mode was set successfully.\r
4297 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4298 @retval EFI_UNSUPPORTED Unsupported TLS/SSL work mode.\r
4299\r
4300**/\r
4301EFI_STATUS\r
4302EFIAPI\r
4303CryptoServiceTlsSetConnectionEnd (\r
7c342378
MK
4304 IN VOID *Tls,\r
4305 IN BOOLEAN IsServer\r
cc1d13c9
MK
4306 )\r
4307{\r
4308 return CALL_BASECRYPTLIB (TlsSet.Services.ConnectionEnd, TlsSetConnectionEnd, (Tls, IsServer), EFI_UNSUPPORTED);\r
4309}\r
4310\r
4311/**\r
4312 Set the ciphers list to be used by the TLS object.\r
4313\r
4314 This function sets the ciphers for use by a specified TLS object.\r
4315\r
4316 @param[in] Tls Pointer to a TLS object.\r
4317 @param[in] CipherId Array of UINT16 cipher identifiers. Each UINT16\r
4318 cipher identifier comes from the TLS Cipher Suite\r
4319 Registry of the IANA, interpreting Byte1 and Byte2\r
4320 in network (big endian) byte order.\r
4321 @param[in] CipherNum The number of cipher in the list.\r
4322\r
4323 @retval EFI_SUCCESS The ciphers list was set successfully.\r
4324 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4325 @retval EFI_UNSUPPORTED No supported TLS cipher was found in CipherId.\r
4326 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
4327\r
4328**/\r
4329EFI_STATUS\r
4330EFIAPI\r
4331CryptoServiceTlsSetCipherList (\r
7c342378
MK
4332 IN VOID *Tls,\r
4333 IN UINT16 *CipherId,\r
4334 IN UINTN CipherNum\r
cc1d13c9
MK
4335 )\r
4336{\r
4337 return CALL_BASECRYPTLIB (TlsSet.Services.CipherList, TlsSetCipherList, (Tls, CipherId, CipherNum), EFI_UNSUPPORTED);\r
4338}\r
4339\r
4340/**\r
4341 Set the compression method for TLS/SSL operations.\r
4342\r
4343 This function handles TLS/SSL integrated compression methods.\r
4344\r
4345 @param[in] CompMethod The compression method ID.\r
4346\r
4347 @retval EFI_SUCCESS The compression method for the communication was\r
4348 set successfully.\r
4349 @retval EFI_UNSUPPORTED Unsupported compression method.\r
4350\r
4351**/\r
4352EFI_STATUS\r
4353EFIAPI\r
4354CryptoServiceTlsSetCompressionMethod (\r
7c342378 4355 IN UINT8 CompMethod\r
cc1d13c9
MK
4356 )\r
4357{\r
4358 return CALL_BASECRYPTLIB (TlsSet.Services.CompressionMethod, TlsSetCompressionMethod, (CompMethod), EFI_UNSUPPORTED);\r
4359}\r
4360\r
4361/**\r
4362 Set peer certificate verification mode for the TLS connection.\r
4363\r
4364 This function sets the verification mode flags for the TLS connection.\r
4365\r
4366 @param[in] Tls Pointer to the TLS object.\r
4367 @param[in] VerifyMode A set of logically or'ed verification mode flags.\r
4368\r
4369**/\r
4370VOID\r
4371EFIAPI\r
4372CryptoServiceTlsSetVerify (\r
7c342378
MK
4373 IN VOID *Tls,\r
4374 IN UINT32 VerifyMode\r
cc1d13c9
MK
4375 )\r
4376{\r
4377 CALL_VOID_BASECRYPTLIB (TlsSet.Services.Verify, TlsSetVerify, (Tls, VerifyMode));\r
4378}\r
4379\r
4380/**\r
4381 Set the specified host name to be verified.\r
4382\r
4383 @param[in] Tls Pointer to the TLS object.\r
4384 @param[in] Flags The setting flags during the validation.\r
4385 @param[in] HostName The specified host name to be verified.\r
4386\r
4387 @retval EFI_SUCCESS The HostName setting was set successfully.\r
4388 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4389 @retval EFI_ABORTED Invalid HostName setting.\r
4390\r
4391**/\r
4392EFI_STATUS\r
4393EFIAPI\r
4394CryptoServiceTlsSetVerifyHost (\r
7c342378
MK
4395 IN VOID *Tls,\r
4396 IN UINT32 Flags,\r
4397 IN CHAR8 *HostName\r
cc1d13c9
MK
4398 )\r
4399{\r
4400 return CALL_BASECRYPTLIB (TlsSet.Services.VerifyHost, TlsSetVerifyHost, (Tls, Flags, HostName), EFI_UNSUPPORTED);\r
4401}\r
4402\r
4403/**\r
4404 Sets a TLS/SSL session ID to be used during TLS/SSL connect.\r
4405\r
4406 This function sets a session ID to be used when the TLS/SSL connection is\r
4407 to be established.\r
4408\r
4409 @param[in] Tls Pointer to the TLS object.\r
4410 @param[in] SessionId Session ID data used for session resumption.\r
4411 @param[in] SessionIdLen Length of Session ID in bytes.\r
4412\r
4413 @retval EFI_SUCCESS Session ID was set successfully.\r
4414 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4415 @retval EFI_UNSUPPORTED No available session for ID setting.\r
4416\r
4417**/\r
4418EFI_STATUS\r
4419EFIAPI\r
4420CryptoServiceTlsSetSessionId (\r
7c342378
MK
4421 IN VOID *Tls,\r
4422 IN UINT8 *SessionId,\r
4423 IN UINT16 SessionIdLen\r
cc1d13c9
MK
4424 )\r
4425{\r
4426 return CALL_BASECRYPTLIB (TlsSet.Services.SessionId, TlsSetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);\r
4427}\r
4428\r
4429/**\r
4430 Adds the CA to the cert store when requesting Server or Client authentication.\r
4431\r
4432 This function adds the CA certificate to the list of CAs when requesting\r
4433 Server or Client authentication for the chosen TLS connection.\r
4434\r
4435 @param[in] Tls Pointer to the TLS object.\r
4436 @param[in] Data Pointer to the data buffer of a DER-encoded binary\r
4437 X.509 certificate or PEM-encoded X.509 certificate.\r
4438 @param[in] DataSize The size of data buffer in bytes.\r
4439\r
4440 @retval EFI_SUCCESS The operation succeeded.\r
4441 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4442 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.\r
4443 @retval EFI_ABORTED Invalid X.509 certificate.\r
4444\r
4445**/\r
4446EFI_STATUS\r
4447EFIAPI\r
4448CryptoServiceTlsSetCaCertificate (\r
7c342378
MK
4449 IN VOID *Tls,\r
4450 IN VOID *Data,\r
4451 IN UINTN DataSize\r
cc1d13c9
MK
4452 )\r
4453{\r
4454 return CALL_BASECRYPTLIB (TlsSet.Services.CaCertificate, TlsSetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4455}\r
4456\r
4457/**\r
4458 Loads the local public certificate into the specified TLS object.\r
4459\r
4460 This function loads the X.509 certificate into the specified TLS object\r
4461 for TLS negotiation.\r
4462\r
4463 @param[in] Tls Pointer to the TLS object.\r
4464 @param[in] Data Pointer to the data buffer of a DER-encoded binary\r
4465 X.509 certificate or PEM-encoded X.509 certificate.\r
4466 @param[in] DataSize The size of data buffer in bytes.\r
4467\r
4468 @retval EFI_SUCCESS The operation succeeded.\r
4469 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4470 @retval EFI_OUT_OF_RESOURCES Required resources could not be allocated.\r
4471 @retval EFI_ABORTED Invalid X.509 certificate.\r
4472\r
4473**/\r
4474EFI_STATUS\r
4475EFIAPI\r
4476CryptoServiceTlsSetHostPublicCert (\r
7c342378
MK
4477 IN VOID *Tls,\r
4478 IN VOID *Data,\r
4479 IN UINTN DataSize\r
cc1d13c9
MK
4480 )\r
4481{\r
4482 return CALL_BASECRYPTLIB (TlsSet.Services.HostPublicCert, TlsSetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4483}\r
4484\r
4485/**\r
4486 Adds the local private key to the specified TLS object.\r
4487\r
8db4e9f9
YL
4488 This function adds the local private key (DER-encoded or PEM-encoded or PKCS#8 private\r
4489 key) into the specified TLS object for TLS negotiation.\r
4490\r
4491 @param[in] Tls Pointer to the TLS object.\r
4492 @param[in] Data Pointer to the data buffer of a DER-encoded or PEM-encoded\r
4493 or PKCS#8 private key.\r
4494 @param[in] DataSize The size of data buffer in bytes.\r
4495 @param[in] Password Pointer to NULL-terminated private key password, set it to NULL\r
4496 if private key not encrypted.\r
4497\r
4498 @retval EFI_SUCCESS The operation succeeded.\r
4499 @retval EFI_UNSUPPORTED This function is not supported.\r
4500 @retval EFI_ABORTED Invalid private key data.\r
4501\r
4502**/\r
4503EFI_STATUS\r
4504EFIAPI\r
4505CryptoServiceTlsSetHostPrivateKeyEx (\r
4506 IN VOID *Tls,\r
4507 IN VOID *Data,\r
4508 IN UINTN DataSize,\r
4509 IN VOID *Password OPTIONAL\r
4510 )\r
4511{\r
4512 return CALL_BASECRYPTLIB (TlsSet.Services.HostPrivateKeyEx, TlsSetHostPrivateKeyEx, (Tls, Data, DataSize, Password), EFI_UNSUPPORTED);\r
4513}\r
4514\r
4515/**\r
4516 Adds the local private key to the specified TLS object.\r
4517\r
4518 This function adds the local private key (DER-encoded or PEM-encoded or PKCS#8 private\r
cc1d13c9
MK
4519 key) into the specified TLS object for TLS negotiation.\r
4520\r
4521 @param[in] Tls Pointer to the TLS object.\r
8db4e9f9 4522 @param[in] Data Pointer to the data buffer of a DER-encoded or PEM-encoded\r
cc1d13c9
MK
4523 or PKCS#8 private key.\r
4524 @param[in] DataSize The size of data buffer in bytes.\r
4525\r
4526 @retval EFI_SUCCESS The operation succeeded.\r
4527 @retval EFI_UNSUPPORTED This function is not supported.\r
4528 @retval EFI_ABORTED Invalid private key data.\r
4529\r
4530**/\r
4531EFI_STATUS\r
4532EFIAPI\r
4533CryptoServiceTlsSetHostPrivateKey (\r
7c342378
MK
4534 IN VOID *Tls,\r
4535 IN VOID *Data,\r
4536 IN UINTN DataSize\r
cc1d13c9
MK
4537 )\r
4538{\r
4539 return CALL_BASECRYPTLIB (TlsSet.Services.HostPrivateKey, TlsSetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4540}\r
4541\r
4542/**\r
4543 Adds the CA-supplied certificate revocation list for certificate validation.\r
4544\r
4545 This function adds the CA-supplied certificate revocation list data for\r
4546 certificate validity checking.\r
4547\r
4548 @param[in] Data Pointer to the data buffer of a DER-encoded CRL data.\r
4549 @param[in] DataSize The size of data buffer in bytes.\r
4550\r
4551 @retval EFI_SUCCESS The operation succeeded.\r
4552 @retval EFI_UNSUPPORTED This function is not supported.\r
4553 @retval EFI_ABORTED Invalid CRL data.\r
4554\r
4555**/\r
4556EFI_STATUS\r
4557EFIAPI\r
4558CryptoServiceTlsSetCertRevocationList (\r
7c342378
MK
4559 IN VOID *Data,\r
4560 IN UINTN DataSize\r
cc1d13c9
MK
4561 )\r
4562{\r
4563 return CALL_BASECRYPTLIB (TlsSet.Services.CertRevocationList, TlsSetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);\r
4564}\r
4565\r
8db4e9f9
YL
4566/**\r
4567 Set the signature algorithm list to used by the TLS object.\r
4568\r
4569 This function sets the signature algorithms for use by a specified TLS object.\r
4570\r
4571 @param[in] Tls Pointer to a TLS object.\r
4572 @param[in] Data Array of UINT8 of signature algorithms. The array consists of\r
4573 pairs of the hash algorithm and the signature algorithm as defined\r
4574 in RFC 5246\r
4575 @param[in] DataSize The length the SignatureAlgoList. Must be divisible by 2.\r
4576\r
4577 @retval EFI_SUCCESS The signature algorithm list was set successfully.\r
4578 @retval EFI_INVALID_PARAMETER The parameters are invalid.\r
4579 @retval EFI_UNSUPPORTED No supported TLS signature algorithm was found in SignatureAlgoList\r
4580 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
4581\r
4582**/\r
4583EFI_STATUS\r
4584EFIAPI\r
4585CryptoServiceTlsSetSignatureAlgoList (\r
4586 IN VOID *Tls,\r
4587 IN UINT8 *Data,\r
4588 IN UINTN DataSize\r
4589 )\r
4590{\r
4591 return CALL_BASECRYPTLIB (TlsSet.Services.SignatureAlgoList, TlsSetSignatureAlgoList, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4592}\r
4593\r
4594/**\r
4595 Set the EC curve to be used for TLS flows\r
4596\r
4597 This function sets the EC curve to be used for TLS flows.\r
4598\r
4599 @param[in] Tls Pointer to a TLS object.\r
4600 @param[in] Data An EC named curve as defined in section 5.1.1 of RFC 4492.\r
4601 @param[in] DataSize Size of Data, it should be sizeof (UINT32)\r
4602\r
4603 @retval EFI_SUCCESS The EC curve was set successfully.\r
4604 @retval EFI_INVALID_PARAMETER The parameters are invalid.\r
4605 @retval EFI_UNSUPPORTED The requested TLS EC curve is not supported\r
4606\r
4607**/\r
4608EFI_STATUS\r
4609EFIAPI\r
4610CryptoServiceTlsSetEcCurve (\r
4611 IN VOID *Tls,\r
4612 IN UINT8 *Data,\r
4613 IN UINTN DataSize\r
4614 )\r
4615{\r
4616 return CALL_BASECRYPTLIB (TlsSet.Services.EcCurve, TlsSetEcCurve, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4617}\r
4618\r
cc1d13c9
MK
4619/**\r
4620 Gets the protocol version used by the specified TLS connection.\r
4621\r
4622 This function returns the protocol version used by the specified TLS\r
4623 connection.\r
4624\r
4625 If Tls is NULL, then ASSERT().\r
4626\r
4627 @param[in] Tls Pointer to the TLS object.\r
4628\r
4629 @return The protocol version of the specified TLS connection.\r
4630\r
4631**/\r
4632UINT16\r
4633EFIAPI\r
4634CryptoServiceTlsGetVersion (\r
7c342378 4635 IN VOID *Tls\r
cc1d13c9
MK
4636 )\r
4637{\r
4638 return CALL_BASECRYPTLIB (TlsGet.Services.Version, TlsGetVersion, (Tls), 0);\r
4639}\r
4640\r
4641/**\r
4642 Gets the connection end of the specified TLS connection.\r
4643\r
4644 This function returns the connection end (as client or as server) used by\r
4645 the specified TLS connection.\r
4646\r
4647 If Tls is NULL, then ASSERT().\r
4648\r
4649 @param[in] Tls Pointer to the TLS object.\r
4650\r
4651 @return The connection end used by the specified TLS connection.\r
4652\r
4653**/\r
4654UINT8\r
4655EFIAPI\r
4656CryptoServiceTlsGetConnectionEnd (\r
7c342378 4657 IN VOID *Tls\r
cc1d13c9
MK
4658 )\r
4659{\r
4660 return CALL_BASECRYPTLIB (TlsGet.Services.ConnectionEnd, TlsGetConnectionEnd, (Tls), 0);\r
4661}\r
4662\r
4663/**\r
4664 Gets the cipher suite used by the specified TLS connection.\r
4665\r
4666 This function returns current cipher suite used by the specified\r
4667 TLS connection.\r
4668\r
4669 @param[in] Tls Pointer to the TLS object.\r
4670 @param[in,out] CipherId The cipher suite used by the TLS object.\r
4671\r
4672 @retval EFI_SUCCESS The cipher suite was returned successfully.\r
4673 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4674 @retval EFI_UNSUPPORTED Unsupported cipher suite.\r
4675\r
4676**/\r
4677EFI_STATUS\r
4678EFIAPI\r
4679CryptoServiceTlsGetCurrentCipher (\r
7c342378
MK
4680 IN VOID *Tls,\r
4681 IN OUT UINT16 *CipherId\r
cc1d13c9
MK
4682 )\r
4683{\r
4684 return CALL_BASECRYPTLIB (TlsGet.Services.CurrentCipher, TlsGetCurrentCipher, (Tls, CipherId), EFI_UNSUPPORTED);\r
4685}\r
4686\r
4687/**\r
4688 Gets the compression methods used by the specified TLS connection.\r
4689\r
4690 This function returns current integrated compression methods used by\r
4691 the specified TLS connection.\r
4692\r
4693 @param[in] Tls Pointer to the TLS object.\r
4694 @param[in,out] CompressionId The current compression method used by\r
4695 the TLS object.\r
4696\r
4697 @retval EFI_SUCCESS The compression method was returned successfully.\r
4698 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4699 @retval EFI_ABORTED Invalid Compression method.\r
4700 @retval EFI_UNSUPPORTED This function is not supported.\r
4701\r
4702**/\r
4703EFI_STATUS\r
4704EFIAPI\r
4705CryptoServiceTlsGetCurrentCompressionId (\r
7c342378
MK
4706 IN VOID *Tls,\r
4707 IN OUT UINT8 *CompressionId\r
cc1d13c9
MK
4708 )\r
4709{\r
4710 return CALL_BASECRYPTLIB (TlsGet.Services.CurrentCompressionId, TlsGetCurrentCompressionId, (Tls, CompressionId), EFI_UNSUPPORTED);\r
4711}\r
4712\r
4713/**\r
4714 Gets the verification mode currently set in the TLS connection.\r
4715\r
4716 This function returns the peer verification mode currently set in the\r
4717 specified TLS connection.\r
4718\r
4719 If Tls is NULL, then ASSERT().\r
4720\r
4721 @param[in] Tls Pointer to the TLS object.\r
4722\r
4723 @return The verification mode set in the specified TLS connection.\r
4724\r
4725**/\r
4726UINT32\r
4727EFIAPI\r
4728CryptoServiceTlsGetVerify (\r
7c342378 4729 IN VOID *Tls\r
cc1d13c9
MK
4730 )\r
4731{\r
4732 return CALL_BASECRYPTLIB (TlsGet.Services.Verify, TlsGetVerify, (Tls), 0);\r
4733}\r
4734\r
4735/**\r
4736 Gets the session ID used by the specified TLS connection.\r
4737\r
4738 This function returns the TLS/SSL session ID currently used by the\r
4739 specified TLS connection.\r
4740\r
4741 @param[in] Tls Pointer to the TLS object.\r
4742 @param[in,out] SessionId Buffer to contain the returned session ID.\r
4743 @param[in,out] SessionIdLen The length of Session ID in bytes.\r
4744\r
4745 @retval EFI_SUCCESS The Session ID was returned successfully.\r
4746 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4747 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.\r
4748\r
4749**/\r
4750EFI_STATUS\r
4751EFIAPI\r
4752CryptoServiceTlsGetSessionId (\r
7c342378
MK
4753 IN VOID *Tls,\r
4754 IN OUT UINT8 *SessionId,\r
4755 IN OUT UINT16 *SessionIdLen\r
cc1d13c9
MK
4756 )\r
4757{\r
4758 return CALL_BASECRYPTLIB (TlsGet.Services.SessionId, TlsGetSessionId, (Tls, SessionId, SessionIdLen), EFI_UNSUPPORTED);\r
4759}\r
4760\r
4761/**\r
4762 Gets the client random data used in the specified TLS connection.\r
4763\r
4764 This function returns the TLS/SSL client random data currently used in\r
4765 the specified TLS connection.\r
4766\r
4767 @param[in] Tls Pointer to the TLS object.\r
4768 @param[in,out] ClientRandom Buffer to contain the returned client\r
4769 random data (32 bytes).\r
4770\r
4771**/\r
4772VOID\r
4773EFIAPI\r
4774CryptoServiceTlsGetClientRandom (\r
7c342378
MK
4775 IN VOID *Tls,\r
4776 IN OUT UINT8 *ClientRandom\r
cc1d13c9
MK
4777 )\r
4778{\r
4779 CALL_VOID_BASECRYPTLIB (TlsGet.Services.ClientRandom, TlsGetClientRandom, (Tls, ClientRandom));\r
4780}\r
4781\r
4782/**\r
4783 Gets the server random data used in the specified TLS connection.\r
4784\r
4785 This function returns the TLS/SSL server random data currently used in\r
4786 the specified TLS connection.\r
4787\r
4788 @param[in] Tls Pointer to the TLS object.\r
4789 @param[in,out] ServerRandom Buffer to contain the returned server\r
4790 random data (32 bytes).\r
4791\r
4792**/\r
4793VOID\r
4794EFIAPI\r
4795CryptoServiceTlsGetServerRandom (\r
7c342378
MK
4796 IN VOID *Tls,\r
4797 IN OUT UINT8 *ServerRandom\r
cc1d13c9
MK
4798 )\r
4799{\r
4800 CALL_VOID_BASECRYPTLIB (TlsGet.Services.ServerRandom, TlsGetServerRandom, (Tls, ServerRandom));\r
4801}\r
4802\r
4803/**\r
4804 Gets the master key data used in the specified TLS connection.\r
4805\r
4806 This function returns the TLS/SSL master key material currently used in\r
4807 the specified TLS connection.\r
4808\r
4809 @param[in] Tls Pointer to the TLS object.\r
4810 @param[in,out] KeyMaterial Buffer to contain the returned key material.\r
4811\r
4812 @retval EFI_SUCCESS Key material was returned successfully.\r
4813 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4814 @retval EFI_UNSUPPORTED Invalid TLS/SSL session.\r
4815\r
4816**/\r
4817EFI_STATUS\r
4818EFIAPI\r
4819CryptoServiceTlsGetKeyMaterial (\r
7c342378
MK
4820 IN VOID *Tls,\r
4821 IN OUT UINT8 *KeyMaterial\r
cc1d13c9
MK
4822 )\r
4823{\r
4824 return CALL_BASECRYPTLIB (TlsGet.Services.KeyMaterial, TlsGetKeyMaterial, (Tls, KeyMaterial), EFI_UNSUPPORTED);\r
4825}\r
4826\r
4827/**\r
4828 Gets the CA Certificate from the cert store.\r
4829\r
4830 This function returns the CA certificate for the chosen\r
4831 TLS connection.\r
4832\r
4833 @param[in] Tls Pointer to the TLS object.\r
4834 @param[out] Data Pointer to the data buffer to receive the CA\r
4835 certificate data sent to the client.\r
4836 @param[in,out] DataSize The size of data buffer in bytes.\r
4837\r
4838 @retval EFI_SUCCESS The operation succeeded.\r
4839 @retval EFI_UNSUPPORTED This function is not supported.\r
4840 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
4841\r
4842**/\r
4843EFI_STATUS\r
4844EFIAPI\r
4845CryptoServiceTlsGetCaCertificate (\r
7c342378
MK
4846 IN VOID *Tls,\r
4847 OUT VOID *Data,\r
4848 IN OUT UINTN *DataSize\r
cc1d13c9
MK
4849 )\r
4850{\r
4851 return CALL_BASECRYPTLIB (TlsGet.Services.CaCertificate, TlsGetCaCertificate, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4852}\r
4853\r
4854/**\r
4855 Gets the local public Certificate set in the specified TLS object.\r
4856\r
4857 This function returns the local public certificate which was currently set\r
4858 in the specified TLS object.\r
4859\r
4860 @param[in] Tls Pointer to the TLS object.\r
4861 @param[out] Data Pointer to the data buffer to receive the local\r
4862 public certificate.\r
4863 @param[in,out] DataSize The size of data buffer in bytes.\r
4864\r
4865 @retval EFI_SUCCESS The operation succeeded.\r
4866 @retval EFI_INVALID_PARAMETER The parameter is invalid.\r
4867 @retval EFI_NOT_FOUND The certificate is not found.\r
4868 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
4869\r
4870**/\r
4871EFI_STATUS\r
4872EFIAPI\r
4873CryptoServiceTlsGetHostPublicCert (\r
7c342378
MK
4874 IN VOID *Tls,\r
4875 OUT VOID *Data,\r
4876 IN OUT UINTN *DataSize\r
cc1d13c9
MK
4877 )\r
4878{\r
4879 return CALL_BASECRYPTLIB (TlsGet.Services.HostPublicCert, TlsGetHostPublicCert, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4880}\r
4881\r
4882/**\r
4883 Gets the local private key set in the specified TLS object.\r
4884\r
4885 This function returns the local private key data which was currently set\r
4886 in the specified TLS object.\r
4887\r
4888 @param[in] Tls Pointer to the TLS object.\r
4889 @param[out] Data Pointer to the data buffer to receive the local\r
4890 private key data.\r
4891 @param[in,out] DataSize The size of data buffer in bytes.\r
4892\r
4893 @retval EFI_SUCCESS The operation succeeded.\r
4894 @retval EFI_UNSUPPORTED This function is not supported.\r
4895 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
4896\r
4897**/\r
4898EFI_STATUS\r
4899EFIAPI\r
4900CryptoServiceTlsGetHostPrivateKey (\r
7c342378
MK
4901 IN VOID *Tls,\r
4902 OUT VOID *Data,\r
4903 IN OUT UINTN *DataSize\r
cc1d13c9
MK
4904 )\r
4905{\r
4906 return CALL_BASECRYPTLIB (TlsGet.Services.HostPrivateKey, TlsGetHostPrivateKey, (Tls, Data, DataSize), EFI_UNSUPPORTED);\r
4907}\r
4908\r
4909/**\r
4910 Gets the CA-supplied certificate revocation list data set in the specified\r
4911 TLS object.\r
4912\r
4913 This function returns the CA-supplied certificate revocation list data which\r
4914 was currently set in the specified TLS object.\r
4915\r
4916 @param[out] Data Pointer to the data buffer to receive the CRL data.\r
4917 @param[in,out] DataSize The size of data buffer in bytes.\r
4918\r
4919 @retval EFI_SUCCESS The operation succeeded.\r
4920 @retval EFI_UNSUPPORTED This function is not supported.\r
4921 @retval EFI_BUFFER_TOO_SMALL The Data is too small to hold the data.\r
4922\r
4923**/\r
4924EFI_STATUS\r
4925EFIAPI\r
4926CryptoServiceTlsGetCertRevocationList (\r
7c342378
MK
4927 OUT VOID *Data,\r
4928 IN OUT UINTN *DataSize\r
cc1d13c9
MK
4929 )\r
4930{\r
4931 return CALL_BASECRYPTLIB (TlsGet.Services.CertRevocationList, TlsGetCertRevocationList, (Data, DataSize), EFI_UNSUPPORTED);\r
4932}\r
4933\r
8db4e9f9
YL
4934/**\r
4935 Derive keying material from a TLS connection.\r
4936\r
4937 This function exports keying material using the mechanism described in RFC\r
4938 5705.\r
4939\r
4940 @param[in] Tls Pointer to the TLS object\r
4941 @param[in] Label Description of the key for the PRF function\r
4942 @param[in] Context Optional context\r
4943 @param[in] ContextLen The length of the context value in bytes\r
4944 @param[out] KeyBuffer Buffer to hold the output of the TLS-PRF\r
4945 @param[in] KeyBufferLen The length of the KeyBuffer\r
4946\r
4947 @retval EFI_SUCCESS The operation succeeded.\r
4948 @retval EFI_INVALID_PARAMETER The TLS object is invalid.\r
4949 @retval EFI_PROTOCOL_ERROR Some other error occurred.\r
4950\r
4951**/\r
4952EFI_STATUS\r
4953EFIAPI\r
4954CryptoServiceTlsGetExportKey (\r
4955 IN VOID *Tls,\r
4956 IN CONST VOID *Label,\r
4957 IN CONST VOID *Context,\r
4958 IN UINTN ContextLen,\r
4959 OUT VOID *KeyBuffer,\r
4960 IN UINTN KeyBufferLen\r
4961 )\r
4962{\r
4963 return CALL_BASECRYPTLIB (\r
4964 TlsGet.Services.ExportKey,\r
4965 TlsGetExportKey,\r
4966 (Tls, Label, Context, ContextLen,\r
4967 KeyBuffer, KeyBufferLen),\r
4968 EFI_UNSUPPORTED\r
4969 );\r
4970}\r
4971\r
c1e66210
ZL
4972/**\r
4973 Carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme.\r
4974\r
4975 This function carries out the RSA-SSA signature generation with EMSA-PSS encoding scheme defined in\r
4976 RFC 8017.\r
4977 Mask generation function is the same as the message digest algorithm.\r
4978 If the Signature buffer is too small to hold the contents of signature, FALSE\r
4979 is returned and SigSize is set to the required buffer size to obtain the signature.\r
4980\r
4981 If RsaContext is NULL, then return FALSE.\r
4982 If Message is NULL, then return FALSE.\r
4983 If MsgSize is zero or > INT_MAX, then return FALSE.\r
4984 If DigestLen is NOT 32, 48 or 64, return FALSE.\r
4985 If SaltLen is not equal to DigestLen, then return FALSE.\r
4986 If SigSize is large enough but Signature is NULL, then return FALSE.\r
4987 If this interface is not supported, then return FALSE.\r
4988\r
4989 @param[in] RsaContext Pointer to RSA context for signature generation.\r
4990 @param[in] Message Pointer to octet message to be signed.\r
4991 @param[in] MsgSize Size of the message in bytes.\r
4992 @param[in] DigestLen Length of the digest in bytes to be used for RSA signature operation.\r
4993 @param[in] SaltLen Length of the salt in bytes to be used for PSS encoding.\r
4994 @param[out] Signature Pointer to buffer to receive RSA PSS signature.\r
4995 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
4996 On output, the size of data returned in Signature buffer in bytes.\r
4997\r
4998 @retval TRUE Signature successfully generated in RSASSA-PSS.\r
4999 @retval FALSE Signature generation failed.\r
5000 @retval FALSE SigSize is too small.\r
5001 @retval FALSE This interface is not supported.\r
5002\r
5003**/\r
5004BOOLEAN\r
5005EFIAPI\r
5006CryptoServiceRsaPssSign (\r
5007 IN VOID *RsaContext,\r
5008 IN CONST UINT8 *Message,\r
5009 IN UINTN MsgSize,\r
5010 IN UINT16 DigestLen,\r
5011 IN UINT16 SaltLen,\r
5012 OUT UINT8 *Signature,\r
5013 IN OUT UINTN *SigSize\r
5014 )\r
5015{\r
5016 return CALL_BASECRYPTLIB (RsaPss.Services.Sign, RsaPssSign, (RsaContext, Message, MsgSize, DigestLen, SaltLen, Signature, SigSize), FALSE);\r
5017}\r
5018\r
5019/**\r
5020 Verifies the RSA signature with RSASSA-PSS signature scheme defined in RFC 8017.\r
5021 Implementation determines salt length automatically from the signature encoding.\r
5022 Mask generation function is the same as the message digest algorithm.\r
5023 Salt length should be equal to digest length.\r
5024\r
5025 @param[in] RsaContext Pointer to RSA context for signature verification.\r
5026 @param[in] Message Pointer to octet message to be verified.\r
5027 @param[in] MsgSize Size of the message in bytes.\r
5028 @param[in] Signature Pointer to RSASSA-PSS signature to be verified.\r
5029 @param[in] SigSize Size of signature in bytes.\r
5030 @param[in] DigestLen Length of digest for RSA operation.\r
5031 @param[in] SaltLen Salt length for PSS encoding.\r
5032\r
5033 @retval TRUE Valid signature encoded in RSASSA-PSS.\r
5034 @retval FALSE Invalid signature or invalid RSA context.\r
5035\r
5036**/\r
5037BOOLEAN\r
5038EFIAPI\r
5039CryptoServiceRsaPssVerify (\r
5040 IN VOID *RsaContext,\r
5041 IN CONST UINT8 *Message,\r
5042 IN UINTN MsgSize,\r
5043 IN CONST UINT8 *Signature,\r
5044 IN UINTN SigSize,\r
5045 IN UINT16 DigestLen,\r
5046 IN UINT16 SaltLen\r
5047 )\r
5048{\r
5049 return CALL_BASECRYPTLIB (RsaPss.Services.Verify, RsaPssVerify, (RsaContext, Message, MsgSize, Signature, SigSize, DigestLen, SaltLen), FALSE);\r
5050}\r
5051\r
5052/**\r
5053 Parallel hash function ParallelHash256, as defined in NIST's Special Publication 800-185,\r
5054 published December 2016.\r
5055\r
5056 @param[in] Input Pointer to the input message (X).\r
5057 @param[in] InputByteLen The number(>0) of input bytes provided for the input data.\r
5058 @param[in] BlockSize The size of each block (B).\r
5059 @param[out] Output Pointer to the output buffer.\r
5060 @param[in] OutputByteLen The desired number of output bytes (L).\r
5061 @param[in] Customization Pointer to the customization string (S).\r
5062 @param[in] CustomByteLen The length of the customization string in bytes.\r
5063\r
5064 @retval TRUE ParallelHash256 digest computation succeeded.\r
5065 @retval FALSE ParallelHash256 digest computation failed.\r
5066 @retval FALSE This interface is not supported.\r
5067\r
5068**/\r
5069BOOLEAN\r
5070EFIAPI\r
5071CryptoServiceParallelHash256HashAll (\r
5072 IN CONST VOID *Input,\r
5073 IN UINTN InputByteLen,\r
5074 IN UINTN BlockSize,\r
5075 OUT VOID *Output,\r
5076 IN UINTN OutputByteLen,\r
5077 IN CONST VOID *Customization,\r
5078 IN UINTN CustomByteLen\r
5079 )\r
5080{\r
5081 return CALL_BASECRYPTLIB (ParallelHash.Services.HashAll, ParallelHash256HashAll, (Input, InputByteLen, BlockSize, Output, OutputByteLen, Customization, CustomByteLen), FALSE);\r
5082}\r
5083\r
022787f8
QZ
5084/**\r
5085 Performs AEAD AES-GCM authenticated encryption on a data buffer and additional authenticated data (AAD).\r
5086\r
5087 IvSize must be 12, otherwise FALSE is returned.\r
5088 KeySize must be 16, 24 or 32, otherwise FALSE is returned.\r
5089 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.\r
5090\r
5091 @param[in] Key Pointer to the encryption key.\r
5092 @param[in] KeySize Size of the encryption key in bytes.\r
5093 @param[in] Iv Pointer to the IV value.\r
5094 @param[in] IvSize Size of the IV value in bytes.\r
5095 @param[in] AData Pointer to the additional authenticated data (AAD).\r
5096 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.\r
5097 @param[in] DataIn Pointer to the input data buffer to be encrypted.\r
5098 @param[in] DataInSize Size of the input data buffer in bytes.\r
5099 @param[out] TagOut Pointer to a buffer that receives the authentication tag output.\r
5100 @param[in] TagSize Size of the authentication tag in bytes.\r
5101 @param[out] DataOut Pointer to a buffer that receives the encryption output.\r
5102 @param[out] DataOutSize Size of the output data buffer in bytes.\r
5103\r
5104 @retval TRUE AEAD AES-GCM authenticated encryption succeeded.\r
5105 @retval FALSE AEAD AES-GCM authenticated encryption failed.\r
5106\r
5107**/\r
5108BOOLEAN\r
5109EFIAPI\r
5110CryptoServiceAeadAesGcmEncrypt (\r
5111 IN CONST UINT8 *Key,\r
5112 IN UINTN KeySize,\r
5113 IN CONST UINT8 *Iv,\r
5114 IN UINTN IvSize,\r
5115 IN CONST UINT8 *AData,\r
5116 IN UINTN ADataSize,\r
5117 IN CONST UINT8 *DataIn,\r
5118 IN UINTN DataInSize,\r
5119 OUT UINT8 *TagOut,\r
5120 IN UINTN TagSize,\r
5121 OUT UINT8 *DataOut,\r
5122 OUT UINTN *DataOutSize\r
5123 )\r
5124{\r
5125 return CALL_BASECRYPTLIB (AeadAesGcm.Services.Encrypt, AeadAesGcmEncrypt, (Key, KeySize, Iv, IvSize, AData, ADataSize, DataIn, DataInSize, TagOut, TagSize, DataOut, DataOutSize), FALSE);\r
5126}\r
5127\r
5128/**\r
5129 Performs AEAD AES-GCM authenticated decryption on a data buffer and additional authenticated data (AAD).\r
5130\r
5131 IvSize must be 12, otherwise FALSE is returned.\r
5132 KeySize must be 16, 24 or 32, otherwise FALSE is returned.\r
5133 TagSize must be 12, 13, 14, 15, 16, otherwise FALSE is returned.\r
5134 If additional authenticated data verification fails, FALSE is returned.\r
5135\r
5136 @param[in] Key Pointer to the encryption key.\r
5137 @param[in] KeySize Size of the encryption key in bytes.\r
5138 @param[in] Iv Pointer to the IV value.\r
5139 @param[in] IvSize Size of the IV value in bytes.\r
5140 @param[in] AData Pointer to the additional authenticated data (AAD).\r
5141 @param[in] ADataSize Size of the additional authenticated data (AAD) in bytes.\r
5142 @param[in] DataIn Pointer to the input data buffer to be decrypted.\r
5143 @param[in] DataInSize Size of the input data buffer in bytes.\r
5144 @param[in] Tag Pointer to a buffer that contains the authentication tag.\r
5145 @param[in] TagSize Size of the authentication tag in bytes.\r
5146 @param[out] DataOut Pointer to a buffer that receives the decryption output.\r
5147 @param[out] DataOutSize Size of the output data buffer in bytes.\r
5148\r
5149 @retval TRUE AEAD AES-GCM authenticated decryption succeeded.\r
5150 @retval FALSE AEAD AES-GCM authenticated decryption failed.\r
5151\r
5152**/\r
5153BOOLEAN\r
5154EFIAPI\r
5155CryptoServiceAeadAesGcmDecrypt (\r
5156 IN CONST UINT8 *Key,\r
5157 IN UINTN KeySize,\r
5158 IN CONST UINT8 *Iv,\r
5159 IN UINTN IvSize,\r
5160 IN CONST UINT8 *AData,\r
5161 IN UINTN ADataSize,\r
5162 IN CONST UINT8 *DataIn,\r
5163 IN UINTN DataInSize,\r
5164 IN CONST UINT8 *Tag,\r
5165 IN UINTN TagSize,\r
5166 OUT UINT8 *DataOut,\r
5167 OUT UINTN *DataOutSize\r
5168 )\r
5169{\r
5170 return CALL_BASECRYPTLIB (AeadAesGcm.Services.Decrypt, AeadAesGcmDecrypt, (Key, KeySize, Iv, IvSize, AData, ADataSize, DataIn, DataInSize, Tag, TagSize, DataOut, DataOutSize), FALSE);\r
5171}\r
5172\r
42951543
YL
5173// =====================================================================================\r
5174// Big number primitives\r
5175// =====================================================================================\r
5176\r
5177/**\r
5178 Allocate new Big Number.\r
5179\r
5180 @retval New BigNum opaque structure or NULL on failure.\r
5181**/\r
5182VOID *\r
5183EFIAPI\r
5184CryptoServiceBigNumInit (\r
5185 VOID\r
5186 )\r
5187{\r
5188 return CALL_BASECRYPTLIB (Bn.Services.Init, BigNumInit, (), NULL);\r
5189}\r
5190\r
5191/**\r
5192 Allocate new Big Number and assign the provided value to it.\r
5193\r
5194 @param[in] Buf Big endian encoded buffer.\r
5195 @param[in] Len Buffer length.\r
5196\r
5197 @retval New BigNum opaque structure or NULL on failure.\r
5198**/\r
5199VOID *\r
5200EFIAPI\r
5201CryptoServiceBigNumFromBin (\r
5202 IN CONST UINT8 *Buf,\r
5203 IN UINTN Len\r
5204 )\r
5205{\r
5206 return CALL_BASECRYPTLIB (Bn.Services.FromBin, BigNumFromBin, (Buf, Len), NULL);\r
5207}\r
5208\r
5209/**\r
5210 Convert the absolute value of Bn into big-endian form and store it at Buf.\r
5211 The Buf array should have at least BigNumBytes() in it.\r
5212\r
5213 @param[in] Bn Big number to convert.\r
5214 @param[out] Buf Output buffer.\r
5215\r
5216 @retval The length of the big-endian number placed at Buf or -1 on error.\r
5217**/\r
5218INTN\r
5219EFIAPI\r
5220CryptoServiceBigNumToBin (\r
5221 IN CONST VOID *Bn,\r
5222 OUT UINT8 *Buf\r
5223 )\r
5224{\r
5225 return CALL_BASECRYPTLIB (Bn.Services.ToBin, BigNumToBin, (Bn, Buf), -1);\r
5226}\r
5227\r
5228/**\r
5229 Free the Big Number.\r
5230\r
5231 @param[in] Bn Big number to free.\r
5232 @param[in] Clear TRUE if the buffer should be cleared.\r
5233**/\r
5234VOID\r
5235EFIAPI\r
5236CryptoServiceBigNumFree (\r
5237 IN VOID *Bn,\r
5238 IN BOOLEAN Clear\r
5239 )\r
5240{\r
5241 CALL_VOID_BASECRYPTLIB (Bn.Services.Free, BigNumFree, (Bn, Clear));\r
5242}\r
5243\r
5244/**\r
5245 Calculate the sum of two Big Numbers.\r
5246 Please note, all "out" Big number arguments should be properly initialized\r
5247 by calling to BigNumInit() or BigNumFromBin() functions.\r
5248\r
5249 @param[in] BnA Big number.\r
5250 @param[in] BnB Big number.\r
5251 @param[out] BnRes The result of BnA + BnB.\r
5252\r
5253 @retval TRUE On success.\r
5254 @retval FALSE Otherwise.\r
5255**/\r
5256BOOLEAN\r
5257EFIAPI\r
5258CryptoServiceBigNumAdd (\r
5259 IN CONST VOID *BnA,\r
5260 IN CONST VOID *BnB,\r
5261 OUT VOID *BnRes\r
5262 )\r
5263{\r
5264 return CALL_BASECRYPTLIB (Bn.Services.Add, BigNumAdd, (BnA, BnB, BnRes), FALSE);\r
5265}\r
5266\r
5267/**\r
5268 Subtract two Big Numbers.\r
5269 Please note, all "out" Big number arguments should be properly initialized\r
5270 by calling to BigNumInit() or BigNumFromBin() functions.\r
5271\r
5272 @param[in] BnA Big number.\r
5273 @param[in] BnB Big number.\r
5274 @param[out] BnRes The result of BnA - BnB.\r
5275\r
5276 @retval TRUE On success.\r
5277 @retval FALSE Otherwise.\r
5278**/\r
5279BOOLEAN\r
5280EFIAPI\r
5281CryptoServiceBigNumSub (\r
5282 IN CONST VOID *BnA,\r
5283 IN CONST VOID *BnB,\r
5284 OUT VOID *BnRes\r
5285 )\r
5286{\r
5287 return CALL_BASECRYPTLIB (Bn.Services.Sub, BigNumSub, (BnA, BnB, BnRes), FALSE);\r
5288}\r
5289\r
5290/**\r
5291 Calculate remainder: BnRes = BnA % BnB.\r
5292 Please note, all "out" Big number arguments should be properly initialized\r
5293 by calling to BigNumInit() or BigNumFromBin() functions.\r
5294\r
5295 @param[in] BnA Big number.\r
5296 @param[in] BnB Big number.\r
5297 @param[out] BnRes The result of BnA % BnB.\r
5298\r
5299 @retval TRUE On success.\r
5300 @retval FALSE Otherwise.\r
5301**/\r
5302BOOLEAN\r
5303EFIAPI\r
5304CryptoServiceBigNumMod (\r
5305 IN CONST VOID *BnA,\r
5306 IN CONST VOID *BnB,\r
5307 OUT VOID *BnRes\r
5308 )\r
5309{\r
5310 return CALL_BASECRYPTLIB (Bn.Services.Mod, BigNumMod, (BnA, BnB, BnRes), FALSE);\r
5311}\r
5312\r
5313/**\r
5314 Compute BnA to the BnP-th power modulo BnM.\r
5315 Please note, all "out" Big number arguments should be properly initialized.\r
5316 by calling to BigNumInit() or BigNumFromBin() functions.\r
5317\r
5318 @param[in] BnA Big number.\r
5319 @param[in] BnP Big number (power).\r
5320 @param[in] BnM Big number (modulo).\r
5321 @param[out] BnRes The result of (BnA ^ BnP) % BnM.\r
5322\r
5323 @retval TRUE On success.\r
5324 @retval FALSE Otherwise.\r
5325**/\r
5326BOOLEAN\r
5327EFIAPI\r
5328CryptoServiceBigNumExpMod (\r
5329 IN CONST VOID *BnA,\r
5330 IN CONST VOID *BnP,\r
5331 IN CONST VOID *BnM,\r
5332 OUT VOID *BnRes\r
5333 )\r
5334{\r
5335 return CALL_BASECRYPTLIB (Bn.Services.ExpMod, BigNumExpMod, (BnA, BnP, BnM, BnRes), FALSE);\r
5336}\r
5337\r
5338/**\r
5339 Compute BnA inverse modulo BnM.\r
5340 Please note, all "out" Big number arguments should be properly initialized\r
5341 by calling to BigNumInit() or BigNumFromBin() functions.\r
5342\r
5343 @param[in] BnA Big number.\r
5344 @param[in] BnM Big number (modulo).\r
5345 @param[out] BnRes The result, such that (BnA * BnRes) % BnM == 1.\r
5346\r
5347 @retval TRUE On success.\r
5348 @retval FALSE Otherwise.\r
5349**/\r
5350BOOLEAN\r
5351EFIAPI\r
5352CryptoServiceBigNumInverseMod (\r
5353 IN CONST VOID *BnA,\r
5354 IN CONST VOID *BnM,\r
5355 OUT VOID *BnRes\r
5356 )\r
5357{\r
5358 return CALL_BASECRYPTLIB (Bn.Services.InverseMod, BigNumInverseMod, (BnA, BnM, BnRes), FALSE);\r
5359}\r
5360\r
5361/**\r
5362 Divide two Big Numbers.\r
5363 Please note, all "out" Big number arguments should be properly initialized\r
5364 by calling to BigNumInit() or BigNumFromBin() functions.\r
5365\r
5366 @param[in] BnA Big number.\r
5367 @param[in] BnB Big number.\r
5368 @param[out] BnRes The result, such that BnA / BnB.\r
5369\r
5370 @retval TRUE On success.\r
5371 @retval FALSE Otherwise.\r
5372**/\r
5373BOOLEAN\r
5374EFIAPI\r
5375CryptoServiceBigNumDiv (\r
5376 IN CONST VOID *BnA,\r
5377 IN CONST VOID *BnB,\r
5378 OUT VOID *BnRes\r
5379 )\r
5380{\r
5381 return CALL_BASECRYPTLIB (Bn.Services.Div, BigNumDiv, (BnA, BnB, BnRes), FALSE);\r
5382}\r
5383\r
5384/**\r
5385 Multiply two Big Numbers modulo BnM.\r
5386 Please note, all "out" Big number arguments should be properly initialized\r
5387 by calling to BigNumInit() or BigNumFromBin() functions.\r
5388\r
5389 @param[in] BnA Big number.\r
5390 @param[in] BnB Big number.\r
5391 @param[in] BnM Big number (modulo).\r
5392 @param[out] BnRes The result, such that (BnA * BnB) % BnM.\r
5393\r
5394 @retval TRUE On success.\r
5395 @retval FALSE Otherwise.\r
5396**/\r
5397BOOLEAN\r
5398EFIAPI\r
5399CryptoServiceBigNumMulMod (\r
5400 IN CONST VOID *BnA,\r
5401 IN CONST VOID *BnB,\r
5402 IN CONST VOID *BnM,\r
5403 OUT VOID *BnRes\r
5404 )\r
5405{\r
5406 return CALL_BASECRYPTLIB (Bn.Services.MulMod, BigNumMulMod, (BnA, BnB, BnM, BnRes), FALSE);\r
5407}\r
5408\r
5409/**\r
5410 Compare two Big Numbers.\r
5411\r
5412 @param[in] BnA Big number.\r
5413 @param[in] BnB Big number.\r
5414\r
5415 @retval 0 BnA == BnB.\r
5416 @retval 1 BnA > BnB.\r
5417 @retval -1 BnA < BnB.\r
5418**/\r
5419INTN\r
5420EFIAPI\r
5421CryptoServiceBigNumCmp (\r
5422 IN CONST VOID *BnA,\r
5423 IN CONST VOID *BnB\r
5424 )\r
5425{\r
5426 return CALL_BASECRYPTLIB (Bn.Services.Cmp, BigNumCmp, (BnA, BnB), 0);\r
5427}\r
5428\r
5429/**\r
5430 Get number of bits in Bn.\r
5431\r
5432 @param[in] Bn Big number.\r
5433\r
5434 @retval Number of bits.\r
5435**/\r
5436UINTN\r
5437EFIAPI\r
5438CryptoServiceBigNumBits (\r
5439 IN CONST VOID *Bn\r
5440 )\r
5441{\r
5442 return CALL_BASECRYPTLIB (Bn.Services.Bits, BigNumBits, (Bn), 0);\r
5443}\r
5444\r
5445/**\r
5446 Get number of bytes in Bn.\r
5447\r
5448 @param[in] Bn Big number.\r
5449\r
5450 @retval Number of bytes.\r
5451**/\r
5452UINTN\r
5453EFIAPI\r
5454CryptoServiceBigNumBytes (\r
5455 IN CONST VOID *Bn\r
5456 )\r
5457{\r
5458 return CALL_BASECRYPTLIB (Bn.Services.Bytes, BigNumBytes, (Bn), 0);\r
5459}\r
5460\r
5461/**\r
5462 Checks if Big Number equals to the given Num.\r
5463\r
5464 @param[in] Bn Big number.\r
5465 @param[in] Num Number.\r
5466\r
5467 @retval TRUE iff Bn == Num.\r
5468 @retval FALSE otherwise.\r
5469**/\r
5470BOOLEAN\r
5471EFIAPI\r
5472CryptoServiceBigNumIsWord (\r
5473 IN CONST VOID *Bn,\r
5474 IN UINTN Num\r
5475 )\r
5476{\r
5477 return CALL_BASECRYPTLIB (Bn.Services.IsWord, BigNumIsWord, (Bn, Num), FALSE);\r
5478}\r
5479\r
5480/**\r
5481 Checks if Big Number is odd.\r
5482\r
5483 @param[in] Bn Big number.\r
5484\r
5485 @retval TRUE Bn is odd (Bn % 2 == 1).\r
5486 @retval FALSE otherwise.\r
5487**/\r
5488BOOLEAN\r
5489EFIAPI\r
5490CryptoServiceBigNumIsOdd (\r
5491 IN CONST VOID *Bn\r
5492 )\r
5493{\r
5494 return CALL_BASECRYPTLIB (Bn.Services.IsOdd, BigNumIsOdd, (Bn), FALSE);\r
5495}\r
5496\r
5497/**\r
5498 Copy Big number.\r
5499\r
5500 @param[out] BnDst Destination.\r
5501 @param[in] BnSrc Source.\r
5502\r
5503 @retval BnDst on success.\r
5504 @retval NULL otherwise.\r
5505**/\r
5506VOID *\r
5507EFIAPI\r
5508CryptoServiceBigNumCopy (\r
5509 OUT VOID *BnDst,\r
5510 IN CONST VOID *BnSrc\r
5511 )\r
5512{\r
5513 return CALL_BASECRYPTLIB (Bn.Services.Copy, BigNumCopy, (BnDst, BnSrc), NULL);\r
5514}\r
5515\r
5516/**\r
5517 Get constant Big number with value of "1".\r
5518 This may be used to save expensive allocations.\r
5519\r
5520 @retval Big Number with value of 1.\r
5521**/\r
5522CONST VOID *\r
5523EFIAPI\r
5524CryptoServiceBigNumValueOne (\r
5525 VOID\r
5526 )\r
5527{\r
5528 return CALL_BASECRYPTLIB (Bn.Services.ValueOne, BigNumValueOne, (), NULL);\r
5529}\r
5530\r
5531/**\r
5532 Shift right Big Number.\r
5533 Please note, all "out" Big number arguments should be properly initialized\r
5534 by calling to BigNumInit() or BigNumFromBin() functions.\r
5535\r
5536 @param[in] Bn Big number.\r
5537 @param[in] N Number of bits to shift.\r
5538 @param[out] BnRes The result.\r
5539\r
5540 @retval TRUE On success.\r
5541 @retval FALSE Otherwise.\r
5542**/\r
5543BOOLEAN\r
5544EFIAPI\r
5545CryptoServiceBigNumRShift (\r
5546 IN CONST VOID *Bn,\r
5547 IN UINTN N,\r
5548 OUT VOID *BnRes\r
5549 )\r
5550{\r
5551 return CALL_BASECRYPTLIB (Bn.Services.RShift, BigNumRShift, (Bn, N, BnRes), FALSE);\r
5552}\r
5553\r
5554/**\r
5555 Mark Big Number for constant time computations.\r
5556 This function should be called before any constant time computations are\r
5557 performed on the given Big number.\r
5558\r
5559 @param[in] Bn Big number.\r
5560**/\r
5561VOID\r
5562EFIAPI\r
5563CryptoServiceBigNumConstTime (\r
5564 IN VOID *Bn\r
5565 )\r
5566{\r
5567 CALL_VOID_BASECRYPTLIB (Bn.Services.ConstTime, BigNumConstTime, (Bn));\r
5568}\r
5569\r
5570/**\r
5571 Calculate square modulo.\r
5572 Please note, all "out" Big number arguments should be properly initialized\r
5573 by calling to BigNumInit() or BigNumFromBin() functions.\r
5574\r
5575 @param[in] BnA Big number.\r
5576 @param[in] BnM Big number (modulo).\r
5577 @param[out] BnRes The result, such that (BnA ^ 2) % BnM.\r
5578\r
5579 @retval TRUE On success.\r
5580 @retval FALSE Otherwise.\r
5581**/\r
5582BOOLEAN\r
5583EFIAPI\r
5584CryptoServiceBigNumSqrMod (\r
5585 IN CONST VOID *BnA,\r
5586 IN CONST VOID *BnM,\r
5587 OUT VOID *BnRes\r
5588 )\r
5589{\r
5590 return CALL_BASECRYPTLIB (Bn.Services.SqrMod, BigNumSqrMod, (BnA, BnM, BnRes), FALSE);\r
5591}\r
5592\r
5593/**\r
5594 Create new Big Number computation context. This is an opaque structure\r
5595 which should be passed to any function that requires it. The BN context is\r
5596 needed to optimize calculations and expensive allocations.\r
5597\r
5598 @retval Big Number context struct or NULL on failure.\r
5599**/\r
5600VOID *\r
5601EFIAPI\r
5602CryptoServiceBigNumNewContext (\r
5603 VOID\r
5604 )\r
5605{\r
5606 return CALL_BASECRYPTLIB (Bn.Services.NewContext, BigNumNewContext, (), NULL);\r
5607}\r
5608\r
5609/**\r
5610 Free Big Number context that was allocated with BigNumNewContext().\r
5611\r
5612 @param[in] BnCtx Big number context to free.\r
5613**/\r
5614VOID\r
5615EFIAPI\r
5616CryptoServiceBigNumContextFree (\r
5617 IN VOID *BnCtx\r
5618 )\r
5619{\r
5620 CALL_VOID_BASECRYPTLIB (Bn.Services.ContextFree, BigNumContextFree, (BnCtx));\r
5621}\r
5622\r
5623/**\r
5624 Set Big Number to a given value.\r
5625\r
5626 @param[in] Bn Big number to set.\r
5627 @param[in] Val Value to set.\r
5628\r
5629 @retval TRUE On success.\r
5630 @retval FALSE Otherwise.\r
5631**/\r
5632BOOLEAN\r
5633EFIAPI\r
5634CryptoServiceBigNumSetUint (\r
5635 IN VOID *Bn,\r
5636 IN UINTN Val\r
5637 )\r
5638{\r
5639 return CALL_BASECRYPTLIB (Bn.Services.SetUint, BigNumSetUint, (Bn, Val), FALSE);\r
5640}\r
5641\r
5642/**\r
5643 Add two Big Numbers modulo BnM.\r
5644\r
5645 @param[in] BnA Big number.\r
5646 @param[in] BnB Big number.\r
5647 @param[in] BnM Big number (modulo).\r
5648 @param[out] BnRes The result, such that (BnA + BnB) % BnM.\r
5649\r
5650 @retval TRUE On success.\r
5651 @retval FALSE Otherwise.\r
5652**/\r
5653BOOLEAN\r
5654EFIAPI\r
5655CryptoServiceBigNumAddMod (\r
5656 IN CONST VOID *BnA,\r
5657 IN CONST VOID *BnB,\r
5658 IN CONST VOID *BnM,\r
5659 OUT VOID *BnRes\r
5660 )\r
5661{\r
5662 return CALL_BASECRYPTLIB (Bn.Services.AddMod, BigNumAddMod, (BnA, BnB, BnM, BnRes), FALSE);\r
5663}\r
5664\r
3b382f5b
YL
5665// =====================================================================================\r
5666// Basic Elliptic Curve Primitives\r
5667// =====================================================================================\r
5668\r
5669/**\r
5670 Initialize new opaque EcGroup object. This object represents an EC curve and\r
5671 and is used for calculation within this group. This object should be freed\r
5672 using EcGroupFree() function.\r
5673\r
5674 @param[in] CryptoNid Identifying number for the ECC curve (Defined in\r
5675 BaseCryptLib.h).\r
5676\r
5677 @retval EcGroup object On success.\r
5678 @retval NULL On failure.\r
5679**/\r
5680VOID *\r
5681EFIAPI\r
5682CryptoServiceEcGroupInit (\r
5683 IN UINTN CryptoNid\r
5684 )\r
5685{\r
5686 return CALL_BASECRYPTLIB (Ec.Services.GroupInit, EcGroupInit, (CryptoNid), NULL);\r
5687}\r
5688\r
5689/**\r
5690 Get EC curve parameters. While elliptic curve equation is Y^2 mod P = (X^3 + AX + B) Mod P.\r
5691 This function will set the provided Big Number objects to the corresponding\r
5692 values. The caller needs to make sure all the "out" BigNumber parameters\r
5693 are properly initialized.\r
5694 @param[in] EcGroup EC group object.\r
5695 @param[out] BnPrime Group prime number.\r
5696 @param[out] BnA A coefficient.\r
5697 @param[out] BnB B coefficient.\r
5698 @param[in] BnCtx BN context.\r
5699\r
5700 @retval TRUE On success.\r
5701 @retval FALSE Otherwise.\r
5702**/\r
5703BOOLEAN\r
5704EFIAPI\r
5705CryptoServiceEcGroupGetCurve (\r
5706 IN CONST VOID *EcGroup,\r
5707 OUT VOID *BnPrime,\r
5708 OUT VOID *BnA,\r
5709 OUT VOID *BnB,\r
5710 IN VOID *BnCtx\r
5711 )\r
5712{\r
5713 return CALL_BASECRYPTLIB (Ec.Services.GroupGetCurve, EcGroupGetCurve, (EcGroup, BnPrime, BnA, BnB, BnCtx), FALSE);\r
5714}\r
5715\r
5716/**\r
5717 Get EC group order.\r
5718 This function will set the provided Big Number object to the corresponding\r
5719 value. The caller needs to make sure that the "out" BigNumber parameter\r
5720 is properly initialized.\r
5721\r
5722 @param[in] EcGroup EC group object.\r
5723 @param[out] BnOrder Group prime number.\r
5724\r
5725 @retval TRUE On success.\r
5726 @retval FALSE Otherwise.\r
5727**/\r
5728BOOLEAN\r
5729EFIAPI\r
5730CryptoServiceEcGroupGetOrder (\r
5731 IN VOID *EcGroup,\r
5732 OUT VOID *BnOrder\r
5733 )\r
5734{\r
5735 return CALL_BASECRYPTLIB (Ec.Services.GroupGetOrder, EcGroupGetOrder, (EcGroup, BnOrder), FALSE);\r
5736}\r
5737\r
5738/**\r
5739 Free previously allocated EC group object using EcGroupInit().\r
5740\r
5741 @param[in] EcGroup EC group object to free.\r
5742**/\r
5743VOID\r
5744EFIAPI\r
5745CryptoServiceEcGroupFree (\r
5746 IN VOID *EcGroup\r
5747 )\r
5748{\r
5749 CALL_VOID_BASECRYPTLIB (Ec.Services.GroupFree, EcGroupFree, (EcGroup));\r
5750}\r
5751\r
5752/**\r
5753 Initialize new opaque EC Point object. This object represents an EC point\r
5754 within the given EC group (curve).\r
5755\r
5756 @param[in] EC Group, properly initialized using EcGroupInit().\r
5757\r
5758 @retval EC Point object On success.\r
5759 @retval NULL On failure.\r
5760**/\r
5761VOID *\r
5762EFIAPI\r
5763CryptoServiceEcPointInit (\r
5764 IN CONST VOID *EcGroup\r
5765 )\r
5766{\r
5767 return CALL_BASECRYPTLIB (Ec.Services.PointInit, EcPointInit, (EcGroup), NULL);\r
5768}\r
5769\r
5770/**\r
5771 Free previously allocated EC Point object using EcPointInit().\r
5772\r
5773 @param[in] EcPoint EC Point to free.\r
5774 @param[in] Clear TRUE iff the memory should be cleared.\r
5775**/\r
5776VOID\r
5777EFIAPI\r
5778CryptoServiceEcPointDeInit (\r
5779 IN VOID *EcPoint,\r
5780 IN BOOLEAN Clear\r
5781 )\r
5782{\r
5783 CALL_VOID_BASECRYPTLIB (Ec.Services.PointDeInit, EcPointDeInit, (EcPoint, Clear));\r
5784}\r
5785\r
5786/**\r
5787 Get EC point affine (x,y) coordinates.\r
5788 This function will set the provided Big Number objects to the corresponding\r
5789 values. The caller needs to make sure all the "out" BigNumber parameters\r
5790 are properly initialized.\r
5791\r
5792 @param[in] EcGroup EC group object.\r
5793 @param[in] EcPoint EC point object.\r
5794 @param[out] BnX X coordinate.\r
5795 @param[out] BnY Y coordinate.\r
5796 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5797\r
5798 @retval TRUE On success.\r
5799 @retval FALSE Otherwise.\r
5800**/\r
5801BOOLEAN\r
5802EFIAPI\r
5803CryptoServiceEcPointGetAffineCoordinates (\r
5804 IN CONST VOID *EcGroup,\r
5805 IN CONST VOID *EcPoint,\r
5806 OUT VOID *BnX,\r
5807 OUT VOID *BnY,\r
5808 IN VOID *BnCtx\r
5809 )\r
5810{\r
5811 return CALL_BASECRYPTLIB (Ec.Services.PointGetAffineCoordinates, EcPointGetAffineCoordinates, (EcGroup, EcPoint, BnX, BnY, BnCtx), FALSE);\r
5812}\r
5813\r
5814/**\r
5815 Set EC point affine (x,y) coordinates.\r
5816\r
5817 @param[in] EcGroup EC group object.\r
5818 @param[in] EcPoint EC point object.\r
5819 @param[in] BnX X coordinate.\r
5820 @param[in] BnY Y coordinate.\r
5821 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5822\r
5823 @retval TRUE On success.\r
5824 @retval FALSE Otherwise.\r
5825**/\r
5826BOOLEAN\r
5827EFIAPI\r
5828CryptoServiceEcPointSetAffineCoordinates (\r
5829 IN CONST VOID *EcGroup,\r
5830 IN VOID *EcPoint,\r
5831 IN CONST VOID *BnX,\r
5832 IN CONST VOID *BnY,\r
5833 IN VOID *BnCtx\r
5834 )\r
5835{\r
5836 return CALL_BASECRYPTLIB (Ec.Services.PointSetAffineCoordinates, EcPointSetAffineCoordinates, (EcGroup, EcPoint, BnX, BnY, BnCtx), FALSE);\r
5837}\r
5838\r
5839/**\r
5840 EC Point addition. EcPointResult = EcPointA + EcPointB.\r
5841 @param[in] EcGroup EC group object.\r
5842 @param[out] EcPointResult EC point to hold the result. The point should\r
5843 be properly initialized.\r
5844 @param[in] EcPointA EC Point.\r
5845 @param[in] EcPointB EC Point.\r
5846 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5847\r
5848 @retval TRUE On success.\r
5849 @retval FALSE Otherwise.\r
5850**/\r
5851BOOLEAN\r
5852EFIAPI\r
5853CryptoServiceEcPointAdd (\r
5854 IN CONST VOID *EcGroup,\r
5855 OUT VOID *EcPointResult,\r
5856 IN CONST VOID *EcPointA,\r
5857 IN CONST VOID *EcPointB,\r
5858 IN VOID *BnCtx\r
5859 )\r
5860{\r
5861 return CALL_BASECRYPTLIB (Ec.Services.PointAdd, EcPointAdd, (EcGroup, EcPointResult, EcPointA, EcPointB, BnCtx), FALSE);\r
5862}\r
5863\r
5864/**\r
5865 Variable EC point multiplication. EcPointResult = EcPoint * BnPScalar.\r
5866\r
5867 @param[in] EcGroup EC group object.\r
5868 @param[out] EcPointResult EC point to hold the result. The point should\r
5869 be properly initialized.\r
5870 @param[in] EcPoint EC Point.\r
5871 @param[in] BnPScalar P Scalar.\r
5872 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5873\r
5874 @retval TRUE On success.\r
5875 @retval FALSE Otherwise.\r
5876**/\r
5877BOOLEAN\r
5878EFIAPI\r
5879CryptoServiceEcPointMul (\r
5880 IN CONST VOID *EcGroup,\r
5881 OUT VOID *EcPointResult,\r
5882 IN CONST VOID *EcPoint,\r
5883 IN CONST VOID *BnPScalar,\r
5884 IN VOID *BnCtx\r
5885 )\r
5886{\r
5887 return CALL_BASECRYPTLIB (Ec.Services.PointMul, EcPointMul, (EcGroup, EcPointResult, EcPoint, BnPScalar, BnCtx), FALSE);\r
5888}\r
5889\r
5890/**\r
5891 Calculate the inverse of the supplied EC point.\r
5892\r
5893 @param[in] EcGroup EC group object.\r
5894 @param[in,out] EcPoint EC point to invert.\r
5895 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5896\r
5897 @retval TRUE On success.\r
5898 @retval FALSE Otherwise.\r
5899**/\r
5900BOOLEAN\r
5901EFIAPI\r
5902CryptoServiceEcPointInvert (\r
5903 IN CONST VOID *EcGroup,\r
5904 IN OUT VOID *EcPoint,\r
5905 IN VOID *BnCtx\r
5906 )\r
5907{\r
5908 return CALL_BASECRYPTLIB (Ec.Services.PointInvert, EcPointInvert, (EcGroup, EcPoint, BnCtx), FALSE);\r
5909}\r
5910\r
5911/**\r
5912 Check if the supplied point is on EC curve.\r
5913\r
5914 @param[in] EcGroup EC group object.\r
5915 @param[in] EcPoint EC point to check.\r
5916 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5917\r
5918 @retval TRUE On curve.\r
5919 @retval FALSE Otherwise.\r
5920**/\r
5921BOOLEAN\r
5922EFIAPI\r
5923CryptoServiceEcPointIsOnCurve (\r
5924 IN CONST VOID *EcGroup,\r
5925 IN CONST VOID *EcPoint,\r
5926 IN VOID *BnCtx\r
5927 )\r
5928{\r
5929 return CALL_BASECRYPTLIB (Ec.Services.PointIsOnCurve, EcPointIsOnCurve, (EcGroup, EcPoint, BnCtx), FALSE);\r
5930}\r
5931\r
5932/**\r
5933 Check if the supplied point is at infinity.\r
5934\r
5935 @param[in] EcGroup EC group object.\r
5936 @param[in] EcPoint EC point to check.\r
5937\r
5938 @retval TRUE At infinity.\r
5939 @retval FALSE Otherwise.\r
5940**/\r
5941BOOLEAN\r
5942EFIAPI\r
5943CryptoServiceEcPointIsAtInfinity (\r
5944 IN CONST VOID *EcGroup,\r
5945 IN CONST VOID *EcPoint\r
5946 )\r
5947{\r
5948 return CALL_BASECRYPTLIB (Ec.Services.PointIsAtInfinity, EcPointIsAtInfinity, (EcGroup, EcPoint), FALSE);\r
5949}\r
5950\r
5951/**\r
5952 Check if EC points are equal.\r
5953\r
5954 @param[in] EcGroup EC group object.\r
5955 @param[in] EcPointA EC point A.\r
5956 @param[in] EcPointB EC point B.\r
5957 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5958\r
5959 @retval TRUE A == B.\r
5960 @retval FALSE Otherwise.\r
5961**/\r
5962BOOLEAN\r
5963EFIAPI\r
5964CryptoServiceEcPointEqual (\r
5965 IN CONST VOID *EcGroup,\r
5966 IN CONST VOID *EcPointA,\r
5967 IN CONST VOID *EcPointB,\r
5968 IN VOID *BnCtx\r
5969 )\r
5970{\r
5971 return CALL_BASECRYPTLIB (Ec.Services.PointEqual, EcPointEqual, (EcGroup, EcPointA, EcPointB, BnCtx), FALSE);\r
5972}\r
5973\r
5974/**\r
5975 Set EC point compressed coordinates. Points can be described in terms of\r
5976 their compressed coordinates. For a point (x, y), for any given value for x\r
5977 such that the point is on the curve there will only ever be two possible\r
5978 values for y. Therefore, a point can be set using this function where BnX is\r
5979 the x coordinate and YBit is a value 0 or 1 to identify which of the two\r
5980 possible values for y should be used.\r
5981\r
5982 @param[in] EcGroup EC group object.\r
5983 @param[in] EcPoint EC Point.\r
5984 @param[in] BnX X coordinate.\r
5985 @param[in] YBit 0 or 1 to identify which Y value is used.\r
5986 @param[in] BnCtx BN context, created with BigNumNewContext().\r
5987\r
5988 @retval TRUE On success.\r
5989 @retval FALSE Otherwise.\r
5990**/\r
5991BOOLEAN\r
5992EFIAPI\r
5993CryptoServiceEcPointSetCompressedCoordinates (\r
5994 IN CONST VOID *EcGroup,\r
5995 IN VOID *EcPoint,\r
5996 IN CONST VOID *BnX,\r
5997 IN UINT8 YBit,\r
5998 IN VOID *BnCtx\r
5999 )\r
6000{\r
6001 return CALL_BASECRYPTLIB (Ec.Services.PointSetCompressedCoordinates, EcPointSetCompressedCoordinates, (EcGroup, EcPoint, BnX, YBit, BnCtx), FALSE);\r
6002}\r
6003\r
6004// =====================================================================================\r
6005// Elliptic Curve Diffie Hellman Primitives\r
6006// =====================================================================================\r
6007\r
6008/**\r
6009 Allocates and Initializes one Elliptic Curve Context for subsequent use\r
6010 with the NID.\r
6011\r
6012 @param[in] Nid cipher NID\r
6013 @return Pointer to the Elliptic Curve Context that has been initialized.\r
6014 If the allocations fails, EcNewByNid() returns NULL.\r
6015**/\r
6016VOID *\r
6017EFIAPI\r
6018CryptoServiceEcNewByNid (\r
6019 IN UINTN Nid\r
6020 )\r
6021{\r
6022 return CALL_BASECRYPTLIB (Ec.Services.NewByNid, EcNewByNid, (Nid), NULL);\r
6023}\r
6024\r
6025/**\r
6026 Release the specified EC context.\r
6027\r
6028 @param[in] EcContext Pointer to the EC context to be released.\r
6029**/\r
6030VOID\r
6031EFIAPI\r
6032CryptoServiceEcFree (\r
6033 IN VOID *EcContext\r
6034 )\r
6035{\r
6036 CALL_VOID_BASECRYPTLIB (Ec.Services.Free, EcFree, (EcContext));\r
6037}\r
6038\r
6039/**\r
6040 Generates EC key and returns EC public key (X, Y), Please note, this function uses\r
6041 pseudo random number generator. The caller must make sure RandomSeed()\r
6042 function was properly called before.\r
6043 The Ec context should be correctly initialized by EcNewByNid.\r
6044 This function generates random secret, and computes the public key (X, Y), which is\r
6045 returned via parameter Public, PublicSize.\r
6046 X is the first half of Public with size being PublicSize / 2,\r
6047 Y is the second half of Public with size being PublicSize / 2.\r
6048 EC context is updated accordingly.\r
6049 If the Public buffer is too small to hold the public X, Y, FALSE is returned and\r
6050 PublicSize is set to the required buffer size to obtain the public X, Y.\r
6051 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.\r
6052 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.\r
6053 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.\r
6054 If EcContext is NULL, then return FALSE.\r
6055 If PublicSize is NULL, then return FALSE.\r
6056 If PublicSize is large enough but Public is NULL, then return FALSE.\r
6057 @param[in, out] EcContext Pointer to the EC context.\r
6058 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.\r
6059 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.\r
6060 On output, the size of data returned in Public buffer in bytes.\r
6061 @retval TRUE EC public X,Y generation succeeded.\r
6062 @retval FALSE EC public X,Y generation failed.\r
6063 @retval FALSE PublicKeySize is not large enough.\r
6064**/\r
6065BOOLEAN\r
6066EFIAPI\r
6067CryptoServiceEcGenerateKey (\r
6068 IN OUT VOID *EcContext,\r
6069 OUT UINT8 *PublicKey,\r
6070 IN OUT UINTN *PublicKeySize\r
6071 )\r
6072{\r
6073 return CALL_BASECRYPTLIB (Ec.Services.GenerateKey, EcGenerateKey, (EcContext, PublicKey, PublicKeySize), FALSE);\r
6074}\r
6075\r
6076/**\r
6077 Gets the public key component from the established EC context.\r
6078 The Ec context should be correctly initialized by EcNewByNid, and successfully\r
6079 generate key pair from EcGenerateKey().\r
6080 For P-256, the PublicSize is 64. First 32-byte is X, Second 32-byte is Y.\r
6081 For P-384, the PublicSize is 96. First 48-byte is X, Second 48-byte is Y.\r
6082 For P-521, the PublicSize is 132. First 66-byte is X, Second 66-byte is Y.\r
6083 @param[in, out] EcContext Pointer to EC context being set.\r
6084 @param[out] PublicKey Pointer to t buffer to receive generated public X,Y.\r
6085 @param[in, out] PublicKeySize On input, the size of Public buffer in bytes.\r
6086 On output, the size of data returned in Public buffer in bytes.\r
6087 @retval TRUE EC key component was retrieved successfully.\r
6088 @retval FALSE Invalid EC key component.\r
6089**/\r
6090BOOLEAN\r
6091EFIAPI\r
6092CryptoServiceEcGetPubKey (\r
6093 IN OUT VOID *EcContext,\r
6094 OUT UINT8 *PublicKey,\r
6095 IN OUT UINTN *PublicKeySize\r
6096 )\r
6097{\r
6098 return CALL_BASECRYPTLIB (Ec.Services.GetPubKey, EcGetPubKey, (EcContext, PublicKey, PublicKeySize), FALSE);\r
6099}\r
6100\r
6101/**\r
6102 Computes exchanged common key.\r
6103 Given peer's public key (X, Y), this function computes the exchanged common key,\r
6104 based on its own context including value of curve parameter and random secret.\r
6105 X is the first half of PeerPublic with size being PeerPublicSize / 2,\r
6106 Y is the second half of PeerPublic with size being PeerPublicSize / 2.\r
6107 If EcContext is NULL, then return FALSE.\r
6108 If PeerPublic is NULL, then return FALSE.\r
6109 If PeerPublicSize is 0, then return FALSE.\r
6110 If Key is NULL, then return FALSE.\r
6111 If KeySize is not large enough, then return FALSE.\r
6112 For P-256, the PeerPublicSize is 64. First 32-byte is X, Second 32-byte is Y.\r
6113 For P-384, the PeerPublicSize is 96. First 48-byte is X, Second 48-byte is Y.\r
6114 For P-521, the PeerPublicSize is 132. First 66-byte is X, Second 66-byte is Y.\r
6115 @param[in, out] EcContext Pointer to the EC context.\r
6116 @param[in] PeerPublic Pointer to the peer's public X,Y.\r
6117 @param[in] PeerPublicSize Size of peer's public X,Y in bytes.\r
6118 @param[in] CompressFlag Flag of PeerPublic is compressed or not.\r
6119 @param[out] Key Pointer to the buffer to receive generated key.\r
6120 @param[in, out] KeySize On input, the size of Key buffer in bytes.\r
6121 On output, the size of data returned in Key buffer in bytes.\r
6122 @retval TRUE EC exchanged key generation succeeded.\r
6123 @retval FALSE EC exchanged key generation failed.\r
6124 @retval FALSE KeySize is not large enough.\r
6125**/\r
6126BOOLEAN\r
6127EFIAPI\r
6128CryptoServiceEcDhComputeKey (\r
6129 IN OUT VOID *EcContext,\r
6130 IN CONST UINT8 *PeerPublic,\r
6131 IN UINTN PeerPublicSize,\r
6132 IN CONST INT32 *CompressFlag,\r
6133 OUT UINT8 *Key,\r
6134 IN OUT UINTN *KeySize\r
6135 )\r
6136{\r
6137 return CALL_BASECRYPTLIB (Ec.Services.DhComputeKey, EcDhComputeKey, (EcContext, PeerPublic, PeerPublicSize, CompressFlag, Key, KeySize), FALSE);\r
6138}\r
6139\r
69a50a24
QZ
6140/**\r
6141 Retrieve the EC Public Key from one DER-encoded X509 certificate.\r
6142\r
6143 @param[in] Cert Pointer to the DER-encoded X509 certificate.\r
6144 @param[in] CertSize Size of the X509 certificate in bytes.\r
6145 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved\r
6146 EC public key component. Use EcFree() function to free the\r
6147 resource.\r
6148\r
6149 If Cert is NULL, then return FALSE.\r
6150 If EcContext is NULL, then return FALSE.\r
6151\r
6152 @retval TRUE EC Public Key was retrieved successfully.\r
6153 @retval FALSE Fail to retrieve EC public key from X509 certificate.\r
6154\r
6155**/\r
6156BOOLEAN\r
6157EFIAPI\r
6158CryptoServiceEcGetPublicKeyFromX509 (\r
6159 IN CONST UINT8 *Cert,\r
6160 IN UINTN CertSize,\r
6161 OUT VOID **EcContext\r
6162 )\r
6163{\r
6164 return CALL_BASECRYPTLIB (Ec.Services.GetPublicKeyFromX509, EcGetPublicKeyFromX509, (Cert, CertSize, EcContext), FALSE);\r
6165}\r
6166\r
6167/**\r
6168 Retrieve the EC Private Key from the password-protected PEM key data.\r
6169\r
6170 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r
6171 @param[in] PemSize Size of the PEM key data in bytes.\r
6172 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r
6173 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved\r
6174 EC private key component. Use EcFree() function to free the\r
6175 resource.\r
6176\r
6177 If PemData is NULL, then return FALSE.\r
6178 If EcContext is NULL, then return FALSE.\r
6179\r
6180 @retval TRUE EC Private Key was retrieved successfully.\r
6181 @retval FALSE Invalid PEM key data or incorrect password.\r
6182\r
6183**/\r
6184BOOLEAN\r
6185EFIAPI\r
6186CryptoServiceEcGetPrivateKeyFromPem (\r
6187 IN CONST UINT8 *PemData,\r
6188 IN UINTN PemSize,\r
6189 IN CONST CHAR8 *Password,\r
6190 OUT VOID **EcContext\r
6191 )\r
6192{\r
6193 return CALL_BASECRYPTLIB (Ec.Services.GetPrivateKeyFromPem, EcGetPrivateKeyFromPem, (PemData, PemSize, Password, EcContext), FALSE);\r
6194}\r
6195\r
6196/**\r
6197 Carries out the EC-DSA signature.\r
6198\r
6199 This function carries out the EC-DSA signature.\r
6200 If the Signature buffer is too small to hold the contents of signature, FALSE\r
6201 is returned and SigSize is set to the required buffer size to obtain the signature.\r
6202\r
6203 If EcContext is NULL, then return FALSE.\r
6204 If MessageHash is NULL, then return FALSE.\r
6205 If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.\r
6206 If SigSize is large enough but Signature is NULL, then return FALSE.\r
6207\r
6208 For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.\r
6209 For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.\r
6210 For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.\r
6211\r
6212 @param[in] EcContext Pointer to EC context for signature generation.\r
6213 @param[in] HashNid hash NID\r
6214 @param[in] MessageHash Pointer to octet message hash to be signed.\r
6215 @param[in] HashSize Size of the message hash in bytes.\r
6216 @param[out] Signature Pointer to buffer to receive EC-DSA signature.\r
6217 @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r
6218 On output, the size of data returned in Signature buffer in bytes.\r
6219\r
6220 @retval TRUE Signature successfully generated in EC-DSA.\r
6221 @retval FALSE Signature generation failed.\r
6222 @retval FALSE SigSize is too small.\r
6223\r
6224**/\r
6225BOOLEAN\r
6226EFIAPI\r
6227CryptoServiceEcDsaSign (\r
6228 IN VOID *EcContext,\r
6229 IN UINTN HashNid,\r
6230 IN CONST UINT8 *MessageHash,\r
6231 IN UINTN HashSize,\r
6232 OUT UINT8 *Signature,\r
6233 IN OUT UINTN *SigSize\r
6234 )\r
6235{\r
6236 return CALL_BASECRYPTLIB (Ec.Services.DsaSign, EcDsaSign, (EcContext, HashNid, MessageHash, HashSize, Signature, SigSize), FALSE);\r
6237}\r
6238\r
6239/**\r
6240 Verifies the EC-DSA signature.\r
6241\r
6242 If EcContext is NULL, then return FALSE.\r
6243 If MessageHash is NULL, then return FALSE.\r
6244 If Signature is NULL, then return FALSE.\r
6245 If HashSize need match the HashNid. HashNid could be SHA256, SHA384, SHA512, SHA3_256, SHA3_384, SHA3_512.\r
6246\r
6247 For P-256, the SigSize is 64. First 32-byte is R, Second 32-byte is S.\r
6248 For P-384, the SigSize is 96. First 48-byte is R, Second 48-byte is S.\r
6249 For P-521, the SigSize is 132. First 66-byte is R, Second 66-byte is S.\r
6250\r
6251 @param[in] EcContext Pointer to EC context for signature verification.\r
6252 @param[in] HashNid hash NID\r
6253 @param[in] MessageHash Pointer to octet message hash to be checked.\r
6254 @param[in] HashSize Size of the message hash in bytes.\r
6255 @param[in] Signature Pointer to EC-DSA signature to be verified.\r
6256 @param[in] SigSize Size of signature in bytes.\r
6257\r
6258 @retval TRUE Valid signature encoded in EC-DSA.\r
6259 @retval FALSE Invalid signature or invalid EC context.\r
6260\r
6261**/\r
6262BOOLEAN\r
6263EFIAPI\r
6264CryptoServiceEcDsaVerify (\r
6265 IN VOID *EcContext,\r
6266 IN UINTN HashNid,\r
6267 IN CONST UINT8 *MessageHash,\r
6268 IN UINTN HashSize,\r
6269 IN CONST UINT8 *Signature,\r
6270 IN UINTN SigSize\r
6271 )\r
6272{\r
6273 return CALL_BASECRYPTLIB (Ec.Services.DsaVerify, EcDsaVerify, (EcContext, HashNid, MessageHash, HashSize, Signature, SigSize), FALSE);\r
6274}\r
6275\r
7c342378 6276const EDKII_CRYPTO_PROTOCOL mEdkiiCrypto = {\r
cc1d13c9
MK
6277 /// Version\r
6278 CryptoServiceGetCryptoVersion,\r
b6174e2d
ZG
6279 /// HMAC MD5 - deprecated and unsupported\r
6280 DeprecatedCryptoServiceHmacMd5New,\r
6281 DeprecatedCryptoServiceHmacMd5Free,\r
6282 DeprecatedCryptoServiceHmacMd5SetKey,\r
6283 DeprecatedCryptoServiceHmacMd5Duplicate,\r
6284 DeprecatedCryptoServiceHmacMd5Update,\r
6285 DeprecatedCryptoServiceHmacMd5Final,\r
c812d320
ZG
6286 /// HMAC SHA1 - deprecated and unsupported\r
6287 DeprecatedCryptoServiceHmacSha1New,\r
6288 DeprecatedCryptoServiceHmacSha1Free,\r
6289 DeprecatedCryptoServiceHmacSha1SetKey,\r
6290 DeprecatedCryptoServiceHmacSha1Duplicate,\r
6291 DeprecatedCryptoServiceHmacSha1Update,\r
6292 DeprecatedCryptoServiceHmacSha1Final,\r
cc1d13c9
MK
6293 /// HMAC SHA256\r
6294 CryptoServiceHmacSha256New,\r
6295 CryptoServiceHmacSha256Free,\r
6296 CryptoServiceHmacSha256SetKey,\r
6297 CryptoServiceHmacSha256Duplicate,\r
6298 CryptoServiceHmacSha256Update,\r
6299 CryptoServiceHmacSha256Final,\r
0a6fc3d0
ZG
6300 /// Md4 - deprecated and unsupported\r
6301 DeprecatedCryptoServiceMd4GetContextSize,\r
6302 DeprecatedCryptoServiceMd4Init,\r
6303 DeprecatedCryptoServiceMd4Duplicate,\r
6304 DeprecatedCryptoServiceMd4Update,\r
6305 DeprecatedCryptoServiceMd4Final,\r
6306 DeprecatedCryptoServiceMd4HashAll,\r
7c342378 6307 #ifndef ENABLE_MD5_DEPRECATED_INTERFACES\r
acfd5557
ZG
6308 /// Md5 - deprecated and unsupported\r
6309 DeprecatedCryptoServiceMd5GetContextSize,\r
6310 DeprecatedCryptoServiceMd5Init,\r
6311 DeprecatedCryptoServiceMd5Duplicate,\r
6312 DeprecatedCryptoServiceMd5Update,\r
6313 DeprecatedCryptoServiceMd5Final,\r
6314 DeprecatedCryptoServiceMd5HashAll,\r
7c342378 6315 #else\r
cc1d13c9
MK
6316 /// Md5\r
6317 CryptoServiceMd5GetContextSize,\r
6318 CryptoServiceMd5Init,\r
6319 CryptoServiceMd5Duplicate,\r
6320 CryptoServiceMd5Update,\r
6321 CryptoServiceMd5Final,\r
6322 CryptoServiceMd5HashAll,\r
7c342378 6323 #endif\r
cc1d13c9
MK
6324 /// Pkcs\r
6325 CryptoServicePkcs1v2Encrypt,\r
6326 CryptoServicePkcs5HashPassword,\r
6327 CryptoServicePkcs7Verify,\r
6328 CryptoServiceVerifyEKUsInPkcs7Signature,\r
6329 CryptoServicePkcs7GetSigners,\r
6330 CryptoServicePkcs7FreeSigners,\r
6331 CryptoServicePkcs7Sign,\r
6332 CryptoServicePkcs7GetAttachedContent,\r
6333 CryptoServicePkcs7GetCertificatesList,\r
6334 CryptoServiceAuthenticodeVerify,\r
6335 CryptoServiceImageTimestampVerify,\r
6336 /// DH\r
6337 CryptoServiceDhNew,\r
6338 CryptoServiceDhFree,\r
6339 CryptoServiceDhGenerateParameter,\r
6340 CryptoServiceDhSetParameter,\r
6341 CryptoServiceDhGenerateKey,\r
6342 CryptoServiceDhComputeKey,\r
6343 /// Random\r
6344 CryptoServiceRandomSeed,\r
6345 CryptoServiceRandomBytes,\r
6346 /// RSA\r
6347 CryptoServiceRsaPkcs1Verify,\r
6348 CryptoServiceRsaNew,\r
6349 CryptoServiceRsaFree,\r
6350 CryptoServiceRsaSetKey,\r
6351 CryptoServiceRsaGetKey,\r
6352 CryptoServiceRsaGenerateKey,\r
6353 CryptoServiceRsaCheckKey,\r
6354 CryptoServiceRsaPkcs1Sign,\r
6355 CryptoServiceRsaPkcs1Verify,\r
6356 CryptoServiceRsaGetPrivateKeyFromPem,\r
6357 CryptoServiceRsaGetPublicKeyFromX509,\r
7c342378 6358 #ifdef DISABLE_SHA1_DEPRECATED_INTERFACES\r
0f01cec5
ZG
6359 /// Sha1 - deprecated and unsupported\r
6360 DeprecatedCryptoServiceSha1GetContextSize,\r
6361 DeprecatedCryptoServiceSha1Init,\r
6362 DeprecatedCryptoServiceSha1Duplicate,\r
6363 DeprecatedCryptoServiceSha1Update,\r
6364 DeprecatedCryptoServiceSha1Final,\r
6365 DeprecatedCryptoServiceSha1HashAll,\r
7c342378 6366 #else\r
cc1d13c9
MK
6367 /// Sha1\r
6368 CryptoServiceSha1GetContextSize,\r
6369 CryptoServiceSha1Init,\r
6370 CryptoServiceSha1Duplicate,\r
6371 CryptoServiceSha1Update,\r
6372 CryptoServiceSha1Final,\r
6373 CryptoServiceSha1HashAll,\r
7c342378 6374 #endif\r
cc1d13c9
MK
6375 /// Sha256\r
6376 CryptoServiceSha256GetContextSize,\r
6377 CryptoServiceSha256Init,\r
6378 CryptoServiceSha256Duplicate,\r
6379 CryptoServiceSha256Update,\r
6380 CryptoServiceSha256Final,\r
6381 CryptoServiceSha256HashAll,\r
6382 /// Sha384\r
6383 CryptoServiceSha384GetContextSize,\r
6384 CryptoServiceSha384Init,\r
6385 CryptoServiceSha384Duplicate,\r
6386 CryptoServiceSha384Update,\r
6387 CryptoServiceSha384Final,\r
6388 CryptoServiceSha384HashAll,\r
6389 /// Sha512\r
6390 CryptoServiceSha512GetContextSize,\r
6391 CryptoServiceSha512Init,\r
6392 CryptoServiceSha512Duplicate,\r
6393 CryptoServiceSha512Update,\r
6394 CryptoServiceSha512Final,\r
6395 CryptoServiceSha512HashAll,\r
6396 /// X509\r
6397 CryptoServiceX509GetSubjectName,\r
6398 CryptoServiceX509GetCommonName,\r
6399 CryptoServiceX509GetOrganizationName,\r
6400 CryptoServiceX509VerifyCert,\r
6401 CryptoServiceX509ConstructCertificate,\r
6402 CryptoServiceX509ConstructCertificateStack,\r
6403 CryptoServiceX509Free,\r
6404 CryptoServiceX509StackFree,\r
6405 CryptoServiceX509GetTBSCert,\r
b8af2c9e
ZG
6406 /// TDES - deprecated and unsupported\r
6407 DeprecatedCryptoServiceTdesGetContextSize,\r
6408 DeprecatedCryptoServiceTdesInit,\r
6409 DeprecatedCryptoServiceTdesEcbEncrypt,\r
6410 DeprecatedCryptoServiceTdesEcbDecrypt,\r
6411 DeprecatedCryptoServiceTdesCbcEncrypt,\r
6412 DeprecatedCryptoServiceTdesCbcDecrypt,\r
80e28dce 6413 /// AES - ECB mode is deprecated and unsupported\r
cc1d13c9
MK
6414 CryptoServiceAesGetContextSize,\r
6415 CryptoServiceAesInit,\r
80e28dce
ZG
6416 DeprecatedCryptoServiceAesEcbEncrypt,\r
6417 DeprecatedCryptoServiceAesEcbDecrypt,\r
cc1d13c9
MK
6418 CryptoServiceAesCbcEncrypt,\r
6419 CryptoServiceAesCbcDecrypt,\r
c22a32e1
ZG
6420 /// Arc4 - deprecated and unsupported\r
6421 DeprecatedCryptoServiceArc4GetContextSize,\r
6422 DeprecatedCryptoServiceArc4Init,\r
6423 DeprecatedCryptoServiceArc4Encrypt,\r
6424 DeprecatedCryptoServiceArc4Decrypt,\r
6425 DeprecatedCryptoServiceArc4Reset,\r
cc1d13c9
MK
6426 /// SM3\r
6427 CryptoServiceSm3GetContextSize,\r
6428 CryptoServiceSm3Init,\r
6429 CryptoServiceSm3Duplicate,\r
6430 CryptoServiceSm3Update,\r
6431 CryptoServiceSm3Final,\r
6432 CryptoServiceSm3HashAll,\r
6433 /// HKDF\r
6434 CryptoServiceHkdfSha256ExtractAndExpand,\r
6435 /// X509 (Continued)\r
6436 CryptoServiceX509ConstructCertificateStackV,\r
6437 /// TLS\r
6438 CryptoServiceTlsInitialize,\r
6439 CryptoServiceTlsCtxFree,\r
6440 CryptoServiceTlsCtxNew,\r
6441 CryptoServiceTlsFree,\r
6442 CryptoServiceTlsNew,\r
6443 CryptoServiceTlsInHandshake,\r
6444 CryptoServiceTlsDoHandshake,\r
6445 CryptoServiceTlsHandleAlert,\r
6446 CryptoServiceTlsCloseNotify,\r
6447 CryptoServiceTlsCtrlTrafficOut,\r
6448 CryptoServiceTlsCtrlTrafficIn,\r
6449 CryptoServiceTlsRead,\r
6450 CryptoServiceTlsWrite,\r
6451 /// TLS Set\r
6452 CryptoServiceTlsSetVersion,\r
6453 CryptoServiceTlsSetConnectionEnd,\r
6454 CryptoServiceTlsSetCipherList,\r
6455 CryptoServiceTlsSetCompressionMethod,\r
6456 CryptoServiceTlsSetVerify,\r
6457 CryptoServiceTlsSetVerifyHost,\r
6458 CryptoServiceTlsSetSessionId,\r
6459 CryptoServiceTlsSetCaCertificate,\r
6460 CryptoServiceTlsSetHostPublicCert,\r
6461 CryptoServiceTlsSetHostPrivateKey,\r
6462 CryptoServiceTlsSetCertRevocationList,\r
6463 /// TLS Get\r
6464 CryptoServiceTlsGetVersion,\r
6465 CryptoServiceTlsGetConnectionEnd,\r
6466 CryptoServiceTlsGetCurrentCipher,\r
6467 CryptoServiceTlsGetCurrentCompressionId,\r
6468 CryptoServiceTlsGetVerify,\r
6469 CryptoServiceTlsGetSessionId,\r
6470 CryptoServiceTlsGetClientRandom,\r
6471 CryptoServiceTlsGetServerRandom,\r
6472 CryptoServiceTlsGetKeyMaterial,\r
6473 CryptoServiceTlsGetCaCertificate,\r
6474 CryptoServiceTlsGetHostPublicCert,\r
6475 CryptoServiceTlsGetHostPrivateKey,\r
c1e66210
ZL
6476 CryptoServiceTlsGetCertRevocationList,\r
6477 /// RSA PSS\r
6478 CryptoServiceRsaPssSign,\r
6479 CryptoServiceRsaPssVerify,\r
6480 /// Parallel hash\r
3f77ccb9
QZ
6481 CryptoServiceParallelHash256HashAll,\r
6482 /// HMAC SHA256 (continued)\r
6483 CryptoServiceHmacSha256All,\r
6484 /// HMAC SHA384\r
6485 CryptoServiceHmacSha384New,\r
6486 CryptoServiceHmacSha384Free,\r
6487 CryptoServiceHmacSha384SetKey,\r
6488 CryptoServiceHmacSha384Duplicate,\r
6489 CryptoServiceHmacSha384Update,\r
6490 CryptoServiceHmacSha384Final,\r
e919c390
QZ
6491 CryptoServiceHmacSha384All,\r
6492 /// HKDF (continued)\r
6493 CryptoServiceHkdfSha256Extract,\r
6494 CryptoServiceHkdfSha256Expand,\r
6495 CryptoServiceHkdfSha384ExtractAndExpand,\r
6496 CryptoServiceHkdfSha384Extract,\r
022787f8
QZ
6497 CryptoServiceHkdfSha384Expand,\r
6498 /// Aead Aes GCM\r
6499 CryptoServiceAeadAesGcmEncrypt,\r
42951543
YL
6500 CryptoServiceAeadAesGcmDecrypt,\r
6501 /// Big Numbers\r
6502 CryptoServiceBigNumInit,\r
6503 CryptoServiceBigNumFromBin,\r
6504 CryptoServiceBigNumToBin,\r
6505 CryptoServiceBigNumFree,\r
6506 CryptoServiceBigNumAdd,\r
6507 CryptoServiceBigNumSub,\r
6508 CryptoServiceBigNumMod,\r
6509 CryptoServiceBigNumExpMod,\r
6510 CryptoServiceBigNumInverseMod,\r
6511 CryptoServiceBigNumDiv,\r
6512 CryptoServiceBigNumMulMod,\r
6513 CryptoServiceBigNumCmp,\r
6514 CryptoServiceBigNumBits,\r
6515 CryptoServiceBigNumBytes,\r
6516 CryptoServiceBigNumIsWord,\r
6517 CryptoServiceBigNumIsOdd,\r
6518 CryptoServiceBigNumCopy,\r
6519 CryptoServiceBigNumValueOne,\r
6520 CryptoServiceBigNumRShift,\r
6521 CryptoServiceBigNumConstTime,\r
6522 CryptoServiceBigNumSqrMod,\r
6523 CryptoServiceBigNumNewContext,\r
6524 CryptoServiceBigNumContextFree,\r
6525 CryptoServiceBigNumSetUint,\r
6526 CryptoServiceBigNumAddMod,\r
3b382f5b
YL
6527 /// EC\r
6528 CryptoServiceEcGroupInit,\r
6529 CryptoServiceEcGroupGetCurve,\r
6530 CryptoServiceEcGroupGetOrder,\r
6531 CryptoServiceEcGroupFree,\r
6532 CryptoServiceEcPointInit,\r
6533 CryptoServiceEcPointDeInit,\r
6534 CryptoServiceEcPointGetAffineCoordinates,\r
6535 CryptoServiceEcPointSetAffineCoordinates,\r
6536 CryptoServiceEcPointAdd,\r
6537 CryptoServiceEcPointMul,\r
6538 CryptoServiceEcPointInvert,\r
6539 CryptoServiceEcPointIsOnCurve,\r
6540 CryptoServiceEcPointIsAtInfinity,\r
6541 CryptoServiceEcPointEqual,\r
6542 CryptoServiceEcPointSetCompressedCoordinates,\r
6543 CryptoServiceEcNewByNid,\r
6544 CryptoServiceEcFree,\r
6545 CryptoServiceEcGenerateKey,\r
6546 CryptoServiceEcGetPubKey,\r
6547 CryptoServiceEcDhComputeKey,\r
8db4e9f9
YL
6548 /// TLS (continued)\r
6549 CryptoServiceTlsShutdown,\r
6550 /// TLS Set (continued)\r
6551 CryptoServiceTlsSetHostPrivateKeyEx,\r
6552 CryptoServiceTlsSetSignatureAlgoList,\r
6553 CryptoServiceTlsSetEcCurve,\r
6554 /// TLS Get (continued)\r
69a50a24
QZ
6555 CryptoServiceTlsGetExportKey,\r
6556 /// Ec (Continued)\r
6557 CryptoServiceEcGetPublicKeyFromX509,\r
6558 CryptoServiceEcGetPrivateKeyFromPem,\r
6559 CryptoServiceEcDsaSign,\r
6560 CryptoServiceEcDsaVerify\r
cc1d13c9 6561};\r