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

Unified Diff: chrome/browser/sync/util/user_settings.cc

Issue 6873156: Move crypto_helpers from sync to base (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Follow bbretw review Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/util/crypto_helpers_unittest.cc ('k') | chrome/browser/sync/util/user_settings_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/util/user_settings.cc
diff --git a/chrome/browser/sync/util/user_settings.cc b/chrome/browser/sync/util/user_settings.cc
index d49a071050f9806c18863b9cee38a64552479c92..b842c43bf3d0eca98a817f177244a5a58da03eab 100644
--- a/chrome/browser/sync/util/user_settings.cc
+++ b/chrome/browser/sync/util/user_settings.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.
//
@@ -18,10 +18,12 @@
#include <vector>
#include "base/file_util.h"
+#include "base/md5.h"
+#include "base/rand_util.h"
#include "base/string_util.h"
#include "chrome/browser/sync/syncable/directory_manager.h" // For migration.
-#include "chrome/browser/sync/util/crypto_helpers.h"
#include "chrome/browser/sync/util/data_encryption.h"
+#include "chrome/common/random.h"
#include "chrome/common/sqlite_utils.h"
using std::numeric_limits;
@@ -166,7 +168,7 @@ static void MakeClientIDTable(sqlite3* const dbhandle) {
SQLStatement statement;
statement.prepare(dbhandle,
"INSERT INTO client_id values ( ? )");
- statement.bind_string(0, Generate128BitRandomHexString());
+ statement.bind_string(0, Generate128BitRandomBase64String());
if (SQLITE_DONE != statement.step()) {
LOG(FATAL) << "INSERT INTO client_id\n" << sqlite3_errmsg(dbhandle);
}
@@ -270,13 +272,12 @@ const int32 kInvalidHash = 0xFFFFFFFF;
// We use 10 bits of data from the MD5 digest as the hash.
const int32 kHashMask = 0x3FF;
-int32 GetHashFromDigest(const vector<uint8>& digest) {
+int32 GetHashFromDigest(MD5Digest& digest) {
int32 hash = 0;
int32 mask = kHashMask;
- for (vector<uint8>::const_iterator i = digest.begin(); i != digest.end();
- ++i) {
+ for (size_t i = 0; i < sizeof(digest.a); ++i) {
hash = hash << 8;
- hash = hash | (*i & kHashMask);
+ hash = hash | (digest.a[i] & kHashMask);
mask = mask >> 8;
if (0 == mask)
break;
@@ -351,12 +352,16 @@ void UserSettings::StoreHashedPassword(const string& email,
const string& password) {
// Save one-way hashed password:
char binary_salt[kSaltSize];
- GetRandomBytes(binary_salt, sizeof(binary_salt));
+ base::RandBytes(binary_salt, sizeof(binary_salt));
const string salt = APEncode(string(binary_salt, sizeof(binary_salt)));
- MD5Calculator md5;
- md5.AddData(salt.data(), salt.size());
- md5.AddData(password.data(), password.size());
+ 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);
+
ScopedDBHandle dbhandle(this);
SQLTransaction transaction(dbhandle.get());
transaction.BeginExclusive();
@@ -367,7 +372,7 @@ void UserSettings::StoreHashedPassword(const string& email,
" values ( ?, ?, ? )");
statement.bind_string(0, email);
statement.bind_string(1, PASSWORD_HASH);
- statement.bind_int(2, GetHashFromDigest(md5.GetDigest()));
+ statement.bind_int(2, GetHashFromDigest(md5_digest));
if (SQLITE_DONE != statement.step()) {
LOG(FATAL) << sqlite3_errmsg(dbhandle.get());
}
@@ -413,10 +418,13 @@ bool UserSettings::VerifyAgainstStoredHash(const string& email,
CHECK(SQLITE_DONE == query_result);
if (salt.empty() || hash == kInvalidHash)
return false;
- MD5Calculator md5;
- md5.AddData(salt.data(), salt.size());
- md5.AddData(password.data(), password.size());
- return hash == GetHashFromDigest(md5.GetDigest());
+ 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);
+ return hash == GetHashFromDigest(md5_digest);
}
void UserSettings::SwitchUser(const string& username) {
« no previous file with comments | « chrome/browser/sync/util/crypto_helpers_unittest.cc ('k') | chrome/browser/sync/util/user_settings_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698