aboutsummaryrefslogtreecommitdiff
path: root/src/revocation
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-05-13 18:00:03 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-05-13 18:00:03 +0200
commit151a0ae35e030d7358b9e9041d8b3ad1838b7349 (patch)
treec78c9ffba4e21bff8bac21ff369fe8a62cf748a2 /src/revocation
parent6707d15ba0232c1ff3485f5ccb3f3c26a77feba7 (diff)
parentf3a3e4ebe452ed741c7d01384c64cbf224d45c95 (diff)
downloadgnunet-151a0ae35e030d7358b9e9041d8b3ad1838b7349.tar.gz
gnunet-151a0ae35e030d7358b9e9041d8b3ad1838b7349.zip
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src/revocation')
-rw-r--r--src/revocation/Makefile.am12
-rw-r--r--src/revocation/gnunet-revocation-tvg.c123
2 files changed, 134 insertions, 1 deletions
diff --git a/src/revocation/Makefile.am b/src/revocation/Makefile.am
index b3b2877ca..6efd461c1 100644
--- a/src/revocation/Makefile.am
+++ b/src/revocation/Makefile.am
@@ -16,7 +16,8 @@ pkgcfg_DATA = \
16 revocation.conf 16 revocation.conf
17 17
18bin_PROGRAMS = \ 18bin_PROGRAMS = \
19 gnunet-revocation 19 gnunet-revocation \
20 gnunet-revocation-tvg
20 21
21 22
22plugin_LTLIBRARIES = \ 23plugin_LTLIBRARIES = \
@@ -41,6 +42,15 @@ gnunet_revocation_LDADD = \
41 $(top_builddir)/src/util/libgnunetutil.la \ 42 $(top_builddir)/src/util/libgnunetutil.la \
42 $(GN_LIBINTL) 43 $(GN_LIBINTL)
43 44
45gnunet_revocation_tvg_SOURCES = \
46 gnunet-revocation-tvg.c
47gnunet_revocation_tvg_LDADD = \
48 libgnunetrevocation.la \
49 $(top_builddir)/src/identity/libgnunetidentity.la \
50 $(top_builddir)/src/util/libgnunetutil.la \
51 $(GN_LIBINTL)
52
53
44lib_LTLIBRARIES = libgnunetrevocation.la 54lib_LTLIBRARIES = libgnunetrevocation.la
45 55
46libgnunetrevocation_la_SOURCES = \ 56libgnunetrevocation_la_SOURCES = \
diff --git a/src/revocation/gnunet-revocation-tvg.c b/src/revocation/gnunet-revocation-tvg.c
new file mode 100644
index 000000000..23a4bf020
--- /dev/null
+++ b/src/revocation/gnunet-revocation-tvg.c
@@ -0,0 +1,123 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020 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/**
22 * @file util/gnunet-revocation-tvg.c
23 * @brief Generate test vectors for revocation.
24 * @author Martin Schanzenbach
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_signatures.h"
29#include "gnunet_revocation_service.h"
30#include "gnunet_dnsparser_lib.h"
31#include "gnunet_testing_lib.h"
32#include <inttypes.h>
33
34#define TEST_EPOCHS 2
35#define TEST_DIFFICULTY 5
36
37/**
38 * Main function that will be run.
39 *
40 * @param cls closure
41 * @param args remaining command-line arguments
42 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
43 * @param cfg configuration
44 */
45static void
46run (void *cls,
47 char *const *args,
48 const char *cfgfile,
49 const struct GNUNET_CONFIGURATION_Handle *cfg)
50{
51 struct GNUNET_CRYPTO_EcdsaPrivateKey id_priv;
52 struct GNUNET_CRYPTO_EcdsaPublicKey id_pub;
53 struct GNUNET_REVOCATION_PowP pow;
54 struct GNUNET_REVOCATION_PowCalculationHandle *ph;
55 char* data_enc;
56
57 GNUNET_CRYPTO_ecdsa_key_create (&id_priv);
58 GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv,
59 &id_pub);
60 GNUNET_STRINGS_base64_encode (&id_priv,
61 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
62 &data_enc);
63 fprintf(stdout, "Zone private key (d):\n%s\n\n", data_enc);
64 GNUNET_free (data_enc);
65 GNUNET_STRINGS_base64_encode (&id_pub,
66 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
67 &data_enc);
68 fprintf(stdout, "Zone public key (zk):\n%s\n\n", data_enc);
69 GNUNET_free (data_enc);
70
71 GNUNET_REVOCATION_pow_init (&id_priv,
72 &pow);
73 ph = GNUNET_REVOCATION_pow_start (&pow,
74 TEST_EPOCHS,
75 TEST_DIFFICULTY);
76 fprintf (stdout, "Difficulty (%d base difficulty + %d epochs): %d\n\n",
77 TEST_DIFFICULTY,
78 TEST_EPOCHS,
79 TEST_DIFFICULTY + TEST_EPOCHS);
80 uint64_t pow_passes = 0;
81 while (GNUNET_YES != GNUNET_REVOCATION_pow_round (ph))
82 {
83 pow_passes++;
84 }
85 GNUNET_STRINGS_base64_encode (&pow,
86 sizeof (struct GNUNET_REVOCATION_PowP),
87 &data_enc);
88 fprintf(stdout, "Proof:\n%s\n", data_enc);
89 GNUNET_free (data_enc);
90}
91
92
93/**
94 * The main function of the test vector generation tool.
95 *
96 * @param argc number of arguments from the command line
97 * @param argv command line arguments
98 * @return 0 ok, 1 on error
99 */
100int
101main (int argc,
102 char *const *argv)
103{
104 const struct GNUNET_GETOPT_CommandLineOption options[] = {
105 GNUNET_GETOPT_OPTION_END
106 };
107
108 GNUNET_assert (GNUNET_OK ==
109 GNUNET_log_setup ("gnunet-revocation-tvg",
110 "INFO",
111 NULL));
112 if (GNUNET_OK !=
113 GNUNET_PROGRAM_run (argc, argv,
114 "gnunet-revocation-tvg",
115 "Generate test vectors for revocation",
116 options,
117 &run, NULL))
118 return 1;
119 return 0;
120}
121
122
123/* end of gnunet-revocation-tvg.c */