remove argon2 dependency. Use limited libsodium argon2id function for GNS and NSE
authorMartin Schanzenbach <mschanzenbach@posteo.de>
Tue, 26 May 2020 09:49:50 +0000 (11:49 +0200)
committerMartin Schanzenbach <mschanzenbach@posteo.de>
Tue, 26 May 2020 09:49:50 +0000 (11:49 +0200)
README
configure.ac
src/include/gnunet_crypto_lib.h
src/nse/gnunet-service-nse.c
src/nse/perf_kdf.c
src/revocation/revocation_api.c
src/util/Makefile.am
src/util/crypto_pow.c
src/util/gnunet-scrypt.c

diff --git a/README b/README
index 34f573d4d6cb1b687e9a44e984fea1bcfd1eb517..d95022de256f708f3317dc03cf44f40b8bb39b96 100644 (file)
--- a/README
+++ b/README
@@ -96,8 +96,6 @@ These are the direct dependencies for running GNUnet:
 - which                             (contrib/apparmor(?), gnunet-bugreport,
                                      and possibly more)
 - zlib
-- argon2             >= 20190702    (for proof-of-work calculations in
-                                     revocation)
 - libsodium          >= 1.0.11      (for elliptic curve cryptography)
 
 These are the dependencies for GNUnet's testsuite:
index 1c732a15242dfeea478aaab8948c7142e97d7802..6dc914c12cfc042eb094826994e48937341c2a95 100644 (file)
@@ -1033,20 +1033,10 @@ AS_IF([test x$nss = xfalse],
 AC_CHECK_LIB([kvm],[kvm_open])
 AC_CHECK_LIB([kstat],[kstat_open])
 
-argon=0
-# test for argon2 (for POW)
-AC_CHECK_LIB([argon2],[argon2d_hash_raw], argon=1, argon=0)
-AS_IF([test x$argon = x1],
-[
- AC_MSG_RESULT([argon2 found])
-],[
- AC_MSG_ERROR([GNUnet requires argon2.])
-])
-
 libsodium=0
 # test for libsodium
 AC_CHECK_HEADER([sodium.h],
-                [AC_CHECK_LIB([sodium], [sodium_init],
+                [AC_CHECK_LIB([sodium], [crypto_pwhash_argon2id],
                               [libsodium=1])])
 
 AS_IF([test x$libsodium = x0],
index e880bd8870f297a1086ce6e1a78b52a5dadc8278..437a1283f134536424f6c00f6873119ebb792710 100644 (file)
@@ -659,7 +659,7 @@ GNUNET_CRYPTO_hash (const void *block,
 /**
  * Calculate the 'proof-of-work' hash (an expensive hash).
  *
- * @param salt salt to use in pow calculation
+ * @param salt salt for the hash. Must be crypto_pwhash_argon2id_SALTBYTES long.
  * @param buf data to hash
  * @param buf_len number of bytes in @a buf
  * @param result where to write the resulting hash
index 461d55a7f2dd1757e8b302346e6c54c5e16304e9..ebf39585e8b87d94c4cbb1ad1683ce6c69819364 100644 (file)
@@ -806,7 +806,7 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey,
   GNUNET_memcpy (&buf[sizeof(val)],
                  pkey,
                  sizeof(struct GNUNET_CRYPTO_EddsaPublicKey));
-  GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
+  GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof",
                           buf,
                           sizeof(buf),
                           &result);
@@ -861,7 +861,7 @@ find_proof (void *cls)
   while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
   {
     GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
-    GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
+    GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof",
                             buf,
                             sizeof(buf),
                             &result);
index c5975aaf2f5522aa0278d41a30f439616329368d..89b70903a1c6c0ed74927ce8a27545414904cf91 100644 (file)
@@ -37,7 +37,7 @@ perfHash ()
 
   memset (buf, 1, sizeof(buf));
   for (unsigned int i = 0; i < 1024; i++)
-    GNUNET_CRYPTO_pow_hash ("gnunet-proof-of-work",
+    GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof",
                             buf,
                             sizeof(buf),
                             &hc);
index 33c67d005554c0fd6d1df70503fe8c7ebf0ce0e2..3815e47b0f0f4ab5b9c74cc194974a31920c1788 100644 (file)
@@ -483,7 +483,7 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow,
   {
     pow_val = GNUNET_ntohll (pow->pow[i]);
     GNUNET_memcpy (buf, &pow->pow[i], sizeof(uint64_t));
-    GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work",
+    GNUNET_CRYPTO_pow_hash ("GnsRevocationPow",
                             buf,
                             sizeof(buf),
                             &result);
@@ -642,7 +642,7 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
   GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
                  &pc->pow->key,
                  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
-  GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work",
+  GNUNET_CRYPTO_pow_hash ("GnsRevocationPow",
                           buf,
                           sizeof(buf),
                           &result);
index f3373fc3849fdfb15fc563b4b3e3c2a1195dd068..83b3b9c3d28d946c6a5462b0241a03230c532181 100644 (file)
@@ -131,7 +131,6 @@ libgnunetutil_la_LIBADD = \
   $(LIBIDN) $(LIBIDN2) \
   $(Z_LIBS) \
   -lunistring \
-  -largon2 \
   -lsodium \
   $(XLIB) \
   $(PTHREAD)
index 6176afc33739363bfe427c44deecfeb22e43c4b7..cfa0676d06051e5c6efeb59d46bcb5c5b65b81e2 100644 (file)
  */
 #include "platform.h"
 #include "gnunet_crypto_lib.h"
-#include <argon2.h>
+#include <sodium.h>
 
 /**
  * Calculate the 'proof-of-work' hash (an expensive hash).
  * We're using a non-standard formula to avoid issues with
  * ASICs appearing (see #3795).
  *
- * @param salt salt for the hash
+ * @param salt salt for the hash. Must be crypto_pwhash_argon2id_SALTBYTES long.
  * @param buf data to hash
  * @param buf_len number of bytes in @a buf
  * @param result where to write the resulting hash
@@ -43,16 +43,17 @@ GNUNET_CRYPTO_pow_hash (const char *salt,
                         size_t buf_len,
                         struct GNUNET_HashCode *result)
 {
-  GNUNET_break (ARGON2_OK ==
-                argon2id_hash_raw (3, /* iterations */
-                                   1024,              /* memory (1 MiB) */
-                                   1,              /* threads */
-                                   buf,
-                                   buf_len,
-                                   salt,
-                                   strlen (salt),
-                                   result,
-                                   sizeof (struct GNUNET_HashCode)));
+  GNUNET_assert (strlen (salt) == crypto_pwhash_argon2id_SALTBYTES);
+  /* Threads hardcoded at 1 in libsodium */
+  GNUNET_break (0 ==
+                crypto_pwhash_argon2id ((unsigned char *) result,
+                                        sizeof (struct GNUNET_HashCode),
+                                        buf,
+                                        buf_len,
+                                        (unsigned char*) salt,
+                                        3, /* iterations */
+                                        1024 * 1024, /* memory (1 MiB) */
+                                        crypto_pwhash_argon2id_ALG_ARGON2ID13));
 }
 
 
index 9bb766595fa936bf194547a55e86417c7fd21e4d..7d13ce46960b14d601dac2b8c0819e49b09c8d03 100644 (file)
@@ -117,7 +117,7 @@ find_proof (void *cls)
   while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
   {
     GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
-    GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
+    GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof",
                             buf,
                             sizeof(buf),
                             &result);