diff options
-rw-r--r-- | doc/man/gnunet-ecc.1 | 6 | ||||
-rw-r--r-- | src/include/gnunet_strings_lib.h | 4 | ||||
-rw-r--r-- | src/util/gnunet-ecc.c | 66 |
3 files changed, 46 insertions, 30 deletions
diff --git a/doc/man/gnunet-ecc.1 b/doc/man/gnunet-ecc.1 index 35d877efd..a91a2ac2f 100644 --- a/doc/man/gnunet-ecc.1 +++ b/doc/man/gnunet-ecc.1 | |||
@@ -1,4 +1,4 @@ | |||
1 | .TH GNUNET\-ECC 1 "Mar 15, 2012" "GNUnet" | 1 | .TH GNUNET\-ECC 1 "Jun 5, 2017" "GNUnet" |
2 | 2 | ||
3 | .SH NAME | 3 | .SH NAME |
4 | gnunet\-ecc \- manipulate GNUnet ECC key files | 4 | gnunet\-ecc \- manipulate GNUnet ECC key files |
@@ -19,6 +19,9 @@ Create COUNT public-private key pairs and write them to FILENAME. Used for crea | |||
19 | .IP "\-p, \-\-print-public-key" | 19 | .IP "\-p, \-\-print-public-key" |
20 | Print the corresponding public key to stdout. This is the value used for PKEY records in GNS. | 20 | Print the corresponding public key to stdout. This is the value used for PKEY records in GNS. |
21 | .B | 21 | .B |
22 | .IP "\-p, \-\-print-hex" | ||
23 | Print the corresponding public key to stdout in HEX format. Useful for comparing to Ed25519 keys in X.509 tools. | ||
24 | .B | ||
22 | .IP "\-P, \-\-print-peer-identity" | 25 | .IP "\-P, \-\-print-peer-identity" |
23 | Print the corresponding peer identity (hash of the public key) to stdout. This hash is used for the name of peers. | 26 | Print the corresponding peer identity (hash of the public key) to stdout. This hash is used for the name of peers. |
24 | .B | 27 | .B |
@@ -37,4 +40,3 @@ Print GNUnet version number. | |||
37 | 40 | ||
38 | .SH BUGS | 41 | .SH BUGS |
39 | Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org> | 42 | Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org> |
40 | |||
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h index 144780c82..897f9f161 100644 --- a/src/include/gnunet_strings_lib.h +++ b/src/include/gnunet_strings_lib.h | |||
@@ -281,7 +281,7 @@ GNUNET_STRINGS_get_short_name (const char *filename); | |||
281 | 281 | ||
282 | 282 | ||
283 | /** | 283 | /** |
284 | * Convert binary data to ASCII encoding using Base32Hex (RFC 4648). | 284 | * Convert binary data to ASCII encoding using CrockfordBase32. |
285 | * Does not append 0-terminator, but returns a pointer to the place where | 285 | * Does not append 0-terminator, but returns a pointer to the place where |
286 | * it should be placed, if needed. | 286 | * it should be placed, if needed. |
287 | * | 287 | * |
@@ -315,7 +315,7 @@ GNUNET_STRINGS_data_to_string_alloc (const void *buf, | |||
315 | 315 | ||
316 | 316 | ||
317 | /** | 317 | /** |
318 | * Convert Base32hex encoding back to data. | 318 | * Convert CrockfordBase32 encoding back to data. |
319 | * @a out_size must match exactly the size of the data before it was encoded. | 319 | * @a out_size must match exactly the size of the data before it was encoded. |
320 | * | 320 | * |
321 | * @param enc the encoding | 321 | * @param enc the encoding |
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; | |||
49 | static int print_public_key; | 49 | static int print_public_key; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Flag for printing public key in hex. | ||
53 | */ | ||
54 | static 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 | */ |
54 | static int print_examples_flag; | 59 | static 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 | |||
409 | main (int argc, | 419 | main (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)) |