TSDuck Version 3.15-955 (TSDuck - The MPEG Transport Stream Toolkit)
ts::CipherChainingTemplate< CIPHER > Class Template Referenceabstract

Base class of all cipher chaining modes, template version. More...

Inheritance diagram for ts::CipherChainingTemplate< CIPHER >:
Collaboration diagram for ts::CipherChainingTemplate< CIPHER >:

Public Member Functions

virtual size_t blockSize () const override
 Size in bytes of the block used by the algorithm. More...
 
virtual bool decrypt (const void *cipher, size_t cipher_length, void *plain, size_t plain_maxsize, size_t *plain_length=0)=0
 Decrypt one block of data. More...
 
virtual bool decryptInPlace (void *data, size_t data_length, size_t *max_actual_length=0)
 Decrypt one block of data in place. More...
 
virtual size_t defaultRounds () const override
 Default number of rounds for the algorithm. More...
 
virtual bool encrypt (const void *plain, size_t plain_length, void *cipher, size_t cipher_maxsize, size_t *cipher_length=0)=0
 Encrypt one block of data. More...
 
virtual bool encryptInPlace (void *data, size_t data_length, size_t *max_actual_length=0)
 Encrypt one block of data in place. More...
 
virtual bool isValidKeySize (size_t size) const override
 Check if a size in bytes is a valid key size. More...
 
virtual size_t maxIVSize () const
 Get the maximum IV sizes in bytes. More...
 
virtual size_t maxKeySize () const override
 Maximum key sizes in bytes. More...
 
virtual size_t maxRounds () const override
 Maximum number of rounds for the algorithm. More...
 
virtual size_t minIVSize () const
 Get the minimum IV sizes in bytes. More...
 
virtual size_t minKeySize () const override
 Minimum key sizes in bytes. More...
 
virtual size_t minMessageSize () const =0
 Get the minimum message size. More...
 
virtual size_t minRounds () const override
 Minimum number of rounds for the algorithm. More...
 
virtual UString name () const =0
 Algorithm name (informational only). More...
 
virtual bool residueAllowed () const =0
 Check if the chaining mode can process residue after the last multiple of the block size. More...
 
virtual bool setIV (const void *iv, size_t iv_length)
 Set a new initialization vector. More...
 
virtual bool setKey (const void *key, size_t key_length, size_t rounds=0) override
 Schedule a new key. More...
 

Protected Member Functions

 CipherChainingTemplate (size_t iv_min_blocks=1, size_t iv_max_blocks=1, size_t work_blocks=1)
 Constructor for subclasses. More...
 
virtual ~CipherChainingTemplate ()
 Destructor.
 

Protected Attributes

BlockCipheralgo
 An instance of the block cipher.
 
const size_t block_size
 Shortcut for algo->blockSize().
 
ByteBlock iv
 Current initialization vector.
 
const size_t iv_max_size
 IV max size in bytes.
 
const size_t iv_min_size
 IV min size in bytes.
 
ByteBlock work
 Temporary working buffer.
 

Detailed Description

template<class CIPHER>
class ts::CipherChainingTemplate< CIPHER >

Base class of all cipher chaining modes, template version.

Each instance uses a specific block cipher. The combination of a block cipher and a chaining mode also implements the same interface as ts::BlockCipher.

Template Parameters
CIPHERA subclass of ts::BlockCipher, the underlying block cipher.

Constructor & Destructor Documentation

◆ CipherChainingTemplate()

template<class CIPHER>
ts::CipherChainingTemplate< CIPHER >::CipherChainingTemplate ( size_t  iv_min_blocks = 1,
size_t  iv_max_blocks = 1,
size_t  work_blocks = 1 
)
inlineprotected

Constructor for subclasses.

Parameters
[in]iv_min_blocksMinimum IV size in multiples of cipher block size (default: 1).
[in]iv_max_blocksMaximum IV size in multiples of cipher block size (default: 1).
[in]work_blocksTemporary work buffer size in multiples of cipher block size (default: 1).

Member Function Documentation

◆ blockSize()

virtual size_t ts::CipherChaining::blockSize ( ) const
overridevirtualinherited

Size in bytes of the block used by the algorithm.

Returns
The size in bytes of the block used by the algorithm.

Implements ts::BlockCipher.

Reimplemented in ts::DVBCSA2.

◆ minKeySize()

