Botan 3.6.1
Crypto and TLS for C&
raw_hash.cpp
Go to the documentation of this file.
1/*
2* (C) 2023 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/internal/raw_hash.h>
8
9#include <botan/exceptn.h>
10
11namespace Botan {
12
13void RawHashFunction::add_data(std::span<const uint8_t> input) {
14 m_bits += std::make_pair(input.data(), input.size());
15}
16
17void RawHashFunction::final_result(std::span<uint8_t> out) {
18 if(m_output_length > 0 && m_bits.size() != m_output_length) {
19 m_bits.clear();
20 throw Invalid_Argument("Raw padding was configured to use a " + std::to_string(m_output_length) +
21 " byte hash but instead was used for a " + std::to_string(m_bits.size()) + " byte hash");
22 }
23
24 copy_mem(out.data(), m_bits.data(), m_bits.size());
25 m_bits.clear();
26}
27
29 m_bits.clear();
30}
31
32std::unique_ptr<HashFunction> RawHashFunction::copy_state() const {
33 return std::make_unique<RawHashFunction>(*this);
34}
35
36std::unique_ptr<HashFunction> RawHashFunction::new_object() const {
37 return std::make_unique<RawHashFunction>(m_name, m_output_length);
38}
39
41 if(m_output_length > 0) {
42 return m_output_length;
43 }
44 return m_bits.size();
45}
46
47} // namespace Botan
void clear() override
Definition raw_hash.cpp:28
void final_result(std::span< uint8_t > out) override
Definition raw_hash.cpp:17
std::unique_ptr< HashFunction > copy_state() const override
Definition raw_hash.cpp:32
void add_data(std::span< const uint8_t > input) override
Definition raw_hash.cpp:13
std::unique_ptr< HashFunction > new_object() const override
Definition raw_hash.cpp:36
size_t output_length() const override
Definition raw_hash.cpp:40
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:146