| 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 /* Append length in bits and transform */ | 253 /* Append length in bits and transform */ |
| 254 ((uint32 *)ctx->in)[ 14 ] = ctx->bits[0]; | 254 ((uint32 *)ctx->in)[ 14 ] = ctx->bits[0]; |
| 255 ((uint32 *)ctx->in)[ 15 ] = ctx->bits[1]; | 255 ((uint32 *)ctx->in)[ 15 ] = ctx->bits[1]; |
| 256 | 256 |
| 257 MD5Transform(ctx->buf, (uint32 *)ctx->in); | 257 MD5Transform(ctx->buf, (uint32 *)ctx->in); |
| 258 byteReverse((unsigned char *)ctx->buf, 4); | 258 byteReverse((unsigned char *)ctx->buf, 4); |
| 259 memcpy(digest->a, ctx->buf, 16); | 259 memcpy(digest->a, ctx->buf, 16); |
| 260 memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ | 260 memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ |
| 261 } | 261 } |
| 262 | 262 |
| 263 void MD5IntermediateFinal(MD5Digest* digest, const MD5Context* context) { |
| 264 /* MD5Final mutates the MD5Context*. Make a copy for generating the |
| 265 intermediate value. */ |
| 266 MD5Context context_copy; |
| 267 memcpy(&context_copy, context, sizeof(context_copy)); |
| 268 MD5Final(digest, &context_copy); |
| 269 } |
| 270 |
| 263 std::string MD5DigestToBase16(const MD5Digest& digest) { | 271 std::string MD5DigestToBase16(const MD5Digest& digest) { |
| 264 static char const zEncode[] = "0123456789abcdef"; | 272 static char const zEncode[] = "0123456789abcdef"; |
| 265 | 273 |
| 266 std::string ret; | 274 std::string ret; |
| 267 ret.resize(32); | 275 ret.resize(32); |
| 268 | 276 |
| 269 int j = 0; | 277 int j = 0; |
| 270 for (int i = 0; i < 16; i ++) { | 278 for (int i = 0; i < 16; i ++) { |
| 271 int a = digest.a[i]; | 279 int a = digest.a[i]; |
| 272 ret[j++] = zEncode[(a>>4)&0xf]; | 280 ret[j++] = zEncode[(a>>4)&0xf]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 283 MD5Final(digest, &ctx); | 291 MD5Final(digest, &ctx); |
| 284 } | 292 } |
| 285 | 293 |
| 286 std::string MD5String(const StringPiece& str) { | 294 std::string MD5String(const StringPiece& str) { |
| 287 MD5Digest digest; | 295 MD5Digest digest; |
| 288 MD5Sum(str.data(), str.length(), &digest); | 296 MD5Sum(str.data(), str.length(), &digest); |
| 289 return MD5DigestToBase16(digest); | 297 return MD5DigestToBase16(digest); |
| 290 } | 298 } |
| 291 | 299 |
| 292 } // namespace base | 300 } // namespace base |
| OLD | NEW |