aboutsummaryrefslogtreecommitdiff
path: root/src/nse/gnunet-service-nse.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-11-30 22:43:08 +0100
committerChristian Grothoff <christian@grothoff.org>2019-11-30 22:43:19 +0100
commitea544ab2cae7f4f969a705d33d10da1a004cbd70 (patch)
treeaa4cc29c9831b5bfa9221ed2740b46e6f79e8841 /src/nse/gnunet-service-nse.c
parentd817f861e6da2da5759a4b55117a8d8d47a91a87 (diff)
downloadgnunet-ea544ab2cae7f4f969a705d33d10da1a004cbd70.tar.gz
gnunet-ea544ab2cae7f4f969a705d33d10da1a004cbd70.zip
create crypto_pow, in preparation for #3795
Diffstat (limited to 'src/nse/gnunet-service-nse.c')
-rw-r--r--src/nse/gnunet-service-nse.c27
1 files changed, 2 insertions, 25 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index 3e72be1c5..3f04314a6 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -488,29 +488,6 @@ get_delay_randomization (uint32_t matching_bits)
488 488
489 489
490/** 490/**
491 * Calculate the 'proof-of-work' hash (an expensive hash).
492 *
493 * @param buf data to hash
494 * @param buf_len number of bytes in @a buf
495 * @param result where to write the resulting hash
496 */
497static void
498pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
499{
500 GNUNET_break (
501 0 == gcry_kdf_derive (buf,
502 buf_len,
503 GCRY_KDF_SCRYPT,
504 1 /* subalgo */,
505 "gnunet-proof-of-work",
506 strlen ("gnunet-proof-of-work"),
507 2 /* iterations; keep cost of individual op small */,
508 sizeof(struct GNUNET_HashCode),
509 result));
510}
511
512
513/**
514 * Get the number of matching bits that the given timestamp has to the given peer ID. 491 * Get the number of matching bits that the given timestamp has to the given peer ID.
515 * 492 *
516 * @param timestamp time to generate key 493 * @param timestamp time to generate key
@@ -828,7 +805,7 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey,
828 GNUNET_memcpy (&buf[sizeof(val)], 805 GNUNET_memcpy (&buf[sizeof(val)],
829 pkey, 806 pkey,
830 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)); 807 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey));
831 pow_hash (buf, sizeof(buf), &result); 808 GNUNET_CRYPTO_pow_hash (buf, sizeof(buf), &result);
832 return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES 809 return (count_leading_zeroes (&result) >= nse_work_required) ? GNUNET_YES
833 : GNUNET_NO; 810 : GNUNET_NO;
834} 811}
@@ -880,7 +857,7 @@ find_proof (void *cls)
880 while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) 857 while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
881 { 858 {
882 GNUNET_memcpy (buf, &counter, sizeof(uint64_t)); 859 GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
883 pow_hash (buf, sizeof(buf), &result); 860 GNUNET_CRYPTO_pow_hash (buf, sizeof(buf), &result);
884 if (nse_work_required <= count_leading_zeroes (&result)) 861 if (nse_work_required <= count_leading_zeroes (&result))
885 { 862 {
886 my_proof = counter; 863 my_proof = counter;