TSDuck v3.40-4034
MPEG Transport Stream Toolkit
|
DVB CSA-2 (Digital Video Broadcasting Common Scrambling Algorithm). More...
#include <tsDVBCSA2.h>
Public Types | |
enum | EntropyMode { FULL_CW , REDUCE_ENTROPY } |
Control word entropy reduction. More... | |
Public Member Functions | |
DVBCSA2 (EntropyMode mode=REDUCE_ENTROPY) | |
Default Constructor. | |
size_t | blockSize () const |
Size in bytes of the block used by the algorithm. | |
int | cipherId () const |
Get the "cipher id" value, as previously stored by the application. | |
const ByteBlock & | currentIV () const |
Get the current initialization vector. | |
const ByteBlock & | currentKey () const |
Get the current key. | |
bool | decrypt (const void *cipher, size_t cipher_length, void *plain, size_t plain_maxsize, size_t *plain_length=nullptr) |
Decrypt data. | |
size_t | decryptionCount () const |
Get the number of times the current key was used for decryption. | |
size_t | decryptionMax () const |
Get the maximum number of times a key should be used for decryption. | |
bool | encrypt (const void *plain, size_t plain_length, void *cipher, size_t cipher_maxsize, size_t *cipher_length=nullptr) |
Encrypt data. | |
size_t | encryptionCount () const |
Get the number of times the current key was used for encryption. | |
size_t | encryptionMax () const |
Get the maximum number of times a key should be used for encryption. | |
EntropyMode | entropyMode () const |
Get the entropy mode, used in setKey(). | |
bool | hasChainingMode () const |
Check if this object is a base encryption algorithm (one block) or includes a chaining mode. | |
bool | hasKey () const |
Check if a current key is present and valid. | |
virtual bool | isValidIVSize (size_t size) const |
Check if a size in bytes is a valid initialization vector size. | |
virtual bool | isValidKeySize (size_t size) const |
Check if a size in bytes is a valid key size. | |
size_t | maxIVSize () const |
Get the maximum initialization vector sizes in bytes. | |
size_t | maxKeySize () const |
Maximum key sizes in bytes. | |
size_t | minIVSize () const |
Get the minimum initialization vector sizes in bytes. | |
size_t | minKeySize () const |
Minimum key sizes in bytes. | |
size_t | minMessageSize () const |
Get the minimum message size. | |
UString | name () const |
Algorithm name (informational only). | |
bool | residueAllowed () const |
Check if the chaining mode can process residue after the last multiple of the block size. | |
void | setAlertHandler (BlockCipherAlertInterface *handler) |
Set the handler to be notified on alert. | |
void | setCipherId (int id) |
Set some arbitrary "cipher id" value. | |
void | setDecryptionMax (size_t count) |
Set the maximum number of times a key should be used for decryption. | |
void | setEncryptionMax (size_t count) |
Set the maximum number of times a key should be used for encryption. | |
void | setEntropyMode (EntropyMode mode) |
Set the entropy mode, used in setKey(). | |
bool | setIV (const ByteBlock &iv) |
Set a new initialization vector without changing the key, or before setting the key. | |
bool | setIV (const void *iv, size_t iv_length) |
Set a new initialization vector without changing the key, or before setting the key. | |
bool | setKey (const ByteBlock &key) |
Schedule a new key. | |
bool | setKey (const ByteBlock &key, const ByteBlock &iv) |
Schedule a new key and initialization vector. | |
bool | setKey (const void *key, size_t key_length, const void *iv=nullptr, size_t iv_length=0) |
Schedule a new key and optional initialization vector. | |
Static Public Member Functions | |
static bool | IsReducedCW (const uint8_t *cw) |
Check if a control word is entropy-reduced. | |
static void | ReduceCW (uint8_t *cw) |
Manually perform the entropy reduction on a control word. | |
Static Public Attributes | |
static constexpr size_t | BLOCK_SIZE = 8 |
DVB CSA-2 block size in bytes (informational only, not relevant to scrambling). | |
static constexpr size_t | KEY_BITS = 64 |
DVB CSA-2 control words size in bits. | |
static constexpr size_t | KEY_SIZE = KEY_BITS / 8 |
DVB CSA-2 control words size in bytes. | |
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 | |
void | canProcessInPlace (bool can_do) |
Inform the superclass that the subclass can encrypt and decrypt in place (identical in/out buffers). | |
virtual bool | decryptImpl (const void *cipher, size_t cipher_length, void *plain, size_t plain_maxsize, size_t *plain_length) override |
Decrypt one block of data (implementation of algorithm-specific part). | |
virtual bool | encryptImpl (const void *plain, size_t plain_length, void *cipher, size_t cipher_maxsize, size_t *cipher_length) override |
Encrypt one block of data (implementation of algorithm-specific part). | |
virtual const EVP_CIPHER * | getAlgorithm () const |
Get the EVP for the cipher algorithm, when the subclass uses OpenSSL. | |
virtual void | getAlgorithm (::BCRYPT_ALG_HANDLE &algo, size_t &length, bool &ignore_iv) const |
Get the algorithm handle and subobject size, when the subclass uses Microsoft BCrypt library. | |
virtual bool | setKeyImpl () override |
Schedule a new key and optional initialization vector (implementation of algorithm-specific part). | |
Static Protected Member Functions | |
static const BlockCipherProperties & | PROPERTIES () |
Properties of this algorithm. | |
Protected Attributes | |
const BlockCipherProperties & | properties |
Properties for this block cipher object instance. | |
ByteBlock | work {} |
Temporary working buffer. | |
DVB CSA-2 (Digital Video Broadcasting Common Scrambling Algorithm).
ts::DVBCSA2::DVBCSA2 | ( | EntropyMode | mode = REDUCE_ENTROPY | ) |
Default Constructor.
[in] | mode | Entropy reduction mode. |
|
inline |
Set the entropy mode, used in setKey().
[in] | mode | Entropy reduction mode. |
|
inline |
Get the entropy mode, used in setKey().
|
static |
Manually perform the entropy reduction on a control word.
Not needed with ts::DVBCSA2 class, preferably use REDUCE_ENTROPY mode.
[in,out] | cw | Address of a control word to reduce. Its size must be ts::DVBCSA2::KEY_SIZE. |
|
static |
Check if a control word is entropy-reduced.
[in] | cw | Address of a control word. Its size must be ts::DVBCSA2::KEY_SIZE. |
|
inlinestaticprotected |
Properties of this algorithm.
|
overrideprotectedvirtual |
Schedule a new key and optional initialization vector (implementation of algorithm-specific part).
Must be implemented by the subclass if it does not use the system-provided cryptographic library.
Reimplemented from ts::BlockCipher.
|
overrideprotectedvirtual |
Encrypt one block of data (implementation of algorithm-specific part).
Must be implemented by the subclass if it does not use the system-provided cryptographic library.
[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. |
Reimplemented from ts::BlockCipher.
|
overrideprotectedvirtual |
Decrypt one block of data (implementation of algorithm-specific part).
Must be implemented by the subclass if it does not use the system-provided cryptographic library.
[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. |
Reimplemented from ts::BlockCipher.
|
inherited |
Algorithm name (informational only).
|
inlineinherited |
Size in bytes of the block used by the algorithm.
|
inlineinherited |
Minimum key sizes in bytes.
|
inlineinherited |
Maximum key sizes in bytes.
|
virtualinherited |
Check if a size in bytes is a valid key size.
[in] | size | Suggested key size in bytes. |
|
virtualinherited |
Check if a size in bytes is a valid initialization vector size.
[in] | size | Suggested IV size in bytes. |
|
inlineinherited |
Check if this object is a base encryption algorithm (one block) or includes a chaining mode.
|
inlineinherited |
Get the minimum initialization vector sizes in bytes.
|
inlineinherited |
Get the maximum initialization vector sizes in bytes.
|
inlineinherited |
Get the minimum message size.
Shorter data cannot be ciphered in this mode.
|
inlineinherited |
Check if the chaining mode can process residue after the last multiple of the block size.
|
inherited |
Schedule a new key and optional initialization vector.
[in] | key | Address of key value. |
[in] | key_length | Key length in bytes. |
[in] | iv | Address of IV value (for chaining mode only). |
[in] | iv_length | IV length in bytes (for chaining mode only). |
|
inlineinherited |
Schedule a new key.
[in] | key | Key value. |
Schedule a new key and initialization vector.
[in] | key | Key value. |
[in] | iv | IV value (for chaining mode only). |
|
inherited |
Set a new initialization vector without changing the key, or before setting the key.
Note that if you need to set the key and IV, it is usually much more efficient to do it in one call instead of two (and not only because of te two calls).
[in] | iv | Address of IV value (for chaining mode only). |
[in] | iv_length | IV length in bytes (for chaining mode only). |
|
inlineinherited |
Set a new initialization vector without changing the key, or before setting the key.
Note that if you need to set the key and IV, it is usually much more efficient to do it in one call instead of two (and not only because of te two calls).
[in] | iv | IV value (for chaining mode only). |
|
inlineinherited |
Check if a current key is present and valid.
|
inlineinherited |
Get the current key.
|
inlineinherited |
Get the current initialization vector.
|
inherited |
Encrypt 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.
Plain and cipher buffers may be identical (start at the same location). If they don't start at the same address, they may not overlap.
[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. |
|
inherited |
Decrypt 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.
Plain and cipher buffers may be identical (start at the same location). If they don't start at the same address, they may not overlap.
[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. |
|
inlineinherited |
Get the number of times the current key was used for encryption.
|
inlineinherited |
Get the number of times the current key was used for decryption.
|
inlineinherited |
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. |
|
inlineinherited |
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. |
|
inlineinherited |
Get the maximum number of times a key should be used for encryption.
|
inlineinherited |
Get the maximum number of times a key should be used for decryption.
|
inlineinherited |
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. |
|
inlineinherited |
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. |
|
inlineinherited |
Get the "cipher id" value, as previously stored by the application.
|
inlineprotectedinherited |
Inform the superclass that the subclass can encrypt and decrypt in place (identical in/out buffers).
Typically called by a subclass in constructor.
[in] | can_do | If true, encrypt and decrypt in place is possible. |
|
protectedvirtualinherited |
Get the algorithm handle and subobject size, when the subclass uses Microsoft BCrypt library.
[out] | algo | Handle to hash algorithm. |
[out] | length | Length in bytes of the subobject to allocate. |
[out] | ignore_iv | The IV shall not be passed to BCrypt. |
Reimplemented in ts::AES128, ts::AES256, ts::DES, and ts::TDES.
|
protectedvirtualinherited |
Get the EVP for the cipher algorithm, when the subclass uses OpenSSL.
|
protectedinherited |
Properties for this block cipher object instance.
Accessible to subclasses, but constant.