8#include <botan/internal/cascade.h>
10#include <botan/internal/fmt.h>
11#include <botan/internal/stl_util.h>
17 size_t c1_blocks = blocks * (
block_size() / m_cipher1->block_size());
18 size_t c2_blocks = blocks * (
block_size() / m_cipher2->block_size());
20 m_cipher1->encrypt_n(in, out, c1_blocks);
21 m_cipher2->encrypt_n(out, out, c2_blocks);
25 size_t c1_blocks = blocks * (
block_size() / m_cipher1->block_size());
26 size_t c2_blocks = blocks * (
block_size() / m_cipher2->block_size());
28 m_cipher2->decrypt_n(in, out, c2_blocks);
29 m_cipher1->decrypt_n(out, out, c1_blocks);
32void Cascade_Cipher::key_schedule(std::span<const uint8_t> key) {
35 m_cipher1->set_key(keys.take(m_cipher1->maximum_keylength()));
36 m_cipher2->set_key(keys.take(m_cipher2->maximum_keylength()));
45 return fmt(
"Cascade({},{})", m_cipher1->name(), m_cipher2->name());
49 return m_cipher1->has_keying_material() && m_cipher2->has_keying_material();
53 return std::make_unique<Cascade_Cipher>(m_cipher1->new_object(), m_cipher2->new_object());
57 m_cipher1(std::move(cipher1)),
58 m_cipher2(std::move(cipher2)),
59 m_block_size(std::
lcm(m_cipher1->block_size(), m_cipher2->block_size())) {
60 BOTAN_ASSERT(m_block_size % m_cipher1->block_size() == 0 && m_block_size % m_cipher2->block_size() == 0,
61 "Combined block size is a multiple of each ciphers block");
#define BOTAN_ASSERT(expr, assertion_made)
bool has_keying_material() const override
std::string name() const override
Cascade_Cipher(std::unique_ptr< BlockCipher > cipher1, std::unique_ptr< BlockCipher > cipher2)
std::unique_ptr< BlockCipher > new_object() const override
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
size_t block_size() const override
std::string fmt(std::string_view format, const T &... args)
BigInt lcm(const BigInt &a, const BigInt &b)