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 <sstream> | 7 #include <sstream> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 Base64Encode(output, permuted); | 153 Base64Encode(output, permuted); |
154 return true; | 154 return true; |
155 } | 155 } |
156 | 156 |
157 // Enc[Kenc,Kmac](value) | 157 // Enc[Kenc,Kmac](value) |
158 bool Nigori::Encrypt(const std::string& value, std::string* encrypted) const { | 158 bool Nigori::Encrypt(const std::string& value, std::string* encrypted) const { |
159 if (0U >= value.size()) | 159 if (0U >= value.size()) |
160 return false; | 160 return false; |
161 | 161 |
162 std::string iv; | 162 std::string iv; |
163 crypto::RandBytes(WriteInto(&iv, kIvSize + 1), kIvSize); | 163 crypto::RandBytes(base::WriteInto(&iv, kIvSize + 1), kIvSize); |
164 | 164 |
165 Encryptor encryptor; | 165 Encryptor encryptor; |
166 if (!encryptor.Init(encryption_key_.get(), Encryptor::CBC, iv)) | 166 if (!encryptor.Init(encryption_key_.get(), Encryptor::CBC, iv)) |
167 return false; | 167 return false; |
168 | 168 |
169 std::string ciphertext; | 169 std::string ciphertext; |
170 if (!encryptor.Encrypt(value, &ciphertext)) | 170 if (!encryptor.Encrypt(value, &ciphertext)) |
171 return false; | 171 return false; |
172 | 172 |
173 std::string raw_mac_key; | 173 std::string raw_mac_key; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 DCHECK(user_key); | 241 DCHECK(user_key); |
242 DCHECK(encryption_key); | 242 DCHECK(encryption_key); |
243 DCHECK(mac_key); | 243 DCHECK(mac_key); |
244 | 244 |
245 return user_key_->GetRawKey(user_key) && | 245 return user_key_->GetRawKey(user_key) && |
246 encryption_key_->GetRawKey(encryption_key) && | 246 encryption_key_->GetRawKey(encryption_key) && |
247 mac_key_->GetRawKey(mac_key); | 247 mac_key_->GetRawKey(mac_key); |
248 } | 248 } |
249 | 249 |
250 } // namespace syncer | 250 } // namespace syncer |
OLD | NEW |