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

Side by Side Diff: trunk/src/sync/util/nigori.cc

Issue 101113004: Revert 239759 "The comment in base64.h implies that base::Base64..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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 | « trunk/src/sync/util/cryptographer.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) 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return false; 143 return false;
144 144
145 std::vector<unsigned char> hash(kHashSize); 145 std::vector<unsigned char> hash(kHashSize);
146 if (!hmac.Sign(ciphertext, &hash[0], hash.size())) 146 if (!hmac.Sign(ciphertext, &hash[0], hash.size()))
147 return false; 147 return false;
148 148
149 std::string output; 149 std::string output;
150 output.assign(ciphertext); 150 output.assign(ciphertext);
151 output.append(hash.begin(), hash.end()); 151 output.append(hash.begin(), hash.end());
152 152
153 Base64Encode(output, permuted); 153 return Base64Encode(output, permuted);
154 return true;
155 } 154 }
156 155
157 // Enc[Kenc,Kmac](value) 156 // Enc[Kenc,Kmac](value)
158 bool Nigori::Encrypt(const std::string& value, std::string* encrypted) const { 157 bool Nigori::Encrypt(const std::string& value, std::string* encrypted) const {
159 if (0U >= value.size()) 158 if (0U >= value.size())
160 return false; 159 return false;
161 160
162 std::string iv; 161 std::string iv;
163 crypto::RandBytes(WriteInto(&iv, kIvSize + 1), kIvSize); 162 crypto::RandBytes(WriteInto(&iv, kIvSize + 1), kIvSize);
164 163
(...skipping 15 matching lines...) Expand all
180 179
181 std::vector<unsigned char> hash(kHashSize); 180 std::vector<unsigned char> hash(kHashSize);
182 if (!hmac.Sign(ciphertext, &hash[0], hash.size())) 181 if (!hmac.Sign(ciphertext, &hash[0], hash.size()))
183 return false; 182 return false;
184 183
185 std::string output; 184 std::string output;
186 output.assign(iv); 185 output.assign(iv);
187 output.append(ciphertext); 186 output.append(ciphertext);
188 output.append(hash.begin(), hash.end()); 187 output.append(hash.begin(), hash.end());
189 188
190 Base64Encode(output, encrypted); 189 return Base64Encode(output, encrypted);
191 return true;
192 } 190 }
193 191
194 bool Nigori::Decrypt(const std::string& encrypted, std::string* value) const { 192 bool Nigori::Decrypt(const std::string& encrypted, std::string* value) const {
195 std::string input; 193 std::string input;
196 if (!Base64Decode(encrypted, &input)) 194 if (!Base64Decode(encrypted, &input))
197 return false; 195 return false;
198 196
199 if (input.size() < kIvSize * 2 + kHashSize) 197 if (input.size() < kIvSize * 2 + kHashSize)
200 return false; 198 return false;
201 199
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 DCHECK(user_key); 239 DCHECK(user_key);
242 DCHECK(encryption_key); 240 DCHECK(encryption_key);
243 DCHECK(mac_key); 241 DCHECK(mac_key);
244 242
245 return user_key_->GetRawKey(user_key) && 243 return user_key_->GetRawKey(user_key) &&
246 encryption_key_->GetRawKey(encryption_key) && 244 encryption_key_->GetRawKey(encryption_key) &&
247 mac_key_->GetRawKey(mac_key); 245 mac_key_->GetRawKey(mac_key);
248 } 246 }
249 247
250 } // namespace syncer 248 } // namespace syncer
OLDNEW
« no previous file with comments | « trunk/src/sync/util/cryptographer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698