aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_ecc.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-11-01 10:33:57 +0100
committerChristian Grothoff <christian@grothoff.org>2017-11-01 10:33:57 +0100
commitd1a84861ce988b9cdc87e19ff140400833e616fd (patch)
tree6bdeab590dc8b6f0695f9808831c96475b299c67 /src/util/crypto_ecc.c
parenta901264efb50a61f096a4966a0cb5789690706f0 (diff)
downloadgnunet-d1a84861ce988b9cdc87e19ff140400833e616fd.tar.gz
gnunet-d1a84861ce988b9cdc87e19ff140400833e616fd.zip
add -P option to gnunet-ecc
Diffstat (limited to 'src/util/crypto_ecc.c')
-rw-r--r--src/util/crypto_ecc.c45
1 files changed, 39 insertions, 6 deletions
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
354 354
355 355
356/** 356/**
357 * Convert a private key to a string.
358 *
359 * @param priv key to convert
360 * @return string representing @a pub
361 */
362char *
363GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
364{
365 char *privkeybuf;
366 size_t keylen = (sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)) * 8;
367 char *end;
368
369 if (keylen % 5 > 0)
370 keylen += 5 - keylen % 5;
371 keylen /= 5;
372 privkeybuf = GNUNET_malloc (keylen + 1);
373 end = GNUNET_STRINGS_data_to_string ((unsigned char *) priv,
374 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey),
375 privkeybuf,
376 keylen);
377 if (NULL == end)
378 {
379 GNUNET_free (privkeybuf);
380 return NULL;
381 }
382 *end = '\0';
383 return privkeybuf;
384}
385
386
387/**
357 * Convert a string representing a public key to a public key. 388 * Convert a string representing a public key to a public key.
358 * 389 *
359 * @param enc encoded public key 390 * @param enc encoded public key
@@ -374,9 +405,10 @@ GNUNET_CRYPTO_ecdsa_public_key_from_string (const char *enc,
374 if (enclen != keylen) 405 if (enclen != keylen)
375 return GNUNET_SYSERR; 406 return GNUNET_SYSERR;
376 407
377 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen, 408 if (GNUNET_OK !=
378 pub, 409 GNUNET_STRINGS_string_to_data (enc, enclen,
379 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 410 pub,
411 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
380 return GNUNET_SYSERR; 412 return GNUNET_SYSERR;
381 return GNUNET_OK; 413 return GNUNET_OK;
382} 414}
@@ -403,9 +435,10 @@ GNUNET_CRYPTO_eddsa_public_key_from_string (const char *enc,
403 if (enclen != keylen) 435 if (enclen != keylen)
404 return GNUNET_SYSERR; 436 return GNUNET_SYSERR;
405 437
406 if (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, enclen, 438 if (GNUNET_OK !=
407 pub, 439 GNUNET_STRINGS_string_to_data (enc, enclen,
408 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))) 440 pub,
441 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)))
409 return GNUNET_SYSERR; 442 return GNUNET_SYSERR;
410 return GNUNET_OK; 443 return GNUNET_OK;
411} 444}