virtual size_t ts::CipherChaining::minKeySize ( ) const
overridevirtualinherited

Minimum key sizes in bytes.

Returns
The minimum key sizes in bytes.

Implements ts::BlockCipher.

Reimplemented in ts::DVBCSA2.

◆ maxKeySize()

virtual size_t ts::CipherChaining::maxKeySize ( ) const
overridevirtualinherited

Maximum key sizes in bytes.

Returns
The maximum key sizes in bytes.

Implements ts::BlockCipher.

Reimplemented in ts::DVBCSA2.

◆ isValidKeySize()

virtual bool ts::CipherChaining::isValidKeySize ( size_t  size) const
overridevirtualinherited

Check if a size in bytes is a valid key size.

Parameters
[in]sizeSuggested key size in bytes.
Returns
True if size is a valid key size for the algorithm.

Implements ts::BlockCipher.

Reimplemented in ts::DVBCSA2.

◆ minRounds()

virtual size_t ts::CipherChaining::minRounds ( ) const
overridevirtualinherited

Minimum number of rounds for the algorithm.

Returns
The minimum number of rounds for the algorithm.

Implements ts::BlockCipher.

Reimplemented in ts::DVBCSA2.

◆ maxRounds()

virtual size_t ts::CipherChaining::maxRounds ( ) const
overridevirtualinherited

Maximum number of rounds for the algorithm.

Returns
The maximum number of rounds for the algorithm.

Implements ts::BlockCipher.

Reimplemented in ts::DVBCSA2.

◆ defaultRounds()

virtual size_t ts::CipherChaining::defaultRounds ( ) const
overridevirtualinherited

Default number of rounds for the algorithm.

Returns
The default number of rounds for the algorithm.

Implements ts::BlockCipher.

Reimplemented in ts::DVBCSA2.

◆ setKey()

virtual bool ts::CipherChaining::setKey ( const void *  key,
size_t  key_length,
size_t  rounds = 0 
)
overridevirtualinherited

Schedule a new key.

Parameters
[in]keyAddress of key value.
[in]key_lengthKey length in bytes.
[in]roundsRequested number of rounds. If zero, the default is used.
Returns
True on success, false on error.

Implements ts::BlockCipher.

Reimplemented in ts::DVBCSA2.

◆ setIV()

virtual bool ts::CipherChaining::setIV ( const void *  iv,
size_t  iv_length 
)
virtualinherited

Set a new initialization vector.

Parameters
[in]ivAddress of IV.
[in]iv_lengthIV length in bytes.
Returns
True on success, false on error.

Reimplemented in ts::DVS042< CIPHER >, ts::DVS042< AES >, ts::DVS042< DES >, and ts::DVBCSA2.

◆ minIVSize()

virtual size_t ts::CipherChaining::minIVSize ( ) const
inlinevirtualinherited

Get the minimum IV sizes in bytes.

Returns
The minimum IV sizes in bytes.

Reimplemented in ts::DVBCSA2.

◆ maxIVSize()

virtual size_t ts::CipherChaining::maxIVSize ( ) const
inlinevirtualinherited

Get the maximum IV sizes in bytes.

Returns
The maximum IV sizes in bytes.

Reimplemented in ts::DVBCSA2.

◆ minMessageSize()

virtual size_t ts::CipherChaining::minMessageSize ( ) const
pure virtualinherited

Get the minimum message size.

Shorter data cannot be ciphered in this mode.

Returns
The minimum message size.

Implemented in ts::DVBCSA2, ts::DVS042< CIPHER >, ts::DVS042< AES >, ts::DVS042< DES >, ts::CTS1< CIPHER >, ts::CTS3< CIPHER >, ts::CTS2< CIPHER >, ts::CTS4< CIPHER >, ts::CBC< CIPHER >, and ts::ECB< CIPHER >.

◆ residueAllowed()

virtual bool ts::CipherChaining::residueAllowed ( ) const
pure virtualinherited

Check if the chaining mode can process residue after the last multiple of the block size.

Returns
True if the chaining mode can process residue after the last multiple of the block size.

Implemented in ts::DVBCSA2, ts::DVS042< CIPHER >, ts::DVS042< AES >, ts::DVS042< DES >, ts::CTS1< CIPHER >, ts::CTS3< CIPHER >, ts::CTS2< CIPHER >, ts::CTS4< CIPHER >, ts::CBC< CIPHER >, and ts::ECB< CIPHER >.

