aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_paillier.c
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2014-01-26 13:51:21 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2014-01-26 13:51:21 +0000
commite0f8645fc08ce4839e42f84fac5bcda8a6711392 (patch)
tree28b8afd17012d3718222842a062cd021e9604368 /src/util/crypto_paillier.c
parent9bd3837cec8372bb8fc012548629ac543932f240 (diff)
downloadgnunet-e0f8645fc08ce4839e42f84fac5bcda8a6711392.tar.gz
gnunet-e0f8645fc08ce4839e42f84fac5bcda8a6711392.zip
- more work on crypto-paillier
Diffstat (limited to 'src/util/crypto_paillier.c')
-rw-r--r--src/util/crypto_paillier.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/util/crypto_paillier.c b/src/util/crypto_paillier.c
index a7a1b6f9d..37627498d 100644
--- a/src/util/crypto_paillier.c
+++ b/src/util/crypto_paillier.c
@@ -99,7 +99,7 @@ GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *pu
99 const gcry_mpi_t m, 99 const gcry_mpi_t m,
100 struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext) 100 struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext)
101{ 101{
102 unsigned int length; 102 int length;
103 gcry_mpi_t n_square; 103 gcry_mpi_t n_square;
104 gcry_mpi_t r; 104 gcry_mpi_t r;
105 gcry_mpi_t g; 105 gcry_mpi_t g;
@@ -109,10 +109,11 @@ GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *pu
109 // determine how many operations we could allow, if the other number 109 // determine how many operations we could allow, if the other number
110 // has the same length. 110 // has the same length.
111 length = gcry_mpi_get_nbits(m); 111 length = gcry_mpi_get_nbits(m);
112 if (length >= GNUNET_CRYPTO_PAILLIER_BITS) 112 if (GNUNET_CRYPTO_PAILLIER_BITS <= length)
113 //paillier with 0 ops makes no sense, better use RSA and co.
113 return -1; 114 return -1;
114 else 115 else
115 ciphertext->remaining_ops = ntohl(pow(2,(GNUNET_CRYPTO_PAILLIER_BITS-length-1))); 116 ciphertext->remaining_ops = htonl(GNUNET_CRYPTO_PAILLIER_BITS - length);
116 117
117 GNUNET_assert (0 != (n_square = gcry_mpi_new (0))); 118 GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
118 GNUNET_assert (0 != (r = gcry_mpi_new (0))); 119 GNUNET_assert (0 != (r = gcry_mpi_new (0)));
@@ -146,7 +147,7 @@ GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *pu
146 gcry_mpi_release (r); 147 gcry_mpi_release (r);
147 gcry_mpi_release (c); 148 gcry_mpi_release (c);
148 149
149 return pow(2,(GNUNET_CRYPTO_PAILLIER_BITS-length-1)); 150 return GNUNET_CRYPTO_PAILLIER_BITS-length;
150} 151}
151 152
152 153
@@ -229,7 +230,7 @@ GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierPublicKey *pu
229 gcry_mpi_mul(n_square, n_square,n_square); 230 gcry_mpi_mul(n_square, n_square,n_square);
230 gcry_mpi_mulm(c,a,b,n_square); 231 gcry_mpi_mulm(c,a,b,n_square);
231 232
232 result->remaining_ops = (c1->remaining_ops > c2->remaining_ops) ? c2->remaining_ops : c1->remaining_ops; 233 result->remaining_ops = ((c1->remaining_ops > c2->remaining_ops) ? c2->remaining_ops : c1->remaining_ops) - 1;
233 GNUNET_CRYPTO_mpi_print_unsigned (result->bits, 234 GNUNET_CRYPTO_mpi_print_unsigned (result->bits,
234 sizeof result->bits, 235 sizeof result->bits,
235 c); 236 c);
@@ -241,4 +242,17 @@ GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierPublicKey *pu
241} 242}
242 243
243 244
245/**
246 * Get the number of remaining supported homomorphic operations.
247 *
248 * @param c Paillier cipher text.
249 * @return the number of remaining homomorphic operations
250 */
251int
252GNUNET_CRYPTO_paillier_hom_get_remaining (const struct GNUNET_CRYPTO_PaillierCiphertext *c)
253{
254 GNUNET_assert(NULL != c);
255 return ntohl(c->remaining_ops);
256}
257
244/* end of crypto_paillier.c */ 258/* end of crypto_paillier.c */