8#include <botan/internal/lion.h>
9#include <botan/internal/fmt.h>
10#include <botan/exceptn.h>
21 const size_t LEFT_SIZE = left_size();
22 const size_t RIGHT_SIZE = right_size();
25 uint8_t* buffer = buffer_vec.data();
27 for(
size_t i = 0; i != blocks; ++i)
29 xor_buf(buffer, in, m_key1.data(), LEFT_SIZE);
30 m_cipher->set_key(buffer, LEFT_SIZE);
31 m_cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
33 m_hash->update(out + LEFT_SIZE, RIGHT_SIZE);
34 m_hash->final(buffer);
35 xor_buf(out, in, buffer, LEFT_SIZE);
37 xor_buf(buffer, out, m_key2.data(), LEFT_SIZE);
38 m_cipher->set_key(buffer, LEFT_SIZE);
39 m_cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
53 const size_t LEFT_SIZE = left_size();
54 const size_t RIGHT_SIZE = right_size();
57 uint8_t* buffer = buffer_vec.data();
59 for(
size_t i = 0; i != blocks; ++i)
61 xor_buf(buffer, in, m_key2.data(), LEFT_SIZE);
62 m_cipher->set_key(buffer, LEFT_SIZE);
63 m_cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
65 m_hash->update(out + LEFT_SIZE, RIGHT_SIZE);
66 m_hash->final(buffer);
67 xor_buf(out, in, buffer, LEFT_SIZE);
69 xor_buf(buffer, out, m_key1.data(), LEFT_SIZE);
70 m_cipher->set_key(buffer, LEFT_SIZE);
71 m_cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
80 return !m_key1.empty() && !m_key2.empty();
86void Lion::key_schedule(
const uint8_t key[],
size_t length)
90 const size_t half = length / 2;
92 m_key1.resize(left_size());
93 m_key2.resize(left_size());
97 copy_mem(m_key2.data(), key + half, half);
105 return fmt(
"Lion({},{},{})", m_hash->name(), m_cipher->name(),
block_size());
110 return std::make_unique<Lion>(m_hash->new_object(), m_cipher->new_object(),
block_size());
128 std::unique_ptr<StreamCipher> cipher,
130 m_block_size(
std::max<size_t>(2*hash->output_length() + 1, bs)),
131 m_hash(
std::move(hash)),
132 m_cipher(
std::move(cipher))
134 if(2*left_size() + 1 > m_block_size)
139 if(!m_cipher->valid_keylength(left_size()))
142 m_cipher->name(), m_hash->name()));
std::unique_ptr< BlockCipher > new_object() const override
bool has_keying_material() const override
size_t block_size() const override
Lion(std::unique_ptr< HashFunction > hash, std::unique_ptr< StreamCipher > cipher, size_t block_size)
std::string name() const override
void decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
void encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const override
void assert_key_material_set() const
void zap(std::vector< T, Alloc > &vec)
std::string fmt(std::string_view format, const T &... args)
constexpr void copy_mem(T *out, const T *in, size_t n)
void xor_buf(uint8_t out[], const uint8_t in[], size_t length)
std::vector< T, secure_allocator< T > > secure_vector
constexpr void clear_mem(T *ptr, size_t n)