5
* Botan is released under the Simplified BSD License (see license.txt)
8
#include <botan/comb4p.h>
9
#include <botan/exceptn.h>
15
void comb4p_round(secure_vector<uint8_t>& out,
16
const secure_vector<uint8_t>& in,
24
h1.update(in.data(), in.size());
25
h2.update(in.data(), in.size());
27
secure_vector<uint8_t> h_buf = h1.final();
28
xor_buf(out.data(), h_buf.data(), std::min(out.size(), h_buf.size()));
31
xor_buf(out.data(), h_buf.data(), std::min(out.size(), h_buf.size()));
36
Comb4P::Comb4P(HashFunction* h1, HashFunction* h2) :
37
m_hash1(h1), m_hash2(h2)
39
if(m_hash1->name() == m_hash2->name())
40
throw Invalid_Argument("Comb4P: Must use two distinct hashes");
42
if(m_hash1->output_length() != m_hash2->output_length())
43
throw Invalid_Argument("Comb4P: Incompatible hashes " +
44
m_hash1->name() + " and " +
50
size_t Comb4P::hash_block_size() const
52
if(m_hash1->hash_block_size() == m_hash2->hash_block_size())
53
return m_hash1->hash_block_size();
56
* Return LCM of the block sizes? This would probably be OK for
57
* HMAC, which is the main thing relying on knowing the block size.
67
// Prep for processing next message, if any
72
std::unique_ptr<HashFunction> Comb4P::copy_state() const
74
std::unique_ptr<Comb4P> copy(new Comb4P);
75
copy->m_hash1 = m_hash1->copy_state();
76
copy->m_hash2 = m_hash2->copy_state();
77
return std::move(copy);
80
void Comb4P::add_data(const uint8_t input[], size_t length)
82
m_hash1->update(input, length);
83
m_hash2->update(input, length);
86
void Comb4P::final_result(uint8_t out[])
88
secure_vector<uint8_t> h1 = m_hash1->final();
89
secure_vector<uint8_t> h2 = m_hash2->final();
92
xor_buf(h1.data(), h2.data(), std::min(h1.size(), h2.size()));
95
comb4p_round(h2, h1, 1, *m_hash1, *m_hash2);
98
comb4p_round(h1, h2, 2, *m_hash1, *m_hash2);
100
copy_mem(out , h1.data(), h1.size());
101
copy_mem(out + h1.size(), h2.data(), h2.size());
103
// Prep for processing next message, if any