]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Actually check whether crypto_pwhash_str() is available
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 8 Apr 2021 16:35:51 +0000 (18:35 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 16 Sep 2021 12:12:27 +0000 (14:12 +0200)
Instead of just checking if libsodium is there.

pdns/credentials.cc
pdns/test-credentials_cc.cc

index edd845d35245fd02f144f3e190effef4e4dd0deb..e17111058d9f5a83a1b7a78a4c5a42af6c29523c 100644 (file)
@@ -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;
index c28067bc571557465a15a4303f6917af1bc976a6..a1853a82ab1b368838f4d5dea4277c42978ecef9 100644 (file)
@@ -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");