summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-28 18:47:09 +0000
committerChristian Grothoff <christian@grothoff.org>2015-01-28 18:47:09 +0000
commit9d510d2c9b77bede694e7cec5b09eac6aeae8c98 (patch)
tree5983eea0ffc4bdb4d03873671638ed9c7018ecf3 /src
parent5b51eac94676e19d2029f00fc8f706b3c33f2c1c (diff)
adding GNUNET_CRYPTO_eddsa_private_key_from_string
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_crypto_lib.h14
-rw-r--r--src/util/crypto_ecc.c29
2 files changed, 43 insertions, 0 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 38ef966a9..e1e2951db 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -1048,6 +1048,20 @@ GNUNET_CRYPTO_ecdsa_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);
+
+
+/**
* Convert a string representing a public key to a public key.
*
* @param enc encoded public key
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index 23d6ade7e..baffc8fcc 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -409,6 +409,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.
*