aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_ecc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/crypto_ecc.c')
-rw-r--r--src/util/crypto_ecc.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index 4bba395b3..eaa49a991 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -38,11 +38,11 @@
38 */ 38 */
39#define CURVE "Ed25519" 39#define CURVE "Ed25519"
40 40
41#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__) 41#define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-ecc", __VA_ARGS__)
42 42
43#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) 43#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-crypto-ecc", syscall)
44 44
45#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename) 45#define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-crypto-ecc", syscall, filename)
46 46
47/** 47/**
48 * Log an error message at log-level 'level' that indicates 48 * Log an error message at log-level 'level' that indicates
@@ -488,6 +488,28 @@ struct GNUNET_CRYPTO_EcdhePrivateKey *
488GNUNET_CRYPTO_ecdhe_key_create () 488GNUNET_CRYPTO_ecdhe_key_create ()
489{ 489{
490 struct GNUNET_CRYPTO_EcdhePrivateKey *priv; 490 struct GNUNET_CRYPTO_EcdhePrivateKey *priv;
491
492 priv = GNUNET_new (struct GNUNET_CRYPTO_EcdhePrivateKey);
493 if (GNUNET_OK !=
494 GNUNET_CRYPTO_ecdhe_key_create2 (priv))
495 {
496 GNUNET_free (priv);
497 return NULL;
498 }
499 return priv;
500}
501
502
503/**
504 * @ingroup crypto
505 * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear().
506 *
507 * @param[out] pk set to fresh private key;
508 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
509 */
510int
511GNUNET_CRYPTO_ecdhe_key_create2 (struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
512{
491 gcry_sexp_t priv_sexp; 513 gcry_sexp_t priv_sexp;
492 gcry_sexp_t s_keyparam; 514 gcry_sexp_t s_keyparam;
493 gcry_mpi_t d; 515 gcry_mpi_t d;
@@ -503,13 +525,13 @@ GNUNET_CRYPTO_ecdhe_key_create ()
503 "(flags eddsa no-keytest)))"))) 525 "(flags eddsa no-keytest)))")))
504 { 526 {
505 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); 527 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
506 return NULL; 528 return GNUNET_SYSERR;
507 } 529 }
508 if (0 != (rc = gcry_pk_genkey (&priv_sexp, s_keyparam))) 530 if (0 != (rc = gcry_pk_genkey (&priv_sexp, s_keyparam)))
509 { 531 {
510 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_genkey", rc); 532 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_genkey", rc);
511 gcry_sexp_release (s_keyparam); 533 gcry_sexp_release (s_keyparam);
512 return NULL; 534 return GNUNET_SYSERR;
513 } 535 }
514 gcry_sexp_release (s_keyparam); 536 gcry_sexp_release (s_keyparam);
515#if EXTRA_CHECKS 537#if EXTRA_CHECKS
@@ -517,20 +539,19 @@ GNUNET_CRYPTO_ecdhe_key_create ()
517 { 539 {
518 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc); 540 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
519 gcry_sexp_release (priv_sexp); 541 gcry_sexp_release (priv_sexp);
520 return NULL; 542 return GNUNET_SYSERR;
521 } 543 }
522#endif 544#endif
523 if (0 != (rc = key_from_sexp (&d, priv_sexp, "private-key", "d"))) 545 if (0 != (rc = key_from_sexp (&d, priv_sexp, "private-key", "d")))
524 { 546 {
525 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "key_from_sexp", rc); 547 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "key_from_sexp", rc);
526 gcry_sexp_release (priv_sexp); 548 gcry_sexp_release (priv_sexp);
527 return NULL; 549 return GNUNET_SYSERR;
528 } 550 }
529 gcry_sexp_release (priv_sexp); 551 gcry_sexp_release (priv_sexp);
530 priv = GNUNET_new (struct GNUNET_CRYPTO_EcdhePrivateKey); 552 GNUNET_CRYPTO_mpi_print_unsigned (pk->d, sizeof (pk->d), d);
531 GNUNET_CRYPTO_mpi_print_unsigned (priv->d, sizeof (priv->d), d);
532 gcry_mpi_release (d); 553 gcry_mpi_release (d);
533 return priv; 554 return GNUNET_OK;
534} 555}
535 556
536 557