OLD | NEW |
1 // The original file was copied from sqlite, and was in the public domain. | 1 // The original file was copied from sqlite, and was in the public domain. |
2 // Modifications Copyright 2006 Google Inc. All Rights Reserved | 2 // Modifications Copyright 2006 Google Inc. All Rights Reserved |
3 | 3 |
4 /* | 4 /* |
5 * This code implements the MD5 message-digest algorithm. | 5 * This code implements the MD5 message-digest algorithm. |
6 * The algorithm is due to Ron Rivest. This code was | 6 * The algorithm is due to Ron Rivest. This code was |
7 * written by Colin Plumb in 1993, no copyright is claimed. | 7 * written by Colin Plumb in 1993, no copyright is claimed. |
8 * This code is in the public domain; do with it what you wish. | 8 * This code is in the public domain; do with it what you wish. |
9 * | 9 * |
10 * Equivalent code is available from RSA Data Security, Inc. | 10 * Equivalent code is available from RSA Data Security, Inc. |
11 * This code has been tested against that, and is equivalent, | 11 * This code has been tested against that, and is equivalent, |
12 * except that you don't need to include two pages of legalese | 12 * except that you don't need to include two pages of legalese |
13 * with every copy. | 13 * with every copy. |
14 * | 14 * |
15 * To compute the message digest of a chunk of bytes, declare an | 15 * To compute the message digest of a chunk of bytes, declare an |
16 * MD5Context structure, pass it to MD5Init, call MD5Update as | 16 * MD5Context structure, pass it to MD5Init, call MD5Update as |
17 * needed on buffers full of bytes, and then call MD5Final, which | 17 * needed on buffers full of bytes, and then call MD5Final, which |
18 * will fill a supplied 16-byte array with the digest. | 18 * will fill a supplied 16-byte array with the digest. |
19 */ | 19 */ |
20 | 20 |
| 21 #include <stddef.h> |
| 22 #include <string.h> |
21 #include <string> | 23 #include <string> |
22 | 24 |
| 25 #include "base/basictypes.h" |
23 #include "base/md5.h" | 26 #include "base/md5.h" |
24 | 27 |
25 #include "base/basictypes.h" | |
26 | |
27 struct Context { | 28 struct Context { |
28 uint32 buf[4]; | 29 uint32 buf[4]; |
29 uint32 bits[2]; | 30 uint32 bits[2]; |
30 unsigned char in[64]; | 31 unsigned char in[64]; |
31 }; | 32 }; |
32 | 33 |
33 /* | 34 /* |
34 * Note: this code is harmless on little-endian machines. | 35 * Note: this code is harmless on little-endian machines. |
35 */ | 36 */ |
36 static void byteReverse(unsigned char *buf, unsigned longs){ | 37 static void byteReverse(unsigned char *buf, unsigned longs){ |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 MD5Init(&ctx); | 271 MD5Init(&ctx); |
271 MD5Update(&ctx, static_cast<const unsigned char*>(data), length); | 272 MD5Update(&ctx, static_cast<const unsigned char*>(data), length); |
272 MD5Final(digest, &ctx); | 273 MD5Final(digest, &ctx); |
273 } | 274 } |
274 | 275 |
275 std::string MD5String(const std::string& str) { | 276 std::string MD5String(const std::string& str) { |
276 MD5Digest digest; | 277 MD5Digest digest; |
277 MD5Sum(str.data(), str.length(), &digest); | 278 MD5Sum(str.data(), str.length(), &digest); |
278 return MD5DigestToBase16(digest); | 279 return MD5DigestToBase16(digest); |
279 } | 280 } |
OLD | NEW |