gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated: add -x option to gnunet-ecc


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: add -x option to gnunet-ecc for #4629
Date: Sun, 04 Jun 2017 14:46:35 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 97baa2271 add -x option to gnunet-ecc for #4629
97baa2271 is described below

commit 97baa2271fab56da227f345fd8ba306d67f2c437
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Jun 4 14:46:33 2017 +0200

    add -x option to gnunet-ecc for #4629
---
 doc/man/gnunet-ecc.1             |  6 ++--
 src/include/gnunet_strings_lib.h |  4 +--
 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 @@
-.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 <address@hidden>
-
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);
 
 
 /**
- * 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
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;
 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.
  */
 static int print_examples_flag;
@@ -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))

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]