OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/util/nigori.h" | 5 #include "chrome/browser/sync/util/nigori.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <winsock2.h> // for htonl | 8 #include <winsock2.h> // for htonl |
9 #else | 9 #else |
10 #include <arpa/inet.h> | 10 #include <arpa/inet.h> |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 std::string GenerateRandomString(size_t size) { | 161 std::string GenerateRandomString(size_t size) { |
162 // TODO(albertb): Use a secure random function. | 162 // TODO(albertb): Use a secure random function. |
163 std::string random(size, 0); | 163 std::string random(size, 0); |
164 for (size_t i = 0; i < size; ++i) | 164 for (size_t i = 0; i < size; ++i) |
165 random[i] = RandInt(0, 0xff); | 165 random[i] = RandInt(0, 0xff); |
166 return random; | 166 return random; |
167 } | 167 } |
168 | 168 |
169 // Enc[Kenc,Kmac](value) | 169 // Enc[Kenc,Kmac](value) |
170 bool Nigori::Encrypt(const std::string& value, std::string* encrypted) const { | 170 bool Nigori::Encrypt(const std::string& value, std::string* encrypted) const { |
171 DCHECK_LT(0U, value.size()); | 171 if (0U >= value.size()) |
| 172 return false; |
172 | 173 |
173 std::string iv = GenerateRandomString(kIvSize); | 174 std::string iv = GenerateRandomString(kIvSize); |
174 | 175 |
175 Encryptor encryptor; | 176 Encryptor encryptor; |
176 if (!encryptor.Init(encryption_key_.get(), Encryptor::CBC, iv)) | 177 if (!encryptor.Init(encryption_key_.get(), Encryptor::CBC, iv)) |
177 return false; | 178 return false; |
178 | 179 |
179 std::string ciphertext; | 180 std::string ciphertext; |
180 if (!encryptor.Encrypt(value, &ciphertext)) | 181 if (!encryptor.Encrypt(value, &ciphertext)) |
181 return false; | 182 return false; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 DCHECK(user_key); | 252 DCHECK(user_key); |
252 DCHECK(encryption_key); | 253 DCHECK(encryption_key); |
253 DCHECK(mac_key); | 254 DCHECK(mac_key); |
254 | 255 |
255 return user_key_->GetRawKey(user_key) && | 256 return user_key_->GetRawKey(user_key) && |
256 encryption_key_->GetRawKey(encryption_key) && | 257 encryption_key_->GetRawKey(encryption_key) && |
257 mac_key_->GetRawKey(mac_key); | 258 mac_key_->GetRawKey(mac_key); |
258 } | 259 } |
259 | 260 |
260 } // namespace browser_sync | 261 } // namespace browser_sync |
OLD | NEW |