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

Side by Side Diff: base/md5.cc

Issue 7003140: Fix two bugs found by a new clang warning I'm currently testing: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 6 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 | « no previous file | media/video/capture/fake_video_capture_device.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 // 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.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 240 }
241 byteReverse(ctx->in, 14); 241 byteReverse(ctx->in, 14);
242 242
243 /* Append length in bits and transform */ 243 /* Append length in bits and transform */
244 ((uint32 *)ctx->in)[ 14 ] = ctx->bits[0]; 244 ((uint32 *)ctx->in)[ 14 ] = ctx->bits[0];
245 ((uint32 *)ctx->in)[ 15 ] = ctx->bits[1]; 245 ((uint32 *)ctx->in)[ 15 ] = ctx->bits[1];
246 246
247 MD5Transform(ctx->buf, (uint32 *)ctx->in); 247 MD5Transform(ctx->buf, (uint32 *)ctx->in);
248 byteReverse((unsigned char *)ctx->buf, 4); 248 byteReverse((unsigned char *)ctx->buf, 4);
249 memcpy(digest->a, ctx->buf, 16); 249 memcpy(digest->a, ctx->buf, 16);
250 memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ 250 memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
251 } 251 }
252 252
253 std::string MD5DigestToBase16(const MD5Digest& digest){ 253 std::string MD5DigestToBase16(const MD5Digest& digest){
254 static char const zEncode[] = "0123456789abcdef"; 254 static char const zEncode[] = "0123456789abcdef";
255 255
256 std::string ret; 256 std::string ret;
257 ret.resize(32); 257 ret.resize(32);
258 258
259 int j = 0; 259 int j = 0;
260 for (int i = 0; i < 16; i ++) { 260 for (int i = 0; i < 16; i ++) {
261 int a = digest.a[i]; 261 int a = digest.a[i];
262 ret[j++] = zEncode[(a>>4)&0xf]; 262 ret[j++] = zEncode[(a>>4)&0xf];
263 ret[j++] = zEncode[a & 0xf]; 263 ret[j++] = zEncode[a & 0xf];
264 } 264 }
265 return ret; 265 return ret;
266 } 266 }
267 267
268 void MD5Sum(const void* data, size_t length, MD5Digest* digest) { 268 void MD5Sum(const void* data, size_t length, MD5Digest* digest) {
269 MD5Context ctx; 269 MD5Context ctx;
270 MD5Init(&ctx); 270 MD5Init(&ctx);
271 MD5Update(&ctx, static_cast<const unsigned char*>(data), length); 271 MD5Update(&ctx, static_cast<const unsigned char*>(data), length);
272 MD5Final(digest, &ctx); 272 MD5Final(digest, &ctx);
273 } 273 }
274 274
275 std::string MD5String(const std::string& str) { 275 std::string MD5String(const std::string& str) {
276 MD5Digest digest; 276 MD5Digest digest;
277 MD5Sum(str.data(), str.length(), &digest); 277 MD5Sum(str.data(), str.length(), &digest);
278 return MD5DigestToBase16(digest); 278 return MD5DigestToBase16(digest);
279 } 279 }
OLDNEW
« no previous file with comments | « no previous file | media/video/capture/fake_video_capture_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698