Botan 3.0.0-alpha0
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 <string>
13#include <memory>
14
15namespace Botan {
16
17/**
18* This class represents hash function (message digest) objects
19*/
21 {
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>
29 create(const std::string& algo_spec,
30 const std::string& provider = "");
31
32 /**
33 * Create an instance based on a name
34 * If provider is empty then best available is chosen.
35 * @param algo_spec algorithm name
36 * @param provider provider implementation to use
37 * Throws Lookup_Error if not found.
38 */
39 static std::unique_ptr<HashFunction>
40 create_or_throw(const std::string& algo_spec,
41 const std::string& provider = "");
42
43 /**
44 * @return list of available providers for this algorithm, empty if not available
45 * @param algo_spec algorithm name
46 */
47 static std::vector<std::string> providers(const std::string& algo_spec);
48
49 /**
50 * @return provider information about this implementation. Default is "base",
51 * might also return "sse2", "avx2", "openssl", or some other arbitrary string.
52 */
53 virtual std::string provider() const { return "base"; }
54
55 virtual ~HashFunction() = default;
56
57 /**
58 * Reset the state.
59 */
60 virtual void clear() = 0;
61
62 /**
63 * @return the hash function name
64 */
65 virtual std::string name() const = 0;
66
67 /**
68 * @return hash block size as defined for this algorithm
69 */
70 virtual size_t hash_block_size() const { return 0; }
71
72 /**
73 * Return a new hash object with the same state as *this. This
74 * allows computing the hash of several messages with a common
75 * prefix more efficiently than would otherwise be possible.
76 *
77 * This function should be called `clone` but that was already
78 * used for the case of returning an uninitialized object.
79 * @return new hash object
80 */
81 virtual std::unique_ptr<HashFunction> copy_state() const = 0;
82
83 /**
84 * @return new object representing the same algorithm as *this
85 */
86 virtual std::unique_ptr<HashFunction> new_object() const = 0;
87
88 /**
89 * @return new object representing the same algorithm as *this
90 */
92 {
93 return this->new_object().release();
94 }
95 };
96
97}
98
99#endif
virtual std::string provider() const
Definition: hash.h:53
HashFunction * clone() const
Definition: hash.h:91
virtual ~HashFunction()=default
virtual size_t hash_block_size() const
Definition: hash.h:70
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
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:13