 |
Kea
1.5.0
|
Go to the documentation of this file.
12 #include <boost/scoped_ptr.hpp>
14 #include <botan/version.h>
15 #include <botan/botan.h>
16 #include <botan/hash.h>
17 #include <botan/types.h>
22 namespace cryptolink {
60 : hash_algorithm_(hash_algorithm), hash_() {
61 Botan::HashFunction* hash;
63 const std::string& name =
65 hash = Botan::get_hash(name);
66 }
catch (
const Botan::Algorithm_Not_Found&) {
68 "Unknown hash algorithm: " <<
69 static_cast<int>(hash_algorithm));
70 }
catch (
const Botan::Exception& exc) {
72 "Botan error: " << exc.
what());
83 return (hash_algorithm_);
90 #if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,0)
91 return (hash_->output_length());
93 #error "Unsupported Botan version (need 1.9 or higher)"
102 void update(
const void* data,
const size_t len) {
104 hash_->update(
static_cast<const Botan::byte*
>(data), len);
105 }
catch (
const Botan::Exception& exc) {
107 "Botan error: " << exc.
what());
116 Botan::SecureVector<Botan::byte> b_result(hash_->final());
118 if (len > b_result.size()) {
119 len = b_result.size();
121 result.writeData(&b_result[0], len);
122 }
catch (
const Botan::Exception& exc) {
124 "Botan error: " << exc.
what());
131 void final(
void* result,
size_t len) {
133 Botan::SecureVector<Botan::byte> b_result(hash_->final());
135 if (output_size > len) {
138 std::memcpy(result, &b_result[0], output_size);
139 }
catch (
const Botan::Exception& exc) {
141 "Botan error: " << exc.
what());
148 std::vector<uint8_t>
final(
size_t len) {
150 Botan::SecureVector<Botan::byte> b_result(hash_->final());
151 if (len > b_result.size()) {
152 len = b_result.size();
154 return (std::vector<uint8_t>(&b_result[0], &b_result[len]));
155 }
catch (
const Botan::Exception& exc) {
157 "Botan error: " << exc.
what());
166 boost::scoped_ptr<Botan::HashFunction> hash_;
171 impl_ =
new HashImpl(hash_algorithm);
195 impl_->
final(result, len);
200 impl_->
final(result, len);
205 return impl_->
final(len);
void final(isc::util::OutputBuffer &result, size_t len)
Calculate the final digest.
HashAlgorithm
Hash algorithm identifiers.
void final(isc::util::OutputBuffer &result, size_t len)
Calculate the final digest.
void update(const void *data, const size_t len)
Add data to digest.
size_t getOutputLength() const
Returns the output size of the digest.
This exception is raised when a general error that was not specifically caught is thrown by the under...
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
This exception is thrown when a cryptographic action is requested for an algorithm that is not suppor...
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
HashAlgorithm getHashAlgorithm() const
Returns the HashAlgorithm of the object.
Botan implementation of Hash.
void update(const void *data, const size_t len)
Adds data to the digest.
const std::string getHashAlgorithmName(isc::cryptolink::HashAlgorithm algorithm)
Decode the HashAlgorithm enum into a name usable by Botan.
HashAlgorithm getHashAlgorithm() const
Returns the HashAlgorithm of the object.
HashImpl(const HashAlgorithm hash_algorithm)
Constructor for specific hash algorithm.
size_t getOutputLength() const
Returns the output size of the digest.
@ UNKNOWN_HASH
This value can be used in conversion functions, to be returned when the input is unknown (but a value...