Deleted Added
full compact
MD5.cpp (261991) MD5.cpp (280031)
1/*
2 * This code is derived from (original license follows):
3 *
4 * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
5 * MD5 Message-Digest Algorithm (RFC 1321).
6 *
7 * Homepage:
8 * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5

--- 194 unchanged lines hidden (view full) ---

203 if (Size < free) {
204 memcpy(&buffer[used], Ptr, Size);
205 return;
206 }
207
208 memcpy(&buffer[used], Ptr, free);
209 Ptr = Ptr + free;
210 Size -= free;
1/*
2 * This code is derived from (original license follows):
3 *
4 * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
5 * MD5 Message-Digest Algorithm (RFC 1321).
6 *
7 * Homepage:
8 * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5

--- 194 unchanged lines hidden (view full) ---

203 if (Size < free) {
204 memcpy(&buffer[used], Ptr, Size);
205 return;
206 }
207
208 memcpy(&buffer[used], Ptr, free);
209 Ptr = Ptr + free;
210 Size -= free;
211 body(ArrayRef<uint8_t>(buffer, 64));
211 body(makeArrayRef(buffer, 64));
212 }
213
214 if (Size >= 64) {
212 }
213
214 if (Size >= 64) {
215 Ptr = body(ArrayRef<uint8_t>(Ptr, Size & ~(unsigned long) 0x3f));
215 Ptr = body(makeArrayRef(Ptr, Size & ~(unsigned long) 0x3f));
216 Size &= 0x3f;
217 }
218
219 memcpy(buffer, Ptr, Size);
220}
221
222/// Add the bytes in the StringRef \p Str to the hash.
223// Note that this isn't a string and so this won't include any trailing NULL
224// bytes.
225void MD5::update(StringRef Str) {
226 ArrayRef<uint8_t> SVal((const uint8_t *)Str.data(), Str.size());
227 update(SVal);
228}
229
230/// \brief Finish the hash and place the resulting hash into \p result.
231/// \param result is assumed to be a minimum of 16-bytes in size.
216 Size &= 0x3f;
217 }
218
219 memcpy(buffer, Ptr, Size);
220}
221
222/// Add the bytes in the StringRef \p Str to the hash.
223// Note that this isn't a string and so this won't include any trailing NULL
224// bytes.
225void MD5::update(StringRef Str) {
226 ArrayRef<uint8_t> SVal((const uint8_t *)Str.data(), Str.size());
227 update(SVal);
228}
229
230/// \brief Finish the hash and place the resulting hash into \p result.
231/// \param result is assumed to be a minimum of 16-bytes in size.
232void MD5::final(MD5Result &result) {
232void MD5::final(MD5Result &Result) {
233 unsigned long used, free;
234
235 used = lo & 0x3f;
236
237 buffer[used++] = 0x80;
238
239 free = 64 - used;
240
241 if (free < 8) {
242 memset(&buffer[used], 0, free);
233 unsigned long used, free;
234
235 used = lo & 0x3f;
236
237 buffer[used++] = 0x80;
238
239 free = 64 - used;
240
241 if (free < 8) {
242 memset(&buffer[used], 0, free);
243 body(ArrayRef<uint8_t>(buffer, 64));
243 body(makeArrayRef(buffer, 64));
244 used = 0;
245 free = 64;
246 }
247
248 memset(&buffer[used], 0, free - 8);
249
250 lo <<= 3;
251 buffer[56] = lo;
252 buffer[57] = lo >> 8;
253 buffer[58] = lo >> 16;
254 buffer[59] = lo >> 24;
255 buffer[60] = hi;
256 buffer[61] = hi >> 8;
257 buffer[62] = hi >> 16;
258 buffer[63] = hi >> 24;
259
244 used = 0;
245 free = 64;
246 }
247
248 memset(&buffer[used], 0, free - 8);
249
250 lo <<= 3;
251 buffer[56] = lo;
252 buffer[57] = lo >> 8;
253 buffer[58] = lo >> 16;
254 buffer[59] = lo >> 24;
255 buffer[60] = hi;
256 buffer[61] = hi >> 8;
257 buffer[62] = hi >> 16;
258 buffer[63] = hi >> 24;
259
260 body(ArrayRef<uint8_t>(buffer, 64));
260 body(makeArrayRef(buffer, 64));
261
261
262 result[0] = a;
263 result[1] = a >> 8;
264 result[2] = a >> 16;
265 result[3] = a >> 24;
266 result[4] = b;
267 result[5] = b >> 8;
268 result[6] = b >> 16;
269 result[7] = b >> 24;
270 result[8] = c;
271 result[9] = c >> 8;
272 result[10] = c >> 16;
273 result[11] = c >> 24;
274 result[12] = d;
275 result[13] = d >> 8;
276 result[14] = d >> 16;
277 result[15] = d >> 24;
262 Result[0] = a;
263 Result[1] = a >> 8;
264 Result[2] = a >> 16;
265 Result[3] = a >> 24;
266 Result[4] = b;
267 Result[5] = b >> 8;
268 Result[6] = b >> 16;
269 Result[7] = b >> 24;
270 Result[8] = c;
271 Result[9] = c >> 8;
272 Result[10] = c >> 16;
273 Result[11] = c >> 24;
274 Result[12] = d;
275 Result[13] = d >> 8;
276 Result[14] = d >> 16;
277 Result[15] = d >> 24;
278}
279
278}
279
280void MD5::stringifyResult(MD5Result &result, SmallString<32> &Str) {
280void MD5::stringifyResult(MD5Result &Result, SmallString<32> &Str) {
281 raw_svector_ostream Res(Str);
282 for (int i = 0; i < 16; ++i)
281 raw_svector_ostream Res(Str);
282 for (int i = 0; i < 16; ++i)
283 Res << format("%.2x", result[i]);
283 Res << format("%.2x", Result[i]);
284}
285
286}
284}
285
286}