]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Hash/CryptSha512.c
2 SHA-384 and SHA-512 Digest Wrapper Implementations over OpenSSL.
4 Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "InternalCryptLib.h"
10 #include <openssl/sha.h>
13 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
15 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
20 Sha384GetContextSize (
25 // Retrieves OpenSSL SHA-384 Context Size
27 return (UINTN
) (sizeof (SHA512_CTX
));
31 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
34 If Sha384Context is NULL, then return FALSE.
36 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
38 @retval TRUE SHA-384 context initialization succeeded.
39 @retval FALSE SHA-384 context initialization failed.
45 OUT VOID
*Sha384Context
49 // Check input parameters.
51 if (Sha384Context
== NULL
) {
56 // OpenSSL SHA-384 Context Initialization
58 return (BOOLEAN
) (SHA384_Init ((SHA512_CTX
*) Sha384Context
));
62 Makes a copy of an existing SHA-384 context.
64 If Sha384Context is NULL, then return FALSE.
65 If NewSha384Context is NULL, then return FALSE.
66 If this interface is not supported, then return FALSE.
68 @param[in] Sha384Context Pointer to SHA-384 context being copied.
69 @param[out] NewSha384Context Pointer to new SHA-384 context.
71 @retval TRUE SHA-384 context copy succeeded.
72 @retval FALSE SHA-384 context copy failed.
73 @retval FALSE This interface is not supported.
79 IN CONST VOID
*Sha384Context
,
80 OUT VOID
*NewSha384Context
84 // Check input parameters.
86 if (Sha384Context
== NULL
|| NewSha384Context
== NULL
) {
90 CopyMem (NewSha384Context
, Sha384Context
, sizeof (SHA512_CTX
));
96 Digests the input data and updates SHA-384 context.
98 This function performs SHA-384 digest on a data buffer of the specified size.
99 It can be called multiple times to compute the digest of long or discontinuous data streams.
100 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
101 by Sha384Final(). Behavior with invalid context is undefined.
103 If Sha384Context is NULL, then return FALSE.
105 @param[in, out] Sha384Context Pointer to the SHA-384 context.
106 @param[in] Data Pointer to the buffer containing the data to be hashed.
107 @param[in] DataSize Size of Data buffer in bytes.
109 @retval TRUE SHA-384 data digest succeeded.
110 @retval FALSE SHA-384 data digest failed.
116 IN OUT VOID
*Sha384Context
,
122 // Check input parameters.
124 if (Sha384Context
== NULL
) {
129 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
131 if (Data
== NULL
&& DataSize
!= 0) {
136 // OpenSSL SHA-384 Hash Update
138 return (BOOLEAN
) (SHA384_Update ((SHA512_CTX
*) Sha384Context
, Data
, DataSize
));
142 Completes computation of the SHA-384 digest value.
144 This function completes SHA-384 hash computation and retrieves the digest value into
145 the specified memory. After this function has been called, the SHA-384 context cannot
147 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
148 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
150 If Sha384Context is NULL, then return FALSE.
151 If HashValue is NULL, then return FALSE.
153 @param[in, out] Sha384Context Pointer to the SHA-384 context.
154 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
157 @retval TRUE SHA-384 digest computation succeeded.
158 @retval FALSE SHA-384 digest computation failed.
164 IN OUT VOID
*Sha384Context
,
169 // Check input parameters.
171 if (Sha384Context
== NULL
|| HashValue
== NULL
) {
176 // OpenSSL SHA-384 Hash Finalization
178 return (BOOLEAN
) (SHA384_Final (HashValue
, (SHA512_CTX
*) Sha384Context
));
182 Computes the SHA-384 message digest of a input data buffer.
184 This function performs the SHA-384 message digest of a given data buffer, and places
185 the digest value into the specified memory.
187 If this interface is not supported, then return FALSE.
189 @param[in] Data Pointer to the buffer containing the data to be hashed.
190 @param[in] DataSize Size of Data buffer in bytes.
191 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
194 @retval TRUE SHA-384 digest computation succeeded.
195 @retval FALSE SHA-384 digest computation failed.
196 @retval FALSE This interface is not supported.
208 // Check input parameters.
210 if (HashValue
== NULL
) {
213 if (Data
== NULL
&& DataSize
!= 0) {
218 // OpenSSL SHA-384 Hash Computation.
220 if (SHA384 (Data
, DataSize
, HashValue
) == NULL
) {
228 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
230 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
235 Sha512GetContextSize (
240 // Retrieves OpenSSL SHA-512 Context Size
242 return (UINTN
) (sizeof (SHA512_CTX
));
246 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
249 If Sha512Context is NULL, then return FALSE.
251 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
253 @retval TRUE SHA-512 context initialization succeeded.
254 @retval FALSE SHA-512 context initialization failed.
260 OUT VOID
*Sha512Context
264 // Check input parameters.
266 if (Sha512Context
== NULL
) {
271 // OpenSSL SHA-512 Context Initialization
273 return (BOOLEAN
) (SHA512_Init ((SHA512_CTX
*) Sha512Context
));
277 Makes a copy of an existing SHA-512 context.
279 If Sha512Context is NULL, then return FALSE.
280 If NewSha512Context is NULL, then return FALSE.
281 If this interface is not supported, then return FALSE.
283 @param[in] Sha512Context Pointer to SHA-512 context being copied.
284 @param[out] NewSha512Context Pointer to new SHA-512 context.
286 @retval TRUE SHA-512 context copy succeeded.
287 @retval FALSE SHA-512 context copy failed.
288 @retval FALSE This interface is not supported.
294 IN CONST VOID
*Sha512Context
,
295 OUT VOID
*NewSha512Context
299 // Check input parameters.
301 if (Sha512Context
== NULL
|| NewSha512Context
== NULL
) {
305 CopyMem (NewSha512Context
, Sha512Context
, sizeof (SHA512_CTX
));
311 Digests the input data and updates SHA-512 context.
313 This function performs SHA-512 digest on a data buffer of the specified size.
314 It can be called multiple times to compute the digest of long or discontinuous data streams.
315 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
316 by Sha512Final(). Behavior with invalid context is undefined.
318 If Sha512Context is NULL, then return FALSE.
320 @param[in, out] Sha512Context Pointer to the SHA-512 context.
321 @param[in] Data Pointer to the buffer containing the data to be hashed.
322 @param[in] DataSize Size of Data buffer in bytes.
324 @retval TRUE SHA-512 data digest succeeded.
325 @retval FALSE SHA-512 data digest failed.
331 IN OUT VOID
*Sha512Context
,
337 // Check input parameters.
339 if (Sha512Context
== NULL
) {
344 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
346 if (Data
== NULL
&& DataSize
!= 0) {
351 // OpenSSL SHA-512 Hash Update
353 return (BOOLEAN
) (SHA512_Update ((SHA512_CTX
*) Sha512Context
, Data
, DataSize
));
357 Completes computation of the SHA-512 digest value.
359 This function completes SHA-512 hash computation and retrieves the digest value into
360 the specified memory. After this function has been called, the SHA-512 context cannot
362 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
363 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
365 If Sha512Context is NULL, then return FALSE.
366 If HashValue is NULL, then return FALSE.
368 @param[in, out] Sha512Context Pointer to the SHA-512 context.
369 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
372 @retval TRUE SHA-512 digest computation succeeded.
373 @retval FALSE SHA-512 digest computation failed.
379 IN OUT VOID
*Sha512Context
,
384 // Check input parameters.
386 if (Sha512Context
== NULL
|| HashValue
== NULL
) {
391 // OpenSSL SHA-512 Hash Finalization
393 return (BOOLEAN
) (SHA384_Final (HashValue
, (SHA512_CTX
*) Sha512Context
));
397 Computes the SHA-512 message digest of a input data buffer.
399 This function performs the SHA-512 message digest of a given data buffer, and places
400 the digest value into the specified memory.
402 If this interface is not supported, then return FALSE.
404 @param[in] Data Pointer to the buffer containing the data to be hashed.
405 @param[in] DataSize Size of Data buffer in bytes.
406 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
409 @retval TRUE SHA-512 digest computation succeeded.
410 @retval FALSE SHA-512 digest computation failed.
411 @retval FALSE This interface is not supported.
423 // Check input parameters.
425 if (HashValue
== NULL
) {
428 if (Data
== NULL
&& DataSize
!= 0) {
433 // OpenSSL SHA-512 Hash Computation.
435 if (SHA512 (Data
, DataSize
, HashValue
) == NULL
) {