From: Schanzenbach, Martin Date: Sun, 15 Mar 2020 14:18:53 +0000 (+0100) Subject: implement new simplified POW for LSD001 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b37cfa2fdf9443f824c8d5585f9a892525e556f9;p=oweals%2Fgnunet.git implement new simplified POW for LSD001 --- 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 @@ #include "gnunet_crypto_lib.h" #include - /** * Calculate the 'proof-of-work' hash (an expensive hash). * We're using a non-standard formula to avoid issues with @@ -44,6 +43,46 @@ 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 (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]; @@ -69,6 +108,7 @@ GNUNET_CRYPTO_pow_hash (const char *salt, &skey, &iv, &rbuf); +#endif GNUNET_break (0 == gcry_kdf_derive (rbuf, buf_len, GCRY_KDF_SCRYPT,