summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c4
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c87
2 files changed, 37 insertions, 54 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
index 2c853d95c..59f422f9e 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
@@ -983,9 +983,7 @@ handle_alice_client_message (void *cls,
if (0 == GNUNET_ntohll (elements[i].value))
continue;
elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
- GNUNET_memcpy (elem,
- &elements[i],
- sizeof(struct GNUNET_SCALARPRODUCT_Element));
+ *elem = elements[i];
if (GNUNET_SYSERR ==
GNUNET_CONTAINER_multihashmap_put (
s->intersected_elements,
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
index 9f6711275..0216aa86d 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c
@@ -54,7 +54,7 @@ struct MpiElement
/**
* Value represented (a).
*/
- struct GNUNET_CRYPTO_EccScalar value;
+ int64_t value;
};
@@ -350,14 +350,8 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s)
e = GNUNET_MQ_msg (msg,
GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA);
msg->contained_element_count = htonl (2);
- if (NULL != s->prod_g_i_b_i)
- GNUNET_CRYPTO_ecc_point_to_bin (edc,
- s->prod_g_i_b_i,
- &msg->prod_g_i_b_i);
- if (NULL != s->prod_h_i_b_i)
- GNUNET_CRYPTO_ecc_point_to_bin (edc,
- s->prod_h_i_b_i,
- &msg->prod_h_i_b_i);
+ msg->prod_g_i_b_i = s->prod_g_i_b_i;
+ msg->prod_h_i_b_i = s->prod_h_i_b_i;
GNUNET_MQ_notify_sent (e,
&bob_cadet_done_cb,
s);
@@ -370,10 +364,9 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s)
* Iterator to copy over messages from the hash map
* into an array for sorting.
*
- * @param cls the `struct BobServiceSession *`
+ * @param cls the `struct AliceServiceSession *`
* @param key the key (unused)
* @param value the `struct GNUNET_SCALARPRODUCT_Element *`
- * TODO: code duplication with Alice!
*/
static int
copy_element_cb (void *cls,
@@ -382,17 +375,10 @@ copy_element_cb (void *cls,
{
struct BobServiceSession *s = cls;
struct GNUNET_SCALARPRODUCT_Element *e = value;
- struct GNUNET_CRYPTO_EccScalar mval;
- int64_t val;
-
- mval = gcry_mpi_new (0);
- val = (int64_t) GNUNET_ntohll (e->value);
- if (0 > val)
- gcry_mpi_sub_ui (mval, mval, -val);
- else
- gcry_mpi_add_ui (mval, mval, val);
- s->sorted_elements [s->used_element_count].value = mval;
- s->sorted_elements [s->used_element_count].key = &e->key;
+
+ s->sorted_elements[s->used_element_count].value = (int64_t) GNUNET_ntohll (
+ e->value);
+ s->sorted_elements[s->used_element_count].key = &e->key;
s->used_element_count++;
return GNUNET_OK;
}
@@ -476,10 +462,8 @@ handle_alices_cryptodata_message (void *cls,
const struct GNUNET_CRYPTO_EccPoint *payload;
uint32_t contained_elements;
unsigned int max;
- const struct MpiElement *b_i;
- struct GNUNET_CRYPTO_EccPoint tmp;
- struct GNUNET_CRYPTO_EccPoint g_i;
- struct GNUNET_CRYPTO_EccPoint h_i;
+ const struct GNUNET_CRYPTO_EccPoint *g_i;
+ const struct GNUNET_CRYPTO_EccPoint *h_i;
struct GNUNET_CRYPTO_EccPoint g_i_b_i;
struct GNUNET_CRYPTO_EccPoint h_i_b_i;
@@ -509,19 +493,24 @@ handle_alices_cryptodata_message (void *cls,
for (unsigned int i = 0; i < contained_elements; i++)
{
- b_i = &s->sorted_elements[i + s->cadet_received_element_count];
- g_i = GNUNET_CRYPTO_ecc_bin_to_point (edc,
- &payload[i * 2]);
- g_i_b_i = GNUNET_CRYPTO_ecc_pmul_mpi (edc,
- g_i,
- b_i->value);
- gcry_mpi_point_release (g_i);
- h_i = GNUNET_CRYPTO_ecc_bin_to_point (edc,
- &payload[i * 2 + 1]);
- h_i_b_i = GNUNET_CRYPTO_ecc_pmul_mpi (edc,
- h_i,
- b_i->value);
- gcry_mpi_point_release (h_i);
+ int64_t val = s->sorted_elements[i + s->cadet_received_element_count].value;
+ struct GNUNET_CRYPTO_EccScalar vali;
+
+ GNUNET_CRYPTO_ecc_scalar_from_int (val > 0 ? val : -val,
+ &vali);
+ if (val < 0)
+ crypto_core_ed25519_scalar_negate (&vali.v[0],
+ &vali.v[0]);
+ g_i = &payload[i * 2];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_ecc_pmul_mpi (g_i,
+ &vali,
+ &g_i_b_i));
+ h_i = &payload[i * 2 + 1];
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_ecc_pmul_mpi (h_i,
+ &vali,
+ &h_i_b_i));
if (0 == i + s->cadet_received_element_count)
{
/* first iteration, nothing to add */
@@ -531,18 +520,14 @@ handle_alices_cryptodata_message (void *cls,
else
{
/* further iterations, cummulate resulting value */
- tmp = GNUNET_CRYPTO_ecc_add (edc,
- s->prod_g_i_b_i,
- g_i_b_i);
- gcry_mpi_point_release (s->prod_g_i_b_i);
- gcry_mpi_point_release (g_i_b_i);
- s->prod_g_i_b_i = tmp;
- tmp = GNUNET_CRYPTO_ecc_add (edc,
- s->prod_h_i_b_i,
- h_i_b_i);
- gcry_mpi_point_release (s->prod_h_i_b_i);
- gcry_mpi_point_release (h_i_b_i);
- s->prod_h_i_b_i = tmp;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_ecc_add (&s->prod_g_i_b_i,
+ &g_i_b_i,
+ &s->prod_g_i_b_i));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_ecc_add (&s->prod_h_i_b_i,
+ &h_i_b_i,
+ &s->prod_h_i_b_i));
}
}
s->cadet_received_element_count += contained_elements;