This file is part of GNUnet.
Copyright (C) 2013 GNUnet e.V.
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ Affero General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
struct GNUNET_CRYPTO_PaillierPublicKey paillier_public_key;
/**
- * The peer's commitment to his presecret.
+ * The peer's commitment to its presecret.
*/
gcry_mpi_t presecret_commitment;
{
unsigned int i;
for (i = 0; i < ks->num_peers; i++)
- if (0 == memcmp (peer, &ks->info[i].peer, sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == GNUNET_memcmp (peer, &ks->info[i].peer))
return &ks->info[i];
return NULL;
}
{
unsigned int i;
for (i = 0; i < ds->share->num_peers; i++)
- if (0 == memcmp (peer, &ds->info[i].peer, sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == GNUNET_memcmp (peer, &ds->info[i].peer))
return &ds->info[i];
return NULL;
}
unsigned int i;
for (i = 0; i < n; i++)
- if (0 == memcmp (&haystack[i],
- needle,
- sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == GNUNET_memcmp (&haystack[i],
+ needle))
return i;
return -1;
}
if (element->size != sizeof (struct GNUNET_SECRETSHARING_KeygenCommitData))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "keygen commit data with wrong size (%u) in consensus, "
- " %u expected\n",
- element->size, sizeof (struct GNUNET_SECRETSHARING_KeygenCommitData));
+ "keygen commit data with wrong size (%u) in consensus, %u expected\n",
+ (unsigned int) element->size,
+ (unsigned int) sizeof (struct GNUNET_SECRETSHARING_KeygenCommitData));
return;
}
GNUNET_SECRETSHARING_ELGAMAL_BITS / 8,
ks->info[i].sigma);
share->original_indices[i] = j;
- if (0 == memcmp (&share->peers[i], &my_peer, sizeof (struct GNUNET_PeerIdentity)))
+ if (0 == GNUNET_memcmp (&share->peers[i], &my_peer))
share->my_peer = j;
j += 1;
}
GNUNET_assert (NULL != (big_b = gcry_mpi_new (0)));
// a = (N,0)^T
- GNUNET_CRYPTO_mpi_scan_unsigned (&a_1, ppub, sizeof (struct GNUNET_CRYPTO_PaillierPublicKey));
+ GNUNET_CRYPTO_mpi_scan_unsigned (&a_1,
+ ppub,
+ sizeof (struct GNUNET_CRYPTO_PaillierPublicKey));
GNUNET_assert (NULL != (a_2 = gcry_mpi_new (0)));
gcry_mpi_set_ui (a_2, 0);
// b = (x,1)^T
gcry_mpi_set (big_b, big_t);
}
- {
- gcry_mpi_t paillier_n;
-
- GNUNET_CRYPTO_mpi_scan_unsigned (&paillier_n, ppub, sizeof (struct GNUNET_CRYPTO_PaillierPublicKey));
-
- gcry_mpi_set (xres, b_2);
- gcry_mpi_invm (xres, xres, elgamal_q);
- gcry_mpi_mulm (xres, xres, b_1, elgamal_q);
- }
+ gcry_mpi_set (xres, b_2);
+ gcry_mpi_invm (xres, xres, elgamal_q);
+ gcry_mpi_mulm (xres, xres, b_1, elgamal_q);
gcry_mpi_release (a_1);
gcry_mpi_release (a_2);
static void
-get_fair_encryption_challenge (const struct GNUNET_SECRETSHARING_FairEncryption *fe, gcry_mpi_t e)
+get_fair_encryption_challenge (const struct GNUNET_SECRETSHARING_FairEncryption *fe,
+ gcry_mpi_t *e)
{
struct {
struct GNUNET_CRYPTO_PaillierCiphertext c;
} hash_data;
struct GNUNET_HashCode e_hash;
+ memset (&hash_data,
+ 0,
+ sizeof (hash_data));
GNUNET_memcpy (&hash_data.c, &fe->c, sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
GNUNET_memcpy (&hash_data.h, &fe->h, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8);
GNUNET_memcpy (&hash_data.t1, &fe->t1, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8);
GNUNET_memcpy (&hash_data.t2, &fe->t2, GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8);
-
- GNUNET_CRYPTO_mpi_scan_unsigned (&e, &e_hash, sizeof (struct GNUNET_HashCode));
- gcry_mpi_mod (e, e, elgamal_q);
+ GNUNET_CRYPTO_hash (&hash_data,
+ sizeof (hash_data),
+ &e_hash);
+ /* This allocates "e" */
+ GNUNET_CRYPTO_mpi_scan_unsigned (e,
+ &e_hash,
+ sizeof (struct GNUNET_HashCode));
+ gcry_mpi_mod (*e, *e, elgamal_q);
}
static int
-verify_fair (const struct GNUNET_CRYPTO_PaillierPublicKey *ppub, const struct GNUNET_SECRETSHARING_FairEncryption *fe)
+verify_fair (const struct GNUNET_CRYPTO_PaillierPublicKey *ppub,
+ const struct GNUNET_SECRETSHARING_FairEncryption *fe)
{
gcry_mpi_t n;
gcry_mpi_t n_sq;
GNUNET_assert (NULL != (n_sq = gcry_mpi_new (0)));
GNUNET_assert (NULL != (tmp1 = gcry_mpi_new (0)));
GNUNET_assert (NULL != (tmp2 = gcry_mpi_new (0)));
- GNUNET_assert (NULL != (e = gcry_mpi_new (0)));
- get_fair_encryption_challenge (fe, e);
+ get_fair_encryption_challenge (fe,
+ &e /* this allocates e */);
- GNUNET_CRYPTO_mpi_scan_unsigned (&n, ppub, sizeof (struct GNUNET_CRYPTO_PaillierPublicKey));
+ GNUNET_CRYPTO_mpi_scan_unsigned (&n,
+ ppub,
+ sizeof (struct GNUNET_CRYPTO_PaillierPublicKey));
GNUNET_CRYPTO_mpi_scan_unsigned (&t1, fe->t1, GNUNET_CRYPTO_PAILLIER_BITS / 8);
GNUNET_CRYPTO_mpi_scan_unsigned (&z, fe->z, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8);
GNUNET_CRYPTO_mpi_scan_unsigned (&y, fe->h, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8);
* @param[out] fe the fair encryption
*/
static void
-encrypt_fair (gcry_mpi_t v, const struct GNUNET_CRYPTO_PaillierPublicKey *ppub, struct GNUNET_SECRETSHARING_FairEncryption *fe)
+encrypt_fair (gcry_mpi_t v,
+ const struct GNUNET_CRYPTO_PaillierPublicKey *ppub,
+ struct GNUNET_SECRETSHARING_FairEncryption *fe)
{
gcry_mpi_t r;
gcry_mpi_t s;
gcry_mpi_t Y;
gcry_mpi_t G;
gcry_mpi_t h;
+
GNUNET_assert (NULL != (r = gcry_mpi_new (0)));
GNUNET_assert (NULL != (s = gcry_mpi_new (0)));
GNUNET_assert (NULL != (t1 = gcry_mpi_new (0)));
GNUNET_assert (NULL != (z = gcry_mpi_new (0)));
GNUNET_assert (NULL != (w = gcry_mpi_new (0)));
GNUNET_assert (NULL != (n_sq = gcry_mpi_new (0)));
- GNUNET_assert (NULL != (e = gcry_mpi_new (0)));
GNUNET_assert (NULL != (u = gcry_mpi_new (0)));
GNUNET_assert (NULL != (Y = gcry_mpi_new (0)));
GNUNET_assert (NULL != (G = gcry_mpi_new (0)));
GNUNET_assert (NULL != (h = gcry_mpi_new (0)));
- GNUNET_CRYPTO_mpi_scan_unsigned (&n, ppub, sizeof (struct GNUNET_CRYPTO_PaillierPublicKey));
+ GNUNET_CRYPTO_mpi_scan_unsigned (&n,
+ ppub,
+ sizeof (struct GNUNET_CRYPTO_PaillierPublicKey));
gcry_mpi_mul (n_sq, n, n);
gcry_mpi_add_ui (G, n, 1);
GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8,
t2);
-
- get_fair_encryption_challenge (fe, e);
+ get_fair_encryption_challenge (fe,
+ &e /* This allocates "e" */);
// compute z
gcry_mpi_mul (z, e, v);
return;
}
- if (0 != memcmp (&d->ciphertext, &session->ciphertext, sizeof (struct GNUNET_SECRETSHARING_Ciphertext)))
+ if (0 != GNUNET_memcmp (&d->ciphertext, &session->ciphertext))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "P%u: got decrypt element with non-matching ciphertext from P%u\n",
(unsigned int) session->share->my_peer, (unsigned int) (info - session->info));