|
Botan 3.13.0
Crypto and TLS for C&
|
#include <chacha.h>
Public Member Functions | |
| size_t | buffer_size () const override |
| ChaCha (size_t rounds=20) | |
| 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) |
| void | clear () override |
| StreamCipher * | clone () const |
| void | decrypt (std::span< uint8_t > inout) |
| size_t | default_iv_length () const override |
| void | encipher (std::span< uint8_t > inout) |
| void | encrypt (std::span< uint8_t > inout) |
| bool | has_keying_material () const override |
| Key_Length_Specification | key_spec () const override |
| 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 |
| std::string | name () const override |
| std::unique_ptr< StreamCipher > | new_object () const override |
| std::string | provider () const override |
| std::optional< uint64_t > | remaining_keystream_bytes () const override |
| void | seek (uint64_t offset) override |
| void | set_iv (const uint8_t iv[], size_t iv_len) |
| void | set_iv (std::span< const uint8_t > iv) |
| void | set_key (const OctetString &key) |
| void | set_key (const uint8_t key[], size_t length) |
| void | set_key (std::span< const uint8_t > key) |
| bool | supports_seek () const override |
| bool | valid_iv_length (size_t iv_len) const override |
| bool | valid_keylength (size_t length) const |
| void | write_keystream (std::span< uint8_t > out) |
| void | write_keystream (uint8_t out[], size_t len) |
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 |
DJB's ChaCha (https://cr.yp.to/chacha.html)
|
explicit |
| rounds | number of rounds |
Definition at line 92 of file chacha.cpp.
References BOTAN_ARG_CHECK.
|
inlineprotectedinherited |
Throw Key_Not_Set unless a key has been set on this object
Definition at line 180 of file sym_algo.h.
References assert_key_material_set(), and has_keying_material().
Referenced by assert_key_material_set(), Botan::Salsa20::cipher_bytes(), Botan::Lion::decrypt_n(), Botan::Lion::encrypt_n(), Botan::GHASH::final(), Botan::Polyval::final(), Botan::Salsa20::generate_keystream(), Botan::GHASH::nonce_hash(), Botan::GHASH::reset_associated_data(), Botan::ChaCha::seek(), Botan::CTR_BE::seek(), Botan::Salsa20::seek(), Botan::GHASH::set_associated_data(), Botan::OCB_Mode::set_associated_data_n(), Botan::Salsa20::set_iv_bytes(), Botan::GHASH::update(), Botan::Polyval::update(), Botan::GHASH::update_associated_data(), and Botan::Polyval::zero_pad().
|
inlineprotectedinherited |
Throw Key_Not_Set unless the predicate holds
| predicate | if false, a Key_Not_Set exception is thrown |
Definition at line 186 of file sym_algo.h.
|
overridevirtual |
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.
Implements Botan::StreamCipher.
Definition at line 341 of file chacha.cpp.
|
inlineinherited |
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 61 of file stream_cipher.h.
References cipher_bytes().
Referenced by cipher1(), cipher1(), create(), Botan::Sodium::crypto_stream_salsa20_xor_ic(), Botan::Sodium::crypto_stream_xsalsa20_xor_ic(), Botan::CTR_BE::CTR_BE(), Botan::CTR_BE::CTR_BE(), decrypt(), encipher(), encrypt(), and Botan::OFB::OFB().
|
inherited |
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 133 of file stream_cipher.cpp.
References BOTAN_ARG_CHECK, and cipher_bytes().
|
inlineinherited |
Encrypt or decrypt a message The message is encrypted/decrypted in place.
| buf | the plaintext / ciphertext |
Definition at line 117 of file stream_cipher.h.
References cipher().
|
inlineinherited |
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 110 of file stream_cipher.h.
References cipher().
Referenced by generate_keystream().
|
overridevirtual |
Reset the internal state. This includes not just the key, but any partial message that may have been in process.
Implements Botan::SymmetricAlgorithm.
Definition at line 429 of file chacha.cpp.
References Botan::zap().
|
inlineinherited |
Create a new uninitialized object of the same type
Definition at line 198 of file stream_cipher.h.
References new_object().
|
staticinherited |
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().
|
staticinherited |
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().
|
inlineinherited |
Decrypt a message in place The message is decrypted in place.
| inout | the plaintext / ciphertext |
Definition at line 138 of file stream_cipher.h.
References cipher().
|
overridevirtual |
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 from Botan::StreamCipher.
Definition at line 360 of file chacha.cpp.
|
inlineinherited |
Encrypt a message The message is encrypted/decrypted in place.
| inout | the plaintext / ciphertext |
Definition at line 124 of file stream_cipher.h.
References cipher().
|
inlineinherited |
Encrypt a message The message is encrypted in place.
| inout | the plaintext / ciphertext |
Definition at line 131 of file stream_cipher.h.
References cipher().
|
overridevirtual |
Test whether a key has been set on this object
Implements Botan::SymmetricAlgorithm.
Definition at line 337 of file chacha.cpp.
Referenced by remaining_keystream_bytes().
|
overridevirtual |
Return the key lengths supported by this algorithm
Implements Botan::SymmetricAlgorithm.
Definition at line 364 of file chacha.cpp.
|
inlineinherited |
Get bytes from the keystream
The bytes are written into a continuous byte buffer of your choosing.
| bytes | The number of bytes to be produced |
Definition at line 98 of file stream_cipher.h.
References write_keystream().
|
inlineinherited |
Return the largest acceptable key length
Definition at line 130 of file sym_algo.h.
References key_spec().
|
inlineinherited |
Return the smallest acceptable key length
Definition at line 136 of file sym_algo.h.
References key_spec().
|
overridevirtual |
Return the name of this algorithm
Implements Botan::SymmetricAlgorithm.
Definition at line 446 of file chacha.cpp.
References Botan::fmt().
|
overridevirtual |
Create a new uninitialized object of the same type
Implements Botan::StreamCipher.
Definition at line 368 of file chacha.cpp.
|
overridevirtual |
Return the name of the provider implementing this object
Reimplemented from Botan::StreamCipher.
Definition at line 112 of file chacha.cpp.
References Botan::CPUFeature::AVX2, Botan::CPUFeature::AVX512, Botan::CPUID::check(), and Botan::CPUFeature::SIMD_4X32.
|
staticinherited |
List the providers available for a given stream cipher
Definition at line 129 of file stream_cipher.cpp.
References Botan::probe_providers_of().
|
overridevirtual |
Many stream ciphers are internally based on encrypting a counter of some kind. If the counter wraps around, keystream bytes would be repeated.
This function returns the number of keystream bytes that can still be produced under the current key/nonce settings, if that limit fits in a uint64_t. If there is no specific limit (eg due to being based on permutations rather than a counter), or if the limit is at least 2**64 bytes (where consuming the entire keystream is not practically possible), then this function returns nullopt.
Note this returns nullopt if no key is set (there are no keystream bytes at all available, in that state) or potentially if the nonce is not set (as in some cases, such as ChaCha, the available counter bytes vary depending on the size of the nonce used).
Implements Botan::StreamCipher.
Definition at line 439 of file chacha.cpp.
References has_keying_material().
|
overridevirtual |
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 |
Implements Botan::StreamCipher.
Definition at line 450 of file chacha.cpp.
References Botan::SymmetricAlgorithm::assert_key_material_set().
|
inlineinherited |
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 168 of file stream_cipher.h.
References set_iv_bytes().
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().
|
inlineinherited |
Resync the cipher using the IV
| iv | the initialization vector |
| Invalid_IV_Length | if an incompatible IV was passed. |
Definition at line 175 of file stream_cipher.h.
References set_iv_bytes().
|
inherited |
Set the symmetric key of this object.
| key | the SymmetricKey to be set. |
Definition at line 14 of file sym_algo.cpp.
References Botan::OctetString::begin(), Botan::OctetString::length(), and 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(), Botan::TLS::TLS_NULL_HMAC_AEAD_Mode::reset(), and 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 162 of file sym_algo.h.
References set_key().
Referenced by set_key().
|
inherited |
Set the symmetric key of this object.
| key | the contiguous byte range to be set. |
Definition at line 22 of file sym_algo.cpp.
References name(), and valid_keylength().
|
inlineoverridevirtual |
Test whether this cipher supports seeking within the keystream
Implements Botan::StreamCipher.
Definition at line 49 of file chacha.h.
|
overridevirtual |
Test if a nonce length is valid for this cipher
| iv_len | the length of the IV in bytes |
Reimplemented from Botan::StreamCipher.
Definition at line 372 of file chacha.cpp.
|
inlineinherited |
Check whether a given key length is valid for this algorithm.
| length | the key length to be checked. |
Definition at line 143 of file sym_algo.h.
References key_spec().
Referenced by set_key().
|
inlineinherited |
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 88 of file stream_cipher.h.
References generate_keystream().
|
inlineinherited |
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 79 of file stream_cipher.h.
References generate_keystream().
Referenced by Botan::Sodium::crypto_stream_salsa20(), Botan::Sodium::crypto_stream_xsalsa20(), keystream_bytes(), and Botan::Sodium::randombytes_buf_deterministic().