aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-11-30 22:51:51 +0100
committerChristian Grothoff <christian@grothoff.org>2019-11-30 22:51:51 +0100
commitf536489f831c5fd243c22545be12a2cd0f88a84d (patch)
tree8e8dffa034594c6696bbee54ad7b78452d0edd96 /src/util
parentea544ab2cae7f4f969a705d33d10da1a004cbd70 (diff)
downloadgnunet-f536489f831c5fd243c22545be12a2cd0f88a84d.tar.gz
gnunet-f536489f831c5fd243c22545be12a2cd0f88a84d.zip
implement code for #3795
Diffstat (limited to 'src/util')
-rw-r--r--src/util/crypto_pow.c57
1 files changed, 46 insertions, 11 deletions
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c
index b4dfbf53a..584665e9a 100644
--- a/src/util/crypto_pow.c
+++ b/src/util/crypto_pow.c
@@ -23,11 +23,12 @@
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * @author Bart Polot 24 * @author Bart Polot
25 */ 25 */
26
27#include "platform.h" 26#include "platform.h"
28#include "gnunet_crypto_lib.h" 27#include "gnunet_crypto_lib.h"
29#include <gcrypt.h> 28#include <gcrypt.h>
30 29
30/* FIXME: change to 1 for #3795 / 0.12! */
31#define NEW_CRYPTO 0
31 32
32/** 33/**
33 * Calculate the 'proof-of-work' hash (an expensive hash). 34 * Calculate the 'proof-of-work' hash (an expensive hash).
@@ -42,16 +43,50 @@ void
42GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct 43GNUNET_CRYPTO_pow_hash (const void *buf, size_t buf_len, struct
43 GNUNET_HashCode *result) 44 GNUNET_HashCode *result)
44{ 45{
45 GNUNET_break ( 46#if NEW_CRYPTO
46 0 == gcry_kdf_derive (buf, 47 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
47 buf_len, 48 struct GNUNET_CRYPTO_SymmetricSessionKey skey;
48 GCRY_KDF_SCRYPT, 49 char rbuf[buf_len];
49 1 /* subalgo */, 50
50 "gnunet-proof-of-work", 51 GNUNET_break (0 == gcry_kdf_derive (buf,
51 strlen ("gnunet-proof-of-work"), 52 buf_len,
52 2 /* iterations; keep cost of individual op small */, 53 GCRY_KDF_SCRYPT,
53 sizeof(struct GNUNET_HashCode), 54 1 /* subalgo */,
54 result)); 55 "gnunet-proof-of-work-1",
56 strlen ("gnunet-proof-of-work-1"),
57 2 /* iterations; keep cost of individual op small */,
58 sizeof(skey),
59 &skey));
60 GNUNET_CRYPTO_symmetric_derive_iv (&iv,
61 &skey,
62 "gnunet-proof-of-work-iv",
63 strlen ("gnunet-proof-of-work-iv"),
64 NULL, 0);
65 GNUNET_CRYPTO_symmetric_encrypt (buf,
66 buf_len,
67 &skey,
68 &iv,
69 &rbuf);
70 GNUNET_break (0 == gcry_kdf_derive (rbuf,
71 buf_len,
72 GCRY_KDF_SCRYPT,
73 1 /* subalgo */,
74 "gnunet-proof-of-work-2",
75 strlen ("gnunet-proof-of-work-2"),
76 2 /* iterations; keep cost of individual op small */,
77 sizeof(struct GNUNET_HashCode),
78 result));
79#else
80 GNUNET_break (0 == gcry_kdf_derive (buf,
81 buf_len,
82 GCRY_KDF_SCRYPT,
83 1 /* subalgo */,
84 "gnunet-proof-of-work",
85 strlen ("gnunet-proof-of-work"),
86 2 /* iterations; keep cost of individual op small */,
87 sizeof(struct GNUNET_HashCode),
88 result));
89#endif
55} 90}
56 91
57 92