aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_crypto_lib.h4
-rw-r--r--src/nse/gnunet-service-nse.c10
-rw-r--r--src/nse/perf_kdf.c31
-rw-r--r--src/revocation/revocation_api.c28
-rw-r--r--src/util/crypto_pow.c21
-rw-r--r--src/util/gnunet-scrypt.c5
6 files changed, 37 insertions, 62 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 4a42c5c74..00fe3fbef 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -657,12 +657,14 @@ GNUNET_CRYPTO_hash (const void *block,
657/** 657/**
658 * Calculate the 'proof-of-work' hash (an expensive hash). 658 * Calculate the 'proof-of-work' hash (an expensive hash).
659 * 659 *
660 * @param salt salt to use in pow calculation
660 * @param buf data to hash 661 * @param buf data to hash
661 * @param buf_len number of bytes in @a buf 662 * @param buf_len number of bytes in @a buf
662 * @param result where to write the resulting hash 663 * @param result where to write the resulting hash
663 */ 664 */
664void 665void
665GNUNET_CRYPTO_pow_hash (const void *buf, 666GNUNET_CRYPTO_pow_hash (const char *salt,
667 const void *buf,
666 size_t buf_len, 668 size_t buf_len,
667 struct GNUNET_HashCode *result); 669 struct GNUNET_HashCode *result);
668 670
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 3f04314a6..f4d4e3e2f 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -805,7 +805,10 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey,
805 GNUNET_memcpy (&buf[sizeof(val)], 805 GNUNET_memcpy (&buf[sizeof(val)],
806 pkey, 806 pkey,
807 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)); 807 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey));
808 GNUNET_CRYPTO_pow_hash (buf, sizeof(buf), &result); 808 GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
809 buf,
810 sizeof(buf),
811 &result);
809 return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES 812 return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES
810 : GNUNET_NO; 813 : GNUNET_NO;
811} 814}
@@ -857,7 +860,10 @@ find_proof (void *cls)
857 while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) 860 while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
858 { 861 {
859 GNUNET_memcpy (buf, &counter, sizeof(uint64_t)); 862 GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
860 GNUNET_CRYPTO_pow_hash (buf, sizeof(buf), &result); 863 GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
864 buf,
865 sizeof(buf),
866 &result);
861 if (nse_work_required <= count_leading_zeroes (&result)) 867 if (nse_work_required <= count_leading_zeroes (&result))
862 { 868 {
863 my_proof = counter; 869 my_proof = counter;
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
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index fd25050e2..ea8db835f 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -324,29 +324,6 @@ GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h)
324 324
325 325
326/** 326/**
327 * Calculate the 'proof-of-work' hash (an expensive hash).
328 *
329 * @param buf data to hash
330 * @param buf_len number of bytes in @a buf
331 * @param result where to write the resulting hash
332 */
333static void
334pow_hash (const void *buf,
335 size_t buf_len,
336 struct GNUNET_HashCode *result)
337{
338 GNUNET_break (0 ==
339 gcry_kdf_derive (buf, buf_len,
340 GCRY_KDF_SCRYPT,
341 1 /* subalgo */,
342 "gnunet-revocation-proof-of-work",
343 strlen ("gnunet-revocation-proof-of-work"),
344 2 /* iterations; keep cost of individual op small */,
345 sizeof(struct GNUNET_HashCode), result));
346}
347
348
349/**
350 * Count the leading zeroes in hash. 327 * Count the leading zeroes in hash.
351 * 328 *
352 * @param hash to count leading zeros in 329 * @param hash to count leading zeros in
@@ -385,7 +362,10 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
385 GNUNET_memcpy (buf, &pow, sizeof(pow)); 362 GNUNET_memcpy (buf, &pow, sizeof(pow));
386 GNUNET_memcpy (&buf[sizeof(pow)], key, 363 GNUNET_memcpy (&buf[sizeof(pow)], key,
387 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); 364 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
388 pow_hash (buf, sizeof(buf), &result); 365 GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work",
366 buf,
367 sizeof(buf),
368 &result);
389 return (count_leading_zeroes (&result) >= 369 return (count_leading_zeroes (&result) >=
390 matching_bits) ? GNUNET_YES : GNUNET_NO; 370 matching_bits) ? GNUNET_YES : GNUNET_NO;
391} 371}
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c
index 584665e9a..af6837e03 100644
--- a/src/util/crypto_pow.c
+++ b/src/util/crypto_pow.c
@@ -35,13 +35,16 @@
35 * We're using a non-standard formula to avoid issues with 35 * We're using a non-standard formula to avoid issues with
36 * ASICs appearing (see #3795). 36 * ASICs appearing (see #3795).
37 * 37 *
38 * @param salt salt for the hash
38 * @param buf data to hash 39 * @param buf data to hash
39 * @param buf_len number of bytes in @a buf 40 * @param buf_len number of bytes in @a buf
40 * @param result where to write the resulting hash 41 * @param result where to write the resulting hash
41 */ 42 */
42void 43void
43GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct 44GNUNET_CRYPTO_pow_hash (const char *salt,
44 GNUNET_HashCode *result) 45 const void *buf,
46 size_t buf_len,
47 struct GNUNET_HashCode *result)
45{ 48{
46#if NEW_CRYPTO 49#if NEW_CRYPTO
47 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 50 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
@@ -52,8 +55,8 @@ GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct
52 buf_len, 55 buf_len,
53 GCRY_KDF_SCRYPT, 56 GCRY_KDF_SCRYPT,
54 1 /* subalgo */, 57 1 /* subalgo */,
55 "gnunet-proof-of-work-1", 58 salt,
56 strlen ("gnunet-proof-of-work-1"), 59 strlen (salt),
57 2 /* iterations; keep cost of individual op small */, 60 2 /* iterations; keep cost of individual op small */,
58 sizeof(skey), 61 sizeof(skey),
59 &skey)); 62 &skey));
@@ -61,6 +64,8 @@ GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct
61 &skey, 64 &skey,
62 "gnunet-proof-of-work-iv", 65 "gnunet-proof-of-work-iv",
63 strlen ("gnunet-proof-of-work-iv"), 66 strlen ("gnunet-proof-of-work-iv"),
67 salt,
68 strlen (salt),
64 NULL, 0); 69 NULL, 0);
65 GNUNET_CRYPTO_symmetric_encrypt (buf, 70 GNUNET_CRYPTO_symmetric_encrypt (buf,
66 buf_len, 71 buf_len,
@@ -71,8 +76,8 @@ GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct
71 buf_len, 76 buf_len,
72 GCRY_KDF_SCRYPT, 77 GCRY_KDF_SCRYPT,
73 1 /* subalgo */, 78 1 /* subalgo */,
74 "gnunet-proof-of-work-2", 79 salt,
75 strlen ("gnunet-proof-of-work-2"), 80 strlen (salt),
76 2 /* iterations; keep cost of individual op small */, 81 2 /* iterations; keep cost of individual op small */,
77 sizeof(struct GNUNET_HashCode), 82 sizeof(struct GNUNET_HashCode),
78 result)); 83 result));
@@ -81,8 +86,8 @@ GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct
81 buf_len, 86 buf_len,
82 GCRY_KDF_SCRYPT, 87 GCRY_KDF_SCRYPT,
83 1 /* subalgo */, 88 1 /* subalgo */,
84 "gnunet-proof-of-work", 89 salt,
85 strlen ("gnunet-proof-of-work"), 90 strlen (salt),
86 2 /* iterations; keep cost of individual op small */, 91 2 /* iterations; keep cost of individual op small */,
87 sizeof(struct GNUNET_HashCode), 92 sizeof(struct GNUNET_HashCode),
88 result)); 93 result));
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index d84f486a7..bc8ce83c0 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -117,7 +117,10 @@ find_proof (void *cls)
117 while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) 117 while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
118 { 118 {
119 GNUNET_memcpy (buf, &counter, sizeof(uint64_t)); 119 GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
120 GNUNET_CRYPTO_pow_hash (buf, sizeof(buf), &result); 120 GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof-of-work",
121 buf,
122 sizeof(buf),
123 &result);
121 if (nse_work_required <= count_leading_zeroes (&result)) 124 if (nse_work_required <= count_leading_zeroes (&result))
122 { 125 {
123 proof = counter; 126 proof = counter;