aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_paillier.c
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2014-01-21 11:37:50 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2014-01-21 11:37:50 +0000
commitb5bdfc8c7f57a9afff7a7dc2b6a8cdf5c303940d (patch)
tree2ffbc466ef232d4ab524b2e6552c1d8349c48ae3 /src/util/crypto_paillier.c
parent84e1871a793507afdba49cf385cbf7ce2e04aca4 (diff)
downloadgnunet-b5bdfc8c7f57a9afff7a7dc2b6a8cdf5c303940d.tar.gz
gnunet-b5bdfc8c7f57a9afff7a7dc2b6a8cdf5c303940d.zip
- added logics for homomorphic operation in paillier
- adjusted headers
Diffstat (limited to 'src/util/crypto_paillier.c')
-rw-r--r--src/util/crypto_paillier.c45
1 files changed, 34 insertions, 11 deletions
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