use new POW function consistently, also in revocation
authorChristian Grothoff <christian@grothoff.org>
Sat, 30 Nov 2019 22:08:49 +0000 (23:08 +0100)
committerChristian Grothoff <christian@grothoff.org>
Sat, 30 Nov 2019 22:08:49 +0000 (23:08 +0100)
src/include/gnunet_crypto_lib.h
src/nse/gnunet-service-nse.c
src/nse/perf_kdf.c
src/revocation/revocation_api.c
src/util/crypto_pow.c
src/util/gnunet-scrypt.c

index 4a42c5c74e6adad0d4debb9f19ef11e90809ea87..00fe3fbef86458ba3ca65bff2aa9574ffab7165a 100644 (file)
@@ -657,12 +657,14 @@ GNUNET_CRYPTO_hash (const void *block,
 /**
  * Calculate the 'proof-of-work' hash (an expensive hash).
  *
+ * @param salt salt to use in pow calculation
  * @param buf data to hash
  * @param buf_len number of bytes in @a buf
  * @param result where to write the resulting hash
  */
 void
-GNUNET_CRYPTO_pow_hash (const void *buf,
+GNUNET_CRYPTO_pow_hash (const char *salt,
+                        const void *buf,
                         size_t buf_len,
                         struct GNUNET_HashCode *result);
 
index 3f04314a614d80f0a5d37789282bd0676b8b6efa..f4d4e3e2fad934e2ff0c7ee30a6441f6f779aff4 100644 (file)
@@ -805,7 +805,10 @@ 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 (buf, sizeof(buf), &result);
+  GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
+                          buf,
+                          sizeof(buf),
+                          &result);
   return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES
          : GNUNET_NO;
 }
@@ -857,7 +860,10 @@ find_proof (void *cls)
   while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
   {
     GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
-    GNUNET_CRYPTO_pow_hash (buf, sizeof(buf), &result);
+    GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
+                            buf,
+                            sizeof(buf),
+                            &result);
     if (nse_work_required <= count_leading_zeroes (&result))
     {
       my_proof = counter;
index ec6dc7ff3088c8b07dfa716a558e2b085c910c89..c5975aaf2f5522aa0278d41a30f439616329368d 100644 (file)
 #include <gauger.h>
 
 
-/**
- * Calculate the 'proof-of-work' hash (an expensive hash).
- *
- * @param buf data to hash
- * @param buf_len number of bytes in 'buf'
- * @param result where to write the resulting hash
- */
-static void
-pow_hash (const void *buf,
-          size_t buf_len,
-          struct GNUNET_HashCode *result)
-{
-  GNUNET_break (0 ==
-                gcry_kdf_derive (buf, buf_len,
-                                 GCRY_KDF_SCRYPT,
-                                 1 /* subalgo */,
-                                 "gnunet-proof-of-work", strlen (
-                                   "gnunet-proof-of-work"),
-                                 2 /* iterations; keep cost of individual op small */,
-                                 sizeof(struct GNUNET_HashCode), result));
-}
-
-
 static void
 perfHash ()
 {
   struct GNUNET_HashCode hc;
-  unsigned int i;
   char buf[64];
 
   memset (buf, 1, sizeof(buf));
-  for (i = 0; i < 1024; i++)
-    pow_hash (buf, sizeof(buf), &hc);
+  for (unsigned int i = 0; i < 1024; i++)
+    GNUNET_CRYPTO_pow_hash ("gnunet-proof-of-work",
+                            buf,
+                            sizeof(buf),
+                            &hc);
 }
 
 
index fd25050e2b7d78986a50f78aad1fc8e3e1f6b21f..ea8db835fc2937633006e344b63c75afd0104cd2 100644 (file)
@@ -323,29 +323,6 @@ GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h)
 }
 
 
