62 gcry_prime_generate (&
p,
65 GCRY_STRONG_RANDOM, 0));
67 gcry_prime_generate (&
q,
70 GCRY_STRONG_RANDOM, 0));
72 while (0 == gcry_mpi_cmp (
p,
q));
85 gcry_mpi_sub_ui (
p,
p, 1);
86 gcry_mpi_sub_ui (
q,
q, 1);
87 gcry_mpi_mul (phi,
p,
q);
100 gcry_mpi_release (phi);
101 gcry_mpi_release (n);
105 gcry_mpi_release (mu);
135 unsigned int highbit;
147 for (possible_opts = -2; gcry_mpi_cmp (tmp1,
m) > 0; possible_opts++)
148 gcry_mpi_div (tmp1, NULL, tmp1, tmp2, 0);
149 gcry_mpi_release (tmp1);
150 gcry_mpi_release (tmp2);
152 if (possible_opts < 1)
155 possible_opts = (desired_ops < possible_opts) ? desired_ops : possible_opts;
164 while ((! gcry_mpi_test_bit (n, highbit)) &&
171 gcry_mpi_release (n);
177 gcry_mpi_mul (n_square, n, n);
182 gcry_mpi_randomize (r, highbit + 1, GCRY_STRONG_RANDOM);
184 while (gcry_mpi_cmp (r, n) >= 0);
188 gcry_mpi_add_ui (c, n, 1);
190 gcry_mpi_powm (c, c,
m, n_square);
192 gcry_mpi_powm (r, r, n, n_square);
194 gcry_mpi_mulm (c, r, c, n_square);
197 sizeof ciphertext->
bits,
200 gcry_mpi_release (n_square);
201 gcry_mpi_release (n);
202 gcry_mpi_release (r);
203 gcry_mpi_release (c);
205 return possible_opts;
237 unsigned int highbit;
241 GNUNET_assert (NULL != (max_num = gcry_mpi_set_ui (NULL, 1)));
242 gcry_mpi_mul_2exp (max_num,
250for (possible_opts = -2; gcry_mpi_cmp (max_num,
m) > 0; possible_opts++)
251 gcry_mpi_div (max_num,
256 gcry_mpi_release (max_num);
258 if (possible_opts < 1)
261 possible_opts =
GNUNET_MIN (desired_ops, possible_opts);
271 while ((! gcry_mpi_test_bit (n, highbit)) &&
278 gcry_mpi_release (n);
286 gcry_mpi_randomize (r, highbit + 1, GCRY_STRONG_RANDOM);
288 while (gcry_mpi_cmp (r, n) >= 0);
292 gcry_mpi_add_ui (g, n, 1);
296 gcry_mpi_mul (n_square,
302 gcry_mpi_powm (gm, g,
m, n_square);
303 gcry_mpi_release (g);
307 gcry_mpi_powm (rn, r, n, n_square);
308 gcry_mpi_release (r);
309 gcry_mpi_release (n);
313 gcry_mpi_mulm (c, rn, gm, n_square);
314 gcry_mpi_release (n_square);
315 gcry_mpi_release (gm);
316 gcry_mpi_release (rn);
319 sizeof(ciphertext->
bits),
321 gcry_mpi_release (c);
323 return possible_opts;
347 sizeof(private_key->
lambda));
350 sizeof(private_key->
mu));
357 sizeof(ciphertext->
bits));
361 gcry_mpi_mul (n_square, n, n);
369 gcry_mpi_release (n_square);
370 gcry_mpi_release (lambda);
371 gcry_mpi_release (c);
375 gcry_mpi_sub_ui (cmum1, cmu, 1);
376 gcry_mpi_release (cmu);
380 gcry_mpi_div (mod, NULL, cmum1, n, 0);
381 gcry_mpi_release (cmum1);
384 gcry_mpi_mulm (
m, mod, mu, n);
385 gcry_mpi_release (mod);
386 gcry_mpi_release (mu);
387 gcry_mpi_release (n);
410 if ((0 >= o1) || (0 >= o2))
429 gcry_mpi_mul (n_square, n, n);
430 gcry_mpi_release (n);
434 gcry_mpi_mulm (c, a, b, n_square);
435 gcry_mpi_release (n_square);
436 gcry_mpi_release (a);
437 gcry_mpi_release (b);
443 gcry_mpi_release (c);
444 return ntohl (
result->remaining_ops);
static int GNUNET_CRYPTO_paillier_encrypt1(const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, const gcry_mpi_t m, int desired_ops, struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext)
Encrypt a plaintext with a paillier public key.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static int result
Global testing status.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static struct GNUNET_OS_Process * p
Helper process we started.
void GNUNET_CRYPTO_mpi_scan_unsigned(gcry_mpi_t *result, const void *data, size_t size)
Convert data buffer into MPI value.
int GNUNET_CRYPTO_paillier_hom_get_remaining(const struct GNUNET_CRYPTO_PaillierCiphertext *c)
Get the number of remaining supported homomorphic operations.
#define GNUNET_CRYPTO_PAILLIER_BITS
Size of paillier plain texts and public keys.
int GNUNET_CRYPTO_paillier_encrypt(const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, const gcry_mpi_t m, int desired_ops, struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext)
Encrypt a plaintext with a paillier public key.
void GNUNET_CRYPTO_mpi_print_unsigned(void *buf, size_t size, gcry_mpi_t val)
Output the given MPI value to the given buffer in network byte order.
void GNUNET_CRYPTO_paillier_create(struct GNUNET_CRYPTO_PaillierPublicKey *public_key, struct GNUNET_CRYPTO_PaillierPrivateKey *private_key)
Create a freshly generated paillier public key.
int GNUNET_CRYPTO_paillier_hom_add(const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, const struct GNUNET_CRYPTO_PaillierCiphertext *c1, const struct GNUNET_CRYPTO_PaillierCiphertext *c2, struct GNUNET_CRYPTO_PaillierCiphertext *result)
Compute a ciphertext that represents the sum of the plaintext in c1 and c2.
void GNUNET_CRYPTO_paillier_decrypt(const struct GNUNET_CRYPTO_PaillierPrivateKey *private_key, const struct GNUNET_CRYPTO_PaillierPublicKey *public_key, const struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext, gcry_mpi_t m)
Decrypt a paillier ciphertext with a private key.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int32_t remaining_ops
Guaranteed minimum number of homomorphic operations with this ciphertext, in network byte order (NBO)...
unsigned char bits[2048 *2/8]
The bits of the ciphertext.
unsigned char mu[2048/8]
Mu-component of the private key.
unsigned char lambda[2048/8]
Lambda-component of the private key.