]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Hash/CryptMd5.c
99471a01760f55fc0bdf4d186d0e45c74696150e
2 MD5 Digest Wrapper Implementation over OpenSSL.
4 Copyright (c) 2009 - 2010, 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 <Library/BaseLib.h>
16 #include <Library/DebugLib.h>
18 #include <Library/BaseCryptLib.h>
19 #include <openssl/md5.h>
23 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
25 @return The size, in bytes, of the context buffer required for MD5 hash operations.
35 // Retrieves the OpenSSL MD5 Context Size
37 return (UINTN
)(sizeof (MD5_CTX
));
42 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
45 If Md5Context is NULL, then ASSERT().
47 @param[in, out] Md5Context Pointer to MD5 Context being initialized.
49 @retval TRUE MD5 context initialization succeeded.
50 @retval FALSE MD5 context initialization failed.
56 IN OUT VOID
*Md5Context
60 // ASSERT if Md5Context is NULL.
62 ASSERT (Md5Context
!= NULL
);
65 // OpenSSL MD5 Context Initialization
67 return (BOOLEAN
) (MD5_Init ((MD5_CTX
*)Md5Context
));
72 Performs MD5 digest on a data buffer of the specified length. This function can
73 be called multiple times to compute the digest of long or discontinuous data streams.
75 If Md5Context is NULL, then ASSERT().
77 @param[in, out] Md5Context Pointer to the MD5 context.
78 @param[in] Data Pointer to the buffer containing the data to be hashed.
79 @param[in] DataLength Length of Data buffer in bytes.
81 @retval TRUE MD5 data digest succeeded.
82 @retval FALSE Invalid MD5 context. After Md5Final function has been called, the
83 MD5 context cannot be reused.
89 IN OUT VOID
*Md5Context
,
95 // ASSERT if Md5Context is NULL
97 ASSERT (Md5Context
!= NULL
);
100 // ASSERT if invalid parameters, in case that only DataLength was checked in OpenSSL
103 ASSERT (DataLength
== 0);
107 // OpenSSL MD5 Hash Update
109 return (BOOLEAN
) (MD5_Update ((MD5_CTX
*)Md5Context
, Data
, DataLength
));
114 Completes MD5 hash computation and retrieves the digest value into the specified
115 memory. After this function has been called, the MD5 context cannot be used again.
117 If Md5Context is NULL, then ASSERT().
118 If HashValue is NULL, then ASSERT().
120 @param[in, out] Md5Context Pointer to the MD5 context
121 @param[out] HashValue Pointer to a buffer that receives the MD5 digest
124 @retval TRUE MD5 digest computation succeeded.
125 @retval FALSE MD5 digest computation failed.
131 IN OUT VOID
*Md5Context
,
136 // ASSERT if Md5Context is NULL or HashValue is NULL
138 ASSERT (Md5Context
!= NULL
);
139 ASSERT (HashValue
!= NULL
);
142 // OpenSSL MD5 Hash Finalization
144 return (BOOLEAN
) (MD5_Final (HashValue
, (MD5_CTX
*)Md5Context
));