gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: clean up GNUNET_CRYPTO_pow_hash API


From: gnunet
Subject: [gnunet] branch master updated: clean up GNUNET_CRYPTO_pow_hash API
Date: Mon, 17 Aug 2020 14:52:23 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 6f2ee9eb3 clean up GNUNET_CRYPTO_pow_hash API
6f2ee9eb3 is described below

commit 6f2ee9eb3c3642147fe381976ffeb88d0c3288e5
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Aug 17 14:45:46 2020 +0200

    clean up GNUNET_CRYPTO_pow_hash API
---
 src/include/gnunet_crypto_lib.h | 12 +++++++++++-
 src/nse/gnunet-service-nse.c    |  9 +++++++--
 src/nse/perf_kdf.c              |  3 ++-
 src/revocation/revocation_api.c |  6 ++++--
 src/util/crypto_pow.c           |  3 +--
 src/util/gnunet-scrypt.c        |  9 ++++++++-
 6 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index f8eef5406..6d3725aa0 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -50,6 +50,7 @@ extern "C" {
 #endif
 #endif
 
+#include <sodium.h>
 
 /**
  * The identity of the host (wraps the signing key of the peer).
@@ -667,6 +668,15 @@ GNUNET_CRYPTO_hash (const void *block,
                     struct GNUNET_HashCode *ret);
 
 
+/**
+ * Value for a salt for #GNUNET_CRYPTO_pow_hash().
+ */
+struct GNUNET_CRYPTO_PowSalt
+{
+  uint8_t salt[crypto_pwhash_argon2id_SALTBYTES];
+};
+
+
 /**
  * Calculate the 'proof-of-work' hash (an expensive hash).
  *
@@ -676,7 +686,7 @@ GNUNET_CRYPTO_hash (const void *block,
  * @param result where to write the resulting hash
  */
 void
-GNUNET_CRYPTO_pow_hash (const char *salt,
+GNUNET_CRYPTO_pow_hash (const struct GNUNET_CRYPTO_PowSalt *salt,
                         const void *buf,
                         size_t buf_len,
                         struct GNUNET_HashCode *result);
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index ebf39585e..dfd71e57a 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -113,6 +113,11 @@ static struct GNUNET_BIO_WriteHandle *histogram;
 
 #endif
 
+/**
+ * Salt for PoW calcualations.
+ */
+static struct GNUNET_CRYPTO_PowSalt salt = { "gnunet-nse-proof" };
+
 
 /**
  * Per-peer information.
@@ -806,7 +811,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",
+  GNUNET_CRYPTO_pow_hash (&salt,
                           buf,
                           sizeof(buf),
                           &result);
@@ -861,7 +866,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",
+    GNUNET_CRYPTO_pow_hash (&salt,
                             buf,
                             sizeof(buf),
                             &result);
diff --git a/src/nse/perf_kdf.c b/src/nse/perf_kdf.c
index 89b70903a..10207675f 100644
--- a/src/nse/perf_kdf.c
+++ b/src/nse/perf_kdf.c
@@ -34,10 +34,11 @@ perfHash ()
 {
   struct GNUNET_HashCode hc;
   char buf[64];
+  struct GNUNET_CRYPTO_PowSalt salt = { "gnunet-nse-proof" };
 
   memset (buf, 1, sizeof(buf));
   for (unsigned int i = 0; i < 1024; i++)
-    GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof",
+    GNUNET_CRYPTO_pow_hash (&salt,
                             buf,
                             sizeof(buf),
                             &hc);
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index e0b195aa9..75cfd8761 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -103,6 +103,8 @@ struct GNUNET_REVOCATION_PowCalculationHandle
 
 };
 
+static struct GNUNET_CRYPTO_PowSalt salt = { "GnsRevocationPow" };
+
 /**
  * Generic error handler, called with the appropriate
  * error code and the same closure specified at the creation of
@@ -483,7 +485,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 ("GnsRevocationPow",
+    GNUNET_CRYPTO_pow_hash (&salt,
                             buf,
                             sizeof(buf),
                             &result);
@@ -644,7 +646,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 ("GnsRevocationPow",
+  GNUNET_CRYPTO_pow_hash (&salt,
                           buf,
                           sizeof(buf),
                           &result);
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c
index cfa0676d0..051a0c209 100644
--- a/src/util/crypto_pow.c
+++ b/src/util/crypto_pow.c
@@ -38,12 +38,11 @@
  * @param result where to write the resulting hash
  */
 void
-GNUNET_CRYPTO_pow_hash (const char *salt,
+GNUNET_CRYPTO_pow_hash (const struct GNUNET_CRYPTO_PowSalt *salt,
                         const void *buf,
                         size_t buf_len,
                         struct GNUNET_HashCode *result)
 {
-  GNUNET_assert (strlen (salt) == crypto_pwhash_argon2id_SALTBYTES);
   /* Threads hardcoded at 1 in libsodium */
   GNUNET_break (0 ==
                 crypto_pwhash_argon2id ((unsigned char *) result,
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index aa64144a8..136c6debb 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -26,6 +26,13 @@
 #include "gnunet_util_lib.h"
 #include <gcrypt.h>
 
+
+/**
+ * Salt for PoW calcualations.
+ */
+static struct GNUNET_CRYPTO_PowSalt salt = { "gnunet-nse-proof" };
+
+
 /**
  * Amount of work required (W-bit collisions) for NSE proofs, in 
collision-bits.
  */
@@ -117,7 +124,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",
+    GNUNET_CRYPTO_pow_hash (&salt,
                             buf,
                             sizeof(buf),
                             &result);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]