gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r35406 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r35406 - gnunet/src/util
Date: Thu, 19 Mar 2015 14:12:47 +0100

Author: grothoff
Date: 2015-03-19 14:12:47 +0100 (Thu, 19 Mar 2015)
New Revision: 35406

Added:
   gnunet/src/util/test_crypto_ecdh_ecdsa.c
Removed:
   gnunet/src/util/test_crypto_ecdh_eddsa.c
Modified:
   gnunet/src/util/Makefile.am
   gnunet/src/util/configuration.c
   gnunet/src/util/crypto_ecc.c
   gnunet/src/util/crypto_mpi.c
   gnunet/src/util/strings.c
Log:
-get test to work, but with ecdsa instead of eddsa

Modified: gnunet/src/util/Makefile.am
===================================================================
--- gnunet/src/util/Makefile.am 2015-03-18 23:45:34 UTC (rev 35405)
+++ gnunet/src/util/Makefile.am 2015-03-19 13:12:47 UTC (rev 35406)
@@ -227,7 +227,7 @@
  test_crypto_ecdsa \
  test_crypto_eddsa \
  test_crypto_ecdhe \
- test_crypto_ecdh_eddsa \
+ test_crypto_ecdh_ecdsa \
  test_crypto_hash \
  test_crypto_hash_context \
  test_crypto_hkdf \

Modified: gnunet/src/util/configuration.c
===================================================================
--- gnunet/src/util/configuration.c     2015-03-18 23:45:34 UTC (rev 35405)
+++ gnunet/src/util/configuration.c     2015-03-19 13:12:47 UTC (rev 35406)
@@ -572,10 +572,9 @@
  * @param iter_cls closure for @a iter
  */
 void
-GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle
-                                       *cfg,
-                                       GNUNET_CONFIGURATION_Section_Iterator
-                                       iter, void *iter_cls)
+GNUNET_CONFIGURATION_iterate_sections (const struct 
GNUNET_CONFIGURATION_Handle *cfg,
+                                       GNUNET_CONFIGURATION_Section_Iterator 
iter,
+                                       void *iter_cls)
 {
   struct ConfigSection *spos;
   struct ConfigSection *next;

Modified: gnunet/src/util/crypto_ecc.c
===================================================================
--- gnunet/src/util/crypto_ecc.c        2015-03-18 23:45:34 UTC (rev 35405)
+++ gnunet/src/util/crypto_ecc.c        2015-03-19 13:12:47 UTC (rev 35406)
@@ -61,7 +61,9 @@
  * @return 0 on success
  */
 static int
-key_from_sexp (gcry_mpi_t * array, gcry_sexp_t sexp, const char *topname,
+key_from_sexp (gcry_mpi_t * array,
+               gcry_sexp_t sexp,
+               const char *topname,
                const char *elems)
 {
   gcry_sexp_t list;
@@ -229,7 +231,7 @@
   GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, sexp, NULL));
   gcry_sexp_release (sexp);
   q = gcry_mpi_ec_get_mpi ("address@hidden", ctx, 0);
-  GNUNET_assert (q);
+  GNUNET_assert (NULL != q);
   GNUNET_CRYPTO_mpi_print_unsigned (pub->q_y, sizeof (pub->q_y), q);
   gcry_mpi_release (q);
   gcry_ctx_release (ctx);
@@ -1313,7 +1315,7 @@
   }
   data = data_to_eddsa_value (validate);
   if (0 != (rc = gcry_sexp_build (&pub_sexpr, NULL,
-                                  "(public-key(ecc(curve " CURVE ")(q %b)))",
+                                  "(public-key(ecc(curve " CURVE ")(flags 
eddsa)(q %b)))",
                                   (int)sizeof (pub->q_y), pub->q_y)))
   {
     gcry_sexp_release (data);
@@ -1506,7 +1508,7 @@
      compressed thus we first store it in the context and then get it
      back as a (decompresssed) point.  */
   q_y = gcry_mpi_set_opaque_copy (NULL, pub->q_y, 8*sizeof (pub->q_y));
-  GNUNET_assert (q_y);
+  GNUNET_assert (NULL != q_y);
   GNUNET_assert (0 == gcry_mpi_ec_set_mpi ("q", q_y, ctx));
   gcry_mpi_release (q_y);
   q = gcry_mpi_ec_get_point ("q", ctx, 0);
@@ -1530,10 +1532,33 @@
   gcry_mpi_point_release (v);
   q_y = gcry_mpi_ec_get_mpi ("address@hidden", ctx, 0);
   GNUNET_assert (q_y);
-  GNUNET_CRYPTO_mpi_print_unsigned (result->q_y, sizeof result->q_y, q_y);
+  GNUNET_CRYPTO_mpi_print_unsigned (result->q_y,
+                                    sizeof (result->q_y),
+                                    q_y);
   gcry_mpi_release (q_y);
   gcry_ctx_release (ctx);
 }
 
 
