Shaka Packager SDK
Public Types | Public Member Functions | List of all members
shaka::media::AesPatternCryptor Class Reference

Implements pattern-based encryption/decryption. More...

#include <aes_pattern_cryptor.h>

Inheritance diagram for shaka::media::AesPatternCryptor:
shaka::media::AesCryptor

Public Types

enum  PatternEncryptionMode { kEncryptIfCryptByteBlockRemaining , kSkipIfCryptByteBlockRemaining }
 
- Public Types inherited from shaka::media::AesCryptor
enum  ConstantIvFlag { kUseConstantIv , kDontUseConstantIv }
 

Public Member Functions

 AesPatternCryptor (uint8_t crypt_byte_block, uint8_t skip_byte_block, PatternEncryptionMode encryption_mode, ConstantIvFlag constant_iv_flag, std::unique_ptr< AesCryptor > cryptor)
 
AesCryptor implementation overrides.
bool InitializeWithIv (const std::vector< uint8_t > &key, const std::vector< uint8_t > &iv) override
 
- Public Member Functions inherited from shaka::media::AesCryptor
 AesCryptor (ConstantIvFlag constant_iv_flag)
 
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
 
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)
 

Additional Inherited Members

- Static Public Member Functions inherited from shaka::media::AesCryptor
static bool GenerateRandomIv (FourCC protection_scheme, std::vector< uint8_t > *iv)
 
- Protected Types inherited from shaka::media::AesCryptor
enum  CipherMode { kCtrMode , kCbcMode }
 
- Protected Member Functions inherited from shaka::media::AesCryptor
bool SetupCipher (size_t key_size, CipherMode mode)
 
- Protected Attributes inherited from shaka::media::AesCryptor
mbedtls_cipher_context_t cipher_ctx_
 

Detailed Description

Implements pattern-based encryption/decryption.

Definition at line 16 of file aes_pattern_cryptor.h.

Member Enumeration Documentation

◆ PatternEncryptionMode

Enumerator for controling encrytion/decryption mode for the last encryption/decrytion block(s).

Enumerator
kEncryptIfCryptByteBlockRemaining 

Use kEncryptIfCryptByteBlockRemaining to encrypt all the full 16-byte blocks even if the remaining bytes are less than encryption_block_bytes. IOW: if (remaining_bytes <= encryption_block_bytes) encrypt(block_aligned_remaining_data)

kSkipIfCryptByteBlockRemaining 

Use kSkipIfCryptByteBlockRemaining to not encrypt/decrypt the remaining bytes if it is less than or equal to encryption_block_bytes. if (remaining_bytes > encryption_block_bytes) encrypt(). Use this mode for HLS SAMPLE-AES.

Definition at line 20 of file aes_pattern_cryptor.h.

Constructor & Destructor Documentation

◆ AesPatternCryptor()

shaka::media::AesPatternCryptor::AesPatternCryptor ( uint8_t  crypt_byte_block,
uint8_t  skip_byte_block,
PatternEncryptionMode  encryption_mode,
ConstantIvFlag  constant_iv_flag,
std::unique_ptr< AesCryptor cryptor 
)
Parameters
crypt_byte_blockindicates number of encrypted blocks (16-byte) in pattern based encryption.
skip_byte_blockindicates number of unencrypted blocks (16-byte) in pattern based encryption.
encryption_modeis used to determine the behavior for the last block.
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.
cryptorpoints to an AesCryptor instance which performs the actual encryption/decryption. Note that cryptor shall not use constant iv.

Definition at line 19 of file aes_pattern_cryptor.cc.

Member Function Documentation

◆ InitializeWithIv()

bool shaka::media::AesPatternCryptor::InitializeWithIv ( const std::vector< uint8_t > &  key,
const std::vector< uint8_t > &  iv 
)
overridevirtual

Initialize the cryptor with specified key and IV.

Returns
true on successful initialization, false otherwise.

Implements shaka::media::AesCryptor.

Definition at line 38 of file aes_pattern_cryptor.cc.


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