Botan 3.6.1
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 RawHashFunction(std::unique_ptr<HashFunction> hash) : RawHashFunction(hash->name(), hash->output_length()) {}
26
27 RawHashFunction(std::string_view name, size_t output_length) : m_name(name), m_output_length(output_length) {}
28
29 void add_data(std::span<const uint8_t> input) override;
30
31 void final_result(std::span<uint8_t> out) override;
32
33 void clear() override;
34
35 std::unique_ptr<HashFunction> copy_state() const override;
36
37 std::unique_ptr<HashFunction> new_object() const override;
38
39 size_t output_length() const override;
40
41 std::string name() const override { return m_name; }
42
43 private:
44 const std::string m_name;
45 const size_t m_output_length;
46 std::vector<uint8_t> m_bits;
47};
48
49} // namespace Botan
50
51#endif
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
std::string name() const override
Definition raw_hash.h:41
RawHashFunction(std::unique_ptr< HashFunction > hash)
Definition raw_hash.h:25
size_t output_length() const override
Definition raw_hash.cpp:40
RawHashFunction(std::string_view name, size_t output_length)
Definition raw_hash.h:27