aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/gnunet-revocation-tvg.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-19 10:19:42 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-19 10:19:42 +0200
commit4e28833d9ecb6bbd933b770eae2b712fc0d80286 (patch)
treef3501ba172352dcfed9bb7072d969417e852270a /src/revocation/gnunet-revocation-tvg.c
parent3bfe2d52dcac5df09783d82b3a80899ae5b5d69a (diff)
downloadgnunet-4e28833d9ecb6bbd933b770eae2b712fc0d80286.tar.gz
gnunet-4e28833d9ecb6bbd933b770eae2b712fc0d80286.zip
BUILD: Move revocation to service
Diffstat (limited to 'src/revocation/gnunet-revocation-tvg.c')
-rw-r--r--src/revocation/gnunet-revocation-tvg.c229
1 files changed, 0 insertions, 229 deletions
diff --git a/src/revocation/gnunet-revocation-tvg.c b/src/revocation/gnunet-revocation-tvg.c
deleted file mode 100644
index b59b7ba62..000000000
--- a/src/revocation/gnunet-revocation-tvg.c
+++ /dev/null
@@ -1,229 +0,0 @@
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_testing_lib.h"
31#include "revocation.h"
32#include <inttypes.h>
33
34#define TEST_EPOCHS 2
35#define TEST_DIFFICULTY 5
36
37static char*d_pkey =
38 "6fea32c05af58bfa979553d188605fd57d8bf9cc263b78d5f7478c07b998ed70";
39
40static char *d_edkey =
41 "5af7020ee19160328832352bbc6a68a8d71a7cbe1b929969a7c66d415a0d8f65";
42
43int
44parsehex (char *src, char *dst, size_t dstlen, int invert)
45{
46 char *line = src;
47 char *data = line;
48 int off;
49 int read_byte;
50 int data_len = 0;
51
52 while (sscanf (data, " %02x%n", &read_byte, &off) == 1)
53 {
54 if (invert)
55 dst[dstlen - 1 - data_len++] = read_byte;
56 else
57 dst[data_len++] = read_byte;
58 data += off;
59 }
60 return data_len;
61}
62
63
64static void
65print_bytes_ (void *buf,
66 size_t buf_len,
67 int fold,
68 int in_be)
69{
70 int i;
71
72 for (i = 0; i < buf_len; i++)
73 {
74 if (0 != i)
75 {
76 if ((0 != fold) && (i % fold == 0))
77 printf ("\n ");
78 else
79 printf (" ");
80 }
81 else
82 {
83 printf (" ");
84 }
85 if (in_be)
86 printf ("%02x", ((unsigned char*) buf)[buf_len - 1 - i]);
87 else
88 printf ("%02x", ((unsigned char*) buf)[i]);
89 }
90 printf ("\n");
91}
92
93
94static void
95print_bytes (void *buf,
96 size_t buf_len,
97 int fold)
98{
99 print_bytes_ (buf, buf_len, fold, 0);
100}
101
102
103static void
104run_with_key (struct GNUNET_CRYPTO_PrivateKey *id_priv)
105{
106 struct GNUNET_CRYPTO_PublicKey id_pub;
107 struct GNUNET_REVOCATION_PowP *pow;
108 struct GNUNET_REVOCATION_PowCalculationHandle *ph;
109 struct GNUNET_TIME_Relative exp;
110 char ztld[128];
111 ssize_t key_len;
112
113 GNUNET_CRYPTO_key_get_public (id_priv,
114 &id_pub);
115 GNUNET_STRINGS_data_to_string (&id_pub,
116 GNUNET_CRYPTO_public_key_get_length (
117 &id_pub),
118 ztld,
119 sizeof (ztld));
120 fprintf (stdout, "\n");
121 fprintf (stdout, "Zone identifier (ztype|zkey):\n");
122 key_len = GNUNET_CRYPTO_public_key_get_length (&id_pub);
123 GNUNET_assert (0 < key_len);
124 print_bytes (&id_pub, key_len, 8);
125 fprintf (stdout, "\n");
126 fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n");
127 fprintf (stdout, "%s\n", ztld);
128 fprintf (stdout, "\n");
129 pow = GNUNET_malloc (GNUNET_REVOCATION_MAX_PROOF_SIZE);
130 GNUNET_REVOCATION_pow_init (id_priv,
131 pow);
132 ph = GNUNET_REVOCATION_pow_start (pow,
133 TEST_EPOCHS,
134 TEST_DIFFICULTY);
135 fprintf (stdout, "Difficulty (%d base difficulty + %d epochs): %d\n\n",
136 TEST_DIFFICULTY,
137 TEST_EPOCHS,
138 TEST_DIFFICULTY + TEST_EPOCHS);
139 uint64_t pow_passes = 0;
140 while (GNUNET_YES != GNUNET_REVOCATION_pow_round (ph))
141 {
142 pow_passes++;
143 }
144 struct GNUNET_REVOCATION_SignaturePurposePS *purp;
145 purp = REV_create_signature_message (pow);
146 fprintf (stdout, "Signed message:\n");
147 print_bytes (purp,
148 ntohl (purp->purpose.size),
149 8);
150 printf ("\n");
151 GNUNET_free (purp);
152
153 exp = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS,
154 TEST_EPOCHS);
155 GNUNET_assert (GNUNET_OK == GNUNET_REVOCATION_check_pow (pow,
156 TEST_DIFFICULTY,
157 exp));
158 fprintf (stdout, "Proof:\n");
159 print_bytes (pow,
160 GNUNET_REVOCATION_proof_get_size (pow),
161 8);
162 GNUNET_free (ph);
163
164}
165
166
167/**
168 * Main function that will be run.
169 *
170 * @param cls closure
171 * @param args remaining command-line arguments
172 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
173 * @param cfg configuration
174 */
175static void
176run (void *cls,
177 char *const *args,
178 const char *cfgfile,
179 const struct GNUNET_CONFIGURATION_Handle *cfg)
180{
181 struct GNUNET_CRYPTO_PrivateKey id_priv;
182
183 id_priv.type = htonl (GNUNET_PUBLIC_KEY_TYPE_ECDSA);
184 parsehex (d_pkey,(char*) &id_priv.ecdsa_key, sizeof (id_priv.ecdsa_key), 1);
185
186 fprintf (stdout, "Zone private key (d, big-endian):\n");
187 print_bytes_ (&id_priv.ecdsa_key, sizeof(id_priv.ecdsa_key), 8, 1);
188 run_with_key (&id_priv);
189 printf ("\n");
190 id_priv.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
191 parsehex (d_edkey,(char*) &id_priv.eddsa_key, sizeof (id_priv.eddsa_key), 0);
192
193 fprintf (stdout, "Zone private key (d):\n");
194 print_bytes (&id_priv.eddsa_key, sizeof(id_priv.eddsa_key), 8);
195 run_with_key (&id_priv);
196}
197
198
199/**
200 * The main function of the test vector generation tool.
201 *
202 * @param argc number of arguments from the command line
203 * @param argv command line arguments
204 * @return 0 ok, 1 on error
205 */
206int
207main (int argc,
208 char *const *argv)
209{
210 const struct GNUNET_GETOPT_CommandLineOption options[] = {
211 GNUNET_GETOPT_OPTION_END
212 };
213
214 GNUNET_assert (GNUNET_OK ==
215 GNUNET_log_setup ("gnunet-revocation-tvg",
216 "INFO",
217 NULL));
218 if (GNUNET_OK !=
219 GNUNET_PROGRAM_run (argc, argv,
220 "gnunet-revocation-tvg",
221 "Generate test vectors for revocation",
222 options,
223 &run, NULL))
224 return 1;
225 return 0;
226}
227
228
229/* end of gnunet-revocation-tvg.c */