+/**
+ * @ingroup crypto
+ * Convert ECDSA public key to ECDHE public key.
+ * Please be very careful when using this function, as mixing
+ * cryptographic primitives is not always healthy.
+ *
+ * @param ecdsa ecdsa public key
+ * @param ecdhe[OUT] ecdhe public key
+ */
+void
+GNUNET_CRYPTO_ecdsa_public_to_ecdhe (const struct GNUNET_CRYPTO_EcdsaPublicKey 
*ecdsa,
+                                     struct GNUNET_CRYPTO_EcdhePublicKey 
*ecdhe)
+{
+  GNUNET_assert (sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) ==
+                 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
+  memcpy (ecdhe,
+          ecdsa,
+          sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
+}
+
+
 /* end of crypto_ecc.c */

Modified: gnunet/src/util/crypto_mpi.c
===================================================================
--- gnunet/src/util/crypto_mpi.c        2015-03-18 23:45:34 UTC (rev 35405)
+++ gnunet/src/util/crypto_mpi.c        2015-03-19 13:12:47 UTC (rev 35406)
@@ -77,6 +77,7 @@
                                   gcry_mpi_t val)
 {
   size_t rsize;
+  int rc;
 
   if (gcry_mpi_get_flag (val, GCRYMPI_FLAG_OPAQUE))
   {
@@ -98,9 +99,17 @@
     /* Store regular MPIs as unsigned integers right aligned into
        the buffer.  */
     rsize = size;
-    GNUNET_assert (0 ==
-                   gcry_mpi_print (GCRYMPI_FMT_USG, buf, rsize, &rsize,
-                                   val));
+    if (0 !=
+        (rc = gcry_mpi_print (GCRYMPI_FMT_USG,
+                              buf,
+                              rsize, &rsize,
+                              val)))
+    {
+      LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+                "gcry_mpi_print",
+                rc);
+      GNUNET_assert (0);
+    }
     adjust (buf, rsize, size);
   }
 }
@@ -126,7 +135,9 @@
                                GCRYMPI_FMT_USG,
                                data, size, &size)))
   {
-    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
+    LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
+              "gcry_mpi_scan",
+              rc);
     GNUNET_assert (0);
   }
 }

Modified: gnunet/src/util/strings.c
===================================================================
--- gnunet/src/util/strings.c   2015-03-18 23:45:34 UTC (rev 35405)
+++ gnunet/src/util/strings.c   2015-03-19 13:12:47 UTC (rev 35406)
@@ -895,7 +895,7 @@
     out[wpos++] = encTable__[(bits >> (vbit - 5)) & 31];
     vbit -= 5;
   }
-  GNUNET_assert (vbit == 0);
+  GNUNET_assert (0 == vbit);
   if (wpos < out_size)
     out[wpos] = '\0';
   return &out[wpos];

