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

Side by Side Diff: crypto/encryptor_win.cc

Issue 7056026: Implement AES-CTR for NSS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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
« crypto/encryptor_unittest.cc ('K') | « crypto/encryptor_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 "crypto/encryptor.h" 5 #include "crypto/encryptor.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "crypto/symmetric_key.h" 9 #include "crypto/symmetric_key.h"
10 10
(...skipping 21 matching lines...) Expand all
32 : key_(NULL), 32 : key_(NULL),
33 mode_(CBC), 33 mode_(CBC),
34 block_size_(0) { 34 block_size_(0) {
35 } 35 }
36 36
37 Encryptor::~Encryptor() { 37 Encryptor::~Encryptor() {
38 } 38 }
39 39
40 bool Encryptor::Init(SymmetricKey* key, Mode mode, const std::string& iv) { 40 bool Encryptor::Init(SymmetricKey* key, Mode mode, const std::string& iv) {
41 DCHECK(key); 41 DCHECK(key);
42 DCHECK_EQ(CBC, mode) << "Unsupported mode of operation"; 42 DCHECK(CBC == mode || ECB == mode) << "Unsupported mode of operation";
43 43
44 // In CryptoAPI, the IV, padding mode, and feedback register (for a chaining 44 // In CryptoAPI, the IV, padding mode, and feedback register (for a chaining
45 // mode) are properties of a key, so we have to create a copy of the key for 45 // mode) are properties of a key, so we have to create a copy of the key for
46 // the Encryptor. See the Remarks section of the CryptEncrypt MSDN page. 46 // the Encryptor. See the Remarks section of the CryptEncrypt MSDN page.
47 BOOL ok = CryptDuplicateKey(key->key(), NULL, 0, capi_key_.receive()); 47 BOOL ok = CryptDuplicateKey(key->key(), NULL, 0, capi_key_.receive());
48 if (!ok) 48 if (!ok)
49 return false; 49 return false;
50 50
51 // CRYPT_MODE_CBC is the default for Microsoft Base Cryptographic Provider, 51 // CRYPT_MODE_CBC is the default for Microsoft Base Cryptographic Provider,
52 // but we set it anyway to be safe. 52 // but we set it anyway to be safe.
53 DWORD cipher_mode = CRYPT_MODE_CBC; 53 DWORD cipher_mode = CRYPT_MODE_CBC;
Ryan Sleevi 2011/05/23 05:55:04 CRYPT_MODE_ECB for ECB. I'm not sure of KP_PADDING
54 ok = CryptSetKeyParam(capi_key_.get(), KP_MODE, 54 ok = CryptSetKeyParam(capi_key_.get(), KP_MODE,
55 reinterpret_cast<BYTE*>(&cipher_mode), 0); 55 reinterpret_cast<BYTE*>(&cipher_mode), 0);
56 if (!ok) 56 if (!ok)
57 return false; 57 return false;
58 58
59 block_size_ = GetCipherBlockSize(capi_key_.get()); 59 block_size_ = GetCipherBlockSize(capi_key_.get());
60 if (block_size_ == 0) 60 if (block_size_ == 0)
61 return false; 61 return false;
62 62
63 if (iv.size() != block_size_) 63 if (iv.size() != block_size_)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 if (!ok) 106 if (!ok)
107 return false; 107 return false;
108 108
109 DCHECK_GT(tmp.size(), data_len); 109 DCHECK_GT(tmp.size(), data_len);
110 110
111 plaintext->assign(reinterpret_cast<char*>(&tmp[0]), data_len); 111 plaintext->assign(reinterpret_cast<char*>(&tmp[0]), data_len);
112 return true; 112 return true;
113 } 113 }
114 114
115 } // namespace crypto 115 } // namespace crypto
OLDNEW
« crypto/encryptor_unittest.cc ('K') | « crypto/encryptor_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698