GNUnet  0.10.x
Macros | Functions | Variables
gnunet-ecc.c File Reference

tool to manipulate EDDSA key files More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_lib.h"
#include <gcrypt.h>
Include dependency graph for gnunet-ecc.c:

Go to the source code of this file.

Macros

#define KEY_STR_LEN   sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) * 8 / 5 + 1
 Number of characters a Base32-encoded public key requires. More...
 

Functions

static void create_keys (const char *fn, const char *prefix)
 Create a flat file with a large number of key pairs for testing. More...
 
static void print_hex (const char *msg, const void *buf, size_t size)
 
static void print_examples_ecdh ()
 
static void print_examples ()
 Print some random example operations to stdout. More...
 
static void print_key (const char *filename)
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 Program to manipulate ECC key files. More...
 

Variables

static int list_keys
 Flag for listing public key. More...
 
static unsigned int list_keys_count
 Flag for listing public key. More...
 
static int print_public_key
 Flag for printing public key. More...
 
static int print_private_key
 Flag for printing private key. More...
 
static int print_public_key_hex
 Flag for printing public key in hex. More...
 
static int print_examples_flag
 Flag for printing the output of random example operations. More...
 
static unsigned int make_keys
 Option set to create a bunch of keys at once. More...
 

Detailed Description

tool to manipulate EDDSA key files

Author
Christian Grothoff

Definition in file gnunet-ecc.c.

Macro Definition Documentation

◆ KEY_STR_LEN

#define KEY_STR_LEN   sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) * 8 / 5 + 1

Number of characters a Base32-encoded public key requires.

Definition at line 34 of file gnunet-ecc.c.

Referenced by create_keys().

Function Documentation

◆ create_keys()

static void create_keys ( const char *  fn,
const char *  prefix 
)
static

Create a flat file with a large number of key pairs for testing.

Parameters
fnFile name to store the keys.
prefixDesired prefix for the public keys, NULL if any key is OK.

Documentation by example: vanity = "A" len = 1 n = 5/8 = 0 (bytes) rest = 5%8 = 5 (bits) mask = ~(2**(8 - 5) - 1) = ~(2**3 - 1) = ~(8 - 1) = ~b111 = b11111000

Definition at line 79 of file gnunet-ecc.c.

