- extended paillier-api to also include caller-suggested maximum supported homs
authorChristian Fuchs <christian.fuchs@cfuchs.net>
Tue, 4 Feb 2014 10:15:29 +0000 (10:15 +0000)
committerChristian Fuchs <christian.fuchs@cfuchs.net>
Tue, 4 Feb 2014 10:15:29 +0000 (10:15 +0000)
src/include/gnunet_crypto_lib.h
src/scalarproduct/gnunet-service-scalarproduct.c
src/secretsharing/gnunet-service-secretsharing.c
src/util/crypto_paillier.c
src/util/test_crypto_paillier.c

index 54923ec5639e09ecf7b766db5518bf9e2a802662..2e333bd17fad8cd210a3ebd4b64a04356d4be033 100644 (file)
@@ -1330,13 +1330,16 @@ GNUNET_CRYPTO_paillier_create (struct GNUNET_CRYPTO_PaillierPublicKey *public_ke
  *
  * @param public_key Public key to use.
  * @param m Plaintext to encrypt.
+ * @param desired_ops How many homomorphic ops the caller intends to use
  * @param[out] ciphertext Encrytion of @a plaintext with @a public_key.
  * @return guaranteed number of supported homomorphic operations >= 1, 
- *         -1 if less than one homomorphic operation is possible
+ *         or desired_ops, in case that is lower,
+ *         or -1 if less than one homomorphic operation is possible
  */
 int
 GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
                                 const gcry_mpi_t m,
+                                int desired_ops,
                                 struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext);
 
 
index 0633656110f692bd6adc3583edd48822b3865b9c..67ddbc06a7893247e49a247986d8f752b355f77b 100644 (file)
@@ -1280,7 +1280,8 @@ compute_service_response (struct ServiceSession * request,
     gcry_mpi_sub (r[i], my_offset, rand_pi[i]);
     gcry_mpi_sub (r[i], r[i], b_pi[i]);
     GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, 
-                                    r[i], 
+                                    r[i],
+                                    2,
                                     &R[i]);
     
     // E(S - r_pi - b_pi) * E(S + a_pi) ==  E(2*S + a - r - b)
@@ -1300,12 +1301,14 @@ compute_service_response (struct ServiceSession * request,
     gcry_mpi_sub (r_prime[i], my_offset, rand_pi_prime[i]);
     GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, 
                                     r_prime[i], 
+                                    2,
                                     &R_prime[i]);
 
     // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi)
     GNUNET_CRYPTO_paillier_hom_add (&request->remote_pubkey, 
                                     &R_prime[i], 
-                                    &A_pi_prime[i], 
+                                    &A_pi_prime[i],
+                                    2,
                                     &R_prime[i]);
   }
   GNUNET_free (a_pi_prime);
@@ -1319,6 +1322,7 @@ compute_service_response (struct ServiceSession * request,
   s_prime = compute_square_sum (rand, count);
   GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, 
                                   s_prime, 
+                                  1,
                                   &S_prime);
 
   // Calculate S = E(SUM( (r_i + b_i)^2 ))
@@ -1327,7 +1331,8 @@ compute_service_response (struct ServiceSession * request,
   }
   s = compute_square_sum (rand, count);
   GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, 
-                                  s[i], 
+                                  s[i],
+                                  1,
                                   &S);
 
   // release r and tmp
index 9c8c442643a8e998ac81bdca28e631aaaddf18bc..b294338246179dc5090d6c491abe3a664b6821a0 100644 (file)
@@ -866,7 +866,7 @@ insert_round2_element (struct KeygenSession *ks)
       // evaluate the polynomial
       horner_eval (v, ks->presecret_polynomial, ks->threshold, idx, elgamal_q);
       // encrypt the result
-      GNUNET_CRYPTO_paillier_encrypt (&ks->info[i].paillier_public_key, v, ciphertext);
+      GNUNET_CRYPTO_paillier_encrypt (&ks->info[i].paillier_public_key, v, 0, ciphertext);
     }
     pos += sizeof *ciphertext;
   }
index d478239053f1fe148113ae71052a518039c20b72..6873d159f4ba2bf23a415c81bcd8596ca683b330 100644 (file)
@@ -92,12 +92,16 @@ GNUNET_CRYPTO_paillier_create (struct GNUNET_CRYPTO_PaillierPublicKey *public_ke
  *
  * @param public_key Public key to use.
  * @param m Plaintext to encrypt.
+ * @param desired_ops How many homomorphic ops the caller intends to use
  * @param[out] ciphertext Encrytion of @a plaintext with @a public_key.
- * @return guaranteed number of supported homomorphic operations, can be zero
+ * @return guaranteed number of supported homomorphic operations >= 1, 
+ *         or desired_ops, in case that is lower,
+ *         or -1 if less than one homomorphic operation is possible
  */
 int
 GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
                                 const gcry_mpi_t m,
+                                int desired_ops,
                                 struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext)
 {
   int possible_opts;
index b771006422622d7cbf21fa6789b8953db30d847e..0dad500ba123d8b2449e6ba273176f69e16df31d 100644 (file)
@@ -45,7 +45,7 @@ test_crypto ()
 
   gcry_mpi_randomize (plaintext, GNUNET_CRYPTO_PAILLIER_BITS / 2, GCRY_WEAK_RANDOM);
 
-  GNUNET_CRYPTO_paillier_encrypt (&public_key, plaintext, &ciphertext);
+  GNUNET_CRYPTO_paillier_encrypt (&public_key, plaintext, 0, &ciphertext);
 
   GNUNET_CRYPTO_paillier_decrypt (&private_key, &public_key,
                                   &ciphertext, plaintext_result);
@@ -88,16 +88,14 @@ test_hom()
   gcry_mpi_mul_2exp(m2,m2,GNUNET_CRYPTO_PAILLIER_BITS-3);
   gcry_mpi_add(result,m1,m2);
 
-  if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m1, &c1))){
+  if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m1, 0, &c1))){
     printf ("GNUNET_CRYPTO_paillier_encrypt 1 failed, should return 1 allowed operation, got %d!\n", ret);
     return 1;
   }
-  if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m2, &c2))){
+  if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m2, 0, &c2))){
     printf ("GNUNET_CRYPTO_paillier_encrypt 2 failed, should return 1 allowed operation, got %d!\n", ret);
     return 1;
   }
-  
-  GNUNET_CRYPTO_paillier_encrypt (&public_key, m2, &c2);
 
   if (0 != (ret = GNUNET_CRYPTO_paillier_hom_add (&public_key, &c1,&c2, &c_result))){
     printf ("GNUNET_CRYPTO_paillier_hom_add failed, expected 0 remaining operations, got %d!\n", ret);