Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: base/md5.cc

Issue 7466003: MD5Update function uses StringPiece instead of raw buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tfarina review Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/md5.h ('k') | base/md5_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
3 // found in the LICENSE file.
4
1 // 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.
2 // Modifications Copyright 2006 Google Inc. All Rights Reserved 6 // Modifications Copyright 2006 Google Inc. All Rights Reserved
brettw 2011/07/26 04:35:58 Just remove the "Modifications Copyright 2006 Goog
3 7
4 /* 8 /*
5 * This code implements the MD5 message-digest algorithm. 9 * This code implements the MD5 message-digest algorithm.
6 * The algorithm is due to Ron Rivest. This code was 10 * The algorithm is due to Ron Rivest. This code was
7 * written by Colin Plumb in 1993, no copyright is claimed. 11 * written by Colin Plumb in 1993, no copyright is claimed.
8 * This code is in the public domain; do with it what you wish. 12 * This code is in the public domain; do with it what you wish.
9 * 13 *
10 * Equivalent code is available from RSA Data Security, Inc. 14 * Equivalent code is available from RSA Data Security, Inc.
11 * This code has been tested against that, and is equivalent, 15 * This code has been tested against that, and is equivalent,
12 * except that you don't need to include two pages of legalese 16 * except that you don't need to include two pages of legalese
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 ctx->buf[2] = 0x98badcfe; 161 ctx->buf[2] = 0x98badcfe;
158 ctx->buf[3] = 0x10325476; 162 ctx->buf[3] = 0x10325476;
159 ctx->bits[0] = 0; 163 ctx->bits[0] = 0;
160 ctx->bits[1] = 0; 164 ctx->bits[1] = 0;
161 } 165 }
162 166
163 /* 167 /*
164 * Update context to reflect the concatenation of another buffer full 168 * Update context to reflect the concatenation of another buffer full
165 * of bytes. 169 * of bytes.
166 */ 170 */
167 void MD5Update(MD5Context* context, const void* inbuf, size_t len) { 171 void MD5Update(MD5Context* context, const StringPiece& data) {
172 const unsigned char* inbuf = (const unsigned char*)data.data();
173 size_t len = data.size();
168 struct Context *ctx = (struct Context *)context; 174 struct Context *ctx = (struct Context *)context;
169 const unsigned char* buf = (const unsigned char*)inbuf; 175 const unsigned char* buf = (const unsigned char*)inbuf;
170 uint32 t; 176 uint32 t;
171 177
172 /* Update bitcount */ 178 /* Update bitcount */
173 179
174 t = ctx->bits[0]; 180 t = ctx->bits[0];
175 if ((ctx->bits[0] = t + ((uint32)len << 3)) < t) 181 if ((ctx->bits[0] = t + ((uint32)len << 3)) < t)
176 ctx->bits[1]++; /* Carry from low to high */ 182 ctx->bits[1]++; /* Carry from low to high */
177 ctx->bits[1] += static_cast<uint32>(len >> 29); 183 ctx->bits[1] += static_cast<uint32>(len >> 29);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 int a = digest.a[i]; 272 int a = digest.a[i];
267 ret[j++] = zEncode[(a>>4)&0xf]; 273 ret[j++] = zEncode[(a>>4)&0xf];
268 ret[j++] = zEncode[a & 0xf]; 274 ret[j++] = zEncode[a & 0xf];
269 } 275 }
270 return ret; 276 return ret;
271 } 277 }
272 278
273 void MD5Sum(const void* data, size_t length, MD5Digest* digest) { 279 void MD5Sum(const void* data, size_t length, MD5Digest* digest) {
274 MD5Context ctx; 280 MD5Context ctx;
275 MD5Init(&ctx); 281 MD5Init(&ctx);
276 MD5Update(&ctx, static_cast<const unsigned char*>(data), length); 282 MD5Update(&ctx,
283 StringPiece(reinterpret_cast<const char*>(data), length));
277 MD5Final(digest, &ctx); 284 MD5Final(digest, &ctx);
278 } 285 }
279 286
280 std::string MD5String(const std::string& str) { 287 std::string MD5String(const StringPiece& str) {
281 MD5Digest digest; 288 MD5Digest digest;
282 MD5Sum(str.data(), str.length(), &digest); 289 MD5Sum(str.data(), str.length(), &digest);
283 return MD5DigestToBase16(digest); 290 return MD5DigestToBase16(digest);
284 } 291 }
285 292
286 } // namespace base 293 } // namespace base
OLDNEW
« no previous file with comments | « base/md5.h ('k') | base/md5_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698