12 #include <boost/scoped_ptr.hpp> 14 #include <botan/lookup.h> 19 namespace cryptolink {
57 : hash_algorithm_(hash_algorithm), hash_() {
58 Botan::HashFunction* hash;
60 const std::string& name =
62 hash = Botan::HashFunction::create(name).release();
63 }
catch (
const Botan::Algorithm_Not_Found&) {
65 "Unknown hash algorithm: " <<
66 static_cast<int>(hash_algorithm));
67 }
catch (
const Botan::Exception& exc) {
69 "Botan error: " << exc.
what());
80 return (hash_algorithm_);
87 return (hash_->output_length());
93 void update(
const void* data,
const size_t len) {
95 hash_->update(static_cast<const Botan::byte*>(data), len);
96 }
catch (
const Botan::Exception& exc) {
98 "Botan error: " << exc.
what());
107 Botan::secure_vector<Botan::byte> b_result(hash_->final());
109 if (len > b_result.size()) {
110 len = b_result.size();
112 result.writeData(&b_result[0], len);
113 }
catch (
const Botan::Exception& exc) {
115 "Botan error: " << exc.
what());
122 void final(
void* result,
size_t len) {
124 Botan::secure_vector<Botan::byte> b_result(hash_->final());
126 if (output_size > len) {
129 std::memcpy(result, &b_result[0], output_size);
130 }
catch (
const Botan::Exception& exc) {
132 "Botan error: " << exc.
what());
139 std::vector<uint8_t>
final(
size_t len) {
141 Botan::secure_vector<Botan::byte> b_result(hash_->final());
142 if (len > b_result.size()) {
143 len = b_result.size();
145 return (std::vector<uint8_t>(&b_result[0], &b_result[len]));
146 }
catch (
const Botan::Exception& exc) {
148 "Botan error: " << exc.
what());
157 boost::scoped_ptr<Botan::HashFunction> hash_;
162 impl_ =
new HashImpl(hash_algorithm);
186 impl_->
final(result, len);
191 impl_->
final(result, len);
196 return impl_->
final(len);
HashAlgorithm getHashAlgorithm() const
Returns the HashAlgorithm of the object.
This exception is raised when a general error that was not specifically caught is thrown by the under...
size_t getOutputLength() const
Returns the output size of the digest.
void final(isc::util::OutputBuffer &result, size_t len)
Calculate the final digest.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
HashAlgorithm
Hash algorithm identifiers.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
HashAlgorithm getHashAlgorithm() const
Returns the HashAlgorithm of the object.
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...
size_t getOutputLength() const
Returns the output size of the digest.
void update(const void *data, const size_t len)
Add data to digest.
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.
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...