23 #include "../detail/openssl-helper.hpp"
32 #if OPENSSL_VERSION_NUMBER < 0x1010000fL
35 HMAC_CTX_init(&m_context);
40 HMAC_CTX_cleanup(&m_context);
52 : m_context(HMAC_CTX_new())
58 HMAC_CTX_free(m_context);
68 #endif // OPENSSL_VERSION_NUMBER < 0x1010000fL
74 BOOST_ASSERT(key !=
nullptr);
75 BOOST_ASSERT(keyLen > 0);
78 if (algorithm ==
nullptr)
79 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Unsupported digest algorithm"));
81 if (HMAC_Init_ex(*m_impl, key, keyLen, algorithm,
nullptr) == 0)
82 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Cannot initialize HMAC"));
86 HmacFilter::convert(
const uint8_t* buf,
size_t size)
88 if (HMAC_Update(*m_impl, buf, size) == 0)
89 BOOST_THROW_EXCEPTION(
Error(
getIndex(),
"Failed to update HMAC"));
95 HmacFilter::finalize()
97 auto buffer = make_unique<OBuffer>(EVP_MAX_MD_SIZE);
98 unsigned int mdLen = 0;
100 if (HMAC_Final(*m_impl, &(*buffer)[0], &mdLen) == 0)
101 BOOST_THROW_EXCEPTION(Error(
getIndex(),
"Failed to finalize HMAC"));
103 buffer->erase(buffer->begin() + mdLen, buffer->end());
109 unique_ptr<Transform>
112 return make_unique<HmacFilter>(algo, key, keyLen);
Copyright (c) 2013-2016 Regents of the University of California.
const EVP_MD * toDigestEvpMd(DigestAlgorithm algo)