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 |
b7d1ba0a | 7 | Copyright (c) 2009 - 2016, 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 | |
143 | MD4 context should be already correctly intialized by Md4Init(), and should not be finalized\r | |
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 | |
172 | MD4 context should be already correctly intialized by Md4Init(), and should not be\r | |
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 | |
283 | MD5 context should be already correctly intialized by Md5Init(), and should not be finalized\r | |
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 | |
312 | MD5 context should be already correctly intialized by Md5Init(), and should not be\r | |
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 | |
423 | SHA-1 context should be already correctly intialized by Sha1Init(), and should not be finalized\r | |
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 | |
452 | SHA-1 context should be already correctly intialized by Sha1Init(), and should not be\r | |
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 | |
558 | SHA-256 context should be already correctly intialized by Sha256Init(), and should not be finalized\r | |
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 | |
585 | SHA-256 context should be already correctly intialized by Sha256Init(), and should not be\r | |
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 | |
689 | SHA-384 context should be already correctly intialized by Sha384Init(), and should not be finalized\r | |
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 | |
716 | SHA-384 context should be already correctly intialized by Sha384Init(), and should not be\r | |
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 | |
820 | SHA-512 context should be already correctly intialized by Sha512Init(), and should not be finalized\r | |
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 | |
847 | SHA-512 context should be already correctly intialized by Sha512Init(), and should not be\r | |
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 | |
900 | \r | |
532616bb | 901 | If this interface is not supported, then return zero.\r |
902 | \r | |
a8c44645 | 903 | @return The size, in bytes, of the context buffer required for HMAC-MD5 operations.\r |
532616bb | 904 | @retval 0 This interface is not supported.\r |
a8c44645 | 905 | \r |
906 | **/\r | |
907 | UINTN\r | |
908 | EFIAPI\r | |
909 | HmacMd5GetContextSize (\r | |
910 | VOID\r | |
911 | );\r | |
912 | \r | |
913 | /**\r | |
914 | Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for\r | |
915 | subsequent use.\r | |
916 | \r | |
16d2c32c | 917 | If HmacMd5Context is NULL, then return FALSE.\r |
532616bb | 918 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 919 | \r |
920 | @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initialized.\r | |
921 | @param[in] Key Pointer to the user-supplied key.\r | |
922 | @param[in] KeySize Key size in bytes.\r | |
923 | \r | |
924 | @retval TRUE HMAC-MD5 context initialization succeeded.\r | |
925 | @retval FALSE HMAC-MD5 context initialization failed.\r | |
532616bb | 926 | @retval FALSE This interface is not supported.\r |
a8c44645 | 927 | \r |
928 | **/\r | |
929 | BOOLEAN\r | |
930 | EFIAPI\r | |
931 | HmacMd5Init (\r | |
932 | OUT VOID *HmacMd5Context,\r | |
933 | IN CONST UINT8 *Key,\r | |
934 | IN UINTN KeySize\r | |
935 | );\r | |
936 | \r | |
937 | /**\r | |
938 | Makes a copy of an existing HMAC-MD5 context.\r | |
939 | \r | |
16d2c32c | 940 | If HmacMd5Context is NULL, then return FALSE.\r |
941 | If NewHmacMd5Context is NULL, then return FALSE.\r | |
532616bb | 942 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 943 | \r |
944 | @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.\r | |
945 | @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.\r | |
946 | \r | |
947 | @retval TRUE HMAC-MD5 context copy succeeded.\r | |
948 | @retval FALSE HMAC-MD5 context copy failed.\r | |
532616bb | 949 | @retval FALSE This interface is not supported.\r |
a8c44645 | 950 | \r |
951 | **/\r | |
952 | BOOLEAN\r | |
953 | EFIAPI\r | |
954 | HmacMd5Duplicate (\r | |
955 | IN CONST VOID *HmacMd5Context,\r | |
956 | OUT VOID *NewHmacMd5Context\r | |
957 | );\r | |
958 | \r | |
959 | /**\r | |
960 | Digests the input data and updates HMAC-MD5 context.\r | |
961 | \r | |
962 | This function performs HMAC-MD5 digest on a data buffer of the specified size.\r | |
963 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
964 | HMAC-MD5 context should be already correctly intialized by HmacMd5Init(), and should not be\r | |
965 | finalized by HmacMd5Final(). Behavior with invalid context is undefined.\r | |
966 | \r | |
16d2c32c | 967 | If HmacMd5Context is NULL, then return FALSE.\r |
532616bb | 968 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 969 | \r |
970 | @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.\r | |
971 | @param[in] Data Pointer to the buffer containing the data to be digested.\r | |
972 | @param[in] DataSize Size of Data buffer in bytes.\r | |
973 | \r | |
974 | @retval TRUE HMAC-MD5 data digest succeeded.\r | |
975 | @retval FALSE HMAC-MD5 data digest failed.\r | |
532616bb | 976 | @retval FALSE This interface is not supported.\r |
a8c44645 | 977 | \r |
978 | **/\r | |
979 | BOOLEAN\r | |
980 | EFIAPI\r | |
981 | HmacMd5Update (\r | |
982 | IN OUT VOID *HmacMd5Context,\r | |
983 | IN CONST VOID *Data,\r | |
984 | IN UINTN DataSize\r | |
985 | );\r | |
986 | \r | |
987 | /**\r | |
988 | Completes computation of the HMAC-MD5 digest value.\r | |
989 | \r | |
990 | This function completes HMAC-MD5 hash computation and retrieves the digest value into\r | |
991 | the specified memory. After this function has been called, the HMAC-MD5 context cannot\r | |
992 | be used again.\r | |
993 | HMAC-MD5 context should be already correctly intialized by HmacMd5Init(), and should not be\r | |
994 | finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.\r | |
995 | \r | |
16d2c32c | 996 | If HmacMd5Context is NULL, then return FALSE.\r |
997 | If HashValue is NULL, then return FALSE.\r | |
532616bb | 998 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 999 | \r |
1000 | @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.\r | |
1001 | @param[out] HashValue Pointer to a buffer that receives the HMAC-MD5 digest\r | |
1002 | value (16 bytes).\r | |
1003 | \r | |
1004 | @retval TRUE HMAC-MD5 digest computation succeeded.\r | |
1005 | @retval FALSE HMAC-MD5 digest computation failed.\r | |
532616bb | 1006 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1007 | \r |
1008 | **/\r | |
1009 | BOOLEAN\r | |
1010 | EFIAPI\r | |
1011 | HmacMd5Final (\r | |
1012 | IN OUT VOID *HmacMd5Context,\r | |
1013 | OUT UINT8 *HmacValue\r | |
1014 | );\r | |
1015 | \r | |
1016 | /**\r | |
1017 | Retrieves the size, in bytes, of the context buffer required for HMAC-SHA1 operations.\r | |
1018 | \r | |
532616bb | 1019 | If this interface is not supported, then return zero.\r |
1020 | \r | |
a8c44645 | 1021 | @return The size, in bytes, of the context buffer required for HMAC-SHA1 operations.\r |
532616bb | 1022 | @retval 0 This interface is not supported.\r |
a8c44645 | 1023 | \r |
1024 | **/\r | |
1025 | UINTN\r | |
1026 | EFIAPI\r | |
1027 | HmacSha1GetContextSize (\r | |
1028 | VOID\r | |
1029 | );\r | |
1030 | \r | |
1031 | /**\r | |
1032 | Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1 context for\r | |
1033 | subsequent use.\r | |
1034 | \r | |
16d2c32c | 1035 | If HmacSha1Context is NULL, then return FALSE.\r |
532616bb | 1036 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1037 | \r |
1038 | @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initialized.\r | |
1039 | @param[in] Key Pointer to the user-supplied key.\r | |
1040 | @param[in] KeySize Key size in bytes.\r | |
1041 | \r | |
1042 | @retval TRUE HMAC-SHA1 context initialization succeeded.\r | |
1043 | @retval FALSE HMAC-SHA1 context initialization failed.\r | |
532616bb | 1044 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1045 | \r |
1046 | **/\r | |
1047 | BOOLEAN\r | |
1048 | EFIAPI\r | |
1049 | HmacSha1Init (\r | |
1050 | OUT VOID *HmacSha1Context,\r | |
1051 | IN CONST UINT8 *Key,\r | |
1052 | IN UINTN KeySize\r | |
1053 | );\r | |
1054 | \r | |
1055 | /**\r | |
1056 | Makes a copy of an existing HMAC-SHA1 context.\r | |
1057 | \r | |
16d2c32c | 1058 | If HmacSha1Context is NULL, then return FALSE.\r |
1059 | If NewHmacSha1Context is NULL, then return FALSE.\r | |
532616bb | 1060 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1061 | \r |
1062 | @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied.\r | |
1063 | @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context.\r | |
1064 | \r | |
1065 | @retval TRUE HMAC-SHA1 context copy succeeded.\r | |
1066 | @retval FALSE HMAC-SHA1 context copy failed.\r | |
532616bb | 1067 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1068 | \r |
1069 | **/\r | |
1070 | BOOLEAN\r | |
1071 | EFIAPI\r | |
1072 | HmacSha1Duplicate (\r | |
1073 | IN CONST VOID *HmacSha1Context,\r | |
1074 | OUT VOID *NewHmacSha1Context\r | |
1075 | );\r | |
1076 | \r | |
1077 | /**\r | |
1078 | Digests the input data and updates HMAC-SHA1 context.\r | |
1079 | \r | |
1080 | This function performs HMAC-SHA1 digest on a data buffer of the specified size.\r | |
1081 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
1082 | HMAC-SHA1 context should be already correctly intialized by HmacSha1Init(), and should not\r | |
1083 | be finalized by HmacSha1Final(). Behavior with invalid context is undefined.\r | |
1084 | \r | |
16d2c32c | 1085 | If HmacSha1Context is NULL, then return FALSE.\r |
532616bb | 1086 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1087 | \r |
1088 | @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.\r | |
1089 | @param[in] Data Pointer to the buffer containing the data to be digested.\r | |
1090 | @param[in] DataSize Size of Data buffer in bytes.\r | |
1091 | \r | |
1092 | @retval TRUE HMAC-SHA1 data digest succeeded.\r | |
1093 | @retval FALSE HMAC-SHA1 data digest failed.\r | |
532616bb | 1094 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1095 | \r |
1096 | **/\r | |
1097 | BOOLEAN\r | |
1098 | EFIAPI\r | |
1099 | HmacSha1Update (\r | |
1100 | IN OUT VOID *HmacSha1Context,\r | |
1101 | IN CONST VOID *Data,\r | |
1102 | IN UINTN DataSize\r | |
1103 | );\r | |
1104 | \r | |
1105 | /**\r | |
1106 | Completes computation of the HMAC-SHA1 digest value.\r | |
1107 | \r | |
1108 | This function completes HMAC-SHA1 hash computation and retrieves the digest value into\r | |
1109 | the specified memory. After this function has been called, the HMAC-SHA1 context cannot\r | |
1110 | be used again.\r | |
1111 | HMAC-SHA1 context should be already correctly intialized by HmacSha1Init(), and should\r | |
1112 | not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined.\r | |
1113 | \r | |
16d2c32c | 1114 | If HmacSha1Context is NULL, then return FALSE.\r |
1115 | If HashValue is NULL, then return FALSE.\r | |
532616bb | 1116 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1117 | \r |
1118 | @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context.\r | |
1119 | @param[out] HashValue Pointer to a buffer that receives the HMAC-SHA1 digest\r | |
1120 | value (20 bytes).\r | |
1121 | \r | |
1122 | @retval TRUE HMAC-SHA1 digest computation succeeded.\r | |
1123 | @retval FALSE HMAC-SHA1 digest computation failed.\r | |
532616bb | 1124 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1125 | \r |
1126 | **/\r | |
1127 | BOOLEAN\r | |
1128 | EFIAPI\r | |
1129 | HmacSha1Final (\r | |
1130 | IN OUT VOID *HmacSha1Context,\r | |
1131 | OUT UINT8 *HmacValue\r | |
1132 | );\r | |
97f98500 | 1133 | \r |
97f98500 HT |
1134 | //=====================================================================================\r |
1135 | // Symmetric Cryptography Primitive\r | |
1136 | //=====================================================================================\r | |
1137 | \r | |
a8c44645 | 1138 | /**\r |
1139 | Retrieves the size, in bytes, of the context buffer required for TDES operations.\r | |
1140 | \r | |
532616bb | 1141 | If this interface is not supported, then return zero.\r |
1142 | \r | |
a8c44645 | 1143 | @return The size, in bytes, of the context buffer required for TDES operations.\r |
532616bb | 1144 | @retval 0 This interface is not supported.\r |
a8c44645 | 1145 | \r |
1146 | **/\r | |
1147 | UINTN\r | |
1148 | EFIAPI\r | |
1149 | TdesGetContextSize (\r | |
1150 | VOID\r | |
1151 | );\r | |
1152 | \r | |
1153 | /**\r | |
1154 | Initializes user-supplied memory as TDES context for subsequent use.\r | |
1155 | \r | |
1156 | This function initializes user-supplied memory pointed by TdesContext as TDES context.\r | |
6b8ebcb8 | 1157 | In addition, it sets up all TDES key materials for subsequent encryption and decryption\r |
a8c44645 | 1158 | operations.\r |
1159 | There are 3 key options as follows:\r | |
1160 | KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES)\r | |
1161 | KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security)\r | |
1162 | KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest)\r | |
1163 | \r | |
16d2c32c | 1164 | If TdesContext is NULL, then return FALSE.\r |
1165 | If Key is NULL, then return FALSE.\r | |
1166 | If KeyLength is not valid, then return FALSE.\r | |
532616bb | 1167 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1168 | \r |
1169 | @param[out] TdesContext Pointer to TDES context being initialized.\r | |
1170 | @param[in] Key Pointer to the user-supplied TDES key.\r | |
1171 | @param[in] KeyLength Length of TDES key in bits.\r | |
1172 | \r | |
1173 | @retval TRUE TDES context initialization succeeded.\r | |
1174 | @retval FALSE TDES context initialization failed.\r | |
532616bb | 1175 | @retval FALSE This interface is not supported.\r |
97f98500 | 1176 | \r |
a8c44645 | 1177 | **/\r |
1178 | BOOLEAN\r | |
1179 | EFIAPI\r | |
1180 | TdesInit (\r | |
1181 | OUT VOID *TdesContext,\r | |
1182 | IN CONST UINT8 *Key,\r | |
1183 | IN UINTN KeyLength\r | |
1184 | );\r | |
1185 | \r | |
1186 | /**\r | |
1187 | Performs TDES encryption on a data buffer of the specified size in ECB mode.\r | |
1188 | \r | |
1189 | This function performs TDES encryption on data buffer pointed by Input, of specified\r | |
1190 | size of InputSize, in ECB mode.\r | |
1191 | InputSize must be multiple of block size (8 bytes). This function does not perform\r | |
1192 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1193 | TdesContext should be already correctly initialized by TdesInit(). Behavior with\r | |
1194 | invalid TDES context is undefined.\r | |
1195 | \r | |
16d2c32c | 1196 | If TdesContext is NULL, then return FALSE.\r |
1197 | If Input is NULL, then return FALSE.\r | |
1198 | If InputSize is not multiple of block size (8 bytes), then return FALSE.\r | |
1199 | If Output is NULL, then return FALSE.\r | |
532616bb | 1200 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1201 | \r |
1202 | @param[in] TdesContext Pointer to the TDES context.\r | |
1203 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1204 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1205 | @param[out] Output Pointer to a buffer that receives the TDES encryption output.\r | |
1206 | \r | |
1207 | @retval TRUE TDES encryption succeeded.\r | |
1208 | @retval FALSE TDES encryption failed.\r | |
532616bb | 1209 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1210 | \r |
1211 | **/\r | |
1212 | BOOLEAN\r | |
1213 | EFIAPI\r | |
1214 | TdesEcbEncrypt (\r | |
1215 | IN VOID *TdesContext,\r | |
1216 | IN CONST UINT8 *Input,\r | |
1217 | IN UINTN InputSize,\r | |
1218 | OUT UINT8 *Output\r | |
1219 | );\r | |
1220 | \r | |
1221 | /**\r | |
1222 | Performs TDES decryption on a data buffer of the specified size in ECB mode.\r | |
1223 | \r | |
1224 | This function performs TDES decryption on data buffer pointed by Input, of specified\r | |
1225 | size of InputSize, in ECB mode.\r | |
1226 | InputSize must be multiple of block size (8 bytes). This function does not perform\r | |
1227 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1228 | TdesContext should be already correctly initialized by TdesInit(). Behavior with\r | |
1229 | invalid TDES context is undefined.\r | |
1230 | \r | |
16d2c32c | 1231 | If TdesContext is NULL, then return FALSE.\r |
1232 | If Input is NULL, then return FALSE.\r | |
1233 | If InputSize is not multiple of block size (8 bytes), then return FALSE.\r | |
1234 | If Output is NULL, then return FALSE.\r | |
532616bb | 1235 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1236 | \r |
1237 | @param[in] TdesContext Pointer to the TDES context.\r | |
1238 | @param[in] Input Pointer to the buffer containing the data to be decrypted.\r | |
1239 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1240 | @param[out] Output Pointer to a buffer that receives the TDES decryption output.\r | |
1241 | \r | |
1242 | @retval TRUE TDES decryption succeeded.\r | |
1243 | @retval FALSE TDES decryption failed.\r | |
532616bb | 1244 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1245 | \r |
1246 | **/\r | |
1247 | BOOLEAN\r | |
1248 | EFIAPI\r | |
1249 | TdesEcbDecrypt (\r | |
1250 | IN VOID *TdesContext,\r | |
1251 | IN CONST UINT8 *Input,\r | |
1252 | IN UINTN InputSize,\r | |
1253 | OUT UINT8 *Output\r | |
1254 | );\r | |
1255 | \r | |
1256 | /**\r | |
1257 | Performs TDES encryption on a data buffer of the specified size in CBC mode.\r | |
1258 | \r | |
1259 | This function performs TDES encryption on data buffer pointed by Input, of specified\r | |
1260 | size of InputSize, in CBC mode.\r | |
1261 | InputSize must be multiple of block size (8 bytes). This function does not perform\r | |
1262 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1263 | Initialization vector should be one block size (8 bytes).\r | |
1264 | TdesContext should be already correctly initialized by TdesInit(). Behavior with\r | |
1265 | invalid TDES context is undefined.\r | |
1266 | \r | |
16d2c32c | 1267 | If TdesContext is NULL, then return FALSE.\r |
1268 | If Input is NULL, then return FALSE.\r | |
1269 | If InputSize is not multiple of block size (8 bytes), then return FALSE.\r | |
1270 | If Ivec is NULL, then return FALSE.\r | |
1271 | If Output is NULL, then return FALSE.\r | |
532616bb | 1272 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1273 | \r |
1274 | @param[in] TdesContext Pointer to the TDES context.\r | |
1275 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1276 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1277 | @param[in] Ivec Pointer to initialization vector.\r | |
1278 | @param[out] Output Pointer to a buffer that receives the TDES encryption output.\r | |
1279 | \r | |
1280 | @retval TRUE TDES encryption succeeded.\r | |
1281 | @retval FALSE TDES encryption failed.\r | |
532616bb | 1282 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1283 | \r |
1284 | **/\r | |
1285 | BOOLEAN\r | |
1286 | EFIAPI\r | |
1287 | TdesCbcEncrypt (\r | |
1288 | IN VOID *TdesContext,\r | |
1289 | IN CONST UINT8 *Input,\r | |
1290 | IN UINTN InputSize,\r | |
1291 | IN CONST UINT8 *Ivec,\r | |
1292 | OUT UINT8 *Output\r | |
1293 | );\r | |
1294 | \r | |
1295 | /**\r | |
1296 | Performs TDES decryption on a data buffer of the specified size in CBC mode.\r | |
1297 | \r | |
1298 | This function performs TDES decryption on data buffer pointed by Input, of specified\r | |
1299 | size of InputSize, in CBC mode.\r | |
1300 | InputSize must be multiple of block size (8 bytes). This function does not perform\r | |
1301 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1302 | Initialization vector should be one block size (8 bytes).\r | |
1303 | TdesContext should be already correctly initialized by TdesInit(). Behavior with\r | |
1304 | invalid TDES context is undefined.\r | |
1305 | \r | |
16d2c32c | 1306 | If TdesContext is NULL, then return FALSE.\r |
1307 | If Input is NULL, then return FALSE.\r | |
1308 | If InputSize is not multiple of block size (8 bytes), then return FALSE.\r | |
1309 | If Ivec is NULL, then return FALSE.\r | |
1310 | If Output is NULL, then return FALSE.\r | |
532616bb | 1311 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1312 | \r |
1313 | @param[in] TdesContext Pointer to the TDES context.\r | |
1314 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1315 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1316 | @param[in] Ivec Pointer to initialization vector.\r | |
1317 | @param[out] Output Pointer to a buffer that receives the TDES encryption output.\r | |
1318 | \r | |
1319 | @retval TRUE TDES decryption succeeded.\r | |
1320 | @retval FALSE TDES decryption failed.\r | |
532616bb | 1321 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1322 | \r |
1323 | **/\r | |
1324 | BOOLEAN\r | |
1325 | EFIAPI\r | |
1326 | TdesCbcDecrypt (\r | |
1327 | IN VOID *TdesContext,\r | |
1328 | IN CONST UINT8 *Input,\r | |
1329 | IN UINTN InputSize,\r | |
1330 | IN CONST UINT8 *Ivec,\r | |
1331 | OUT UINT8 *Output\r | |
1332 | );\r | |
1333 | \r | |
1334 | /**\r | |
1335 | Retrieves the size, in bytes, of the context buffer required for AES operations.\r | |
1336 | \r | |
532616bb | 1337 | If this interface is not supported, then return zero.\r |
1338 | \r | |
a8c44645 | 1339 | @return The size, in bytes, of the context buffer required for AES operations.\r |
532616bb | 1340 | @retval 0 This interface is not supported.\r |
a8c44645 | 1341 | \r |
1342 | **/\r | |
1343 | UINTN\r | |
1344 | EFIAPI\r | |
1345 | AesGetContextSize (\r | |
1346 | VOID\r | |
1347 | );\r | |
1348 | \r | |
1349 | /**\r | |
1350 | Initializes user-supplied memory as AES context for subsequent use.\r | |
1351 | \r | |
1352 | This function initializes user-supplied memory pointed by AesContext as AES context.\r | |
6b8ebcb8 | 1353 | In addition, it sets up all AES key materials for subsequent encryption and decryption\r |
a8c44645 | 1354 | operations.\r |
1355 | There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r | |
1356 | \r | |
16d2c32c | 1357 | If AesContext is NULL, then return FALSE.\r |
1358 | If Key is NULL, then return FALSE.\r | |
1359 | If KeyLength is not valid, then return FALSE.\r | |
532616bb | 1360 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1361 | \r |
1362 | @param[out] AesContext Pointer to AES context being initialized.\r | |
1363 | @param[in] Key Pointer to the user-supplied AES key.\r | |
1364 | @param[in] KeyLength Length of AES key in bits.\r | |
1365 | \r | |
1366 | @retval TRUE AES context initialization succeeded.\r | |
1367 | @retval FALSE AES context initialization failed.\r | |
532616bb | 1368 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1369 | \r |
1370 | **/\r | |
1371 | BOOLEAN\r | |
1372 | EFIAPI\r | |
1373 | AesInit (\r | |
1374 | OUT VOID *AesContext,\r | |
1375 | IN CONST UINT8 *Key,\r | |
1376 | IN UINTN KeyLength\r | |
1377 | );\r | |
1378 | \r | |
1379 | /**\r | |
1380 | Performs AES encryption on a data buffer of the specified size in ECB mode.\r | |
1381 | \r | |
1382 | This function performs AES encryption on data buffer pointed by Input, of specified\r | |
1383 | size of InputSize, in ECB mode.\r | |
1384 | InputSize must be multiple of block size (16 bytes). This function does not perform\r | |
1385 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1386 | AesContext should be already correctly initialized by AesInit(). Behavior with\r | |
1387 | invalid AES context is undefined.\r | |
1388 | \r | |
16d2c32c | 1389 | If AesContext is NULL, then return FALSE.\r |
1390 | If Input is NULL, then return FALSE.\r | |
1391 | If InputSize is not multiple of block size (16 bytes), then return FALSE.\r | |
1392 | If Output is NULL, then return FALSE.\r | |
532616bb | 1393 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1394 | \r |
1395 | @param[in] AesContext Pointer to the AES context.\r | |
1396 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1397 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1398 | @param[out] Output Pointer to a buffer that receives the AES encryption output.\r | |
1399 | \r | |
1400 | @retval TRUE AES encryption succeeded.\r | |
1401 | @retval FALSE AES encryption failed.\r | |
532616bb | 1402 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1403 | \r |
1404 | **/\r | |
1405 | BOOLEAN\r | |
1406 | EFIAPI\r | |
1407 | AesEcbEncrypt (\r | |
1408 | IN VOID *AesContext,\r | |
1409 | IN CONST UINT8 *Input,\r | |
1410 | IN UINTN InputSize,\r | |
1411 | OUT UINT8 *Output\r | |
1412 | );\r | |
1413 | \r | |
1414 | /**\r | |
1415 | Performs AES decryption on a data buffer of the specified size in ECB mode.\r | |
1416 | \r | |
1417 | This function performs AES decryption on data buffer pointed by Input, of specified\r | |
1418 | size of InputSize, in ECB mode.\r | |
1419 | InputSize must be multiple of block size (16 bytes). This function does not perform\r | |
1420 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1421 | AesContext should be already correctly initialized by AesInit(). Behavior with\r | |
1422 | invalid AES context is undefined.\r | |
1423 | \r | |
16d2c32c | 1424 | If AesContext is NULL, then return FALSE.\r |
1425 | If Input is NULL, then return FALSE.\r | |
1426 | If InputSize is not multiple of block size (16 bytes), then return FALSE.\r | |
1427 | If Output is NULL, then return FALSE.\r | |
532616bb | 1428 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1429 | \r |
1430 | @param[in] AesContext Pointer to the AES context.\r | |
1431 | @param[in] Input Pointer to the buffer containing the data to be decrypted.\r | |
1432 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1433 | @param[out] Output Pointer to a buffer that receives the AES decryption output.\r | |
1434 | \r | |
1435 | @retval TRUE AES decryption succeeded.\r | |
1436 | @retval FALSE AES decryption failed.\r | |
532616bb | 1437 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1438 | \r |
1439 | **/\r | |
1440 | BOOLEAN\r | |
1441 | EFIAPI\r | |
1442 | AesEcbDecrypt (\r | |
1443 | IN VOID *AesContext,\r | |
1444 | IN CONST UINT8 *Input,\r | |
1445 | IN UINTN InputSize,\r | |
1446 | OUT UINT8 *Output\r | |
1447 | );\r | |
1448 | \r | |
1449 | /**\r | |
1450 | Performs AES encryption on a data buffer of the specified size in CBC mode.\r | |
1451 | \r | |
1452 | This function performs AES encryption on data buffer pointed by Input, of specified\r | |
1453 | size of InputSize, in CBC mode.\r | |
1454 | InputSize must be multiple of block size (16 bytes). This function does not perform\r | |
1455 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1456 | Initialization vector should be one block size (16 bytes).\r | |
1457 | AesContext should be already correctly initialized by AesInit(). Behavior with\r | |
1458 | invalid AES context is undefined.\r | |
1459 | \r | |
16d2c32c | 1460 | If AesContext is NULL, then return FALSE.\r |
1461 | If Input is NULL, then return FALSE.\r | |
1462 | If InputSize is not multiple of block size (16 bytes), then return FALSE.\r | |
1463 | If Ivec is NULL, then return FALSE.\r | |
1464 | If Output is NULL, then return FALSE.\r | |
532616bb | 1465 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1466 | \r |
1467 | @param[in] AesContext Pointer to the AES context.\r | |
1468 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1469 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1470 | @param[in] Ivec Pointer to initialization vector.\r | |
1471 | @param[out] Output Pointer to a buffer that receives the AES encryption output.\r | |
1472 | \r | |
1473 | @retval TRUE AES encryption succeeded.\r | |
1474 | @retval FALSE AES encryption failed.\r | |
532616bb | 1475 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1476 | \r |
1477 | **/\r | |
1478 | BOOLEAN\r | |
1479 | EFIAPI\r | |
1480 | AesCbcEncrypt (\r | |
1481 | IN VOID *AesContext,\r | |
1482 | IN CONST UINT8 *Input,\r | |
1483 | IN UINTN InputSize,\r | |
1484 | IN CONST UINT8 *Ivec,\r | |
1485 | OUT UINT8 *Output\r | |
1486 | );\r | |
1487 | \r | |
1488 | /**\r | |
1489 | Performs AES decryption on a data buffer of the specified size in CBC mode.\r | |
1490 | \r | |
1491 | This function performs AES decryption on data buffer pointed by Input, of specified\r | |
1492 | size of InputSize, in CBC mode.\r | |
1493 | InputSize must be multiple of block size (16 bytes). This function does not perform\r | |
1494 | padding. Caller must perform padding, if necessary, to ensure valid input data size.\r | |
1495 | Initialization vector should be one block size (16 bytes).\r | |
1496 | AesContext should be already correctly initialized by AesInit(). Behavior with\r | |
1497 | invalid AES context is undefined.\r | |
1498 | \r | |
16d2c32c | 1499 | If AesContext is NULL, then return FALSE.\r |
1500 | If Input is NULL, then return FALSE.\r | |
1501 | If InputSize is not multiple of block size (16 bytes), then return FALSE.\r | |
1502 | If Ivec is NULL, then return FALSE.\r | |
1503 | If Output is NULL, then return FALSE.\r | |
532616bb | 1504 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1505 | \r |
1506 | @param[in] AesContext Pointer to the AES context.\r | |
1507 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1508 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1509 | @param[in] Ivec Pointer to initialization vector.\r | |
1510 | @param[out] Output Pointer to a buffer that receives the AES encryption output.\r | |
1511 | \r | |
1512 | @retval TRUE AES decryption succeeded.\r | |
1513 | @retval FALSE AES decryption failed.\r | |
532616bb | 1514 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1515 | \r |
1516 | **/\r | |
1517 | BOOLEAN\r | |
1518 | EFIAPI\r | |
1519 | AesCbcDecrypt (\r | |
1520 | IN VOID *AesContext,\r | |
1521 | IN CONST UINT8 *Input,\r | |
1522 | IN UINTN InputSize,\r | |
1523 | IN CONST UINT8 *Ivec,\r | |
1524 | OUT UINT8 *Output\r | |
1525 | );\r | |
1526 | \r | |
1527 | /**\r | |
1528 | Retrieves the size, in bytes, of the context buffer required for ARC4 operations.\r | |
1529 | \r | |
532616bb | 1530 | If this interface is not supported, then return zero.\r |
1531 | \r | |
a8c44645 | 1532 | @return The size, in bytes, of the context buffer required for ARC4 operations.\r |
532616bb | 1533 | @retval 0 This interface is not supported.\r |
a8c44645 | 1534 | \r |
1535 | **/\r | |
1536 | UINTN\r | |
1537 | EFIAPI\r | |
1538 | Arc4GetContextSize (\r | |
1539 | VOID\r | |
1540 | );\r | |
1541 | \r | |
1542 | /**\r | |
1543 | Initializes user-supplied memory as ARC4 context for subsequent use.\r | |
1544 | \r | |
1545 | This function initializes user-supplied memory pointed by Arc4Context as ARC4 context.\r | |
6b8ebcb8 | 1546 | In addition, it sets up all ARC4 key materials for subsequent encryption and decryption\r |
a8c44645 | 1547 | operations.\r |
1548 | \r | |
16d2c32c | 1549 | If Arc4Context is NULL, then return FALSE.\r |
1550 | If Key is NULL, then return FALSE.\r | |
1551 | If KeySize does not in the range of [5, 256] bytes, then return FALSE.\r | |
532616bb | 1552 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1553 | \r |
1554 | @param[out] Arc4Context Pointer to ARC4 context being initialized.\r | |
1555 | @param[in] Key Pointer to the user-supplied ARC4 key.\r | |
1556 | @param[in] KeySize Size of ARC4 key in bytes.\r | |
1557 | \r | |
1558 | @retval TRUE ARC4 context initialization succeeded.\r | |
1559 | @retval FALSE ARC4 context initialization failed.\r | |
532616bb | 1560 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1561 | \r |
1562 | **/\r | |
1563 | BOOLEAN\r | |
1564 | EFIAPI\r | |
1565 | Arc4Init (\r | |
1566 | OUT VOID *Arc4Context,\r | |
1567 | IN CONST UINT8 *Key,\r | |
1568 | IN UINTN KeySize\r | |
1569 | );\r | |
1570 | \r | |
1571 | /**\r | |
1572 | Performs ARC4 encryption on a data buffer of the specified size.\r | |
1573 | \r | |
1574 | This function performs ARC4 encryption on data buffer pointed by Input, of specified\r | |
1575 | size of InputSize.\r | |
1576 | Arc4Context should be already correctly initialized by Arc4Init(). Behavior with\r | |
1577 | invalid ARC4 context is undefined.\r | |
1578 | \r | |
16d2c32c | 1579 | If Arc4Context is NULL, then return FALSE.\r |
1580 | If Input is NULL, then return FALSE.\r | |
1581 | If Output is NULL, then return FALSE.\r | |
532616bb | 1582 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1583 | \r |
1584 | @param[in] Arc4Context Pointer to the ARC4 context.\r | |
1585 | @param[in] Input Pointer to the buffer containing the data to be encrypted.\r | |
1586 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1587 | @param[out] Output Pointer to a buffer that receives the ARC4 encryption output.\r | |
1588 | \r | |
1589 | @retval TRUE ARC4 encryption succeeded.\r | |
1590 | @retval FALSE ARC4 encryption failed.\r | |
532616bb | 1591 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1592 | \r |
1593 | **/\r | |
1594 | BOOLEAN\r | |
1595 | EFIAPI\r | |
1596 | Arc4Encrypt (\r | |
1597 | IN OUT VOID *Arc4Context,\r | |
1598 | IN CONST UINT8 *Input,\r | |
1599 | IN UINTN InputSize,\r | |
1600 | OUT UINT8 *Output\r | |
1601 | );\r | |
1602 | \r | |
1603 | /**\r | |
1604 | Performs ARC4 decryption on a data buffer of the specified size.\r | |
1605 | \r | |
1606 | This function performs ARC4 decryption on data buffer pointed by Input, of specified\r | |
1607 | size of InputSize.\r | |
1608 | Arc4Context should be already correctly initialized by Arc4Init(). Behavior with\r | |
1609 | invalid ARC4 context is undefined.\r | |
1610 | \r | |
16d2c32c | 1611 | If Arc4Context is NULL, then return FALSE.\r |
1612 | If Input is NULL, then return FALSE.\r | |
1613 | If Output is NULL, then return FALSE.\r | |
532616bb | 1614 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1615 | \r |
1616 | @param[in] Arc4Context Pointer to the ARC4 context.\r | |
1617 | @param[in] Input Pointer to the buffer containing the data to be decrypted.\r | |
1618 | @param[in] InputSize Size of the Input buffer in bytes.\r | |
1619 | @param[out] Output Pointer to a buffer that receives the ARC4 decryption output.\r | |
1620 | \r | |
1621 | @retval TRUE ARC4 decryption succeeded.\r | |
1622 | @retval FALSE ARC4 decryption failed.\r | |
532616bb | 1623 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1624 | \r |
1625 | **/\r | |
1626 | BOOLEAN\r | |
1627 | EFIAPI\r | |
1628 | Arc4Decrypt (\r | |
1629 | IN OUT VOID *Arc4Context,\r | |
1630 | IN UINT8 *Input,\r | |
1631 | IN UINTN InputSize,\r | |
1632 | OUT UINT8 *Output\r | |
1633 | );\r | |
1634 | \r | |
1635 | /**\r | |
1636 | Resets the ARC4 context to the initial state.\r | |
1637 | \r | |
1638 | The function resets the ARC4 context to the state it had immediately after the\r | |
1639 | ARC4Init() function call.\r | |
1640 | Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context\r | |
1641 | should be already correctly initialized by ARC4Init().\r | |
1642 | \r | |
16d2c32c | 1643 | If Arc4Context is NULL, then return FALSE.\r |
532616bb | 1644 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1645 | \r |
1646 | @param[in, out] Arc4Context Pointer to the ARC4 context.\r | |
1647 | \r | |
1648 | @retval TRUE ARC4 reset succeeded.\r | |
1649 | @retval FALSE ARC4 reset failed.\r | |
532616bb | 1650 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1651 | \r |
1652 | **/\r | |
1653 | BOOLEAN\r | |
1654 | EFIAPI\r | |
1655 | Arc4Reset (\r | |
1656 | IN OUT VOID *Arc4Context\r | |
1657 | );\r | |
97f98500 HT |
1658 | \r |
1659 | //=====================================================================================\r | |
1660 | // Asymmetric Cryptography Primitive\r | |
1661 | //=====================================================================================\r | |
1662 | \r | |
1663 | /**\r | |
a8c44645 | 1664 | Allocates and initializes one RSA context for subsequent use.\r |
97f98500 | 1665 | \r |
a8c44645 | 1666 | @return Pointer to the RSA context that has been initialized.\r |
97f98500 HT |
1667 | If the allocations fails, RsaNew() returns NULL.\r |
1668 | \r | |
1669 | **/\r | |
1670 | VOID *\r | |
1671 | EFIAPI\r | |
1672 | RsaNew (\r | |
1673 | VOID\r | |
1674 | );\r | |
1675 | \r | |
97f98500 | 1676 | /**\r |
a8c44645 | 1677 | Release the specified RSA context.\r |
1678 | \r | |
16d2c32c | 1679 | If RsaContext is NULL, then return FALSE.\r |
97f98500 HT |
1680 | \r |
1681 | @param[in] RsaContext Pointer to the RSA context to be released.\r | |
1682 | \r | |
1683 | **/\r | |
1684 | VOID\r | |
1685 | EFIAPI\r | |
1686 | RsaFree (\r | |
1687 | IN VOID *RsaContext\r | |
1688 | );\r | |
1689 | \r | |
97f98500 | 1690 | /**\r |
a8c44645 | 1691 | Sets the tag-designated key component into the established RSA context.\r |
1692 | \r | |
1693 | This function sets the tag-designated RSA key component into the established\r | |
1694 | RSA context from the user-specified non-negative integer (octet string format\r | |
1695 | represented in RSA PKCS#1).\r | |
1696 | If BigNumber is NULL, then the specified key componenet in RSA context is cleared.\r | |
97f98500 | 1697 | \r |
16d2c32c | 1698 | If RsaContext is NULL, then return FALSE.\r |
97f98500 HT |
1699 | \r |
1700 | @param[in, out] RsaContext Pointer to RSA context being set.\r | |
1701 | @param[in] KeyTag Tag of RSA key component being set.\r | |
1702 | @param[in] BigNumber Pointer to octet integer buffer.\r | |
a8c44645 | 1703 | If NULL, then the specified key componenet in RSA\r |
1704 | context is cleared.\r | |
1705 | @param[in] BnSize Size of big number buffer in bytes.\r | |
1706 | If BigNumber is NULL, then it is ignored.\r | |
97f98500 | 1707 | \r |
a8c44645 | 1708 | @retval TRUE RSA key component was set successfully.\r |
1709 | @retval FALSE Invalid RSA key component tag.\r | |
97f98500 HT |
1710 | \r |
1711 | **/\r | |
1712 | BOOLEAN\r | |
1713 | EFIAPI\r | |
1714 | RsaSetKey (\r | |
a8c44645 | 1715 | IN OUT VOID *RsaContext,\r |
1716 | IN RSA_KEY_TAG KeyTag,\r | |
1717 | IN CONST UINT8 *BigNumber,\r | |
1718 | IN UINTN BnSize\r | |
1719 | );\r | |
1720 | \r | |
1721 | /**\r | |
1722 | Gets the tag-designated RSA key component from the established RSA context.\r | |
1723 | \r | |
1724 | This function retrieves the tag-designated RSA key component from the\r | |
1725 | established RSA context as a non-negative integer (octet string format\r | |
1726 | represented in RSA PKCS#1).\r | |
1727 | If specified key component has not been set or has been cleared, then returned\r | |
1728 | BnSize is set to 0.\r | |
1729 | If the BigNumber buffer is too small to hold the contents of the key, FALSE\r | |
1730 | is returned and BnSize is set to the required buffer size to obtain the key.\r | |
1731 | \r | |
16d2c32c | 1732 | If RsaContext is NULL, then return FALSE.\r |
1733 | If BnSize is NULL, then return FALSE.\r | |
1734 | If BnSize is large enough but BigNumber is NULL, then return FALSE.\r | |
532616bb | 1735 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1736 | \r |
1737 | @param[in, out] RsaContext Pointer to RSA context being set.\r | |
1738 | @param[in] KeyTag Tag of RSA key component being set.\r | |
1739 | @param[out] BigNumber Pointer to octet integer buffer.\r | |
1740 | @param[in, out] BnSize On input, the size of big number buffer in bytes.\r | |
1741 | On output, the size of data returned in big number buffer in bytes.\r | |
1742 | \r | |
1743 | @retval TRUE RSA key component was retrieved successfully.\r | |
1744 | @retval FALSE Invalid RSA key component tag.\r | |
1745 | @retval FALSE BnSize is too small.\r | |
532616bb | 1746 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1747 | \r |
1748 | **/\r | |
1749 | BOOLEAN\r | |
1750 | EFIAPI\r | |
1751 | RsaGetKey (\r | |
1752 | IN OUT VOID *RsaContext,\r | |
1753 | IN RSA_KEY_TAG KeyTag,\r | |
1754 | OUT UINT8 *BigNumber,\r | |
1755 | IN OUT UINTN *BnSize\r | |
1756 | );\r | |
1757 | \r | |
1758 | /**\r | |
1759 | Generates RSA key components.\r | |
1760 | \r | |
1761 | This function generates RSA key components. It takes RSA public exponent E and\r | |
1762 | length in bits of RSA modulus N as input, and generates all key components.\r | |
1763 | If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used.\r | |
1764 | \r | |
1765 | Before this function can be invoked, pseudorandom number generator must be correctly\r | |
1766 | initialized by RandomSeed().\r | |
1767 | \r | |
16d2c32c | 1768 | If RsaContext is NULL, then return FALSE.\r |
532616bb | 1769 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1770 | \r |
1771 | @param[in, out] RsaContext Pointer to RSA context being set.\r | |
1772 | @param[in] ModulusLength Length of RSA modulus N in bits.\r | |
1773 | @param[in] PublicExponent Pointer to RSA public exponent.\r | |
2ac68e8b | 1774 | @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes.\r |
a8c44645 | 1775 | \r |
1776 | @retval TRUE RSA key component was generated successfully.\r | |
1777 | @retval FALSE Invalid RSA key component tag.\r | |
532616bb | 1778 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1779 | \r |
1780 | **/\r | |
1781 | BOOLEAN\r | |
1782 | EFIAPI\r | |
1783 | RsaGenerateKey (\r | |
1784 | IN OUT VOID *RsaContext,\r | |
1785 | IN UINTN ModulusLength,\r | |
1786 | IN CONST UINT8 *PublicExponent,\r | |
1787 | IN UINTN PublicExponentSize\r | |
1788 | );\r | |
1789 | \r | |
1790 | /**\r | |
1791 | Validates key components of RSA context.\r | |
952bd229 QL |
1792 | NOTE: This function performs integrity checks on all the RSA key material, so\r |
1793 | the RSA key structure must contain all the private key data.\r | |
a8c44645 | 1794 | \r |
1795 | This function validates key compoents of RSA context in following aspects:\r | |
1796 | - Whether p is a prime\r | |
1797 | - Whether q is a prime\r | |
1798 | - Whether n = p * q\r | |
1799 | - Whether d*e = 1 mod lcm(p-1,q-1)\r | |
1800 | \r | |
16d2c32c | 1801 | If RsaContext is NULL, then return FALSE.\r |
532616bb | 1802 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1803 | \r |
1804 | @param[in] RsaContext Pointer to RSA context to check.\r | |
1805 | \r | |
1806 | @retval TRUE RSA key components are valid.\r | |
1807 | @retval FALSE RSA key components are not valid.\r | |
532616bb | 1808 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1809 | \r |
1810 | **/\r | |
1811 | BOOLEAN\r | |
1812 | EFIAPI\r | |
1813 | RsaCheckKey (\r | |
1814 | IN VOID *RsaContext\r | |
97f98500 HT |
1815 | );\r |
1816 | \r | |
a8c44645 | 1817 | /**\r |
1818 | Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme.\r | |
1819 | \r | |
1820 | This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in\r | |
1821 | RSA PKCS#1.\r | |
1822 | If the Signature buffer is too small to hold the contents of signature, FALSE\r | |
1823 | is returned and SigSize is set to the required buffer size to obtain the signature.\r | |
1824 | \r | |
16d2c32c | 1825 | If RsaContext is NULL, then return FALSE.\r |
1826 | If MessageHash is NULL, then return FALSE.\r | |
1827 | If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE.\r | |
1828 | If SigSize is large enough but Signature is NULL, then return FALSE.\r | |
532616bb | 1829 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 1830 | \r |
1831 | @param[in] RsaContext Pointer to RSA context for signature generation.\r | |
1832 | @param[in] MessageHash Pointer to octet message hash to be signed.\r | |
1833 | @param[in] HashSize Size of the message hash in bytes.\r | |
1834 | @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature.\r | |
1835 | @param[in, out] SigSize On input, the size of Signature buffer in bytes.\r | |
b7d320f8 | 1836 | On output, the size of data returned in Signature buffer in bytes.\r |
a8c44645 | 1837 | \r |
1838 | @retval TRUE Signature successfully generated in PKCS1-v1_5.\r | |
1839 | @retval FALSE Signature generation failed.\r | |
1840 | @retval FALSE SigSize is too small.\r | |
532616bb | 1841 | @retval FALSE This interface is not supported.\r |
a8c44645 | 1842 | \r |
1843 | **/\r | |
1844 | BOOLEAN\r | |
1845 | EFIAPI\r | |
1846 | RsaPkcs1Sign (\r | |
1847 | IN VOID *RsaContext,\r | |
1848 | IN CONST UINT8 *MessageHash,\r | |
1849 | IN UINTN HashSize,\r | |
1850 | OUT UINT8 *Signature,\r | |
1851 | IN OUT UINTN *SigSize\r | |
1852 | );\r | |
97f98500 HT |
1853 | \r |
1854 | /**\r | |
1855 | Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r | |
1856 | RSA PKCS#1.\r | |
1857 | \r | |
16d2c32c | 1858 | If RsaContext is NULL, then return FALSE.\r |
1859 | If MessageHash is NULL, then return FALSE.\r | |
1860 | If Signature is NULL, then return FALSE.\r | |
1861 | If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE.\r | |
97f98500 HT |
1862 | \r |
1863 | @param[in] RsaContext Pointer to RSA context for signature verification.\r | |
1864 | @param[in] MessageHash Pointer to octet message hash to be checked.\r | |
a8c44645 | 1865 | @param[in] HashSize Size of the message hash in bytes.\r |
97f98500 | 1866 | @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r |
a8c44645 | 1867 | @param[in] SigSize Size of signature in bytes.\r |
97f98500 | 1868 | \r |
a8c44645 | 1869 | @retval TRUE Valid signature encoded in PKCS1-v1_5.\r |
1870 | @retval FALSE Invalid signature or invalid RSA context.\r | |
97f98500 HT |
1871 | \r |
1872 | **/\r | |
1873 | BOOLEAN\r | |
1874 | EFIAPI\r | |
1875 | RsaPkcs1Verify (\r | |
1876 | IN VOID *RsaContext,\r | |
1877 | IN CONST UINT8 *MessageHash,\r | |
a8c44645 | 1878 | IN UINTN HashSize,\r |
8c5720b4 | 1879 | IN CONST UINT8 *Signature,\r |
a8c44645 | 1880 | IN UINTN SigSize\r |
97f98500 HT |
1881 | );\r |
1882 | \r | |
4a567c96 | 1883 | /**\r |
1884 | Retrieve the RSA Private Key from the password-protected PEM key data.\r | |
1885 | \r | |
532616bb | 1886 | If PemData is NULL, then return FALSE.\r |
1887 | If RsaContext is NULL, then return FALSE.\r | |
1888 | If this interface is not supported, then return FALSE.\r | |
1889 | \r | |
4a567c96 | 1890 | @param[in] PemData Pointer to the PEM-encoded key data to be retrieved.\r |
1891 | @param[in] PemSize Size of the PEM key data in bytes.\r | |
1892 | @param[in] Password NULL-terminated passphrase used for encrypted PEM key data.\r | |
1893 | @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r | |
1894 | RSA private key component. Use RsaFree() function to free the\r | |
1895 | resource.\r | |
1896 | \r | |
4a567c96 | 1897 | @retval TRUE RSA Private Key was retrieved successfully.\r |
1898 | @retval FALSE Invalid PEM key data or incorrect password.\r | |
532616bb | 1899 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1900 | \r |
1901 | **/\r | |
1902 | BOOLEAN\r | |
1903 | EFIAPI\r | |
1904 | RsaGetPrivateKeyFromPem (\r | |
1905 | IN CONST UINT8 *PemData,\r | |
1906 | IN UINTN PemSize,\r | |
1907 | IN CONST CHAR8 *Password,\r | |
1908 | OUT VOID **RsaContext\r | |
1909 | );\r | |
1910 | \r | |
1911 | /**\r | |
1912 | Retrieve the RSA Public Key from one DER-encoded X509 certificate.\r | |
1913 | \r | |
532616bb | 1914 | If Cert is NULL, then return FALSE.\r |
1915 | If RsaContext is NULL, then return FALSE.\r | |
1916 | If this interface is not supported, then return FALSE.\r | |
1917 | \r | |
4a567c96 | 1918 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r |
1919 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1920 | @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved\r | |
1921 | RSA public key component. Use RsaFree() function to free the\r | |
1922 | resource.\r | |
1923 | \r | |
4a567c96 | 1924 | @retval TRUE RSA Public Key was retrieved successfully.\r |
1925 | @retval FALSE Fail to retrieve RSA public key from X509 certificate.\r | |
532616bb | 1926 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1927 | \r |
1928 | **/\r | |
1929 | BOOLEAN\r | |
1930 | EFIAPI\r | |
1931 | RsaGetPublicKeyFromX509 (\r | |
1932 | IN CONST UINT8 *Cert,\r | |
1933 | IN UINTN CertSize,\r | |
1934 | OUT VOID **RsaContext\r | |
1935 | );\r | |
1936 | \r | |
1937 | /**\r | |
1938 | Retrieve the subject bytes from one X.509 certificate.\r | |
1939 | \r | |
532616bb | 1940 | If Cert is NULL, then return FALSE.\r |
1941 | If SubjectSize is NULL, then return FALSE.\r | |
1942 | If this interface is not supported, then return FALSE.\r | |
1943 | \r | |
4a567c96 | 1944 | @param[in] Cert Pointer to the DER-encoded X509 certificate.\r |
1945 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1946 | @param[out] CertSubject Pointer to the retrieved certificate subject bytes.\r | |
1947 | @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input,\r | |
1948 | and the size of buffer returned CertSubject on output.\r | |
1949 | \r | |
4a567c96 | 1950 | @retval TRUE The certificate subject retrieved successfully.\r |
1951 | @retval FALSE Invalid certificate, or the SubjectSize is too small for the result.\r | |
1952 | The SubjectSize will be updated with the required size.\r | |
532616bb | 1953 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1954 | \r |
1955 | **/\r | |
1956 | BOOLEAN\r | |
1957 | EFIAPI\r | |
1958 | X509GetSubjectName (\r | |
1959 | IN CONST UINT8 *Cert,\r | |
1960 | IN UINTN CertSize,\r | |
1961 | OUT UINT8 *CertSubject,\r | |
1962 | IN OUT UINTN *SubjectSize\r | |
1963 | );\r | |
1964 | \r | |
1965 | /**\r | |
1966 | Verify one X509 certificate was issued by the trusted CA.\r | |
1967 | \r | |
532616bb | 1968 | If Cert is NULL, then return FALSE.\r |
1969 | If CACert is NULL, then return FALSE.\r | |
1970 | If this interface is not supported, then return FALSE.\r | |
1971 | \r | |
4a567c96 | 1972 | @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified.\r |
1973 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
1974 | @param[in] CACert Pointer to the DER-encoded trusted CA certificate.\r | |
1975 | @param[in] CACertSize Size of the CA Certificate in bytes.\r | |
1976 | \r | |
4a567c96 | 1977 | @retval TRUE The certificate was issued by the trusted CA.\r |
1978 | @retval FALSE Invalid certificate or the certificate was not issued by the given\r | |
1979 | trusted CA.\r | |
532616bb | 1980 | @retval FALSE This interface is not supported.\r |
4a567c96 | 1981 | \r |
1982 | **/\r | |
1983 | BOOLEAN\r | |
1984 | EFIAPI\r | |
1985 | X509VerifyCert (\r | |
1986 | IN CONST UINT8 *Cert,\r | |
1987 | IN UINTN CertSize,\r | |
1988 | IN CONST UINT8 *CACert,\r | |
1989 | IN UINTN CACertSize\r | |
1990 | );\r | |
1991 | \r | |
b7d320f8 | 1992 | /**\r |
1993 | Construct a X509 object from DER-encoded certificate data.\r | |
1994 | \r | |
16d2c32c | 1995 | If Cert is NULL, then return FALSE.\r |
1996 | If SingleX509Cert is NULL, then return FALSE.\r | |
532616bb | 1997 | If this interface is not supported, then return FALSE.\r |
b7d320f8 | 1998 | \r |
1999 | @param[in] Cert Pointer to the DER-encoded certificate data.\r | |
2000 | @param[in] CertSize The size of certificate data in bytes.\r | |
2001 | @param[out] SingleX509Cert The generated X509 object.\r | |
2002 | \r | |
2003 | @retval TRUE The X509 object generation succeeded.\r | |
2004 | @retval FALSE The operation failed.\r | |
532616bb | 2005 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 2006 | \r |
2007 | **/\r | |
2008 | BOOLEAN\r | |
2009 | EFIAPI\r | |
2010 | X509ConstructCertificate (\r | |
2011 | IN CONST UINT8 *Cert,\r | |
2012 | IN UINTN CertSize,\r | |
2013 | OUT UINT8 **SingleX509Cert\r | |
2014 | );\r | |
2015 | \r | |
2016 | /**\r | |
2017 | Construct a X509 stack object from a list of DER-encoded certificate data.\r | |
2018 | \r | |
16d2c32c | 2019 | If X509Stack is NULL, then return FALSE.\r |
532616bb | 2020 | If this interface is not supported, then return FALSE.\r |
b7d320f8 | 2021 | \r |
952bd229 | 2022 | @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object.\r |
b7d320f8 | 2023 | On output, pointer to the X509 stack object with new\r |
2024 | inserted X509 certificate.\r | |
2025 | @param ... A list of DER-encoded single certificate data followed\r | |
2026 | by certificate size. A NULL terminates the list. The\r | |
2027 | pairs are the arguments to X509ConstructCertificate().\r | |
2ac68e8b | 2028 | \r |
b7d320f8 | 2029 | @retval TRUE The X509 stack construction succeeded.\r |
2030 | @retval FALSE The construction operation failed.\r | |
532616bb | 2031 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 2032 | \r |
2033 | **/\r | |
2034 | BOOLEAN\r | |
2035 | EFIAPI\r | |
2036 | X509ConstructCertificateStack (\r | |
2037 | IN OUT UINT8 **X509Stack,\r | |
2ac68e8b | 2038 | ...\r |
b7d320f8 | 2039 | );\r |
2040 | \r | |
2041 | /**\r | |
2042 | Release the specified X509 object.\r | |
2043 | \r | |
532616bb | 2044 | If the interface is not supported, then ASSERT().\r |
b7d320f8 | 2045 | \r |
2046 | @param[in] X509Cert Pointer to the X509 object to be released.\r | |
2047 | \r | |
2048 | **/\r | |
2049 | VOID\r | |
2050 | EFIAPI\r | |
2051 | X509Free (\r | |
2052 | IN VOID *X509Cert\r | |
2053 | );\r | |
2054 | \r | |
2055 | /**\r | |
2056 | Release the specified X509 stack object.\r | |
2057 | \r | |
532616bb | 2058 | If the interface is not supported, then ASSERT().\r |
b7d320f8 | 2059 | \r |
2060 | @param[in] X509Stack Pointer to the X509 stack object to be released.\r | |
2061 | \r | |
2062 | **/\r | |
2063 | VOID\r | |
2064 | EFIAPI\r | |
2065 | X509StackFree (\r | |
2066 | IN VOID *X509Stack\r | |
2067 | );\r | |
2068 | \r | |
12d95665 LQ |
2069 | /**\r |
2070 | Retrieve the TBSCertificate from one given X.509 certificate.\r | |
2071 | \r | |
2072 | @param[in] Cert Pointer to the given DER-encoded X509 certificate.\r | |
2073 | @param[in] CertSize Size of the X509 certificate in bytes.\r | |
2074 | @param[out] TBSCert DER-Encoded To-Be-Signed certificate.\r | |
2075 | @param[out] TBSCertSize Size of the TBS certificate in bytes.\r | |
2076 | \r | |
2077 | If Cert is NULL, then return FALSE.\r | |
2078 | If TBSCert is NULL, then return FALSE.\r | |
2079 | If TBSCertSize is NULL, then return FALSE.\r | |
2080 | If this interface is not supported, then return FALSE.\r | |
2081 | \r | |
2082 | @retval TRUE The TBSCertificate was retrieved successfully.\r | |
2083 | @retval FALSE Invalid X.509 certificate.\r | |
2084 | \r | |
2085 | **/\r | |
2086 | BOOLEAN\r | |
2087 | EFIAPI\r | |
2088 | X509GetTBSCert (\r | |
2089 | IN CONST UINT8 *Cert,\r | |
2090 | IN UINTN CertSize,\r | |
2091 | OUT UINT8 **TBSCert,\r | |
2092 | OUT UINTN *TBSCertSize\r | |
2093 | );\r | |
2094 | \r | |
e8b4eb04 | 2095 | /**\r |
2096 | Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7:\r | |
2097 | Cryptographic Message Syntax Standard". The input signed data could be wrapped\r | |
2098 | in a ContentInfo structure.\r | |
2099 | \r | |
2100 | If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then\r | |
2101 | return FALSE. If P7Length overflow, then return FAlSE.\r | |
532616bb | 2102 | If this interface is not supported, then return FALSE.\r |
e8b4eb04 | 2103 | \r |
2104 | @param[in] P7Data Pointer to the PKCS#7 message to verify.\r | |
2105 | @param[in] P7Length Length of the PKCS#7 message in bytes.\r | |
2106 | @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data.\r | |
2107 | It's caller's responsiblity to free the buffer.\r | |
2108 | @param[out] StackLength Length of signer's certificates in bytes.\r | |
2109 | @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates.\r | |
2110 | It's caller's responsiblity to free the buffer.\r | |
2111 | @param[out] CertLength Length of the trusted certificate in bytes.\r | |
2112 | \r | |
2113 | @retval TRUE The operation is finished successfully.\r | |
2114 | @retval FALSE Error occurs during the operation.\r | |
532616bb | 2115 | @retval FALSE This interface is not supported.\r |
e8b4eb04 | 2116 | \r |
2117 | **/\r | |
2118 | BOOLEAN\r | |
2119 | EFIAPI\r | |
2120 | Pkcs7GetSigners (\r | |
2121 | IN CONST UINT8 *P7Data,\r | |
2122 | IN UINTN P7Length,\r | |
2123 | OUT UINT8 **CertStack,\r | |
2124 | OUT UINTN *StackLength,\r | |
2125 | OUT UINT8 **TrustedCert,\r | |
2126 | OUT UINTN *CertLength\r | |
2127 | );\r | |
2128 | \r | |
2129 | /**\r | |
2130 | Wrap function to use free() to free allocated memory for certificates.\r | |
2131 | \r | |
532616bb | 2132 | If this interface is not supported, then ASSERT().\r |
2133 | \r | |
e8b4eb04 | 2134 | @param[in] Certs Pointer to the certificates to be freed.\r |
2135 | \r | |
2136 | **/\r | |
2137 | VOID\r | |
2138 | EFIAPI\r | |
2139 | Pkcs7FreeSigners (\r | |
2140 | IN UINT8 *Certs\r | |
45419de6 QL |
2141 | );\r |
2142 | \r | |
2143 | /**\r | |
2144 | Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7:\r | |
2145 | Cryptographic Message Syntax Standard", and outputs two certificate lists chained and\r | |
2146 | unchained to the signer's certificates.\r | |
2147 | The input signed data could be wrapped in a ContentInfo structure.\r | |
2148 | \r | |
2149 | @param[in] P7Data Pointer to the PKCS#7 message.\r | |
2150 | @param[in] P7Length Length of the PKCS#7 message in bytes.\r | |
0f5f6b3d | 2151 | @param[out] SignerChainCerts Pointer to the certificates list chained to signer's\r |
45419de6 QL |
2152 | certificate. It's caller's responsiblity to free the buffer.\r |
2153 | @param[out] ChainLength Length of the chained certificates list buffer in bytes.\r | |
2154 | @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's\r | |
2155 | responsiblity to free the buffer.\r | |
2156 | @param[out] UnchainLength Length of the unchained certificates list buffer in bytes.\r | |
2157 | \r | |
2158 | @retval TRUE The operation is finished successfully.\r | |
2159 | @retval FALSE Error occurs during the operation.\r | |
2160 | \r | |
2161 | **/\r | |
2162 | BOOLEAN\r | |
2163 | EFIAPI\r | |
2164 | Pkcs7GetCertificatesList (\r | |
2165 | IN CONST UINT8 *P7Data,\r | |
2166 | IN UINTN P7Length,\r | |
2167 | OUT UINT8 **SignerChainCerts,\r | |
2168 | OUT UINTN *ChainLength,\r | |
2169 | OUT UINT8 **UnchainCerts,\r | |
2170 | OUT UINTN *UnchainLength\r | |
e8b4eb04 | 2171 | );\r |
2172 | \r | |
b7d320f8 | 2173 | /**\r |
2174 | Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message\r | |
2175 | Syntax Standard, version 1.5". This interface is only intended to be used for\r | |
2176 | application to perform PKCS#7 functionality validation.\r | |
2177 | \r | |
532616bb | 2178 | If this interface is not supported, then return FALSE.\r |
2179 | \r | |
b7d320f8 | 2180 | @param[in] PrivateKey Pointer to the PEM-formatted private key data for\r |
2181 | data signing.\r | |
2182 | @param[in] PrivateKeySize Size of the PEM private key data in bytes.\r | |
2183 | @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM\r | |
2184 | key data.\r | |
2185 | @param[in] InData Pointer to the content to be signed.\r | |
2186 | @param[in] InDataSize Size of InData in bytes.\r | |
2187 | @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with.\r | |
2188 | @param[in] OtherCerts Pointer to an optional additional set of certificates to\r | |
2189 | include in the PKCS#7 signedData (e.g. any intermediate\r | |
2190 | CAs in the chain).\r | |
2191 | @param[out] SignedData Pointer to output PKCS#7 signedData.\r | |
2192 | @param[out] SignedDataSize Size of SignedData in bytes.\r | |
2193 | \r | |
2194 | @retval TRUE PKCS#7 data signing succeeded.\r | |
2195 | @retval FALSE PKCS#7 data signing failed.\r | |
532616bb | 2196 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 2197 | \r |
2198 | **/\r | |
2199 | BOOLEAN\r | |
2200 | EFIAPI\r | |
2201 | Pkcs7Sign (\r | |
2202 | IN CONST UINT8 *PrivateKey,\r | |
2203 | IN UINTN PrivateKeySize,\r | |
2204 | IN CONST UINT8 *KeyPassword,\r | |
2205 | IN UINT8 *InData,\r | |
2206 | IN UINTN InDataSize,\r | |
2207 | IN UINT8 *SignCert,\r | |
2208 | IN UINT8 *OtherCerts OPTIONAL,\r | |
2209 | OUT UINT8 **SignedData,\r | |
2210 | OUT UINTN *SignedDataSize\r | |
2211 | );\r | |
2212 | \r | |
97f98500 | 2213 | /**\r |
e8b4eb04 | 2214 | Verifies the validility of a PKCS#7 signed data as described in "PKCS #7:\r |
2215 | Cryptographic Message Syntax Standard". The input signed data could be wrapped\r | |
2216 | in a ContentInfo structure.\r | |
97f98500 | 2217 | \r |
e8b4eb04 | 2218 | If P7Data, TrustedCert or InData is NULL, then return FALSE.\r |
2219 | If P7Length, CertLength or DataLength overflow, then return FAlSE.\r | |
532616bb | 2220 | If this interface is not supported, then return FALSE.\r |
97f98500 HT |
2221 | \r |
2222 | @param[in] P7Data Pointer to the PKCS#7 message to verify.\r | |
e8b4eb04 | 2223 | @param[in] P7Length Length of the PKCS#7 message in bytes.\r |
97f98500 HT |
2224 | @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r |
2225 | is used for certificate chain verification.\r | |
e8b4eb04 | 2226 | @param[in] CertLength Length of the trusted certificate in bytes.\r |
97f98500 | 2227 | @param[in] InData Pointer to the content to be verified.\r |
e8b4eb04 | 2228 | @param[in] DataLength Length of InData in bytes.\r |
97f98500 | 2229 | \r |
a8c44645 | 2230 | @retval TRUE The specified PKCS#7 signed data is valid.\r |
2231 | @retval FALSE Invalid PKCS#7 signed data.\r | |
532616bb | 2232 | @retval FALSE This interface is not supported.\r |
97f98500 HT |
2233 | \r |
2234 | **/\r | |
2235 | BOOLEAN\r | |
2236 | EFIAPI\r | |
2237 | Pkcs7Verify (\r | |
2238 | IN CONST UINT8 *P7Data,\r | |
e8b4eb04 | 2239 | IN UINTN P7Length,\r |
97f98500 | 2240 | IN CONST UINT8 *TrustedCert,\r |
e8b4eb04 | 2241 | IN UINTN CertLength,\r |
97f98500 | 2242 | IN CONST UINT8 *InData,\r |
e8b4eb04 | 2243 | IN UINTN DataLength\r |
a8c44645 | 2244 | );\r |
2245 | \r | |
afeb55e4 QL |
2246 | /**\r |
2247 | Extracts the attached content from a PKCS#7 signed data if existed. The input signed\r | |
2248 | data could be wrapped in a ContentInfo structure.\r | |
2249 | \r | |
2250 | If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,\r | |
2251 | then return FAlSE. If the P7Data is not correctly formatted, then return FALSE.\r | |
2252 | \r | |
2253 | Caution: This function may receive untrusted input. So this function will do\r | |
2254 | basic check for PKCS#7 data structure.\r | |
2255 | \r | |
2256 | @param[in] P7Data Pointer to the PKCS#7 signed data to process.\r | |
2257 | @param[in] P7Length Length of the PKCS#7 signed data in bytes.\r | |
2258 | @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.\r | |
2259 | It's caller's responsiblity to free the buffer.\r | |
2260 | @param[out] ContentSize The size of the extracted content in bytes.\r | |
2261 | \r | |
2262 | @retval TRUE The P7Data was correctly formatted for processing.\r | |
2263 | @retval FALSE The P7Data was not correctly formatted for processing.\r | |
2264 | \r | |
2265 | */\r | |
2266 | BOOLEAN\r | |
2267 | EFIAPI\r | |
2268 | Pkcs7GetAttachedContent (\r | |
2269 | IN CONST UINT8 *P7Data,\r | |
2270 | IN UINTN P7Length,\r | |
2271 | OUT VOID **Content,\r | |
2272 | OUT UINTN *ContentSize\r | |
2273 | );\r | |
2274 | \r | |
b7d320f8 | 2275 | /**\r |
2276 | Verifies the validility of a PE/COFF Authenticode Signature as described in "Windows\r | |
2277 | Authenticode Portable Executable Signature Format".\r | |
2278 | \r | |
16d2c32c | 2279 | If AuthData is NULL, then return FALSE.\r |
2280 | If ImageHash is NULL, then return FALSE.\r | |
532616bb | 2281 | If this interface is not supported, then return FALSE.\r |
b7d320f8 | 2282 | \r |
2283 | @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r | |
2284 | PE/COFF image to be verified.\r | |
2285 | @param[in] DataSize Size of the Authenticode Signature in bytes.\r | |
2286 | @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which\r | |
2287 | is used for certificate chain verification.\r | |
2288 | @param[in] CertSize Size of the trusted certificate in bytes.\r | |
2289 | @param[in] ImageHash Pointer to the original image file hash value. The procudure\r | |
2290 | for calculating the image hash value is described in Authenticode\r | |
2291 | specification.\r | |
2292 | @param[in] HashSize Size of Image hash value in bytes.\r | |
2293 | \r | |
2294 | @retval TRUE The specified Authenticode Signature is valid.\r | |
2295 | @retval FALSE Invalid Authenticode Signature.\r | |
532616bb | 2296 | @retval FALSE This interface is not supported.\r |
b7d320f8 | 2297 | \r |
2298 | **/\r | |
2299 | BOOLEAN\r | |
2300 | EFIAPI\r | |
2301 | AuthenticodeVerify (\r | |
2302 | IN CONST UINT8 *AuthData,\r | |
2303 | IN UINTN DataSize,\r | |
2304 | IN CONST UINT8 *TrustedCert,\r | |
2305 | IN UINTN CertSize,\r | |
2306 | IN CONST UINT8 *ImageHash,\r | |
2307 | IN UINTN HashSize\r | |
2308 | );\r | |
2309 | \r | |
2ac68e8b QL |
2310 | /**\r |
2311 | Verifies the validility of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode\r | |
2312 | signature.\r | |
2313 | \r | |
2314 | If AuthData is NULL, then return FALSE.\r | |
12d95665 | 2315 | If this interface is not supported, then return FALSE.\r |
2ac68e8b QL |
2316 | \r |
2317 | @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed\r | |
2318 | PE/COFF image to be verified.\r | |
2319 | @param[in] DataSize Size of the Authenticode Signature in bytes.\r | |
2320 | @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which\r | |
2321 | is used for TSA certificate chain verification.\r | |
2322 | @param[in] CertSize Size of the trusted certificate in bytes.\r | |
2323 | @param[out] SigningTime Return the time of timestamp generation time if the timestamp\r | |
2324 | signature is valid.\r | |
2325 | \r | |
2326 | @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature.\r | |
2327 | @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data.\r | |
2328 | \r | |
2329 | **/\r | |
2330 | BOOLEAN\r | |
2331 | EFIAPI\r | |
2332 | ImageTimestampVerify (\r | |
2333 | IN CONST UINT8 *AuthData,\r | |
2334 | IN UINTN DataSize,\r | |
2335 | IN CONST UINT8 *TsaCert,\r | |
2336 | IN UINTN CertSize,\r | |
2337 | OUT EFI_TIME *SigningTime\r | |
2338 | );\r | |
2339 | \r | |
a8c44645 | 2340 | //=====================================================================================\r |
2341 | // DH Key Exchange Primitive\r | |
2342 | //=====================================================================================\r | |
2343 | \r | |
2344 | /**\r | |
2345 | Allocates and Initializes one Diffie-Hellman Context for subsequent use.\r | |
2346 | \r | |
2347 | @return Pointer to the Diffie-Hellman Context that has been initialized.\r | |
2348 | If the allocations fails, DhNew() returns NULL.\r | |
532616bb | 2349 | If the interface is not supported, DhNew() returns NULL.\r |
a8c44645 | 2350 | \r |
2351 | **/\r | |
2352 | VOID *\r | |
2353 | EFIAPI\r | |
2354 | DhNew (\r | |
2355 | VOID\r | |
2356 | );\r | |
2357 | \r | |
2358 | /**\r | |
2359 | Release the specified DH context.\r | |
2360 | \r | |
532616bb | 2361 | If the interface is not supported, then ASSERT().\r |
a8c44645 | 2362 | \r |
2363 | @param[in] DhContext Pointer to the DH context to be released.\r | |
2364 | \r | |
2365 | **/\r | |
2366 | VOID\r | |
2367 | EFIAPI\r | |
2368 | DhFree (\r | |
2369 | IN VOID *DhContext\r | |
2370 | );\r | |
2371 | \r | |
2372 | /**\r | |
2373 | Generates DH parameter.\r | |
2374 | \r | |
2375 | Given generator g, and length of prime number p in bits, this function generates p,\r | |
2376 | and sets DH context according to value of g and p.\r | |
2ac68e8b | 2377 | \r |
a8c44645 | 2378 | Before this function can be invoked, pseudorandom number generator must be correctly\r |
2379 | initialized by RandomSeed().\r | |
2380 | \r | |
16d2c32c | 2381 | If DhContext is NULL, then return FALSE.\r |
2382 | If Prime is NULL, then return FALSE.\r | |
532616bb | 2383 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2384 | \r |
2385 | @param[in, out] DhContext Pointer to the DH context.\r | |
2386 | @param[in] Generator Value of generator.\r | |
2387 | @param[in] PrimeLength Length in bits of prime to be generated.\r | |
2388 | @param[out] Prime Pointer to the buffer to receive the generated prime number.\r | |
2389 | \r | |
2390 | @retval TRUE DH pamameter generation succeeded.\r | |
2391 | @retval FALSE Value of Generator is not supported.\r | |
2392 | @retval FALSE PRNG fails to generate random prime number with PrimeLength.\r | |
532616bb | 2393 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2394 | \r |
2395 | **/\r | |
2396 | BOOLEAN\r | |
2397 | EFIAPI\r | |
2398 | DhGenerateParameter (\r | |
2399 | IN OUT VOID *DhContext,\r | |
2400 | IN UINTN Generator,\r | |
2401 | IN UINTN PrimeLength,\r | |
2402 | OUT UINT8 *Prime\r | |
2403 | );\r | |
2404 | \r | |
2405 | /**\r | |
2406 | Sets generator and prime parameters for DH.\r | |
2407 | \r | |
2408 | Given generator g, and prime number p, this function and sets DH\r | |
2409 | context accordingly.\r | |
2410 | \r | |
16d2c32c | 2411 | If DhContext is NULL, then return FALSE.\r |
2412 | If Prime is NULL, then return FALSE.\r | |
532616bb | 2413 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2414 | \r |
2415 | @param[in, out] DhContext Pointer to the DH context.\r | |
2416 | @param[in] Generator Value of generator.\r | |
2417 | @param[in] PrimeLength Length in bits of prime to be generated.\r | |
2418 | @param[in] Prime Pointer to the prime number.\r | |
2419 | \r | |
2420 | @retval TRUE DH pamameter setting succeeded.\r | |
2421 | @retval FALSE Value of Generator is not supported.\r | |
2422 | @retval FALSE Value of Generator is not suitable for the Prime.\r | |
2423 | @retval FALSE Value of Prime is not a prime number.\r | |
2424 | @retval FALSE Value of Prime is not a safe prime number.\r | |
532616bb | 2425 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2426 | \r |
2427 | **/\r | |
2428 | BOOLEAN\r | |
2429 | EFIAPI\r | |
2430 | DhSetParameter (\r | |
2431 | IN OUT VOID *DhContext,\r | |
2432 | IN UINTN Generator,\r | |
2433 | IN UINTN PrimeLength,\r | |
2434 | IN CONST UINT8 *Prime\r | |
97f98500 HT |
2435 | );\r |
2436 | \r | |
a8c44645 | 2437 | /**\r |
2438 | Generates DH public key.\r | |
2439 | \r | |
2ac68e8b | 2440 | This function generates random secret exponent, and computes the public key, which is\r |
a8c44645 | 2441 | returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly.\r |
2442 | If the PublicKey buffer is too small to hold the public key, FALSE is returned and\r | |
2443 | PublicKeySize is set to the required buffer size to obtain the public key.\r | |
2444 | \r | |
16d2c32c | 2445 | If DhContext is NULL, then return FALSE.\r |
2446 | If PublicKeySize is NULL, then return FALSE.\r | |
2447 | If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.\r | |
532616bb | 2448 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2449 | \r |
2450 | @param[in, out] DhContext Pointer to the DH context.\r | |
2451 | @param[out] PublicKey Pointer to the buffer to receive generated public key.\r | |
2452 | @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes.\r | |
2453 | On output, the size of data returned in PublicKey buffer in bytes.\r | |
2454 | \r | |
2455 | @retval TRUE DH public key generation succeeded.\r | |
2456 | @retval FALSE DH public key generation failed.\r | |
2457 | @retval FALSE PublicKeySize is not large enough.\r | |
532616bb | 2458 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2459 | \r |
2460 | **/\r | |
2461 | BOOLEAN\r | |
2462 | EFIAPI\r | |
2463 | DhGenerateKey (\r | |
2464 | IN OUT VOID *DhContext,\r | |
2465 | OUT UINT8 *PublicKey,\r | |
2466 | IN OUT UINTN *PublicKeySize\r | |
2467 | );\r | |
2468 | \r | |
2469 | /**\r | |
2470 | Computes exchanged common key.\r | |
2471 | \r | |
2472 | Given peer's public key, this function computes the exchanged common key, based on its own\r | |
dda39f3a | 2473 | context including value of prime modulus and random secret exponent.\r |
a8c44645 | 2474 | \r |
16d2c32c | 2475 | If DhContext is NULL, then return FALSE.\r |
2476 | If PeerPublicKey is NULL, then return FALSE.\r | |
2477 | If KeySize is NULL, then return FALSE.\r | |
dda39f3a | 2478 | If Key is NULL, then return FALSE.\r |
2479 | If KeySize is not large enough, then return FALSE.\r | |
532616bb | 2480 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2481 | \r |
2482 | @param[in, out] DhContext Pointer to the DH context.\r | |
2483 | @param[in] PeerPublicKey Pointer to the peer's public key.\r | |
2484 | @param[in] PeerPublicKeySize Size of peer's public key in bytes.\r | |
2485 | @param[out] Key Pointer to the buffer to receive generated key.\r | |
2486 | @param[in, out] KeySize On input, the size of Key buffer in bytes.\r | |
2487 | On output, the size of data returned in Key buffer in bytes.\r | |
2488 | \r | |
2489 | @retval TRUE DH exchanged key generation succeeded.\r | |
2490 | @retval FALSE DH exchanged key generation failed.\r | |
2491 | @retval FALSE KeySize is not large enough.\r | |
532616bb | 2492 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2493 | \r |
2494 | **/\r | |
2495 | BOOLEAN\r | |
2496 | EFIAPI\r | |
2497 | DhComputeKey (\r | |
2498 | IN OUT VOID *DhContext,\r | |
2499 | IN CONST UINT8 *PeerPublicKey,\r | |
2500 | IN UINTN PeerPublicKeySize,\r | |
2501 | OUT UINT8 *Key,\r | |
2502 | IN OUT UINTN *KeySize\r | |
2503 | );\r | |
2504 | \r | |
2505 | //=====================================================================================\r | |
2506 | // Pseudo-Random Generation Primitive\r | |
2507 | //=====================================================================================\r | |
2508 | \r | |
2509 | /**\r | |
2510 | Sets up the seed value for the pseudorandom number generator.\r | |
2511 | \r | |
2512 | This function sets up the seed value for the pseudorandom number generator.\r | |
2513 | If Seed is not NULL, then the seed passed in is used.\r | |
2514 | If Seed is NULL, then default seed is used.\r | |
532616bb | 2515 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2516 | \r |
2517 | @param[in] Seed Pointer to seed value.\r | |
2518 | If NULL, default seed is used.\r | |
2519 | @param[in] SeedSize Size of seed value.\r | |
2520 | If Seed is NULL, this parameter is ignored.\r | |
2521 | \r | |
2522 | @retval TRUE Pseudorandom number generator has enough entropy for random generation.\r | |
2523 | @retval FALSE Pseudorandom number generator does not have enough entropy for random generation.\r | |
532616bb | 2524 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2525 | \r |
2526 | **/\r | |
2527 | BOOLEAN\r | |
2528 | EFIAPI\r | |
2529 | RandomSeed (\r | |
2530 | IN CONST UINT8 *Seed OPTIONAL,\r | |
2531 | IN UINTN SeedSize\r | |
2532 | );\r | |
2533 | \r | |
2534 | /**\r | |
2535 | Generates a pseudorandom byte stream of the specified size.\r | |
2536 | \r | |
16d2c32c | 2537 | If Output is NULL, then return FALSE.\r |
532616bb | 2538 | If this interface is not supported, then return FALSE.\r |
a8c44645 | 2539 | \r |
2540 | @param[out] Output Pointer to buffer to receive random value.\r | |
2541 | @param[in] Size Size of randome bytes to generate.\r | |
2542 | \r | |
2543 | @retval TRUE Pseudorandom byte stream generated successfully.\r | |
2544 | @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy.\r | |
532616bb | 2545 | @retval FALSE This interface is not supported.\r |
a8c44645 | 2546 | \r |
2547 | **/\r | |
2548 | BOOLEAN\r | |
2549 | EFIAPI\r | |
2550 | RandomBytes (\r | |
2551 | OUT UINT8 *Output,\r | |
2552 | IN UINTN Size\r | |
2553 | );\r | |
97f98500 | 2554 | \r |
afeb55e4 | 2555 | #endif // __BASE_CRYPT_LIB_H__\r |