Shaka Packager SDK
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
shaka::media::AesCryptor Class Referenceabstract
Inheritance diagram for shaka::media::AesCryptor:
shaka::media::AesCbcDecryptor shaka::media::AesCbcEncryptor shaka::media::AesCtrEncryptor shaka::media::AesPatternCryptor shaka::media::MockAesCryptor shaka::media::SampleAesEc3Cryptor

Public Types

enum  ConstantIvFlag { kUseConstantIv , kDontUseConstantIv }
 

Public Member Functions

 AesCryptor (ConstantIvFlag constant_iv_flag)
 
virtual bool InitializeWithIv (const std::vector< uint8_t > &key, const std::vector< uint8_t > &iv)=0
 
virtual size_t RequiredOutputSize (size_t plaintext_size)
 
bool SetIv (const std::vector< uint8_t > &iv)
 
void UpdateIv ()
 
const std::vector< uint8_t > & iv () const
 
bool use_constant_iv () const
 
Various forms of crypt (Encrypt/Decrypt) calls.

It is an Encrypt function for encryptor and a Decrypt function for decryptor. The text and crypt_text pointers can be the same address for in place encryption/decryption.

bool Crypt (const std::vector< uint8_t > &text, std::vector< uint8_t > *crypt_text)
 
bool Crypt (const std::string &text, std::string *crypt_text)
 
bool Crypt (const uint8_t *text, size_t text_size, uint8_t *crypt_text)
 
bool Crypt (const uint8_t *text, size_t text_size, uint8_t *crypt_text, size_t *crypt_text_size)
 

Static Public Member Functions

static bool GenerateRandomIv (FourCC protection_scheme, std::vector< uint8_t > *iv)
 

Protected Types

enum  CipherMode { kCtrMode , kCbcMode }
 

Protected Member Functions

bool SetupCipher (size_t key_size, CipherMode mode)
 

Protected Attributes

mbedtls_cipher_context_t cipher_ctx_
 

Detailed Description

Definition at line 24 of file aes_cryptor.h.

Constructor & Destructor Documentation

◆ AesCryptor()

shaka::media::AesCryptor::AesCryptor ( ConstantIvFlag  constant_iv_flag)
explicit
Parameters
constant_iv_flagindicates 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 can be incremented (for counter mode) or chained (for cipher block chaining mode) internally inside Crypt call, i.e. iv will be updated across Crypt calls.

Definition at line 32 of file aes_cryptor.cc.

Member Function Documentation

◆ Crypt()

bool shaka::media::AesCryptor::Crypt ( const uint8_t *  text,
size_t  text_size,
uint8_t *  crypt_text 
)
inline
Parameters
crypt_textshould have at least text_size bytes.

Definition at line 58 of file aes_cryptor.h.

◆ GenerateRandomIv()

bool shaka::media::AesCryptor::GenerateRandomIv ( FourCC  protection_scheme,
std::vector< uint8_t > *  iv 
)
static
Parameters
protection_schemespecifies the protection scheme: 'cenc', 'cens', 'cbc1', 'cbcs', which is useful to determine the random iv size.
ivpoints to generated initialization vector.
Returns
true on success, false otherwise.

Definition at line 110 of file aes_cryptor.cc.

◆ InitializeWithIv()

virtual bool shaka::media::AesCryptor::InitializeWithIv ( const std::vector< uint8_t > &  key,
const std::vector< uint8_t > &  iv 
)
pure virtual

Initialize the cryptor with specified key and IV.

Returns
true on successful initialization, false otherwise.

Implemented in shaka::media::SampleAesEc3Cryptor, shaka::media::AesPatternCryptor, shaka::media::AesCbcEncryptor, shaka::media::AesCtrEncryptor, and shaka::media::AesCbcDecryptor.

◆ iv()

const std::vector<uint8_t>& shaka::media::AesCryptor::iv ( ) const
inline
Returns
The current iv.

Definition at line 85 of file aes_cryptor.h.

◆ SetIv()

bool shaka::media::AesCryptor::SetIv ( const std::vector< uint8_t > &  iv)

Set IV. SetIv() implementation guarantees that the iv passed to SetIv() is set to iv() and then calls SetIvInternal().

Returns
true if successful, false if the input is invalid.

Definition at line 70 of file aes_cryptor.cc.

◆ UpdateIv()

void shaka::media::AesCryptor::UpdateIv ( )

Update IV for next sample. As recommended in ISO/IEC 23001-7: IV need to be updated per sample for CENC. This is used by encryptors only. It is a NOP if using kUseConstantIv.

Definition at line 81 of file aes_cryptor.cc.

◆ use_constant_iv()

bool shaka::media::AesCryptor::use_constant_iv ( ) const
inline
Returns
true if constant iv is used, false otherwise.

Definition at line 88 of file aes_cryptor.h.


The documentation for this class was generated from the following files: