diff options
Diffstat (limited to 'src/util/test_crypto_ecdh_eddsa.c')
-rw-r--r-- | src/util/test_crypto_ecdh_eddsa.c | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/src/util/test_crypto_ecdh_eddsa.c b/src/util/test_crypto_ecdh_eddsa.c index ec7819c3b..b7b1634e4 100644 --- a/src/util/test_crypto_ecdh_eddsa.c +++ b/src/util/test_crypto_ecdh_eddsa.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2002-2015 GNUnet e.V. | 3 | Copyright (C) 2002-2015 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | 17 | ||
20 | */ | 18 | */ |
21 | /** | 19 | /** |
@@ -36,30 +34,35 @@ test_ecdh() | |||
36 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh; | 34 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh; |
37 | struct GNUNET_CRYPTO_EddsaPublicKey id1; | 35 | struct GNUNET_CRYPTO_EddsaPublicKey id1; |
38 | struct GNUNET_CRYPTO_EcdhePublicKey id2; | 36 | struct GNUNET_CRYPTO_EcdhePublicKey id2; |
39 | struct GNUNET_HashCode dh[3]; | 37 | struct GNUNET_HashCode dh[2]; |
40 | 38 | ||
41 | /* Generate keys */ | 39 | /* Generate keys */ |
42 | priv_dsa = GNUNET_CRYPTO_eddsa_key_create (); | 40 | 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, | 41 | GNUNET_CRYPTO_eddsa_key_get_public (priv_dsa, |
46 | &id1); | 42 | &id1); |
47 | GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh, | 43 | for (unsigned int j=0;j<4;j++) |
48 | &id2); | 44 | { |
49 | /* Do ECDH */ | 45 | fprintf (stderr, ","); |
50 | GNUNET_assert (GNUNET_OK == | 46 | priv_ecdh = GNUNET_CRYPTO_ecdhe_key_create (); |
51 | GNUNET_CRYPTO_eddsa_ecdh (priv_dsa, | 47 | /* Extract public keys */ |
52 | &id2, | 48 | GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh, |
53 | &dh[0])); | 49 | &id2); |
54 | GNUNET_assert (GNUNET_OK == | 50 | /* Do ECDH */ |
55 | GNUNET_CRYPTO_ecdh_eddsa (priv_ecdh, | 51 | GNUNET_assert (GNUNET_OK == |
56 | &id1, | 52 | GNUNET_CRYPTO_eddsa_ecdh (priv_dsa, |
57 | &dh[1])); | 53 | &id2, |
58 | /* Check that both DH results are equal. */ | 54 | &dh[0])); |
59 | GNUNET_assert (0 == memcmp (&dh[0], &dh[1], | 55 | GNUNET_assert (GNUNET_OK == |
60 | sizeof (struct GNUNET_HashCode))); | 56 | GNUNET_CRYPTO_ecdh_eddsa (priv_ecdh, |
57 | &id1, | ||
58 | &dh[1])); | ||
59 | /* Check that both DH results are equal. */ | ||
60 | GNUNET_assert (0 == memcmp (&dh[0], | ||
61 | &dh[1], | ||
62 | sizeof (struct GNUNET_HashCode))); | ||
63 | GNUNET_free (priv_ecdh); | ||
64 | } | ||
61 | GNUNET_free (priv_dsa); | 65 | GNUNET_free (priv_dsa); |
62 | GNUNET_free (priv_ecdh); | ||
63 | return 0; | 66 | return 0; |
64 | } | 67 | } |
65 | 68 | ||
@@ -75,10 +78,15 @@ main (int argc, char *argv[]) | |||
75 | return 0; | 78 | return 0; |
76 | } | 79 | } |
77 | if (getenv ("GNUNET_GCRYPT_DEBUG")) | 80 | if (getenv ("GNUNET_GCRYPT_DEBUG")) |
78 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0); | 81 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); |
79 | GNUNET_log_setup ("test-crypto-ecdh-eddsa", "WARNING", NULL); | 82 | GNUNET_log_setup ("test-crypto-ecdh-eddsa", "WARNING", NULL); |
80 | if (0 != test_ecdh()) | 83 | for (unsigned int i=0;i<4;i++) |
81 | return 1; | 84 | { |
85 | fprintf (stderr, | ||
86 | "."); | ||
87 | if (0 != test_ecdh()) | ||
88 | return 1; | ||
89 | } | ||
82 | return 0; | 90 | return 0; |
83 | } | 91 | } |
84 | 92 | ||