| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 key_->key(), param_.get())); | 94 key_->key(), param_.get())); |
| 95 if (!context.get()) | 95 if (!context.get()) |
| 96 return false; | 96 return false; |
| 97 | 97 |
| 98 if (mode_ == CTR) | 98 if (mode_ == CTR) |
| 99 return CryptCTR(context.get(), ciphertext, plaintext); | 99 return CryptCTR(context.get(), ciphertext, plaintext); |
| 100 | 100 |
| 101 if (ciphertext.size() % AES_BLOCK_SIZE != 0) { | 101 if (ciphertext.size() % AES_BLOCK_SIZE != 0) { |
| 102 // Decryption will fail if the input is not a multiple of the block size. | 102 // Decryption will fail if the input is not a multiple of the block size. |
| 103 // PK11_CipherOp has a bug where it will do an invalid memory access before | 103 // PK11_CipherOp has a bug where it will do an invalid memory access before |
| 104 // the start of the input, so avoid calling it. (Possibly NSS bug 921687). | 104 // the start of the input, so avoid calling it. (NSS bug 922780). |
| 105 plaintext->clear(); | 105 plaintext->clear(); |
| 106 return false; | 106 return false; |
| 107 } | 107 } |
| 108 | 108 |
| 109 return Crypt(context.get(), ciphertext, plaintext); | 109 return Crypt(context.get(), ciphertext, plaintext); |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool Encryptor::Crypt(PK11Context* context, | 112 bool Encryptor::Crypt(PK11Context* context, |
| 113 const base::StringPiece& input, | 113 const base::StringPiece& input, |
| 114 std::string* output) { | 114 std::string* output) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 // Use |output_data| to mask |input|. | 194 // Use |output_data| to mask |input|. |
| 195 MaskMessage( | 195 MaskMessage( |
| 196 reinterpret_cast<uint8*>(const_cast<char*>(input.data())), | 196 reinterpret_cast<uint8*>(const_cast<char*>(input.data())), |
| 197 input.length(), output_data, output_data); | 197 input.length(), output_data, output_data); |
| 198 output->resize(input.length()); | 198 output->resize(input.length()); |
| 199 return true; | 199 return true; |
| 200 } | 200 } |
| 201 | 201 |
| 202 } // namespace crypto | 202 } // namespace crypto |
| OLD | NEW |