]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Hash/CryptSha1.c
2 SHA-1 Digest Wrapper Implementation over OpenSSL.
4 Copyright (c) 2009 - 2012, 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>
20 Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
22 @return The size, in bytes, of the context buffer required for SHA-1 hash operations.
32 // Retrieves OpenSSL SHA Context Size
34 return (UINTN
) (sizeof (SHA_CTX
));
38 Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
41 If Sha1Context is NULL, then return FALSE.
43 @param[out] Sha1Context Pointer to SHA-1 context being initialized.
45 @retval TRUE SHA-1 context initialization succeeded.
46 @retval FALSE SHA-1 context initialization failed.
56 // Check input parameters.
58 if (Sha1Context
== NULL
) {
63 // OpenSSL SHA-1 Context Initialization
65 return (BOOLEAN
) (SHA1_Init ((SHA_CTX
*) Sha1Context
));
69 Makes a copy of an existing SHA-1 context.
71 If Sha1Context is NULL, then return FALSE.
72 If NewSha1Context is NULL, then return FALSE.
74 @param[in] Sha1Context Pointer to SHA-1 context being copied.
75 @param[out] NewSha1Context Pointer to new SHA-1 context.
77 @retval TRUE SHA-1 context copy succeeded.
78 @retval FALSE SHA-1 context copy failed.
84 IN CONST VOID
*Sha1Context
,
85 OUT VOID
*NewSha1Context
89 // Check input parameters.
91 if (Sha1Context
== NULL
|| NewSha1Context
== NULL
) {
95 CopyMem (NewSha1Context
, Sha1Context
, sizeof (SHA_CTX
));
101 Digests the input data and updates SHA-1 context.
103 This function performs SHA-1 digest on a data buffer of the specified size.
104 It can be called multiple times to compute the digest of long or discontinuous data streams.
105 SHA-1 context should be already correctly intialized by Sha1Init(), and should not be finalized
106 by Sha1Final(). Behavior with invalid context is undefined.
108 If Sha1Context is NULL, then return FALSE.
110 @param[in, out] Sha1Context Pointer to the SHA-1 context.
111 @param[in] Data Pointer to the buffer containing the data to be hashed.
112 @param[in] DataSize Size of Data buffer in bytes.
114 @retval TRUE SHA-1 data digest succeeded.
115 @retval FALSE SHA-1 data digest failed.
121 IN OUT VOID
*Sha1Context
,
127 // Check input parameters.
129 if (Sha1Context
== NULL
) {
134 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
136 if (Data
== NULL
&& DataSize
!= 0) {
141 // OpenSSL SHA-1 Hash Update
143 return (BOOLEAN
) (SHA1_Update ((SHA_CTX
*) Sha1Context
, Data
, DataSize
));
147 Completes computation of the SHA-1 digest value.
149 This function completes SHA-1 hash computation and retrieves the digest value into
150 the specified memory. After this function has been called, the SHA-1 context cannot
152 SHA-1 context should be already correctly intialized by Sha1Init(), and should not be
153 finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
155 If Sha1Context is NULL, then return FALSE.
156 If HashValue is NULL, then return FALSE.
158 @param[in, out] Sha1Context Pointer to the SHA-1 context.
159 @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
162 @retval TRUE SHA-1 digest computation succeeded.
163 @retval FALSE SHA-1 digest computation failed.
169 IN OUT VOID
*Sha1Context
,
174 // Check input parameters.
176 if (Sha1Context
== NULL
|| HashValue
== NULL
) {
181 // OpenSSL SHA-1 Hash Finalization
183 return (BOOLEAN
) (SHA1_Final (HashValue
, (SHA_CTX
*) Sha1Context
));