GNUnet  0.11.x
Functions
crypto_pow.c File Reference

proof-of-work hashing More...

#include "platform.h"
#include "gnunet_crypto_lib.h"
#include <gcrypt.h>
Include dependency graph for crypto_pow.c:

Go to the source code of this file.

Functions

void GNUNET_CRYPTO_pow_hash (const char *salt, const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
 Calculate the 'proof-of-work' hash (an expensive hash). More...
 

Detailed Description

proof-of-work hashing

Author
Christian Grothoff
Bart Polot

Definition in file crypto_pow.c.

Function Documentation

◆ GNUNET_CRYPTO_pow_hash()

void GNUNET_CRYPTO_pow_hash ( const char *  salt,
const void *  buf,
size_t  buf_len,
struct GNUNET_HashCode result 
)

Calculate the 'proof-of-work' hash (an expensive hash).

We're using a non-standard formula to avoid issues with ASICs appearing (see #3795).

Parameters
saltsalt for the hash
bufdata to hash
buf_lennumber of bytes in buf
resultwhere to write the resulting hash

Definition at line 41 of file crypto_pow.c.

References GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_kdf(), GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_CRYPTO_symmetric_encrypt(), and handle.

Referenced by check_proof_of_work(), find_proof(), and GNUNET_REVOCATION_check_pow().

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
88  char rbuf[buf_len];
89 
90  GNUNET_break (0 == gcry_kdf_derive (buf,
91  buf_len,
92  GCRY_KDF_SCRYPT,
93  1 /* subalgo */,
94  salt,
95  strlen (salt),
96  2 /* iterations; keep cost of individual op small */,
97  sizeof(skey),
98  &skey));
100  &skey,
101  "gnunet-proof-of-work-iv",
102  strlen ("gnunet-proof-of-work-iv"),
103  salt,
104  strlen (salt),
105  NULL, 0);
107  buf_len,
108  &skey,
109  &iv,
110  &rbuf);
111 #endif
112  GNUNET_break (0 == gcry_kdf_derive (rbuf,
113  buf_len,
114  GCRY_KDF_SCRYPT,
115  1 /* subalgo */,
116  salt,
117  strlen (salt),
118  2 /* iterations; keep cost of individual op small */,
119  sizeof(struct GNUNET_HashCode),
120  result));
121 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
void GNUNET_CRYPTO_symmetric_derive_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len,...)
Derive an IV.
static char buf[2048]
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
A 512-bit hashcode.
int GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:89
Here is the call graph for this function:
Here is the caller graph for this function: