8#ifndef BOTAN_BLOCK_CIPHER_H_
9#define BOTAN_BLOCK_CIPHER_H_
11#include <botan/mem_ops.h>
12#include <botan/sym_algo.h>
32 static std::unique_ptr<BlockCipher> create(std::string_view algo_spec, std::string_view provider =
"");
39 static std::unique_ptr<BlockCipher> create_or_throw(std::string_view algo_spec, std::string_view provider =
"");
45 static std::vector<std::string> providers(std::string_view algo_spec);
66 virtual std::string
provider()
const {
return "base"; }
75 void encrypt(
const uint8_t in[], uint8_t out[])
const { encrypt_n(in, out, 1); }
84 void decrypt(
const uint8_t in[], uint8_t out[])
const { decrypt_n(in, out, 1); }
92 void encrypt(uint8_t block[])
const { encrypt_n(block, block, 1); }
100 void decrypt(uint8_t block[])
const { decrypt_n(block, block, 1); }
106 void encrypt(std::span<uint8_t> block)
const {
107 return encrypt_n(block.data(), block.data(), block.size() / block_size());
114 void decrypt(std::span<uint8_t> block)
const {
115 return decrypt_n(block.data(), block.data(), block.size() / block_size());
123 void encrypt(std::span<const uint8_t> in, std::span<uint8_t> out)
const {
124 return encrypt_n(in.data(), out.data(), in.size() / block_size());
132 void decrypt(std::span<const uint8_t> in, std::span<uint8_t> out)
const {
133 return decrypt_n(in.data(), out.data(), in.size() / block_size());
142 virtual void encrypt_n(
const uint8_t in[], uint8_t out[],
size_t blocks)
const = 0;
150 virtual void decrypt_n(
const uint8_t in[], uint8_t out[],
size_t blocks)
const = 0;
152 virtual void encrypt_n_xex(uint8_t data[],
const uint8_t mask[],
size_t blocks)
const {
153 const size_t BS = block_size();
154 xor_buf(data, mask, blocks * BS);
155 encrypt_n(data, data, blocks);
156 xor_buf(data, mask, blocks * BS);
159 virtual void decrypt_n_xex(uint8_t data[],
const uint8_t mask[],
size_t blocks)
const {
160 const size_t BS = block_size();
161 xor_buf(data, mask, blocks * BS);
162 decrypt_n(data, data, blocks);
163 xor_buf(data, mask, blocks * BS);
188 virtual void set_tweak(
const uint8_t tweak[],
size_t len) = 0;
194template <
size_t BS,
size_t KMIN,
size_t KMAX = 0,
size_t KMOD = 1,
typename BaseClass = BlockCipher>
void encrypt(const uint8_t in[], uint8_t out[]) const
void decrypt(const uint8_t in[], uint8_t out[]) const
void decrypt(std::span< uint8_t > block) const
void decrypt(std::span< const uint8_t > in, std::span< uint8_t > out) const
~BlockCipher() override=default
void encrypt(std::span< const uint8_t > in, std::span< uint8_t > out) const
virtual void encrypt_n_xex(uint8_t data[], const uint8_t mask[], size_t blocks) const
void encrypt(std::span< uint8_t > block) const
virtual void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
virtual void decrypt_n_xex(uint8_t data[], const uint8_t mask[], size_t blocks) const
virtual void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const =0
BlockCipher * clone() const
virtual std::unique_ptr< BlockCipher > new_object() const =0
virtual size_t block_size() const =0
virtual size_t parallelism() const
void decrypt(uint8_t block[]) const
virtual std::string provider() const
size_t parallel_bytes() const
void encrypt(uint8_t block[]) const
size_t block_size() const final
Key_Length_Specification key_spec() const final
virtual void set_tweak(const uint8_t tweak[], size_t len)=0
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
#define BOTAN_BLOCK_CIPHER_PAR_MULT
constexpr void xor_buf(ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)