add -x option to gnunet-ecc for #4629
authorChristian Grothoff <christian@grothoff.org>
Sun, 4 Jun 2017 12:46:33 +0000 (14:46 +0200)
committerChristian Grothoff <christian@grothoff.org>
Sun, 4 Jun 2017 12:46:33 +0000 (14:46 +0200)
doc/man/gnunet-ecc.1
src/include/gnunet_strings_lib.h
src/util/gnunet-ecc.c

index 35d877efd5fc130624217123fe40b3c4b3097c74..a91a2ac2f7cb175be24495d333e630a888b3f998 100644 (file)
@@ -1,4 +1,4 @@
-.TH GNUNET\-ECC 1 "Mar 15, 2012" "GNUnet"
+.TH GNUNET\-ECC 1 "Jun 5, 2017" "GNUnet"
 
 .SH NAME
 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
 .IP "\-p, \-\-print-public-key"
 Print the corresponding public key to stdout.  This is the value used for PKEY records in GNS.
 .B
+.IP "\-p, \-\-print-hex"
+Print the corresponding public key to stdout in HEX format.  Useful for comparing to Ed25519 keys in X.509 tools.
+.B
 .IP "\-P, \-\-print-peer-identity"
 Print the corresponding peer identity (hash of the public key) to stdout.  This hash is used for the name of peers.
 .B
@@ -37,4 +40,3 @@ Print GNUnet version number.
 
 .SH BUGS
 Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org>
-
index 144780c8211d7455e2f3b3421186283d4c2bd467..897f9f16171ca013a01e7b523c3877dbde8c37f8 100644 (file)
@@ -281,7 +281,7 @@ GNUNET_STRINGS_get_short_name (const char *filename);
 
 
 /**
- * Convert binary data to ASCII encoding using Base32Hex (RFC 4648).
+ * Convert binary data to ASCII encoding using CrockfordBase32.
  * Does not append 0-terminator, but returns a pointer to the place where
  * it should be placed, if needed.
  *
@@ -315,7 +315,7 @@ GNUNET_STRINGS_data_to_string_alloc (const void *buf,
 
 
 /**
- * Convert Base32hex encoding back to data.
+ * Convert CrockfordBase32 encoding back to data.
  * @a out_size must match exactly the size of the data before it was encoded.
  *
  * @param enc the encoding
index 2a712f4ebd09fdf01d3a8f28e942ecf9035dd79e..42ecc2101dbea2c2e2b89d35a550be33f84af6e5 100644 (file)
@@ -48,6 +48,11 @@ static unsigned int list_keys_count;
  */
 static int print_public_key;
 
+/**
+ * Flag for printing public key in hex.
+ */
+static int print_public_key_hex;
+
 /**
  * Flag for printing the output of random example operations.
  */
@@ -195,12 +200,10 @@ print_hex (const char *msg,
            const void *buf,
            size_t size)
 {
-  size_t i;
-
   printf ("%s: ", msg);
-  for (i = 0; i < size; i++)
+  for (size_t i = 0; i < size; i++)
   {
-    printf ("%02hhx", ((const char *)buf)[i]);
+    printf ("%02hhx", ((const uint8_t *)buf)[i]);
   }
   printf ("\n");
 }
@@ -374,7 +377,7 @@ run (void *cls, char *const *args, const char *cfgfile,
     create_keys (args[0], args[1]);
     return;
   }
-  if (print_public_key)
+  if (print_public_key || print_public_key_hex)
   {
     char *str;
     struct GNUNET_DISK_FileHandle *keyfile;
@@ -388,9 +391,16 @@ run (void *cls, char *const *args, const char *cfgfile,
     while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
     {
       GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub);
-      str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
-      FPRINTF (stdout, "%s\n", str);
-      GNUNET_free (str);
+      if (print_public_key_hex)
+      {
+        print_hex ("HEX:", &pub, sizeof (pub));
+      }
+      else
+      {
+        str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
+        FPRINTF (stdout, "%s\n", str);
+        GNUNET_free (str);
+      }
     }
     GNUNET_DISK_file_close (keyfile);
   }
@@ -409,34 +419,38 @@ int
 main (int argc,
       char *const *argv)
 {
-  list_keys_count = UINT32_MAX;
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_option_flag ('i',
-                                  "iterate",
-                                  gettext_noop ("list keys included in a file (for testing)"),
-                                  &list_keys),
+                               "iterate",
+                               gettext_noop ("list keys included in a file (for testing)"),
+                               &list_keys),
     GNUNET_GETOPT_option_uint ('e',
-                                   "end=",
-                                   "COUNT",
-                                   gettext_noop ("number of keys to list included in a file (for testing)"),
-                                   &list_keys_count),
+                               "end=",
+                               "COUNT",
+                               gettext_noop ("number of keys to list included in a file (for testing)"),
+                               &list_keys_count),
     GNUNET_GETOPT_option_uint ('g',
-                                   "generate-keys",
-                                   "COUNT",
-                                   gettext_noop ("create COUNT public-private key pairs (for testing)"),
-                                   &make_keys),
+                               "generate-keys",
+                               "COUNT",
+                               gettext_noop ("create COUNT public-private key pairs (for testing)"),
+                               &make_keys),
     GNUNET_GETOPT_option_flag ('p',
-                                  "print-public-key",
-                                  gettext_noop ("print the public key in ASCII format"),
-                                  &print_public_key),
+                               "print-public-key",
+                               gettext_noop ("print the public key in ASCII format"),
+                               &print_public_key),
+    GNUNET_GETOPT_option_flag ('x',
+                               "print-hex",
+                               gettext_noop ("print the public key in HEX format"),
+                               &print_public_key_hex),
     GNUNET_GETOPT_option_flag ('E',
-                                  "examples",
-                                  gettext_noop ("print examples of ECC operations (used for compatibility testing)"),
-                                  &print_examples_flag),
+                               "examples",
+                               gettext_noop ("print examples of ECC operations (used for compatibility testing)"),
+                               &print_examples_flag),
     GNUNET_GETOPT_OPTION_END
   };
   int ret;
 
+  list_keys_count = UINT32_MAX;
   if (GNUNET_OK !=
       GNUNET_STRINGS_get_utf8_args (argc, argv,
                                     &argc, &argv))