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

Side by Side Diff: chrome/browser/sync/util/nigori.cc

Issue 7108067: [Sync] Ensure cryptographer ready before encrypting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/util/cryptographer_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « chrome/browser/sync/util/cryptographer_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698