8#include <botan/stream_cipher.h>
10#include <botan/exceptn.h>
11#include <botan/mem_ops.h>
12#include <botan/internal/algorithm_spec.h>
13#include <botan/internal/probe_providers.h>
15#if defined(BOTAN_HAS_CHACHA)
16 #include <botan/internal/chacha.h>
19#if defined(BOTAN_HAS_SALSA20)
20 #include <botan/internal/salsa20.h>
23#if defined(BOTAN_HAS_SHAKE_CIPHER)
24 #include <botan/internal/shake_cipher.h>
27#if defined(BOTAN_HAS_CTR_BE)
28 #include <botan/internal/ctr.h>
31#if defined(BOTAN_HAS_OFB)
32 #include <botan/internal/ofb.h>
35#if defined(BOTAN_HAS_RC4)
36 #include <botan/internal/rc4.h>
42#if defined(BOTAN_HAS_SHAKE_CIPHER)
43 if(algo_spec ==
"SHAKE-128" || algo_spec ==
"SHAKE-128-XOF") {
45 return std::make_unique<SHAKE_128_Cipher>();
49 if(algo_spec ==
"SHAKE-256" || algo_spec ==
"SHAKE-256-XOF") {
51 return std::make_unique<SHAKE_256_Cipher>();
56#if defined(BOTAN_HAS_CHACHA)
57 if(algo_spec ==
"ChaCha20") {
59 return std::make_unique<ChaCha>(20);
64#if defined(BOTAN_HAS_SALSA20)
65 if(algo_spec ==
"Salsa20") {
67 return std::make_unique<Salsa20>();
74#if defined(BOTAN_HAS_CTR_BE)
75 if(
auto m = req.
match(
"CTR-BE|CTR({cipher},{ctr_size:int?})")) {
78 const size_t ctr_size = m->has(
"ctr_size") ? m->integer(
"ctr_size") :
cipher->block_size();
79 return std::make_unique<CTR_BE>(std::move(
cipher), ctr_size);
85#if defined(BOTAN_HAS_CHACHA)
86 if(
auto m = req.
match(
"ChaCha({rounds:int=20})")) {
88 return std::make_unique<ChaCha>(m->integer(
"rounds"));
93#if defined(BOTAN_HAS_OFB)
94 if(
auto m = req.
match(
"OFB({cipher})")) {
97 return std::make_unique<OFB>(std::move(
cipher));
103#if defined(BOTAN_HAS_RC4)
104 if(
auto m = req.
match(
"RC4|ARC4({skip:int=0})")) {
106 return std::make_unique<RC4>(m->integer(
"skip"));
112 return std::make_unique<RC4>(256);
136 BOTAN_ARG_CHECK(in.size() <= out.size(),
"Output buffer of stream cipher must be at least as long as input buffer");
#define BOTAN_ARG_CHECK(expr, msg)
bool matches(const AlgorithmPattern &pattern) const
std::optional< AlgorithmMatch > match(const AlgorithmPattern &pattern) const &
static std::unique_ptr< BlockCipher > create(std::string_view algo_spec, std::string_view provider="")
void cipher1(uint8_t buf[], size_t len)
static std::unique_ptr< StreamCipher > create_or_throw(std::string_view algo_spec, std::string_view provider="")
static std::unique_ptr< StreamCipher > create(std::string_view algo_spec, std::string_view provider="")
virtual size_t default_iv_length() const
virtual void generate_keystream(uint8_t out[], size_t len)
virtual void cipher_bytes(const uint8_t in[], uint8_t out[], size_t len)=0
static std::vector< std::string > providers(std::string_view algo_spec)
void cipher(const uint8_t in[], uint8_t out[], size_t len)
virtual std::string provider() const
std::vector< std::string > probe_providers_of(std::string_view algo_spec, const std::vector< std::string > &possible={"base"})
constexpr void clear_mem(T *ptr, size_t n)