2 This file is part of GNUnet.
3 Copyright (C) 2018 GNUnet e.V.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file util/crypto_bug.c
23 * @brief work around unidentified public key cryptography bug
24 * @author Christian Grothoff
28 * Enable work-around. Will cause code to call #check_eddsa_key() to
29 * see if we have a bad key, and if so, create a new one.
36 * Check if ECDH works with @a priv_dsa and this version
39 * @param priv_dsa key to check
40 * @return #GNUNET_OK if key passes
43 check_eddsa_key (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv_dsa)
45 struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ecdh;
46 struct GNUNET_CRYPTO_EddsaPublicKey id1;
47 struct GNUNET_CRYPTO_EcdhePublicKey id2;
48 struct GNUNET_HashCode dh[2];
50 GNUNET_CRYPTO_eddsa_key_get_public (priv_dsa,
52 for (unsigned int j=0;j<4;j++)
54 priv_ecdh = GNUNET_CRYPTO_ecdhe_key_create ();
55 /* Extract public keys */
56 GNUNET_CRYPTO_ecdhe_key_get_public (priv_ecdh,
59 GNUNET_assert (GNUNET_OK ==
60 GNUNET_CRYPTO_eddsa_ecdh (priv_dsa,
63 GNUNET_assert (GNUNET_OK ==
64 GNUNET_CRYPTO_ecdh_eddsa (priv_ecdh,
67 /* Check that both DH results are equal. */
68 if (0 != memcmp (&dh[0],
70 sizeof (struct GNUNET_HashCode)))
72 GNUNET_break (0); /* bad EdDSA key! */
75 GNUNET_free (priv_ecdh);