2 This file is part of GNUnet.
3 Copyright (C) 2002-2015 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file util/test_crypto_ecdh_ecdsa.c
23 * @brief testcase for ECC DH key exchange with EdDSA private keys.
24 * @author Christian Grothoff
28 #include "gnunet_util_lib.h"
35 struct GNUNET_CRYPTO_EcdsaPrivateKey *priv1;
36 struct GNUNET_CRYPTO_EcdhePrivateKey priv2;
37 struct GNUNET_CRYPTO_EcdsaPublicKey pub1;
38 struct GNUNET_CRYPTO_EcdhePublicKey pub2;
39 struct GNUNET_CRYPTO_EcdhePublicKey pub1c;
41 /* Generate, cast keys */
42 priv1 = GNUNET_CRYPTO_ecdsa_key_create ();
43 GNUNET_CRYPTO_ecdsa_private_to_ecdhe (priv1,
45 /* Extract public keys */
46 GNUNET_CRYPTO_ecdsa_key_get_public (priv1, &pub1);
47 GNUNET_CRYPTO_ecdhe_key_get_public (&priv2, &pub2);
49 GNUNET_CRYPTO_ecdsa_public_to_ecdhe (&pub1, &pub1c);
50 if (0 == memcmp (&pub1c,
52 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
65 struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_dsa1;
66 struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_dsa2;
67 struct GNUNET_CRYPTO_EcdsaPublicKey id1;
68 struct GNUNET_CRYPTO_EcdsaPublicKey id2;
69 struct GNUNET_CRYPTO_EcdhePublicKey id1c;
70 struct GNUNET_CRYPTO_EcdhePublicKey id2c;
72 struct GNUNET_CRYPTO_EcdhePrivateKey priv1;
73 struct GNUNET_CRYPTO_EcdhePrivateKey priv2;
74 struct GNUNET_CRYPTO_EcdhePublicKey pub2;
75 struct GNUNET_HashCode dh[3];
77 /* Generate, cast keys */
78 priv_dsa1 = GNUNET_CRYPTO_ecdsa_key_create ();
79 priv_dsa2 = GNUNET_CRYPTO_ecdsa_key_create ();
80 GNUNET_CRYPTO_ecdsa_private_to_ecdhe (priv_dsa1,
83 GNUNET_CRYPTO_ecdsa_private_to_ecdhe (priv_dsa2,
85 /* Extract public keys */
86 GNUNET_CRYPTO_ecdsa_key_get_public (priv_dsa1, &id1);
87 GNUNET_CRYPTO_ecdsa_key_get_public (priv_dsa2, &id2);
88 GNUNET_CRYPTO_ecdhe_key_get_public (&priv2, &pub2);
91 GNUNET_CRYPTO_ecdsa_public_to_ecdhe (&id2,
93 GNUNET_CRYPTO_ecdsa_public_to_ecdhe (&id1,
95 GNUNET_CRYPTO_ecc_ecdh (&priv1,
98 GNUNET_CRYPTO_ecc_ecdh (&priv2,
101 GNUNET_CRYPTO_ecc_ecdh (&priv1, &pub2, &dh[2]);
103 /* Check that both DH results are equal. */
104 GNUNET_assert (0 == memcmp (&dh[0], &dh[1],
105 sizeof (struct GNUNET_HashCode)));
106 GNUNET_free (priv_dsa1);
107 GNUNET_free (priv_dsa2);
113 main (int argc, char *argv[])
115 if (! gcry_check_version ("1.6.0"))
118 _("libgcrypt has not the expected version (version %s is required).\n"),
122 if (getenv ("GNUNET_GCRYPT_DEBUG"))
123 gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
124 GNUNET_log_setup ("test-crypto-ecdh-ecdsa", "WARNING", NULL);
127 if (0 != test_ecdh())
133 /* end of test_crypto_ecdh_ecdsa.c */