GNUnet  0.11.x
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_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 static void
39  size_t buf_len,
40  int fold)
41 {
42  int i;
43 
44  for (i = 0; i < buf_len; i++)
45  {
46  if ((0 != i) && (0 != fold) && (i%fold == 0))
47  printf("\n");
48  printf("%02x", ((unsigned char*)buf)[i]);
49  }
50  printf("\n");
51 }
52 
61 static void
62 run (void *cls,
63  char *const *args,
64  const char *cfgfile,
65  const struct GNUNET_CONFIGURATION_Handle *cfg)
66 {
67  struct GNUNET_CRYPTO_EcdsaPrivateKey id_priv;
68  struct GNUNET_CRYPTO_EcdsaPublicKey id_pub;
69  struct GNUNET_REVOCATION_PowP pow;
71  struct GNUNET_TIME_Relative exp;
72 
75  &id_pub);
76  fprintf(stdout, "Zone private key (d, little-endian scalar):\n");
77  print_bytes (&id_priv, sizeof(id_priv), 0);
78  fprintf(stdout, "\n");
79  fprintf(stdout, "Zone public key (zk):\n");
80  print_bytes (&id_pub, sizeof(id_pub), 0);
81  fprintf(stdout, "\n");
82  memset (&pow, 0, sizeof (pow));
84  &pow);
85  ph = GNUNET_REVOCATION_pow_start (&pow,
88  fprintf (stdout, "Difficulty (%d base difficulty + %d epochs): %d\n\n",
92  uint64_t pow_passes = 0;
94  {
95  pow_passes++;
96  }
98  TEST_EPOCHS);
101  exp));
102  fprintf(stdout, "Proof:\n");
103  print_bytes (&pow,
104  sizeof (pow),
105  8);
106 }
107 
108 
116 int
117 main (int argc,
118  char *const *argv)
119 {
120  const struct GNUNET_GETOPT_CommandLineOption options[] = {
122  };
123 
125  GNUNET_log_setup ("gnunet-revocation-tvg",
126  "INFO",
127  NULL));
128  if (GNUNET_OK !=
129  GNUNET_PROGRAM_run (argc, argv,
130  "gnunet-revocation-tvg",
131  "Generate test vectors for revocation",
132  options,
133  &run, NULL))
134  return 1;
135  return 0;
136 }
137 
138 
139 /* end of gnunet-revocation-tvg.c */
void GNUNET_REVOCATION_pow_init(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, struct GNUNET_REVOCATION_PowP *pow)
Initializes a fresh PoW computation.
static void print_bytes(void *buf, size_t buf_len, int fold)
#define TEST_EPOCHS
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
enum GNUNET_GenericReturnValue GNUNET_REVOCATION_pow_round(struct GNUNET_REVOCATION_PowCalculationHandle *pc)
Calculate a single round in the key revocation PoW.
Struct for a proof of work as part of the revocation.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
Definition of a command line option.
Private ECC key encoded for transmission.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
#define TEST_DIFFICULTY
static char buf[2048]
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:442
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:176
static unsigned int pow_passes
Pow passes.
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...
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
configuration data
Definition: configuration.c:84
void GNUNET_CRYPTO_ecdsa_key_create(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:524
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_TIME_UNIT_YEARS
One year (365 days).
int 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, parse options).
Definition: program.c:367
The handle to a PoW calculation.
int main(int argc, char *const *argv)
The main function of the test vector generation tool.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
Time for relative time used by GNUnet, in microseconds.
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.