diff --git a/packager/media/base/aes_cryptor.cc b/packager/media/base/aes_cryptor.cc index acbb8911af..dd3cee7e39 100644 --- a/packager/media/base/aes_cryptor.cc +++ b/packager/media/base/aes_cryptor.cc @@ -7,6 +7,7 @@ #include "packager/media/base/aes_cryptor.h" #include +#include #include #include @@ -31,7 +32,9 @@ namespace media { AesCryptor::AesCryptor(ConstantIvFlag constant_iv_flag) : aes_key_(new AES_KEY), constant_iv_flag_(constant_iv_flag), - num_crypt_bytes_(0) {} + num_crypt_bytes_(0) { + CRYPTO_library_init(); +} AesCryptor::~AesCryptor() {} diff --git a/packager/media/base/aes_cryptor_unittest.cc b/packager/media/base/aes_cryptor_unittest.cc index 8fe02e88dc..fd40c1ff74 100644 --- a/packager/media/base/aes_cryptor_unittest.cc +++ b/packager/media/base/aes_cryptor_unittest.cc @@ -625,5 +625,40 @@ INSTANTIATE_TEST_CASE_P(CbcTestCases, AesCbcCryptorVerificationTest, ::testing::ValuesIn(kCbcTestCases)); +class AesPerformanceTest : public ::testing::Test { + public: + AesPerformanceTest() + : cbc_encryptor_(kNoPadding, AesCryptor::kUseConstantIv), + key_(kAesKey, kAesKey + arraysize(kAesKey)), + iv_(kAesIv, kAesIv + arraysize(kAesIv)) {} + + void SetUp() override { + plaintext_.resize(0x10000); + for (size_t i = 0; i < plaintext_.size(); i++) + plaintext_[i] = static_cast(i); + } + + protected: + AesCbcEncryptor cbc_encryptor_; + AesCtrEncryptor ctr_encryptor_; + std::vector key_; + std::vector iv_; + std::vector plaintext_; +}; + +TEST_F(AesPerformanceTest, AesCbc) { + ASSERT_TRUE(cbc_encryptor_.InitializeWithIv(key_, iv_)); + std::vector encrypted; + for (int i = 0; i < 0x100; i++) + ASSERT_TRUE(cbc_encryptor_.Crypt(plaintext_, &encrypted)); +} + +TEST_F(AesPerformanceTest, AesCtr) { + ASSERT_TRUE(ctr_encryptor_.InitializeWithIv(key_, iv_)); + std::vector encrypted; + for (int i = 0; i < 0x100; i++) + ASSERT_TRUE(ctr_encryptor_.Crypt(plaintext_, &encrypted)); +} + } // namespace media } // namespace shaka