]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Hash/CryptSha512.c
491f45dce62384c063c296340335ca159230e831
2 SHA-384 and SHA-512 Digest Wrapper Implementations over OpenSSL.
4 Copyright (c) 2014, 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 intialized 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 intialized 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 Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations.
190 @return The size, in bytes, of the context buffer required for SHA-512 hash operations.
195 Sha512GetContextSize (
200 // Retrieves OpenSSL SHA-512 Context Size
202 return (UINTN
) (sizeof (SHA512_CTX
));
206 Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for
209 If Sha512Context is NULL, then return FALSE.
211 @param[out] Sha512Context Pointer to SHA-512 context being initialized.
213 @retval TRUE SHA-512 context initialization succeeded.
214 @retval FALSE SHA-512 context initialization failed.
220 OUT VOID
*Sha512Context
224 // Check input parameters.
226 if (Sha512Context
== NULL
) {
231 // OpenSSL SHA-512 Context Initialization
233 return (BOOLEAN
) (SHA512_Init ((SHA512_CTX
*) Sha512Context
));
237 Makes a copy of an existing SHA-512 context.
239 If Sha512Context is NULL, then return FALSE.
240 If NewSha512Context is NULL, then return FALSE.
241 If this interface is not supported, then return FALSE.
243 @param[in] Sha512Context Pointer to SHA-512 context being copied.
244 @param[out] NewSha512Context Pointer to new SHA-512 context.
246 @retval TRUE SHA-512 context copy succeeded.
247 @retval FALSE SHA-512 context copy failed.
248 @retval FALSE This interface is not supported.
254 IN CONST VOID
*Sha512Context
,
255 OUT VOID
*NewSha512Context
259 // Check input parameters.
261 if (Sha512Context
== NULL
|| NewSha512Context
== NULL
) {
265 CopyMem (NewSha512Context
, Sha512Context
, sizeof (SHA512_CTX
));
271 Digests the input data and updates SHA-512 context.
273 This function performs SHA-512 digest on a data buffer of the specified size.
274 It can be called multiple times to compute the digest of long or discontinuous data streams.
275 SHA-512 context should be already correctly intialized by Sha512Init(), and should not be finalized
276 by Sha512Final(). Behavior with invalid context is undefined.
278 If Sha512Context is NULL, then return FALSE.
280 @param[in, out] Sha512Context Pointer to the SHA-512 context.
281 @param[in] Data Pointer to the buffer containing the data to be hashed.
282 @param[in] DataSize Size of Data buffer in bytes.
284 @retval TRUE SHA-512 data digest succeeded.
285 @retval FALSE SHA-512 data digest failed.
291 IN OUT VOID
*Sha512Context
,
297 // Check input parameters.
299 if (Sha512Context
== NULL
) {
304 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
306 if (Data
== NULL
&& DataSize
!= 0) {
311 // OpenSSL SHA-512 Hash Update
313 return (BOOLEAN
) (SHA512_Update ((SHA512_CTX
*) Sha512Context
, Data
, DataSize
));
317 Completes computation of the SHA-512 digest value.
319 This function completes SHA-512 hash computation and retrieves the digest value into
320 the specified memory. After this function has been called, the SHA-512 context cannot
322 SHA-512 context should be already correctly intialized by Sha512Init(), and should not be
323 finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined.
325 If Sha512Context is NULL, then return FALSE.
326 If HashValue is NULL, then return FALSE.
328 @param[in, out] Sha512Context Pointer to the SHA-512 context.
329 @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest
332 @retval TRUE SHA-512 digest computation succeeded.
333 @retval FALSE SHA-512 digest computation failed.
339 IN OUT VOID
*Sha512Context
,
344 // Check input parameters.
346 if (Sha512Context
== NULL
|| HashValue
== NULL
) {
351 // OpenSSL SHA-512 Hash Finalization
353 return (BOOLEAN
) (SHA384_Final (HashValue
, (SHA512_CTX
*) Sha512Context
));