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