]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use sodium_memcmp() if CRYPTO_memcmp() is not available
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 8 Apr 2021 16:33:59 +0000 (18:33 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 16 Sep 2021 12:12:27 +0000 (14:12 +0200)
m4/pdns_with_libsodium.m4
pdns/misc.cc

index 44e034b2d267fc76128a7684d962a68fcd587327..2c316de7cae163ebeb0b396c594af5d0c65e2023 100644 (file)
@@ -15,7 +15,7 @@ AC_DEFUN([PDNS_WITH_LIBSODIUM], [
         save_LIBS=$LIBS
         CFLAGS="$LIBSODIUM_CFLAGS $CFLAGS"
         LIBS="$LIBSODIUM_LIBS $LIBS"
-        AC_CHECK_FUNCS([crypto_box_easy_afternm crypto_box_curve25519xchacha20poly1305_easy randombytes_stir])
+        AC_CHECK_FUNCS([crypto_box_easy_afternm crypto_box_curve25519xchacha20poly1305_easy randombytes_stir sodium_memcmp crypto_pwhash_str])
         CFLAGS=$save_CFLAGS
         LIBS=$save_LIBS
       ], [ : ])
index ca480c8f54c1c9601c69785dff8a5ebecc5fae83..ad3a2f450682c8c768d99eb8ba4ca5223ebae3a5 100644 (file)
@@ -1648,7 +1648,11 @@ size_t parseSVCBValueList(const std::string &in, vector<std::string> &val) {
 
 #ifdef HAVE_CRYPTO_MEMCMP
 #include <openssl/crypto.h>
-#endif
+#else /* HAVE_CRYPTO_MEMCMP */
+#ifdef HAVE_SODIUM_MEMCMP
+#include <sodium.h>
+#endif /* HAVE_SODIUM_MEMCMP */
+#endif /* HAVE_CRYPTO_MEMCMP */
 
 bool constantTimeStringEquals(const std::string& a, const std::string& b)
 {
@@ -1658,7 +1662,10 @@ bool constantTimeStringEquals(const std::string& a, const std::string& b)
   const size_t size = a.size();
 #ifdef HAVE_CRYPTO_MEMCMP
   return CRYPTO_memcmp(a.c_str(), b.c_str(), size) == 0;
-#else
+#else /* HAVE_CRYPTO_MEMCMP */
+#ifdef HAVE_SODIUM_MEMCMP
+  return sodium_memcmp(a.c_str(), b.c_str(), size) == 0;
+#else /* HAVE_SODIUM_MEMCMP */
   const volatile unsigned char *_a = (const volatile unsigned char *) a.c_str();
   const volatile unsigned char *_b = (const volatile unsigned char *) b.c_str();
   unsigned char res = 0;
@@ -1668,6 +1675,6 @@ bool constantTimeStringEquals(const std::string& a, const std::string& b)
   }
 
   return res == 0;
-#endif
+#endif /* !HAVE_SODIUM_MEMCMP */
+#endif /* !HAVE_CRYPTO_MEMCMP */
 }
-