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 -P option to gnunet-ecc


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: add -P option to gnunet-ecc
Date: Wed, 01 Nov 2017 10:34:07 +0100

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 d1a84861c add -P option to gnunet-ecc
d1a84861c is described below

commit d1a84861ce988b9cdc87e19ff140400833e616fd
Author: Christian Grothoff <address@hidden>
AuthorDate: Wed Nov 1 10:33:57 2017 +0100

    add -P option to gnunet-ecc
---
 src/include/gnunet_crypto_lib.h | 10 +++++++++
 src/util/crypto_ecc.c           | 45 +++++++++++++++++++++++++++++++++++------
 src/util/gnunet-ecc.c           | 22 +++++++++++++++++---
 3 files changed, 68 insertions(+), 9 deletions(-)

diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 5dc5b60d7..6ac2a67fa 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -1110,6 +1110,16 @@ GNUNET_CRYPTO_ecdsa_public_key_to_string (const struct 
GNUNET_CRYPTO_EcdsaPublic
 
 
 /**
+ * Convert a private key to a string.
+ *
+ * @param priv key to convert
+ * @return string representing @a pub
+ */
+char *
+GNUNET_CRYPTO_eddsa_private_key_to_string (const struct 
GNUNET_CRYPTO_EddsaPrivateKey *priv);
+
+
+/**
  * Convert a public key to a string.
  *
  * @param pub key to convert
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index eaa49a991..7845932ee 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -354,6 +354,37 @@ GNUNET_CRYPTO_eddsa_public_key_to_string (const struct 
GNUNET_CRYPTO_EddsaPublic
 
 
 /**
+ * Convert a private key to a string.
+ *
+ * @param priv key to convert
+ * @return string representing @a pub
+ */
+char *
+GNUNET_CRYPTO_eddsa_private_key_to_string (const struct 
GNUNET_CRYPTO_EddsaPrivateKey *priv)
+{
+  char *privkeybuf;
+  size_t keylen = (sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
+  char *end;
+
+  if (keylen % 5 > 0)
+    keylen += 5 - keylen % 5;
+  keylen /= 5;
+  privkeybuf = GNUNET_malloc (keylen + 1);
+  end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
+                                      sizeof (struct 
GNUNET_CRYPTO_EddsaPrivateKey),
+                                      privkeybuf,
+                                      keylen);
+  if (NULL == end)
+  {
+    GNUNET_free (privkeybuf);
+    return NULL;
+  }
+  *end = '\0';
+  return privkeybuf;
+}
+
+
+/**
  * Convert a string representing a public key to a public key.
  *
  * @param enc encoded public key
@@ -374,9 +405,10 @@ GNUNET_CRYPTO_ecdsa_public_key_from_string (const char 
*enc,
   if (enclen != keylen)
     return GNUNET_SYSERR;
 
-  if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen,
-                                                 pub,
-                                                 sizeof (struct 
GNUNET_CRYPTO_EcdsaPublicKey)))
+  if (GNUNET_OK !=
+      GNUNET_STRINGS_string_to_data (enc, enclen,
+                                    pub,
+                                    sizeof (struct 
GNUNET_CRYPTO_EcdsaPublicKey)))
     return GNUNET_SYSERR;
   return GNUNET_OK;
 }
@@ -403,9 +435,10 @@ GNUNET_CRYPTO_eddsa_public_key_from_string (const char 
*enc,
   if (enclen != keylen)
     return GNUNET_SYSERR;
 
-  if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen,
-                                                 pub,
-                                                 sizeof (struct 
GNUNET_CRYPTO_EddsaPublicKey)))
+  if (GNUNET_OK !=
+      GNUNET_STRINGS_string_to_data (enc, enclen,
+                                    pub,
+                                    sizeof (struct 
GNUNET_CRYPTO_EddsaPublicKey)))
     return GNUNET_SYSERR;
   return GNUNET_OK;
 }
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c
index 42ecc2101..66a4bd3e9 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 private key.
+ */
+static int print_private_key;
+
+/**
  * Flag for printing public key in hex.
  */
 static int print_public_key_hex;
@@ -377,7 +382,7 @@ run (void *cls, char *const *args, const char *cfgfile,
     create_keys (args[0], args[1]);
     return;
   }
-  if (print_public_key || print_public_key_hex)
+  if (print_public_key || print_public_key_hex || print_private_key)
   {
     char *str;
     struct GNUNET_DISK_FileHandle *keyfile;
@@ -388,19 +393,26 @@ run (void *cls, char *const *args, const char *cfgfile,
                                      GNUNET_DISK_PERM_NONE);
     if (NULL == keyfile)
       return;
-    while (sizeof (pk) == GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
+    while (sizeof (pk) ==
+          GNUNET_DISK_file_read (keyfile, &pk, sizeof (pk)))
     {
       GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub);
       if (print_public_key_hex)
       {
         print_hex ("HEX:", &pub, sizeof (pub));
       }
-      else
+      else if (print_public_key)
       {
         str = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
         FPRINTF (stdout, "%s\n", str);
         GNUNET_free (str);
       }
+      else if (print_private_key)
+      {
+        str = GNUNET_CRYPTO_eddsa_private_key_to_string (&pk);
+        FPRINTF (stdout, "%s\n", str);
+        GNUNET_free (str);
+      }
     }
     GNUNET_DISK_file_close (keyfile);
   }
@@ -438,6 +450,10 @@ main (int argc,
                                "print-public-key",
                                gettext_noop ("print the public key in ASCII 
format"),
                                &print_public_key),
+    GNUNET_GETOPT_option_flag ('P',
+                               "print-private-key",
+                               gettext_noop ("print the private key in ASCII 
format"),
+                               &print_private_key),
     GNUNET_GETOPT_option_flag ('x',
                                "print-hex",
                                gettext_noop ("print the public key in HEX 
format"),

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



reply via email to

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