9 #ifndef MEDIA_BASE_AES_ENCRYPTOR_H_
10 #define MEDIA_BASE_AES_ENCRYPTOR_H_
15 #include "packager/base/memory/scoped_ptr.h"
16 #include "packager/base/stl_util.h"
19 typedef struct aes_key_st AES_KEY;
21 namespace edash_packager {
38 const std::vector<uint8_t>&
iv);
42 bool Encrypt(
const std::vector<uint8_t>& plaintext,
43 std::vector<uint8_t>* ciphertext);
44 bool Encrypt(
const std::string& plaintext, std::string* ciphertext);
45 bool Encrypt(
const uint8_t* plaintext,
46 size_t plaintext_size,
47 uint8_t* ciphertext) {
59 virtual bool SetIv(
const std::vector<uint8_t>& iv) = 0;
62 const std::vector<uint8_t>&
iv()
const {
return iv_; }
71 size_t plaintext_size,
72 uint8_t* ciphertext) = 0;
77 void set_iv(
const std::vector<uint8_t>& iv) { iv_ =
iv; }
78 AES_KEY* aes_key()
const {
return aes_key_.get(); }
82 std::vector<uint8_t> iv_;
84 scoped_ptr<AES_KEY> aes_key_;
86 DISALLOW_COPY_AND_ASSIGN(AesEncryptor);
103 bool SetIv(
const std::vector<uint8_t>& iv)
override;
106 uint32_t block_offset()
const {
return block_offset_; }
110 size_t plaintext_size,
111 uint8_t* ciphertext)
override;
116 uint32_t block_offset_;
118 std::vector<uint8_t> counter_;
120 std::vector<uint8_t> encrypted_counter_;
122 bool counter_overflow_;
127 enum CbcPaddingScheme {
133 const bool kChainAcrossCalls =
true;
143 AesCbcEncryptor(CbcPaddingScheme padding_scheme,
bool chain_across_calls);
150 bool SetIv(
const std::vector<uint8_t>& iv)
override;
155 size_t plaintext_size,
156 uint8_t* ciphertext)
override;
160 const CbcPaddingScheme padding_scheme_;
161 const bool chain_across_calls_;
169 #endif // MEDIA_BASE_AES_ENCRYPTOR_H_