diff options
30 files changed, 187 insertions, 170 deletions
diff --git a/base/md5.cc b/base/md5.cc index ff69dc0..2211a28 100644 --- a/base/md5.cc +++ b/base/md5.cc @@ -22,6 +22,8 @@ #include "base/basictypes.h" +namespace { + struct Context { uint32 buf[4]; uint32 bits[2]; @@ -31,7 +33,7 @@ struct Context { /* * Note: this code is harmless on little-endian machines. */ -static void byteReverse(unsigned char *buf, unsigned longs){ +void byteReverse(unsigned char *buf, unsigned longs) { uint32 t; do { t = (uint32)((unsigned)buf[3]<<8 | buf[2]) << 16 | @@ -40,6 +42,7 @@ static void byteReverse(unsigned char *buf, unsigned longs){ buf += 4; } while (--longs); } + /* The four core functions - F1 is optimized somewhat */ /* #define F1(x, y, z) (x & y | ~x & z) */ @@ -57,7 +60,7 @@ static void byteReverse(unsigned char *buf, unsigned longs){ * reflect the addition of 16 longwords of new data. MD5Update blocks * the data and converts bytes into longwords for this routine. */ -static void MD5Transform(uint32 buf[4], const uint32 in[16]){ +void MD5Transform(uint32 buf[4], const uint32 in[16]) { register uint32 a, b, c, d; a = buf[0]; @@ -139,12 +142,16 @@ static void MD5Transform(uint32 buf[4], const uint32 in[16]){ buf[3] += d; } +} // namespace + +namespace base { + /* * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * initialization constants. */ -void MD5Init(MD5Context *pCtx){ - struct Context *ctx = (struct Context *)pCtx; +void MD5Init(MD5Context* context) { + struct Context *ctx = (struct Context *)context; ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; ctx->buf[2] = 0x98badcfe; @@ -157,8 +164,8 @@ void MD5Init(MD5Context *pCtx){ * Update context to reflect the concatenation of another buffer full * of bytes. */ -void MD5Update(MD5Context *pCtx, const void *inbuf, size_t len){ - struct Context *ctx = (struct Context *)pCtx; +void MD5Update(MD5Context* context, const void* inbuf, size_t len) { + struct Context *ctx = (struct Context *)context; const unsigned char* buf = (const unsigned char*)inbuf; uint32 t; @@ -207,8 +214,8 @@ void MD5Update(MD5Context *pCtx, const void *inbuf, size_t len){ * Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ -void MD5Final(MD5Digest* digest, MD5Context *pCtx){ - struct Context *ctx = (struct Context *)pCtx; +void MD5Final(MD5Digest* digest, MD5Context* context) { + struct Context *ctx = (struct Context *)context; unsigned count; unsigned char *p; @@ -248,7 +255,7 @@ void MD5Final(MD5Digest* digest, MD5Context *pCtx){ memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ } -std::string MD5DigestToBase16(const MD5Digest& digest){ +std::string MD5DigestToBase16(const MD5Digest& digest) { static char const zEncode[] = "0123456789abcdef"; std::string ret; @@ -275,3 +282,5 @@ std::string MD5String(const std::string& str) { MD5Sum(str.data(), str.length(), &digest); return MD5DigestToBase16(digest); } + +} // namespace base @@ -10,6 +10,8 @@ #include "base/base_api.h" +namespace base { + // MD5 stands for Message Digest algorithm 5. // MD5 is a robust hash function, designed for cyptography, but often used // for file checksums. The code is complex and slow, but has few @@ -64,4 +66,9 @@ BASE_API std::string MD5DigestToBase16(const MD5Digest& digest); // Returns the MD5 (in hexadecimal) of a string. BASE_API std::string MD5String(const std::string& str); +} // namespace base + +// TODO(tfarina): Fix third_party/hunspell then remove this hack. +using base::MD5Digest; + #endif // BASE_MD5_H_ diff --git a/chrome/browser/bookmarks/bookmark_codec.cc b/chrome/browser/bookmarks/bookmark_codec.cc index 50cd3fcc..23bd411 100644 --- a/chrome/browser/bookmarks/bookmark_codec.cc +++ b/chrome/browser/bookmarks/bookmark_codec.cc @@ -337,11 +337,11 @@ void BookmarkCodec::ReassignIDsHelper(BookmarkNode* node) { } void BookmarkCodec::UpdateChecksum(const std::string& str) { - MD5Update(&md5_context_, str.data(), str.length() * sizeof(char)); + base::MD5Update(&md5_context_, str.data(), str.length() * sizeof(char)); } void BookmarkCodec::UpdateChecksum(const string16& str) { - MD5Update(&md5_context_, str.data(), str.length() * sizeof(char16)); + base::MD5Update(&md5_context_, str.data(), str.length() * sizeof(char16)); } void BookmarkCodec::UpdateChecksumWithUrlNode(const std::string& id, @@ -362,11 +362,11 @@ void BookmarkCodec::UpdateChecksumWithFolderNode(const std::string& id, } void BookmarkCodec::InitializeChecksum() { - MD5Init(&md5_context_); + base::MD5Init(&md5_context_); } void BookmarkCodec::FinalizeChecksum() { - MD5Digest digest; - MD5Final(&digest, &md5_context_); - computed_checksum_ = MD5DigestToBase16(digest); + base::MD5Digest digest; + base::MD5Final(&digest, &md5_context_); + computed_checksum_ = base::MD5DigestToBase16(digest); } diff --git a/chrome/browser/bookmarks/bookmark_codec.h b/chrome/browser/bookmarks/bookmark_codec.h index fa2da5a..daa2e91 100644 --- a/chrome/browser/bookmarks/bookmark_codec.h +++ b/chrome/browser/bookmarks/bookmark_codec.h @@ -159,7 +159,7 @@ class BookmarkCodec { std::set<int64> ids_; // MD5 context used to compute MD5 hash of all bookmark data. - MD5Context md5_context_; + base::MD5Context md5_context_; // Checksums. std::string computed_checksum_; diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc index d0e3619..1c6f67f 100644 --- a/chrome/browser/history/top_sites.cc +++ b/chrome/browser/history/top_sites.cc @@ -766,7 +766,7 @@ std::string TopSites::GetURLString(const GURL& url) { std::string TopSites::GetURLHash(const GURL& url) { // We don't use canonical URLs here to be able to blacklist only one of // the two 'duplicate' sites, e.g. 'gmail.com' and 'mail.google.com'. - return MD5String(url.spec()); + return base::MD5String(url.spec()); } base::TimeDelta TopSites::GetUpdateDelay() { diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index 19d18084..e5fbe6f 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -1122,8 +1122,8 @@ MetricsService::LogRecallStatus MetricsService::RecallUnsentLogsHelper( list.GetSize() - kChecksumEntryCount) return MakeRecallStatusHistogram(LIST_SIZE_CORRUPTION); - MD5Context ctx; - MD5Init(&ctx); + base::MD5Context ctx; + base::MD5Init(&ctx); std::string encoded_log; std::string decoded_log; for (ListValue::const_iterator it = list.begin() + 1; @@ -1134,7 +1134,7 @@ MetricsService::LogRecallStatus MetricsService::RecallUnsentLogsHelper( return MakeRecallStatusHistogram(LOG_STRING_CORRUPTION); } - MD5Update(&ctx, encoded_log.data(), encoded_log.length()); + base::MD5Update(&ctx, encoded_log.data(), encoded_log.length()); if (!base::Base64Decode(encoded_log, &decoded_log)) { local_list->clear(); @@ -1144,8 +1144,8 @@ MetricsService::LogRecallStatus MetricsService::RecallUnsentLogsHelper( } // Verify checksum. - MD5Digest digest; - MD5Final(&digest, &ctx); + base::MD5Digest digest; + base::MD5Final(&digest, &ctx); std::string recovered_md5; // We store the hash at the end of the list. valid = (*(list.end() - 1))->GetAsString(&recovered_md5); @@ -1153,7 +1153,7 @@ MetricsService::LogRecallStatus MetricsService::RecallUnsentLogsHelper( local_list->clear(); return MakeRecallStatusHistogram(CHECKSUM_STRING_CORRUPTION); } - if (recovered_md5 != MD5DigestToBase16(digest)) { + if (recovered_md5 != base::MD5DigestToBase16(digest)) { local_list->clear(); return MakeRecallStatusHistogram(CHECKSUM_CORRUPTION); } @@ -1188,8 +1188,8 @@ void MetricsService::StoreUnsentLogsHelper( // Store size at the beginning of the list. list->Append(Value::CreateIntegerValue(local_list.size() - start)); - MD5Context ctx; - MD5Init(&ctx); + base::MD5Context ctx; + base::MD5Init(&ctx); std::string encoded_log; for (std::vector<std::string>::const_iterator it = local_list.begin() + start; it != local_list.end(); ++it) { @@ -1200,14 +1200,14 @@ void MetricsService::StoreUnsentLogsHelper( list->Clear(); return; } - MD5Update(&ctx, encoded_log.data(), encoded_log.length()); + base::MD5Update(&ctx, encoded_log.data(), encoded_log.length()); list->Append(Value::CreateStringValue(encoded_log)); } // Append hash to the end of the list. - MD5Digest digest; - MD5Final(&digest, &ctx); - list->Append(Value::CreateStringValue(MD5DigestToBase16(digest))); + base::MD5Digest digest; + base::MD5Final(&digest, &ctx); + list->Append(Value::CreateStringValue(base::MD5DigestToBase16(digest))); DCHECK(list->GetSize() >= 3); // Minimum of 3 elements (size, data, hash). MakeStoreStatusHistogram(STORE_SUCCESS); } diff --git a/chrome/browser/metrics/metrics_service_unittest.cc b/chrome/browser/metrics/metrics_service_unittest.cc index 9e7b463..2ddb2f8 100644 --- a/chrome/browser/metrics/metrics_service_unittest.cc +++ b/chrome/browser/metrics/metrics_service_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -76,7 +76,7 @@ TEST(MetricsServiceTest, SingleElementLogList) { ++it; (*it)->GetAsString(&str); // MD5 for encoded "Hello world!" string. - EXPECT_TRUE(MD5String(encoded) == str); + EXPECT_TRUE(base::MD5String(encoded) == str); ++it; EXPECT_TRUE(it == list.end()); // Reached end of list. diff --git a/chrome/browser/safe_browsing/malware_details_cache.cc b/chrome/browser/safe_browsing/malware_details_cache.cc index 72ba461..481b972 100644 --- a/chrome/browser/safe_browsing/malware_details_cache.cc +++ b/chrome/browser/safe_browsing/malware_details_cache.cc @@ -12,8 +12,8 @@ #include "base/string_util.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/safe_browsing/malware_details_cache.h" -#include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/safe_browsing/report.pb.h" +#include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "content/browser/browser_thread.h" #include "net/base/host_port_pair.h" #include "net/base/load_flags.h" @@ -186,9 +186,9 @@ void MalwareDetailsCacheCollector::ReadData( pb_response->set_body(data); } pb_response->set_bodylength(data.size()); - MD5Digest digest; - MD5Sum(data.c_str(), data.size(), &digest); - pb_response->set_bodydigest(MD5DigestToBase16(digest)); + base::MD5Digest digest; + base::MD5Sum(data.c_str(), data.size(), &digest); + pb_response->set_bodydigest(base::MD5DigestToBase16(digest)); } void MalwareDetailsCacheCollector::AdvanceEntry() { diff --git a/chrome/browser/safe_browsing/prefix_set.cc b/chrome/browser/safe_browsing/prefix_set.cc index c61cdad..13890a0 100644 --- a/chrome/browser/safe_browsing/prefix_set.cc +++ b/chrome/browser/safe_browsing/prefix_set.cc @@ -161,6 +161,7 @@ PrefixSet* PrefixSet::LoadFile(const FilePath& filter_name) { int64 size_64; if (!file_util::GetFileSize(filter_name, &size_64)) return NULL; + using base::MD5Digest; if (size_64 < static_cast<int64>(sizeof(FileHeader) + sizeof(MD5Digest))) return NULL; @@ -189,9 +190,9 @@ PrefixSet* PrefixSet::LoadFile(const FilePath& filter_name) { return NULL; // The file looks valid, start building the digest. - MD5Context context; - MD5Init(&context); - MD5Update(&context, &header, sizeof(header)); + base::MD5Context context; + base::MD5Init(&context); + base::MD5Update(&context, &header, sizeof(header)); // Read the index vector. Herb Sutter indicates that vectors are // guaranteed to be contiuguous, so reading to where element 0 lives @@ -200,19 +201,19 @@ PrefixSet* PrefixSet::LoadFile(const FilePath& filter_name) { read = fread(&(index[0]), sizeof(index[0]), index.size(), file.get()); if (read != index.size()) return NULL; - MD5Update(&context, &(index[0]), index_bytes); + base::MD5Update(&context, &(index[0]), index_bytes); // Read vector of deltas. deltas.resize(header.deltas_size); read = fread(&(deltas[0]), sizeof(deltas[0]), deltas.size(), file.get()); if (read != deltas.size()) return NULL; - MD5Update(&context, &(deltas[0]), deltas_bytes); + base::MD5Update(&context, &(deltas[0]), deltas_bytes); - MD5Digest calculated_digest; - MD5Final(&calculated_digest, &context); + base::MD5Digest calculated_digest; + base::MD5Final(&calculated_digest, &context); - MD5Digest file_digest; + base::MD5Digest file_digest; read = fread(&file_digest, sizeof(file_digest), 1, file.get()); if (read != 1) return NULL; @@ -242,15 +243,15 @@ bool PrefixSet::WriteFile(const FilePath& filter_name) const { if (!file.get()) return false; - MD5Context context; - MD5Init(&context); + base::MD5Context context; + base::MD5Init(&context); // TODO(shess): The I/O code in safe_browsing_store_file.cc would // sure be useful about now. size_t written = fwrite(&header, sizeof(header), 1, file.get()); if (written != 1) return false; - MD5Update(&context, &header, sizeof(header)); + base::MD5Update(&context, &header, sizeof(header)); // As for reads, the standard guarantees the ability to access the // contents of the vector by a pointer to an element. @@ -258,17 +259,17 @@ bool PrefixSet::WriteFile(const FilePath& filter_name) const { written = fwrite(&(index_[0]), sizeof(index_[0]), index_.size(), file.get()); if (written != index_.size()) return false; - MD5Update(&context, &(index_[0]), index_bytes); + base::MD5Update(&context, &(index_[0]), index_bytes); const size_t deltas_bytes = sizeof(deltas_[0]) * deltas_.size(); written = fwrite(&(deltas_[0]), sizeof(deltas_[0]), deltas_.size(), file.get()); if (written != deltas_.size()) return false; - MD5Update(&context, &(deltas_[0]), deltas_bytes); + base::MD5Update(&context, &(deltas_[0]), deltas_bytes); - MD5Digest digest; - MD5Final(&digest, &context); + base::MD5Digest digest; + base::MD5Final(&digest, &context); written = fwrite(&digest, sizeof(digest), 1, file.get()); if (written != 1) return false; diff --git a/chrome/browser/safe_browsing/prefix_set_unittest.cc b/chrome/browser/safe_browsing/prefix_set_unittest.cc index 62c0427..22d26d8 100644 --- a/chrome/browser/safe_browsing/prefix_set_unittest.cc +++ b/chrome/browser/safe_browsing/prefix_set_unittest.cc @@ -99,12 +99,13 @@ class PrefixSetTest : public PlatformTest { // Helper function to re-generated |fp|'s checksum to be correct for // the file's contents. |fp| should be opened in r+ mode. static void CleanChecksum(FILE* fp) { - MD5Context context; - MD5Init(&context); + base::MD5Context context; + base::MD5Init(&context); ASSERT_NE(-1, fseek(fp, 0, SEEK_END)); long file_size = ftell(fp); + using base::MD5Digest; size_t payload_size = static_cast<size_t>(file_size) - sizeof(MD5Digest); size_t digested_size = 0; ASSERT_NE(-1, fseek(fp, 0, SEEK_SET)); @@ -112,14 +113,14 @@ class PrefixSetTest : public PlatformTest { char buf[1024]; size_t nitems = std::min(payload_size - digested_size, sizeof(buf)); ASSERT_EQ(nitems, fread(buf, 1, nitems, fp)); - MD5Update(&context, &buf, nitems); + base::MD5Update(&context, &buf, nitems); digested_size += nitems; } ASSERT_EQ(digested_size, payload_size); ASSERT_EQ(static_cast<long>(digested_size), ftell(fp)); - MD5Digest new_digest; - MD5Final(&new_digest, &context); + base::MD5Digest new_digest; + base::MD5Final(&new_digest, &context); ASSERT_NE(-1, fseek(fp, digested_size, SEEK_SET)); ASSERT_EQ(1U, fwrite(&new_digest, sizeof(new_digest), 1, fp)); ASSERT_EQ(file_size, ftell(fp)); @@ -409,7 +410,7 @@ TEST_F(PrefixSetTest, CorruptionDigest) { int64 size_64; ASSERT_TRUE(file_util::GetFileSize(filename, &size_64)); file_util::ScopedFILE file(file_util::OpenFile(filename, "r+b")); - long digest_offset = static_cast<long>(size_64 - sizeof(MD5Digest)); + long digest_offset = static_cast<long>(size_64 - sizeof(base::MD5Digest)); ASSERT_NO_FATAL_FAILURE(IncrementIntAt(file.get(), digest_offset, 1)); file.reset(); scoped_ptr<safe_browsing::PrefixSet> diff --git a/chrome/browser/safe_browsing/safe_browsing_store_file.cc b/chrome/browser/safe_browsing/safe_browsing_store_file.cc index bfb6062..110fa54 100644 --- a/chrome/browser/safe_browsing/safe_browsing_store_file.cc +++ b/chrome/browser/safe_browsing/safe_browsing_store_file.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" #include "base/callback.h" -#include "base/metrics/histogram.h" #include "base/md5.h" +#include "base/metrics/histogram.h" namespace { @@ -53,13 +53,13 @@ bool FileSkip(size_t bytes, FILE* fp) { // input data into the checksum in |context|, if non-NULL. Return // true on success. template <class T> -bool ReadArray(T* ptr, size_t nmemb, FILE* fp, MD5Context* context) { +bool ReadArray(T* ptr, size_t nmemb, FILE* fp, base::MD5Context* context) { const size_t ret = fread(ptr, sizeof(T), nmemb, fp); if (ret != nmemb) return false; if (context) - MD5Update(context, ptr, sizeof(T) * nmemb); + base::MD5Update(context, ptr, sizeof(T) * nmemb); return true; } @@ -67,13 +67,14 @@ bool ReadArray(T* ptr, size_t nmemb, FILE* fp, MD5Context* context) { // output data into the checksum in |context|, if non-NULL. Return // true on success. template <class T> -bool WriteArray(const T* ptr, size_t nmemb, FILE* fp, MD5Context* context) { +bool WriteArray(const T* ptr, size_t nmemb, FILE* fp, + base::MD5Context* context) { const size_t ret = fwrite(ptr, sizeof(T), nmemb, fp); if (ret != nmemb) return false; if (context) - MD5Update(context, ptr, sizeof(T) * nmemb); + base::MD5Update(context, ptr, sizeof(T) * nmemb); return true; } @@ -82,8 +83,8 @@ bool WriteArray(const T* ptr, size_t nmemb, FILE* fp, MD5Context* context) { // |fp| and fold them into the checksum in |context|. Returns true on // success. template <class T> -bool ReadToVector(std::vector<T>* values, size_t count, - FILE* fp, MD5Context* context) { +bool ReadToVector(std::vector<T>* values, size_t count, FILE* fp, + base::MD5Context* context) { // Pointers into an empty vector may not be valid. if (!count) return true; @@ -107,7 +108,8 @@ bool ReadToVector(std::vector<T>* values, size_t count, // Write all of |values| to |fp|, and fold the data into the checksum // in |context|, if non-NULL. Returns true on succsess. template <class T> -bool WriteVector(const std::vector<T>& values, FILE* fp, MD5Context* context) { +bool WriteVector(const std::vector<T>& values, FILE* fp, + base::MD5Context* context) { // Pointers into empty vectors may not be valid. if (values.empty()) return true; @@ -120,8 +122,8 @@ bool WriteVector(const std::vector<T>& values, FILE* fp, MD5Context* context) { // Read an array of |count| integers and add them to |values|. // Returns true on success. -bool ReadToChunkSet(std::set<int32>* values, size_t count, - FILE* fp, MD5Context* context) { +bool ReadToChunkSet(std::set<int32>* values, size_t count, FILE* fp, + base::MD5Context* context) { if (!count) return true; @@ -135,8 +137,8 @@ bool ReadToChunkSet(std::set<int32>* values, size_t count, // Write the contents of |values| as an array of integers. Returns // true on success. -bool WriteChunkSet(const std::set<int32>& values, - FILE* fp, MD5Context* context) { +bool WriteChunkSet(const std::set<int32>& values, FILE* fp, + base::MD5Context* context) { if (values.empty()) return true; @@ -171,7 +173,7 @@ bool FileHeaderSanityCheck(const FilePath& filename, expected_size += header.sub_prefix_count * sizeof(SBSubPrefix); expected_size += header.add_hash_count * sizeof(SBAddFullHash); expected_size += header.sub_hash_count * sizeof(SBSubFullHash); - expected_size += sizeof(MD5Digest); + expected_size += sizeof(base::MD5Digest); if (size != expected_size) return false; @@ -183,7 +185,7 @@ bool FileHeaderSanityCheck(const FilePath& filename, bool ReadAndVerifyHeader(const FilePath& filename, FILE* fp, FileHeader* header, - MD5Context* context) { + base::MD5Context* context) { if (!ReadArray(header, 1, fp, context)) return false; if (header->magic != kFileMagic || header->version != kFileVersion) @@ -493,8 +495,8 @@ bool SafeBrowsingStoreFile::DoUpdate( if (!FileRewind(file_.get())) return OnCorruptDatabase(); - MD5Context context; - MD5Init(&context); + base::MD5Context context; + base::MD5Init(&context); // Read the file header and make sure it looks right. FileHeader header; @@ -521,11 +523,11 @@ bool SafeBrowsingStoreFile::DoUpdate( return OnCorruptDatabase(); // Calculate the digest to this point. - MD5Digest calculated_digest; - MD5Final(&calculated_digest, &context); + base::MD5Digest calculated_digest; + base::MD5Final(&calculated_digest, &context); // Read the stored checksum and verify it. - MD5Digest file_digest; + base::MD5Digest file_digest; if (!ReadArray(&file_digest, 1, file_.get(), NULL)) return OnCorruptDatabase(); @@ -612,8 +614,8 @@ bool SafeBrowsingStoreFile::DoUpdate( if (!FileRewind(new_file_.get())) return false; - MD5Context context; - MD5Init(&context); + base::MD5Context context; + base::MD5Init(&context); // Write a file header. FileHeader header; @@ -638,8 +640,8 @@ bool SafeBrowsingStoreFile::DoUpdate( return false; // Write the checksum at the end. - MD5Digest digest; - MD5Final(&digest, &context); + base::MD5Digest digest; + base::MD5Final(&digest, &context); if (!WriteArray(&digest, 1, new_file_.get(), NULL)) return false; diff --git a/chrome/browser/spellcheck_host_metrics.cc b/chrome/browser/spellcheck_host_metrics.cc index 220c42b..1e91e93 100644 --- a/chrome/browser/spellcheck_host_metrics.cc +++ b/chrome/browser/spellcheck_host_metrics.cc @@ -52,10 +52,10 @@ void SpellCheckHostMetrics::RecordCheckedWordStats(const string16& word, UMA_HISTOGRAM_PERCENTAGE("SpellCheck.MisspellRatio", percentage); // Collects actual number of checked words, excluding duplication. - MD5Digest digest; - MD5Sum(reinterpret_cast<const unsigned char*>(word.c_str()), + base::MD5Digest digest; + base::MD5Sum(reinterpret_cast<const unsigned char*>(word.c_str()), word.size() * sizeof(char16), &digest); - checked_word_hashes_.insert(MD5DigestToBase16(digest)); + checked_word_hashes_.insert(base::MD5DigestToBase16(digest)); RecordWordCounts(); } diff --git a/chrome/browser/sync/util/user_settings.cc b/chrome/browser/sync/util/user_settings.cc index b842c43..df8ab6b 100644 --- a/chrome/browser/sync/util/user_settings.cc +++ b/chrome/browser/sync/util/user_settings.cc @@ -272,7 +272,7 @@ const int32 kInvalidHash = 0xFFFFFFFF; // We use 10 bits of data from the MD5 digest as the hash. const int32 kHashMask = 0x3FF; -int32 GetHashFromDigest(MD5Digest& digest) { +int32 GetHashFromDigest(base::MD5Digest& digest) { int32 hash = 0; int32 mask = kHashMask; for (size_t i = 0; i < sizeof(digest.a); ++i) { @@ -355,12 +355,12 @@ void UserSettings::StoreHashedPassword(const string& email, base::RandBytes(binary_salt, sizeof(binary_salt)); const string salt = APEncode(string(binary_salt, sizeof(binary_salt))); - MD5Context md5_context; - MD5Init(&md5_context); - MD5Update(&md5_context, salt.data(), salt.size()); - MD5Update(&md5_context, password.data(), password.size()); - MD5Digest md5_digest; - MD5Final(&md5_digest, &md5_context); + base::MD5Context md5_context; + base::MD5Init(&md5_context); + base::MD5Update(&md5_context, salt.data(), salt.size()); + base::MD5Update(&md5_context, password.data(), password.size()); + base::MD5Digest md5_digest; + base::MD5Final(&md5_digest, &md5_context); ScopedDBHandle dbhandle(this); SQLTransaction transaction(dbhandle.get()); @@ -418,12 +418,12 @@ bool UserSettings::VerifyAgainstStoredHash(const string& email, CHECK(SQLITE_DONE == query_result); if (salt.empty() || hash == kInvalidHash) return false; - MD5Context md5_context; - MD5Init(&md5_context); - MD5Update(&md5_context, salt.data(), salt.size()); - MD5Update(&md5_context, password.data(), password.size()); - MD5Digest md5_digest; - MD5Final(&md5_digest, &md5_context); + base::MD5Context md5_context; + base::MD5Init(&md5_context); + base::MD5Update(&md5_context, salt.data(), salt.size()); + base::MD5Update(&md5_context, password.data(), password.size()); + base::MD5Digest md5_digest; + base::MD5Final(&md5_digest, &md5_context); return hash == GetHashFromDigest(md5_digest); } diff --git a/chrome/browser/ui/webui/ntp/most_visited_handler.cc b/chrome/browser/ui/webui/ntp/most_visited_handler.cc index 98446f2..73a1363 100644 --- a/chrome/browser/ui/webui/ntp/most_visited_handler.cc +++ b/chrome/browser/ui/webui/ntp/most_visited_handler.cc @@ -329,7 +329,7 @@ void MostVisitedHandler::BlacklistURL(const GURL& url) { } std::string MostVisitedHandler::GetDictionaryKeyForURL(const std::string& url) { - return MD5String(url); + return base::MD5String(url); } // static diff --git a/chrome/common/metrics_helpers.cc b/chrome/common/metrics_helpers.cc index 55c28bd..c7aef5b 100644 --- a/chrome/common/metrics_helpers.cc +++ b/chrome/common/metrics_helpers.cc @@ -11,15 +11,15 @@ #endif #include "base/base64.h" -#include "base/time.h" #include "base/basictypes.h" #include "base/file_util.h" #include "base/md5.h" #include "base/perftimer.h" #include "base/string_number_conversions.h" #include "base/sys_info.h" -#include "base/utf_string_conversions.h" #include "base/third_party/nspr/prtime.h" +#include "base/time.h" +#include "base/utf_string_conversions.h" #include "chrome/common/logging_chrome.h" #include "googleurl/src/gurl.h" #include "libxml/xmlwriter.h" @@ -175,12 +175,12 @@ int MetricsLogBase::GetElapsedSeconds() { } std::string MetricsLogBase::CreateHash(const std::string& value) { - MD5Context ctx; - MD5Init(&ctx); - MD5Update(&ctx, value.data(), value.length()); + base::MD5Context ctx; + base::MD5Init(&ctx); + base::MD5Update(&ctx, value.data(), value.length()); - MD5Digest digest; - MD5Final(&digest, &ctx); + base::MD5Digest digest; + base::MD5Final(&digest, &ctx); uint64 reverse_uint64; // UMA only uses first 8 chars of hash. We use the above uint64 instead diff --git a/chrome/common/visitedlink_common.cc b/chrome/common/visitedlink_common.cc index 92a6743..7fb254e 100644 --- a/chrome/common/visitedlink_common.cc +++ b/chrome/common/visitedlink_common.cc @@ -79,13 +79,13 @@ VisitedLinkCommon::Fingerprint VisitedLinkCommon::ComputeURLFingerprint( const uint8 salt[LINK_SALT_LENGTH]) { DCHECK(url_len > 0) << "Canonical URLs should not be empty"; - MD5Context ctx; - MD5Init(&ctx); - MD5Update(&ctx, salt, LINK_SALT_LENGTH * sizeof(uint8)); - MD5Update(&ctx, canonical_url, url_len * sizeof(char)); + base::MD5Context ctx; + base::MD5Init(&ctx); + base::MD5Update(&ctx, salt, LINK_SALT_LENGTH * sizeof(uint8)); + base::MD5Update(&ctx, canonical_url, url_len * sizeof(char)); - MD5Digest digest; - MD5Final(&digest, &ctx); + base::MD5Digest digest; + base::MD5Final(&digest, &ctx); // This is the same as "return *(Fingerprint*)&digest.a;" but if we do that // direct cast the alignment could be wrong, and we can't access a 64-bit int diff --git a/chrome/service/cloud_print/cloud_print_helpers.cc b/chrome/service/cloud_print/cloud_print_helpers.cc index f7db653..71bfea7 100644 --- a/chrome/service/cloud_print/cloud_print_helpers.cc +++ b/chrome/service/cloud_print/cloud_print_helpers.cc @@ -218,7 +218,7 @@ std::string CloudPrintHelpers::GenerateHashOfStringMap( values_list.append(it->first); values_list.append(it->second); } - return MD5String(values_list); + return base::MD5String(values_list); } void CloudPrintHelpers::GenerateMultipartPostDataForPrinterTags( @@ -251,7 +251,7 @@ void CloudPrintHelpers::GenerateMultipartPostDataForPrinterTags( AddMultipartValueForUpload(kPrinterTagValue, msg, mime_boundary, std::string(), post_data); } - std::string tags_hash = MD5String(tags_list); + std::string tags_hash = base::MD5String(tags_list); std::string tags_hash_msg(kTagsHashTagName); tags_hash_msg += "="; tags_hash_msg += tags_hash; diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc index 92250c8..7e6b3b1 100644 --- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc +++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc @@ -10,9 +10,9 @@ #include "base/file_util.h" #include "base/md5.h" #include "base/rand_util.h" -#include "base/stringprintf.h" #include "base/string_number_conversions.h" #include "base/string_split.h" +#include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/common/net/gaia/gaia_oauth_client.h" @@ -682,7 +682,7 @@ void CloudPrintProxyBackend::Core::OnReceivePrinterCaps( // later to check if the capabilities have changed CloudPrintHelpers::AddMultipartValueForUpload( kPrinterCapsHashValue, - MD5String(last_uploaded_printer_info_.printer_capabilities), + base::MD5String(last_uploaded_printer_info_.printer_capabilities), mime_boundary, std::string(), &post_data); GURL post_url = CloudPrintHelpers::GetUrlForPrinterRegistration( cloud_print_server_url_); diff --git a/chrome/service/cloud_print/print_system_cups.cc b/chrome/service/cloud_print/print_system_cups.cc index 22ebdfc..3387334 100644 --- a/chrome/service/cloud_print/print_system_cups.cc +++ b/chrome/service/cloud_print/print_system_cups.cc @@ -23,8 +23,8 @@ #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/task.h" -#include "base/values.h" #include "base/utf_string_conversions.h" +#include "base/values.h" #include "chrome/service/cloud_print/cloud_print_consts.h" #include "chrome/service/cloud_print/cloud_print_helpers.h" #include "googleurl/src/gurl.h" @@ -224,7 +224,7 @@ class PrintServerWatcherCUPS for (size_t i = 0; i < printers.size(); i++) to_hash += printers[i]; - return MD5String(to_hash); + return base::MD5String(to_hash); } scoped_refptr<PrintSystemCUPS> print_system_; @@ -329,7 +329,7 @@ class PrinterWatcherCUPS to_hash += caps.printer_defaults; to_hash += caps.defaults_mime_type; - return MD5String(to_hash); + return base::MD5String(to_hash); } std::string printer_name_; @@ -818,4 +818,3 @@ void PrintSystemCUPS::RunCapsCallback( } } // namespace cloud_print - diff --git a/chrome/service/cloud_print/printer_job_handler.cc b/chrome/service/cloud_print/printer_job_handler.cc index 6c4b50c..0d883d8 100644 --- a/chrome/service/cloud_print/printer_job_handler.cc +++ b/chrome/service/cloud_print/printer_job_handler.cc @@ -194,7 +194,8 @@ void PrinterJobHandler::OnReceivePrinterCaps( CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary); if (succeeded) { - std::string caps_hash = MD5String(caps_and_defaults.printer_capabilities); + std::string caps_hash = + base::MD5String(caps_and_defaults.printer_capabilities); if (caps_hash != printer_info_cloud_.caps_hash) { // Hashes don't match, we need to upload new capabilities (the defaults // go for free along with the capabilities) diff --git a/media/test/ffmpeg_tests/ffmpeg_tests.cc b/media/test/ffmpeg_tests/ffmpeg_tests.cc index 4bdc6ba..8c0bc7c 100644 --- a/media/test/ffmpeg_tests/ffmpeg_tests.cc +++ b/media/test/ffmpeg_tests/ffmpeg_tests.cc @@ -102,8 +102,8 @@ int main(int argc, const char** argv) { unsigned int hash_value = 5381u; // Seed for DJB2. bool hash_djb2 = false; - MD5Context ctx; // Intermediate MD5 data: do not use - MD5Init(&ctx); + base::MD5Context ctx; // Intermediate MD5 data: do not use + base::MD5Init(&ctx); bool hash_md5 = false; std::ostream* log_out = &std::cout; @@ -316,9 +316,8 @@ int main(int argc, const char** argv) { if (hash_djb2) { hash_value = DJB2Hash(u8_samples, size_out, hash_value); } - if (hash_md5) { - MD5Update(&ctx, u8_samples, size_out); - } + if (hash_md5) + base::MD5Update(&ctx, u8_samples, size_out); } } else if (target_codec == AVMEDIA_TYPE_VIDEO) { int got_picture = 0; @@ -378,8 +377,8 @@ int main(int argc, const char** argv) { } if (hash_md5) { for (size_t i = 0; i < copy_lines; ++i) { - MD5Update(&ctx, reinterpret_cast<const uint8*>(source), - bytes_per_line); + base::MD5Update(&ctx, reinterpret_cast<const uint8*>(source), + bytes_per_line); source += source_stride; } } @@ -482,9 +481,9 @@ int main(int argc, const char** argv) { << " " << in_path.value() << std::endl; } if (hash_md5) { - MD5Digest digest; // The result of the computation. - MD5Final(&digest, &ctx); - *log_out << " MD5 Hash: " << MD5DigestToBase16(digest) + base::MD5Digest digest; // The result of the computation. + base::MD5Final(&digest, &ctx); + *log_out << " MD5 Hash: " << base::MD5DigestToBase16(digest) << " " << in_path.value() << std::endl; } #endif // SHOW_VERBOSE diff --git a/media/tools/media_bench/media_bench.cc b/media/tools/media_bench/media_bench.cc index 1bf45bc..1d3872a 100644 --- a/media/tools/media_bench/media_bench.cc +++ b/media/tools/media_bench/media_bench.cc @@ -200,12 +200,11 @@ int main(int argc, const char** argv) { hash_djb2 = true; } - MD5Context ctx; // Intermediate MD5 data: do not use - MD5Init(&ctx); + base::MD5Context ctx; // Intermediate MD5 data: do not use + base::MD5Init(&ctx); bool hash_md5 = false; - if (cmd_line->HasSwitch(switches::kMd5)) { + if (cmd_line->HasSwitch(switches::kMd5)) hash_md5 = true; - } int skip = 0; if (cmd_line->HasSwitch(switches::kSkip)) { @@ -427,9 +426,8 @@ int main(int argc, const char** argv) { if (hash_djb2) { hash_value = DJB2Hash(u8_samples, size_out, hash_value); } - if (hash_md5) { - MD5Update(&ctx, u8_samples, size_out); - } + if (hash_md5) + base::MD5Update(&ctx, u8_samples, size_out); } } else if (target_codec == AVMEDIA_TYPE_VIDEO) { int got_picture = 0; @@ -489,8 +487,8 @@ int main(int argc, const char** argv) { } if (hash_md5) { for (size_t i = 0; i < copy_lines; ++i) { - MD5Update(&ctx, reinterpret_cast<const uint8*>(source), - bytes_per_line); + base::MD5Update(&ctx, reinterpret_cast<const uint8*>(source), + bytes_per_line); source += source_stride; } } @@ -575,9 +573,9 @@ int main(int argc, const char** argv) { << " " << in_path.value() << std::endl; } if (hash_md5) { - MD5Digest digest; // The result of the computation. - MD5Final(&digest, &ctx); - *log_out << " MD5 Hash: " << MD5DigestToBase16(digest) + base::MD5Digest digest; // The result of the computation. + base::MD5Final(&digest, &ctx); + *log_out << " MD5 Hash: " << base::MD5DigestToBase16(digest) << " " << in_path.value() << std::endl; } #if defined(ENABLE_WINDOWS_EXCEPTIONS) diff --git a/net/http/http_auth_handler_digest.cc b/net/http/http_auth_handler_digest.cc index 28d2f58..da7a601 100644 --- a/net/http/http_auth_handler_digest.cc +++ b/net/http/http_auth_handler_digest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -321,21 +321,21 @@ std::string HttpAuthHandlerDigest::AssembleResponseDigest( const std::string& nc) const { // ha1 = MD5(A1) // TODO(eroman): is this the right encoding? - std::string ha1 = MD5String(UTF16ToUTF8(username) + ":" + realm_ + ":" + - UTF16ToUTF8(password)); + std::string ha1 = base::MD5String(UTF16ToUTF8(username) + ":" + realm_ + ":" + + UTF16ToUTF8(password)); if (algorithm_ == HttpAuthHandlerDigest::ALGORITHM_MD5_SESS) - ha1 = MD5String(ha1 + ":" + nonce_ + ":" + cnonce); + ha1 = base::MD5String(ha1 + ":" + nonce_ + ":" + cnonce); // ha2 = MD5(A2) // TODO(eroman): need to add MD5(req-entity-body) for qop=auth-int. - std::string ha2 = MD5String(method + ":" + path); + std::string ha2 = base::MD5String(method + ":" + path); std::string nc_part; if (qop_ != HttpAuthHandlerDigest::QOP_UNSPECIFIED) { nc_part = nc + ":" + cnonce + ":" + QopToString(qop_) + ":"; } - return MD5String(ha1 + ":" + nonce_ + ":" + nc_part + ha2); + return base::MD5String(ha1 + ":" + nonce_ + ":" + nc_part + ha2); } std::string HttpAuthHandlerDigest::AssembleCredentials( diff --git a/net/http/http_auth_handler_ntlm_portable.cc b/net/http/http_auth_handler_ntlm_portable.cc index fac37c8..92b3e5b 100644 --- a/net/http/http_auth_handler_ntlm_portable.cc +++ b/net/http/http_auth_handler_ntlm_portable.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -555,7 +555,7 @@ static int GenerateType3Msg(const string16& domain, uint8 ntlm_hash[NTLM_HASH_LEN]; if (msg.flags & NTLM_NegotiateNTLM2Key) { // compute NTLM2 session response - MD5Digest session_hash; + base::MD5Digest session_hash; uint8 temp[16]; memcpy(lm_resp, rand_8_bytes, 8); @@ -563,7 +563,7 @@ static int GenerateType3Msg(const string16& domain, memcpy(temp, msg.challenge, 8); memcpy(temp + 8, lm_resp, 8); - MD5Sum(temp, 16, &session_hash); + base::MD5Sum(temp, 16, &session_hash); NTLM_Hash(password, ntlm_hash); LM_Response(ntlm_hash, session_hash.a, ntlm_resp); diff --git a/net/http/http_vary_data.cc b/net/http/http_vary_data.cc index 09aab9d..cb41a36 100644 --- a/net/http/http_vary_data.cc +++ b/net/http/http_vary_data.cc @@ -20,8 +20,8 @@ HttpVaryData::HttpVaryData() : is_valid_(false) { bool HttpVaryData::Init(const HttpRequestInfo& request_info, const HttpResponseHeaders& response_headers) { - MD5Context ctx; - MD5Init(&ctx); + base::MD5Context ctx; + base::MD5Init(&ctx); is_valid_ = false; bool processed_header = false; @@ -60,7 +60,7 @@ bool HttpVaryData::Init(const HttpRequestInfo& request_info, if (!processed_header) return false; - MD5Final(&request_digest_, &ctx); + base::MD5Final(&request_digest_, &ctx); return is_valid_ = true; } @@ -111,7 +111,7 @@ std::string HttpVaryData::GetRequestValue( // static void HttpVaryData::AddField(const HttpRequestInfo& request_info, const std::string& request_header, - MD5Context* ctx) { + base::MD5Context* ctx) { std::string request_value = GetRequestValue(request_info, request_header); // Append a character that cannot appear in the request header line so that we @@ -120,7 +120,7 @@ void HttpVaryData::AddField(const HttpRequestInfo& request_info, // For example, "foo: 12\nbar: 3" looks like "foo: 1\nbar: 23" otherwise. request_value.append(1, '\n'); - MD5Update(ctx, request_value.data(), request_value.size()); + base::MD5Update(ctx, request_value.data(), request_value.size()); } } // namespace net diff --git a/net/http/http_vary_data.h b/net/http/http_vary_data.h index 876d867..5bc2c70 100644 --- a/net/http/http_vary_data.h +++ b/net/http/http_vary_data.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef NET_HTTP_HTTP_VARY_DATA_H__ -#define NET_HTTP_HTTP_VARY_DATA_H__ +#ifndef NET_HTTP_HTTP_VARY_DATA_H_ +#define NET_HTTP_HTTP_VARY_DATA_H_ #pragma once #include "base/md5.h" @@ -72,10 +72,10 @@ class NET_TEST HttpVaryData { // Append to the MD5 context for the given request header. static void AddField(const HttpRequestInfo& request_info, const std::string& request_header, - MD5Context* context); + base::MD5Context* context); // A digested version of the request headers corresponding to the Vary header. - MD5Digest request_digest_; + base::MD5Digest request_digest_; // True when request_digest_ contains meaningful data. bool is_valid_; @@ -83,4 +83,4 @@ class NET_TEST HttpVaryData { } // namespace net -#endif // NET_HTTP_HTTP_VARY_DATA_H__ +#endif // NET_HTTP_HTTP_VARY_DATA_H_ diff --git a/net/server/http_server.cc b/net/server/http_server.cc index 9c18490..061731a 100644 --- a/net/server/http_server.cc +++ b/net/server/http_server.cc @@ -85,8 +85,8 @@ void HttpServer::AcceptWebSocket( memcpy(data + 4, &fp2, 4); memcpy(data + 8, &request.data[0], 8); - MD5Digest digest; - MD5Sum(data, 16, &digest); + base::MD5Digest digest; + base::MD5Sum(data, 16, &digest); std::string origin = GetHeaderValue(request, "Origin"); std::string host = GetHeaderValue(request, "Host"); diff --git a/net/websockets/websocket_handshake.cc b/net/websockets/websocket_handshake.cc index 07c7a85..789c6df 100644 --- a/net/websockets/websocket_handshake.cc +++ b/net/websockets/websocket_handshake.cc @@ -260,8 +260,8 @@ void WebSocketHandshake::Parameter::GetExpectedResponse(uint8 *expected) const { SetChallengeNumber(&challenge[0], number_1_); SetChallengeNumber(&challenge[4], number_2_); memcpy(&challenge[8], key_3_.data(), kKey3Size); - MD5Digest digest; - MD5Sum(challenge, kExpectedResponseSize, &digest); + base::MD5Digest digest; + base::MD5Sum(challenge, kExpectedResponseSize, &digest); memcpy(expected, digest.a, kExpectedResponseSize); } diff --git a/net/websockets/websocket_handshake_handler.cc b/net/websockets/websocket_handshake_handler.cc index 4a424ca..398e084 100644 --- a/net/websockets/websocket_handshake_handler.cc +++ b/net/websockets/websocket_handshake_handler.cc @@ -435,8 +435,8 @@ bool WebSocketHandshakeResponseHandler::ParseResponseInfo( response_message += "\r\n"; if (protocol_version_ < kMinVersionOfHybiNewHandshake) { - MD5Digest digest; - MD5Sum(challenge.data(), challenge.size(), &digest); + base::MD5Digest digest; + base::MD5Sum(challenge.data(), challenge.size(), &digest); const char* digest_data = reinterpret_cast<char*>(digest.a); response_message.append(digest_data, sizeof(digest.a)); @@ -490,8 +490,8 @@ bool WebSocketHandshakeResponseHandler::ParseResponseHeaderBlock( response_message += "\r\n"; if (protocol_version_ < kMinVersionOfHybiNewHandshake) { - MD5Digest digest; - MD5Sum(challenge.data(), challenge.size(), &digest); + base::MD5Digest digest; + base::MD5Sum(challenge.data(), challenge.size(), &digest); const char* digest_data = reinterpret_cast<char*>(digest.a); response_message.append(digest_data, sizeof(digest.a)); diff --git a/printing/image.cc b/printing/image.cc index 062ac89..f9b177b 100644 --- a/printing/image.cc +++ b/printing/image.cc @@ -50,8 +50,8 @@ Image::Image(const Image& image) Image::~Image() {} std::string Image::checksum() const { - MD5Digest digest; - MD5Sum(&data_[0], data_.size(), &digest); + base::MD5Digest digest; + base::MD5Sum(&data_[0], data_.size(), &digest); return base::HexEncode(&digest, sizeof(digest)); } |