Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "chrome/common/visitedlink_common.h" | 5 #include "chrome/common/visitedlink_common.h" |
| 6 | 6 |
| 7 #include <string.h> // for memset() | 7 #include <string.h> // for memset() |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/md5.h" | 10 #include "base/md5.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 | 74 |
| 75 // static | 75 // static |
| 76 VisitedLinkCommon::Fingerprint VisitedLinkCommon::ComputeURLFingerprint( | 76 VisitedLinkCommon::Fingerprint VisitedLinkCommon::ComputeURLFingerprint( |
| 77 const char* canonical_url, | 77 const char* canonical_url, |
| 78 size_t url_len, | 78 size_t url_len, |
| 79 const uint8 salt[LINK_SALT_LENGTH]) { | 79 const uint8 salt[LINK_SALT_LENGTH]) { |
| 80 DCHECK(url_len > 0) << "Canonical URLs should not be empty"; | 80 DCHECK(url_len > 0) << "Canonical URLs should not be empty"; |
| 81 | 81 |
| 82 MD5Context ctx; | 82 MD5Context ctx; |
| 83 MD5Init(&ctx); | 83 MD5Init(&ctx); |
| 84 MD5Update(&ctx, salt, sizeof(salt)); | 84 |
| 85 // This should really be | |
| 86 // MD5Update(&ctx, salt, sizeof(salt) * LINK_SALT_LENGTH); | |
| 87 // but fixing this requires regenerating local databases. 4 bytes of salt | |
| 88 // should be enough for everyone. | |
| 89 MD5Update(&ctx, salt, sizeof(uint8*)); | |
|
brettw
2011/05/25 22:39:01
Hm, it sucks that this is different on 64 and 32 b
Nico
2011/05/25 22:41:56
Tell me what you want (and if it's 2, a three-sent
| |
| 90 | |
| 85 MD5Update(&ctx, canonical_url, url_len * sizeof(char)); | 91 MD5Update(&ctx, canonical_url, url_len * sizeof(char)); |
| 86 | 92 |
| 87 MD5Digest digest; | 93 MD5Digest digest; |
| 88 MD5Final(&digest, &ctx); | 94 MD5Final(&digest, &ctx); |
| 89 | 95 |
| 90 // This is the same as "return *(Fingerprint*)&digest.a;" but if we do that | 96 // This is the same as "return *(Fingerprint*)&digest.a;" but if we do that |
| 91 // direct cast the alignment could be wrong, and we can't access a 64-bit int | 97 // direct cast the alignment could be wrong, and we can't access a 64-bit int |
| 92 // on arbitrary alignment on some processors. This reinterpret_casts it | 98 // on arbitrary alignment on some processors. This reinterpret_casts it |
| 93 // down to a char array of the same size as fingerprint, and then does the | 99 // down to a char array of the same size as fingerprint, and then does the |
| 94 // bit cast, which amounts to a memcpy. This does not handle endian issues. | 100 // bit cast, which amounts to a memcpy. This does not handle endian issues. |
| 95 return bit_cast<Fingerprint, uint8[8]>( | 101 return bit_cast<Fingerprint, uint8[8]>( |
| 96 *reinterpret_cast<uint8(*)[8]>(&digest.a)); | 102 *reinterpret_cast<uint8(*)[8]>(&digest.a)); |
| 97 } | 103 } |
| OLD | NEW |