summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-08-17 14:45:46 +0200
committerChristian Grothoff <christian@grothoff.org>2020-08-17 14:46:08 +0200
commit6f2ee9eb3c3642147fe381976ffeb88d0c3288e5 (patch)
tree26a66a4d123c667aa88d2aa5595add21390d53a8
parentf6acda6d3299bda2e6ea6e38bef5cabfb01b8ab9 (diff)
clean up GNUNET_CRYPTO_pow_hash API
-rw-r--r--src/include/gnunet_crypto_lib.h12
-rw-r--r--src/nse/gnunet-service-nse.c9
-rw-r--r--src/nse/perf_kdf.c3
-rw-r--r--src/revocation/revocation_api.c6
-rw-r--r--src/util/crypto_pow.c3
-rw-r--r--src/util/gnunet-scrypt.c9
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).
@@ -668,6 +669,15 @@ GNUNET_CRYPTO_hash (const void *block,
/**
+ * 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).
*
* @param salt salt for the hash. Must be crypto_pwhash_argon2id_SALTBYTES long.
@@ -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);