12 #include <boost/scoped_ptr.hpp> 14 #include <openssl/evp.h> 23 namespace cryptolink {
38 return (EVP_sha256());
40 return (EVP_sha224());
42 return (EVP_sha384());
44 return (EVP_sha512());
62 : hash_algorithm_(hash_algorithm), md_(0) {
66 "Unknown hash algorithm: " <<
67 static_cast<int>(hash_algorithm));
70 md_ = EVP_MD_CTX_new();
73 "OpenSSL EVP_MD_CTX_new() failed");
76 EVP_DigestInit_ex(md_, algo, NULL);
89 return (hash_algorithm_);
96 return (EVP_MD_CTX_size(md_));
102 void update(
const void* data,
const size_t len) {
103 EVP_DigestUpdate(md_, data, len);
111 std::vector<unsigned char>
digest(size);
112 EVP_DigestFinal_ex(md_, &
digest[0], NULL);
116 result.writeData(&
digest[0], len);
122 void final(
void* result,
size_t len) {
124 std::vector<unsigned char>
digest(size);
125 EVP_DigestFinal_ex(md_, &
digest[0], NULL);
129 std::memcpy(result, &
digest[0], len);
135 std::vector<uint8_t>
final(
size_t len) {
137 std::vector<unsigned char>
digest(size);
138 EVP_DigestFinal_ex(md_, &
digest[0], NULL);
142 return (std::vector<uint8_t>(
digest.begin(),
digest.end()));
155 impl_ =
new HashImpl(hash_algorithm);
179 impl_->
final(result, len);
184 impl_->
final(result, len);
189 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.
Botan implementation of Hash.
void final(isc::util::OutputBuffer &result, size_t len)
Calculate the final digest.
HashAlgorithm
Hash algorithm identifiers.
const EVP_MD * getHashAlgorithm(isc::cryptolink::HashAlgorithm algorithm)
Decode the HashAlgorithm enum into an EVP_MD pointer (or 0)
#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.
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.
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...