| Index: crypto/encryptor_mac.cc
|
| diff --git a/crypto/encryptor_mac.cc b/crypto/encryptor_mac.cc
|
| index 6be373a5d92028052b1de94d5f1d85739b54ffcf..972fc0432403a0ba7379f04d1de2957af6b7aa70 100644
|
| --- a/crypto/encryptor_mac.cc
|
| +++ b/crypto/encryptor_mac.cc
|
| @@ -23,8 +23,10 @@ Encryptor::~Encryptor() {
|
| bool Encryptor::Init(SymmetricKey* key,
|
| Mode mode,
|
| const base::StringPiece& iv) {
|
| - DCHECK(key);
|
| - DCHECK_EQ(CBC, mode) << "Unsupported mode of operation";
|
| + DCHECK_EQ(CBC, mode);
|
| + if (!key)
|
| + return false;
|
| +
|
| CSSM_DATA raw_key = key->cssm_data();
|
| if (raw_key.Length != kCCKeySizeAES128 &&
|
| raw_key.Length != kCCKeySizeAES192 &&
|
| @@ -42,15 +44,17 @@ bool Encryptor::Init(SymmetricKey* key,
|
| bool Encryptor::Crypt(int /*CCOperation*/ op,
|
| const base::StringPiece& input,
|
| std::string* output) {
|
| - DCHECK(key_);
|
| + if (!key_)
|
| + return false;
|
| +
|
| CSSM_DATA raw_key = key_->cssm_data();
|
| // CommonCryptor.h: "A general rule for the size of the output buffer which
|
| // must be provided by the caller is that for block ciphers, the output
|
| // length is never larger than the input length plus the block size."
|
| -
|
| size_t output_size = input.size() + iv_.size();
|
| - CHECK_GT(output_size, 0u);
|
| - CHECK_GT(output_size + 1, input.size());
|
| + if (output_size == 0 || output_size + 1 < input.size())
|
| + return false;
|
| +
|
| CCCryptorStatus err = CCCrypt(op,
|
| kCCAlgorithmAES128,
|
| kCCOptionPKCS7Padding,
|
| @@ -61,7 +65,6 @@ bool Encryptor::Crypt(int /*CCOperation*/ op,
|
| output_size,
|
| &output_size);
|
| if (err) {
|
| - output->clear();
|
| LOG(ERROR) << "CCCrypt returned " << err;
|
| return false;
|
| }
|
| @@ -71,13 +74,15 @@ bool Encryptor::Crypt(int /*CCOperation*/ op,
|
|
|
| bool Encryptor::Encrypt(const base::StringPiece& plaintext,
|
| std::string* ciphertext) {
|
| - CHECK(!plaintext.empty() || (mode_ == CBC));
|
| + if (plaintext.empty() && mode_ != CBC)
|
| + return false;
|
| return Crypt(kCCEncrypt, plaintext, ciphertext);
|
| }
|
|
|
| bool Encryptor::Decrypt(const base::StringPiece& ciphertext,
|
| std::string* plaintext) {
|
| - CHECK(!ciphertext.empty());
|
| + if (ciphertext.empty())
|
| + return false;
|
| return Crypt(kCCDecrypt, ciphertext, plaintext);
|
| }
|
|
|
|
|