gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit 47a164b83ebd56bc13167a57bf38aeafe78d354b
parent f2d27a480dea985dc49f1b9fe7a57eb21ee18d42
Author: Florian Dold <florian.dold@gmail.com>
Date:   Tue,  7 Jan 2014 09:40:05 +0000

missing secretsharing_common.c

Diffstat:
Msrc/secretsharing/gnunet-service-secretsharing.c | 8++++++++
Asrc/secretsharing/secretsharing_common.c | 136+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 144 insertions(+), 0 deletions(-)

diff --git a/src/secretsharing/gnunet-service-secretsharing.c b/src/secretsharing/gnunet-service-secretsharing.c @@ -1020,6 +1020,10 @@ insert_round1_element (struct KeygenSession *ks) element->data = d; element->size = sizeof *d; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "alloc'd size %u\n", sizeof *element + sizeof *d); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "element size %u\n", element->size); + + d->peer = my_peer; GNUNET_assert (0 != (v = gcry_mpi_new (PAILLIER_BITS))); @@ -1032,6 +1036,8 @@ insert_round1_element (struct KeygenSession *ks) GNUNET_CRYPTO_hash (v_data, PAILLIER_BITS / 8, &d->commitment); + /* + GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, (unsigned char *) d->pubkey.g, PAILLIER_BITS / 8, NULL, ks->info[ks->local_peer_idx].paillier_g)); @@ -1040,6 +1046,8 @@ insert_round1_element (struct KeygenSession *ks) (unsigned char *) d->pubkey.n, PAILLIER_BITS / 8, NULL, ks->info[ks->local_peer_idx].paillier_n)); + */ + d->purpose.size = htonl ((sizeof *d) - offsetof (struct GNUNET_SECRETSHARING_KeygenCommitData, purpose)); d->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1); GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_peer_private_key, &d->purpose, &d->signature)); diff --git a/src/secretsharing/secretsharing_common.c b/src/secretsharing/secretsharing_common.c @@ -0,0 +1,136 @@ +/* + This file is part of GNUnet. + (C) 2014 Christian Grothoff (and other contributing authors) + + 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 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. + + 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., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "secretsharing.h" + +/** + * Read a share from its binary representation. + * + * @param data Binary representation of the share. + * @param len Length of @a data. + * @param[out] readlen Number of bytes read, + * ignored if NULL. + * @return The share, or NULL on error. + */ +struct GNUNET_SECRETSHARING_Share * +GNUNET_SECRETSHARING_share_read (const void *data, size_t len, size_t *readlen) +{ + struct GNUNET_SECRETSHARING_Share *share; + const struct GNUNET_SECRETSHARING_ShareHeaderNBO *sh = data; + char *p; + size_t n; + uint16_t payload_size; + + payload_size = ntohs (sh->num_peers) * + (sizeof (uint16_t) + sizeof (struct GNUNET_SECRETSHARING_FieldElement) + + sizeof (struct GNUNET_PeerIdentity)); + + if (NULL != readlen) + *readlen = payload_size + sizeof *sh; + + share = GNUNET_malloc (sizeof *share); + + share->threshold = ntohs (sh->threshold); + share->num_peers = ntohs (sh->num_peers); + share->my_peer = ntohs (sh->my_peer); + + share->my_share = sh->my_share; + share->public_key = sh->public_key; + + p = (void *) &sh[1]; + + n = share->num_peers * sizeof (struct GNUNET_PeerIdentity); + share->peers = GNUNET_malloc (n); + memcpy (share->peers, p, n); + p += n; + + n = share->num_peers * sizeof (struct GNUNET_SECRETSHARING_FieldElement); + share->hom_share_commitments = GNUNET_malloc (n); + memcpy (share->hom_share_commitments, p, n); + p += n; + + n = share->num_peers * sizeof (uint16_t); + share->original_indices = GNUNET_malloc (n); + memcpy (share->original_indices, p, n); + + return share; +} + + +/** + * Convert a share to its binary representation. + * Can be called with a NULL @a buf to get the size of the share. + * + * @param share Share to write. + * @param buf Buffer to write to. + * @param buflen Number of writable bytes in @a buf. + * @param[out] writelen Pointer to store number of bytes written, + * ignored if NULL. + * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure. + */ +int +GNUNET_SECRETSHARING_share_write (const struct GNUNET_SECRETSHARING_Share *share, + void *buf, size_t buflen, size_t *writelen) +{ + uint16_t payload_size; + struct GNUNET_SECRETSHARING_ShareHeaderNBO *sh; + char *p; + int n; + + payload_size = ntohs (sh->num_peers) * + (sizeof (uint16_t) + sizeof (struct GNUNET_SECRETSHARING_FieldElement) + + sizeof (struct GNUNET_PeerIdentity)); + + if (NULL != writelen) + *writelen = payload_size + sizeof (struct GNUNET_SECRETSHARING_ShareHeaderNBO); + + /* just a query for the writelen */ + if (buf == NULL) + return GNUNET_OK; + + /* wrong buffer size */ + if (buflen < payload_size + sizeof (struct GNUNET_SECRETSHARING_ShareHeaderNBO)) + return GNUNET_SYSERR; + + sh = buf; + + sh->threshold = htons (share->threshold); + sh->num_peers = htons (share->num_peers); + sh->my_peer = htons (share->my_peer); + + sh->my_share = share->my_share; + sh->public_key = share->public_key; + + p = (void *) &sh[1]; + + n = share->num_peers * sizeof (struct GNUNET_PeerIdentity); + memcpy (p, share->peers, n); + p += n; + + n = share->num_peers * sizeof (struct GNUNET_SECRETSHARING_FieldElement); + memcpy (p, share->hom_share_commitments, n); + p += n; + + n = share->num_peers * sizeof (uint16_t); + memcpy (p, share->original_indices, n); + + return GNUNET_OK; +} +