glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / util / test_crypto_ecdhe.c
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 */
16 /**
17  * @file util/test_crypto_ecdhe.c
18  * @brief testcase for ECC ECDHE public key crypto
19  * @author Christian Grothoff
20  */
21 #include "platform.h"
22 #include "gnunet_util_lib.h"
23 #include <gcrypt.h>
24
25
26 int
27 main (int argc, char *argv[])
28 {
29   struct GNUNET_CRYPTO_EcdhePrivateKey *priv1;
30   struct GNUNET_CRYPTO_EcdhePrivateKey *priv2;
31   struct GNUNET_CRYPTO_EcdhePublicKey pub1;
32   struct GNUNET_CRYPTO_EcdhePublicKey pub2;
33   struct GNUNET_HashCode ecdh1;
34   struct GNUNET_HashCode ecdh2;
35
36   if (! gcry_check_version ("1.6.0"))
37   {
38     FPRINTF (stderr,
39              _
40              ("libgcrypt has not the expected version (version %s is required).\n"),
41              "1.6.0");
42     return 0;
43   }
44   if (getenv ("GNUNET_GCRYPT_DEBUG"))
45     gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
46   GNUNET_log_setup ("test-crypto-ecdhe", "WARNING", NULL);
47
48   for (unsigned int i=0;i<100;i++)
49   {
50     fprintf (stderr,
51              ".");
52     priv1 = GNUNET_CRYPTO_ecdhe_key_create ();
53     priv2 = GNUNET_CRYPTO_ecdhe_key_create ();
54     GNUNET_CRYPTO_ecdhe_key_get_public (priv1, &pub1);
55     GNUNET_CRYPTO_ecdhe_key_get_public (priv2, &pub2);
56     GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &ecdh1);
57     GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &ecdh2);
58     GNUNET_assert (0 == memcmp (&ecdh1, &ecdh2,
59                                 sizeof (struct GNUNET_HashCode)));
60     GNUNET_free (priv1);
61     GNUNET_free (priv2);
62   }
63   return 0;
64 }
65
66 /* end of test_crypto_ecdhe.c */