adding GNUNET_CRYPTO_eddsa_private_key_from_string
authorChristian Grothoff <christian@grothoff.org>
Wed, 28 Jan 2015 18:47:09 +0000 (18:47 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 28 Jan 2015 18:47:09 +0000 (18:47 +0000)
src/include/gnunet_crypto_lib.h
src/util/crypto_ecc.c

index 38ef966a935ad79d12ca04a17786928220fedd0c..e1e2951db3d72173cc95cbd154d9384559bec846 100644 (file)
@@ -1047,6 +1047,20 @@ GNUNET_CRYPTO_ecdsa_public_key_from_string (const char *enc,
                                             struct GNUNET_CRYPTO_EcdsaPublicKey *pub);
 
 
+/**
+ * Convert a string representing a private key to a private key.
+ *
+ * @param enc encoded public key
+ * @param enclen number of bytes in @a enc (without 0-terminator)
+ * @param priv where to store the private key
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc,
+                                             size_t enclen,
+                                             struct GNUNET_CRYPTO_EddsaPrivateKey *pub);
+
+
 /**
  * Convert a string representing a public key to a public key.
  *
index 23d6ade7e5d0efeb42f37fb2acc215a9e72871c4..baffc8fcc4fed1872781fe69689f7e39fe7f268a 100644 (file)
@@ -408,6 +408,35 @@ GNUNET_CRYPTO_eddsa_public_key_from_string (const char *enc,
 }
 
 
+/**
+ * Convert a string representing a private key to a private key.
+ *
+ * @param enc encoded public key
+ * @param enclen number of bytes in @a enc (without 0-terminator)
+ * @param priv where to store the private key
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc,
+                                             size_t enclen,
+                                             struct GNUNET_CRYPTO_EddsaPrivateKey *pub)
+{
+  size_t keylen = (sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
+
+  if (keylen % 5 > 0)
+    keylen += 5 - keylen % 5;
+  keylen /= 5;
+  if (enclen != keylen)
+    return GNUNET_SYSERR;
+
+  if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen,
+                                                 pub,
+                                                 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
+    return GNUNET_SYSERR;
+  return GNUNET_OK;
+}
+
+
 /**
  * @ingroup crypto
  * Clear memory that was used to store a private key.