◆ name()

virtual UString ts::BlockCipher::name ( ) const
pure virtualinherited

◆ encrypt()

virtual bool ts::BlockCipher::encrypt ( const void *  plain,
size_t  plain_length,
void *  cipher,
size_t  cipher_maxsize,
size_t *  cipher_length = 0 
)
pure virtualinherited

Encrypt one block of data.

For pure block ciphers such as AES or DES, the plain text and cipher text must have the block size of the algorithm. For cipher chainings, the acceptable message sizes depend on the chaining mode.

Parameters
[in]plainAddress of plain text.
[in]plain_lengthPlain text length in bytes.
[out]cipherAddress of buffer for cipher text.
[in]cipher_maxsizeSize of cipher buffer.
[out]cipher_lengthReturned actual size of cipher text. Ignored if zero.
Returns
True on success, false on error.

Implemented in ts::DVBCSA2, ts::DVS042< CIPHER >, ts::DVS042< AES >, ts::DVS042< DES >, ts::CTS1< CIPHER >, ts::CTS3< CIPHER >, ts::CTS2< CIPHER >, ts::CTS4< CIPHER >, ts::AES, ts::CBC< CIPHER >, ts::ECB< CIPHER >, ts::DES, and ts::TDES.

◆ decrypt()

virtual bool ts::BlockCipher::decrypt ( const void *  cipher,
size_t  cipher_length,
void *  plain,
size_t  plain_maxsize,
size_t *  plain_length = 0 
)
pure virtualinherited

Decrypt one block of data.

For pure block ciphers such as AES or DES, the plain text and cipher text must have the block size of the algorithm. For cipher chainings, the acceptable message sizes depend on the chaining mode.

Parameters
[in]cipherAddress of cipher text.
[in]cipher_lengthCipher text length in bytes.
[out]plainAddress of buffer for plain text.
[in]plain_maxsizeSize of plain buffer.
[out]plain_lengthReturned actual size of plain text. Ignored if zero.
Returns
True on success, false on error.

Implemented in ts::DVBCSA2, ts::DVS042< CIPHER >, ts::DVS042< AES >, ts::DVS042< DES >, ts::CTS1< CIPHER >, ts::CTS3< CIPHER >, ts::CTS2< CIPHER >, ts::CTS4< CIPHER >, ts::AES, ts::CBC< CIPHER >, ts::ECB< CIPHER >, ts::DES, and ts::TDES.

◆ encryptInPlace()

virtual bool ts::BlockCipher::encryptInPlace ( void *  data,
size_t  data_length,
size_t *  max_actual_length = 0 
)
virtualinherited

Encrypt one block of data in place.

The default implementation is to call encrypt() and copy the data. A subclass may provide a more efficient implementation.

For pure block ciphers such as AES or DES, the plain text and cipher text must have the block size of the algorithm. For cipher chainings, the acceptable message sizes depend on the chaining mode.

Parameters
[in,out]dataAddress of data buffer to encrypt.
[in]data_lengthInput plain text length in bytes.
[in,out]max_actual_lengthOptional, ignored if zero. On input, contain the maximum size of the data buffer, which can be larger than data_length. On output, receive the actual size of the encrypted data. For pure block ciphers, this is the same as data_length. For cipher chainings with padding, this can be larger.
Returns
True on success, false on error.

Reimplemented in ts::DVBCSA2.

◆ decryptInPlace()

virtual bool ts::BlockCipher::decryptInPlace ( void *  data,
size_t  data_length,
size_t *  max_actual_length = 0 
)
virtualinherited

Decrypt one block of data in place.

The default implementation is to call decrypt() and copy the data. A subclass may provide a more efficient implementation.

For pure block ciphers such as AES or DES, the plain text and cipher text must have the block size of the algorithm. For cipher chainings, the acceptable message sizes depend on the chaining mode.

Parameters
[in,out]dataAddress of data buffer to decrypt.
[in]data_lengthInput cipher text length in bytes.
[in,out]max_actual_lengthOptional, ignored if zero. On input, contain the maximum size of the data buffer, which can be larger than data_length. On output, receive the actual size of the decrypted data. For pure block ciphers, this is the same as data_length. For cipher chainings with padding, this can be smaller.
Returns
True on success, false on error.

Reimplemented in ts::DVBCSA2.


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