aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-03-15 22:06:34 +0100
committerChristian Grothoff <christian@grothoff.org>2020-03-15 22:06:34 +0100
commit16864fd3b848f78fa6e1928c7ae6b37826c316d3 (patch)
treee8c1047f4ff14d41f009c0909dafcd4af0bfcc85 /src
parent7de26292b744122b20e9cd6ecea95a2273311587 (diff)
parentb37cfa2fdf9443f824c8d5585f9a892525e556f9 (diff)
downloadgnunet-16864fd3b848f78fa6e1928c7ae6b37826c316d3.tar.gz
gnunet-16864fd3b848f78fa6e1928c7ae6b37826c316d3.zip
Merge branch 'master' of git+ssh://gnunet.org/gnunet
Diffstat (limited to 'src')
-rw-r--r--src/util/crypto_pow.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/util/crypto_pow.c b/src/util/crypto_pow.c
index be575e537..9b20ab345 100644
--- a/src/util/crypto_pow.c
+++ b/src/util/crypto_pow.c
@@ -27,7 +27,6 @@
27#include "gnunet_crypto_lib.h" 27#include "gnunet_crypto_lib.h"
28#include <gcrypt.h> 28#include <gcrypt.h>
29 29
30
31/** 30/**
32 * Calculate the 'proof-of-work' hash (an expensive hash). 31 * Calculate the 'proof-of-work' hash (an expensive hash).
33 * We're using a non-standard formula to avoid issues with 32 * We're using a non-standard formula to avoid issues with
@@ -44,6 +43,46 @@ GNUNET_CRYPTO_pow_hash (const char *salt,
44 size_t buf_len, 43 size_t buf_len,
45 struct GNUNET_HashCode *result) 44 struct GNUNET_HashCode *result)
46{ 45{
46#ifdef LSD001
47 char twofish_iv[128 / 8]; //128 bit IV
48 char twofish_key[256 / 8]; //256 bit Key
49 char rbuf[buf_len];
50 int rc;
51 gcry_cipher_hd_t handle;
52
53 GNUNET_break (0 == gcry_kdf_derive (buf,
54 buf_len,
55 GCRY_KDF_SCRYPT,
56 1 /* subalgo */,
57 salt,
58 strlen (salt),
59 2 /* iterations; keep cost of individual op small */,
60 sizeof(twofish_key),
61 &twofish_key));
62
63 GNUNET_CRYPTO_kdf (twofish_iv,
64 sizeof (twofish_iv),
65 "gnunet-proof-of-work-iv",
66 strlen ("gnunet-proof-of-work-iv"),
67 twofish_key,
68 sizeof(twofish_key),
69 salt,
70 strlen (salt),
71 NULL, 0);
72 GNUNET_assert (0 ==
73 gcry_cipher_open (&handle, GCRY_CIPHER_TWOFISH,
74 GCRY_CIPHER_MODE_CFB, 0));
75 rc = gcry_cipher_setkey (handle,
76 twofish_key,
77 sizeof(twofish_key));
78 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
79 rc = gcry_cipher_setiv (handle,
80 twofish_iv,
81 sizeof(twofish_iv));
82 GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
83 GNUNET_assert (0 == gcry_cipher_encrypt (handle, &rbuf, buf_len, buf, buf_len));
84 gcry_cipher_close (handle);
85#else
47 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 86 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
48 struct GNUNET_CRYPTO_SymmetricSessionKey skey; 87 struct GNUNET_CRYPTO_SymmetricSessionKey skey;
49 char rbuf[buf_len]; 88 char rbuf[buf_len];
@@ -69,6 +108,7 @@ GNUNET_CRYPTO_pow_hash (const char *salt,
69 &skey, 108 &skey,
70 &iv, 109 &iv,
71 &rbuf); 110 &rbuf);
111#endif
72 GNUNET_break (0 == gcry_kdf_derive (rbuf, 112 GNUNET_break (0 == gcry_kdf_derive (rbuf,
73 buf_len, 113 buf_len,
74 GCRY_KDF_SCRYPT, 114 GCRY_KDF_SCRYPT,