Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
15 namespace Botan {
16
17 /**
18 * This class represents hash function (message digest) objects
19 */
20 class BOTAN_PUBLIC_API(2,0) HashFunction : public Buffered_Computation
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 new object representing the same algorithm as *this
51 */
52 virtual HashFunction* clone() const = 0;
53
54 /**
55 * @return provider information about this implementation. Default is "base",
56 * might also return "sse2", "avx2", "openssl", or some other arbitrary string.
57 */
58 virtual std::string provider() const { return "base"; }
59
60 virtual ~HashFunction() = default;
61
62 /**
63 * Reset the state.
64 */
65 virtual void clear() = 0;
66
67 /**
68 * @return the hash function name
69 */
70 virtual std::string name() const = 0;
71
72 /**
73 * @return hash block size as defined for this algorithm
74 */
75 virtual size_t hash_block_size() const { return 0; }
76
77 /**
78 * Return a new hash object with the same state as *this. This
79 * allows computing the hash of several messages with a common
80 * prefix more efficiently than would otherwise be possible.
81 *
82 * This function should be called `clone` but that was already
83 * used for the case of returning an uninitialized object.
84 * @return new hash object
85 */
86 virtual std::unique_ptr<HashFunction> copy_state() const = 0;
87 };
88
89 }
90
91 #endif
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::Buffered_Computation
Definition: buf_comp.h:20
Botan::HashFunction::provider
virtual std::string provider() const
Definition: hash.h:58
name
std::string name
Definition: commoncrypto_hash.cpp:23
Botan
Definition: alg_id.cpp:13
Botan::HashFunction::hash_block_size
virtual size_t hash_block_size() const
Definition: hash.h:75
Botan::HashFunction
Definition: hash.h:20