12#include <boost/scoped_ptr.hpp>
14#include <openssl/evp.h>
33 return (EVP_sha256());
35 return (EVP_sha224());
37 return (EVP_sha384());
39 return (EVP_sha512());
57 : hash_algorithm_(hash_algorithm), md_(0) {
61 "Unknown hash algorithm: " <<
62 static_cast<int>(hash_algorithm));
65 md_ = EVP_MD_CTX_new();
68 "OpenSSL EVP_MD_CTX_new() failed");
71 EVP_DigestInit_ex(md_, algo, NULL);
84 return (hash_algorithm_);
91 return (EVP_MD_CTX_size(md_));
97 void update(
const void* data,
const size_t len) {
98 EVP_DigestUpdate(md_, data, len);
106 std::vector<unsigned char>
digest(size);
107 EVP_DigestFinal_ex(md_, &
digest[0], NULL);
111 result.writeData(&
digest[0], len);
117 void final(
void* result,
size_t len) {
119 std::vector<unsigned char>
digest(size);
120 EVP_DigestFinal_ex(md_, &
digest[0], NULL);
124 std::memcpy(result, &
digest[0], len);
130 std::vector<uint8_t>
final(
size_t len) {
132 std::vector<unsigned char>
digest(size);
133 EVP_DigestFinal_ex(md_, &
digest[0], NULL);
137 return (std::vector<uint8_t>(
digest.begin(),
digest.end()));
149 impl_ =
new HashImpl(hash_algorithm);
173 impl_->
final(result, len);
178 impl_->
final(result, len);
183 return impl_->
final(len);
Botan implementation of Hash.
size_t getOutputLength() const
Returns the output size of the digest.
HashAlgorithm getHashAlgorithm() const
Returns the HashAlgorithm of the object.
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 EVP_MD * getHashAlgorithm(isc::cryptolink::HashAlgorithm algorithm)
Decode the HashAlgorithm enum into an EVP_MD pointer (or 0)
HashAlgorithm
Hash algorithm identifiers.
void digest(const void *data, const size_t data_len, const HashAlgorithm hash_algorithm, isc::util::OutputBuffer &result, size_t len)
Create an Hash digest for the given data.
Defines the logger used by the top-level component of kea-lfc.