References _, removetrailingwhitespace::f, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_eddsa_key_create(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_free, GNUNET_OK, GNUNET_strlcpy(), GNUNET_TESTING_HOSTKEYFILESIZE, KEY_STR_LEN, len, make_keys, and pk.

Referenced by run().

80 {
81  FILE *f;
83  struct GNUNET_CRYPTO_EddsaPublicKey target_pub;
84  static char vanity[KEY_STR_LEN + 1];
85  size_t len;
86  size_t n;
87  size_t rest;
88  unsigned char mask;
89  unsigned target_byte;
90  char *s;
91 
92  if (NULL == (f = fopen(fn, "w+")))
93  {
94  fprintf(stderr, _("Failed to open `%s': %s\n"), fn, strerror(errno));
95  return;
96  }
97  if (NULL != prefix)
98  {
99  len = GNUNET_strlcpy(vanity, prefix, sizeof(vanity));
100  n = len * 5 / 8;
101  rest = len * 5 % 8;
102 
103  memset(&vanity[len], '0', KEY_STR_LEN - len);
104  vanity[KEY_STR_LEN] = '\0';
107  KEY_STR_LEN,
108  &target_pub));
109  if (0 != rest)
110  {
119  mask = ~((int)pow(2, 8 - rest) - 1);
120  target_byte = ((unsigned char *)&target_pub)[n] & mask;
121  }
122  else
123  {
124  /* Just so old (debian) versions of GCC calm down with the warnings. */
125  mask = target_byte = 0;
126  }
128  fprintf(stderr,
129  _("Generating %u keys like %s, please wait"),
130  make_keys,
131  s);
132  GNUNET_free(s);
133  fprintf(stderr, "\nattempt %s [%u, %X]\n", vanity, (unsigned int)n, mask);
134  }
135  else
136  {
137  fprintf(stderr, _("Generating %u keys, please wait"), make_keys);
138  /* Just so old (debian) versions of GCC calm down with the warnings. */
139  n = rest = target_byte = mask = 0;
140  }
141 
142  while (0 < make_keys--)
143  {
144  fprintf(stderr, ".");
145  if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create()))
146  {
147  GNUNET_break(0);
148  break;
149  }
150  if (NULL != prefix)
151  {
152  struct GNUNET_CRYPTO_EddsaPublicKey newkey;
153 
155  if (0 != memcmp(&target_pub, &newkey, n))
156  {
157  make_keys++;
158  continue;
159  }
160  if (0 != rest)
161  {
162  unsigned char new_byte;
163 
164  new_byte = ((unsigned char *)&newkey)[n] & mask;
165  if (target_byte != new_byte)
166  {
167  make_keys++;
168  continue;
169  }
170  }
171  }
173  fwrite(pk, 1, GNUNET_TESTING_HOSTKEYFILESIZE, f))
174  {
175  fprintf(stderr,
176  _("\nFailed to write to `%s': %s\n"),
177  fn,
178  strerror(errno));
179  GNUNET_free(pk);
180  break;
181  }
182  GNUNET_free(pk);
183  }
184  if (UINT_MAX == make_keys)
185  fprintf(stderr, _("\nFinished!\n"));
186  else
187  fprintf(stderr, _("\nError, %u keys not generated\n"), make_keys);
188  fclose(f);
189 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_TESTING_HOSTKEYFILESIZE
Size of each hostkey in the hostkey file (in BYTES).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create(void)
Create a new private key.
Definition: crypto_ecc.c:746
static unsigned int make_keys
Option set to create a bunch of keys at once.
Definition: gnunet-ecc.c:69
static char * fn
Filename of the unique file.
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:367
#define KEY_STR_LEN
Number of characters a Base32-encoded public key requires.
Definition: gnunet-ecc.c:34
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:272
Private ECC key encoded for transmission.
int GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:501
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Definition: strings.c:219
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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:

◆ print_hex()

static void print_hex ( const char *  msg,
const void *  buf,
size_t  size 
)
static

Definition at line 193 of file gnunet-ecc.c.

References size.

Referenced by print_examples_ecdh(), and run().

