aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_ecc.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-03-19 13:12:47 +0000
committerChristian Grothoff <christian@grothoff.org>2015-03-19 13:12:47 +0000
commit56af9c4ba537faf4c0a4a3acf8447a49673eec64 (patch)
tree1a98bea2666fb86bef94d361199c3d01fde93db9 /src/util/crypto_ecc.c
parentd86130ceeb0e9f7ef7adf192b8f44bf94398b466 (diff)
downloadgnunet-56af9c4ba537faf4c0a4a3acf8447a49673eec64.tar.gz
gnunet-56af9c4ba537faf4c0a4a3acf8447a49673eec64.zip
-get test to work, but with ecdsa instead of eddsa
Diffstat (limited to 'src/util/crypto_ecc.c')
-rw-r--r--src/util/crypto_ecc.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index c11739b27..25393cbf6 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -61,7 +61,9 @@
61 * @return 0 on success 61 * @return 0 on success
62 */ 62 */
63static int 63static int
64key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname, 64key_from_sexp (gcry_mpi_t * array,
65 gcry_sexp_t sexp,
66 const char *topname,
65 const char *elems) 67 const char *elems)
66{ 68{
67 gcry_sexp_t list; 69 gcry_sexp_t list;
@@ -229,7 +231,7 @@ GNUNET_CRYPTO_ecdsa_key_get_public (const struct GNUNET_CRYPTO_EcdsaPrivateKey *
229 GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL)); 231 GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL));
230 gcry_sexp_release (sexp); 232 gcry_sexp_release (sexp);
231 q = gcry_mpi_ec_get_mpi ("q@eddsa", ctx, 0); 233 q = gcry_mpi_ec_get_mpi ("q@eddsa", ctx, 0);
232 GNUNET_assert (q); 234 GNUNET_assert (NULL != q);
233 GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q); 235 GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q);
234 gcry_mpi_release (q); 236 gcry_mpi_release (q);
235 gcry_ctx_release (ctx); 237 gcry_ctx_release (ctx);
@@ -1313,7 +1315,7 @@ GNUNET_CRYPTO_eddsa_verify (uint32_t purpose,
1313 } 1315 }
1314 data = data_to_eddsa_value (validate); 1316 data = data_to_eddsa_value (validate);
1315 if (0 != (rc = gcry_sexp_build (&pub_sexpr, NULL, 1317 if (0 != (rc = gcry_sexp_build (&pub_sexpr, NULL,
1316 "(public-key(ecc(curve " CURVE ")(q %b)))", 1318 "(public-key(ecc(curve " CURVE ")(flags eddsa)(q %b)))",
1317 (int)sizeof (pub->q_y), pub->q_y))) 1319 (int)sizeof (pub->q_y), pub->q_y)))
1318 { 1320 {
1319 gcry_sexp_release (data); 1321 gcry_sexp_release (data);
@@ -1506,7 +1508,7 @@ GNUNET_CRYPTO_ecdsa_public_key_derive (const struct GNUNET_CRYPTO_EcdsaPublicKey
1506 compressed thus we first store it in the context and then get it 1508 compressed thus we first store it in the context and then get it
1507 back as a (decompresssed) point. */ 1509 back as a (decompresssed) point. */
1508 q_y = gcry_mpi_set_opaque_copy (NULL, pub->q_y, 8*sizeof (pub->q_y)); 1510 q_y = gcry_mpi_set_opaque_copy (NULL, pub->q_y, 8*sizeof (pub->q_y));
1509 GNUNET_assert (q_y); 1511 GNUNET_assert (NULL != q_y);
1510 GNUNET_assert (0 == gcry_mpi_ec_set_mpi ("q", q_y, ctx)); 1512 GNUNET_assert (0 == gcry_mpi_ec_set_mpi ("q", q_y, ctx));
1511 gcry_mpi_release (q_y); 1513 gcry_mpi_release (q_y);
1512 q = gcry_mpi_ec_get_point ("q", ctx, 0); 1514 q = gcry_mpi_ec_get_point ("q", ctx, 0);
@@ -1530,10 +1532,33 @@ GNUNET_CRYPTO_ecdsa_public_key_derive (const struct GNUNET_CRYPTO_EcdsaPublicKey
1530 gcry_mpi_point_release (v); 1532 gcry_mpi_point_release (v);
1531 q_y = gcry_mpi_ec_get_mpi ("q@eddsa", ctx, 0); 1533 q_y = gcry_mpi_ec_get_mpi ("q@eddsa", ctx, 0);
1532 GNUNET_assert (q_y); 1534 GNUNET_assert (q_y);
1533 GNUNET_CRYPTO_mpi_print_unsigned (result->q_y, sizeof result->q_y, q_y); 1535 GNUNET_CRYPTO_mpi_print_unsigned (result->q_y,
1536 sizeof (result->q_y),
1537 q_y);
1534 gcry_mpi_release (q_y); 1538 gcry_mpi_release (q_y);
1535 gcry_ctx_release (ctx); 1539 gcry_ctx_release (ctx);
1536} 1540}
1537 1541
1538 1542
1543/**
1544 * @ingroup crypto
1545 * Convert ECDSA public key to ECDHE public key.
1546 * Please be very careful when using this function, as mixing
1547 * cryptographic primitives is not always healthy.
1548 *
1549 * @param ecdsa ecdsa public key
1550 * @param ecdhe[OUT] ecdhe public key
1551 */
1552void
1553GNUNET_CRYPTO_ecdsa_public_to_ecdhe (const struct GNUNET_CRYPTO_EcdsaPublicKey *ecdsa,
1554 struct GNUNET_CRYPTO_EcdhePublicKey *ecdhe)
1555{
1556 GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) ==
1557 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
1558 memcpy (ecdhe,
1559 ecdsa,
1560 sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
1561}
1562
1563
1539/* end of crypto_ecc.c */ 1564/* end of crypto_ecc.c */