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