2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2016 Google LLC. All rights reserved.
|
2016-03-17 17:03:19 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
//
|
2022-11-02 15:34:06 +00:00
|
|
|
// AES Decryptor implementation using mbedtls.
|
2016-03-17 17:03:19 +00:00
|
|
|
|
2016-04-06 00:19:16 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_BASE_AES_DECRYPTOR_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_AES_DECRYPTOR_H_
|
2016-03-17 17:03:19 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2023-10-14 16:36:01 +00:00
|
|
|
#include <packager/macros/classes.h>
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/base/aes_cryptor.h>
|
|
|
|
#include <packager/media/base/aes_encryptor.h>
|
2016-03-17 17:03:19 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-03-17 17:03:19 +00:00
|
|
|
namespace media {
|
|
|
|
|
2016-04-06 00:19:16 +00:00
|
|
|
/// For AES-CTR, encryption and decryption are identical.
|
|
|
|
using AesCtrDecryptor = AesCtrEncryptor;
|
2016-03-17 17:03:19 +00:00
|
|
|
|
2016-04-06 00:19:16 +00:00
|
|
|
/// Class which implements AES-CBC (Cipher block chaining) decryption.
|
|
|
|
class AesCbcDecryptor : public AesCryptor {
|
2016-03-17 17:03:19 +00:00
|
|
|
public:
|
2016-04-13 17:52:41 +00:00
|
|
|
/// Creates a AesCbcDecryptor with continous cipher block chain across Crypt
|
|
|
|
/// calls.
|
2016-03-25 18:02:43 +00:00
|
|
|
/// @param padding_scheme indicates the padding scheme used. Currently
|
|
|
|
/// supported schemes: kNoPadding, kPkcs5Padding, kCtsPadding.
|
2016-04-13 17:52:41 +00:00
|
|
|
explicit AesCbcDecryptor(CbcPaddingScheme padding_scheme);
|
|
|
|
|
|
|
|
/// @param padding_scheme indicates the padding scheme used. Currently
|
|
|
|
/// supported schemes: kNoPadding, kPkcs5Padding, kCtsPadding.
|
|
|
|
/// @param constant_iv_flag indicates whether a constant iv is used,
|
|
|
|
/// kUseConstantIv means that the same iv is used for all Crypt calls
|
|
|
|
/// until iv is changed via SetIv; otherwise, iv is updated internally
|
|
|
|
/// and there is a continuous cipher block chain across Crypt calls
|
|
|
|
/// util iv is changed explicitly via SetIv or UpdateIv functions.
|
|
|
|
AesCbcDecryptor(CbcPaddingScheme padding_scheme,
|
|
|
|
ConstantIvFlag constant_iv_flag);
|
|
|
|
|
2016-03-25 18:02:43 +00:00
|
|
|
~AesCbcDecryptor() override;
|
2016-03-17 17:03:19 +00:00
|
|
|
|
2016-04-06 00:19:16 +00:00
|
|
|
/// @name AesCryptor implementation overrides.
|
2016-03-17 17:03:19 +00:00
|
|
|
/// @{
|
|
|
|
bool InitializeWithIv(const std::vector<uint8_t>& key,
|
|
|
|
const std::vector<uint8_t>& iv) override;
|
2023-08-31 23:59:46 +00:00
|
|
|
|
|
|
|
size_t RequiredOutputSize(size_t plaintext_size) override;
|
2016-03-17 17:03:19 +00:00
|
|
|
/// @}
|
|
|
|
|
|
|
|
private:
|
2016-04-06 00:19:16 +00:00
|
|
|
bool CryptInternal(const uint8_t* ciphertext,
|
|
|
|
size_t ciphertext_size,
|
|
|
|
uint8_t* plaintext,
|
|
|
|
size_t* plaintext_size) override;
|
2016-04-13 17:52:41 +00:00
|
|
|
void SetIvInternal() override;
|
2022-11-02 15:34:06 +00:00
|
|
|
void CbcDecryptBlocks(const uint8_t* plaintext,
|
|
|
|
size_t plaintext_size,
|
|
|
|
uint8_t* ciphertext);
|
2016-04-06 00:19:16 +00:00
|
|
|
|
2016-03-25 18:02:43 +00:00
|
|
|
const CbcPaddingScheme padding_scheme_;
|
2016-04-13 17:52:41 +00:00
|
|
|
// 16-byte internal iv for crypto operations.
|
|
|
|
std::vector<uint8_t> internal_iv_;
|
2016-03-25 18:02:43 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AesCbcDecryptor);
|
2016-03-17 17:03:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2016-03-17 17:03:19 +00:00
|
|
|
|
2016-04-06 00:19:16 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_AES_DECRYPTOR_H_
|