diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-05-13 16:19:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-05-13 16:19:10 +0000 |
commit | 55d612a4f2b68911b472d10bb7efd50d8740fe6e (patch) | |
tree | 95adabb8bee4032937a6ab9f19ec758896caf94f /src/util/test_crypto_ecdh_eddsa.c | |
parent | 4725d59b468f1f30ba2910992333ca157682ce29 (diff) | |
download | gnunet-55d612a4f2b68911b472d10bb7efd50d8740fe6e.tar.gz gnunet-55d612a4f2b68911b472d10bb7efd50d8740fe6e.zip |
towards using EdDSA-ECDHE instead of ECDSA-ECDHE combined cryptosystem (API only)
Diffstat (limited to 'src/util/test_crypto_ecdh_eddsa.c')
-rw-r--r-- | src/util/test_crypto_ecdh_eddsa.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/util/test_crypto_ecdh_eddsa.c b/src/util/test_crypto_ecdh_eddsa.c new file mode 100644 index 000000000..6b9867b1e --- /dev/null +++ b/src/util/test_crypto_ecdh_eddsa.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2002-2015 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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. | ||
19 | |||
20 | */ | ||
21 | /** | ||
22 | * @file util/test_crypto_ecdh_eddsa.c | ||
23 | * @brief testcase for ECC DH key exchange with EdDSA private keys. | ||
24 | * @author Christian Grothoff | ||
25 | * @author Bart Polot | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include <gcrypt.h> | ||
30 | |||
31 | |||
32 | static int | ||
33 | test_ecdh() | ||
34 | { | ||
35 | struct GNUNET_CRYPTO_EddsaPrivateKey *priv_dsa; | ||
36 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh; | ||
37 | struct GNUNET_CRYPTO_EddsaPublicKey id1; | ||
38 | struct GNUNET_CRYPTO_EcdhePublicKey id2; | ||
39 | struct GNUNET_HashCode dh[3]; | ||
40 | |||
41 | /* Generate keys */ | ||
42 | priv_dsa = GNUNET_CRYPTO_eddsa_key_create (); | ||
43 | priv_ecdh = GNUNET_CRYPTO_ecdhe_key_create (); | ||
44 | /* Extract public keys */ | ||
45 | GNUNET_CRYPTO_eddsa_key_get_public (priv_dsa, | ||
46 | &id1); | ||
47 | GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh, | ||
48 | &id2); | ||
49 | /* Do ECDH */ | ||
50 | GNUNET_assert (GNUNET_OK == | ||
51 | GNUNET_CRYPTO_eddsa_ecdh (priv_dsa, | ||
52 | &id2, | ||
53 | &dh[0])); | ||
54 | GNUNET_assert (GNUNET_OK == | ||
55 | GNUNET_CRYPTO_ecdh_eddsa (priv_ecdh, | ||
56 | &id1, | ||
57 | &dh[1])); | ||
58 | /* Check that both DH results are equal. */ | ||
59 | GNUNET_assert (0 == memcmp (&dh[0], &dh[1], | ||
60 | sizeof (struct GNUNET_HashCode))); | ||
61 | GNUNET_free (priv_dsa); | ||
62 | GNUNET_free (priv_ecdh); | ||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | |||
67 | int | ||
68 | main (int argc, char *argv[]) | ||
69 | { | ||
70 | if (! gcry_check_version ("1.6.0")) | ||
71 | { | ||
72 | FPRINTF (stderr, | ||
73 | _("libgcrypt has not the expected version (version %s is required).\n"), | ||
74 | "1.6.0"); | ||
75 | return 0; | ||
76 | } | ||
77 | if (getenv ("GNUNET_GCRYPT_DEBUG")) | ||
78 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0); | ||
79 | GNUNET_log_setup ("test-crypto-ecdh-eddsa", "WARNING", NULL); | ||
80 | if (0 != test_ecdh()) | ||
81 | return 1; | ||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | |||
86 | /* end of test_crypto_ecdh_eddsa.c */ | ||