aboutsummaryrefslogtreecommitdiff
path: root/src/nse
diff options
context:
space:
mode:
Diffstat (limited to 'src/nse')
-rw-r--r--src/nse/gnunet-service-nse.c33
-rw-r--r--src/nse/nse.conf.in3
-rw-r--r--src/nse/perf_kdf.c31
3 files changed, 14 insertions, 53 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 3e72be1c5..f4d4e3e2f 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -488,29 +488,6 @@ get_delay_randomization (uint32_t matching_bits)
488 488
489 489
490/** 490/**
491 * Calculate the 'proof-of-work' hash (an expensive hash).
492 *
493 * @param buf data to hash
494 * @param buf_len number of bytes in @a buf
495 * @param result where to write the resulting hash
496 */
497static void
498pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
499{
500 GNUNET_break (
501 0 == gcry_kdf_derive (buf,
502 buf_len,
503 GCRY_KDF_SCRYPT,
504 1 /* subalgo */,
505 "gnunet-proof-of-work",
506 strlen ("gnunet-proof-of-work"),
507 2 /* iterations; keep cost of individual op small */,
508 sizeof(struct GNUNET_HashCode),
509 result));
510}
511
512
513/**
514 * Get the number of matching bits that the given timestamp has to the given peer ID. 491 * Get the number of matching bits that the given timestamp has to the given peer ID.
515 * 492 *
516 * @param timestamp time to generate key 493 * @param timestamp time to generate key
@@ -828,7 +805,10 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey,
828 GNUNET_memcpy (&buf[sizeof(val)], 805 GNUNET_memcpy (&buf[sizeof(val)],
829 pkey, 806 pkey,
830 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)); 807 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey));
831 pow_hash (buf, sizeof(buf), &result); 808 GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
809 buf,
810 sizeof(buf),
811 &result);
832 return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES 812 return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES
833 : GNUNET_NO; 813 : GNUNET_NO;
834} 814}
@@ -880,7 +860,10 @@ find_proof (void *cls)
880 while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) 860 while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
881 { 861 {
882 GNUNET_memcpy (buf, &counter, sizeof(uint64_t)); 862 GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
883 pow_hash (buf, sizeof(buf), &result); 863 GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
864 buf,
865 sizeof(buf),
866 &result);
884 if (nse_work_required <= count_leading_zeroes (&result)) 867 if (nse_work_required <= count_leading_zeroes (&result))
885 { 868 {
886 my_proof = counter; 869 my_proof = counter;
diff --git a/src/nse/nse.conf.in b/src/nse/nse.conf.in
index f3bd90e42..d3c9a64b1 100644
--- a/src/nse/nse.conf.in
+++ b/src/nse/nse.conf.in
@@ -31,9 +31,8 @@ WORKDELAY = 5 ms
31# DO NOT CHANGE THIS VALUE, doing so will break the protocol! 31# DO NOT CHANGE THIS VALUE, doing so will break the protocol!
32INTERVAL = 1 h 32INTERVAL = 1 h
33 33
34# 2^22 hash operations take about 2-3h on a modern i7 (single-core) 34# 2^22 hash operations take about 2-3h on a first-generation i7 (single-core)
35# for SCRYPT; with 2ms/op and 5ms workdelay, we can expect 35# for SCRYPT; with 2ms/op and 5ms workdelay, we can expect
36# the POW calculation to be done by a high-end peer in about 6h 36# the POW calculation to be done by a high-end peer in about 6h
37# DO NOT CHANGE THIS VALUE, doing so will break the protocol! 37# DO NOT CHANGE THIS VALUE, doing so will break the protocol!
38WORKBITS = 22 38WORKBITS = 22
39
diff --git a/src/nse/perf_kdf.c b/src/nse/perf_kdf.c
index ec6dc7ff3..c5975aaf2 100644
--- a/src/nse/perf_kdf.c
+++ b/src/nse/perf_kdf.c
@@ -29,39 +29,18 @@
29#include <gauger.h> 29#include <gauger.h>
30 30
31 31
32/**
33 * Calculate the 'proof-of-work' hash (an expensive hash).
34 *
35 * @param buf data to hash
36 * @param buf_len number of bytes in 'buf'
37 * @param result where to write the resulting hash
38 */
39static void
40pow_hash (const void *buf,
41 size_t buf_len,
42 struct GNUNET_HashCode *result)
43{
44 GNUNET_break (0 ==
45 gcry_kdf_derive (buf, buf_len,
46 GCRY_KDF_SCRYPT,
47 1 /* subalgo */,
48 "gnunet-proof-of-work", strlen (
49 "gnunet-proof-of-work"),
50 2 /* iterations; keep cost of individual op small */,
51 sizeof(struct GNUNET_HashCode), result));
52}
53
54
55static void 32static void
56perfHash () 33perfHash ()
57{ 34{
58 struct GNUNET_HashCode hc; 35 struct GNUNET_HashCode hc;
59 unsigned int i;
60 char buf[64]; 36 char buf[64];
61 37
62 memset (buf, 1, sizeof(buf)); 38 memset (buf, 1, sizeof(buf));
63 for (i = 0; i < 1024; i++) 39 for (unsigned int i = 0; i < 1024; i++)
64 pow_hash (buf, sizeof(buf), &hc); 40 GNUNET_CRYPTO_pow_hash ("gnunet-proof-of-work",
41 buf,
42 sizeof(buf),
43 &hc);
65} 44}
66 45
67 46