Copied: gnunet/src/util/test_crypto_ecdh_ecdsa.c (from rev 35405, 
gnunet/src/util/test_crypto_ecdh_eddsa.c)
===================================================================
--- gnunet/src/util/test_crypto_ecdh_ecdsa.c                            (rev 0)
+++ gnunet/src/util/test_crypto_ecdh_ecdsa.c    2015-03-19 13:12:47 UTC (rev 
35406)
@@ -0,0 +1,141 @@
+/*
+     This file is part of GNUnet.
+     Copyright (C) 2002-2015 Christian Grothoff (and other contributing 
authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+
+*/
+/**
+ * @file util/test_crypto_ecdh_ecdsa.c
+ * @brief testcase for ECC DH key exchange with EdDSA private keys.
+ * @author Christian Grothoff
+ * @author Bart Polot
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include <gcrypt.h>
+
+
+static int
+test_pk()
+{
+  struct GNUNET_CRYPTO_EcdsaPrivateKey *priv1;
+  struct GNUNET_CRYPTO_EcdhePrivateKey priv2;
+  struct GNUNET_CRYPTO_EcdsaPublicKey pub1;
+  struct GNUNET_CRYPTO_EcdhePublicKey pub2;
+  struct GNUNET_CRYPTO_EcdhePublicKey pub1c;
+
+  /* Generate, cast keys */
+  priv1 = GNUNET_CRYPTO_ecdsa_key_create ();
+  memcpy (&priv2,
+          priv1,
+          sizeof (priv2));
+
+  /* Extract public keys */
+  GNUNET_CRYPTO_ecdsa_key_get_public (priv1, &pub1);
+  GNUNET_CRYPTO_ecdhe_key_get_public (&priv2, &pub2);
+
+  GNUNET_CRYPTO_ecdsa_public_to_ecdhe (&pub1, &pub1c);
+  if (0 == memcmp (&pub1c,
+                   &pub2,
+                   sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
+  {
+    GNUNET_free (priv1);
+    return 0;
+  }
+  GNUNET_free (priv1);
+  return 1;
+}
+
+
+static int
+test_ecdh()
+{
+  struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_dsa1;
+  struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_dsa2;
+  struct GNUNET_CRYPTO_EcdsaPublicKey id1;
+  struct GNUNET_CRYPTO_EcdsaPublicKey id2;
+  struct GNUNET_CRYPTO_EcdhePublicKey id1c;
+  struct GNUNET_CRYPTO_EcdhePublicKey id2c;
+
+  struct GNUNET_CRYPTO_EcdhePrivateKey *priv1;
+  struct GNUNET_CRYPTO_EcdhePrivateKey *priv2;
+  struct GNUNET_CRYPTO_EcdhePublicKey pub2;
+  struct GNUNET_HashCode dh[3];
+
+  /* Generate, cast keys */
+  priv_dsa1 = GNUNET_CRYPTO_ecdsa_key_create ();
+  priv_dsa2 = GNUNET_CRYPTO_ecdsa_key_create ();
+  priv1 = (struct GNUNET_CRYPTO_EcdhePrivateKey *) priv_dsa1;
+  priv2 = (struct GNUNET_CRYPTO_EcdhePrivateKey *) priv_dsa2;
+
+  /* Extract public keys */
+  GNUNET_CRYPTO_ecdsa_key_get_public (priv_dsa1, &id1);
+  GNUNET_CRYPTO_ecdsa_key_get_public (priv_dsa2, &id2);
+  GNUNET_CRYPTO_ecdhe_key_get_public (priv2, &pub2);
+
+  /* Do ECDH */
+  GNUNET_CRYPTO_ecdsa_public_to_ecdhe (&id2,
+                                       &id2c);
+  GNUNET_CRYPTO_ecdsa_public_to_ecdhe (&id1,
+                                       &id1c);
+  GNUNET_CRYPTO_ecc_ecdh (priv1,
+                          &id2c,
+                          &dh[0]);
+  GNUNET_CRYPTO_ecc_ecdh (priv2,
+                          &id1c,
+                          &dh[1]);
+  GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &dh[2]);
+
+  /* Check that both DH results are equal. */
+  GNUNET_assert (0 == memcmp (&dh[0], &dh[1],
+                             sizeof (struct GNUNET_HashCode)));
+
+  /* FIXME: Maybe it should be the same as with ECDHE. */
+  // GNUNET_assert (0 == memcmp (&dh[1], &dh[2],
+  //                            sizeof (struct GNUNET_HashCode)));
+  // GNUNET_assert (0 == memcmp (&id1, &pub1,
+  //                            sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)));
+
+  /* Free */
+  GNUNET_free (priv1);
+  GNUNET_free (priv2);
+  return 0;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+  if (! gcry_check_version ("1.6.0"))
+  {
+    FPRINTF (stderr,
+             _("libgcrypt has not the expected version (version %s is 
required).\n"),
+             "1.6.0");
+    return 0;
+  }
+  if (getenv ("GNUNET_GCRYPT_DEBUG"))
+    gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
+  GNUNET_log_setup ("test-crypto-ecdh-ecdsa", "WARNING", NULL);
+  if (0 != test_pk())
+    return 1;
+  if (0 != test_ecdh())
+    return 1;
+  return 0;
+}
+
+
+/* end of test_crypto_ecdh_ecdsa.c */

