Botan 3.9.0
Crypto and TLS for C&
hash.h
Go to the documentation of this file.
1/*
2* Hash Function Base Class
3* (C) 1999-2008 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_HASH_FUNCTION_BASE_CLASS_H_
9#define BOTAN_HASH_FUNCTION_BASE_CLASS_H_
10
11#include <botan/buf_comp.h>
12#include <memory>
13#include <string>
14#include <string_view>
15
16namespace Botan {
17
18/**
19* This class represents hash function (message digest) objects
20*/
22 public:
23 /**
24 * Create an instance based on a name, or return null if the
25 * algo/provider combination cannot be found. If provider is
26 * empty then best available is chosen.
27 */
28 static std::unique_ptr<HashFunction> create(std::string_view algo_spec, std::string_view provider = "");
29
30 /**
31 * Create an instance based on a name
32 * If provider is empty then best available is chosen.
33 * @param algo_spec algorithm name
34 * @param provider provider implementation to use
35 * Throws Lookup_Error if not found.
36 */
37 static std::unique_ptr<HashFunction> create_or_throw(std::string_view algo_spec, std::string_view provider = "");
38
39 /**
40 * @return list of available providers for this algorithm, empty if not available
41 * @param algo_spec algorithm name
42 */
43 static std::vector<std::string> providers(std::string_view algo_spec);
44
45 /**
46 * @return provider information about this implementation. Default is "base",
47 * might also return "sse2", "avx2", "openssl", or some other arbitrary string.
48 */
49 virtual std::string provider() const { return "base"; }
50
51 /**
52 * Reset the state.
53 */
54 virtual void clear() = 0;
55
56 /**
57 * @return the hash function name
58 */
59 virtual std::string name() const = 0;
60
61 /**
62 * @return hash block size as defined for this algorithm
63 */
64 virtual size_t hash_block_size() const { return 0; }
65
66 /**
67 * Return a new hash object with the same state as *this. This
68 * allows computing the hash of several messages with a common
69 * prefix more efficiently than would otherwise be possible.
70 *
71 * This function should be called `clone` but that was already
72 * used for the case of returning an uninitialized object.
73 * @return new hash object
74 */
75 virtual std::unique_ptr<HashFunction> copy_state() const = 0;
76
77 /**
78 * @return new object representing the same algorithm as *this
79 */
80 virtual std::unique_ptr<HashFunction> new_object() const = 0;
81
82 /**
83 * @return new object representing the same algorithm as *this
84 */
85 HashFunction* clone() const { return this->new_object().release(); }
86};
87
88} // namespace Botan
89
90#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
static std::vector< std::string > providers(std::string_view algo_spec)
Definition hash.cpp:305
virtual std::string provider() const
Definition hash.h:49
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:298
HashFunction * clone() const
Definition hash.h:85
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:107
virtual size_t hash_block_size() const
Definition hash.h:64
virtual std::unique_ptr< HashFunction > copy_state() const =0
virtual std::unique_ptr< HashFunction > new_object() const =0
virtual std::string name() const =0
virtual void clear()=0