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 "crypto/encryptor.h" | 5 #include "crypto/encryptor.h" |
6 | 6 |
7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 const base::StringPiece& iv) { | 46 const base::StringPiece& iv) { |
47 DCHECK(key); | 47 DCHECK(key); |
48 DCHECK(CBC == mode || CTR == mode) << "Unsupported mode of operation"; | 48 DCHECK(CBC == mode || CTR == mode) << "Unsupported mode of operation"; |
49 | 49 |
50 key_ = key; | 50 key_ = key; |
51 mode_ = mode; | 51 mode_ = mode; |
52 | 52 |
53 if (mode == CBC && iv.size() != AES_BLOCK_SIZE) | 53 if (mode == CBC && iv.size() != AES_BLOCK_SIZE) |
54 return false; | 54 return false; |
55 | 55 |
56 slot_.reset(PK11_GetBestSlot(GetMechanism(mode), NULL)); | |
57 if (!slot_.get()) | |
58 return false; | |
59 | |
60 switch (mode) { | 56 switch (mode) { |
61 case CBC: | 57 case CBC: |
62 SECItem iv_item; | 58 SECItem iv_item; |
63 iv_item.type = siBuffer; | 59 iv_item.type = siBuffer; |
64 iv_item.data = reinterpret_cast<unsigned char*>( | 60 iv_item.data = reinterpret_cast<unsigned char*>( |
65 const_cast<char *>(iv.data())); | 61 const_cast<char *>(iv.data())); |
66 iv_item.len = iv.size(); | 62 iv_item.len = iv.size(); |
67 | 63 |
68 param_.reset(PK11_ParamFromIV(GetMechanism(mode), &iv_item)); | 64 param_.reset(PK11_ParamFromIV(GetMechanism(mode), &iv_item)); |
69 break; | 65 break; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 184 |
189 // Use |output_data| to mask |input|. | 185 // Use |output_data| to mask |input|. |
190 MaskMessage( | 186 MaskMessage( |
191 reinterpret_cast<uint8*>(const_cast<char*>(input.data())), | 187 reinterpret_cast<uint8*>(const_cast<char*>(input.data())), |
192 input.length(), output_data, output_data); | 188 input.length(), output_data, output_data); |
193 output->resize(input.length()); | 189 output->resize(input.length()); |
194 return true; | 190 return true; |
195 } | 191 } |
196 | 192 |
197 } // namespace crypto | 193 } // namespace crypto |
OLD | NEW |