25 #include "ndn-cxx/security/impl/openssl-helper.hpp" 27 #include <boost/lexical_cast.hpp> 33 class VerifierFilter::Impl
36 Impl(
const uint8_t*
sig,
size_t siglen)
51 : m_impl(make_unique<Impl>(sig, sigLen))
52 , m_keyType(key.getKeyType())
54 init(algo, key.getEvpPkey());
59 : m_impl(make_unique<Impl>(sig, sigLen))
60 , m_keyType(key.getKeyType())
65 init(algo, key.getEvpPkey());
73 const EVP_MD* md = detail::digestAlgorithmToEvpMd(algo);
76 boost::lexical_cast<std::string>(algo)));
80 ret = EVP_DigestSignInit(m_impl->ctx,
nullptr, md,
nullptr, reinterpret_cast<EVP_PKEY*>(pkey));
82 ret = EVP_DigestVerifyInit(m_impl->ctx,
nullptr, md,
nullptr, reinterpret_cast<EVP_PKEY*>(pkey));
86 boost::lexical_cast<std::string>(algo) +
" digest and " +
87 boost::lexical_cast<std::string>(m_keyType) +
" key"));
91 VerifierFilter::convert(
const uint8_t* buf,
size_t size)
95 ret = EVP_DigestSignUpdate(m_impl->ctx, buf, size);
97 ret = EVP_DigestVerifyUpdate(m_impl->ctx, buf, size);
106 VerifierFilter::finalize()
110 auto hmacBuf = make_unique<OBuffer>(EVP_MAX_MD_SIZE);
113 if (EVP_DigestSignFinal(m_impl->ctx, hmacBuf->data(), &hmacLen) != 1)
116 ok = CRYPTO_memcmp(hmacBuf->data(), m_impl->sig, std::min(hmacLen, m_impl->siglen)) == 0;
119 ok = EVP_DigestVerifyFinal(m_impl->ctx, m_impl->sig, m_impl->siglen) == 1;
122 auto buffer = make_unique<OBuffer>(1);
123 (*buffer)[0] = ok ? 1 : 0;
129 unique_ptr<Transform>
132 return make_unique<VerifierFilter>(algo, key,
sig,
sigLen);
135 unique_ptr<Transform>
138 return make_unique<VerifierFilter>(algo, key,
sig,
sigLen);
HMAC key, supports sign/verify operations.