GNUnet  0.19.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 #include "revocation.h"
32 #include <inttypes.h>
33 
34 #define TEST_EPOCHS 2
35 #define TEST_DIFFICULTY 5
36 
37 static char* d_pkey =
38 "6fea32c05af58bfa979553d188605fd57d8bf9cc263b78d5f7478c07b998ed70";
39 
40 int parsehex(char *src, char *dst, size_t dstlen, int invert)
41 {
42  char *line = src;
43  char *data = line;
44  int off;
45  int read_byte;
46  int data_len = 0;
47 
48  while (sscanf(data, " %02x%n", &read_byte, &off) == 1) {
49  if (invert)
50  dst[dstlen - 1 - data_len++] = read_byte;
51  else
52  dst[data_len++] = read_byte;
53  data += off;
54  }
55  return data_len;
56 }
57 
58 
59 static void
61  size_t buf_len,
62  int fold,
63  int in_be)
64 {
65  int i;
66 
67  for (i = 0; i < buf_len; i++)
68  {
69  if ((0 != i) && (0 != fold) && (i % fold == 0))
70  printf ("\n");
71  if (in_be)
72  printf ("%02x", ((unsigned char*) buf)[buf_len - 1 - i]);
73  else
74  printf ("%02x", ((unsigned char*) buf)[i]);
75  }
76  printf ("\n");
77 }
78 
79 static void
81  size_t buf_len,
82  int fold)
83 {
84  print_bytes_ (buf, buf_len, fold, 0);
85 }
86 
87 
88 
97 static void
98 run (void *cls,
99  char *const *args,
100  const char *cfgfile,
101  const struct GNUNET_CONFIGURATION_Handle *cfg)
102 {
103  struct GNUNET_IDENTITY_PrivateKey id_priv;
104  struct GNUNET_IDENTITY_PublicKey id_pub;
105  struct GNUNET_REVOCATION_PowP *pow;
107  struct GNUNET_TIME_Relative exp;
108  char ztld[128];
109  ssize_t key_len;
110 
111  id_priv.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA);
113  parsehex(d_pkey,(char*)&id_priv.ecdsa_key, sizeof (id_priv.ecdsa_key), 1);
115  &id_pub);
118  ztld,
119  sizeof (ztld));
120  fprintf (stdout, "Zone private key (d, big-endian scalar):\n");
121  print_bytes_ (&id_priv.ecdsa_key, sizeof(id_priv.ecdsa_key), 8, 1);
122  fprintf (stdout, "\n");
123  fprintf (stdout, "Zone identifier (ztype|zkey):\n");
124  key_len = GNUNET_IDENTITY_public_key_get_length (&id_pub);
125  GNUNET_assert (0 < key_len);
126  print_bytes (&id_pub, key_len, 8);
127  fprintf (stdout, "\n");
128  fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n");
129  fprintf (stdout, "%s\n", ztld);
130  fprintf (stdout, "\n");
132  GNUNET_REVOCATION_pow_init (&id_priv,
133  pow);
135  TEST_EPOCHS,
137  fprintf (stdout, "Difficulty (%d base difficulty + %d epochs): %d\n\n",
139  TEST_EPOCHS,
141  uint64_t pow_passes = 0;
143  {
144  pow_passes++;
145  }
147  purp = REV_create_signature_message (pow);
148  fprintf (stdout, "Signed message:\n");
149  print_bytes (purp,
150  ntohl (purp->purpose.size),
151  8);
152  printf ("\n");
153  GNUNET_free (purp);
154 
156  TEST_EPOCHS);
159  exp));
160  fprintf (stdout, "Proof:\n");
161  print_bytes (pow,
163  8);
164  GNUNET_free (ph);
165 }
166 
167 
175 int
176 main (int argc,
177  char *const *argv)
178 {
179  const struct GNUNET_GETOPT_CommandLineOption options[] = {
181  };
182 
184  GNUNET_log_setup ("gnunet-revocation-tvg",
185  "INFO",
186  NULL));
187  if (GNUNET_OK !=
188  GNUNET_PROGRAM_run (argc, argv,
189  "gnunet-revocation-tvg",
190  "Generate test vectors for revocation",
191  options,
192  &run, NULL))
193  return 1;
194  return 0;
195 }
196 
197 
198 /* 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
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
static char * line
Desired phone line (string to be converted to a hash).
uint32_t data
The data value.
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_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.
static char buf[2048]
API to perform and access key revocations.
Convenience API for writing testcases for GNUnet.
void GNUNET_CRYPTO_ecdsa_key_create(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:446
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_key_get_public(const struct GNUNET_IDENTITY_PrivateKey *privkey, struct GNUNET_IDENTITY_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: identity_api.c:179
ssize_t GNUNET_IDENTITY_public_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:830
@ GNUNET_IDENTITY_TYPE_ECDSA
The identity type.
@ GNUNET_OK
@ GNUNET_YES
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(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:400
size_t GNUNET_REVOCATION_proof_get_size(const struct GNUNET_REVOCATION_PowP *pow)
void GNUNET_REVOCATION_pow_init(const struct GNUNET_IDENTITY_PrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)
Initializes a fresh PoW computation.
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_pow_round(struct GNUNET_REVOCATION_PowCalculationHandle *pc)
Calculate a single round in the key revocation PoW.
#define GNUNET_REVOCATION_MAX_PROOF_SIZE
Maximum length of a revocation.
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_check_pow(const struct GNUNET_REVOCATION_PowP *pow, unsigned int matching_bits, struct GNUNET_TIME_Relative epoch_duration)
Check if the given proof-of-work is valid.
struct GNUNET_REVOCATION_PowCalculationHandle * GNUNET_REVOCATION_pow_start(struct GNUNET_REVOCATION_PowP *pow, int epochs, unsigned int difficulty)
Starts a proof-of-work calculation given the pow object as well as target epochs and difficulty.
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:708
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:484
#define GNUNET_TIME_UNIT_YEARS
One year (365 days).
messages for key revocation
GNUNET_NETWORK_STRUCT_END struct GNUNET_REVOCATION_SignaturePurposePS * REV_create_signature_message(const struct GNUNET_REVOCATION_PowP *pow)
Create the revocation metadata to sign for a revocation message.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
Definition of a command line option.
A private key for an identity as per LSD0001.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key
An ECDSA identity key.
An identity key as per LSD0001.
The handle to a PoW calculation.
Struct for a proof of work as part of the revocation.
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.