aboutsummaryrefslogtreecommitdiff
path: root/src/secretsharing
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2014-01-21 09:40:50 +0000
committerFlorian Dold <florian.dold@gmail.com>2014-01-21 09:40:50 +0000
commit0fef52ef6595387d26ffc4b3233bf751b1bb8078 (patch)
treed325b68a6ce325780c98beaafa6b7870908b9513 /src/secretsharing
parentcbf0ad306298a3c214b2c1ea64ea8f5a66860403 (diff)
downloadgnunet-0fef52ef6595387d26ffc4b3233bf751b1bb8078.tar.gz
gnunet-0fef52ef6595387d26ffc4b3233bf751b1bb8078.zip
paillier constants / structs from util
Diffstat (limited to 'src/secretsharing')
-rw-r--r--src/secretsharing/gnunet-service-secretsharing.c30
-rw-r--r--src/secretsharing/secretsharing_protocol.h19
2 files changed, 16 insertions, 33 deletions
diff --git a/src/secretsharing/gnunet-service-secretsharing.c b/src/secretsharing/gnunet-service-secretsharing.c
index 0da56bf73..29899c2ac 100644
--- a/src/secretsharing/gnunet-service-secretsharing.c
+++ b/src/secretsharing/gnunet-service-secretsharing.c
@@ -546,8 +546,8 @@ paillier_create (gcry_mpi_t n, gcry_mpi_t lambda, gcry_mpi_t mu)
546 gcry_mpi_t phi; 546 gcry_mpi_t phi;
547 gcry_mpi_t tmp; 547 gcry_mpi_t tmp;
548 548
549 GNUNET_assert (NULL != (phi = gcry_mpi_new (PAILLIER_BITS))); 549 GNUNET_assert (NULL != (phi = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS)));
550 GNUNET_assert (NULL != (tmp = gcry_mpi_new (PAILLIER_BITS))); 550 GNUNET_assert (NULL != (tmp = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS)));
551 551
552 p = q = NULL; 552 p = q = NULL;
553 553
@@ -560,9 +560,9 @@ paillier_create (gcry_mpi_t n, gcry_mpi_t lambda, gcry_mpi_t mu)
560 if (NULL != q) 560 if (NULL != q)
561 gcry_mpi_release (q); 561 gcry_mpi_release (q);
562 // generate rsa modulus 562 // generate rsa modulus
563 GNUNET_assert (0 == gcry_prime_generate (&p, PAILLIER_BITS / 2, 0, NULL, NULL, NULL, 563 GNUNET_assert (0 == gcry_prime_generate (&p, GNUNET_CRYPTO_PAILLIER_BITS / 2, 0, NULL, NULL, NULL,
564 GCRY_WEAK_RANDOM, 0)); 564 GCRY_WEAK_RANDOM, 0));
565 GNUNET_assert (0 == gcry_prime_generate (&q, PAILLIER_BITS / 2, 0, NULL, NULL, NULL, 565 GNUNET_assert (0 == gcry_prime_generate (&q, GNUNET_CRYPTO_PAILLIER_BITS / 2, 0, NULL, NULL, NULL,
566 GCRY_WEAK_RANDOM, 0)); 566 GCRY_WEAK_RANDOM, 0));
567 } while (0 == gcry_mpi_cmp (p, q)); 567 } while (0 == gcry_mpi_cmp (p, q));
568 gcry_mpi_mul (n, p, q); 568 gcry_mpi_mul (n, p, q);
@@ -606,7 +606,7 @@ paillier_encrypt (gcry_mpi_t c, gcry_mpi_t m, gcry_mpi_t n)
606 // generate r < n 606 // generate r < n
607 do 607 do
608 { 608 {
609 gcry_mpi_randomize (r, PAILLIER_BITS, GCRY_WEAK_RANDOM); 609 gcry_mpi_randomize (r, GNUNET_CRYPTO_PAILLIER_BITS, GCRY_WEAK_RANDOM);
610 } 610 }
611 while (gcry_mpi_cmp (r, n) >= 0); 611 while (gcry_mpi_cmp (r, n) >= 0);
612 612
@@ -798,8 +798,8 @@ keygen_round1_new_element (void *cls,
798 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "keygen commit data with invalid signature in consensus\n"); 798 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "keygen commit data with invalid signature in consensus\n");
799 return; 799 return;
800 } 800 }
801 GNUNET_CRYPTO_mpi_scan_unsigned (&info->paillier_n, &d->pubkey.n, PAILLIER_BITS / 8); 801 GNUNET_CRYPTO_mpi_scan_unsigned (&info->paillier_n, &d->pubkey.n, GNUNET_CRYPTO_PAILLIER_BITS / 8);
802 GNUNET_CRYPTO_mpi_scan_unsigned (&info->presecret_commitment, &d->pubkey.n, PAILLIER_BITS / 8); 802 GNUNET_CRYPTO_mpi_scan_unsigned (&info->presecret_commitment, &d->pubkey.n, GNUNET_CRYPTO_PAILLIER_BITS / 8);
803 info->round1_valid = GNUNET_YES; 803 info->round1_valid = GNUNET_YES;
804} 804}
805 805
@@ -939,7 +939,7 @@ insert_round2_element (struct KeygenSession *ks)
939 element_size = (sizeof (struct GNUNET_SECRETSHARING_KeygenRevealData) + 939 element_size = (sizeof (struct GNUNET_SECRETSHARING_KeygenRevealData) +
940 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers + 940 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers +
941 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->threshold + 941 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->threshold +
942 PAILLIER_BITS * 2 / 8 * ks->num_peers); 942 GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8 * ks->num_peers);
943 943
944 element = GNUNET_malloc (sizeof (struct GNUNET_SET_Element) + element_size); 944 element = GNUNET_malloc (sizeof (struct GNUNET_SET_Element) + element_size);
945 element->size = element_size; 945 element->size = element_size;
@@ -987,8 +987,8 @@ insert_round2_element (struct KeygenSession *ks)
987 // encrypt the result 987 // encrypt the result
988 paillier_encrypt (c, v, ks->info[i].paillier_n); 988 paillier_encrypt (c, v, ks->info[i].paillier_n);
989 } 989 }
990 GNUNET_CRYPTO_mpi_print_unsigned (pos, PAILLIER_BITS * 2 / 8, c); 990 GNUNET_CRYPTO_mpi_print_unsigned (pos, GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8, c);
991 pos += PAILLIER_BITS * 2 / 8; 991 pos += GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8;
992 } 992 }
993 993
994 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: computed enc preshares\n", 994 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "P%u: computed enc preshares\n",
@@ -1038,7 +1038,7 @@ keygen_round2_new_element (void *cls,
1038 1038
1039 expected_element_size = (sizeof (struct GNUNET_SECRETSHARING_KeygenRevealData) + 1039 expected_element_size = (sizeof (struct GNUNET_SECRETSHARING_KeygenRevealData) +
1040 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers + 1040 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers +
1041 PAILLIER_BITS / 8 * 2 * ks->num_peers + 1041 GNUNET_CRYPTO_PAILLIER_BITS / 8 * 2 * ks->num_peers +
1042 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->threshold); 1042 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->threshold);
1043 1043
1044 if (element->size != expected_element_size) 1044 if (element->size != expected_element_size)
@@ -1084,7 +1084,7 @@ keygen_round2_new_element (void *cls,
1084 // skip exponentiated pre-shares 1084 // skip exponentiated pre-shares
1085 pos += GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers; 1085 pos += GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers;
1086 // skip encrypted pre-shares 1086 // skip encrypted pre-shares
1087 pos += PAILLIER_BITS * 2 / 8 * ks->num_peers; 1087 pos += GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8 * ks->num_peers;
1088 // the first exponentiated coefficient is the public key share 1088 // the first exponentiated coefficient is the public key share
1089 GNUNET_CRYPTO_mpi_scan_unsigned (&info->public_key_share, pos, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8); 1089 GNUNET_CRYPTO_mpi_scan_unsigned (&info->public_key_share, pos, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8);
1090 1090
@@ -1092,9 +1092,9 @@ keygen_round2_new_element (void *cls,
1092 // skip exp. pre-shares 1092 // skip exp. pre-shares
1093 pos += GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers; 1093 pos += GNUNET_SECRETSHARING_ELGAMAL_BITS / 8 * ks->num_peers;
1094 // skip to the encrypted value for our peer 1094 // skip to the encrypted value for our peer
1095 pos += PAILLIER_BITS * 2 / 8 * ks->local_peer_idx; 1095 pos += GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8 * ks->local_peer_idx;
1096 1096
1097 GNUNET_CRYPTO_mpi_scan_unsigned (&c, pos, PAILLIER_BITS * 2 / 8); 1097 GNUNET_CRYPTO_mpi_scan_unsigned (&c, pos, GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8);
1098 1098
1099 GNUNET_assert (0 != (info->decrypted_preshare = mpi_new (0))); 1099 GNUNET_assert (0 != (info->decrypted_preshare = mpi_new (0)));
1100 1100
@@ -1177,7 +1177,7 @@ insert_round1_element (struct KeygenSession *ks)
1177 1177
1178 GNUNET_CRYPTO_hash (v_data, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8, &d->commitment); 1178 GNUNET_CRYPTO_hash (v_data, GNUNET_SECRETSHARING_ELGAMAL_BITS / 8, &d->commitment);
1179 1179
1180 GNUNET_CRYPTO_mpi_print_unsigned (d->pubkey.n, PAILLIER_BITS / 8, 1180 GNUNET_CRYPTO_mpi_print_unsigned (d->pubkey.n, GNUNET_CRYPTO_PAILLIER_BITS / 8,
1181 ks->info[ks->local_peer_idx].paillier_n); 1181 ks->info[ks->local_peer_idx].paillier_n);
1182 1182
1183 d->purpose.size = htonl ((sizeof *d) - offsetof (struct GNUNET_SECRETSHARING_KeygenCommitData, purpose)); 1183 d->purpose.size = htonl ((sizeof *d) - offsetof (struct GNUNET_SECRETSHARING_KeygenCommitData, purpose));
diff --git a/src/secretsharing/secretsharing_protocol.h b/src/secretsharing/secretsharing_protocol.h
index 5d833cbb3..3930c1231 100644
--- a/src/secretsharing/secretsharing_protocol.h
+++ b/src/secretsharing/secretsharing_protocol.h
@@ -33,28 +33,11 @@
33#include "gnunet_protocols.h" 33#include "gnunet_protocols.h"
34#include "secretsharing.h" 34#include "secretsharing.h"
35 35
36/**
37 * Bit length used for the Paillier crypto system.
38 */
39#define PAILLIER_BITS 2048
40 36
41GNUNET_NETWORK_STRUCT_BEGIN 37GNUNET_NETWORK_STRUCT_BEGIN
42 38
43 39
44/** 40/**
45 * Public key for the Paillier crypto system.
46 */
47struct PaillierPublicKey
48{
49 /**
50 * Network order representation of the
51 * n-component.
52 */
53 uint32_t n[PAILLIER_BITS / 8 / sizeof (uint32_t)];
54};
55
56
57/**
58 * Consensus element data used in the first round of key generation. 41 * Consensus element data used in the first round of key generation.
59 */ 42 */
60struct GNUNET_SECRETSHARING_KeygenCommitData 43struct GNUNET_SECRETSHARING_KeygenCommitData
@@ -75,7 +58,7 @@ struct GNUNET_SECRETSHARING_KeygenCommitData
75 * Ephemeral paillier public key used by 'peer' for 58 * Ephemeral paillier public key used by 'peer' for
76 * this session. 59 * this session.
77 */ 60 */
78 struct PaillierPublicKey pubkey GNUNET_PACKED; 61 struct GNUNET_CRYPTO_PaillierPublicKey pubkey;
79 /** 62 /**
80 * Commitment of 'peer' to his presecret. 63 * Commitment of 'peer' to his presecret.
81 */ 64 */