Index: components/sync/base/nigori.cc |
diff --git a/components/sync/base/nigori.cc b/components/sync/base/nigori.cc |
index 03c61b23472a34410579a40e987186db3bcde1d8..ef9f7d6eeb728e4380c1ae122803f279163ad9a9 100644 |
--- a/components/sync/base/nigori.cc |
+++ b/components/sync/base/nigori.cc |
@@ -79,6 +79,11 @@ bool Nigori::InitByDerivation(const std::string& hostname, |
if (!user_salt->GetRawKey(&raw_user_salt)) |
return false; |
+ // Kuser = PBKDF2(P, Suser, Nuser, 16) |
+ user_key_ = SymmetricKey::DeriveKeyFromPassword( |
+ SymmetricKey::AES, password, raw_user_salt, kUserIterations, |
+ kDerivedKeySizeInBits); |
pavely
2017/04/10 21:27:29
Could you keep DCHECK and return value check for I
Patrick Noland
2017/04/10 23:43:06
Done.
|
+ |
// Kenc = PBKDF2(P, Suser, Nenc, 16) |
encryption_key_ = SymmetricKey::DeriveKeyFromPassword( |
SymmetricKey::AES, password, raw_user_salt, kEncryptionIterations, |
@@ -94,8 +99,11 @@ bool Nigori::InitByDerivation(const std::string& hostname, |
return encryption_key_ && mac_key_; |
} |
-bool Nigori::InitByImport(const std::string& encryption_key, |
+bool Nigori::InitByImport(const std::string& user_key, |
+ const std::string& encryption_key, |
const std::string& mac_key) { |
+ user_key_ = SymmetricKey::Import(SymmetricKey::AES, user_key); |
pavely
2017/04/10 21:27:29
Could you add a comment here or in nigori.h explai
Patrick Noland
2017/04/10 23:43:06
Done.
|
+ |
encryption_key_ = SymmetricKey::Import(SymmetricKey::AES, encryption_key); |
DCHECK(encryption_key_); |
@@ -223,11 +231,14 @@ bool Nigori::Decrypt(const std::string& encrypted, std::string* value) const { |
return true; |
} |
-bool Nigori::ExportKeys(std::string* encryption_key, |
+bool Nigori::ExportKeys(std::string* user_key, |
+ std::string* encryption_key, |
std::string* mac_key) const { |
DCHECK(encryption_key); |
DCHECK(mac_key); |
+ user_key_->GetRawKey(user_key); |
+ |
return encryption_key_->GetRawKey(encryption_key) && |
mac_key_->GetRawKey(mac_key); |
} |