Abstract interface of block ciphers. More...
Public Member Functions | |
BlockCipher () | |
Constructor. | |
virtual | ~BlockCipher () |
Virtual destructor. | |
virtual size_t | blockSize () const =0 |
Size in bytes of the block used by the algorithm. More... | |
int | cipherId () const |
Get the "cipher id" value, as previously stored by the application. More... | |
bool | decrypt (const void *cipher, size_t cipher_length, void *plain, size_t plain_maxsize, size_t *plain_length=nullptr) |
Decrypt one block of data. More... | |
bool | decryptInPlace (void *data, size_t data_length, size_t *max_actual_length=nullptr) |
Decrypt one block of data in place. More... | |
size_t | decryptionCount () const |
Get the number of times the current key was used for decryption. More... | |
size_t | decryptionMax () const |
Get the maximum number of times a key should be used for decryption. More... | |
virtual size_t | defaultRounds () const =0 |
Default number of rounds for the algorithm. More... | |
bool | encrypt (const void *plain, size_t plain_length, void *cipher, size_t cipher_maxsize, size_t *cipher_length=nullptr) |
Encrypt one block of data. More... | |
bool | encryptInPlace (void *data, size_t data_length, size_t *max_actual_length=nullptr) |
Encrypt one block of data in place. More... | |
size_t | encryptionCount () const |
Get the number of times the current key was used for encryption. More... | |
size_t | encryptionMax () const |
Get the maximum number of times a key should be used for encryption. More... | |
bool | getKey (ByteBlock &key) const |
Get the current key. 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... | |
void | setAlertHandler (BlockCipherAlertInterface *handler) |
Set the handler to be notified on alert. More... | |
void | setCipherId (int id) |
Set some arbitrary "cipher id" value. More... | |
void | setDecryptionMax (size_t count) |
Set the maximum number of times a key should be used for decryption. More... | |
void | setEncryptionMax (size_t count) |
Set the maximum number of times a key should be used for encryption. More... | |
bool | setKey (const void *key, size_t key_length, size_t rounds=0) |
Schedule a new key. More... | |
Static Public Attributes | |
static constexpr size_t | UNLIMITED = std::numeric_limits<size_t>::max() |
A constant meaning "may use a key an unlimited number of times". | |
Protected Member Functions | |
virtual bool | decryptImpl (const void *cipher, size_t cipher_length, void *plain, size_t plain_maxsize, size_t *plain_length)=0 |
Decrypt one block of data (implementation of algorithm-specific part). More... | |
virtual bool | decryptInPlaceImpl (void *data, size_t data_length, size_t *max_actual_length) |
Decrypt one block of data in place (implementation of algorithm-specific part). More... | |
virtual bool | encryptImpl (const void *plain, size_t plain_length, void *cipher, size_t cipher_maxsize, size_t *cipher_length)=0 |
Encrypt one block of data (implementation of algorithm-specific part). More... | |
virtual bool | encryptInPlaceImpl (void *data, size_t data_length, size_t *max_actual_length) |
Encrypt one block of data in place (implementation of algorithm-specific part). More... | |
virtual bool | setKeyImpl (const void *key, size_t key_length, size_t rounds)=0 |
Schedule a new key (implementation of algorithm-specific part). More... | |
Abstract interface of block ciphers.
|
pure virtual |
Algorithm name (informational only).
Implemented in ts::TDES, ts::SCTE52_2008, ts::SCTE52_2003, ts::IDSA, ts::ECB< CIPHER >, ts::DVS042< CIPHER >, ts::DVBCSA2, ts::DVBCISSA, ts::DES, ts::CTS4< CIPHER >, ts::CTS3< CIPHER >, ts::CTS2< CIPHER >, ts::CTS1< CIPHER >, ts::CTR< CIPHER >, ts::CBC< CIPHER >, and ts::AES.
|
pure virtual |
Size in bytes of the block used by the algorithm.
Implemented in ts::TDES, ts::DVBCSA2, ts::DES, ts::CipherChaining, and ts::AES.
|
pure virtual |
Minimum key sizes in bytes.
Implemented in ts::TDES, ts::DVBCSA2, ts::DES, ts::CipherChaining, and ts::AES.
|
pure virtual |
Maximum key sizes in bytes.
Implemented in ts::TDES, ts::DVBCSA2, ts::DES, ts::CipherChaining, and ts::AES.
|
pure virtual |
Check if a size in bytes is a valid key size.
[in] | size | Suggested key size in bytes. |
Implemented in ts::TDES, ts::DVBCSA2, ts::DES, ts::CipherChaining, and ts::AES.
|
pure virtual |
Minimum number of rounds for the algorithm.
Implemented in ts::TDES, ts::DVBCSA2, ts::DES, ts::CipherChaining, and ts::AES.
|
pure virtual |
Maximum number of rounds for the algorithm.
Implemented in ts::TDES, ts::DVBCSA2, ts::DES, ts::CipherChaining, and ts::AES.
|
pure virtual |
Default number of rounds for the algorithm.
Implemented in ts::TDES, ts::DVBCSA2, ts::DES, ts::CipherChaining, and ts::AES.
bool ts::BlockCipher::setKey | ( | const void * | key, |
size_t | key_length, | ||
size_t | rounds = 0 |
||
) |
Schedule a new key.
[in] | key | Address of key value. |
[in] | key_length | Key length in bytes. |
[in] | rounds | Requested number of rounds. If zero, the default is used. |
bool ts::BlockCipher::getKey | ( | ByteBlock & | key | ) | const |
Get the current key.
[out] | key | Current key value. |
bool ts::BlockCipher::encrypt | ( | const void * | plain, |
size_t | plain_length, | ||
void * | cipher, | ||
size_t | cipher_maxsize, | ||
size_t * | cipher_length = nullptr |
||
) |
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.
[in] | plain | Address of plain text. |
[in] | plain_length | Plain text length in bytes. |
[out] | cipher | Address of buffer for cipher text. |
[in] | cipher_maxsize | Size of cipher buffer. |
[out] | cipher_length | Returned actual size of cipher text. Ignored if zero. |
bool ts::BlockCipher::decrypt | ( | const void * | cipher, |
size_t | cipher_length, | ||
void * | plain, | ||
size_t | plain_maxsize, | ||
size_t * | plain_length = nullptr |
||
) |
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.
[in] | cipher | Address of cipher text. |
[in] | cipher_length | Cipher text length in bytes. |
[out] | plain | Address of buffer for plain text. |
[in] | plain_maxsize | Size of plain buffer. |
[out] | plain_length | Returned actual size of plain text. Ignored if zero. |
bool ts::BlockCipher::encryptInPlace | ( | void * | data, |
size_t | data_length, | ||
size_t * | max_actual_length = nullptr |
||
) |
Encrypt one block of data in place.
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.
[in,out] | data | Address of data buffer to encrypt. |
[in] | data_length | Input plain text length in bytes. |
[in,out] | max_actual_length | Optional, 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. |
bool ts::BlockCipher::decryptInPlace | ( | void * | data, |
size_t | data_length, | ||
size_t * | max_actual_length = nullptr |
||
) |
Decrypt one block of data in place.
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.
[in,out] | data | Address of data buffer to decrypt. |
[in] | data_length | Input cipher text length in bytes. |
[in,out] | max_actual_length | Optional, 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. |
|
inline |
Get the number of times the current key was used for encryption.
|
inline |
Get the number of times the current key was used for decryption.
|
inline |
Set the maximum number of times a key should be used for encryption.
The default initial value is UNLIMITED.
[in] | count | The maximum number of times a key should be used for encryption. |
|
inline |
Set the maximum number of times a key should be used for decryption.
The default initial value is UNLIMITED.
[in] | count | The maximum number of times a key should be used for decryption. |
|
inline |
Get the maximum number of times a key should be used for encryption.
|
inline |
Get the maximum number of times a key should be used for decryption.
|
inline |
Set the handler to be notified on alert.
Only one handler can be set at a time.
[in] | handler | Handler to set. Use a null pointer to remove the handler. |
|
inline |
Set some arbitrary "cipher id" value.
This value is chosen and set by the application and can be retrieved later. The cipher id is not interpreted by the block cipher engine, it is only stored for the application. The initial value of a cipher id is zero.
[in] | id | Application-defined cipher id to assign. |
|
inline |
Get the "cipher id" value, as previously stored by the application.
|
protectedpure virtual |
Schedule a new key (implementation of algorithm-specific part).
[in] | key | Address of key value. |
[in] | key_length | Key length in bytes. |
[in] | rounds | Requested number of rounds. If zero, the default is used. |
Implemented in ts::TDES, ts::DVBCSA2, ts::DES, ts::CipherChaining, and ts::AES.
|
protectedpure virtual |
Encrypt one block of data (implementation of algorithm-specific part).
[in] | plain | Address of plain text. |
[in] | plain_length | Plain text length in bytes. |
[out] | cipher | Address of buffer for cipher text. |
[in] | cipher_maxsize | Size of cipher buffer. |
[out] | cipher_length | Returned actual size of cipher text. Ignored if zero. |
Implemented in ts::TDES, ts::ECB< CIPHER >, ts::DVS042< CIPHER >, ts::DVS042< AES >, ts::DVS042< DES >, ts::DVBCSA2, ts::DES, ts::CTS4< CIPHER >, ts::CTS3< CIPHER >, ts::CTS2< CIPHER >, ts::CTS1< CIPHER >, ts::CTR< CIPHER >, ts::CTR< ts::AES >, ts::CBC< CIPHER >, ts::CBC< ts::AES >, ts::CBC< AES >, and ts::AES.
|
protectedpure virtual |
Decrypt one block of data (implementation of algorithm-specific part).
[in] | cipher | Address of cipher text. |
[in] | cipher_length | Cipher text length in bytes. |
[out] | plain | Address of buffer for plain text. |
[in] | plain_maxsize | Size of plain buffer. |
[out] | plain_length | Returned actual size of plain text. Ignored if zero. |
Implemented in ts::TDES, ts::ECB< CIPHER >, ts::DVS042< CIPHER >, ts::DVS042< AES >, ts::DVS042< DES >, ts::DVBCSA2, ts::DES, ts::CTS4< CIPHER >, ts::CTS3< CIPHER >, ts::CTS2< CIPHER >, ts::CTS1< CIPHER >, ts::CTR< CIPHER >, ts::CTR< ts::AES >, ts::CBC< CIPHER >, ts::CBC< ts::AES >, ts::CBC< AES >, and ts::AES.
|
protectedvirtual |
Encrypt one block of data in place (implementation of algorithm-specific part).
The default implementation is to call encryptImpl() and copy the data. A subclass may provide a more efficient implementation.
[in,out] | data | Address of data buffer to encrypt. |
[in] | data_length | Input plain text length in bytes. |
[in,out] | max_actual_length | Optional, 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. |
Reimplemented in ts::DVBCSA2.
|
protectedvirtual |
Decrypt one block of data in place (implementation of algorithm-specific part).
The default implementation is to call decryptImpl() and copy the data. A subclass may provide a more efficient implementation.
[in,out] | data | Address of data buffer to decrypt. |
[in] | data_length | Input cipher text length in bytes. |
[in,out] | max_actual_length | Optional, 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. |
Reimplemented in ts::DVBCSA2.