TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptSha512.c
Go to the documentation of this file.
1
9#include "InternalCryptLib.h"
10#include <openssl/sha.h>
11
19EFIAPI
21 VOID
22 )
23{
24 //
25 // Retrieves OpenSSL SHA-384 Context Size
26 //
27 return (UINTN)(sizeof (SHA512_CTX));
28}
29
42BOOLEAN
43EFIAPI
45 OUT VOID *Sha384Context
46 )
47{
48 //
49 // Check input parameters.
50 //
51 if (Sha384Context == NULL) {
52 return FALSE;
53 }
54
55 //
56 // OpenSSL SHA-384 Context Initialization
57 //
58 return (BOOLEAN)(SHA384_Init ((SHA512_CTX *)Sha384Context));
59}
60
76BOOLEAN
77EFIAPI
79 IN CONST VOID *Sha384Context,
80 OUT VOID *NewSha384Context
81 )
82{
83 //
84 // Check input parameters.
85 //
86 if ((Sha384Context == NULL) || (NewSha384Context == NULL)) {
87 return FALSE;
88 }
89
90 CopyMem (NewSha384Context, Sha384Context, sizeof (SHA512_CTX));
91
92 return TRUE;
93}
94
113BOOLEAN
114EFIAPI
116 IN OUT VOID *Sha384Context,
117 IN CONST VOID *Data,
118 IN UINTN DataSize
119 )
120{
121 //
122 // Check input parameters.
123 //
124 if (Sha384Context == NULL) {
125 return FALSE;
126 }
127
128 //
129 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
130 //
131 if ((Data == NULL) && (DataSize != 0)) {
132 return FALSE;
133 }
134
135 //
136 // OpenSSL SHA-384 Hash Update
137 //
138 return (BOOLEAN)(SHA384_Update ((SHA512_CTX *)Sha384Context, Data, DataSize));
139}
140
161BOOLEAN
162EFIAPI
164 IN OUT VOID *Sha384Context,
165 OUT UINT8 *HashValue
166 )
167{
168 //
169 // Check input parameters.
170 //
171 if ((Sha384Context == NULL) || (HashValue == NULL)) {
172 return FALSE;
173 }
174
175 //
176 // OpenSSL SHA-384 Hash Finalization
177 //
178 return (BOOLEAN)(SHA384_Final (HashValue, (SHA512_CTX *)Sha384Context));
179}
180
199BOOLEAN
200EFIAPI
202 IN CONST VOID *Data,
203 IN UINTN DataSize,
204 OUT UINT8 *HashValue
205 )
206{
207 SHA512_CTX Context;
208
209 //
210 // Check input parameters.
211 //
212 if (HashValue == NULL) {
213 return FALSE;
214 }
215
216 if ((Data == NULL) && (DataSize != 0)) {
217 return FALSE;
218 }
219
220 //
221 // OpenSSL SHA-384 Hash Computation.
222 //
223 if (!SHA384_Init (&Context)) {
224 return FALSE;
225 }
226
227 if (!SHA384_Update (&Context, Data, DataSize)) {
228 return FALSE;
229 }
230
231 if (!SHA384_Final (HashValue, &Context)) {
232 return FALSE;
233 }
234
235 return TRUE;
236}
237
244UINTN
245EFIAPI
247 VOID
248 )
249{
250 //
251 // Retrieves OpenSSL SHA-512 Context Size
252 //
253 return (UINTN)(sizeof (SHA512_CTX));
254}
255
268BOOLEAN
269EFIAPI
271 OUT VOID *Sha512Context
272 )
273{
274 //
275 // Check input parameters.
276 //
277 if (Sha512Context == NULL) {
278 return FALSE;
279 }
280
281 //
282 // OpenSSL SHA-512 Context Initialization
283 //
284 return (BOOLEAN)(SHA512_Init ((SHA512_CTX *)Sha512Context));
285}
286
302BOOLEAN
303EFIAPI
305 IN CONST VOID *Sha512Context,
306 OUT VOID *NewSha512Context
307 )
308{
309 //
310 // Check input parameters.
311 //
312 if ((Sha512Context == NULL) || (NewSha512Context == NULL)) {
313 return FALSE;
314 }
315
316 CopyMem (NewSha512Context, Sha512Context, sizeof (SHA512_CTX));
317
318 return TRUE;
319}
320
339BOOLEAN
340EFIAPI
342 IN OUT VOID *Sha512Context,
343 IN CONST VOID *Data,
344 IN UINTN DataSize
345 )
346{
347 //
348 // Check input parameters.
349 //
350 if (Sha512Context == NULL) {
351 return FALSE;
352 }
353
354 //
355 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
356 //
357 if ((Data == NULL) && (DataSize != 0)) {
358 return FALSE;
359 }
360
361 //
362 // OpenSSL SHA-512 Hash Update
363 //
364 return (BOOLEAN)(SHA512_Update ((SHA512_CTX *)Sha512Context, Data, DataSize));
365}
366
387BOOLEAN
388EFIAPI
390 IN OUT VOID *Sha512Context,
391 OUT UINT8 *HashValue
392 )
393{
394 //
395 // Check input parameters.
396 //
397 if ((Sha512Context == NULL) || (HashValue == NULL)) {
398 return FALSE;
399 }
400
401 //
402 // OpenSSL SHA-512 Hash Finalization
403 //
404 return (BOOLEAN)(SHA384_Final (HashValue, (SHA512_CTX *)Sha512Context));
405}
406
425BOOLEAN
426EFIAPI
428 IN CONST VOID *Data,
429 IN UINTN DataSize,
430 OUT UINT8 *HashValue
431 )
432{
433 SHA512_CTX Context;
434
435 //
436 // Check input parameters.
437 //
438 if (HashValue == NULL) {
439 return FALSE;
440 }
441
442 if ((Data == NULL) && (DataSize != 0)) {
443 return FALSE;
444 }
445
446 //
447 // OpenSSL SHA-512 Hash Computation.
448 //
449 if (!SHA512_Init (&Context)) {
450 return FALSE;
451 }
452
453 if (!SHA512_Update (&Context, Data, DataSize)) {
454 return FALSE;
455 }
456
457 if (!SHA512_Final (HashValue, &Context)) {
458 return FALSE;
459 }
460
461 return TRUE;
462}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
UINTN EFIAPI Sha384GetContextSize(VOID)
Definition: CryptSha512.c:20
BOOLEAN EFIAPI Sha512HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
Definition: CryptSha512.c:427
BOOLEAN EFIAPI Sha512Final(IN OUT VOID *Sha512Context, OUT UINT8 *HashValue)
Definition: CryptSha512.c:389
BOOLEAN EFIAPI Sha384Duplicate(IN CONST VOID *Sha384Context, OUT VOID *NewSha384Context)
Definition: CryptSha512.c:78
UINTN EFIAPI Sha512GetContextSize(VOID)
Definition: CryptSha512.c:246
BOOLEAN EFIAPI Sha512Init(OUT VOID *Sha512Context)
Definition: CryptSha512.c:270
BOOLEAN EFIAPI Sha384HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
Definition: CryptSha512.c:201
BOOLEAN EFIAPI Sha384Update(IN OUT VOID *Sha384Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha512.c:115
BOOLEAN EFIAPI Sha512Duplicate(IN CONST VOID *Sha512Context, OUT VOID *NewSha512Context)
Definition: CryptSha512.c:304
BOOLEAN EFIAPI Sha384Final(IN OUT VOID *Sha384Context, OUT UINT8 *HashValue)
Definition: CryptSha512.c:163
BOOLEAN EFIAPI Sha384Init(OUT VOID *Sha384Context)
Definition: CryptSha512.c:44
BOOLEAN EFIAPI Sha512Update(IN OUT VOID *Sha512Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha512.c:341
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284