]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Hash/CryptMd5.c
2 MD5 Digest Wrapper Implementation over OpenSSL.
4 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "InternalCryptLib.h"
10 #include <openssl/md5.h>
14 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
16 @return The size, in bytes, of the context buffer required for MD5 hash operations.
26 // Retrieves the OpenSSL MD5 Context Size
28 return (UINTN
) (sizeof (MD5_CTX
));
33 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
36 If Md5Context is NULL, then return FALSE.
38 @param[out] Md5Context Pointer to MD5 context being initialized.
40 @retval TRUE MD5 context initialization succeeded.
41 @retval FALSE MD5 context initialization failed.
51 // Check input parameters.
53 if (Md5Context
== NULL
) {
58 // OpenSSL MD5 Context Initialization
60 return (BOOLEAN
) (MD5_Init ((MD5_CTX
*) Md5Context
));
64 Makes a copy of an existing MD5 context.
66 If Md5Context is NULL, then return FALSE.
67 If NewMd5Context is NULL, then return FALSE.
69 @param[in] Md5Context Pointer to MD5 context being copied.
70 @param[out] NewMd5Context Pointer to new MD5 context.
72 @retval TRUE MD5 context copy succeeded.
73 @retval FALSE MD5 context copy failed.
79 IN CONST VOID
*Md5Context
,
80 OUT VOID
*NewMd5Context
84 // Check input parameters.
86 if (Md5Context
== NULL
|| NewMd5Context
== NULL
) {
90 CopyMem (NewMd5Context
, Md5Context
, sizeof (MD5_CTX
));
96 Digests the input data and updates MD5 context.
98 This function performs MD5 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 MD5 context should be already correctly initialized by Md5Init(), and should not be finalized
101 by Md5Final(). Behavior with invalid context is undefined.
103 If Md5Context is NULL, then return FALSE.
105 @param[in, out] Md5Context Pointer to the MD5 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 MD5 data digest succeeded.
110 @retval FALSE MD5 data digest failed.
116 IN OUT VOID
*Md5Context
,
122 // Check input parameters.
124 if (Md5Context
== NULL
) {
129 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
131 if (Data
== NULL
&& (DataSize
!= 0)) {
136 // OpenSSL MD5 Hash Update
138 return (BOOLEAN
) (MD5_Update ((MD5_CTX
*) Md5Context
, Data
, DataSize
));
142 Completes computation of the MD5 digest value.
144 This function completes MD5 hash computation and retrieves the digest value into
145 the specified memory. After this function has been called, the MD5 context cannot
147 MD5 context should be already correctly initialized by Md5Init(), and should not be
148 finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
150 If Md5Context is NULL, then return FALSE.
151 If HashValue is NULL, then return FALSE.
153 @param[in, out] Md5Context Pointer to the MD5 context.
154 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
157 @retval TRUE MD5 digest computation succeeded.
158 @retval FALSE MD5 digest computation failed.
164 IN OUT VOID
*Md5Context
,
169 // Check input parameters.
171 if (Md5Context
== NULL
|| HashValue
== NULL
) {
176 // OpenSSL MD5 Hash Finalization
178 return (BOOLEAN
) (MD5_Final (HashValue
, (MD5_CTX
*) Md5Context
));
182 Computes the MD5 message digest of a input data buffer.
184 This function performs the MD5 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 MD5 digest
194 @retval TRUE MD5 digest computation succeeded.
195 @retval FALSE MD5 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 MD5 Hash Computation.
220 if (MD5 (Data
, DataSize
, HashValue
) == NULL
) {