12 #include <boost/scoped_ptr.hpp>
14 #include <botan/lookup.h>
19 namespace cryptolink {
53 : hash_algorithm_(hash_algorithm), hash_() {
54 Botan::HashFunction* hash;
56 const std::string& name =
58 hash = Botan::HashFunction::create(name).release();
59 }
catch (
const Botan::Algorithm_Not_Found&) {
61 "Unknown hash algorithm: " <<
62 static_cast<int>(hash_algorithm));
63 }
catch (
const Botan::Exception& exc) {
65 "Botan error: " << exc.
what());
76 return (hash_algorithm_);
83 return (hash_->output_length());
89 void update(
const void* data,
const size_t len) {
91 hash_->update(static_cast<const Botan::byte*>(data), len);
92 }
catch (
const Botan::Exception& exc) {
94 "Botan error: " << exc.
what());
103 Botan::secure_vector<Botan::byte> b_result(hash_->final());
105 if (len > b_result.size()) {
106 len = b_result.size();
108 result.writeData(&b_result[0], len);
109 }
catch (
const Botan::Exception& exc) {
111 "Botan error: " << exc.
what());
118 void final(
void* result,
size_t len) {
120 Botan::secure_vector<Botan::byte> b_result(hash_->final());
122 if (output_size > len) {
125 std::memcpy(result, &b_result[0], output_size);
126 }
catch (
const Botan::Exception& exc) {
128 "Botan error: " << exc.
what());
135 std::vector<uint8_t>
final(
size_t len) {
137 Botan::secure_vector<Botan::byte> b_result(hash_->final());
138 if (len > b_result.size()) {
139 len = b_result.size();
144 return (std::vector<uint8_t>(&b_result[0], &b_result[0]+len));
145 }
catch (
const Botan::Exception& exc) {
147 "Botan error: " << exc.
what());
156 boost::scoped_ptr<Botan::HashFunction> hash_;
161 impl_ =
new HashImpl(hash_algorithm);
185 impl_->
final(result, len);
190 impl_->
final(result, len);
195 return impl_->
final(len);
This exception is raised when a general error that was not specifically caught is thrown by the under...
Botan implementation of Hash.
void final(isc::util::OutputBuffer &result, size_t len)
Calculate the final digest.
HashAlgorithm
Hash algorithm identifiers.
size_t getOutputLength() const
Returns the output size of the digest.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void final(isc::util::OutputBuffer &result, size_t len)
Calculate the final digest.
This exception is thrown when a cryptographic action is requested for an algorithm that is not suppor...
void update(const void *data, const size_t len)
Add data to digest.
HashAlgorithm getHashAlgorithm() const
Returns the HashAlgorithm of the object.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Defines the logger used by the top-level component of kea-dhcp-ddns.
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.
size_t getOutputLength() const
Returns the output size of the digest.
HashImpl(const HashAlgorithm hash_algorithm)
Constructor for specific hash algorithm.
void update(const void *data, const size_t len)
Adds data to the digest.
This value can be used in conversion functions, to be returned when the input is unknown (but a value...