aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util/test_crypto_ecdh_eddsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/test_crypto_ecdh_eddsa.c')
-rw-r--r--src/lib/util/test_crypto_ecdh_eddsa.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/lib/util/test_crypto_ecdh_eddsa.c b/src/lib/util/test_crypto_ecdh_eddsa.c
new file mode 100644
index 000000000..875f479c2
--- /dev/null
+++ b/src/lib/util/test_crypto_ecdh_eddsa.c
@@ -0,0 +1,96 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2002-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
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
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include <gcrypt.h>
31
32
33static int
34test_ecdh ()
35{
36 struct GNUNET_CRYPTO_EddsaPrivateKey priv_dsa;
37 struct GNUNET_CRYPTO_EcdhePrivateKey priv_ecdh;
38 struct GNUNET_CRYPTO_EddsaPublicKey id1;
39 struct GNUNET_CRYPTO_EcdhePublicKey id2;
40 struct GNUNET_HashCode dh[2];
41
42 /* Generate keys */
43 GNUNET_CRYPTO_eddsa_key_create (&priv_dsa);
44 GNUNET_CRYPTO_eddsa_key_get_public (&priv_dsa,
45 &id1);
46 for (unsigned int j = 0; j < 4; j++)
47 {
48 fprintf (stderr, ",");
49 GNUNET_CRYPTO_ecdhe_key_create (&priv_ecdh);
50 /* Extract public keys */
51 GNUNET_CRYPTO_ecdhe_key_get_public (&priv_ecdh,
52 &id2);
53 /* Do ECDH */
54 GNUNET_assert (GNUNET_OK ==
55 GNUNET_CRYPTO_eddsa_ecdh (&priv_dsa,
56 &id2,
57 &dh[0]));
58 GNUNET_assert (GNUNET_OK ==
59 GNUNET_CRYPTO_ecdh_eddsa (&priv_ecdh,
60 &id1,
61 &dh[1]));
62 /* Check that both DH results are equal. */
63 GNUNET_assert (0 ==
64 GNUNET_memcmp (&dh[0],
65 &dh[1]));
66 }
67 return 0;
68}
69
70
71int
72main (int argc, char *argv[])
73{
74 if (! gcry_check_version ("1.6.0"))
75 {
76 fprintf (stderr,
77 _ (
78 "libgcrypt has not the expected version (version %s is required).\n"),
79 "1.6.0");
80 return 0;
81 }
82 if (getenv ("GNUNET_GCRYPT_DEBUG"))
83 gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
84 GNUNET_log_setup ("test-crypto-ecdh-eddsa", "WARNING", NULL);
85 for (unsigned int i = 0; i < 4; i++)
86 {
87 fprintf (stderr,
88 ".");
89 if (0 != test_ecdh ())
90 return 1;
91 }
92 return 0;
93}
94
95
96/* end of test_crypto_ecdh_eddsa.c */