aboutsummaryrefslogtreecommitdiff
path: root/src/secretsharing/gnunet-service-secretsharing.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2014-01-21 10:05:56 +0000
committerFlorian Dold <florian.dold@gmail.com>2014-01-21 10:05:56 +0000
commitdcb7f90287cfdeb6d21d70715e4817a980a17c85 (patch)
tree335ad78369eb31ae815713cad732057d417f1f70 /src/secretsharing/gnunet-service-secretsharing.c
parent2e09e80c283642d7d4cd943a9c3f39790f209210 (diff)
downloadgnunet-dcb7f90287cfdeb6d21d70715e4817a980a17c85.tar.gz
gnunet-dcb7f90287cfdeb6d21d70715e4817a980a17c85.zip
use paillier public key container in secretsharing
Diffstat (limited to 'src/secretsharing/gnunet-service-secretsharing.c')
-rw-r--r--src/secretsharing/gnunet-service-secretsharing.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/secretsharing/gnunet-service-secretsharing.c b/src/secretsharing/gnunet-service-secretsharing.c
index ce61246d2..ba63c32cd 100644
--- a/src/secretsharing/gnunet-service-secretsharing.c
+++ b/src/secretsharing/gnunet-service-secretsharing.c
@@ -50,7 +50,7 @@ struct KeygenPeerInfo
50 * The peer's paillier public key. 50 * The peer's paillier public key.
51 * Freshly generated for each keygen session. 51 * Freshly generated for each keygen session.
52 */ 52 */
53 gcry_mpi_t paillier_n; 53 struct GNUNET_CRYPTO_PaillierPublicKey paillier_public_key;
54 54
55 /** 55 /**
56 * The peer's commitment to his presecret. 56 * The peer's commitment to his presecret.
@@ -678,7 +678,8 @@ keygen_round1_new_element (void *cls,
678 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "keygen commit data with invalid signature in consensus\n"); 678 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "keygen commit data with invalid signature in consensus\n");
679 return; 679 return;
680 } 680 }
681 GNUNET_CRYPTO_mpi_scan_unsigned (&info->paillier_n, &d->pubkey.n, GNUNET_CRYPTO_PAILLIER_BITS / 8); 681 info->paillier_public_key = d->pubkey;
682 // FIXME: does not make any sense / is wrong
682 GNUNET_CRYPTO_mpi_scan_unsigned (&info->presecret_commitment, &d->pubkey.n, GNUNET_CRYPTO_PAILLIER_BITS / 8); 683 GNUNET_CRYPTO_mpi_scan_unsigned (&info->presecret_commitment, &d->pubkey.n, GNUNET_CRYPTO_PAILLIER_BITS / 8);
683 info->round1_valid = GNUNET_YES; 684 info->round1_valid = GNUNET_YES;
684} 685}
@@ -862,14 +863,12 @@ insert_round2_element (struct KeygenSession *ks)
862 if (GNUNET_YES == ks->info[i].round1_valid) 863 if (GNUNET_YES == ks->info[i].round1_valid)
863 { 864 {
864 struct GNUNET_CRYPTO_PaillierPlaintext plaintext; 865 struct GNUNET_CRYPTO_PaillierPlaintext plaintext;
865 struct GNUNET_CRYPTO_PaillierPublicKey public_key;
866 gcry_mpi_set_ui (idx, i + 1); 866 gcry_mpi_set_ui (idx, i + 1);
867 // evaluate the polynomial 867 // evaluate the polynomial
868 horner_eval (v, ks->presecret_polynomial, ks->threshold, idx, elgamal_q); 868 horner_eval (v, ks->presecret_polynomial, ks->threshold, idx, elgamal_q);
869 GNUNET_CRYPTO_mpi_print_unsigned (&plaintext, sizeof plaintext, v); 869 GNUNET_CRYPTO_mpi_print_unsigned (&plaintext, sizeof plaintext, v);
870 GNUNET_CRYPTO_mpi_print_unsigned (&public_key, sizeof public_key, ks->info[i].paillier_n);
871 // encrypt the result 870 // encrypt the result
872 GNUNET_CRYPTO_paillier_encrypt (&public_key, &plaintext, ciphertext); 871 GNUNET_CRYPTO_paillier_encrypt (&ks->info[i].paillier_public_key, &plaintext, ciphertext);
873 } 872 }
874 pos += sizeof *ciphertext; 873 pos += sizeof *ciphertext;
875 } 874 }
@@ -980,18 +979,16 @@ keygen_round2_new_element (void *cls,
980 979
981 // FIXME: remove this ugly block once we changed all MPIs to containers 980 // FIXME: remove this ugly block once we changed all MPIs to containers
982 { 981 {
983 struct GNUNET_CRYPTO_PaillierPublicKey public_key;
984 struct GNUNET_CRYPTO_PaillierPrivateKey private_key; 982 struct GNUNET_CRYPTO_PaillierPrivateKey private_key;
985 struct GNUNET_CRYPTO_PaillierPlaintext plaintext; 983 struct GNUNET_CRYPTO_PaillierPlaintext plaintext;
986 struct GNUNET_CRYPTO_PaillierCiphertext ciphertext; 984 struct GNUNET_CRYPTO_PaillierCiphertext ciphertext;
987 985
988 GNUNET_CRYPTO_mpi_print_unsigned (&public_key, sizeof public_key, ks->info[ks->local_peer_idx].paillier_n);
989 GNUNET_CRYPTO_mpi_print_unsigned (&private_key.lambda, sizeof private_key.lambda, ks->paillier_lambda); 986 GNUNET_CRYPTO_mpi_print_unsigned (&private_key.lambda, sizeof private_key.lambda, ks->paillier_lambda);
990 GNUNET_CRYPTO_mpi_print_unsigned (&private_key.mu, sizeof private_key.mu, ks->paillier_mu); 987 GNUNET_CRYPTO_mpi_print_unsigned (&private_key.mu, sizeof private_key.mu, ks->paillier_mu);
991 GNUNET_CRYPTO_mpi_print_unsigned (&ciphertext, sizeof ciphertext, c); 988 GNUNET_CRYPTO_mpi_print_unsigned (&ciphertext, sizeof ciphertext, c);
992 989
993 990
994 GNUNET_CRYPTO_paillier_decrypt (&private_key, &public_key, 991 GNUNET_CRYPTO_paillier_decrypt (&private_key, &ks->info[ks->local_peer_idx].paillier_public_key,
995 &ciphertext, &plaintext); 992 &ciphertext, &plaintext);
996 GNUNET_CRYPTO_mpi_scan_unsigned (&info->decrypted_preshare, &plaintext, 993 GNUNET_CRYPTO_mpi_scan_unsigned (&info->decrypted_preshare, &plaintext,
997 sizeof plaintext); 994 sizeof plaintext);
@@ -1074,8 +1071,7 @@ insert_round1_element (struct KeygenSession *ks)
1074 1071
1075 GNUNET_CRYPTO_hash (v_data, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8, &d->commitment); 1072 GNUNET_CRYPTO_hash (v_data, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8, &d->commitment);
1076 1073
1077 GNUNET_CRYPTO_mpi_print_unsigned (d->pubkey.n, GNUNET_CRYPTO_PAILLIER_BITS / 8, 1074 d->pubkey = ks->info[ks->local_peer_idx].paillier_public_key;
1078 ks->info[ks->local_peer_idx].paillier_n);
1079 1075
1080 d->purpose.size = htonl ((sizeof *d) - offsetof (struct GNUNET_SECRETSHARING_KeygenCommitData, purpose)); 1076 d->purpose.size = htonl ((sizeof *d) - offsetof (struct GNUNET_SECRETSHARING_KeygenCommitData, purpose));
1081 d->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1); 1077 d->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SECRETSHARING_DKG1);
@@ -1106,7 +1102,6 @@ static void handle_client_keygen (void *cls,
1106 struct KeygenSession *ks; 1102 struct KeygenSession *ks;
1107 unsigned int i; 1103 unsigned int i;
1108 struct GNUNET_CRYPTO_PaillierPrivateKey private_key; 1104 struct GNUNET_CRYPTO_PaillierPrivateKey private_key;
1109 struct GNUNET_CRYPTO_PaillierPublicKey public_key;
1110 1105
1111 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client requested key generation\n"); 1106 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client requested key generation\n");
1112 1107
@@ -1136,14 +1131,12 @@ static void handle_client_keygen (void *cls,
1136 for (i = 0; i < ks->num_peers; i++) 1131 for (i = 0; i < ks->num_peers; i++)
1137 ks->info[i].peer = ks->peers[i]; 1132 ks->info[i].peer = ks->peers[i];
1138 1133
1139 GNUNET_assert (0 != (ks->info[ks->local_peer_idx].paillier_n = mpi_new (0)));
1140 GNUNET_assert (0 != (ks->paillier_lambda = mpi_new (0))); 1134 GNUNET_assert (0 != (ks->paillier_lambda = mpi_new (0)));
1141 GNUNET_assert (0 != (ks->paillier_mu = mpi_new (0))); 1135 GNUNET_assert (0 != (ks->paillier_mu = mpi_new (0)));
1142 1136
1143 GNUNET_CRYPTO_paillier_create (&public_key, &private_key); 1137 GNUNET_CRYPTO_paillier_create (&ks->info[ks->local_peer_idx].paillier_public_key,
1138 &private_key);
1144 1139
1145 GNUNET_CRYPTO_mpi_scan_unsigned (&ks->info[ks->local_peer_idx].paillier_n,
1146 &public_key, sizeof public_key);
1147 GNUNET_CRYPTO_mpi_scan_unsigned (&ks->paillier_lambda, 1140 GNUNET_CRYPTO_mpi_scan_unsigned (&ks->paillier_lambda,
1148 &private_key.lambda, sizeof private_key.lambda); 1141 &private_key.lambda, sizeof private_key.lambda);
1149 GNUNET_CRYPTO_mpi_scan_unsigned (&ks->paillier_mu, 1142 GNUNET_CRYPTO_mpi_scan_unsigned (&ks->paillier_mu,