Botan 3.9.0
Crypto and TLS for C&
raw_hash.h
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#ifndef BOTAN_RAW_HASH_FN_H_
8#define BOTAN_RAW_HASH_FN_H_
9
10#include <botan/hash.h>
11#include <memory>
12
13namespace Botan {
14
15/**
16* This is not an actual hash function; it simply emits as the "hash"
17* the value it is given as input. This is useful when implementing
18* certain protocols where the hash is provided externally somehow to
19* the unit which is generating the signature.
20*
21* This is exposed as the "Raw" padding scheme for signatures.
22*/
24 public:
25 explicit RawHashFunction(std::unique_ptr<HashFunction> hash) :
26 RawHashFunction(hash->name(), hash->output_length()) {}
27
28 RawHashFunction(std::string_view name, size_t output_length) : m_name(name), m_output_length(output_length) {}
29
30 void add_data(std::span<const uint8_t> input) override;
31
32 void final_result(std::span<uint8_t> out) override;
33
34 void clear() override;
35
36 std::unique_ptr<HashFunction> copy_state() const override;
37
38 std::unique_ptr<HashFunction> new_object() const override;
39
40 size_t output_length() const override;
41
42 std::string name() const override { return m_name; }
43
44 private:
45 const std::string m_name;
46 const size_t m_output_length;
47 std::vector<uint8_t> m_bits;
48};
49
50} // namespace Botan
51
52#endif
void final(uint8_t out[])
Definition buf_comp.h:69
void clear() override
Definition raw_hash.cpp:29
void final_result(std::span< uint8_t > out) override
Definition raw_hash.cpp:18
std::unique_ptr< HashFunction > copy_state() const override
Definition raw_hash.cpp:33
void add_data(std::span< const uint8_t > input) override
Definition raw_hash.cpp:14
std::unique_ptr< HashFunction > new_object() const override
Definition raw_hash.cpp:37
std::string name() const override
Definition raw_hash.h:42
RawHashFunction(std::unique_ptr< HashFunction > hash)
Definition raw_hash.h:25
size_t output_length() const override
Definition raw_hash.cpp:41
RawHashFunction(std::string_view name, size_t output_length)
Definition raw_hash.h:28