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