194 {
195  printf("%s: ", msg);
196  for (size_t i = 0; i < size; i++)
197  {
198  printf("%02hhx", ((const uint8_t *)buf)[i]);
199  }
200  printf("\n");
201 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static char buf[2048]
static unsigned int size
Size of the "table".
Definition: peer.c:66
Here is the caller graph for this function:

◆ print_examples_ecdh()

static void print_examples_ecdh ( )
static

Definition at line 205 of file gnunet-ecc.c.

References buf, GNUNET_assert, GNUNET_CRYPTO_ecc_ecdh(), GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_STRINGS_data_to_string(), and print_hex().

Referenced by print_examples().

206 {
207  struct GNUNET_CRYPTO_EcdhePrivateKey *dh_priv1;
208  struct GNUNET_CRYPTO_EcdhePublicKey *dh_pub1;
209  struct GNUNET_CRYPTO_EcdhePrivateKey *dh_priv2;
210  struct GNUNET_CRYPTO_EcdhePublicKey *dh_pub2;
211  struct GNUNET_HashCode hash;
212  char buf[128];
213 
214  dh_pub1 = GNUNET_new(struct GNUNET_CRYPTO_EcdhePublicKey);
215  dh_priv1 = GNUNET_CRYPTO_ecdhe_key_create();
216  dh_pub2 = GNUNET_new(struct GNUNET_CRYPTO_EcdhePublicKey);
217  dh_priv2 = GNUNET_CRYPTO_ecdhe_key_create();
218  GNUNET_CRYPTO_ecdhe_key_get_public(dh_priv1, dh_pub1);
219  GNUNET_CRYPTO_ecdhe_key_get_public(dh_priv2, dh_pub2);
220 
221  GNUNET_assert(NULL !=
222  GNUNET_STRINGS_data_to_string(dh_priv1, 32, buf, 128));
223  printf("ECDHE key 1:\n");
224  printf("private: %s\n", buf);
225  print_hex("private(hex)", dh_priv1, sizeof *dh_priv1);
226  GNUNET_assert(NULL != GNUNET_STRINGS_data_to_string(dh_pub1, 32, buf, 128));
227  printf("public: %s\n", buf);
228  print_hex("public(hex)", dh_pub1, sizeof *dh_pub1);
229 
230  GNUNET_assert(NULL !=
231  GNUNET_STRINGS_data_to_string(dh_priv2, 32, buf, 128));
232  printf("ECDHE key 2:\n");
233  printf("private: %s\n", buf);
234  print_hex("private(hex)", dh_priv2, sizeof *dh_priv2);
235  GNUNET_assert(NULL != GNUNET_STRINGS_data_to_string(dh_pub2, 32, buf, 128));
236  printf("public: %s\n", buf);
237  print_hex("public(hex)", dh_pub2, sizeof *dh_pub2);
238 
240  GNUNET_CRYPTO_ecc_ecdh(dh_priv1, dh_pub2, &hash));
241  GNUNET_assert(NULL != GNUNET_STRINGS_data_to_string(&hash, 64, buf, 128));
242  printf("ECDH shared secret: %s\n", buf);
243 
244  GNUNET_free(dh_priv1);
245  GNUNET_free(dh_priv2);
246  GNUNET_free(dh_pub1);
247  GNUNET_free(dh_pub2);
248 }
#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:1185
struct GNUNET_CRYPTO_EcdhePrivateKey * GNUNET_CRYPTO_ecdhe_key_create(void)
Create a new private key.
Definition: crypto_ecc.c:610
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void print_hex(const char *msg, const void *buf, size_t size)
Definition: gnunet-ecc.c:193
static char buf[2048]
A 512-bit hashcode.
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:303
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
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:857
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_examples()

static void print_examples ( )
static

Print some random example operations to stdout.

Definition at line 255 of file gnunet-ecc.c.

References print_examples_ecdh().

Referenced by run().

256 {
258  // print_examples_ecdsa ();
259  // print_examples_eddsa ();
260 }
static void print_examples_ecdh()
Definition: gnunet-ecc.c:205
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_key()

static void print_key ( const char *  filename)
static

Definition at line 264 of file gnunet-ecc.c.

References _, GNUNET_DISK_FileHandle::fd, fs, GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_strerror_file, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_TESTING_HOSTKEYFILESIZE, GNUNET_YES, hostkeys_data, and list_keys_count.

Referenced by run().

