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