2016-03-17 17:03:19 +00:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
// AES Decryptor implementation using openssl.
|
|
|
|
|
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>
|
|
|
|
|
2016-04-06 00:19:16 +00:00
|
|
|
#include "packager/base/macros.h"
|
|
|
|
#include "packager/media/base/aes_cryptor.h"
|
2016-03-17 17:03:19 +00:00
|
|
|
#include "packager/media/base/aes_encryptor.h"
|
|
|
|
|
|
|
|
namespace edash_packager {
|
|
|
|
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-03-25 18:02:43 +00:00
|
|
|
/// @param padding_scheme indicates the padding scheme used. Currently
|
|
|
|
/// supported schemes: kNoPadding, kPkcs5Padding, kCtsPadding.
|
|
|
|
/// @param chain_across_calls indicates whether there is a continuous cipher
|
|
|
|
/// block chain across calls for Decrypt function. If it is false, iv
|
|
|
|
/// is not updated across Decrypt function calls.
|
|
|
|
AesCbcDecryptor(CbcPaddingScheme padding_scheme, bool chain_across_calls);
|
|
|
|
~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;
|
|
|
|
bool SetIv(const std::vector<uint8_t>& iv) override;
|
2016-04-06 00:19:16 +00:00
|
|
|
void UpdateIv() override {
|
|
|
|
// Nop for decryptor.
|
|
|
|
}
|
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-03-25 18:02:43 +00:00
|
|
|
const CbcPaddingScheme padding_scheme_;
|
|
|
|
const bool chain_across_calls_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AesCbcDecryptor);
|
2016-03-17 17:03:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
} // namespace edash_packager
|
|
|
|
|
2016-04-06 00:19:16 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_AES_DECRYPTOR_H_
|