8 #include <botan/comb4p.h>
9 #include <botan/internal/xor_buf.h>
16 void comb4p_round(MemoryRegion<byte>& out,
17 const MemoryRegion<byte>& in,
25 h1->update(&in[0], in.size());
26 h2->update(&in[0], in.size());
28 SecureVector<byte> h_buf = h1->final();
29 xor_buf(&out[0], &h_buf[0], std::min(out.size(), h_buf.size()));
32 xor_buf(&out[0], &h_buf[0], std::min(out.size(), h_buf.size()));
41 throw std::invalid_argument(
"Comb4P: Must use two distinct hashes");
44 throw std::invalid_argument(
"Comb4P: Incompatible hashes " +
45 hash1->
name() +
" and " +
73 void Comb4P::add_data(
const byte input[],
size_t length)
75 hash1->
update(input, length);
76 hash2->
update(input, length);
79 void Comb4P::final_result(
byte out[])
81 SecureVector<byte> h1 = hash1->
final();
82 SecureVector<byte> h2 = hash2->
final();
85 xor_buf(&h1[0], &h2[0], std::min(h1.size(), h2.size()));
88 comb4p_round(h2, h1, 1, hash1, hash2);
91 comb4p_round(h1, h2, 2, hash1, hash2);
94 copy_mem(out + h1.size(), &h2[0], h2.size());
Comb4P(HashFunction *h1, HashFunction *h2)
size_t hash_block_size() const
void update(const byte in[], size_t length)
void copy_mem(T *out, const T *in, size_t n)
virtual std::string name() const =0
virtual size_t hash_block_size() const
void xor_buf(byte out[], const byte in[], size_t length)
virtual size_t output_length() const =0