aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-ecc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/gnunet-ecc.c')
-rw-r--r--src/util/gnunet-ecc.c66
1 files changed, 40 insertions, 26 deletions
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c
index 2a712f4eb..42ecc2101 100644
--- a/src/util/gnunet-ecc.c
+++ b/src/util/gnunet-ecc.c
@@ -49,6 +49,11 @@ static unsigned int list_keys_count;
49static int print_public_key; 49static int print_public_key;
50 50
51/** 51/**
52 * Flag for printing public key in hex.
53 */
54static int print_public_key_hex;
55
56/**
52 * Flag for printing the output of random example operations. 57 * Flag for printing the output of random example operations.
53 */ 58 */
54static int print_examples_flag; 59static int print_examples_flag;
@@ -195,12 +200,10 @@ print_hex (const char *msg,
195 const void *buf, 200 const void *buf,
196 size_t size) 201 size_t size)
197{ 202{
198 size_t i;
199
200 printf ("%s: ", msg); 203 printf ("%s: ", msg);
201 for (i = 0; i < size; i++) 204 for (size_t i = 0; i < size; i++)
202 { 205 {
203 printf ("%02hhx", ((const char *)buf)[i]); 206 printf ("%02hhx", ((const uint8_t *)buf)[i]);
204 } 207 }
205 printf ("\n"); 208 printf ("\n");
206} 209}
@@ -374,7 +377,7 @@ run (void *cls, char *const *args, const char *cfgfile,
374 create_keys (args[0], args[1]); 377 create_keys (args[0], args[1]);
375 return; 378 return;
376 } 379 }
377 if (print_public_key) 380 if (print_public_key || print_public_key_hex)
378 { 381 {
379 char *str; 382 char *str;
380 struct GNUNET_DISK_FileHandle *keyfile; 383 struct GNUNET_DISK_FileHandle *keyfile;
@@ -388,9 +391,16 @@ run (void *cls, char *const *args, const char *cfgfile,
388 while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk))) 391 while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
389 { 392 {
390 GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub); 393 GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub);
391 str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub); 394 if (print_public_key_hex)
392 FPRINTF (stdout, "%s\n", str); 395 {
393 GNUNET_free (str); 396 print_hex ("HEX:", &pub, sizeof (pub));
397 }
398 else
399 {
400 str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
401 FPRINTF (stdout, "%s\n", str);
402 GNUNET_free (str);
403 }
394 } 404 }
395 GNUNET_DISK_file_close (keyfile); 405 GNUNET_DISK_file_close (keyfile);
396 } 406 }
@@ -409,34 +419,38 @@ int
409main (int argc, 419main (int argc,
410 char *const *argv) 420 char *const *argv)
411{ 421{
412 list_keys_count = UINT32_MAX;
413 struct GNUNET_GETOPT_CommandLineOption options[] = { 422 struct GNUNET_GETOPT_CommandLineOption options[] = {
414 GNUNET_GETOPT_option_flag ('i', 423 GNUNET_GETOPT_option_flag ('i',
415 "iterate", 424 "iterate",
416 gettext_noop ("list keys included in a file (for testing)"), 425 gettext_noop ("list keys included in a file (for testing)"),
417 &list_keys), 426 &list_keys),
418 GNUNET_GETOPT_option_uint ('e', 427 GNUNET_GETOPT_option_uint ('e',
419 "end=", 428 "end=",
420 "COUNT", 429 "COUNT",
421 gettext_noop ("number of keys to list included in a file (for testing)"), 430 gettext_noop ("number of keys to list included in a file (for testing)"),
422 &list_keys_count), 431 &list_keys_count),
423 GNUNET_GETOPT_option_uint ('g', 432 GNUNET_GETOPT_option_uint ('g',
424 "generate-keys", 433 "generate-keys",
425 "COUNT", 434 "COUNT",
426 gettext_noop ("create COUNT public-private key pairs (for testing)"), 435 gettext_noop ("create COUNT public-private key pairs (for testing)"),
427 &make_keys), 436 &make_keys),
428 GNUNET_GETOPT_option_flag ('p', 437 GNUNET_GETOPT_option_flag ('p',
429 "print-public-key", 438 "print-public-key",
430 gettext_noop ("print the public key in ASCII format"), 439 gettext_noop ("print the public key in ASCII format"),
431 &print_public_key), 440 &print_public_key),
441 GNUNET_GETOPT_option_flag ('x',
442 "print-hex",
443 gettext_noop ("print the public key in HEX format"),
444 &print_public_key_hex),
432 GNUNET_GETOPT_option_flag ('E', 445 GNUNET_GETOPT_option_flag ('E',
433 "examples", 446 "examples",
434 gettext_noop ("print examples of ECC operations (used for compatibility testing)"), 447 gettext_noop ("print examples of ECC operations (used for compatibility testing)"),
435 &print_examples_flag), 448 &print_examples_flag),
436 GNUNET_GETOPT_OPTION_END 449 GNUNET_GETOPT_OPTION_END
437 }; 450 };
438 int ret; 451 int ret;
439 452
453 list_keys_count = UINT32_MAX;
440 if (GNUNET_OK != 454 if (GNUNET_OK !=
441 GNUNET_STRINGS_get_utf8_args (argc, argv, 455 GNUNET_STRINGS_get_utf8_args (argc, argv,
442 &argc, &argv)) 456 &argc, &argv))