8#include <botan/cascade.h>
15 size_t c1_blocks = blocks * (
block_size() / m_cipher1->block_size());
16 size_t c2_blocks = blocks * (
block_size() / m_cipher2->block_size());
18 m_cipher1->encrypt_n(in, out, c1_blocks);
19 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(
const uint8_t key[],
size_t)
34 const uint8_t* key2 = key + m_cipher1->maximum_keylength();
36 m_cipher1->set_key(key , m_cipher1->maximum_keylength());
37 m_cipher2->set_key(key2, m_cipher2->maximum_keylength());
48 return "Cascade(" + m_cipher1->name() +
"," + m_cipher2->name() +
")";
59size_t euclids_algorithm(
size_t a,
size_t b)
71size_t block_size_for_cascade(
size_t bs,
size_t bs2)
76 const size_t gcd = euclids_algorithm(bs, bs2);
78 return (bs * bs2) /
gcd;
84 m_cipher1(c1), m_cipher2(c2)
90 "Combined block size is a multiple of each ciphers block");
#define BOTAN_ASSERT(expr, assertion_made)
virtual size_t block_size() const =0
std::string name() const override
Cascade_Cipher(BlockCipher *cipher1, BlockCipher *cipher2)
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
BlockCipher * clone() const override
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
size_t block_size() const override
BigInt gcd(const BigInt &a, const BigInt &b)