| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <openssl/aes.h> | 5 #include <openssl/aes.h> |
| 6 #include <openssl/evp.h> | 6 #include <openssl/evp.h> |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 if (!output_max_len.IsValid()) | 58 if (!output_max_len.IsValid()) |
| 59 return Status::ErrorDataTooLarge(); | 59 return Status::ErrorDataTooLarge(); |
| 60 | 60 |
| 61 const unsigned remainder = output_max_len.ValueOrDie() % AES_BLOCK_SIZE; | 61 const unsigned remainder = output_max_len.ValueOrDie() % AES_BLOCK_SIZE; |
| 62 if (remainder != 0) | 62 if (remainder != 0) |
| 63 output_max_len += AES_BLOCK_SIZE - remainder; | 63 output_max_len += AES_BLOCK_SIZE - remainder; |
| 64 if (!output_max_len.IsValid()) | 64 if (!output_max_len.IsValid()) |
| 65 return Status::ErrorDataTooLarge(); | 65 return Status::ErrorDataTooLarge(); |
| 66 | 66 |
| 67 // Note: PKCS padding is enabled by default | 67 // Note: PKCS padding is enabled by default |
| 68 crypto::ScopedOpenSSL<EVP_CIPHER_CTX, EVP_CIPHER_CTX_free>::Type context( | 68 crypto::ScopedOpenSSL<EVP_CIPHER_CTX, EVP_CIPHER_CTX_free> context( |
| 69 EVP_CIPHER_CTX_new()); | 69 EVP_CIPHER_CTX_new()); |
| 70 | 70 |
| 71 if (!context.get()) | 71 if (!context.get()) |
| 72 return Status::OperationError(); | 72 return Status::OperationError(); |
| 73 | 73 |
| 74 const EVP_CIPHER* const cipher = GetAESCipherByKeyLength(raw_key.size()); | 74 const EVP_CIPHER* const cipher = GetAESCipherByKeyLength(raw_key.size()); |
| 75 DCHECK(cipher); | 75 DCHECK(cipher); |
| 76 | 76 |
| 77 if (!EVP_CipherInit_ex(context.get(), cipher, NULL, &raw_key[0], | 77 if (!EVP_CipherInit_ex(context.get(), cipher, NULL, &raw_key[0], |
| 78 params->iv().data(), cipher_operation)) { | 78 params->iv().data(), cipher_operation)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 } // namespace | 125 } // namespace |
| 126 | 126 |
| 127 AlgorithmImplementation* CreatePlatformAesCbcImplementation() { | 127 AlgorithmImplementation* CreatePlatformAesCbcImplementation() { |
| 128 return new AesCbcImplementation; | 128 return new AesCbcImplementation; |
| 129 } | 129 } |
| 130 | 130 |
| 131 } // namespace webcrypto | 131 } // namespace webcrypto |
| 132 | 132 |
| 133 } // namespace content | 133 } // namespace content |
| OLD | NEW |