39 #define LOG(kind, ...) \ 40 GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) 47 #define MAX_RESULT (1024 * 1024) 55 #define MAX_RAM (1024) 305 "Sending session-end notification with status %d to client for session %s\n",
326 unsigned char *product_exported = NULL;
327 size_t product_length = 0;
339 value = gcry_mpi_new (0);
340 sign = gcry_mpi_cmp_ui (s->
product, 0);
344 gcry_mpi_sub (value, value, s->
product);
349 gcry_mpi_add (value, value, s->
product);
359 if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD,
368 gcry_mpi_release (value);
373 msg->
range = htonl (range);
375 if (NULL != product_exported)
382 "Sent result to client, session %s has ended!\n",
402 "Peer disconnected, terminating session %s with peer %s\n",
425 gcry_mpi_point_t prod_g_i_b_i,
426 gcry_mpi_point_t prod_h_i_b_i)
428 gcry_mpi_point_t g_i_b_i_a_inv;
429 gcry_mpi_point_t g_ai_bi;
436 gcry_mpi_point_release (g_i_b_i_a_inv);
438 gcry_mpi_point_release (g_ai_bi);
443 "Scalar product result out of range\n");
446 ret = gcry_mpi_new (0);
449 gcry_mpi_set_ui (ret, ai_bi);
453 gcry_mpi_set_ui (ret, -ai_bi);
454 gcry_mpi_neg (ret, ret);
472 gcry_mpi_point_t prod_g_i_b_i;
473 gcry_mpi_point_t prod_h_i_b_i;
499 "Received %u crypto values from Bob\n",
500 (
unsigned int) contained);
505 gcry_mpi_point_release (prod_g_i_b_i);
506 gcry_mpi_point_release (prod_h_i_b_i);
527 mval = gcry_mpi_new (0);
530 gcry_mpi_sub_ui (mval, mval, -val);
532 gcry_mpi_add_ui (mval, mval, val);
561 #define ELEMENT_CAPACITY \ 562 ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 \ 563 - sizeof(struct EccAliceCryptodataMessage)) \ 564 / sizeof(struct GNUNET_CRYPTO_EccPoint)) 583 unsigned int todo_count;
593 "Finished intersection, %d items remain\n",
600 while (off < s->used_element_count)
606 "Sending %u/%u crypto values to Bob\n",
607 (
unsigned int) todo_count,
617 r_ia = gcry_mpi_new (0);
618 r_ia_ai = gcry_mpi_new (0);
619 for (i = off; i < off + todo_count; i++)
622 gcry_mpi_point_t g_i;
623 gcry_mpi_point_t h_i;
629 gcry_mpi_release (r_i);
635 gcry_mpi_point_release (g_i);
636 gcry_mpi_point_release (h_i);
638 gcry_mpi_release (r_ia);
639 gcry_mpi_release (r_ia_ai);
659 uint64_t current_size,
673 "Intersection removed element with key %s and value %lld\n",
741 "Received intersection request from %s!\n",
792 "Creating new channel for session with key %s.\n",
844 uint32_t contained_count;
852 (0 == contained_count) ||
876 uint32_t contained_count;
884 for (uint32_t i = 0; i < contained_count; i++)
901 set_elem.
size =
sizeof(elem->
key);
911 "Received client multipart data, waiting for more!\n");
933 uint32_t total_count;
934 uint32_t contained_count;
946 if ((0 == total_count) || (0 == contained_count) ||
970 uint32_t contained_count;
971 uint32_t total_count;
980 s->
total = total_count;
987 for (uint32_t i = 0; i < contained_count; i++)
1007 set_elem.
size =
sizeof(elem->
key);
1017 "Received partial client request, waiting for more!\n");
1036 if (NULL != my_cadet)
1091 "Client %p disconnected from us.\n",
1116 if (NULL == my_cadet)
1130 "scalarproduct-alice",
1141 alice_client_message_multipart,
uint32_t contained_element_count
How many elements we appended to this message? In NBO.
We encountered some error.
GNUNET_SERVICE_MAIN("scalarproduct-alice", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(alice_client_message, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, struct AliceComputationMessage, NULL), GNUNET_MQ_hd_var_size(alice_client_message_multipart, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, struct ComputationBobCryptodataMultipartMessage, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
A scalarproduct session which tracks a request form the client to our final response.
struct GNUNET_CRYPTO_EccPoint prod_g_i_b_i
The product of the g_i^{b_i} values.
Message type passed from service client to finalize a session as requester or responder.
struct GNUNET_HashCode session_id
The transaction/session key used to identify a session.
static void cb_intersection_element_removed(void *cls, const struct GNUNET_SETI_Element *element, uint64_t current_size, enum GNUNET_SETI_Status status)
Callback for set operation results.
int in_destroy
Flag to prevent recursive calls to destroy_service_session() from doing harm.
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Vector of ECC-encrypted values sent by Alice to Bob (after set intersection).
struct GNUNET_SETI_Handle * intersection_set
Set of elements for which will conduction an intersection.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
Point on a curve (always for Curve25519) encoded in a format suitable for network transmission (ECDH)...
Success, all elements have been sent (and received).
gcry_mpi_point_t GNUNET_CRYPTO_ecc_bin_to_point(struct GNUNET_CRYPTO_EccDlogContext *edc, const struct GNUNET_CRYPTO_EccPoint *bin)
Convert binary representation of a point to computational representation.
struct GNUNET_MessageHeader * msg
void GNUNET_CRYPTO_ecc_rnd_mpi(struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_t *r, gcry_mpi_t *r_inv)
Obtain a random scalar for point multiplication on the curve and its multiplicative inverse...
int GNUNET_SETI_add_element(struct GNUNET_SETI_Handle *set, const struct GNUNET_SETI_Element *element, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Add an element to the given set.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
struct GNUNET_CADET_Channel * channel
channel-handle associated with our cadet handle
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE
Client -> Alice multipart.
struct GNUNET_MQ_Handle * cadet_mq
The message queue for CADET.
The other peer refused to do the operation with us, or something went wrong.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
static void handle_alice_client_message(void *cls, const struct AliceComputationMessage *msg)
Handler for Alice's client request message.
Opaque handle to the service.
gcry_mpi_t GNUNET_CRYPTO_ecc_random_mod_n(struct GNUNET_CRYPTO_EccDlogContext *edc)
Generate a random value mod n.
scalarproduct service P2P messages
static const struct GNUNET_CONFIGURATION_Handle * cfg
GNUnet configuration handle.
uint16_t size
Number of bytes in the buffer pointed to by data.
const struct GNUNET_HashCode * key
Key used to identify matching pairs of values to multiply.
Operation is still active (never returned, used internally).
int GNUNET_SETI_commit(struct GNUNET_SETI_OperationHandle *oh, struct GNUNET_SETI_Handle *set)
Commit a set to be used with a set operation.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
struct GNUNET_HashCode key
Key used to identify matching pairs of values to multiply.
struct GNUNET_SETI_ListenHandle * intersection_listen
Handle to Alice's Intersection operation listening for Bob.
static int copy_element_cb(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator to copy over messages from the hash map into an array for sorting.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA
Alice -> Bob ECC crypto data.
Option for set operations.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int32_t range
Workaround for libgcrypt: -1 if negative, 0 if zero, else 1.
#define LOG_GCRY(level, cmd, rc)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
void GNUNET_MQ_env_set_options(struct GNUNET_MQ_Envelope *env, enum GNUNET_MQ_PriorityPreferences pp)
Set application-specific options for this envelope.
struct GNUNET_MessageHeader header
GNUNET message header with type GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE.
static void send_alices_cryptodata_message(struct AliceServiceSession *s)
Send the cryptographic data from Alice to Bob.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
static struct GNUNET_CADET_Handle * my_cadet
Handle to the CADET service.
static int ret
Return value of the commandline.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
static struct Experiment * e
static struct GNUNET_HashCode session_id
Opaque handle to a channel.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static void shutdown_task(void *cls)
Task run during shutdown.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void cb_intersection_request_alice(void *cls, const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_MessageHeader *context_msg, struct GNUNET_SETI_Request *request)
Called when another peer wants to do a set operation with the local peer.
enum GNUNET_SCALARPRODUCT_ResponseStatus status
State of this session.
struct GNUNET_CRYPTO_EccDlogContext * GNUNET_CRYPTO_ecc_dlog_prepare(unsigned int max, unsigned int mem)
Do pre-calculation for ECC discrete logarithm for small factors.
gcry_mpi_t value
a_i value, not disclosed to Bob.
void GNUNET_CRYPTO_ecc_point_to_bin(struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_point_t point, struct GNUNET_CRYPTO_EccPoint *bin)
Convert point value to binary representation.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
struct GNUNET_SETI_ListenHandle * GNUNET_SETI_listen(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HashCode *app_id, GNUNET_SETI_ListenCallback listen_cb, void *listen_cls)
Wait for set operation requests for the given application ID.
Opaque handle to a listen operation.
Internal representation of the hash map.
Handle for a set operation request from another peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void handle_bobs_cryptodata_message(void *cls, const struct EccBobCryptodataMessage *msg)
Handle a response we got from another service we wanted to calculate a scalarproduct with...
uint32_t total
How many elements we were supplied with from the client (total count before intersection).
Message type passed from client to service to initiate a request or responder role.
struct GNUNET_HashCode session_key
the transaction/session key used to identify a session
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
Handle to a client that is connected to a service.
static void transmit_client_response(struct AliceServiceSession *s)
Prepare the final (positive) response we will send to Alice's client.
uint32_t status
Status information about the outcome of this session, An enum GNUNET_SCALARPRODUCT_ResponseStatus (in...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
static struct GNUNET_CRYPTO_EccDlogContext * edc
Context for DLOG operations on a curve.
struct MpiElement * sorted_elements
a(Alice), sorted array by key of length used_element_count.
struct GNUNET_SETI_OperationHandle * GNUNET_SETI_accept(struct GNUNET_SETI_Request *request, const struct GNUNET_SETI_Option options[], GNUNET_SETI_ResultIterator result_cb, void *result_cls)
Accept a request we got via GNUNET_SETI_listen().
struct GNUNET_PeerIdentity peer
the identity of a remote peer we want to communicate with
Scalar Product API Message Types.
void GNUNET_SETI_operation_cancel(struct GNUNET_SETI_OperationHandle *oh)
Cancel the given set operation.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
uint32_t element_count_total
how many elements the vector in payload contains
uint16_t status
See PRISM_STATUS_*-constants.
gcry_mpi_point_t GNUNET_CRYPTO_ecc_add(struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_point_t a, gcry_mpi_point_t b)
Add two points on the elliptic curve.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
const void * data
Actual data of the element.
struct GNUNET_SETI_Handle * GNUNET_SETI_create(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create an empty set, supporting the specified operation.
struct GNUNET_CRYPTO_EccPoint prod_h_i_b_i
The product of the h_i^{b_i} values.
uint32_t contained_element_count
How many elements this individual message delivers (in NBO), always TWO.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Initialization of the program and message handlers.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Message handler for a specific message type.
static void cb_channel_destruction(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called whenever a channel is destroyed.
struct GNUNET_PeerIdentity peer
Alice or Bob's peerID.
struct GNUNET_HashCode session_id
(hopefully) unique transaction ID
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE
Client -> Alice.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
Message type passed from responding service Bob to responding service Alice to complete a request and...
static int free_element_cb(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator called to free elements.
#define MAX_RESULT
Maximum allowed result value for the scalarproduct computation.
An encrypted element key-value pair.
static int check_alice_client_message_multipart(void *cls, const struct ComputationBobCryptodataMultipartMessage *msg)
We're receiving additional set data.
void GNUNET_CRYPTO_ecc_dlog_release(struct GNUNET_CRYPTO_EccDlogContext *dlc)
Release precalculated values.
Message type passed from requesting service Alice to responding service Bob to initiate a request and...
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_cls)
A client disconnected.
static gcry_mpi_t my_privkey
Alice's private key ('a').
uint32_t product_length
0 if no product attached
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION
Alice -> Bob ECC session initialization.
int64_t value
Value to multiply in scalar product, in NBO.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
static unsigned long long payload
How much data are we currently storing in the database?
gcry_mpi_point_t GNUNET_CRYPTO_ecc_dexp_mpi(struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_t val)
Multiply the generator g of the elliptic curve by val to obtain the point on the curve representing v...
Element should be delete from the result set of the local peer, i.e.
uint32_t used_element_count
How many elements actually are used for the scalar product.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_CONTAINER_MultiHashMap * intersected_elements
all non-0-value'd elements transmitted to us.
gcry_mpi_t product
The computed scalar.
Handle to a message queue.
static int check_alice_client_message(void *cls, const struct AliceComputationMessage *msg)
Handler for Alice's client request message.
The identity of the host (wraps the signing key of the peer).
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
struct GNUNET_CADET_Channel * GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h, void *channel_cls, const struct GNUNET_PeerIdentity *destination, const struct GNUNET_HashCode *port, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Create a new channel towards a remote peer.
The computation was successful.
struct GNUNET_MessageHeader header
GNUNET message header.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA
Bob -> Alice ECC crypto data.
GNUNET_SETI_Status
Status for the result callback.
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
static gcry_mpi_t compute_scalar_product(struct AliceServiceSession *session, gcry_mpi_point_t prod_g_i_b_i, gcry_mpi_point_t prod_h_i_b_i)
Compute our scalar product, done by Alice.
struct GNUNET_MQ_Handle * mq
#define GNUNET_log(kind,...)
#define ELEMENT_CAPACITY
Maximum number of elements we can put into a single cryptodata message.
uint32_t element_count_contained
contained elements the vector in payload contains
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
uint32_t element_count_contained
contained elements the vector in payload contains
multipart messages following struct ComputationMessage
Internal structure used to cache pre-calculated values for DLOG calculation.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
static gcry_mpi_t my_privkey_inv
Inverse of Alice's private key ('a_inv').
struct GNUNET_SERVICE_Client * client
The client this request is related to.
static void client_request_complete_alice(struct AliceServiceSession *s)
Our client has finished sending us its multipart message.
GNUNET_SCALARPRODUCT_ResponseStatus
Result status values for the computation.
static void handle_alice_client_message_multipart(void *cls, const struct ComputationBobCryptodataMultipartMessage *msg)
We're receiving additional set data.
struct GNUNET_MQ_Handle * client_mq
The message queue for the client.
Highest priority, control traffic (i.e.
struct GNUNET_SETI_OperationHandle * intersection_op
Set of elements for which will conduction an intersection.
int GNUNET_CRYPTO_ecc_dlog(struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_point_t input)
Calculate ECC discrete logarithm for small factors.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CRYPTO_PaillierCiphertext s
Bob's "s".
void GNUNET_SETI_listen_cancel(struct GNUNET_SETI_ListenHandle *lh)
Cancel the given listen operation.
#define MAX_RAM
How many values should DLOG store in memory (determines baseline RAM consumption, roughly 100 bytes t...
uint32_t client_received_element_count
Already transferred elements from client to us.
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
gcry_mpi_point_t GNUNET_CRYPTO_ecc_pmul_mpi(struct GNUNET_CRYPTO_EccDlogContext *edc, gcry_mpi_point_t p, gcry_mpi_t val)
Multiply the point p on the elliptic curve by val.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
uint16_t element_type
Application-specific element type.
static void destroy_service_session(struct AliceServiceSession *s)
Destroy session state, we are done with it.
static void prepare_client_end_notification(struct AliceServiceSession *session)
Notify the client that the session has failed.
An element key-value pair for scalarproduct.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
static int element_cmp(const void *a, const void *b)
Compare two struct MpiValues by key for sorting.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT
Alice/Bob -> Client Result.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_SETI_destroy(struct GNUNET_SETI_Handle *set)
Destroy the set handle, and free all associated resources.
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected peer.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
A client connected.