8#include <botan/internal/comb4p.h>
10#include <botan/exceptn.h>
11#include <botan/mem_ops.h>
12#include <botan/internal/fmt.h>
13#include <botan/internal/stl_util.h>
27 h1.update(in.data(), in.size());
28 h2.update(in.data(), in.size());
31 xor_buf(out.data(), h_buf.data(), std::min(out.size(), h_buf.size()));
34 xor_buf(out.data(), h_buf.data(), std::min(out.size(), h_buf.size()));
39Comb4P::Comb4P(std::unique_ptr<HashFunction> h1, std::unique_ptr<HashFunction> h2) :
40 m_hash1(std::move(h1)), m_hash2(std::move(h2)) {
41 if(m_hash1->name() == m_hash2->name()) {
42 throw Invalid_Argument(
"Comb4P: Must use two distinct hashes");
45 if(m_hash1->output_length() != m_hash2->output_length()) {
46 throw Invalid_Argument(fmt(
"Comb4P: Incompatible hashes {} and {}", m_hash1->name(), m_hash2->name()));
39Comb4P::Comb4P(std::unique_ptr<HashFunction> h1, std::unique_ptr<HashFunction> h2) : {
…}
53 return fmt(
"Comb4P({},{})", m_hash1->name(), m_hash2->name());
57 return std::make_unique<Comb4P>(m_hash1->new_object(), m_hash2->new_object());
61 if(m_hash1->hash_block_size() == m_hash2->hash_block_size()) {
62 return m_hash1->hash_block_size();
83 std::unique_ptr<Comb4P> copy(
new Comb4P);
84 copy->m_hash1 = m_hash1->copy_state();
85 copy->m_hash2 = m_hash2->copy_state();
89void Comb4P::add_data(std::span<const uint8_t> input) {
90 m_hash1->update(input);
91 m_hash2->update(input);
94void Comb4P::final_result(std::span<uint8_t> output) {
99 xor_buf(h1.data(), h2.data(), std::min(h1.size(), h2.size()));
102 comb4p_round(h2, h1, 1, *m_hash1, *m_hash2);
105 comb4p_round(h1, h2, 2, *m_hash1, *m_hash2);
107 BufferStuffer out(output);
108 copy_mem(out.next(h1.size()).data(), h1.data(), h1.size());
109 copy_mem(out.next(h2.size()).data(), h2.data(), h2.size());
std::unique_ptr< HashFunction > new_object() const override
Comb4P(std::unique_ptr< HashFunction > h1, std::unique_ptr< HashFunction > h2)
std::unique_ptr< HashFunction > copy_state() const override
std::string name() const override
size_t hash_block_size() const override
std::string fmt(std::string_view format, const T &... args)
constexpr void xor_buf(ranges::contiguous_output_range< uint8_t > auto &&out, ranges::contiguous_range< uint8_t > auto &&in)
std::vector< T, secure_allocator< T > > secure_vector
constexpr void copy_mem(T *out, const T *in, size_t n)