12#include <botan/hash.h>
13#include <botan/exceptn.h>
52 : hash_algorithm_(hash_algorithm), hash_() {
54 const std::string& name =
56 hash_ = Botan::HashFunction::create_or_throw(name);
57 }
catch (
const Botan::Lookup_Error&) {
59 "Unknown hash algorithm: " <<
60 static_cast<int>(hash_algorithm));
61 }
catch (
const Botan::Exception& exc) {
63 "Botan error: " << exc.
what());
72 return (hash_algorithm_);
79 return (hash_->output_length());
85 void update(
const void* data,
const size_t len) {
87 hash_->update(
static_cast<const Botan::byte*
>(data), len);
88 }
catch (
const Botan::Exception& exc) {
90 "Botan error: " << exc.
what());
99 Botan::secure_vector<Botan::byte> b_result(hash_->final());
101 if (len > b_result.size()) {
102 len = b_result.size();
104 result.writeData(&b_result[0], len);
105 }
catch (
const Botan::Exception& exc) {
107 "Botan error: " << exc.
what());
114 void final(
void* result,
size_t len) {
116 Botan::secure_vector<Botan::byte> b_result(hash_->final());
118 if (output_size > len) {
121 std::memcpy(result, &b_result[0], output_size);
122 }
catch (
const Botan::Exception& exc) {
124 "Botan error: " << exc.
what());
131 std::vector<uint8_t>
final(
size_t len) {
133 Botan::secure_vector<Botan::byte> b_result(hash_->final());
134 if (len > b_result.size()) {
135 len = b_result.size();
140 return (std::vector<uint8_t>(&b_result[0], &b_result[0]+len));
141 }
catch (
const Botan::Exception& exc) {
143 "Botan error: " << exc.
what());
152 std::unique_ptr<Botan::HashFunction> hash_;
157 impl_ =
new HashImpl(hash_algorithm);
181 impl_->
final(result, len);
186 impl_->
final(result, len);
191 return impl_->
final(len);
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Botan implementation of Hash.
size_t getOutputLength() const
Returns the output size of the digest.
HashAlgorithm getHashAlgorithm() const
Returns the HashAlgorithm of the object.
~HashImpl()=default
Destructor.
void update(const void *data, const size_t len)
Adds data to the digest.
HashImpl(const HashAlgorithm hash_algorithm)
Constructor for specific hash algorithm.
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.
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 raised when a general error that was not specifically caught is thrown by the under...
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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
const std::string getHashAlgorithmName(isc::cryptolink::HashAlgorithm algorithm)
Decode the HashAlgorithm enum into a name usable by Botan.
HashAlgorithm
Hash algorithm identifiers.
Defines the logger used by the top-level component of kea-lfc.