GNUnet  0.11.x
Data Structures | Functions
gnunet-crypto-tvg.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_signatures.h"
#include "gnunet_testing_lib.h"
#include <gcrypt.h>
Include dependency graph for gnunet-crypto-tvg.c:

Go to the source code of this file.

Data Structures

struct  TestSignatureDataPS
 Sample signature struct. More...


static GNUNET_NETWORK_STRUCT_END void display_data (char *label, void *data, size_t size)
 Print data base32-crockford with a preceding label. More...
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...

Function Documentation

◆ display_data()

static GNUNET_NETWORK_STRUCT_END void display_data ( char *  label,
void *  data,
size_t  size 

Print data base32-crockford with a preceding label.

labellabel to print
datadata to print
sizesize of data

Definition at line 56 of file gnunet-crypto-tvg.c.

References enc, GNUNET_free, and GNUNET_STRINGS_data_to_string_alloc().

Referenced by run().

57 {
59  printf ("%s %s\n", label, enc);
60  GNUNET_free (enc);
61 }
static unsigned int size
Size of the "table".
Definition: peer.c:67
static OpusEncoder * enc
OPUS encoder.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:937
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
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 73 of file gnunet-crypto-tvg.c.

References ctx, display_data(), GNUNET_assert, GNUNET_CRYPTO_ecc_ecdh(), GNUNET_CRYPTO_ecdh_eddsa(), GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_eddsa_key_create(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_sign, GNUNET_CRYPTO_eddsa_verify, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_kdf(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block(), GNUNET_CRYPTO_rsa_blind(), GNUNET_CRYPTO_rsa_private_key_create(), GNUNET_CRYPTO_rsa_private_key_free(), GNUNET_CRYPTO_rsa_private_key_get_public(), GNUNET_CRYPTO_rsa_public_key_encode(), GNUNET_CRYPTO_rsa_public_key_free(), GNUNET_CRYPTO_rsa_sign_blinded(), GNUNET_CRYPTO_rsa_signature_encode(), GNUNET_CRYPTO_rsa_signature_free(), GNUNET_CRYPTO_rsa_unblind(), GNUNET_CRYPTO_rsa_verify(), GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_TEST, GNUNET_YES, pkey, GNUNET_CRYPTO_EccSignaturePurpose::purpose, TestSignatureDataPS::purpose, salt, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by main().

77 {
78  {
79  struct GNUNET_HashCode hc;
80  char *str = "Hello, GNUnet";
82  GNUNET_CRYPTO_hash (str, strlen (str), &hc);
84  printf ("hash code:\n");
85  display_data (" input", str, strlen (str));
86  display_data (" output", &hc, sizeof (struct GNUNET_HashCode));
87  }
88  {
89  struct GNUNET_CRYPTO_EcdhePrivateKey priv1;
90  struct GNUNET_CRYPTO_EcdhePublicKey pub1;
91  struct GNUNET_CRYPTO_EcdhePrivateKey priv2;
92  struct GNUNET_HashCode skm;
97  &pub1);
99  GNUNET_CRYPTO_ecc_ecdh (&priv2,
100  &pub1,
101  &skm));
103  printf ("ecdhe key:\n");
104  display_data (" priv1",
105  &priv1,
106  sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
107  display_data (" pub1",
108  &pub1,
109  sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
110  display_data (" priv2",
111  &priv2,
112  sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
113  display_data (" skm",
114  &skm,
115  sizeof (struct GNUNET_HashCode));
116  }
118  {
119  struct GNUNET_CRYPTO_EddsaPrivateKey priv;
124  &pub);
126  printf ("eddsa key:\n");
127  display_data (" priv",
128  &priv,
129  sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
130  display_data (" pub",
131  &pub,
132  sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
133  }
134  {
135  struct GNUNET_CRYPTO_EddsaPrivateKey priv;
137  struct GNUNET_CRYPTO_EddsaSignature sig;
138  struct TestSignatureDataPS data = { 0 };
142  &pub);
143  data.purpose.size = htonl (sizeof (data));
146  &data,
147  &sig);
150  &data,
151  &sig,
152  &pub));
154  printf ("eddsa sig:\n");
155  display_data (" priv",
156  &priv,
157  sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
158  display_data (" pub",
159  &pub,
160  sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
161  display_data (" data",
162  &data,
163  sizeof (struct TestSignatureDataPS));
164  display_data (" sig",
165  &sig,
166  sizeof (struct GNUNET_CRYPTO_EddsaSignature));
167  }
169  {
170  size_t out_len = 64;
171  char out[out_len];
172  char *ikm = "I'm the secret input key material";
173  char *salt = "I'm very salty";
174  char *ctx = "I'm a context chunk, also known as 'info' in the RFC";
177  GNUNET_CRYPTO_kdf (&out,
178  out_len,
179  salt,
180  strlen (salt),
181  ikm,
182  strlen (ikm),
183  ctx,
184  strlen (ctx),
185  NULL));
187  printf ("kdf:\n");
188  display_data (" salt", salt, strlen (salt));
189  display_data (" ikm", ikm, strlen (ikm));
190  display_data (" ctx", ctx, strlen (ctx));
191  printf (" out_len %u\n", (unsigned int) out_len);
192  display_data (" out", out, out_len);
193  }
194  {
195  struct GNUNET_CRYPTO_EcdhePrivateKey priv_ecdhe;
196  struct GNUNET_CRYPTO_EcdhePublicKey pub_ecdhe;
197  struct GNUNET_CRYPTO_EddsaPrivateKey priv_eddsa;
198  struct GNUNET_CRYPTO_EddsaPublicKey pub_eddsa;
199  struct GNUNET_HashCode key_material;
201  GNUNET_CRYPTO_ecdhe_key_create (&priv_ecdhe);
202  GNUNET_CRYPTO_ecdhe_key_get_public (&priv_ecdhe, &pub_ecdhe);
203  GNUNET_CRYPTO_eddsa_key_create (&priv_eddsa);
204  GNUNET_CRYPTO_eddsa_key_get_public (&priv_eddsa, &pub_eddsa);
205  GNUNET_CRYPTO_ecdh_eddsa (&priv_ecdhe, &pub_eddsa, &key_material);
207  printf ("eddsa_ecdh:\n");
208  display_data (" priv_ecdhe",
209  &priv_ecdhe,
210  sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey));
211  display_data (" pub_ecdhe",
212  &pub_ecdhe,
213  sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
214  display_data (" priv_eddsa",
215  &priv_eddsa,
216  sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey));
217  display_data (" pub_eddsa",
218  &pub_eddsa,
219  sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
220  display_data (" key_material",
221  &key_material,
222  sizeof (struct GNUNET_HashCode));
223  }
225  {
226  struct GNUNET_CRYPTO_RsaPrivateKey *skey;
228  struct GNUNET_HashCode message_hash;
230  struct GNUNET_CRYPTO_RsaSignature *blinded_sig;
231  struct GNUNET_CRYPTO_RsaSignature *sig;
232  void *blinded_data;
233  size_t blinded_len;
234  void *public_enc_data;
235  size_t public_enc_len;
236  void *blinded_sig_enc_data;
237  size_t blinded_sig_enc_length;
238  void *sig_enc_data;
239  size_t sig_enc_length;
243  &message_hash,
244  sizeof (struct GNUNET_HashCode));
246  &bks,
247  sizeof (struct
250  GNUNET_CRYPTO_rsa_blind (&message_hash,
251  &bks,
252  pkey,
253  &blinded_data,
254  &blinded_len));
255  blinded_sig = GNUNET_CRYPTO_rsa_sign_blinded (skey, blinded_data,
256  blinded_len);
257  sig = GNUNET_CRYPTO_rsa_unblind (blinded_sig, &bks, pkey);
258  GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_rsa_verify (&message_hash, sig,
259  pkey));
260  public_enc_len = GNUNET_CRYPTO_rsa_public_key_encode (pkey,
261  &public_enc_data);
262  blinded_sig_enc_length = GNUNET_CRYPTO_rsa_signature_encode (blinded_sig,
263  &
264  blinded_sig_enc_data);
265  sig_enc_length = GNUNET_CRYPTO_rsa_signature_encode (sig, &sig_enc_data);
266  printf ("blind signing:\n");
267  display_data (" message_hash", &message_hash, sizeof (struct
268  GNUNET_HashCode));
269  display_data (" rsa_public_key", public_enc_data, public_enc_len);
270  display_data (" blinding_key_secret", &bks, sizeof (struct
272  display_data (" blinded_message", blinded_data, blinded_len);
273  display_data (" blinded_sig", blinded_sig_enc_data,
274  blinded_sig_enc_length);
275  display_data (" sig", sig_enc_data, sig_enc_length);
279  GNUNET_CRYPTO_rsa_signature_free (blinded_sig);
280  }
281 }
int GNUNET_CRYPTO_rsa_blind(const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey, void **buf, size_t *buf_size)
Blinds the given message with the given blinding key.
Definition: crypto_rsa.c:841
static char * pkey
Public key of the zone to look in, in ASCII.
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
an RSA signature
Definition: crypto_rsa.c:63
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:1061
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
static GNUNET_NETWORK_STRUCT_END void display_data(char *label, void *data, size_t size)
Print data base32-crockford with a preceding label.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CRYPTO_ecc_ecdh(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a public and a private ECC key.
Definition: crypto_ecc.c:850
size_t GNUNET_CRYPTO_rsa_signature_encode(const struct GNUNET_CRYPTO_RsaSignature *sig, void **buffer)
Encode the given signature in a format suitable for storing it into a file.
Definition: crypto_rsa.c:1076
struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_private_key_create(unsigned int len)
Create a new private key.
Definition: crypto_rsa.c:149
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
int GNUNET_CRYPTO_rsa_verify(const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaPublicKey *public_key)
Verify whether the given hash corresponds to the given signature and the signature is valid with resp...
Definition: crypto_rsa.c:1285
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:508
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
Test signature, not valid for anything other than writing a test.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
A 512-bit hashcode.
int GNUNET_CRYPTO_ecdh_eddsa(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a EdDSA public key and a private ECDH key.
Definition: crypto_ecc.c:1084
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_unblind(const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey)
Unblind a blind-signed signature.
Definition: crypto_rsa.c:1195
Private ECC key encoded for transmission.
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:215
void GNUNET_CRYPTO_eddsa_key_create(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:544
an ECC signature using EdDSA.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:193
static struct GNUNET_CRYPTO_PowSalt salt
Salt for PoW calcualations.
Private ECC key encoded for transmission.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:46
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_sign_blinded(const struct GNUNET_CRYPTO_RsaPrivateKey *key, const void *msg, size_t msg_len)
Sign a blinded value, which must be a full domain hash of a message.
Definition: crypto_rsa.c:1005
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
The private information of an RSA key pair.
Definition: crypto_rsa.c:39
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_private_key_get_public(const struct GNUNET_CRYPTO_RsaPrivateKey *priv)
Extract the public key of the given private key.
Definition: crypto_rsa.c:265
Constant-size pre-secret for blinding key generation.
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:305
size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, void **buffer)
Encode the public key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:346
Sample signature struct.
uint32_t data
The data value.
int GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:90
void GNUNET_CRYPTO_rsa_private_key_free(struct GNUNET_CRYPTO_RsaPrivateKey *key)
Free memory occupied by the private key.
Definition: crypto_rsa.c:183
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
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 292 of file gnunet-crypto-tvg.c.

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

294 {
295  const struct GNUNET_GETOPT_CommandLineOption options[] = {
297  };
300  GNUNET_log_setup ("gnunet-crypto-tvg",
301  "INFO",
302  NULL));
303  if (GNUNET_OK !=
304  GNUNET_PROGRAM_run (argc, argv,
305  "gnunet-crypto-tvg",
306  "Generate test vectors for cryptographic operations",
307  options,
308  &run, NULL))
309  return 1;
310  return 0;
311 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Definition of a command line option.
Definition: 002.c:13
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_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:372
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
Here is the call graph for this function: