]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Hash/CryptSha512.c
59e5708465880969dff81cf2670eee277e1f9194
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
) {
214 if ((Data
== NULL
) && (DataSize
!= 0)) {
219 // OpenSSL SHA-384 Hash Computation.
221 if (SHA384 (Data
, DataSize
, HashValue
) == NULL
) {
229 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
231 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
236 Sha512GetContextSize (
241 // Retrieves OpenSSL SHA-512 Context Size
243 return (UINTN
)(sizeof (SHA512_CTX
));
247 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
250 If Sha512Context is NULL, then return FALSE.
252 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
254 @retval TRUE SHA-512 context initialization succeeded.
255 @retval FALSE SHA-512 context initialization failed.
261 OUT VOID
*Sha512Context
265 // Check input parameters.
267 if (Sha512Context
== NULL
) {
272 // OpenSSL SHA-512 Context Initialization
274 return (BOOLEAN
)(SHA512_Init ((SHA512_CTX
*)Sha512Context
));
278 Makes a copy of an existing SHA-512 context.
280 If Sha512Context is NULL, then return FALSE.
281 If NewSha512Context is NULL, then return FALSE.
282 If this interface is not supported, then return FALSE.
284 @param[in] Sha512Context Pointer to SHA-512 context being copied.
285 @param[out] NewSha512Context Pointer to new SHA-512 context.
287 @retval TRUE SHA-512 context copy succeeded.
288 @retval FALSE SHA-512 context copy failed.
289 @retval FALSE This interface is not supported.
295 IN CONST VOID
*Sha512Context
,
296 OUT VOID
*NewSha512Context
300 // Check input parameters.
302 if ((Sha512Context
== NULL
) || (NewSha512Context
== NULL
)) {
306 CopyMem (NewSha512Context
, Sha512Context
, sizeof (SHA512_CTX
));
312 Digests the input data and updates SHA-512 context.
314 This function performs SHA-512 digest on a data buffer of the specified size.
315 It can be called multiple times to compute the digest of long or discontinuous data streams.
316 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
317 by Sha512Final(). Behavior with invalid context is undefined.
319 If Sha512Context is NULL, then return FALSE.
321 @param[in, out] Sha512Context Pointer to the SHA-512 context.
322 @param[in] Data Pointer to the buffer containing the data to be hashed.
323 @param[in] DataSize Size of Data buffer in bytes.
325 @retval TRUE SHA-512 data digest succeeded.
326 @retval FALSE SHA-512 data digest failed.
332 IN OUT VOID
*Sha512Context
,
338 // Check input parameters.
340 if (Sha512Context
== NULL
) {
345 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
347 if ((Data
== NULL
) && (DataSize
!= 0)) {
352 // OpenSSL SHA-512 Hash Update
354 return (BOOLEAN
)(SHA512_Update ((SHA512_CTX
*)Sha512Context
, Data
, DataSize
));
358 Completes computation of the SHA-512 digest value.
360 This function completes SHA-512 hash computation and retrieves the digest value into
361 the specified memory. After this function has been called, the SHA-512 context cannot
363 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
364 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
366 If Sha512Context is NULL, then return FALSE.
367 If HashValue is NULL, then return FALSE.
369 @param[in, out] Sha512Context Pointer to the SHA-512 context.
370 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
373 @retval TRUE SHA-512 digest computation succeeded.
374 @retval FALSE SHA-512 digest computation failed.
380 IN OUT VOID
*Sha512Context
,
385 // Check input parameters.
387 if ((Sha512Context
== NULL
) || (HashValue
== NULL
)) {
392 // OpenSSL SHA-512 Hash Finalization
394 return (BOOLEAN
)(SHA384_Final (HashValue
, (SHA512_CTX
*)Sha512Context
));
398 Computes the SHA-512 message digest of a input data buffer.
400 This function performs the SHA-512 message digest of a given data buffer, and places
401 the digest value into the specified memory.
403 If this interface is not supported, then return FALSE.
405 @param[in] Data Pointer to the buffer containing the data to be hashed.
406 @param[in] DataSize Size of Data buffer in bytes.
407 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
410 @retval TRUE SHA-512 digest computation succeeded.
411 @retval FALSE SHA-512 digest computation failed.
412 @retval FALSE This interface is not supported.
424 // Check input parameters.
426 if (HashValue
== NULL
) {
430 if ((Data
== NULL
) && (DataSize
!= 0)) {
435 // OpenSSL SHA-512 Hash Computation.
437 if (SHA512 (Data
, DataSize
, HashValue
) == NULL
) {