GNUnet 0.22.2
gnunet-revocation-tvg.c
Go to the documentation of this file.
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
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_signatures.h"
30#include "gnunet_testing_lib.h"
31// FIXME try to avoid this include somehow
32#include "../../lib/gnsrecord/gnsrecord_crypto.h"
33#include <inttypes.h>
34
35#define TEST_EPOCHS 2
36#define TEST_DIFFICULTY 5
37
38static char*d_pkey =
39 "6fea32c05af58bfa979553d188605fd57d8bf9cc263b78d5f7478c07b998ed70";
40
41static char *d_edkey =
42 "5af7020ee19160328832352bbc6a68a8d71a7cbe1b929969a7c66d415a0d8f65";
43
44int
45parsehex (char *src, char *dst, size_t dstlen, int invert)
46{
47 char *line = src;
48 char *data = line;
49 int off;
50 int read_byte;
51 int data_len = 0;
52
53 while (sscanf (data, " %02x%n", &read_byte, &off) == 1)
54 {
55 if (invert)
56 dst[dstlen - 1 - data_len++] = read_byte;
57 else
58 dst[data_len++] = read_byte;
59 data += off;
60 }
61 return data_len;
62}
63
64
65static void
66print_bytes_ (void *buf,
67 size_t buf_len,
68 int fold,
69 int in_be)
70{
71 int i;
72
73 for (i = 0; i < buf_len; i++)
74 {
75 if (0 != i)
76 {
77 if ((0 != fold) && (i % fold == 0))
78 printf ("\n ");
79 else
80 printf (" ");
81 }
82 else
83 {
84 printf (" ");
85 }
86 if (in_be)
87 printf ("%02x", ((unsigned char*) buf)[buf_len - 1 - i]);
88 else
89 printf ("%02x", ((unsigned char*) buf)[i]);
90 }
91 printf ("\n");
92}
93
94
95static void
96print_bytes (void *buf,
97 size_t buf_len,
98 int fold)
99{
100 print_bytes_ (buf, buf_len, fold, 0);
101}
102
103
104static void
106{
107 struct GNUNET_CRYPTO_PublicKey id_pub;
110 struct GNUNET_TIME_Relative exp;
111 char ztld[128];
112 ssize_t key_len;
113
115 &id_pub);
118 &id_pub),
119 ztld,
120 sizeof (ztld));
121 fprintf (stdout, "\n");
122 fprintf (stdout, "Zone identifier (ztype|zkey):\n");
123 key_len = GNUNET_CRYPTO_public_key_get_length (&id_pub);
124 GNUNET_assert (0 < key_len);
125 print_bytes (&id_pub, key_len, 8);
126 fprintf (stdout, "\n");
127 fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n");
128 fprintf (stdout, "%s\n", ztld);
129 fprintf (stdout, "\n");
132 pow);
136 fprintf (stdout, "Difficulty (%d base difficulty + %d epochs): %d\n\n",
140 uint64_t pow_passes = 0;
142 {
143 pow_passes++;
144 }
146 purp = GNR_create_signature_message (pow);
147 fprintf (stdout, "Signed message:\n");
148 print_bytes (purp,
149 ntohl (purp->purpose.size),
150 8);
151 printf ("\n");
152 GNUNET_free (purp);
153
158 exp));
159 fprintf (stdout, "Proof:\n");
160 print_bytes (pow,
162 8);
163 GNUNET_free (ph);
164
165}
166
167
176static void
177run (void *cls,
178 char *const *args,
179 const char *cfgfile,
180 const struct GNUNET_CONFIGURATION_Handle *cfg)
181{
182 struct GNUNET_CRYPTO_PrivateKey id_priv;
183
184 id_priv.type = htonl (GNUNET_PUBLIC_KEY_TYPE_ECDSA);
185 parsehex (d_pkey,(char*) &id_priv.ecdsa_key, sizeof (id_priv.ecdsa_key), 1);
186
187 fprintf (stdout, "Zone private key (d, big-endian):\n");
188 print_bytes_ (&id_priv.ecdsa_key, sizeof(id_priv.ecdsa_key), 8, 1);
189 run_with_key (&id_priv);
190 printf ("\n");
191 id_priv.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA);
192 parsehex (d_edkey,(char*) &id_priv.eddsa_key, sizeof (id_priv.eddsa_key), 0);
193
194 fprintf (stdout, "Zone private key (d):\n");
195 print_bytes (&id_priv.eddsa_key, sizeof(id_priv.eddsa_key), 8);
196 run_with_key (&id_priv);
197}
198
199
207int
208main (int argc,
209 char *const *argv)
210{
213 };
214
216 GNUNET_log_setup ("gnunet-revocation-tvg",
217 "INFO",
218 NULL));
219 if (GNUNET_OK !=
221 argc, argv,
222 "gnunet-revocation-tvg",
223 "Generate test vectors for revocation",
224 options,
225 &run, NULL))
226 return 1;
227 return 0;
228}
229
230
231/* end of gnunet-revocation-tvg.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_GNSRECORD_SignaturePurposePS * GNR_create_signature_message(const struct GNUNET_GNSRECORD_PowP *pow)
Create the revocation metadata to sign for a revocation message.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static char * line
Desired phone line (string to be converted to a hash).
static char * data
The data to insert into the dht.
static void print_bytes_(void *buf, size_t buf_len, int fold, int in_be)
#define TEST_DIFFICULTY
int parsehex(char *src, char *dst, size_t dstlen, int invert)
static void print_bytes(void *buf, size_t buf_len, int fold)
static char * d_edkey
static void run_with_key(struct GNUNET_CRYPTO_PrivateKey *id_priv)
static char * d_pkey
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
#define TEST_EPOCHS
int main(int argc, char *const *argv)
The main function of the test vector generation tool.
static unsigned int pow_passes
Pow passes.
API to perform and access key revocations.
size_t GNUNET_GNSRECORD_proof_get_size(const struct GNUNET_GNSRECORD_PowP *pow)
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_pow_round(struct GNUNET_GNSRECORD_PowCalculationHandle *pc)
Calculate a single round in the key revocation PoW.
void GNUNET_GNSRECORD_pow_init(const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_GNSRECORD_PowP *pow)
Initializes a fresh PoW computation.
struct GNUNET_GNSRECORD_PowCalculationHandle * GNUNET_GNSRECORD_pow_start(struct GNUNET_GNSRECORD_PowP *pow, int epochs, unsigned int difficulty)
Starts a proof-of-work calculation given the pow object as well as target epochs and difficulty.
#define GNUNET_MAX_POW_SIZE
Maximum length of a revocation.
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_check_pow(const struct GNUNET_GNSRECORD_PowP *pow, unsigned int matching_bits, struct GNUNET_TIME_Relative epoch_duration)
Check if the given proof-of-work is valid.
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:85
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: crypto_pkey.c:430
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:407
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
Definition: strings.c:732
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:486
#define GNUNET_TIME_UNIT_YEARS
One year (365 days).
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
A private key for an identity as per LSD0001.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key
AN EdDSA identtiy key.
struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key
An ECDSA identity key.
An identity key as per LSD0001.
Definition of a command line option.
The handle to a PoW calculation.
Definition: gnsrecord_pow.c:55
Struct for a proof of work as part of the revocation.
uint64_t pow[32]
The PoWs.
The signature object we use for the PoW.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
The signature purpose.
Time for relative time used by GNUnet, in microseconds.