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);
49 bool Encrypt(
const uint8_t* plaintext,
50 size_t plaintext_size,
53 bool Encrypt(
const std::vector<uint8_t>& plaintext,
54 std::vector<uint8_t>* ciphertext) {
55 ciphertext->resize(plaintext.size());
56 return Encrypt(&plaintext[0], plaintext.size(), &(*ciphertext)[0]);
59 bool Encrypt(
const std::string& plaintext, std::string* ciphertext) {
60 ciphertext->resize(plaintext.size());
61 return Encrypt(reinterpret_cast<const uint8_t*>(plaintext.data()),
63 reinterpret_cast<uint8_t*
>(string_as_array(ciphertext)));
68 bool Decrypt(
const uint8_t* ciphertext,
69 size_t ciphertext_size,
71 return Encrypt(ciphertext, ciphertext_size, plaintext);
74 bool Decrypt(
const std::vector<uint8_t>& ciphertext,
75 std::vector<uint8_t>* plaintext) {
76 return Encrypt(ciphertext, plaintext);
79 bool Decrypt(
const std::string& ciphertext, std::string* plaintext) {
80 return Encrypt(ciphertext, plaintext);
91 bool SetIv(
const std::vector<uint8_t>& iv);
93 const std::vector<uint8_t>& iv()
const {
return iv_; }
95 uint32_t block_offset()
const {
return block_offset_; }
99 std::vector<uint8_t> iv_;
101 uint32_t block_offset_;
103 scoped_ptr<AES_KEY> aes_key_;
105 std::vector<uint8_t> counter_;
107 std::vector<uint8_t> encrypted_counter_;
109 bool counter_overflow_;
127 const std::vector<uint8_t>& iv);
131 void Encrypt(
const std::string& plaintext, std::string* ciphertext);
134 bool SetIv(
const std::vector<uint8_t>& iv);
136 const std::vector<uint8_t>& iv()
const {
return iv_; }
139 std::vector<uint8_t> iv_;
140 scoped_ptr<AES_KEY> encrypt_key_;
158 const std::vector<uint8_t>& iv);
163 bool Decrypt(
const std::string& ciphertext, std::string* plaintext);
166 bool SetIv(
const std::vector<uint8_t>& iv);
168 const std::vector<uint8_t>& iv()
const {
return iv_; }
171 std::vector<uint8_t> iv_;
172 scoped_ptr<AES_KEY> decrypt_key_;
190 const std::vector<uint8_t>& iv);
197 void Encrypt(
const uint8_t* plaintext,
size_t size, uint8_t* ciphertext);
202 void Encrypt(
const std::vector<uint8_t>& plaintext,
203 std::vector<uint8_t>* ciphertext);
207 bool SetIv(
const std::vector<uint8_t>& iv);
209 const std::vector<uint8_t>& iv()
const {
return iv_; }
212 std::vector<uint8_t> iv_;
213 scoped_ptr<AES_KEY> encrypt_key_;
231 const std::vector<uint8_t>& iv);
238 void Decrypt(
const uint8_t* ciphertext,
size_t size, uint8_t* plaintext);
243 void Decrypt(
const std::vector<uint8_t>& ciphertext,
244 std::vector<uint8_t>* plaintext);
247 bool SetIv(
const std::vector<uint8_t>& iv);
249 const std::vector<uint8_t>& iv()
const {
return iv_; }
252 std::vector<uint8_t> iv_;
253 scoped_ptr<AES_KEY> decrypt_key_;
261 #endif // MEDIA_BASE_AES_ENCRYPTOR_H_