aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_crypto_lib.h12
-rw-r--r--src/util/crypto_paillier.c45
2 files changed, 41 insertions, 16 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index a8e9d6027..5dc76be79 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -1372,16 +1372,18 @@ GNUNET_CRYPTO_paillier_decrypt (const struct GNUNET_CRYPTO_PaillierPrivateKey *p
1372 * Note that this operation can only be done a finite number of times 1372 * Note that this operation can only be done a finite number of times
1373 * before an overflow occurs. 1373 * before an overflow occurs.
1374 * 1374 *
1375 * @param x1 Paillier cipher text. 1375 * @param public_key Public key to use for encryption.
1376 * @param x2 Paillier cipher text. 1376 * @param c1 Paillier cipher text.
1377 * @param c2 Paillier cipher text.
1377 * @param[out] result Result of the homomorphic operation. 1378 * @param[out] result Result of the homomorphic operation.
1378 * @return #GNUNET_OK if the result could be computed, 1379 * @return #GNUNET_OK if the result could be computed,
1379 * #GNUNET_SYSERR if no more homomorphic operations are remaining. 1380 * #GNUNET_SYSERR if no more homomorphic operations are remaining.
1380 */ 1381 */
1381int 1382int
1382GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierCiphertext *x1, 1383GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
1383 const struct GNUNET_CRYPTO_PaillierCiphertext *x2, 1384 const struct GNUNET_CRYPTO_PaillierCiphertext *c1,
1384 const struct GNUNET_CRYPTO_PaillierCiphertext *result); 1385 const struct GNUNET_CRYPTO_PaillierCiphertext *c2,
1386 struct GNUNET_CRYPTO_PaillierCiphertext *result);
1385 1387
1386 1388
1387#if 0 /* keep Emacsens' auto-indent happy */ 1389#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/util/crypto_paillier.c b/src/util/crypto_paillier.c
index 60c06e48c..a7a1b6f9d 100644
--- a/src/util/crypto_paillier.c
+++ b/src/util/crypto_paillier.c
@@ -139,7 +139,7 @@ GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *pu
139 gcry_mpi_mulm (c, r, c, n_square); 139 gcry_mpi_mulm (c, r, c, n_square);
140 140
141 GNUNET_CRYPTO_mpi_print_unsigned (ciphertext->bits, 141 GNUNET_CRYPTO_mpi_print_unsigned (ciphertext->bits,
142 sizeof(*ciphertext) - sizeof(ciphertext->remaining_ops), 142 sizeof ciphertext->bits,
143 c); 143 c);
144 144
145 gcry_mpi_release (n_square); 145 gcry_mpi_release (n_square);
@@ -154,7 +154,7 @@ GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *pu
154 * Decrypt a paillier ciphertext with a private key. 154 * Decrypt a paillier ciphertext with a private key.
155 * 155 *
156 * @param private_key Private key to use for decryption. 156 * @param private_key Private key to use for decryption.
157 * @param public_key Public key to use for decryption. 157 * @param public_key Public key to use for encryption.
158 * @param ciphertext Ciphertext to decrypt. 158 * @param ciphertext Ciphertext to decrypt.
159 * @param[out] m Decryption of @a ciphertext with @private_key. 159 * @param[out] m Decryption of @a ciphertext with @private_key.
160 */ 160 */
@@ -172,7 +172,6 @@ GNUNET_CRYPTO_paillier_decrypt (const struct GNUNET_CRYPTO_PaillierPrivateKey *p
172 172
173 GNUNET_assert (0 != (n_square = gcry_mpi_new (0))); 173 GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
174 174
175
176 GNUNET_CRYPTO_mpi_scan_unsigned (&lambda, private_key->lambda, sizeof private_key->lambda); 175 GNUNET_CRYPTO_mpi_scan_unsigned (&lambda, private_key->lambda, sizeof private_key->lambda);
177 GNUNET_CRYPTO_mpi_scan_unsigned (&mu, private_key->mu, sizeof private_key->mu); 176 GNUNET_CRYPTO_mpi_scan_unsigned (&mu, private_key->mu, sizeof private_key->mu);
178 GNUNET_CRYPTO_mpi_scan_unsigned (&n, public_key, sizeof *public_key); 177 GNUNET_CRYPTO_mpi_scan_unsigned (&n, public_key, sizeof *public_key);
@@ -201,20 +200,44 @@ GNUNET_CRYPTO_paillier_decrypt (const struct GNUNET_CRYPTO_PaillierPrivateKey *p
201 * Note that this operation can only be done a finite number of times 200 * Note that this operation can only be done a finite number of times
202 * before an overflow occurs. 201 * before an overflow occurs.
203 * 202 *
204 * @param x1 Paillier cipher text. 203 * @param public_key Public key to use for encryption.
205 * @param x2 Paillier cipher text. 204 * @param c1 Paillier cipher text.
205 * @param c2 Paillier cipher text.
206 * @param[out] result Result of the homomorphic operation. 206 * @param[out] result Result of the homomorphic operation.
207 * @return #GNUNET_OK if the result could be computed, 207 * @return #GNUNET_OK if the result could be computed,
208 * #GNUNET_SYSERR if no more homomorphic operations are remaining. 208 * #GNUNET_SYSERR if no more homomorphic operations are remaining.
209 */ 209 */
210int 210int
211GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierCiphertext *x1, 211GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
212 const struct GNUNET_CRYPTO_PaillierCiphertext *x2, 212 const struct GNUNET_CRYPTO_PaillierCiphertext *c1,
213 const struct GNUNET_CRYPTO_PaillierCiphertext *result) 213 const struct GNUNET_CRYPTO_PaillierCiphertext *c2,
214 struct GNUNET_CRYPTO_PaillierCiphertext *result)
214{ 215{
215 // not implemented yet 216 gcry_mpi_t a;
216 GNUNET_assert (0); 217 gcry_mpi_t b;
217 return GNUNET_SYSERR; 218 gcry_mpi_t c;
219 gcry_mpi_t n_square;
220
221 if (0 == c1->remaining_ops || 0 == c2->remaining_ops)
222 return GNUNET_SYSERR;
223
224 GNUNET_assert (0 != (c = gcry_mpi_new (0)));
225
226 GNUNET_CRYPTO_mpi_scan_unsigned (&a, c1->bits, sizeof c1->bits);
227 GNUNET_CRYPTO_mpi_scan_unsigned (&b, c1->bits, sizeof c2->bits);
228 GNUNET_CRYPTO_mpi_scan_unsigned (&n_square, public_key, sizeof *public_key);
229 gcry_mpi_mul(n_square, n_square,n_square);
230 gcry_mpi_mulm(c,a,b,n_square);
231
232 result->remaining_ops = (c1->remaining_ops > c2->remaining_ops) ? c2->remaining_ops : c1->remaining_ops;
233 GNUNET_CRYPTO_mpi_print_unsigned (result->bits,
234 sizeof result->bits,
235 c);
236 gcry_mpi_release (a);
237 gcry_mpi_release (b);
238 gcry_mpi_release (c);
239 gcry_mpi_release (n_square);
240 return GNUNET_OK;
218} 241}
219 242
220 243