aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2014-02-03 17:17:14 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2014-02-03 17:17:14 +0000
commitf52d267bb4d1ec781cf051b9a8d5beaa2b2ceb03 (patch)
tree4f11223833284364b3f658cb1b207b2b8db214b1 /src/scalarproduct
parent92a7f822eacb4dec18adc1a53008cfc64b62bed1 (diff)
downloadgnunet-f52d267bb4d1ec781cf051b9a8d5beaa2b2ceb03.tar.gz
gnunet-f52d267bb4d1ec781cf051b9a8d5beaa2b2ceb03.zip
- more partially replacing of pailier-encryption functionality in scalarproduct with the new API
Diffstat (limited to 'src/scalarproduct')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c
index 154c48d8f..063365611 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct.c
@@ -1191,7 +1191,9 @@ compute_service_response (struct ServiceSession * request,
1191 gcry_mpi_t * rand_pi; 1191 gcry_mpi_t * rand_pi;
1192 gcry_mpi_t * rand_pi_prime; 1192 gcry_mpi_t * rand_pi_prime;
1193 gcry_mpi_t s = NULL; 1193 gcry_mpi_t s = NULL;
1194 struct GNUNET_CRYPTO_PaillierCiphertext * S;
1194 gcry_mpi_t s_prime = NULL; 1195 gcry_mpi_t s_prime = NULL;
1196 struct GNUNET_CRYPTO_PaillierCiphertext * S_prime;
1195 1197
1196 uint32_t value; 1198 uint32_t value;
1197 1199
@@ -1256,8 +1258,11 @@ compute_service_response (struct ServiceSession * request,
1256 memcpy (b_pi, b, sizeof (gcry_mpi_t) * count); 1258 memcpy (b_pi, b, sizeof (gcry_mpi_t) * count);
1257 memcpy (rand_pi, rand, sizeof (gcry_mpi_t) * count); 1259 memcpy (rand_pi, rand, sizeof (gcry_mpi_t) * count);
1258 memcpy (rand_pi_prime, rand, sizeof (gcry_mpi_t) * count); 1260 memcpy (rand_pi_prime, rand, sizeof (gcry_mpi_t) * count);
1261
1262 //todo get API-cryptoblocks, instead of MPI values
1259 1263
1260 // generate p and q permutations for a, b and r 1264 // generate p and q permutations for a, b and r
1265 // TODO: APIify
1261 GNUNET_assert (permute_vector (a_pi, p, count)); 1266 GNUNET_assert (permute_vector (a_pi, p, count));
1262 GNUNET_assert (permute_vector (b_pi, p, count)); 1267 GNUNET_assert (permute_vector (b_pi, p, count));
1263 GNUNET_assert (permute_vector (rand_pi, p, count)); 1268 GNUNET_assert (permute_vector (rand_pi, p, count));
@@ -1312,17 +1317,18 @@ compute_service_response (struct ServiceSession * request,
1312 1317
1313 // Calculate S' = E(SUM( r_i^2 )) 1318 // Calculate S' = E(SUM( r_i^2 ))
1314 s_prime = compute_square_sum (rand, count); 1319 s_prime = compute_square_sum (rand, count);
1315 encrypt_element (s_prime, s_prime, remote_g, remote_n, remote_nsquare); 1320 GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey,
1321 s_prime,
1322 &S_prime);
1316 1323
1317 // Calculate S = E(SUM( (r_i + b_i)^2 )) 1324 // Calculate S = E(SUM( (r_i + b_i)^2 ))
1318 for (i = 0; i < count; i++) { 1325 for (i = 0; i < count; i++) {
1319 gcry_mpi_add (rand[i], rand[i], b[i]); 1326 gcry_mpi_add (rand[i], rand[i], b[i]);
1320 } 1327 }
1321 s = compute_square_sum (rand, count); 1328 s = compute_square_sum (rand, count);
1322 encrypt_element (s, s, remote_g, remote_n, remote_nsquare); 1329 GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey,
1323 gcry_mpi_release (remote_n); 1330 s[i],
1324 gcry_mpi_release (remote_g); 1331 &S);
1325 gcry_mpi_release (remote_nsquare);
1326 1332
1327 // release r and tmp 1333 // release r and tmp
1328 for (i = 0; i < count; i++) 1334 for (i = 0; i < count; i++)
@@ -1330,7 +1336,7 @@ compute_service_response (struct ServiceSession * request,
1330 gcry_mpi_release (rand[i]); 1336 gcry_mpi_release (rand[i]);
1331 1337
1332 // copy the r[], r_prime[], S and Stick into a new message, prepare_service_response frees these 1338 // copy the r[], r_prime[], S and Stick into a new message, prepare_service_response frees these
1333 if (GNUNET_YES != prepare_service_response (s, s_prime, request)) 1339 if (GNUNET_YES != prepare_service_response (S, S_prime, request))
1334 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Failed to communicate with `%s', scalar product calculation aborted.\n"), 1340 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Failed to communicate with `%s', scalar product calculation aborted.\n"),
1335 GNUNET_i2s (&request->peer)); 1341 GNUNET_i2s (&request->peer));
1336 else 1342 else