diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-02-03 16:25:17 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2014-02-03 16:25:17 +0000 |
commit | d6d4ffb707a1607c5aaa8e790de6afa21a195afe (patch) | |
tree | c21d5dee93c2996a51bbbb1e663a4f10dd1cf2de /src/util/crypto_paillier.c | |
parent | 1559917beb213bd0ab794bc7a450851b34117a82 (diff) | |
download | gnunet-d6d4ffb707a1607c5aaa8e790de6afa21a195afe.tar.gz gnunet-d6d4ffb707a1607c5aaa8e790de6afa21a195afe.zip |
- added more information on when paillier-encrypt soft-fails (too long number, no homomorphic ops possible)
Diffstat (limited to 'src/util/crypto_paillier.c')
-rw-r--r-- | src/util/crypto_paillier.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/util/crypto_paillier.c b/src/util/crypto_paillier.c index 8a9e44df3..12acefbbe 100644 --- a/src/util/crypto_paillier.c +++ b/src/util/crypto_paillier.c | |||
@@ -93,7 +93,8 @@ GNUNET_CRYPTO_paillier_create (struct GNUNET_CRYPTO_PaillierPublicKey *public_ke | |||
93 | * @param public_key Public key to use. | 93 | * @param public_key Public key to use. |
94 | * @param m Plaintext to encrypt. | 94 | * @param m Plaintext to encrypt. |
95 | * @param[out] ciphertext Encrytion of @a plaintext with @a public_key. | 95 | * @param[out] ciphertext Encrytion of @a plaintext with @a public_key. |
96 | * @return guaranteed number of supported homomorphic operations >= 1, -1 for failure | 96 | * @return guaranteed number of supported homomorphic operations >= 1, |
97 | * -1 if less than one homomorphic operation is possible | ||
97 | */ | 98 | */ |
98 | int | 99 | int |
99 | GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, | 100 | GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, |
@@ -114,16 +115,22 @@ GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *pu | |||
114 | GNUNET_assert (NULL != (tmp1 = gcry_mpi_set_ui (NULL, 1))); | 115 | GNUNET_assert (NULL != (tmp1 = gcry_mpi_set_ui (NULL, 1))); |
115 | GNUNET_assert (NULL != (tmp2 = gcry_mpi_set_ui (NULL, 2))); | 116 | GNUNET_assert (NULL != (tmp2 = gcry_mpi_set_ui (NULL, 2))); |
116 | gcry_mpi_mul_2exp (tmp1, tmp1, GNUNET_CRYPTO_PAILLIER_BITS); | 117 | gcry_mpi_mul_2exp (tmp1, tmp1, GNUNET_CRYPTO_PAILLIER_BITS); |
117 | 118 | ||
119 | // count number of possible operations | ||
120 | // this would be nicer with gcry_mpi_get_nbits, however it does not return | ||
121 | // the BITLENGTH of the given MPI's value, but the bits required | ||
122 | // to represent the number as MPI. | ||
118 | for (possible_opts = -2; gcry_mpi_cmp (tmp1, m) > 0; possible_opts++) { | 123 | for (possible_opts = -2; gcry_mpi_cmp (tmp1, m) > 0; possible_opts++) { |
119 | gcry_mpi_div (tmp1, NULL, tmp1, tmp2, 0); | 124 | gcry_mpi_div (tmp1, NULL, tmp1, tmp2, 0); |
120 | } | 125 | } |
121 | gcry_mpi_release (tmp1); | 126 | gcry_mpi_release (tmp1); |
122 | gcry_mpi_release (tmp2); | 127 | gcry_mpi_release (tmp2); |
128 | |||
129 | // can we do at least one homomorphic operation with this value? | ||
123 | if (possible_opts < 1) | 130 | if (possible_opts < 1) |
131 | // no, don't use paillier please! | ||
124 | return -1; | 132 | return -1; |
125 | else | 133 | else |
126 | // reduce by one to guarantee the final homomorphic operation | ||
127 | ciphertext->remaining_ops = htonl (possible_opts); | 134 | ciphertext->remaining_ops = htonl (possible_opts); |
128 | 135 | ||
129 | GNUNET_assert (0 != (n_square = gcry_mpi_new (0))); | 136 | GNUNET_assert (0 != (n_square = gcry_mpi_new (0))); |