gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r32166 - in gnunet/src: . scalarproduct


From: gnunet
Subject: [GNUnet-SVN] r32166 - in gnunet/src: . scalarproduct
Date: Mon, 3 Feb 2014 17:56:34 +0100

Author: cfuchs
Date: 2014-02-03 17:56:34 +0100 (Mon, 03 Feb 2014)
New Revision: 32166

Modified:
   gnunet/src/Makefile.am
   gnunet/src/scalarproduct/gnunet-service-scalarproduct.c
Log:
- begun migrating scalarproduct to use crypto_paillier and set intersection
- removed paillier from the regular build for now
- partially replaced pailier-encryption functionality in scalarproduct with the 
new API

Modified: gnunet/src/Makefile.am
===================================================================
--- gnunet/src/Makefile.am      2014-02-03 16:25:17 UTC (rev 32165)
+++ gnunet/src/Makefile.am      2014-02-03 16:56:34 UTC (rev 32166)
@@ -8,18 +8,19 @@
  CONSENSUS = consensus
 # SECRETSHARING = secretsharing
  EXPERIMENTATION = experimentation
+# SCALARPRODUCT = scalarproduct
 endif
 
 if HAVE_EXPERIMENTAL
  EXP_DIR = \
   dv \
-  scalarproduct \
   multicast \
   env \
   psycstore \
   psyc \
   $(CONSENSUS) \
   $(SECRETSHARING) \
+  $(SCALARPRODUCT) \
   $(EXPERIMENTATION)
 endif
 

Modified: gnunet/src/scalarproduct/gnunet-service-scalarproduct.c
===================================================================
--- gnunet/src/scalarproduct/gnunet-service-scalarproduct.c     2014-02-03 
16:25:17 UTC (rev 32165)
+++ gnunet/src/scalarproduct/gnunet-service-scalarproduct.c     2014-02-03 
16:56:34 UTC (rev 32166)
@@ -471,36 +471,6 @@
 
 
 /**
- * Encrypts an element using the paillier crypto system
- *
- * @param c ciphertext (output)
- * @param m plaintext
- * @param g the public base
- * @param n the module from which which r is chosen (Z*_n)
- * @param n_square the module for encryption, for performance reasons.
- */
-static void
-encrypt_element (gcry_mpi_t c, gcry_mpi_t m, gcry_mpi_t g, gcry_mpi_t n, 
gcry_mpi_t n_square)
-{
-  gcry_mpi_t tmp;
-
-  GNUNET_assert (tmp = gcry_mpi_new (0));
-
-  while (0 >= gcry_mpi_cmp_ui (tmp, 1))
-  {
-    gcry_mpi_randomize (tmp, KEYBITS / 3, GCRY_WEAK_RANDOM);
-    // r must be 1 < r < n
-  }
-
-  gcry_mpi_powm (c, g, m, n_square);
-  gcry_mpi_powm (tmp, tmp, n, n_square);
-  gcry_mpi_mulm (c, tmp, c, n_square);
-
-  gcry_mpi_release (tmp);
-}
-
-
-/**
  * decrypts an element using the paillier crypto system
  *
  * @param m plaintext (output)
@@ -1211,7 +1181,9 @@
   uint32_t count;
   gcry_mpi_t * rand = NULL;
   gcry_mpi_t * r = NULL;
+  struct GNUNET_CRYPTO_PaillierCiphertext * R;
   gcry_mpi_t * r_prime = NULL;
+  struct GNUNET_CRYPTO_PaillierCiphertext * R_prime;
   gcry_mpi_t * b;
   gcry_mpi_t * a_pi;
   gcry_mpi_t * a_pi_prime;
@@ -1220,10 +1192,7 @@
   gcry_mpi_t * rand_pi_prime;
   gcry_mpi_t s = NULL;
   gcry_mpi_t s_prime = NULL;
-  gcry_mpi_t remote_n = NULL;
-  gcry_mpi_t remote_nsquare;
-  gcry_mpi_t remote_g = NULL;
-  gcry_sexp_t tmp_exp;
+  
   uint32_t value;
 
   count = request->used;
@@ -1257,42 +1226,6 @@
   response->vector = NULL;
   q = NULL;
   p = NULL;
-  tmp_exp = gcry_sexp_find_token (request->remote_pubkey, "n", 0);
-  if (!tmp_exp)
-  {
-    GNUNET_break_op (0);
-    gcry_sexp_release (request->remote_pubkey);
-    request->remote_pubkey = NULL;
-    goto except;
-  }
-  remote_n = gcry_sexp_nth_mpi (tmp_exp, 1, GCRYMPI_FMT_USG);
-  if (!remote_n)
-  {
-    GNUNET_break (0);
-    gcry_sexp_release (tmp_exp);
-    goto except;
-  }
-  remote_nsquare = gcry_mpi_new (KEYBITS + 1);
-  gcry_mpi_mul (remote_nsquare, remote_n, remote_n);
-  gcry_sexp_release (tmp_exp);
-  tmp_exp = gcry_sexp_find_token (request->remote_pubkey, "g", 0);
-  gcry_sexp_release (request->remote_pubkey);
-  request->remote_pubkey = NULL;
-  if (!tmp_exp)
-  {
-    GNUNET_break_op (0);
-    gcry_mpi_release (remote_n);
-    goto except;
-  }
-  remote_g = gcry_sexp_nth_mpi (tmp_exp, 1, GCRYMPI_FMT_USG);
-  if (!remote_g)
-  {
-    GNUNET_break (0);
-    gcry_mpi_release (remote_n);
-    gcry_sexp_release (tmp_exp);
-    goto except;
-  }
-  gcry_sexp_release (tmp_exp);
 
   // generate r, p and q
   rand = initialize_mpi_vector (count);
@@ -1341,10 +1274,15 @@
     // E(S - r_pi - b_pi)
     gcry_mpi_sub (r[i], my_offset, rand_pi[i]);
     gcry_mpi_sub (r[i], r[i], b_pi[i]);
-    encrypt_element (r[i], r[i], remote_g, remote_n, remote_nsquare);
-
+    GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, 
+                                    r[i], 
+                                    &R[i]);
+    
     // E(S - r_pi - b_pi) * E(S + a_pi) ==  E(2*S + a - r - b)
-    gcry_mpi_mulm (r[i], r[i], a_pi[i], remote_nsquare);
+    GNUNET_CRYPTO_paillier_hom_add (&request->remote_pubkey, 
+                                    &R[i], 
+                                    &A_pi[i], 
+                                    &R[i]);
   }
   GNUNET_free (a_pi);
   GNUNET_free (b_pi);
@@ -1355,10 +1293,15 @@
   {
     // E(S - r_qi)
     gcry_mpi_sub (r_prime[i], my_offset, rand_pi_prime[i]);
-    encrypt_element (r_prime[i], r_prime[i], remote_g, remote_n, 
remote_nsquare);
+    GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, 
+                                    r_prime[i], 
+                                    &R_prime[i]);
 
     // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi)
-    gcry_mpi_mulm (r_prime[i], r_prime[i], a_pi_prime[i], remote_nsquare);
+    GNUNET_CRYPTO_paillier_hom_add (&request->remote_pubkey, 
+                                    &R_prime[i], 
+                                    &A_pi_prime[i], 
+                                    &R_prime[i]);
   }
   GNUNET_free (a_pi_prime);
   GNUNET_free (rand_pi_prime);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]