From 769f1b4b0470ee4c6f483ad165f6d025d30b943d Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 8 Apr 2021 18:35:51 +0200 Subject: [PATCH] Actually check whether crypto_pwhash_str() is available Instead of just checking if libsodium is there. --- pdns/credentials.cc | 8 ++++---- pdns/test-credentials_cc.cc | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pdns/credentials.cc b/pdns/credentials.cc index edd845d352..e17111058d 100644 --- a/pdns/credentials.cc +++ b/pdns/credentials.cc @@ -32,7 +32,7 @@ std::string hashPassword(const std::string& password) { -#ifdef HAVE_LIBSODIUM +#ifdef HAVE_CRYPTO_PWHASH_STR std::string result; result.resize(crypto_pwhash_STRBYTES); sodium_mlock(result.data(), result.size()); @@ -54,7 +54,7 @@ std::string hashPassword(const std::string& password) bool verifyPassword(const std::string& hash, const std::string& password) { -#ifdef HAVE_LIBSODIUM +#ifdef HAVE_CRYPTO_PWHASH_STR if (hash.size() > crypto_pwhash_STRBYTES) { throw std::runtime_error("Invalid password hash supplied for verification, size is " + std::to_string(hash.size()) + ", expected at most " + std::to_string(crypto_pwhash_STRBYTES)); } @@ -70,7 +70,7 @@ bool verifyPassword(const std::string& hash, const std::string& password) bool isPasswordHashed(const std::string& password) { -#ifdef HAVE_LIBSODIUM +#ifdef HAVE_CRYPTO_PWHASH_STR if (password.size() > crypto_pwhash_STRBYTES) { return false; } @@ -145,7 +145,7 @@ bool CredentialsHolder::matches(const std::string& password) const bool CredentialsHolder::isHashingAvailable() { -#ifdef HAVE_LIBSODIUM +#ifdef HAVE_CRYPTO_PWHASH_STR return true; #else return false; diff --git a/pdns/test-credentials_cc.cc b/pdns/test-credentials_cc.cc index c28067bc57..a1853a82ab 100644 --- a/pdns/test-credentials_cc.cc +++ b/pdns/test-credentials_cc.cc @@ -9,7 +9,7 @@ BOOST_AUTO_TEST_SUITE(credentials_cc) -#ifdef HAVE_LIBSODIUM +#ifdef HAVE_CRYPTO_PWHASH_STR BOOST_AUTO_TEST_CASE(test_CredentialsUtils) { const std::string plaintext("test"); @@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(test_CredentialsHolder) BOOST_CHECK(!holder.matches("not test")); BOOST_CHECK(!holder.wasHashed()); -#ifdef HAVE_LIBSODIUM +#ifdef HAVE_CRYPTO_PWHASH_STR BOOST_CHECK(CredentialsHolder::isHashingAvailable()); const std::string sampleHash("$argon2id$v=19$m=65536,t=2,p=1$ndQKu3+ZsWedqRrlNFUaNw$tnb0MJVe5C2hlqkDt0Ln3R6VKCYkfMYdxDy+puXes3s"); -- 2.47.2