265 {
266  struct GNUNET_DISK_FileHandle *fd;
267  struct GNUNET_CRYPTO_EddsaPrivateKey private_key;
268  struct GNUNET_CRYPTO_EddsaPublicKey public_key;
269  char *hostkeys_data;
270  char *hostkey_str;
271  uint64_t fs;
272  unsigned int total_hostkeys;
273  unsigned int c;
274  ssize_t sret;
275 
277  {
278  fprintf(stderr, _("Hostkeys file `%s' not found\n"), filename);
279  return;
280  }
281 
282  /* Check hostkey file size, read entire thing into memory */
283  if (GNUNET_OK !=
285  fs = 0;
286  if (0 == fs)
287  {
288  fprintf(stderr, _("Hostkeys file `%s' is empty\n"), filename);
289  return; /* File is empty */
290  }
291  if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
292  {
293  fprintf(stderr, _("Incorrect hostkey file format: %s\n"), filename);
294  return;
295  }
299  if (NULL == fd)
300  {
302  return;
303  }
304  hostkeys_data = GNUNET_malloc(fs);
305  sret = GNUNET_DISK_file_read(fd, hostkeys_data, fs);
306  if ((sret < 0) || (fs != (size_t)sret))
307  {
308  fprintf(stderr, _("Could not read hostkey file: %s\n"), filename);
309  GNUNET_free(hostkeys_data);
311  return;
312  }
314 
315  if (NULL == hostkeys_data)
316  return;
317  total_hostkeys = fs / GNUNET_TESTING_HOSTKEYFILESIZE;
318  for (c = 0; (c < total_hostkeys) && (c < list_keys_count); c++)
319  {
320  GNUNET_memcpy(&private_key,
321  hostkeys_data + (c * GNUNET_TESTING_HOSTKEYFILESIZE),
322  GNUNET_TESTING_HOSTKEYFILESIZE);
323  GNUNET_CRYPTO_eddsa_key_get_public(&private_key, &public_key);
324  hostkey_str = GNUNET_CRYPTO_eddsa_public_key_to_string(&public_key);
325  if (NULL != hostkey_str)
326  {
327  fprintf(stderr, "%4u: %s\n", c, hostkey_str);
328  GNUNET_free(hostkey_str);
329  }
330  else
331  fprintf(stderr, "%4u: %s\n", c, "invalid");
332  }
333  GNUNET_free(hostkeys_data);
334 }
int GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:541
Open the file for reading.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1339
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:729
Nobody is allowed to do anything to the file.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_TESTING_HOSTKEYFILESIZE
Size of each hostkey in the hostkey file (in BYTES).
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static void * hostkeys_data
The hostkeys data.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:367
static char * filename
static unsigned int list_keys_count
Flag for listing public key.
Definition: gnunet-ecc.c:44
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
int GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:254
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:272
Private ECC key encoded for transmission.
#define GNUNET_YES
Definition: gnunet_common.h:77
int fd
File handle on Unix-like systems.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1262
Handle used to access files (and pipes).
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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:

◆ 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 by the scheduler.

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

Definition at line 346 of file gnunet-ecc.c.

References _, create_keys(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_private_key_to_string(), GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_free, list_keys, make_keys, print_examples(), print_examples_flag, print_hex(), print_key(), print_private_key, print_public_key, and print_public_key_hex.

Referenced by main().

350 {
351  (void)cls;
352  (void)cfgfile;
353  (void)cfg;
354 
356  {
357  print_examples();
358  return;
359  }
360  if (NULL == args[0])
361  {
362  fprintf(stderr, "%s", _("No hostkey file specified on command line\n"));
363  return;
364  }
365  if (list_keys)
366  {
367  print_key(args[0]);
368  return;
369  }
370  if (make_keys > 0)
371  {
372  create_keys(args[0], args[1]);
373  return;
374  }
376  {
377  char *str;
378  struct GNUNET_DISK_FileHandle *keyfile;
381 
382  keyfile = GNUNET_DISK_file_open(args[0],
385  if (NULL == keyfile)
386  return;
387  while (sizeof(pk) == GNUNET_DISK_file_read(keyfile, &pk, sizeof(pk)))
388  {
391  {
392  print_hex("HEX:", &pub, sizeof(pub));
393  }
394  else if (print_public_key)
395  {
397  fprintf(stdout, "%s\n", str);
398  GNUNET_free(str);
399  }
400  else if (print_private_key)
401  {
403  fprintf(stdout, "%s\n", str);
404  GNUNET_free(str);
405  }
406  }
407  GNUNET_DISK_file_close(keyfile);
408  }
409 }
Open the file for reading.
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
static int list_keys
Flag for listing public key.
Definition: gnunet-ecc.c:39
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1339
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:729
Nobody is allowed to do anything to the file.
static void print_hex(const char *msg, const void *buf, size_t size)
Definition: gnunet-ecc.c:193
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static unsigned int make_keys
Option set to create a bunch of keys at once.
Definition: gnunet-ecc.c:69
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:367
static void print_key(const char *filename)
Definition: gnunet-ecc.c:264
static void print_examples()
Print some random example operations to stdout.
Definition: gnunet-ecc.c:255
static int print_public_key_hex
Flag for printing public key in hex.
Definition: gnunet-ecc.c:59
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:272
static int print_public_key
Flag for printing public key.
Definition: gnunet-ecc.c:49
Private ECC key encoded for transmission.
static int print_private_key
Flag for printing private key.
Definition: gnunet-ecc.c:54
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
char * GNUNET_CRYPTO_eddsa_private_key_to_string(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Convert a private key to a string.
Definition: crypto_ecc.c:400
static int print_examples_flag
Flag for printing the output of random example operations.
Definition: gnunet-ecc.c:64
static void create_keys(const char *fn, const char *prefix)
Create a flat file with a large number of key pairs for testing.
Definition: gnunet-ecc.c:79
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1262
Handle used to access files (and pipes).
#define GNUNET_free(ptr)
Wrapper around free.
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 
)

Program to manipulate ECC key files.

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

Definition at line 420 of file gnunet-ecc.c.

References gettext_noop, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_uint(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), list_keys, list_keys_count, make_keys, print_examples_flag, print_private_key, print_public_key, print_public_key_hex, ret, and run().

421 {
424  "iterate",
425  gettext_noop(
426  "list keys included in a file (for testing)"),
427  &list_keys),
429  'e',
430  "end=",
431  "COUNT",
432  gettext_noop("number of keys to list included in a file (for testing)"),
433  &list_keys_count),
435  'g',
436  "generate-keys",
437  "COUNT",
438  gettext_noop("create COUNT public-private key pairs (for testing)"),
439  &make_keys),
441  "print-public-key",
442  gettext_noop(
443  "print the public key in ASCII format"),
446  "print-private-key",
447  gettext_noop(
448  "print the private key in ASCII format"),
451  "print-hex",
452  gettext_noop(
453  "print the public key in HEX format"),
456  'E',
457  "examples",
458  gettext_noop(
459  "print examples of ECC operations (used for compatibility testing)"),
462  int ret;
463 
464  list_keys_count = UINT32_MAX;
465  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
466  return 2;
467 
468  ret = (GNUNET_OK ==
469  GNUNET_PROGRAM_run(argc,
470  argv,
471  "gnunet-ecc [OPTIONS] keyfile [VANITY_PREFIX]",
472  gettext_noop(
473  "Manipulate GNUnet private ECC key files"),
474  options,
475  &run,
476  NULL))
477  ? 0
478  : 1;
479  GNUNET_free((void *)argv);
480  return ret;
481 }
static int list_keys
Flag for listing public key.
Definition: gnunet-ecc.c:39
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static unsigned int make_keys
Option set to create a bunch of keys at once.
Definition: gnunet-ecc.c:69
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
Definition: gnunet-ecc.c:346
static unsigned int list_keys_count
Flag for listing public key.
Definition: gnunet-ecc.c:44
static int print_public_key_hex
Flag for printing public key in hex.
Definition: gnunet-ecc.c:59
static int print_public_key
Flag for printing public key.
Definition: gnunet-ecc.c:49
static int print_private_key
Flag for printing private key.
Definition: gnunet-ecc.c:54
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
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
static int print_examples_flag
Flag for printing the output of random example operations.
Definition: gnunet-ecc.c:64
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ list_keys

int list_keys
static

Flag for listing public key.

Definition at line 39 of file gnunet-ecc.c.

Referenced by main(), and run().

◆ list_keys_count

unsigned int list_keys_count
static

Flag for listing public key.

Definition at line 44 of file gnunet-ecc.c.

Referenced by main(), and print_key().

◆ print_public_key

int print_public_key
static

Flag for printing public key.

Definition at line 49 of file gnunet-ecc.c.

Referenced by main(), and run().

◆ print_private_key

int print_private_key
static

Flag for printing private key.

Definition at line 54 of file gnunet-ecc.c.

Referenced by main(), and run().

◆ print_public_key_hex

int print_public_key_hex
static

Flag for printing public key in hex.

Definition at line 59 of file gnunet-ecc.c.

Referenced by main(), and run().

◆ print_examples_flag

int print_examples_flag
static

Flag for printing the output of random example operations.

Definition at line 64 of file gnunet-ecc.c.

Referenced by main(), and run().

◆ make_keys

unsigned int make_keys
static

Option set to create a bunch of keys at once.

Definition at line 69 of file gnunet-ecc.c.

Referenced by create_keys(), main(), and run().