aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/util/Makefile.am1
-rw-r--r--src/util/crypto_pow.c59
2 files changed, 37 insertions, 23 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index ae72abb44..fed0dad79 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -133,6 +133,7 @@ libgnunetutil_la_LIBADD = \
133 $(LIBIDN) $(LIBIDN2) \ 133 $(LIBIDN) $(LIBIDN2) \
134 $(Z_LIBS) \ 134 $(Z_LIBS) \
135 -lunistring \ 135 -lunistring \
136 -largon2 \
136 $(XLIB) \ 137 $(XLIB) \
137 $(PTHREAD) 138 $(PTHREAD)
138 139
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c
index 9b20ab345..d3e4dbc43 100644
--- a/src/util/crypto_pow.c
+++ b/src/util/crypto_pow.c
@@ -25,7 +25,9 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_crypto_lib.h" 27#include "gnunet_crypto_lib.h"
28#include <gcrypt.h> 28#include <argon2.h>
29
30#define LSD001
29 31
30/** 32/**
31 * Calculate the 'proof-of-work' hash (an expensive hash). 33 * Calculate the 'proof-of-work' hash (an expensive hash).
@@ -44,21 +46,21 @@ GNUNET_CRYPTO_pow_hash (const char *salt,
44 struct GNUNET_HashCode *result) 46 struct GNUNET_HashCode *result)
45{ 47{
46#ifdef LSD001 48#ifdef LSD001
47 char twofish_iv[128 / 8]; //128 bit IV 49 char twofish_iv[128 / 8]; // 128 bit IV
48 char twofish_key[256 / 8]; //256 bit Key 50 char twofish_key[256 / 8]; // 256 bit Key
49 char rbuf[buf_len]; 51 char rbuf[buf_len];
50 int rc; 52 int rc;
51 gcry_cipher_hd_t handle; 53 gcry_cipher_hd_t handle;
52 54
53 GNUNET_break (0 == gcry_kdf_derive (buf, 55 GNUNET_break (ARGON2_OK == argon2d_hash_raw (2, /* iterations */
54 buf_len, 56 100000, /* memory (kb) */
55 GCRY_KDF_SCRYPT, 57 1, /* threads */
56 1 /* subalgo */, 58 buf,
57 salt, 59 buf_len,
58 strlen (salt), 60 salt,
59 2 /* iterations; keep cost of individual op small */, 61 strlen (salt),
60 sizeof(twofish_key), 62 &twofish_key,
61 &twofish_key)); 63 sizeof (twofish_key)));
62 64
63 GNUNET_CRYPTO_kdf (twofish_iv, 65 GNUNET_CRYPTO_kdf (twofish_iv,
64 sizeof (twofish_iv), 66 sizeof (twofish_iv),
@@ -80,22 +82,33 @@ GNUNET_CRYPTO_pow_hash (const char *salt,
80 twofish_iv, 82 twofish_iv,
81 sizeof(twofish_iv)); 83 sizeof(twofish_iv));
82 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); 84 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
83 GNUNET_assert (0 == gcry_cipher_encrypt (handle, &rbuf, buf_len, buf, buf_len)); 85 GNUNET_assert (0 == gcry_cipher_encrypt (handle, &rbuf, buf_len, buf,
86 buf_len));
84 gcry_cipher_close (handle); 87 gcry_cipher_close (handle);
88 GNUNET_break (ARGON2_OK == argon2d_hash_raw (2, /* iterations */
89 100000, /* memory */
90 1, /* threads */
91 rbuf,
92 buf_len,
93 salt,
94 strlen (salt),
95 result,
96 sizeof (struct GNUNET_HashCode)));
97
85#else 98#else
86 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 99 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
87 struct GNUNET_CRYPTO_SymmetricSessionKey skey; 100 struct GNUNET_CRYPTO_SymmetricSessionKey skey;
88 char rbuf[buf_len]; 101 char rbuf[buf_len];
89 102
90 GNUNET_break (0 == gcry_kdf_derive (buf, 103 GNUNET_break (ARGON2_OK == argon2d_hash_raw (buf,
91 buf_len, 104 buf_len,
92 GCRY_KDF_SCRYPT, 105 GCRY_KDF_SCRYPT,
93 1 /* subalgo */, 106 1 /* subalgo */,
94 salt, 107 salt,
95 strlen (salt), 108 strlen (salt),
96 2 /* iterations; keep cost of individual op small */, 109 2 /* iterations; keep cost of individual op small */,
97 sizeof(skey), 110 sizeof(skey),
98 &skey)); 111 &skey));
99 GNUNET_CRYPTO_symmetric_derive_iv (&iv, 112 GNUNET_CRYPTO_symmetric_derive_iv (&iv,
100 &skey, 113 &skey,
101 "gnunet-proof-of-work-iv", 114 "gnunet-proof-of-work-iv",
@@ -108,7 +121,6 @@ GNUNET_CRYPTO_pow_hash (const char *salt,
108 &skey, 121 &skey,
109 &iv, 122 &iv,
110 &rbuf); 123 &rbuf);
111#endif
112 GNUNET_break (0 == gcry_kdf_derive (rbuf, 124 GNUNET_break (0 == gcry_kdf_derive (rbuf,
113 buf_len, 125 buf_len,
114 GCRY_KDF_SCRYPT, 126 GCRY_KDF_SCRYPT,
@@ -118,6 +130,7 @@ GNUNET_CRYPTO_pow_hash (const char *salt,
118 2 /* iterations; keep cost of individual op small */, 130 2 /* iterations; keep cost of individual op small */,
119 sizeof(struct GNUNET_HashCode), 131 sizeof(struct GNUNET_HashCode),
120 result)); 132 result));
133#endif
121} 134}
122 135
123 136