diff options
Diffstat (limited to 'src/lib/util/crypto_pow.c')
-rw-r--r-- | src/lib/util/crypto_pow.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lib/util/crypto_pow.c b/src/lib/util/crypto_pow.c new file mode 100644 index 000000000..bfaaf555d --- /dev/null +++ b/src/lib/util/crypto_pow.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2012, 2013, 2019 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/crypto_pow.c | ||
22 | * @brief proof-of-work hashing | ||
23 | * @author Christian Grothoff | ||
24 | * @author Bart Polot | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include <sodium.h> | ||
30 | |||
31 | /** | ||
32 | * Calculate the 'proof-of-work' hash (an expensive hash). | ||
33 | * We're using a non-standard formula to avoid issues with | ||
34 | * ASICs appearing (see #3795). | ||
35 | * | ||
36 | * @param salt salt for the hash. Must be crypto_pwhash_argon2id_SALTBYTES long. | ||
37 | * @param buf data to hash | ||
38 | * @param buf_len number of bytes in @a buf | ||
39 | * @param result where to write the resulting hash | ||
40 | */ | ||
41 | void | ||
42 | GNUNET_CRYPTO_pow_hash (const struct GNUNET_CRYPTO_PowSalt *salt, | ||
43 | const void *buf, | ||
44 | size_t buf_len, | ||
45 | struct GNUNET_HashCode *result) | ||
46 | { | ||
47 | /* Threads hardcoded at 1 in libsodium */ | ||
48 | GNUNET_break (0 == | ||
49 | crypto_pwhash_argon2id ((unsigned char *) result, | ||
50 | sizeof (struct GNUNET_HashCode), | ||
51 | buf, | ||
52 | buf_len, | ||
53 | (unsigned char*) salt, | ||
54 | 3, /* iterations */ | ||
55 | 1024 * 1024, /* memory (1 MiB) */ | ||
56 | crypto_pwhash_argon2id_ALG_ARGON2ID13)); | ||
57 | } | ||
58 | |||
59 | |||
60 | /* end of crypto_pow.c */ | ||