OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The original file was copied from sqlite, and was in the public domain. | 5 // The original file was copied from sqlite, and was in the public domain. |
6 | 6 |
7 /* | 7 /* |
8 * This code implements the MD5 message-digest algorithm. | 8 * This code implements the MD5 message-digest algorithm. |
9 * The algorithm is due to Ron Rivest. This code was | 9 * The algorithm is due to Ron Rivest. This code was |
10 * written by Colin Plumb in 1993, no copyright is claimed. | 10 * written by Colin Plumb in 1993, no copyright is claimed. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 MD5Transform(ctx->buf, (uint32 *)ctx->in); | 208 MD5Transform(ctx->buf, (uint32 *)ctx->in); |
209 buf += 64; | 209 buf += 64; |
210 len -= 64; | 210 len -= 64; |
211 } | 211 } |
212 | 212 |
213 /* Handle any remaining bytes of data. */ | 213 /* Handle any remaining bytes of data. */ |
214 | 214 |
215 memcpy(ctx->in, buf, len); | 215 memcpy(ctx->in, buf, len); |
216 } | 216 } |
217 | 217 |
| 218 void MD5Clone(MD5Context* clone_context, MD5Context* original_context) { |
| 219 memcpy(clone_context, original_context, sizeof(MD5Context)); |
| 220 } |
| 221 |
218 /* | 222 /* |
219 * Final wrapup - pad to 64-byte boundary with the bit pattern | 223 * Final wrapup - pad to 64-byte boundary with the bit pattern |
220 * 1 0* (64-bit count of bits processed, MSB-first) | 224 * 1 0* (64-bit count of bits processed, MSB-first) |
221 */ | 225 */ |
222 void MD5Final(MD5Digest* digest, MD5Context* context) { | 226 void MD5Final(MD5Digest* digest, MD5Context* context) { |
223 struct Context *ctx = (struct Context *)context; | 227 struct Context *ctx = (struct Context *)context; |
224 unsigned count; | 228 unsigned count; |
225 unsigned char *p; | 229 unsigned char *p; |
226 | 230 |
227 /* Compute number of bytes mod 64 */ | 231 /* Compute number of bytes mod 64 */ |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 MD5Final(digest, &ctx); | 287 MD5Final(digest, &ctx); |
284 } | 288 } |
285 | 289 |
286 std::string MD5String(const StringPiece& str) { | 290 std::string MD5String(const StringPiece& str) { |
287 MD5Digest digest; | 291 MD5Digest digest; |
288 MD5Sum(str.data(), str.length(), &digest); | 292 MD5Sum(str.data(), str.length(), &digest); |
289 return MD5DigestToBase16(digest); | 293 return MD5DigestToBase16(digest); |
290 } | 294 } |
291 | 295 |
292 } // namespace base | 296 } // namespace base |
OLD | NEW |