| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/util/nigori.h" | 5 #include "sync/util/nigori.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 Nigori::~Nigori() { | 67 Nigori::~Nigori() { |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool Nigori::InitByDerivation(const std::string& hostname, | 70 bool Nigori::InitByDerivation(const std::string& hostname, |
| 71 const std::string& username, | 71 const std::string& username, |
| 72 const std::string& password) { | 72 const std::string& password) { |
| 73 NigoriStream salt_password; | 73 NigoriStream salt_password; |
| 74 salt_password << username << hostname; | 74 salt_password << username << hostname; |
| 75 | 75 |
| 76 // Suser = PBKDF2(Username || Servername, "saltsalt", Nsalt, 8) | 76 // Suser = PBKDF2(Username || Servername, "saltsalt", Nsalt, 8) |
| 77 scoped_ptr<SymmetricKey> user_salt(SymmetricKey::DeriveKeyFromPassword( | 77 std::unique_ptr<SymmetricKey> user_salt(SymmetricKey::DeriveKeyFromPassword( |
| 78 SymmetricKey::HMAC_SHA1, salt_password.str(), | 78 SymmetricKey::HMAC_SHA1, salt_password.str(), kSaltSalt, kSaltIterations, |
| 79 kSaltSalt, | |
| 80 kSaltIterations, | |
| 81 kSaltKeySizeInBits)); | 79 kSaltKeySizeInBits)); |
| 82 DCHECK(user_salt.get()); | 80 DCHECK(user_salt.get()); |
| 83 | 81 |
| 84 std::string raw_user_salt; | 82 std::string raw_user_salt; |
| 85 if (!user_salt->GetRawKey(&raw_user_salt)) | 83 if (!user_salt->GetRawKey(&raw_user_salt)) |
| 86 return false; | 84 return false; |
| 87 | 85 |
| 88 // Kuser = PBKDF2(P, Suser, Nuser, 16) | 86 // Kuser = PBKDF2(P, Suser, Nuser, 16) |
| 89 user_key_.reset(SymmetricKey::DeriveKeyFromPassword(SymmetricKey::AES, | 87 user_key_.reset(SymmetricKey::DeriveKeyFromPassword(SymmetricKey::AES, |
| 90 password, raw_user_salt, kUserIterations, kDerivedKeySizeInBits)); | 88 password, raw_user_salt, kUserIterations, kDerivedKeySizeInBits)); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 DCHECK(user_key); | 242 DCHECK(user_key); |
| 245 DCHECK(encryption_key); | 243 DCHECK(encryption_key); |
| 246 DCHECK(mac_key); | 244 DCHECK(mac_key); |
| 247 | 245 |
| 248 return user_key_->GetRawKey(user_key) && | 246 return user_key_->GetRawKey(user_key) && |
| 249 encryption_key_->GetRawKey(encryption_key) && | 247 encryption_key_->GetRawKey(encryption_key) && |
| 250 mac_key_->GetRawKey(mac_key); | 248 mac_key_->GetRawKey(mac_key); |
| 251 } | 249 } |
| 252 | 250 |
| 253 } // namespace syncer | 251 } // namespace syncer |
| OLD | NEW |