aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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,
1048 1048
1049 1049
1050/** 1050/**
1051 * Convert a string representing a private key to a private key.
1052 *
1053 * @param enc encoded public key
1054 * @param enclen number of bytes in @a enc (without 0-terminator)
1055 * @param priv where to store the private key
1056 * @return #GNUNET_OK on success
1057 */
1058int
1059GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc,
1060 size_t enclen,
1061 struct GNUNET_CRYPTO_EddsaPrivateKey *pub);
1062
1063
1064/**
1051 * Convert a string representing a public key to a public key. 1065 * Convert a string representing a public key to a public key.
1052 * 1066 *
1053 * @param enc encoded public key 1067 * @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,
409 409
410 410
411/** 411/**
412 * Convert a string representing a private key to a private key.
413 *
414 * @param enc encoded public key
415 * @param enclen number of bytes in @a enc (without 0-terminator)
416 * @param priv where to store the private key
417 * @return #GNUNET_OK on success
418 */
419int
420GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc,
421 size_t enclen,
422 struct GNUNET_CRYPTO_EddsaPrivateKey *pub)
423{
424 size_t keylen = (sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
425
426 if (keylen % 5 > 0)
427 keylen += 5 - keylen % 5;
428 keylen /= 5;
429 if (enclen != keylen)
430 return GNUNET_SYSERR;
431
432 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen,
433 pub,
434 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)))
435 return GNUNET_SYSERR;
436 return GNUNET_OK;
437}
438
439
440/**
412 * @ingroup crypto 441 * @ingroup crypto
413 * Clear memory that was used to store a private key. 442 * Clear memory that was used to store a private key.
414 * 443 *