diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-01-21 09:51:01 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-01-21 09:51:01 +0000 |
commit | 029cb201f0aa6c23afc63fb1d80732d43d5c92a3 (patch) | |
tree | 702cdfe61c2e77652506e6b641ad938b331c93fc /src/secretsharing/gnunet-service-secretsharing.c | |
parent | 37e8e8840403bf7da9446b5997878153419a9dc3 (diff) | |
download | gnunet-029cb201f0aa6c23afc63fb1d80732d43d5c92a3.tar.gz gnunet-029cb201f0aa6c23afc63fb1d80732d43d5c92a3.zip |
remove paillier_encrypt in secretsharing
Diffstat (limited to 'src/secretsharing/gnunet-service-secretsharing.c')
-rw-r--r-- | src/secretsharing/gnunet-service-secretsharing.c | 58 |
1 files changed, 11 insertions, 47 deletions
diff --git a/src/secretsharing/gnunet-service-secretsharing.c b/src/secretsharing/gnunet-service-secretsharing.c index 64851009d..07426a13b 100644 --- a/src/secretsharing/gnunet-service-secretsharing.c +++ b/src/secretsharing/gnunet-service-secretsharing.c | |||
@@ -529,45 +529,6 @@ compute_lagrange_coefficient (gcry_mpi_t coeff, unsigned int j, | |||
529 | 529 | ||
530 | 530 | ||
531 | /** | 531 | /** |
532 | * Encrypt a value using Paillier's scheme. | ||
533 | * | ||
534 | * @param[out] c resulting ciphertext | ||
535 | * @param m plaintext to encrypt | ||
536 | * @param n n-component of public key | ||
537 | */ | ||
538 | static void | ||
539 | paillier_encrypt (gcry_mpi_t c, gcry_mpi_t m, gcry_mpi_t n) | ||
540 | { | ||
541 | gcry_mpi_t n_square; | ||
542 | gcry_mpi_t r; | ||
543 | gcry_mpi_t g; | ||
544 | |||
545 | GNUNET_assert (0 != (n_square = gcry_mpi_new (0))); | ||
546 | GNUNET_assert (0 != (r = gcry_mpi_new (0))); | ||
547 | GNUNET_assert (0 != (g = gcry_mpi_new (0))); | ||
548 | |||
549 | gcry_mpi_add_ui (g, n, 1); | ||
550 | |||
551 | gcry_mpi_mul (n_square, n, n); | ||
552 | |||
553 | // generate r < n | ||
554 | do | ||
555 | { | ||
556 | gcry_mpi_randomize (r, GNUNET_CRYPTO_PAILLIER_BITS, GCRY_WEAK_RANDOM); | ||
557 | } | ||
558 | while (gcry_mpi_cmp (r, n) >= 0); | ||
559 | |||
560 | gcry_mpi_powm (c, g, m, n_square); | ||
561 | gcry_mpi_powm (r, r, n, n_square); | ||
562 | gcry_mpi_mulm (c, r, c, n_square); | ||
563 | |||
564 | gcry_mpi_release (n_square); | ||
565 | gcry_mpi_release (r); | ||
566 | gcry_mpi_release (g); | ||
567 | } | ||
568 | |||
569 | |||
570 | /** | ||
571 | * Decrypt a ciphertext using Paillier's scheme. | 532 | * Decrypt a ciphertext using Paillier's scheme. |
572 | * | 533 | * |
573 | * @param[out] m resulting plaintext | 534 | * @param[out] m resulting plaintext |
@@ -921,21 +882,24 @@ insert_round2_element (struct KeygenSession *ks) | |||
921 | for (i = 0; i < ks->num_peers; i++) | 882 | for (i = 0; i < ks->num_peers; i++) |
922 | { | 883 | { |
923 | ptrdiff_t remaining = last_pos - pos; | 884 | ptrdiff_t remaining = last_pos - pos; |
885 | struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext; | ||
886 | |||
924 | GNUNET_assert (remaining > 0); | 887 | GNUNET_assert (remaining > 0); |
925 | if (GNUNET_NO == ks->info[i].round1_valid) | 888 | ciphertext = (void *) pos; |
926 | { | 889 | memset (ciphertext, 0, sizeof *ciphertext); |
927 | gcry_mpi_set_ui (c, 0); | 890 | if (GNUNET_YES == ks->info[i].round1_valid) |
928 | } | ||
929 | else | ||
930 | { | 891 | { |
892 | struct GNUNET_CRYPTO_PaillierPlaintext plaintext; | ||
893 | struct GNUNET_CRYPTO_PaillierPublicKey public_key; | ||
931 | gcry_mpi_set_ui (idx, i + 1); | 894 | gcry_mpi_set_ui (idx, i + 1); |
932 | // evaluate the polynomial | 895 | // evaluate the polynomial |
933 | horner_eval (v, ks->presecret_polynomial, ks->threshold, idx, elgamal_q); | 896 | horner_eval (v, ks->presecret_polynomial, ks->threshold, idx, elgamal_q); |
897 | GNUNET_CRYPTO_mpi_print_unsigned (&plaintext, sizeof plaintext, v); | ||
898 | GNUNET_CRYPTO_mpi_print_unsigned (&public_key, sizeof public_key, ks->info[i].paillier_n); | ||
934 | // encrypt the result | 899 | // encrypt the result |
935 | paillier_encrypt (c, v, ks->info[i].paillier_n); | 900 | GNUNET_CRYPTO_paillier_encrypt (&public_key, &plaintext, ciphertext); |
936 | } | 901 | } |
937 | GNUNET_CRYPTO_mpi_print_unsigned (pos, GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8, c); | 902 | pos += sizeof *ciphertext; |
938 | pos += GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8; | ||
939 | } | 903 | } |
940 | 904 | ||
941 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: computed enc preshares\n", | 905 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: computed enc preshares\n", |