Botan 3.6.1
Crypto and TLS for C&
|
#include <stream_cipher.h>
Public Member Functions | |
virtual size_t | buffer_size () const =0 |
void | cipher (const uint8_t in[], uint8_t out[], size_t len) |
void | cipher (std::span< const uint8_t > in, std::span< uint8_t > out) |
void | cipher1 (std::span< uint8_t > buf) |
void | cipher1 (uint8_t buf[], size_t len) |
virtual void | clear ()=0 |
StreamCipher * | clone () const |
void | decrypt (std::span< uint8_t > inout) |
virtual size_t | default_iv_length () const |
void | encipher (std::span< uint8_t > inout) |
void | encrypt (std::span< uint8_t > inout) |
virtual bool | has_keying_material () const =0 |
virtual Key_Length_Specification | key_spec () const =0 |
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>> | |
T | keystream_bytes (size_t bytes) |
size_t | maximum_keylength () const |
size_t | minimum_keylength () const |
virtual std::string | name () const =0 |
virtual std::unique_ptr< StreamCipher > | new_object () const =0 |
virtual std::string | provider () const |
virtual void | seek (uint64_t offset)=0 |
void | set_iv (const uint8_t iv[], size_t iv_len) |
void | set_iv (std::span< const uint8_t > iv) |
void | set_key (const SymmetricKey &key) |
void | set_key (const uint8_t key[], size_t length) |
void | set_key (std::span< const uint8_t > key) |
virtual bool | valid_iv_length (size_t iv_len) const |
bool | valid_keylength (size_t length) const |
void | write_keystream (std::span< uint8_t > out) |
void | write_keystream (uint8_t out[], size_t len) |
~StreamCipher () override=default | |
Static Public Member Functions | |
static std::unique_ptr< StreamCipher > | create (std::string_view algo_spec, std::string_view provider="") |
static std::unique_ptr< StreamCipher > | create_or_throw (std::string_view algo_spec, std::string_view provider="") |
static std::vector< std::string > | providers (std::string_view algo_spec) |
Protected Member Functions | |
void | assert_key_material_set () const |
void | assert_key_material_set (bool predicate) const |
virtual void | cipher_bytes (const uint8_t in[], uint8_t out[], size_t len)=0 |
virtual void | generate_keystream (uint8_t out[], size_t len) |
virtual void | set_iv_bytes (const uint8_t iv[], size_t iv_len)=0 |
Base class for all stream ciphers
Definition at line 23 of file stream_cipher.h.
|
overridedefault |
|
inlineprotectedinherited |
Definition at line 139 of file sym_algo.h.
References Botan::SymmetricAlgorithm::assert_key_material_set().
Referenced by Botan::SymmetricAlgorithm::assert_key_material_set(), Botan::Salsa20::cipher_bytes(), Botan::AES_128::decrypt_n(), Botan::AES_192::decrypt_n(), Botan::AES_256::decrypt_n(), Botan::ARIA_128::decrypt_n(), Botan::ARIA_192::decrypt_n(), Botan::ARIA_256::decrypt_n(), Botan::Blowfish::decrypt_n(), Botan::Camellia_128::decrypt_n(), Botan::Camellia_192::decrypt_n(), Botan::Camellia_256::decrypt_n(), Botan::CAST_128::decrypt_n(), Botan::DES::decrypt_n(), Botan::GOST_28147_89::decrypt_n(), Botan::IDEA::decrypt_n(), Botan::Kuznyechik::decrypt_n(), Botan::Lion::decrypt_n(), Botan::Noekeon::decrypt_n(), Botan::SEED::decrypt_n(), Botan::Serpent::decrypt_n(), Botan::SHACAL2::decrypt_n(), Botan::SM4::decrypt_n(), Botan::Threefish_512::decrypt_n(), Botan::TripleDES::decrypt_n(), Botan::Twofish::decrypt_n(), Botan::AES_128::encrypt_n(), Botan::AES_192::encrypt_n(), Botan::AES_256::encrypt_n(), Botan::ARIA_128::encrypt_n(), Botan::ARIA_192::encrypt_n(), Botan::ARIA_256::encrypt_n(), Botan::Blowfish::encrypt_n(), Botan::Camellia_128::encrypt_n(), Botan::Camellia_192::encrypt_n(), Botan::Camellia_256::encrypt_n(), Botan::CAST_128::encrypt_n(), Botan::DES::encrypt_n(), Botan::GOST_28147_89::encrypt_n(), Botan::IDEA::encrypt_n(), Botan::Kuznyechik::encrypt_n(), Botan::Lion::encrypt_n(), Botan::Noekeon::encrypt_n(), Botan::SEED::encrypt_n(), Botan::Serpent::encrypt_n(), Botan::SHACAL2::encrypt_n(), Botan::SM4::encrypt_n(), Botan::Threefish_512::encrypt_n(), Botan::TripleDES::encrypt_n(), Botan::Twofish::encrypt_n(), Botan::GHASH::final(), Botan::GHASH::ghash_update(), Botan::ChaCha::seek(), Botan::CTR_BE::seek(), Botan::Salsa20::seek(), Botan::OCB_Mode::set_associated_data_n(), Botan::Salsa20::set_iv_bytes(), Botan::GHASH::update(), and Botan::GHASH::update_associated_data().
|
inlineprotectedinherited |
Definition at line 141 of file sym_algo.h.
|
pure virtual |
Return the optimium buffer size to use with this cipher
Most stream ciphers internally produce blocks of bytes. This function returns that block size. Aligning buffer sizes to a multiple of this size may improve performance by reducing internal buffering overhead.
Note the return value of this function may change for any particular algorithm due to changes in the implementation from release to release, or changes in the runtime environment (such as CPUID indicating availability of an optimized implementation). It is not intrinsic to the algorithm; it is just a suggestion for gaining best performance.
Implemented in Botan::ChaCha, Botan::CTR_BE, Botan::OFB, Botan::RC4, Botan::Salsa20, and Botan::SHAKE_Cipher.
|
inline |
Encrypt or decrypt a message
Processes all bytes plain/ciphertext from in
and writes the result to out
.
in | the plaintext |
out | the byte array to hold the output, i.e. the ciphertext |
len | the length of both in and out in bytes |
Definition at line 60 of file stream_cipher.h.
Referenced by create(), Botan::Sodium::crypto_stream_salsa20_xor_ic(), and Botan::Sodium::crypto_stream_xsalsa20_xor_ic().
|
inline |
Encrypt or decrypt a message
in | the plaintext |
out | the byte array to hold the output, i.e. the ciphertext with at least the same size as in |
Definition at line 68 of file stream_cipher.h.
References BOTAN_ARG_CHECK.
|
inline |
Encrypt or decrypt a message The message is encrypted/decrypted in place.
buf | the plaintext / ciphertext |
Definition at line 120 of file stream_cipher.h.
|
inline |
Encrypt or decrypt a message The message is encrypted/decrypted in place.
buf | the plaintext / ciphertext |
len | the length of buf in bytes |
Definition at line 113 of file stream_cipher.h.
Referenced by generate_keystream().
|
protectedpure virtual |
Encrypt or decrypt a message
Implemented in Botan::Salsa20.
|
pure virtualinherited |
Reset the internal state. This includes not just the key, but any partial message that may have been in process.
Implemented in Botan::AES_128, Botan::AES_192, Botan::AES_256, Botan::ANSI_X919_MAC, Botan::ARIA_128, Botan::ARIA_192, Botan::ARIA_256, Botan::BLAKE2b, Botan::BLAKE2bMAC, Botan::Blowfish, Botan::Camellia_128, Botan::Camellia_192, Botan::Camellia_256, Botan::Cascade_Cipher, Botan::CAST_128, Botan::CBC_Mode, Botan::CCM_Mode, Botan::CFB_Mode, Botan::ChaCha20Poly1305_Mode, Botan::ChaCha, Botan::CMAC, Botan::CTR_BE, Botan::DES, Botan::EAX_Mode, Botan::FPE_FE1, Botan::GCM_Mode, Botan::GHASH, Botan::GMAC, Botan::GOST_28147_89, Botan::HMAC, Botan::IDEA, Botan::KMAC, Botan::Kuznyechik, Botan::Lion, Botan::Noekeon, Botan::OCB_Mode, Botan::OFB, Botan::Poly1305, Botan::RC4, Botan::Salsa20, Botan::SEED, Botan::Serpent, Botan::SHACAL2, Botan::SHAKE_Cipher, Botan::SipHash, Botan::SIV_Mode, Botan::SM4, Botan::Threefish_512, Botan::TLS::TLS_CBC_HMAC_AEAD_Mode, Botan::TripleDES, Botan::Twofish, and Botan::XTS_Mode.
Referenced by Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::clear().
|
inline |
Definition at line 199 of file stream_cipher.h.
|
static |
Create an instance based on a name If provider is empty then best available is chosen.
algo_spec | algorithm name |
provider | provider implementation to use |
Definition at line 40 of file stream_cipher.cpp.
References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_as_integer(), Botan::SCAN_Name::arg_count(), Botan::SCAN_Name::arg_count_between(), BOTAN_UNUSED, cipher(), Botan::BlockCipher::create(), and provider().
Referenced by Botan::BlockCipher::create(), Botan::Cipher_Mode::create(), and create_or_throw().
|
static |
Create an instance based on a name If provider is empty then best available is chosen.
algo_spec | algorithm name |
provider | provider implementation to use Throws a Lookup_Error if the algo/provider combination cannot be found |
Definition at line 122 of file stream_cipher.cpp.
References create(), and provider().
Referenced by Botan::ChaCha_RNG::ChaCha_RNG(), Botan::ChaCha_RNG::ChaCha_RNG(), Botan::ChaCha_RNG::ChaCha_RNG(), Botan::ChaCha_RNG::ChaCha_RNG(), Botan::ChaCha_RNG::ChaCha_RNG(), Botan::Sodium::crypto_secretbox_detached(), Botan::Sodium::crypto_secretbox_open_detached(), Botan::Sodium::crypto_secretbox_xsalsa20poly1305(), Botan::Sodium::crypto_secretbox_xsalsa20poly1305_open(), Botan::Sodium::crypto_stream_chacha20(), Botan::Sodium::crypto_stream_chacha20_ietf(), Botan::Sodium::crypto_stream_chacha20_ietf_xor_ic(), Botan::Sodium::crypto_stream_chacha20_xor_ic(), Botan::Sodium::crypto_stream_xchacha20(), and Botan::Sodium::crypto_stream_xchacha20_xor_ic().
|
inline |
Decrypt a message in place The message is decrypted in place.
inout | the plaintext / ciphertext |
Definition at line 141 of file stream_cipher.h.
|
virtual |
Return the default (preferred) nonce length
If this function returns zero, then this cipher does not support nonces; in this case any call to set_iv with a (non-empty) value will fail.
Default implementation returns 0
Reimplemented in Botan::ChaCha, Botan::CTR_BE, Botan::OFB, and Botan::Salsa20.
Definition at line 133 of file stream_cipher.cpp.
|
inline |
Encrypt a message The message is encrypted/decrypted in place.
inout | the plaintext / ciphertext |
Definition at line 127 of file stream_cipher.h.
|
inline |
Encrypt a message The message is encrypted in place.
inout | the plaintext / ciphertext |
Definition at line 134 of file stream_cipher.h.
|
protectedvirtual |
Write keystream bytes to a buffer
Definition at line 137 of file stream_cipher.cpp.
References cipher1(), and Botan::clear_mem().
|
pure virtualinherited |
Implemented in Botan::AES_128, Botan::AES_192, Botan::AES_256, Botan::ANSI_X919_MAC, Botan::ARIA_128, Botan::ARIA_192, Botan::ARIA_256, Botan::BLAKE2b, Botan::BLAKE2bMAC, Botan::Blowfish, Botan::Camellia_128, Botan::Camellia_192, Botan::Camellia_256, Botan::Cascade_Cipher, Botan::CAST_128, Botan::CBC_Mode, Botan::CCM_Mode, Botan::CFB_Mode, Botan::ChaCha20Poly1305_Mode, Botan::ChaCha, Botan::CMAC, Botan::CTR_BE, Botan::DES, Botan::EAX_Mode, Botan::FPE_FE1, Botan::GCM_Mode, Botan::GHASH, Botan::GMAC, Botan::GOST_28147_89, Botan::HMAC, Botan::IDEA, Botan::KMAC, Botan::Kuznyechik, Botan::Lion, Botan::Noekeon, Botan::OCB_Mode, Botan::OFB, Botan::Poly1305, Botan::RC4, Botan::Salsa20, Botan::SEED, Botan::Serpent, Botan::SHACAL2, Botan::SHAKE_Cipher, Botan::SipHash, Botan::SIV_Mode, Botan::SM4, Botan::Threefish_512, Botan::TLS::TLS_CBC_HMAC_AEAD_Mode, Botan::TripleDES, Botan::Twofish, and Botan::XTS_Mode.
Referenced by Botan::TLS::TLS_CBC_HMAC_AEAD_Mode::has_keying_material().
|
pure virtualinherited |
Implemented in Botan::ANSI_X919_MAC, Botan::BLAKE2b, Botan::BLAKE2bMAC, Botan::Block_Cipher_Fixed_Params< BS, KMIN, KMAX, KMOD, BaseClass >, Botan::Block_Cipher_Fixed_Params< 16, 16 >, Botan::Block_Cipher_Fixed_Params< 16, 16, 32, 8 >, Botan::Block_Cipher_Fixed_Params< 16, 24 >, Botan::Block_Cipher_Fixed_Params< 16, 32 >, Botan::Block_Cipher_Fixed_Params< 32, 16, 64, 4 >, Botan::Block_Cipher_Fixed_Params< 64, 64, 0, 1, Tweakable_Block_Cipher >, Botan::Block_Cipher_Fixed_Params< 8, 1, 56 >, Botan::Block_Cipher_Fixed_Params< 8, 11, 16 >, Botan::Block_Cipher_Fixed_Params< 8, 16 >, Botan::Block_Cipher_Fixed_Params< 8, 16, 24, 8 >, Botan::Block_Cipher_Fixed_Params< 8, 32 >, Botan::Block_Cipher_Fixed_Params< 8, 8 >, Botan::Cascade_Cipher, Botan::CBC_Mode, Botan::CCM_Mode, Botan::CFB_Mode, Botan::ChaCha20Poly1305_Mode, Botan::ChaCha, Botan::CMAC, Botan::CTR_BE, Botan::EAX_Mode, Botan::FPE_FE1, Botan::GCM_Mode, Botan::GHASH, Botan::GMAC, Botan::HMAC, Botan::KMAC, Botan::Lion, Botan::OCB_Mode, Botan::OFB, Botan::Poly1305, Botan::RC4, Botan::Salsa20, Botan::SHAKE_Cipher, Botan::SipHash, Botan::SIV_Mode, Botan::TLS::TLS_CBC_HMAC_AEAD_Mode, and Botan::XTS_Mode.
Referenced by Botan::CBC_Mode::key_spec(), Botan::CFB_Mode::key_spec(), and Botan::XTS_Mode::key_spec().
|
inline |
Get bytes
from the keystream
The bytes are written into a continous byte buffer of your choosing.
bytes | The number of bytes to be produced |
Definition at line 101 of file stream_cipher.h.
References T.
|
inlineinherited |
Definition at line 95 of file sym_algo.h.
|
inlineinherited |
Definition at line 100 of file sym_algo.h.
|
pure virtualinherited |
Implemented in Botan::AES_128, Botan::AES_192, Botan::AES_256, Botan::ANSI_X919_MAC, Botan::ARIA_128, Botan::ARIA_192, Botan::ARIA_256, Botan::BLAKE2b, Botan::BLAKE2bMAC, Botan::Blowfish, Botan::Camellia_128, Botan::Camellia_192, Botan::Camellia_256, Botan::Cascade_Cipher, Botan::CAST_128, Botan::CBC_Mode, Botan::CCM_Mode, Botan::CFB_Mode, Botan::ChaCha20Poly1305_Mode, Botan::ChaCha, Botan::CMAC, Botan::CTR_BE, Botan::DES, Botan::EAX_Mode, Botan::FPE_FE1, Botan::GCM_Mode, Botan::GHASH, Botan::GMAC, Botan::GOST_28147_89, Botan::HMAC, Botan::IDEA, Botan::KMAC128, Botan::KMAC256, Botan::Kuznyechik, Botan::Lion, Botan::Noekeon, Botan::OCB_Mode, Botan::OFB, Botan::Poly1305, Botan::RC4, Botan::Salsa20, Botan::SEED, Botan::Serpent, Botan::SHACAL2, Botan::SHAKE_128_Cipher, Botan::SHAKE_256_Cipher, Botan::SipHash, Botan::SIV_Mode, Botan::SM4, Botan::Threefish_512, Botan::TLS::TLS_CBC_HMAC_AEAD_Mode, Botan::TripleDES, Botan::Twofish, and Botan::XTS_Mode.
Referenced by Botan::XTS_Mode::name(), Botan::SymmetricAlgorithm::set_key(), and Botan::MessageAuthenticationCode::start_msg().
|
pure virtual |
Implemented in Botan::ChaCha, Botan::CTR_BE, Botan::OFB, Botan::RC4, Botan::Salsa20, Botan::SHAKE_128_Cipher, and Botan::SHAKE_256_Cipher.
|
inlinevirtual |
Reimplemented in Botan::ChaCha.
Definition at line 225 of file stream_cipher.h.
Referenced by create(), and create_or_throw().
|
static |
Definition at line 129 of file stream_cipher.cpp.
References Botan::probe_providers_of().
|
pure virtual |
Set the offset and the state used later to generate the keystream
Sets the state of the stream cipher and keystream according to the passed offset
, exactly as if offset
bytes had first been encrypted. The key and (if required) the IV have to be set before this can be called.
offset | the offset where we begin to generate the keystream |
Implemented in Botan::ChaCha, Botan::CTR_BE, Botan::OFB, Botan::RC4, Botan::Salsa20, and Botan::SHAKE_Cipher.
|
inline |
Resync the cipher using the IV
Load IV
into the stream cipher state. This should happen after the key is set (set_key()) and before any operation (encrypt(), decrypt() or seek()) is called.
If the cipher does not support IVs, then a call with an empty IV will be accepted and any other length will cause an Invalid_IV_Length exception.
iv | the initialization vector |
iv_len | the length of the IV in bytes |
Definition at line 171 of file stream_cipher.h.
Referenced by Botan::Sodium::crypto_stream_salsa20(), Botan::Sodium::crypto_stream_salsa20_xor_ic(), Botan::Sodium::crypto_stream_xsalsa20(), Botan::Sodium::crypto_stream_xsalsa20_xor_ic(), Botan::Sodium::randombytes_buf_deterministic(), and Botan::SIV_Mode::set_ctr_iv().
|
inline |
Resync the cipher using the IV
iv | the initialization vector |
Invalid_IV_Length | if an incompatible IV was passed. |
Definition at line 178 of file stream_cipher.h.
|
protectedpure virtual |
Resync the cipher using the IV
Implemented in Botan::Salsa20.
|
inlineinherited |
Set the symmetric key of this object.
key | the SymmetricKey to be set. |
Definition at line 113 of file sym_algo.h.
References Botan::OctetString::begin(), Botan::OctetString::length(), and Botan::SymmetricAlgorithm::set_key().
Referenced by Botan::create_aes_row_generator(), Botan::Sodium::crypto_stream_salsa20(), Botan::Sodium::crypto_stream_salsa20_xor_ic(), Botan::Sodium::crypto_stream_xsalsa20(), Botan::Sodium::crypto_stream_xsalsa20_xor_ic(), Botan::FPE::fe1_decrypt(), Botan::FPE::fe1_encrypt(), Botan::Sphincs_Hash_Functions_Sha2::PRF_msg(), Botan::Sodium::randombytes_buf_deterministic(), and Botan::SymmetricAlgorithm::set_key().
|
inlineinherited |
Set the symmetric key of this object.
key | the to be set as a byte array. |
length | in bytes of key param |
Definition at line 126 of file sym_algo.h.
References Botan::SymmetricAlgorithm::set_key().
Referenced by Botan::SymmetricAlgorithm::set_key().
|
inherited |
Set the symmetric key of this object.
key | the contiguous byte range to be set. |
Definition at line 17 of file sym_algo.cpp.
References Botan::SymmetricAlgorithm::name(), and Botan::SymmetricAlgorithm::valid_keylength().
|
inlinevirtual |
iv_len | the length of the IV in bytes |
Reimplemented in Botan::ChaCha, Botan::CTR_BE, Botan::OFB, and Botan::Salsa20.
Definition at line 194 of file stream_cipher.h.
|
inlineinherited |
Check whether a given key length is valid for this algorithm.
length | the key length to be checked. |
Definition at line 107 of file sym_algo.h.
Referenced by Botan::SymmetricAlgorithm::set_key().
|
inline |
Fill a given buffer with keystream bytes
The contents of out
are ignored/overwritten
out | the byte array to hold the keystream |
Definition at line 91 of file stream_cipher.h.
|
inline |
Write keystream bytes to a buffer
The contents of out
are ignored/overwritten
out | the byte array to hold the keystream |
len | the length of out in bytes |
Definition at line 82 of file stream_cipher.h.
Referenced by Botan::Sodium::crypto_stream_salsa20(), Botan::Sodium::crypto_stream_xsalsa20(), and Botan::Sodium::randombytes_buf_deterministic().