Deleted: gnunet/src/util/test_crypto_ecdh_eddsa.c
===================================================================
--- gnunet/src/util/test_crypto_ecdh_eddsa.c    2015-03-18 23:45:34 UTC (rev 
35405)
+++ gnunet/src/util/test_crypto_ecdh_eddsa.c    2015-03-19 13:12:47 UTC (rev 
35406)
@@ -1,88 +0,0 @@
-/*
-     This file is part of GNUnet.
-     Copyright (C) 2002-2015 Christian Grothoff (and other contributing 
authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-
-*/
-/**
- * @file util/test_crypto_ecdh_ecdsa.c
- * @brief testcase for ECC DH key exchange with EdDSA private keys.
- * @author Christian Grothoff, Bart Polot
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include <gcrypt.h>
-
-
-int
-main (int argc, char *argv[])
-{
-  struct GNUNET_CRYPTO_EddsaPrivateKey *priv_dsa1;
-  struct GNUNET_CRYPTO_EddsaPrivateKey *priv_dsa2;
-  struct GNUNET_CRYPTO_EddsaPublicKey id1;
-  struct GNUNET_CRYPTO_EddsaPublicKey id2;
-
-  struct GNUNET_CRYPTO_EcdhePrivateKey *priv1;
-  struct GNUNET_CRYPTO_EcdhePrivateKey *priv2;
-  struct GNUNET_CRYPTO_EcdhePublicKey pub2;
-  struct GNUNET_HashCode dh[3];
-
-  if (! gcry_check_version ("1.6.0"))
-  {
-    FPRINTF (stderr,
-             _
-             ("libgcrypt has not the expected version (version %s is 
required).\n"),
-             "1.6.0");
-    return 0;
-  }
-  if (getenv ("GNUNET_GCRYPT_DEBUG"))
-    gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
-  GNUNET_log_setup ("test-crypto-ecdh-eddsa", "WARNING", NULL);
-
-  /* Generate, cast keys */
-  priv_dsa1 = GNUNET_CRYPTO_eddsa_key_create ();
-  priv_dsa2 = GNUNET_CRYPTO_eddsa_key_create ();
-  priv1 = (struct GNUNET_CRYPTO_EcdhePrivateKey *) priv_dsa1;
-  priv2 = (struct GNUNET_CRYPTO_EcdhePrivateKey *) priv_dsa2;
-
-  /* Extract public keys */
-  GNUNET_CRYPTO_eddsa_key_get_public (priv_dsa1, &id1);
-  GNUNET_CRYPTO_eddsa_key_get_public (priv_dsa2, &id2);
-  GNUNET_CRYPTO_ecdhe_key_get_public (priv2, &pub2);
-
-  /* Do ECDH */
-  GNUNET_CRYPTO_ecc_ecdh (priv1, (struct GNUNET_CRYPTO_EcdhePublicKey *)&id2, 
&dh[0]);
-  GNUNET_CRYPTO_ecc_ecdh (priv2, (struct GNUNET_CRYPTO_EcdhePublicKey *)&id1, 
&dh[1]);
-  GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &dh[2]);
-
-  /* Check that both DH results are equal. */
-  GNUNET_assert (0 == memcmp (&dh[0], &dh[1],
-                             sizeof (struct GNUNET_HashCode)));
-
-  /* FIXME: Maybe it should be the same as with ECDHE. */
-  // GNUNET_assert (0 == memcmp (&dh[1], &dh[2],
-  //                            sizeof (struct GNUNET_HashCode)));
-  // GNUNET_assert (0 == memcmp (&id1, &pub1,
-  //                            sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)));
-
-  /* Free */
-  GNUNET_free (priv1);
-  GNUNET_free (priv2);
-  return 0;
-}
-
-/* end of test_crypto_ecdh_ecdsa.c */




reply via email to

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