TSDuck Version 3.16-1064 (TSDuck - The MPEG Transport Stream Toolkit)
ts::BlockCipher Class Referenceabstract

Abstract interface of block ciphers. More...

Inheritance diagram for ts::BlockCipher:

Public Member Functions

virtual ~BlockCipher ()
 Virtual destructor.
 
virtual size_t blockSize () const =0
 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=nullptr)=0
 Decrypt one block of data. More...
 
virtual bool decryptInPlace (void *data, size_t data_length, size_t *max_actual_length=nullptr)
 Decrypt one block of data in place. More...
 
virtual size_t defaultRounds () const =0
 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=nullptr)=0
 Encrypt one block of data. More...
 
virtual bool encryptInPlace (void *data, size_t data_length, size_t *max_actual_length=nullptr)
 Encrypt one block of data in place. More...
 
virtual bool isValidKeySize (size_t size) const =0
 Check if a size in bytes is a valid key size. More...
 
virtual size_t maxKeySize () const =0
 Maximum key sizes in bytes. More...
 
virtual size_t maxRounds () const =0
 Maximum number of rounds for the algorithm. More...
 
virtual size_t minKeySize () const =0
 Minimum key sizes in bytes. More...
 
virtual size_t minRounds () const =0
 Minimum number of rounds for the algorithm. More...
 
virtual UString name () const =0
 Algorithm name (informational only). More...
 
virtual bool setKey (const void *key, size_t key_length, size_t rounds=0)=0
 Schedule a new key. More...
 

Detailed Description

Abstract interface of block ciphers.

Member Function Documentation

◆ name()

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

◆ blockSize()

virtual size_t ts::BlockCipher::blockSize ( ) const
pure virtual

Size in bytes of the block used by the algorithm.

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

Implemented in ts::DVBCSA2, ts::AES, ts::CipherChaining, ts::DES, and ts::TDES.

◆ minKeySize()

virtual size_t ts::BlockCipher::minKeySize ( ) const
pure virtual

Minimum key sizes in bytes.

Returns
The minimum key sizes in bytes.

Implemented in ts::DVBCSA2, ts::AES, ts::CipherChaining, ts::DES, and ts::TDES.

◆ maxKeySize()

virtual size_t ts::BlockCipher::maxKeySize ( ) const
pure virtual

Maximum key sizes in bytes.

Returns
The maximum key sizes in bytes.

Implemented in ts::DVBCSA2, ts::AES, ts::CipherChaining, ts::DES, and ts::TDES.

◆ isValidKeySize()

virtual bool ts::BlockCipher::isValidKeySize ( size_t  size) const
pure virtual

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.

Implemented in ts::DVBCSA2, ts::AES, ts::CipherChaining, ts::DES, and ts::TDES.

◆ minRounds()

virtual size_t ts::BlockCipher::minRounds ( ) const
pure virtual

Minimum number of rounds for the algorithm.

Returns
The minimum number of rounds for the algorithm.

Implemented in ts::DVBCSA2, ts::AES, ts::CipherChaining, ts::DES, and ts::TDES.

◆ maxRounds()

virtual size_t ts::BlockCipher::maxRounds ( ) const
pure virtual

Maximum number of rounds for the algorithm.

Returns
The maximum number of rounds for the algorithm.

Implemented in ts::DVBCSA2, ts::AES, ts::CipherChaining, ts::DES, and ts::TDES.

◆ defaultRounds()

virtual size_t ts::BlockCipher::defaultRounds ( ) const
pure virtual

Default number of rounds for the algorithm.

Returns
The default number of rounds for the algorithm.

Implemented in ts::DVBCSA2, ts::AES, ts::CipherChaining, ts::DES, and ts::TDES.

◆ setKey()

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

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.

Implemented in ts::DVBCSA2, ts::AES, ts::DES, ts::TDES, and ts::CipherChaining.

◆ encrypt()

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

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 = nullptr 
)
pure virtual

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 = nullptr 
)
virtual

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 = nullptr 
)
virtual

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: