gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r29290 - in gnunet/src: core util


From: gnunet
Subject: [GNUnet-SVN] r29290 - in gnunet/src: core util
Date: Mon, 16 Sep 2013 09:49:28 +0200

Author: grothoff
Date: 2013-09-16 09:49:27 +0200 (Mon, 16 Sep 2013)
New Revision: 29290

Modified:
   gnunet/src/core/gnunet-service-core_kx.c
   gnunet/src/util/crypto_ecc.c
   gnunet/src/util/test_crypto_ecc.c
Log:
-fix compiler warnings

Modified: gnunet/src/core/gnunet-service-core_kx.c
===================================================================
--- gnunet/src/core/gnunet-service-core_kx.c    2013-09-16 05:00:32 UTC (rev 
29289)
+++ gnunet/src/core/gnunet-service-core_kx.c    2013-09-16 07:49:27 UTC (rev 
29290)
@@ -111,7 +111,7 @@
    * Ephemeral public ECC key (always for NIST P-521) encoded in a format 
suitable
    * for network transmission as created using 'gcry_sexp_sprint'.
    */
-  struct GNUNET_CRYPTO_EccPublicSignKey ephemeral_key;  
+  struct GNUNET_CRYPTO_EccPublicEncryptKey ephemeral_key;  
 
   /**
    * Public key of the signing peer (persistent version, not the ephemeral 
public key).
@@ -1492,8 +1492,8 @@
   {
     current_ekm.expiration_time = GNUNET_TIME_absolute_hton 
(GNUNET_TIME_UNIT_FOREVER_ABS);
   }
-  GNUNET_CRYPTO_ecc_key_get_public_for_signature (my_ephemeral_key,
-                                   &current_ekm.ephemeral_key);
+  GNUNET_CRYPTO_ecc_key_get_public_for_encryption (my_ephemeral_key,
+                                                  &current_ekm.ephemeral_key);
   current_ekm.origin_public_key = my_public_key;
   GNUNET_assert (GNUNET_OK ==
                 GNUNET_CRYPTO_ecc_sign (my_private_key,

Modified: gnunet/src/util/crypto_ecc.c
===================================================================
--- gnunet/src/util/crypto_ecc.c        2013-09-16 05:00:32 UTC (rev 29289)
+++ gnunet/src/util/crypto_ecc.c        2013-09-16 07:49:27 UTC (rev 29290)
@@ -227,9 +227,9 @@
  * @param ctx context to use for ECC operations
  */ 
 static void
-point_to_public_key (gcry_mpi_point_t q,
-                    gcry_ctx_t ctx,
-                    struct GNUNET_CRYPTO_EccPublicSignKey *pub)
+point_to_public_sign_key (gcry_mpi_point_t q,
+                         gcry_ctx_t ctx,
+                         struct GNUNET_CRYPTO_EccPublicSignKey *pub)
 {
   gcry_mpi_t q_x;
   gcry_mpi_t q_y;
@@ -250,6 +250,37 @@
 
 
 /**
+ * Initialize public key struct from the respective point
+ * on the curve.
+ *
+ * @param q point on curve
+ * @param pub public key struct to initialize
+ * @param ctx context to use for ECC operations
+ */ 
+static void
+point_to_public_encrypt_key (gcry_mpi_point_t q,
+                            gcry_ctx_t ctx,
+                            struct GNUNET_CRYPTO_EccPublicEncryptKey *pub)
+{
+  gcry_mpi_t q_x;
+  gcry_mpi_t q_y;
+  
+  q_x = gcry_mpi_new (256);
+  q_y = gcry_mpi_new (256);
+  if (gcry_mpi_ec_get_affine (q_x, q_y, q, ctx))
+  {
+    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "get_affine failed", 0);
+    return;
+  }
+
+  mpi_print (pub->q_x, sizeof (pub->q_x), q_x);
+  mpi_print (pub->q_y, sizeof (pub->q_y), q_y);
+  gcry_mpi_release (q_x);
+  gcry_mpi_release (q_y);
+}
+
+
+/**
  * Extract the public key for the given private key.
  *
  * @param priv the private key
@@ -268,13 +299,38 @@
   GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL));
   gcry_sexp_release (sexp);
   q = gcry_mpi_ec_get_point ("q", ctx, 0);
-  point_to_public_key (q, ctx, pub);
+  point_to_public_sign_key (q, ctx, pub);
   gcry_ctx_release (ctx);
   gcry_mpi_point_release (q);
 }
 
 
 /**
+ * Extract the public key for the given private key.
+ *
+ * @param priv the private key
+ * @param pub where to write the public key
+ */
+void
+GNUNET_CRYPTO_ecc_key_get_public_for_encryption (const struct 
GNUNET_CRYPTO_EccPrivateKey *priv,
+                                                struct 
GNUNET_CRYPTO_EccPublicEncryptKey *pub)
+{
+  gcry_sexp_t sexp;
+  gcry_ctx_t ctx;
+  gcry_mpi_point_t q;
+
+  sexp = decode_private_key (priv);
+  GNUNET_assert (NULL != sexp);
+  GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL));
+  gcry_sexp_release (sexp);
+  q = gcry_mpi_ec_get_point ("q", ctx, 0);
+  point_to_public_encrypt_key (q, ctx, pub);
+  gcry_ctx_release (ctx);
+  gcry_mpi_point_release (q);
+}
+
+
+/**
  * Convert a public key to a string.
  *
  * @param pub key to convert
@@ -1047,7 +1103,7 @@
   gcry_mpi_release (n);
   gcry_mpi_point_release (q);
   /* convert point 'v' to public key that we return */
-  point_to_public_key (v, ctx, result);
+  point_to_public_sign_key (v, ctx, result);
   gcry_mpi_point_release (v);
   gcry_ctx_release (ctx);
 }

Modified: gnunet/src/util/test_crypto_ecc.c
===================================================================
--- gnunet/src/util/test_crypto_ecc.c   2013-09-16 05:00:32 UTC (rev 29289)
+++ gnunet/src/util/test_crypto_ecc.c   2013-09-16 07:49:27 UTC (rev 29290)
@@ -204,15 +204,15 @@
 {
   struct GNUNET_CRYPTO_EccPrivateKey *priv1;
   struct GNUNET_CRYPTO_EccPrivateKey *priv2;
-  struct GNUNET_CRYPTO_EccPublicSignKey pub1;
-  struct GNUNET_CRYPTO_EccPublicSignKey pub2;
+  struct GNUNET_CRYPTO_EccPublicEncryptKey pub1;
+  struct GNUNET_CRYPTO_EccPublicEncryptKey pub2;
   struct GNUNET_HashCode ecdh1;
   struct GNUNET_HashCode ecdh2;
 
   priv1 = GNUNET_CRYPTO_ecc_key_create ();
   priv2 = GNUNET_CRYPTO_ecc_key_create ();
-  GNUNET_CRYPTO_ecc_key_get_public_for_signature (priv1, &pub1);
-  GNUNET_CRYPTO_ecc_key_get_public_for_signature (priv2, &pub2);
+  GNUNET_CRYPTO_ecc_key_get_public_for_encryption (priv1, &pub1);
+  GNUNET_CRYPTO_ecc_key_get_public_for_encryption (priv2, &pub2);
   GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &ecdh1);
   GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &ecdh2);
   GNUNET_assert (0 == memcmp (&ecdh1, &ecdh2,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]