]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4.c
1. Remove conducting ASSERT in BaseCryptLib.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Hash / CryptMd4.c
... / ...
CommitLineData
1/** @file\r
2 MD4 Digest Wrapper Implementation over OpenSSL.\r
3\r
4Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "InternalCryptLib.h"\r
16#include <openssl/md4.h>\r
17\r
18/**\r
19 Retrieves the size, in bytes, of the context buffer required for MD4 hash operations.\r
20\r
21 @return The size, in bytes, of the context buffer required for MD4 hash operations.\r
22\r
23**/\r
24UINTN\r
25EFIAPI\r
26Md4GetContextSize (\r
27 VOID\r
28 )\r
29{\r
30 //\r
31 // Retrieves the OpenSSL MD4 Context Size\r
32 //\r
33 return (UINTN)(sizeof (MD4_CTX));\r
34}\r
35\r
36/**\r
37 Initializes user-supplied memory pointed by Md4Context as MD4 hash context for\r
38 subsequent use.\r
39\r
40 If Md4Context is NULL, then return FALSE.\r
41\r
42 @param[out] Md4Context Pointer to MD4 context being initialized.\r
43\r
44 @retval TRUE MD4 context initialization succeeded.\r
45 @retval FALSE MD4 context initialization failed.\r
46\r
47**/\r
48BOOLEAN\r
49EFIAPI\r
50Md4Init (\r
51 OUT VOID *Md4Context\r
52 )\r
53{\r
54 //\r
55 // Check input parameters.\r
56 //\r
57 if (Md4Context == NULL) {\r
58 return FALSE;\r
59 }\r
60\r
61 //\r
62 // OpenSSL MD4 Context Initialization\r
63 //\r
64 return (BOOLEAN) (MD4_Init ((MD4_CTX *)Md4Context));\r
65}\r
66\r
67/**\r
68 Makes a copy of an existing MD4 context.\r
69\r
70 If Md4Context is NULL, then return FALSE.\r
71 If NewMd4Context is NULL, then return FALSE.\r
72\r
73 @param[in] Md4Context Pointer to MD4 context being copied.\r
74 @param[out] NewMd4Context Pointer to new MD4 context.\r
75\r
76 @retval TRUE MD4 context copy succeeded.\r
77 @retval FALSE MD4 context copy failed.\r
78\r
79**/\r
80BOOLEAN\r
81EFIAPI\r
82Md4Duplicate (\r
83 IN CONST VOID *Md4Context,\r
84 OUT VOID *NewMd4Context\r
85 )\r
86{\r
87 //\r
88 // Check input parameters.\r
89 //\r
90 if (Md4Context == NULL || NewMd4Context == NULL) {\r
91 return FALSE;\r
92 }\r
93\r
94 CopyMem (NewMd4Context, Md4Context, sizeof (MD4_CTX));\r
95\r
96 return TRUE;\r
97}\r
98\r
99/**\r
100 Digests the input data and updates MD4 context.\r
101\r
102 This function performs MD4 digest on a data buffer of the specified size.\r
103 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
104 MD4 context should be already correctly intialized by Md4Init(), and should not be finalized\r
105 by Md4Final(). Behavior with invalid context is undefined.\r
106\r
107 If Md4Context is NULL, then return FALSE.\r
108\r
109 @param[in, out] Md4Context Pointer to the MD4 context.\r
110 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
111 @param[in] DataSize Size of Data buffer in bytes.\r
112\r
113 @retval TRUE MD4 data digest succeeded.\r
114 @retval FALSE MD4 data digest failed.\r
115\r
116**/\r
117BOOLEAN\r
118EFIAPI\r
119Md4Update (\r
120 IN OUT VOID *Md4Context,\r
121 IN CONST VOID *Data,\r
122 IN UINTN DataSize\r
123 )\r
124{\r
125 //\r
126 // Check input parameters.\r
127 //\r
128 if (Md4Context == NULL) {\r
129 return FALSE;\r
130 }\r
131\r
132 //\r
133 // Check invalid parameters, in case that only DataLength was checked in OpenSSL\r
134 //\r
135 if (Data == NULL && DataSize != 0) {\r
136 return FALSE;\r
137 }\r
138\r
139 //\r
140 // OpenSSL MD4 Hash Update\r
141 //\r
142 return (BOOLEAN) (MD4_Update ((MD4_CTX *)Md4Context, Data, DataSize));\r
143}\r
144\r
145/**\r
146 Completes computation of the MD4 digest value.\r
147\r
148 This function completes MD4 hash computation and retrieves the digest value into\r
149 the specified memory. After this function has been called, the MD4 context cannot\r
150 be used again.\r
151 MD4 context should be already correctly intialized by Md4Init(), and should not be\r
152 finalized by Md4Final(). Behavior with invalid MD4 context is undefined.\r
153\r
154 If Md4Context is NULL, then return FALSE.\r
155 If HashValue is NULL, then return FALSE.\r
156\r
157 @param[in, out] Md4Context Pointer to the MD4 context.\r
158 @param[out] HashValue Pointer to a buffer that receives the MD4 digest\r
159 value (16 bytes).\r
160\r
161 @retval TRUE MD4 digest computation succeeded.\r
162 @retval FALSE MD4 digest computation failed.\r
163\r
164**/\r
165BOOLEAN\r
166EFIAPI\r
167Md4Final (\r
168 IN OUT VOID *Md4Context,\r
169 OUT UINT8 *HashValue\r
170 )\r
171{\r
172 //\r
173 // Check input parameters.\r
174 //\r
175 if (Md4Context == NULL || HashValue == NULL) {\r
176 return FALSE;\r
177 }\r
178\r
179 //\r
180 // OpenSSL MD4 Hash Finalization\r
181 //\r
182 return (BOOLEAN) (MD4_Final (HashValue, (MD4_CTX *)Md4Context));\r
183}\r