]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Hash/CryptSha512.c
3ce372a066d67f08ac558048f1ac0278225540cb
2 SHA-384 and SHA-512 Digest Wrapper Implementations over OpenSSL.
4 Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "InternalCryptLib.h"
16 #include <openssl/sha.h>
19 Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations.
21 @return The size, in bytes, of the context buffer required for SHA-384 hash operations.
26 Sha384GetContextSize (
31 // Retrieves OpenSSL SHA-384 Context Size
33 return (UINTN
) (sizeof (SHA512_CTX
));
37 Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for
40 If Sha384Context is NULL, then return FALSE.
42 @param[out] Sha384Context Pointer to SHA-384 context being initialized.
44 @retval TRUE SHA-384 context initialization succeeded.
45 @retval FALSE SHA-384 context initialization failed.
51 OUT VOID
*Sha384Context
55 // Check input parameters.
57 if (Sha384Context
== NULL
) {
62 // OpenSSL SHA-384 Context Initialization
64 return (BOOLEAN
) (SHA384_Init ((SHA512_CTX
*) Sha384Context
));
68 Makes a copy of an existing SHA-384 context.
70 If Sha384Context is NULL, then return FALSE.
71 If NewSha384Context is NULL, then return FALSE.
72 If this interface is not supported, then return FALSE.
74 @param[in] Sha384Context Pointer to SHA-384 context being copied.
75 @param[out] NewSha384Context Pointer to new SHA-384 context.
77 @retval TRUE SHA-384 context copy succeeded.
78 @retval FALSE SHA-384 context copy failed.
79 @retval FALSE This interface is not supported.
85 IN CONST VOID
*Sha384Context
,
86 OUT VOID
*NewSha384Context
90 // Check input parameters.
92 if (Sha384Context
== NULL
|| NewSha384Context
== NULL
) {
96 CopyMem (NewSha384Context
, Sha384Context
, sizeof (SHA512_CTX
));
102 Digests the input data and updates SHA-384 context.
104 This function performs SHA-384 digest on a data buffer of the specified size.
105 It can be called multiple times to compute the digest of long or discontinuous data streams.
106 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized
107 by Sha384Final(). Behavior with invalid context is undefined.
109 If Sha384Context is NULL, then return FALSE.
111 @param[in, out] Sha384Context Pointer to the SHA-384 context.
112 @param[in] Data Pointer to the buffer containing the data to be hashed.
113 @param[in] DataSize Size of Data buffer in bytes.
115 @retval TRUE SHA-384 data digest succeeded.
116 @retval FALSE SHA-384 data digest failed.
122 IN OUT VOID
*Sha384Context
,
128 // Check input parameters.
130 if (Sha384Context
== NULL
) {
135 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
137 if (Data
== NULL
&& DataSize
!= 0) {
142 // OpenSSL SHA-384 Hash Update
144 return (BOOLEAN
) (SHA384_Update ((SHA512_CTX
*) Sha384Context
, Data
, DataSize
));
148 Completes computation of the SHA-384 digest value.
150 This function completes SHA-384 hash computation and retrieves the digest value into
151 the specified memory. After this function has been called, the SHA-384 context cannot
153 SHA-384 context should be already correctly initialized by Sha384Init(), and should not be
154 finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined.
156 If Sha384Context is NULL, then return FALSE.
157 If HashValue is NULL, then return FALSE.
159 @param[in, out] Sha384Context Pointer to the SHA-384 context.
160 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
163 @retval TRUE SHA-384 digest computation succeeded.
164 @retval FALSE SHA-384 digest computation failed.
170 IN OUT VOID
*Sha384Context
,
175 // Check input parameters.
177 if (Sha384Context
== NULL
|| HashValue
== NULL
) {
182 // OpenSSL SHA-384 Hash Finalization
184 return (BOOLEAN
) (SHA384_Final (HashValue
, (SHA512_CTX
*) Sha384Context
));
188 Computes the SHA-384 message digest of a input data buffer.
190 This function performs the SHA-384 message digest of a given data buffer, and places
191 the digest value into the specified memory.
193 If this interface is not supported, then return FALSE.
195 @param[in] Data Pointer to the buffer containing the data to be hashed.
196 @param[in] DataSize Size of Data buffer in bytes.
197 @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest
200 @retval TRUE SHA-384 digest computation succeeded.
201 @retval FALSE SHA-384 digest computation failed.
202 @retval FALSE This interface is not supported.
214 // Check input parameters.
216 if (HashValue
== NULL
) {
219 if (Data
== NULL
&& DataSize
!= 0) {
224 // OpenSSL SHA-384 Hash Computation.
226 if (SHA384 (Data
, DataSize
, HashValue
) == NULL
) {
234 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
236 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
241 Sha512GetContextSize (
246 // Retrieves OpenSSL SHA-512 Context Size
248 return (UINTN
) (sizeof (SHA512_CTX
));
252 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
255 If Sha512Context is NULL, then return FALSE.
257 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
259 @retval TRUE SHA-512 context initialization succeeded.
260 @retval FALSE SHA-512 context initialization failed.
266 OUT VOID
*Sha512Context
270 // Check input parameters.
272 if (Sha512Context
== NULL
) {
277 // OpenSSL SHA-512 Context Initialization
279 return (BOOLEAN
) (SHA512_Init ((SHA512_CTX
*) Sha512Context
));
283 Makes a copy of an existing SHA-512 context.
285 If Sha512Context is NULL, then return FALSE.
286 If NewSha512Context is NULL, then return FALSE.
287 If this interface is not supported, then return FALSE.
289 @param[in] Sha512Context Pointer to SHA-512 context being copied.
290 @param[out] NewSha512Context Pointer to new SHA-512 context.
292 @retval TRUE SHA-512 context copy succeeded.
293 @retval FALSE SHA-512 context copy failed.
294 @retval FALSE This interface is not supported.
300 IN CONST VOID
*Sha512Context
,
301 OUT VOID
*NewSha512Context
305 // Check input parameters.
307 if (Sha512Context
== NULL
|| NewSha512Context
== NULL
) {
311 CopyMem (NewSha512Context
, Sha512Context
, sizeof (SHA512_CTX
));
317 Digests the input data and updates SHA-512 context.
319 This function performs SHA-512 digest on a data buffer of the specified size.
320 It can be called multiple times to compute the digest of long or discontinuous data streams.
321 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized
322 by Sha512Final(). Behavior with invalid context is undefined.
324 If Sha512Context is NULL, then return FALSE.
326 @param[in, out] Sha512Context Pointer to the SHA-512 context.
327 @param[in] Data Pointer to the buffer containing the data to be hashed.
328 @param[in] DataSize Size of Data buffer in bytes.
330 @retval TRUE SHA-512 data digest succeeded.
331 @retval FALSE SHA-512 data digest failed.
337 IN OUT VOID
*Sha512Context
,
343 // Check input parameters.
345 if (Sha512Context
== NULL
) {
350 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
352 if (Data
== NULL
&& DataSize
!= 0) {
357 // OpenSSL SHA-512 Hash Update
359 return (BOOLEAN
) (SHA512_Update ((SHA512_CTX
*) Sha512Context
, Data
, DataSize
));
363 Completes computation of the SHA-512 digest value.
365 This function completes SHA-512 hash computation and retrieves the digest value into
366 the specified memory. After this function has been called, the SHA-512 context cannot
368 SHA-512 context should be already correctly initialized by Sha512Init(), and should not be
369 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
371 If Sha512Context is NULL, then return FALSE.
372 If HashValue is NULL, then return FALSE.
374 @param[in, out] Sha512Context Pointer to the SHA-512 context.
375 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
378 @retval TRUE SHA-512 digest computation succeeded.
379 @retval FALSE SHA-512 digest computation failed.
385 IN OUT VOID
*Sha512Context
,
390 // Check input parameters.
392 if (Sha512Context
== NULL
|| HashValue
== NULL
) {
397 // OpenSSL SHA-512 Hash Finalization
399 return (BOOLEAN
) (SHA384_Final (HashValue
, (SHA512_CTX
*) Sha512Context
));
403 Computes the SHA-512 message digest of a input data buffer.
405 This function performs the SHA-512 message digest of a given data buffer, and places
406 the digest value into the specified memory.
408 If this interface is not supported, then return FALSE.
410 @param[in] Data Pointer to the buffer containing the data to be hashed.
411 @param[in] DataSize Size of Data buffer in bytes.
412 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
415 @retval TRUE SHA-512 digest computation succeeded.
416 @retval FALSE SHA-512 digest computation failed.
417 @retval FALSE This interface is not supported.
429 // Check input parameters.
431 if (HashValue
== NULL
) {
434 if (Data
== NULL
&& DataSize
!= 0) {
439 // OpenSSL SHA-512 Hash Computation.
441 if (SHA512 (Data
, DataSize
, HashValue
) == NULL
) {