GNUnet  0.20.0
gnunet-revocation-tvg.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_signatures.h"
#include "gnunet_revocation_service.h"
#include "gnunet_testing_lib.h"
#include "revocation.h"
#include <inttypes.h>
Include dependency graph for gnunet-revocation-tvg.c:

Go to the source code of this file.


#define TEST_EPOCHS   2


int parsehex (char *src, char *dst, size_t dstlen, int invert)
static void print_bytes_ (void *buf, size_t buf_len, int fold, int in_be)
static void print_bytes (void *buf, size_t buf_len, int fold)
static void run_with_key (struct GNUNET_IDENTITY_PrivateKey *id_priv)
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run. More...
int main (int argc, char *const *argv)
 The main function of the test vector generation tool. More...


static char * d_pkey
static char * d_edkey

Macro Definition Documentation


#define TEST_EPOCHS   2

Definition at line 34 of file gnunet-revocation-tvg.c.



Definition at line 35 of file gnunet-revocation-tvg.c.

Function Documentation

◆ parsehex()

int parsehex ( char *  src,
char *  dst,
size_t  dstlen,
int  invert 

Definition at line 44 of file gnunet-revocation-tvg.c.

45 {
46  char *line = src;
47  char *data = line;
48  int off;
49  int read_byte;
50  int data_len = 0;
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 }
static char * line
Desired phone line (string to be converted to a hash).
uint32_t data
The data value.

References data, and line.

Referenced by run().

Here is the caller graph for this function:

◆ print_bytes_()

static void print_bytes_ ( void *  buf,
size_t  buf_len,
int  fold,
int  in_be 

Definition at line 65 of file gnunet-revocation-tvg.c.

69 {
70  int i;
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 }
static char buf[2048]

References buf.

Referenced by print_bytes(), and run().

Here is the caller graph for this function:

◆ print_bytes()

static void print_bytes ( void *  buf,
size_t  buf_len,
int  fold 

Definition at line 95 of file gnunet-revocation-tvg.c.

98 {
99  print_bytes_ (buf, buf_len, fold, 0);
100 }
static void print_bytes_(void *buf, size_t buf_len, int fold, int in_be)

References buf, and print_bytes_().

Referenced by run(), and run_with_key().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_with_key()

static void run_with_key ( struct GNUNET_IDENTITY_PrivateKey id_priv)

Definition at line 104 of file gnunet-revocation-tvg.c.

105 {
106  struct GNUNET_IDENTITY_PublicKey id_pub;
107  struct GNUNET_REVOCATION_PowP *pow;
109  struct GNUNET_TIME_Relative exp;
110  char ztld[128];
111  ssize_t key_len;
114  &id_pub);
117  &id_pub),
118  ztld,
119  sizeof (ztld));
120  fprintf (stdout, "\n");
121  fprintf (stdout, "Zone identifier (ztype|zkey):\n");
122  key_len = GNUNET_IDENTITY_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");
131  pow);
135  fprintf (stdout, "Difficulty (%d base difficulty + %d epochs): %d\n\n",
139  uint64_t pow_passes = 0;
141  {
142  pow_passes++;
143  }
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);
157  exp));
158  fprintf (stdout, "Proof:\n");
159  print_bytes (pow,
161  8);
162  GNUNET_free (ph);
164 }
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
static void print_bytes(void *buf, size_t buf_len, int fold)
static unsigned int pow_passes
Pow passes.
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
#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.
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.
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
One year (365 days).
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 (!...
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.

References GNUNET_assert, GNUNET_free, GNUNET_IDENTITY_key_get_public(), GNUNET_IDENTITY_public_key_get_length(), GNUNET_malloc, GNUNET_OK, GNUNET_REVOCATION_check_pow(), GNUNET_REVOCATION_MAX_PROOF_SIZE, GNUNET_REVOCATION_pow_init(), GNUNET_REVOCATION_pow_round(), GNUNET_REVOCATION_pow_start(), GNUNET_REVOCATION_proof_get_size(), GNUNET_STRINGS_data_to_string(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_YEARS, GNUNET_YES, ph, GNUNET_REVOCATION_PowP::pow, pow_passes, print_bytes(), GNUNET_REVOCATION_SignaturePurposePS::purpose, REV_create_signature_message(), GNUNET_CRYPTO_EccSignaturePurpose::size, TEST_DIFFICULTY, and TEST_EPOCHS.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 

Main function that will be run.

argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)

Definition at line 176 of file gnunet-revocation-tvg.c.

180 {
181  struct GNUNET_IDENTITY_PrivateKey id_priv;
183  id_priv.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA);
184  parsehex (d_pkey,(char*) &id_priv.ecdsa_key, sizeof (id_priv.ecdsa_key), 1);
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_IDENTITY_TYPE_EDDSA);
191  parsehex (d_edkey,(char*) &id_priv.eddsa_key, sizeof (id_priv.eddsa_key), 0);
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 }
int parsehex(char *src, char *dst, size_t dstlen, int invert)
static void run_with_key(struct GNUNET_IDENTITY_PrivateKey *id_priv)
static char * d_edkey
static char * d_pkey
The identity type.
EDDSA identity.
A private key for an identity as per LSD0001.
uint32_t type
Type of public key.

References d_edkey, d_pkey, GNUNET_IDENTITY_PrivateKey::ecdsa_key, GNUNET_IDENTITY_PrivateKey::eddsa_key, GNUNET_IDENTITY_TYPE_ECDSA, GNUNET_IDENTITY_TYPE_EDDSA, parsehex(), print_bytes(), print_bytes_(), run_with_key(), and GNUNET_IDENTITY_PrivateKey::type.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 

The main function of the test vector generation tool.

argcnumber of arguments from the command line
argvcommand line arguments
0 ok, 1 on error

Definition at line 207 of file gnunet-revocation-tvg.c.

209 {
210  const struct GNUNET_GETOPT_CommandLineOption options[] = {
212  };
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 }
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
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
Definition of a command line option.

References GNUNET_assert, GNUNET_GETOPT_OPTION_END, GNUNET_log_setup(), GNUNET_OK, GNUNET_PROGRAM_run(), options, and run().

Here is the call graph for this function:

Variable Documentation

◆ d_pkey

char* d_pkey
Initial value:

Definition at line 37 of file gnunet-revocation-tvg.c.

Referenced by run().

◆ d_edkey

char* d_edkey
Initial value:

Definition at line 40 of file gnunet-revocation-tvg.c.

Referenced by run().