diff options
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 5 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 11 | ||||
-rw-r--r-- | src/secretsharing/gnunet-service-secretsharing.c | 2 | ||||
-rw-r--r-- | src/util/crypto_paillier.c | 6 | ||||
-rw-r--r-- | src/util/test_crypto_paillier.c | 8 |
5 files changed, 21 insertions, 11 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 54923ec56..2e333bd17 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -1330,13 +1330,16 @@ GNUNET_CRYPTO_paillier_create (struct GNUNET_CRYPTO_PaillierPublicKey *public_ke | |||
1330 | * | 1330 | * |
1331 | * @param public_key Public key to use. | 1331 | * @param public_key Public key to use. |
1332 | * @param m Plaintext to encrypt. | 1332 | * @param m Plaintext to encrypt. |
1333 | * @param desired_ops How many homomorphic ops the caller intends to use | ||
1333 | * @param[out] ciphertext Encrytion of @a plaintext with @a public_key. | 1334 | * @param[out] ciphertext Encrytion of @a plaintext with @a public_key. |
1334 | * @return guaranteed number of supported homomorphic operations >= 1, | 1335 | * @return guaranteed number of supported homomorphic operations >= 1, |
1335 | * -1 if less than one homomorphic operation is possible | 1336 | * or desired_ops, in case that is lower, |
1337 | * or -1 if less than one homomorphic operation is possible | ||
1336 | */ | 1338 | */ |
1337 | int | 1339 | int |
1338 | GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, | 1340 | GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, |
1339 | const gcry_mpi_t m, | 1341 | const gcry_mpi_t m, |
1342 | int desired_ops, | ||
1340 | struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext); | 1343 | struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext); |
1341 | 1344 | ||
1342 | 1345 | ||
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index 063365611..67ddbc06a 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -1280,7 +1280,8 @@ compute_service_response (struct ServiceSession * request, | |||
1280 | gcry_mpi_sub (r[i], my_offset, rand_pi[i]); | 1280 | gcry_mpi_sub (r[i], my_offset, rand_pi[i]); |
1281 | gcry_mpi_sub (r[i], r[i], b_pi[i]); | 1281 | gcry_mpi_sub (r[i], r[i], b_pi[i]); |
1282 | GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, | 1282 | GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, |
1283 | r[i], | 1283 | r[i], |
1284 | 2, | ||
1284 | &R[i]); | 1285 | &R[i]); |
1285 | 1286 | ||
1286 | // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b) | 1287 | // 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, | |||
1300 | gcry_mpi_sub (r_prime[i], my_offset, rand_pi_prime[i]); | 1301 | gcry_mpi_sub (r_prime[i], my_offset, rand_pi_prime[i]); |
1301 | GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, | 1302 | GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, |
1302 | r_prime[i], | 1303 | r_prime[i], |
1304 | 2, | ||
1303 | &R_prime[i]); | 1305 | &R_prime[i]); |
1304 | 1306 | ||
1305 | // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi) | 1307 | // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi) |
1306 | GNUNET_CRYPTO_paillier_hom_add (&request->remote_pubkey, | 1308 | GNUNET_CRYPTO_paillier_hom_add (&request->remote_pubkey, |
1307 | &R_prime[i], | 1309 | &R_prime[i], |
1308 | &A_pi_prime[i], | 1310 | &A_pi_prime[i], |
1311 | 2, | ||
1309 | &R_prime[i]); | 1312 | &R_prime[i]); |
1310 | } | 1313 | } |
1311 | GNUNET_free (a_pi_prime); | 1314 | GNUNET_free (a_pi_prime); |
@@ -1319,6 +1322,7 @@ compute_service_response (struct ServiceSession * request, | |||
1319 | s_prime = compute_square_sum (rand, count); | 1322 | s_prime = compute_square_sum (rand, count); |
1320 | GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, | 1323 | GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, |
1321 | s_prime, | 1324 | s_prime, |
1325 | 1, | ||
1322 | &S_prime); | 1326 | &S_prime); |
1323 | 1327 | ||
1324 | // Calculate S = E(SUM( (r_i + b_i)^2 )) | 1328 | // Calculate S = E(SUM( (r_i + b_i)^2 )) |
@@ -1327,7 +1331,8 @@ compute_service_response (struct ServiceSession * request, | |||
1327 | } | 1331 | } |
1328 | s = compute_square_sum (rand, count); | 1332 | s = compute_square_sum (rand, count); |
1329 | GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, | 1333 | GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey, |
1330 | s[i], | 1334 | s[i], |
1335 | 1, | ||
1331 | &S); | 1336 | &S); |
1332 | 1337 | ||
1333 | // release r and tmp | 1338 | // release r and tmp |
diff --git a/src/secretsharing/gnunet-service-secretsharing.c b/src/secretsharing/gnunet-service-secretsharing.c index 9c8c44264..b29433824 100644 --- a/src/secretsharing/gnunet-service-secretsharing.c +++ b/src/secretsharing/gnunet-service-secretsharing.c | |||
@@ -866,7 +866,7 @@ insert_round2_element (struct KeygenSession *ks) | |||
866 | // evaluate the polynomial | 866 | // evaluate the polynomial |
867 | horner_eval (v, ks->presecret_polynomial, ks->threshold, idx, elgamal_q); | 867 | horner_eval (v, ks->presecret_polynomial, ks->threshold, idx, elgamal_q); |
868 | // encrypt the result | 868 | // encrypt the result |
869 | GNUNET_CRYPTO_paillier_encrypt (&ks->info[i].paillier_public_key, v, ciphertext); | 869 | GNUNET_CRYPTO_paillier_encrypt (&ks->info[i].paillier_public_key, v, 0, ciphertext); |
870 | } | 870 | } |
871 | pos += sizeof *ciphertext; | 871 | pos += sizeof *ciphertext; |
872 | } | 872 | } |
diff --git a/src/util/crypto_paillier.c b/src/util/crypto_paillier.c index d47823905..6873d159f 100644 --- a/src/util/crypto_paillier.c +++ b/src/util/crypto_paillier.c | |||
@@ -92,12 +92,16 @@ GNUNET_CRYPTO_paillier_create (struct GNUNET_CRYPTO_PaillierPublicKey *public_ke | |||
92 | * | 92 | * |
93 | * @param public_key Public key to use. | 93 | * @param public_key Public key to use. |
94 | * @param m Plaintext to encrypt. | 94 | * @param m Plaintext to encrypt. |
95 | * @param desired_ops How many homomorphic ops the caller intends to use | ||
95 | * @param[out] ciphertext Encrytion of @a plaintext with @a public_key. | 96 | * @param[out] ciphertext Encrytion of @a plaintext with @a public_key. |
96 | * @return guaranteed number of supported homomorphic operations, can be zero | 97 | * @return guaranteed number of supported homomorphic operations >= 1, |
98 | * or desired_ops, in case that is lower, | ||
99 | * or -1 if less than one homomorphic operation is possible | ||
97 | */ | 100 | */ |
98 | int | 101 | int |
99 | GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, | 102 | GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, |
100 | const gcry_mpi_t m, | 103 | const gcry_mpi_t m, |
104 | int desired_ops, | ||
101 | struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext) | 105 | struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext) |
102 | { | 106 | { |
103 | int possible_opts; | 107 | int possible_opts; |
diff --git a/src/util/test_crypto_paillier.c b/src/util/test_crypto_paillier.c index b77100642..0dad500ba 100644 --- a/src/util/test_crypto_paillier.c +++ b/src/util/test_crypto_paillier.c | |||
@@ -45,7 +45,7 @@ test_crypto () | |||
45 | 45 | ||
46 | gcry_mpi_randomize (plaintext, GNUNET_CRYPTO_PAILLIER_BITS / 2, GCRY_WEAK_RANDOM); | 46 | gcry_mpi_randomize (plaintext, GNUNET_CRYPTO_PAILLIER_BITS / 2, GCRY_WEAK_RANDOM); |
47 | 47 | ||
48 | GNUNET_CRYPTO_paillier_encrypt (&public_key, plaintext, &ciphertext); | 48 | GNUNET_CRYPTO_paillier_encrypt (&public_key, plaintext, 0, &ciphertext); |
49 | 49 | ||
50 | GNUNET_CRYPTO_paillier_decrypt (&private_key, &public_key, | 50 | GNUNET_CRYPTO_paillier_decrypt (&private_key, &public_key, |
51 | &ciphertext, plaintext_result); | 51 | &ciphertext, plaintext_result); |
@@ -88,16 +88,14 @@ test_hom() | |||
88 | gcry_mpi_mul_2exp(m2,m2,GNUNET_CRYPTO_PAILLIER_BITS-3); | 88 | gcry_mpi_mul_2exp(m2,m2,GNUNET_CRYPTO_PAILLIER_BITS-3); |
89 | gcry_mpi_add(result,m1,m2); | 89 | gcry_mpi_add(result,m1,m2); |
90 | 90 | ||
91 | if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m1, &c1))){ | 91 | if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m1, 0, &c1))){ |
92 | printf ("GNUNET_CRYPTO_paillier_encrypt 1 failed, should return 1 allowed operation, got %d!\n", ret); | 92 | printf ("GNUNET_CRYPTO_paillier_encrypt 1 failed, should return 1 allowed operation, got %d!\n", ret); |
93 | return 1; | 93 | return 1; |
94 | } | 94 | } |
95 | if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m2, &c2))){ | 95 | if (1 != (ret = GNUNET_CRYPTO_paillier_encrypt (&public_key, m2, 0, &c2))){ |
96 | printf ("GNUNET_CRYPTO_paillier_encrypt 2 failed, should return 1 allowed operation, got %d!\n", ret); | 96 | printf ("GNUNET_CRYPTO_paillier_encrypt 2 failed, should return 1 allowed operation, got %d!\n", ret); |
97 | return 1; | 97 | return 1; |
98 | } | 98 | } |
99 | |||
100 | GNUNET_CRYPTO_paillier_encrypt (&public_key, m2, &c2); | ||
101 | 99 | ||
102 | if (0 != (ret = GNUNET_CRYPTO_paillier_hom_add (&public_key, &c1,&c2, &c_result))){ | 100 | if (0 != (ret = GNUNET_CRYPTO_paillier_hom_add (&public_key, &c1,&c2, &c_result))){ |
103 | printf ("GNUNET_CRYPTO_paillier_hom_add failed, expected 0 remaining operations, got %d!\n", ret); | 101 | printf ("GNUNET_CRYPTO_paillier_hom_add failed, expected 0 remaining operations, got %d!\n", ret); |