aboutsummaryrefslogtreecommitdiff
path: root/src/nse
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-03-23 20:00:45 +0000
committerChristian Grothoff <christian@grothoff.org>2013-03-23 20:00:45 +0000
commitd5eec64dbfd73da3f179d9223a3108a6bff5ed71 (patch)
treeb28f93b247e1eee4a6e442a11be34daa7d0c6690 /src/nse
parent856ce6820e23c219d58816dd12b5a99a59b9e667 (diff)
downloadgnunet-d5eec64dbfd73da3f179d9223a3108a6bff5ed71.tar.gz
gnunet-d5eec64dbfd73da3f179d9223a3108a6bff5ed71.zip
-towards implementing #2685
Diffstat (limited to 'src/nse')
-rw-r--r--src/nse/Makefile.am9
-rw-r--r--src/nse/gnunet-service-nse.c30
-rw-r--r--src/nse/nse.conf.in3
-rw-r--r--src/nse/perf_kdf.c86
4 files changed, 123 insertions, 5 deletions
diff --git a/src/nse/Makefile.am b/src/nse/Makefile.am
index a67ffeaf8..971d4c1b1 100644
--- a/src/nse/Makefile.am
+++ b/src/nse/Makefile.am
@@ -53,7 +53,7 @@ gnunet_service_nse_LDADD = \
53 $(top_builddir)/src/util/libgnunetutil.la \ 53 $(top_builddir)/src/util/libgnunetutil.la \
54 $(top_builddir)/src/core/libgnunetcore.la \ 54 $(top_builddir)/src/core/libgnunetcore.la \
55 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 55 $(top_builddir)/src/statistics/libgnunetstatistics.la \
56 -lm \ 56 -lm -lgcrypt \
57 $(GN_LIBINTL) 57 $(GN_LIBINTL)
58gnunet_service_nse_DEPENDENCIES = \ 58gnunet_service_nse_DEPENDENCIES = \
59 libgnunetnse.la 59 libgnunetnse.la
@@ -64,6 +64,7 @@ endif
64 64
65check_PROGRAMS = \ 65check_PROGRAMS = \
66 test_nse_api \ 66 test_nse_api \
67 perf_kdf \
67 $(MULTIPEER_TEST) 68 $(MULTIPEER_TEST)
68 69
69 70
@@ -86,6 +87,12 @@ test_nse_multipeer_LDADD = \
86 $(top_builddir)/src/testbed/libgnunettestbed.la \ 87 $(top_builddir)/src/testbed/libgnunettestbed.la \
87 -lm 88 -lm
88 89
90perf_kdf_SOURCES = \
91 perf_kdf.c
92perf_kdf_LDADD = \
93 $(top_builddir)/src/util/libgnunetutil.la \
94 -lgcrypt
95
89EXTRA_DIST = \ 96EXTRA_DIST = \
90 test_nse.conf \ 97 test_nse.conf \
91 nse_profiler_test.conf 98 nse_profiler_test.conf
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c
index b3707ca75..3047860b8 100644
--- a/src/nse/gnunet-service-nse.c
+++ b/src/nse/gnunet-service-nse.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2010, 2011, 2012, 2013 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -45,6 +45,8 @@
45#include "gnunet_core_service.h" 45#include "gnunet_core_service.h"
46#include "gnunet_nse_service.h" 46#include "gnunet_nse_service.h"
47#include "nse.h" 47#include "nse.h"
48#include <gcrypt.h>
49
48 50
49/** 51/**
50 * Should messages be delayed randomly? This option should be set to 52 * Should messages be delayed randomly? This option should be set to
@@ -477,6 +479,28 @@ get_delay_randomization (uint32_t matching_bits)
477 479
478 480
479/** 481/**
482 * Calculate the 'proof-of-work' hash (an expensive hash).
483 *
484 * @param buf data to hash
485 * @param buf_len number of bytes in 'buf'
486 * @param result where to write the resulting hash
487 */
488static void
489pow_hash (const void *buf,
490 size_t buf_len,
491 struct GNUNET_HashCode *result)
492{
493 GNUNET_break (0 ==
494 gcry_kdf_derive (buf, buf_len,
495 GCRY_KDF_PBKDF2 /* FIX: use SCRYPT! */,
496 1 /* subalgo */,
497 "gnunet-proof-of-work", strlen ("gnunet-proof-of-work"),
498 2 /* iterations; keep cost of individual op small */,
499 sizeof (struct GNUNET_HashCode), result));
500}
501
502
503/**
480 * Get the number of matching bits that the given timestamp has to the given peer ID. 504 * Get the number of matching bits that the given timestamp has to the given peer ID.
481 * 505 *
482 * @param timestamp time to generate key 506 * @param timestamp time to generate key
@@ -835,7 +859,7 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pkey,
835 memcpy (buf, &val, sizeof (val)); 859 memcpy (buf, &val, sizeof (val));
836 memcpy (&buf[sizeof (val)], pkey, 860 memcpy (&buf[sizeof (val)], pkey,
837 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)); 861 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
838 GNUNET_CRYPTO_hash (buf, sizeof (buf), &result); 862 pow_hash (buf, sizeof (buf), &result);
839 return (count_leading_zeroes (&result) >= 863 return (count_leading_zeroes (&result) >=
840 nse_work_required) ? GNUNET_YES : GNUNET_NO; 864 nse_work_required) ? GNUNET_YES : GNUNET_NO;
841} 865}
@@ -886,7 +910,7 @@ find_proof (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
886 while ((counter != UINT64_MAX) && (i < ROUND_SIZE)) 910 while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
887 { 911 {
888 memcpy (buf, &counter, sizeof (uint64_t)); 912 memcpy (buf, &counter, sizeof (uint64_t));
889 GNUNET_CRYPTO_hash (buf, sizeof (buf), &result); 913 pow_hash (buf, sizeof (buf), &result);
890 if (nse_work_required <= count_leading_zeroes (&result)) 914 if (nse_work_required <= count_leading_zeroes (&result))
891 { 915 {
892 my_proof = counter; 916 my_proof = counter;
diff --git a/src/nse/nse.conf.in b/src/nse/nse.conf.in
index 84f1f6c22..374617fa8 100644
--- a/src/nse/nse.conf.in
+++ b/src/nse/nse.conf.in
@@ -19,6 +19,7 @@ WORKDELAY = 5 ms
19# Note: changing any of the values below will make this peer 19# Note: changing any of the values below will make this peer
20# completely incompatible with other peers! 20# completely incompatible with other peers!
21INTERVAL = 1 h 21INTERVAL = 1 h
22# 26 is about 10 minutes on a modern i7 (single-core) 22# 26 is about 100 minutes on a modern i7 (single-core) for PBKDF2;
23# need to re-calibrate once we have SCRYPT!
23WORKBITS = 26 24WORKBITS = 26
24 25
diff --git a/src/nse/perf_kdf.c b/src/nse/perf_kdf.c
new file mode 100644
index 000000000..e462c129f
--- /dev/null
+++ b/src/nse/perf_kdf.c
@@ -0,0 +1,86 @@
1/*
2 This file is part of GNUnet.
3 (C) 2002, 2003, 2004, 2006, 2013 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @author Christian Grothoff
23 * @file nse/perf_kdf.c
24 * @brief measure performance of KDF hash function
25 */
26#include "platform.h"
27#include "gnunet_common.h"
28#include "gnunet_util_lib.h"
29#include <gcrypt.h>
30#include <gauger.h>
31
32
33
34/**
35 * Calculate the 'proof-of-work' hash (an expensive hash).
36 *
37 * @param buf data to hash
38 * @param buf_len number of bytes in 'buf'
39 * @param result where to write the resulting hash
40 */
41static void
42pow_hash (const void *buf,
43 size_t buf_len,
44 struct GNUNET_HashCode *result)
45{
46 GNUNET_break (0 ==
47 gcry_kdf_derive (buf, buf_len,
48 GCRY_KDF_PBKDF2 /* FIX: use SCRYPT! */,
49 1 /* subalgo */,
50 "gnunet-proof-of-work", strlen ("gnunet-proof-of-work"),
51 2 /* iterations; keep cost of individual op small */,
52 sizeof (struct GNUNET_HashCode), result));
53}
54
55
56static void
57perfHash ()
58{
59 struct GNUNET_HashCode hc;
60 unsigned int i;
61 char buf[64];
62
63 memset (buf, 1, sizeof (buf));
64 for (i = 0; i < 1024; i++)
65 pow_hash (buf, sizeof (buf), &hc);
66}
67
68
69int
70main (int argc, char *argv[])
71{
72 struct GNUNET_TIME_Absolute start;
73
74 start = GNUNET_TIME_absolute_get ();
75 perfHash ();
76 printf ("Hash perf took %s\n",
77 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
78 GNUNET_YES));
79 GAUGER ("NSE", "Proof-of-work hashing",
80 1024 / (1 +
81 GNUNET_TIME_absolute_get_duration
82 (start).rel_value), "hashes/s");
83 return 0;
84}
85
86/* end of perf_kdf.c */