GNUnet 0.21.1
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 "../../lib/gnsrecord/gnsrecord_crypto.h"
#include <inttypes.h>
Include dependency graph for gnunet-revocation-tvg.c:

Go to the source code of this file.

Macros

#define TEST_EPOCHS   2
 
#define TEST_DIFFICULTY   5
 

Functions

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_CRYPTO_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...
 

Variables

static char * d_pkey
 
static char * d_edkey
 

Macro Definition Documentation

◆ TEST_EPOCHS

#define TEST_EPOCHS   2

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

◆ TEST_DIFFICULTY

#define TEST_DIFFICULTY   5

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

Function Documentation

◆ parsehex()

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

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

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}
static char * line
Desired phone line (string to be converted to a hash).
static char * data
The data to insert into the dht.

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 
)
static

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

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}

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 
)
static

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

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

References 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_CRYPTO_PrivateKey id_priv)
static

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

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}
struct GNUNET_GNSRECORD_SignaturePurposePS * GNR_create_signature_message(const struct GNUNET_GNSRECORD_PowP *pow)
Create the revocation metadata to sign for a revocation message.
#define TEST_DIFFICULTY
static void print_bytes(void *buf, size_t buf_len, int fold)
#define TEST_EPOCHS
static unsigned int pow_passes
Pow passes.
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:619
@ GNUNET_OK
@ GNUNET_YES
#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.
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:709
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).
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.
Definition: gnsrecord_pow.c:56
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.

References GNR_create_signature_message(), GNUNET_assert, GNUNET_CRYPTO_key_get_public(), GNUNET_CRYPTO_public_key_get_length(), GNUNET_free, GNUNET_GNSRECORD_check_pow(), GNUNET_GNSRECORD_pow_init(), GNUNET_GNSRECORD_pow_round(), GNUNET_GNSRECORD_pow_start(), GNUNET_GNSRECORD_proof_get_size(), GNUNET_malloc, GNUNET_MAX_POW_SIZE, GNUNET_OK, GNUNET_STRINGS_data_to_string(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_YEARS, GNUNET_YES, GNUNET_GNSRECORD_PowP::pow, pow_passes, print_bytes(), GNUNET_GNSRECORD_SignaturePurposePS::purpose, 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 
)
static

Main function that will be run.

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

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

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}
int parsehex(char *src, char *dst, size_t dstlen, int invert)
static char * d_edkey
static void run_with_key(struct GNUNET_CRYPTO_PrivateKey *id_priv)
static char * d_pkey
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
A private key for an identity as per LSD0001.
uint32_t type
Type of public key.

References d_edkey, d_pkey, GNUNET_CRYPTO_PrivateKey::ecdsa_key, GNUNET_CRYPTO_PrivateKey::eddsa_key, GNUNET_PUBLIC_KEY_TYPE_ECDSA, GNUNET_PUBLIC_KEY_TYPE_EDDSA, parsehex(), print_bytes(), print_bytes_(), run_with_key(), and GNUNET_CRYPTO_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.

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

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

210{
213 };
214
216 GNUNET_log_setup ("gnunet-revocation-tvg",
217 "INFO",
218 NULL));
219 if (GNUNET_OK !=
220 GNUNET_PROGRAM_run (argc, argv,
221 "gnunet-revocation-tvg",
222 "Generate test vectors for revocation",
223 options,
224 &run, NULL))
225 return 1;
226 return 0;
227}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
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.
enum GNUNET_GenericReturnValue 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
static
Initial value:
=
"6fea32c05af58bfa979553d188605fd57d8bf9cc263b78d5f7478c07b998ed70"

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

Referenced by run().

◆ d_edkey

char* d_edkey
static
Initial value:
=
"5af7020ee19160328832352bbc6a68a8d71a7cbe1b929969a7c66d415a0d8f65"

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

Referenced by run().