in src/native/hashing/hasher.cpp [155:215]
void hasher::reset()
{
#ifdef USE_BCRYPT
#ifndef STATUS_SUCCESS
#define STATUS_SUCCESS ((NTSTATUS)0x00000000)
#endif
BCRYPT_HASH_HANDLE hash_handle;
NTSTATUS ntstatus = BCryptCreateHash(
m_algorithm_provider_handle.get(), &hash_handle, nullptr, 0, nullptr, 0, BCRYPT_HASH_REUSABLE_FLAG);
if (ntstatus != STATUS_SUCCESS)
{
std::string msg = "BCryptCreateHash() returned: " + std::to_string(ntstatus);
throw errors::user_exception(errors::error_code::hash_initialization_failure, msg);
}
m_hash_handle.reset(hash_handle);
#endif
#ifdef USE_LIBGCRYPT
if (m_hd)
{
gcry_md_reset(m_hd);
}
else
{
auto algo = alg_to_gcrypt_algo(m_alg);
auto open_err = gcry_md_open(&m_hd, algo, 0);
if (open_err)
{
std::string msg = "gcry_md_open(" + gcrypt_algo_to_string(algo) + ") failed: ";
msg += get_libgcrypt_err_message(open_err);
throw errors::user_exception(errors::error_code::hash_initialization_failure, msg);
}
}
#endif
#ifdef USE_OPENSSL
auto evp_mp = algorithm_to_EVP_MP(m_alg);
if (evp_mp == nullptr)
{
std::string msg = "Couldn't get evp_mp for algorithm: " + std::to_string(static_cast<int>(m_alg));
throw errors::user_exception(errors::error_code::hash_initialization_failure, msg);
}
if (m_md_ctx == nullptr)
{
m_md_ctx = EVP_MD_CTX_new();
}
else
{
EVP_MD_CTX_reset(m_md_ctx);
}
if (!EVP_DigestInit_ex(m_md_ctx, evp_mp, NULL))
{
std::string msg = "EVP_DigestInit_ex() failed with err = " + std::to_string(static_cast<int>(ERR_get_error()));
throw errors::user_exception(errors::error_code::hash_initialization_failure, msg);
}
#endif
}