]>
Commit | Line | Data |
---|---|---|
4a567c96 | 1 | /** @file\r |
2 | MD4 Digest Wrapper Implementation over OpenSSL.\r | |
3 | \r | |
b7d1ba0a | 4 | Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r |
4a567c96 | 5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT 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 | |
24 | UINTN\r | |
25 | EFIAPI\r | |
26 | Md4GetContextSize (\r | |
27 | VOID\r | |
28 | )\r | |
29 | {\r | |
30 | //\r | |
31 | // Retrieves the OpenSSL MD4 Context Size\r | |
32 | //\r | |
6b8ebcb8 | 33 | return (UINTN) (sizeof (MD4_CTX));\r |
4a567c96 | 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 | |
16d2c32c | 40 | If Md4Context is NULL, then return FALSE.\r |
4a567c96 | 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 | |
48 | BOOLEAN\r | |
49 | EFIAPI\r | |
50 | Md4Init (\r | |
51 | OUT VOID *Md4Context\r | |
52 | )\r | |
53 | {\r | |
54 | //\r | |
16d2c32c | 55 | // Check input parameters.\r |
4a567c96 | 56 | //\r |
16d2c32c | 57 | if (Md4Context == NULL) {\r |
58 | return FALSE;\r | |
59 | }\r | |
4a567c96 | 60 | \r |
61 | //\r | |
62 | // OpenSSL MD4 Context Initialization\r | |
63 | //\r | |
6b8ebcb8 | 64 | return (BOOLEAN) (MD4_Init ((MD4_CTX *) Md4Context));\r |
4a567c96 | 65 | }\r |
66 | \r | |
67 | /**\r | |
68 | Makes a copy of an existing MD4 context.\r | |
69 | \r | |
16d2c32c | 70 | If Md4Context is NULL, then return FALSE.\r |
71 | If NewMd4Context is NULL, then return FALSE.\r | |
4a567c96 | 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 | |
80 | BOOLEAN\r | |
81 | EFIAPI\r | |
82 | Md4Duplicate (\r | |
83 | IN CONST VOID *Md4Context,\r | |
84 | OUT VOID *NewMd4Context\r | |
85 | )\r | |
86 | {\r | |
87 | //\r | |
16d2c32c | 88 | // Check input parameters.\r |
4a567c96 | 89 | //\r |
16d2c32c | 90 | if (Md4Context == NULL || NewMd4Context == NULL) {\r |
91 | return FALSE;\r | |
92 | }\r | |
4a567c96 | 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 | |
2998af86 | 104 | MD4 context should be already correctly initialized by Md4Init(), and should not be finalized\r |
4a567c96 | 105 | by Md4Final(). Behavior with invalid context is undefined.\r |
106 | \r | |
16d2c32c | 107 | If Md4Context is NULL, then return FALSE.\r |
4a567c96 | 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 | |
117 | BOOLEAN\r | |
118 | EFIAPI\r | |
119 | Md4Update (\r | |
120 | IN OUT VOID *Md4Context,\r | |
121 | IN CONST VOID *Data,\r | |
122 | IN UINTN DataSize\r | |
123 | )\r | |
124 | {\r | |
125 | //\r | |
16d2c32c | 126 | // Check input parameters.\r |
4a567c96 | 127 | //\r |
16d2c32c | 128 | if (Md4Context == NULL) {\r |
129 | return FALSE;\r | |
130 | }\r | |
4a567c96 | 131 | \r |
132 | //\r | |
16d2c32c | 133 | // Check invalid parameters, in case that only DataLength was checked in OpenSSL\r |
4a567c96 | 134 | //\r |
16d2c32c | 135 | if (Data == NULL && DataSize != 0) {\r |
136 | return FALSE;\r | |
4a567c96 | 137 | }\r |
138 | \r | |
139 | //\r | |
140 | // OpenSSL MD4 Hash Update\r | |
141 | //\r | |
6b8ebcb8 | 142 | return (BOOLEAN) (MD4_Update ((MD4_CTX *) Md4Context, Data, DataSize));\r |
4a567c96 | 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 | |
2998af86 | 151 | MD4 context should be already correctly initialized by Md4Init(), and should not be\r |
4a567c96 | 152 | finalized by Md4Final(). Behavior with invalid MD4 context is undefined.\r |
153 | \r | |
16d2c32c | 154 | If Md4Context is NULL, then return FALSE.\r |
155 | If HashValue is NULL, then return FALSE.\r | |
4a567c96 | 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 | |
165 | BOOLEAN\r | |
166 | EFIAPI\r | |
167 | Md4Final (\r | |
168 | IN OUT VOID *Md4Context,\r | |
169 | OUT UINT8 *HashValue\r | |
170 | )\r | |
171 | {\r | |
172 | //\r | |
16d2c32c | 173 | // Check input parameters.\r |
4a567c96 | 174 | //\r |
16d2c32c | 175 | if (Md4Context == NULL || HashValue == NULL) {\r |
176 | return FALSE;\r | |
177 | }\r | |
4a567c96 | 178 | \r |
179 | //\r | |
180 | // OpenSSL MD4 Hash Finalization\r | |
181 | //\r | |
6b8ebcb8 | 182 | return (BOOLEAN) (MD4_Final (HashValue, (MD4_CTX *) Md4Context));\r |
4a567c96 | 183 | }\r |
b7d1ba0a QL |
184 | \r |
185 | /**\r | |
186 | Computes the MD4 message digest of a input data buffer.\r | |
187 | \r | |
188 | This function performs the MD4 message digest of a given data buffer, and places\r | |
189 | the digest value into the specified memory.\r | |
190 | \r | |
191 | If this interface is not supported, then return FALSE.\r | |
192 | \r | |
193 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
194 | @param[in] DataSize Size of Data buffer in bytes.\r | |
195 | @param[out] HashValue Pointer to a buffer that receives the MD4 digest\r | |
196 | value (16 bytes).\r | |
197 | \r | |
198 | @retval TRUE MD4 digest computation succeeded.\r | |
199 | @retval FALSE MD4 digest computation failed.\r | |
200 | @retval FALSE This interface is not supported.\r | |
201 | \r | |
202 | **/\r | |
203 | BOOLEAN\r | |
204 | EFIAPI\r | |
205 | Md4HashAll (\r | |
206 | IN CONST VOID *Data,\r | |
207 | IN UINTN DataSize,\r | |
208 | OUT UINT8 *HashValue\r | |
209 | )\r | |
210 | {\r | |
211 | //\r | |
212 | // Check input parameters.\r | |
213 | //\r | |
214 | if (HashValue == NULL) {\r | |
215 | return FALSE;\r | |
216 | }\r | |
217 | if (Data == NULL && DataSize != 0) {\r | |
218 | return FALSE;\r | |
219 | }\r | |
220 | \r | |
221 | //\r | |
222 | // OpenSSL MD4 Hash Computation.\r | |
223 | //\r | |
224 | if (MD4 (Data, DataSize, HashValue) == NULL) {\r | |
225 | return FALSE;\r | |
226 | } else {\r | |
227 | return TRUE;\r | |
228 | }\r | |
229 | }\r |