/*
This file is part of GNUnet.
Copyright (C) 2013, 2014, 2016 GNUnet e.V.
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
Affero General Public License for more details.
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/>.
*/
/**
* @file scalarproduct/gnunet-service-scalarproduct_bob.c
* @brief scalarproduct service implementation
* @author Christian M. Fuchs
* @author Christian Grothoff
*/
#include "platform.h"
#include <limits.h>
#include <gcrypt.h>
#include "gnunet_util_lib.h"
#include "gnunet_core_service.h"
#include "gnunet_cadet_service.h"
#include "gnunet_applications.h"
#include "gnunet_protocols.h"
#include "gnunet_scalarproduct_service.h"
#include "gnunet_set_service.h"
#include "scalarproduct.h"
#include "gnunet-service-scalarproduct.h"
#define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-bob", __VA_ARGS__)
/**
* An encrypted element key-value pair.
*/
struct MpiElement
{
/**
* Key used to identify matching pairs of values to multiply.
* Points into an existing data structure, to avoid copying
* and doubling memory use.
*/
const struct GNUNET_HashCode *key;
/**
* Value represented (a).
*/
gcry_mpi_t value;
};
/**
* A scalarproduct session which tracks an offer for a
* multiplication service by a local client.
*/
struct BobServiceSession
{
/**
* (hopefully) unique transaction ID
*/
struct GNUNET_HashCode session_id;
/**
* The client this request is related to.
*/
struct GNUNET_SERVICE_Client *client;
/**
* Client message queue.
*/
struct GNUNET_MQ_Handle *client_mq;
/**
* All non-0-value'd elements transmitted to us.
*/
struct GNUNET_CONTAINER_MultiHashMap *intersected_elements;
/**
* Set of elements for which we will be conducting an intersection.
* The resulting elements are then used for computing the scalar product.
*/
struct GNUNET_SET_Handle *intersection_set;
/**
* Set of elements for which will conduction an intersection.
* the resulting elements are then used for computing the scalar product.
*/
struct GNUNET_SET_OperationHandle *intersection_op;
/**
* CADET port we are listening on.
*/
struct GNUNET_CADET_Port *port;
/**
* a(Alice)
*/
struct MpiElement *sorted_elements;
/**
* E(ai)(Bob) after applying the mask
*/
struct GNUNET_CRYPTO_PaillierCiphertext *e_a;
/**
* Bob's permutation p of R
*/
struct GNUNET_CRYPTO_PaillierCiphertext *r;
/**
* Bob's permutation q of R
*/
struct GNUNET_CRYPTO_PaillierCiphertext *r_prime;
/**
* Bob's "s"
*/
struct GNUNET_CRYPTO_PaillierCiphertext s;
/**
* Bob's "s'"
*/
struct GNUNET_CRYPTO_PaillierCiphertext s_prime;
/**
* Handle for our associated incoming CADET session, or NULL
* if we have not gotten one yet.
*/
struct CadetIncomingSession *cadet