aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util/test_crypto_ecdhe.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/test_crypto_ecdhe.c')
-rw-r--r--src/lib/util/test_crypto_ecdhe.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/lib/util/test_crypto_ecdhe.c b/src/lib/util/test_crypto_ecdhe.c
new file mode 100644
index 000000000..cf59cfa64
--- /dev/null
+++ b/src/lib/util/test_crypto_ecdhe.c
@@ -0,0 +1,71 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2002-2013 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_ecdhe.c
23 * @brief testcase for ECC ECDHE public key crypto
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include <gcrypt.h>
30
31
32int
33main (int argc, char *argv[])
34{
35 struct GNUNET_CRYPTO_EcdhePrivateKey priv1;
36 struct GNUNET_CRYPTO_EcdhePrivateKey priv2;
37 struct GNUNET_CRYPTO_EcdhePublicKey pub1;
38 struct GNUNET_CRYPTO_EcdhePublicKey pub2;
39 struct GNUNET_HashCode ecdh1;
40 struct GNUNET_HashCode ecdh2;
41
42 if (! gcry_check_version ("1.6.0"))
43 {
44 fprintf (stderr,
45 "libgcrypt has not the expected version (version %s is required).\n",
46 "1.6.0");
47 return 0;
48 }
49 if (getenv ("GNUNET_GCRYPT_DEBUG"))
50 gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
51 GNUNET_log_setup ("test-crypto-ecdhe", "WARNING", NULL);
52
53 for (unsigned int i = 0; i < 100; i++)
54 {
55 fprintf (stderr,
56 ".");
57 GNUNET_CRYPTO_ecdhe_key_create (&priv1);
58 GNUNET_CRYPTO_ecdhe_key_create (&priv2);
59 GNUNET_CRYPTO_ecdhe_key_get_public (&priv1, &pub1);
60 GNUNET_CRYPTO_ecdhe_key_get_public (&priv2, &pub2);
61 GNUNET_CRYPTO_ecc_ecdh (&priv1, &pub2, &ecdh1);
62 GNUNET_CRYPTO_ecc_ecdh (&priv2, &pub1, &ecdh2);
63 GNUNET_assert (0 ==
64 GNUNET_memcmp (&ecdh1,
65 &ecdh2));
66 }
67 return 0;
68}
69
70
71/* end of test_crypto_ecdhe.c */