use new POW function consistently, also in revocation
[oweals/gnunet.git] / src / nse / gnunet-service-nse.c
index d16abed719fce2021e3f7f01973b2d86fa88e7c1..f4d4e3e2fad934e2ff0c7ee30a6441f6f779aff4 100644 (file)
@@ -75,7 +75,7 @@
   (GNUNET_MQ_PRIO_BACKGROUND | GNUNET_MQ_PREF_UNRELIABLE   \
    | GNUNET_MQ_PREF_CORK_ALLOWED)
 
-#if BSD
+#ifdef BSD
 #define log2(a) (log (a) / log (2))
 #endif
 
@@ -487,29 +487,6 @@ get_delay_randomization (uint32_t matching_bits)
 }
 
 
-/**
- * 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-proof-of-work",
-                          strlen ("gnunet-proof-of-work"),
-                          2 /* iterations; keep cost of individual op small */,
-                          sizeof(struct GNUNET_HashCode),
-                          result));
-}
-
-
 /**
  * Get the number of matching bits that the given timestamp has to the given peer ID.
  *
@@ -828,7 +805,10 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey,
   GNUNET_memcpy (&buf[sizeof(val)],
                  pkey,
                  sizeof(struct GNUNET_CRYPTO_EddsaPublicKey));
-  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;
 }
@@ -880,7 +860,10 @@ find_proof (void *cls)
   while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
   {
     GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
-    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;
@@ -1579,7 +1562,7 @@ GNUNET_SERVICE_MAIN ("nse",
                      GNUNET_MQ_handler_end ());
 
 
-#if defined(LINUX) && defined(__GLIBC__)
+#if defined(__linux__) && defined(__GLIBC__)
 #include <malloc.h>
 
 /**