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 {
43 const std::vector<uint8_t>& iv);
48 bool Encrypt(
const uint8_t* plaintext,
49 size_t plaintext_size,
52 bool Encrypt(
const std::vector<uint8_t>& plaintext,
53 std::vector<uint8_t>* ciphertext) {
54 ciphertext->resize(plaintext.size());
55 return Encrypt(&plaintext[0], plaintext.size(), &(*ciphertext)[0]);
58 bool Encrypt(
const std::string& plaintext, std::string* ciphertext) {
59 ciphertext->resize(plaintext.size());
60 return Encrypt(reinterpret_cast<const uint8_t*>(plaintext.data()),
62 reinterpret_cast<uint8_t*
>(string_as_array(ciphertext)));
67 bool Decrypt(
const uint8_t* ciphertext,
68 size_t ciphertext_size,
70 return Encrypt(ciphertext, ciphertext_size, plaintext);
73 bool Decrypt(
const std::vector<uint8_t>& ciphertext,
74 std::vector<uint8_t>* plaintext) {
75 return Encrypt(ciphertext, plaintext);
78 bool Decrypt(
const std::string& ciphertext, std::string* plaintext) {
79 return Encrypt(ciphertext, plaintext);
90 bool SetIv(
const std::vector<uint8_t>& iv);
92 const std::vector<uint8_t>& iv()
const {
return iv_; }
94 uint32_t block_offset()
const {
return block_offset_; }
98 std::vector<uint8_t> iv_;
100 uint32_t block_offset_;
102 scoped_ptr<AES_KEY> aes_key_;
104 std::vector<uint8_t> counter_;
106 std::vector<uint8_t> encrypted_counter_;
108 bool counter_overflow_;
126 const std::vector<uint8_t>& iv);
130 void Encrypt(
const std::string& plaintext, std::string* ciphertext);
133 bool SetIv(
const std::vector<uint8_t>& iv);
135 const std::vector<uint8_t>& iv()
const {
return iv_; }
138 std::vector<uint8_t> iv_;
139 scoped_ptr<AES_KEY> encrypt_key_;
157 const std::vector<uint8_t>& iv);
162 bool Decrypt(
const std::string& ciphertext, std::string* plaintext);
165 bool SetIv(
const std::vector<uint8_t>& iv);
167 const std::vector<uint8_t>& iv()
const {
return iv_; }
170 std::vector<uint8_t> iv_;
171 scoped_ptr<AES_KEY> decrypt_key_;
189 const std::vector<uint8_t>& iv);
196 void Encrypt(
const uint8_t* plaintext,
size_t size, uint8_t* ciphertext);
201 void Encrypt(
const std::vector<uint8_t>& plaintext,
202 std::vector<uint8_t>* ciphertext);
206 bool SetIv(
const std::vector<uint8_t>& iv);
208 const std::vector<uint8_t>& iv()
const {
return iv_; }
211 std::vector<uint8_t> iv_;
212 scoped_ptr<AES_KEY> encrypt_key_;
230 const std::vector<uint8_t>& iv);
237 void Decrypt(
const uint8_t* ciphertext,
size_t size, uint8_t* plaintext);
242 void Decrypt(
const std::vector<uint8_t>& ciphertext,
243 std::vector<uint8_t>* plaintext);
246 bool SetIv(
const std::vector<uint8_t>& iv);
248 const std::vector<uint8_t>& iv()
const {
return iv_; }
251 std::vector<uint8_t> iv_;
252 scoped_ptr<AES_KEY> decrypt_key_;
260 #endif // MEDIA_BASE_AES_ENCRYPTOR_H_