aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_paillier.c
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2014-01-21 10:54:47 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2014-01-21 10:54:47 +0000
commit84e1871a793507afdba49cf385cbf7ce2e04aca4 (patch)
tree5846909b13922f6c551606801ef2812b16d14b74 /src/util/crypto_paillier.c
parenta43f7e0dad6e3c984f57b6181f0234566e771ce1 (diff)
downloadgnunet-84e1871a793507afdba49cf385cbf7ce2e04aca4.tar.gz
gnunet-84e1871a793507afdba49cf385cbf7ce2e04aca4.zip
- scalarproduct element container was 1 byte too large
- added logics to compute the maximum supported number of paillier hom.ops for a ciphertext - updated comments
Diffstat (limited to 'src/util/crypto_paillier.c')
-rw-r--r--src/util/crypto_paillier.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/util/crypto_paillier.c b/src/util/crypto_paillier.c
index d6cf9b306..60c06e48c 100644
--- a/src/util/crypto_paillier.c
+++ b/src/util/crypto_paillier.c
@@ -92,18 +92,28 @@ GNUNET_CRYPTO_paillier_create (struct GNUNET_CRYPTO_PaillierPublicKey *public_ke
92 * @param public_key Public key to use. 92 * @param public_key Public key to use.
93 * @param m Plaintext to encrypt. 93 * @param m Plaintext to encrypt.
94 * @param[out] ciphertext Encrytion of @a plaintext with @a public_key. 94 * @param[out] ciphertext Encrytion of @a plaintext with @a public_key.
95 * @return guaranteed number of supported homomorphic operations >= 1, -1 for failure
95 */ 96 */
96void 97int
97GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, 98GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
98 const gcry_mpi_t m, 99 const gcry_mpi_t m,
99 struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext) 100 struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext)
100{ 101{
102 unsigned int length;
101 gcry_mpi_t n_square; 103 gcry_mpi_t n_square;
102 gcry_mpi_t r; 104 gcry_mpi_t r;
103 gcry_mpi_t g; 105 gcry_mpi_t g;
104 gcry_mpi_t c; 106 gcry_mpi_t c;
105 gcry_mpi_t n; 107 gcry_mpi_t n;
106 108
109 // determine how many operations we could allow, if the other number
110 // has the same length.
111 length = gcry_mpi_get_nbits(m);
112 if (length >= GNUNET_CRYPTO_PAILLIER_BITS)
113 return -1;
114 else
115 ciphertext->remaining_ops = ntohl(pow(2,(GNUNET_CRYPTO_PAILLIER_BITS-length-1)));
116
107 GNUNET_assert (0 != (n_square = gcry_mpi_new (0))); 117 GNUNET_assert (0 != (n_square = gcry_mpi_new (0)));
108 GNUNET_assert (0 != (r = gcry_mpi_new (0))); 118 GNUNET_assert (0 != (r = gcry_mpi_new (0)));
109 GNUNET_assert (0 != (g = gcry_mpi_new (0))); 119 GNUNET_assert (0 != (g = gcry_mpi_new (0)));
@@ -135,6 +145,8 @@ GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *pu
135 gcry_mpi_release (n_square); 145 gcry_mpi_release (n_square);
136 gcry_mpi_release (r); 146 gcry_mpi_release (r);
137 gcry_mpi_release (c); 147 gcry_mpi_release (c);
148
149 return pow(2,(GNUNET_CRYPTO_PAILLIER_BITS-length-1));
138} 150}
139 151
140 152