diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/util/Makefile.am | 8 | ||||
-rw-r--r-- | src/util/test_crypto_ecdh_ecdsa.c | 97 |
2 files changed, 105 insertions, 0 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 0f6251f96..387f22a9f 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -298,6 +298,7 @@ check_PROGRAMS = \ | |||
298 | test_crypto_eddsa \ | 298 | test_crypto_eddsa \ |
299 | test_crypto_ecdhe \ | 299 | test_crypto_ecdhe \ |
300 | test_crypto_ecdh_eddsa \ | 300 | test_crypto_ecdh_eddsa \ |
301 | test_crypto_ecdh_ecdsa \ | ||
301 | test_crypto_ecc_dlog \ | 302 | test_crypto_ecc_dlog \ |
302 | test_crypto_hash \ | 303 | test_crypto_hash \ |
303 | test_crypto_hash_context \ | 304 | test_crypto_hash_context \ |
@@ -476,6 +477,13 @@ test_crypto_ecdh_eddsa_LDADD = \ | |||
476 | libgnunetutil.la \ | 477 | libgnunetutil.la \ |
477 | $(LIBGCRYPT_LIBS) | 478 | $(LIBGCRYPT_LIBS) |
478 | 479 | ||
480 | test_crypto_ecdh_ecdsa_SOURCES = \ | ||
481 | test_crypto_ecdh_ecdsa.c | ||
482 | test_crypto_ecdh_ecdsa_LDADD = \ | ||
483 | libgnunetutil.la \ | ||
484 | $(LIBGCRYPT_LIBS) | ||
485 | |||
486 | |||
479 | test_crypto_hash_SOURCES = \ | 487 | test_crypto_hash_SOURCES = \ |
480 | test_crypto_hash.c | 488 | test_crypto_hash.c |
481 | test_crypto_hash_LDADD = \ | 489 | test_crypto_hash_LDADD = \ |
diff --git a/src/util/test_crypto_ecdh_ecdsa.c b/src/util/test_crypto_ecdh_ecdsa.c new file mode 100644 index 000000000..8a581ef73 --- /dev/null +++ b/src/util/test_crypto_ecdh_ecdsa.c | |||
@@ -0,0 +1,97 @@ | |||
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_ecdsa.c | ||
23 | * @brief testcase for ECC DH key exchange with ECDSA 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_EcdsaPrivateKey *priv_dsa; | ||
36 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh; | ||
37 | struct GNUNET_CRYPTO_EcdsaPublicKey id1; | ||
38 | struct GNUNET_CRYPTO_EcdhePublicKey id2; | ||
39 | struct GNUNET_HashCode dh[2]; | ||
40 | |||
41 | /* Generate keys */ | ||
42 | priv_dsa = GNUNET_CRYPTO_ecdsa_key_create (); | ||
43 | GNUNET_CRYPTO_ecdsa_key_get_public (priv_dsa, | ||
44 | &id1); | ||
45 | for (unsigned int j = 0; j < 4; j++) | ||
46 | { | ||
47 | fprintf (stderr, ","); | ||
48 | priv_ecdh = GNUNET_CRYPTO_ecdhe_key_create (); | ||
49 | /* Extract public keys */ | ||
50 | GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh, | ||
51 | &id2); | ||
52 | /* Do ECDH */ | ||
53 | GNUNET_assert (GNUNET_OK == | ||
54 | GNUNET_CRYPTO_ecdsa_ecdh (priv_dsa, | ||
55 | &id2, | ||
56 | &dh[0])); | ||
57 | GNUNET_assert (GNUNET_OK == | ||
58 | GNUNET_CRYPTO_ecdh_ecdsa (priv_ecdh, | ||
59 | &id1, | ||
60 | &dh[1])); | ||
61 | /* Check that both DH results are equal. */ | ||
62 | GNUNET_assert (0 == memcmp (&dh[0], | ||
63 | &dh[1], | ||
64 | sizeof(struct GNUNET_HashCode))); | ||
65 | GNUNET_free (priv_ecdh); | ||
66 | } | ||
67 | GNUNET_free (priv_dsa); | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | |||
72 | int | ||
73 | main (int argc, char *argv[]) | ||
74 | { | ||
75 | if (! gcry_check_version ("1.6.0")) | ||
76 | { | ||
77 | fprintf (stderr, | ||
78 | _ ( | ||
79 | "libgcrypt has not the expected version (version %s is required).\n"), | ||
80 | "1.6.0"); | ||
81 | return 0; | ||
82 | } | ||
83 | if (getenv ("GNUNET_GCRYPT_DEBUG")) | ||
84 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); | ||
85 | GNUNET_log_setup ("test-crypto-ecdh-ecdsa", "WARNING", NULL); | ||
86 | for (unsigned int i = 0; i < 4; i++) | ||
87 | { | ||
88 | fprintf (stderr, | ||
89 | "."); | ||
90 | if (0 != test_ecdh ()) | ||
91 | return 1; | ||
92 | } | ||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | |||
97 | /* end of test_crypto_ecdh_ecdsa.c */ | ||