-/**
- * Calculate the 'proof-of-work' hash (an expensive hash).
- *
- * @param buf data to hash
- * @param buf_len number of bytes in @a buf
- * @param result where to write the resulting hash
- */
-static void
-pow_hash (const void *buf,
-          size_t buf_len,
-          struct GNUNET_HashCode *result)
-{
-  GNUNET_break (0 ==
-                gcry_kdf_derive (buf, buf_len,
-                                 GCRY_KDF_SCRYPT,
-                                 1 /* subalgo */,
-                                 "gnunet-revocation-proof-of-work",
-                                 strlen ("gnunet-revocation-proof-of-work"),
-                                 2 /* iterations; keep cost of individual op small */,
-                                 sizeof(struct GNUNET_HashCode), result));
-}
-
-
 /**
  * Count the leading zeroes in hash.
  *
@@ -385,7 +362,10 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
   GNUNET_memcpy (buf, &pow, sizeof(pow));
   GNUNET_memcpy (&buf[sizeof(pow)], key,
                  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
-  pow_hash (buf, sizeof(buf), &result);
+  GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work",
+                          buf,
+                          sizeof(buf),
+                          &result);
   return (count_leading_zeroes (&result) >=
           matching_bits) ? GNUNET_YES : GNUNET_NO;
 }
index 584665e9a27829ab32e9b27e5bc3778ef940ee90..af6837e03ab003972a46c2199913e68a704dc9dc 100644 (file)
  * We're using a non-standard formula to avoid issues with
  * ASICs appearing (see #3795).
  *
+ * @param salt salt for the hash
  * @param buf data to hash
  * @param buf_len number of bytes in @a buf
  * @param result where to write the resulting hash
  */
 void
-GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct
-                        GNUNET_HashCode *result)
+GNUNET_CRYPTO_pow_hash (const char *salt,
+                        const void *buf,
+                        size_t buf_len,
+                        struct GNUNET_HashCode *result)
 {
 #if NEW_CRYPTO
   struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
@@ -52,8 +55,8 @@ GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct
                                       buf_len,
                                       GCRY_KDF_SCRYPT,
                                       1 /* subalgo */,
-                                      "gnunet-proof-of-work-1",
-                                      strlen ("gnunet-proof-of-work-1"),
+                                      salt,
+                                      strlen (salt),
                                       2 /* iterations; keep cost of individual op small */,
                                       sizeof(skey),
                                       &skey));
@@ -61,6 +64,8 @@ GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct
                                      &skey,
                                      "gnunet-proof-of-work-iv",
                                      strlen ("gnunet-proof-of-work-iv"),
+                                     salt,
+                                     strlen (salt),
                                      NULL, 0);
   GNUNET_CRYPTO_symmetric_encrypt (buf,
                                    buf_len,
@@ -71,8 +76,8 @@ GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct
                                       buf_len,
                                       GCRY_KDF_SCRYPT,
                                       1 /* subalgo */,
-                                      "gnunet-proof-of-work-2",
-                                      strlen ("gnunet-proof-of-work-2"),
+                                      salt,
+                                      strlen (salt),
                                       2 /* iterations; keep cost of individual op small */,
                                       sizeof(struct GNUNET_HashCode),
                                       result));
@@ -81,8 +86,8 @@ GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct
                                       buf_len,
                                       GCRY_KDF_SCRYPT,
                                       1 /* subalgo */,
-                                      "gnunet-proof-of-work",
-                                      strlen ("gnunet-proof-of-work"),
+                                      salt,
+                                      strlen (salt),
                                       2 /* iterations; keep cost of individual op small */,
                                       sizeof(struct GNUNET_HashCode),
                                       result));
index d84f486a70522ee0183db37a5eee16f4ba369e1a..bc8ce83c035e66d838549678eda556eef3c4ff37 100644 (file)
@@ -117,7 +117,10 @@ find_proof (void *cls)
   while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
   {
     GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
-    GNUNET_CRYPTO_pow_hash (buf, sizeof(buf), &result);
+    GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
+                            buf,
+                            sizeof(buf),
+                            &result);
     if (nse_work_required <= count_leading_zeroes (&result))
     {
       proof = counter;