summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-22 17:10:57 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-22 17:10:57 +0200
commitf225e568840aa0233fd41b7ccd838e8ba2031bf9 (patch)
tree80f6bc4247c6f5fbddcd27099ecbc3dc3203ca1f /src/util
parentbf99d2243fedaeb662b5d7b20138cf2ee064a110 (diff)
parentc4fa48421916ff0777e9cf1bbb3b83634392a494 (diff)
Merge branch 'schanzen/argon_pow'
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am1
-rw-r--r--src/util/crypto_pow.c86
2 files changed, 12 insertions, 75 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 = \
$(LIBIDN) $(LIBIDN2) \
$(Z_LIBS) \
-lunistring \
+ -largon2 \
$(XLIB) \
$(PTHREAD)
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c
index 9b20ab345..35511a130 100644
--- a/src/util/crypto_pow.c
+++ b/src/util/crypto_pow.c
@@ -25,7 +25,7 @@
*/
#include "platform.h"
#include "gnunet_crypto_lib.h"
-#include <gcrypt.h>
+#include <argon2.h>
/**
* Calculate the 'proof-of-work' hash (an expensive hash).
@@ -43,81 +43,17 @@ GNUNET_CRYPTO_pow_hash (const char *salt,
size_t buf_len,
struct GNUNET_HashCode *result)
{
-#ifdef LSD001
- char twofish_iv[128 / 8]; //128 bit IV
- char twofish_key[256 / 8]; //256 bit Key
- char rbuf[buf_len];
- int rc;
- gcry_cipher_hd_t handle;
+ GNUNET_break (ARGON2_OK == argon2d_hash_raw (3, /* iterations */
+ 1024, /* memory (1 MiB) */
+ 1, /* threads */
+ buf,
+ buf_len,
+ salt,
+ strlen (salt),
+ result,
+ sizeof (struct
+ GNUNET_HashCode)));
- GNUNET_break (0 == gcry_kdf_derive (buf,
- buf_len,
- GCRY_KDF_SCRYPT,
- 1 /* subalgo */,
- salt,
- strlen (salt),
- 2 /* iterations; keep cost of individual op small */,
- sizeof(twofish_key),
- &twofish_key));
-
- GNUNET_CRYPTO_kdf (twofish_iv,
- sizeof (twofish_iv),
- "gnunet-proof-of-work-iv",
- strlen ("gnunet-proof-of-work-iv"),
- twofish_key,
- sizeof(twofish_key),
- salt,
- strlen (salt),
- NULL, 0);
- GNUNET_assert (0 ==
- gcry_cipher_open (&handle, GCRY_CIPHER_TWOFISH,
- GCRY_CIPHER_MODE_CFB, 0));
- rc = gcry_cipher_setkey (handle,
- twofish_key,
- sizeof(twofish_key));
- GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
- rc = gcry_cipher_setiv (handle,
- twofish_iv,
- sizeof(twofish_iv));
- GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
- GNUNET_assert (0 == gcry_cipher_encrypt (handle, &rbuf, buf_len, buf, buf_len));
- gcry_cipher_close (handle);
-#else
- struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
- struct GNUNET_CRYPTO_SymmetricSessionKey skey;
- char rbuf[buf_len];
-
- GNUNET_break (0 == gcry_kdf_derive (buf,
- buf_len,
- GCRY_KDF_SCRYPT,
- 1 /* subalgo */,
- salt,
- strlen (salt),
- 2 /* iterations; keep cost of individual op small */,
- sizeof(skey),
- &skey));
- GNUNET_CRYPTO_symmetric_derive_iv (&iv,
- &skey,
- "gnunet-proof-of-work-iv",
- strlen ("gnunet-proof-of-work-iv"),
- salt,
- strlen (salt),
- NULL, 0);
- GNUNET_CRYPTO_symmetric_encrypt (buf,
- buf_len,
- &skey,
- &iv,
- &rbuf);
-#endif
- GNUNET_break (0 == gcry_kdf_derive (rbuf,
- buf_len,
- GCRY_KDF_SCRYPT,
- 1 /* subalgo */,
- salt,
- strlen (salt),
- 2 /* iterations; keep cost of individual op small */,
- sizeof(struct GNUNET_HashCode),
- result));
}