aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-11 21:55:36 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-11 21:55:36 +0000
commitaddd20663f6f7ccdd666af0bc07b41c384e956a2 (patch)
tree699b69ec8adde0972ef57b3e7b6737b7ee66ad92 /src/scalarproduct
parentdcc098d1fdefcb74bed0a6ff6f81347500367ab6 (diff)
downloadgnunet-addd20663f6f7ccdd666af0bc07b41c384e956a2.tar.gz
gnunet-addd20663f6f7ccdd666af0bc07b41c384e956a2.zip
-fix bugs
Diffstat (limited to 'src/scalarproduct')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_alice.c14
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_bob.c89
-rwxr-xr-xsrc/scalarproduct/perf_scalarproduct.sh10
-rw-r--r--src/scalarproduct/test_scalarproduct.conf2
4 files changed, 74 insertions, 41 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index be5ae1e13..3642ff09c 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
@@ -861,7 +861,7 @@ element_cmp (const void *a,
861 * Maximum number of elements we can put into a single cryptodata 861 * Maximum number of elements we can put into a single cryptodata
862 * message 862 * message
863 */ 863 */
864#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - sizeof (struct AliceCryptodataMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) 864#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct AliceCryptodataMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
865 865
866 866
867/** 867/**
@@ -911,15 +911,16 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
911 msg->contained_element_count = htonl (todo_count); 911 msg->contained_element_count = htonl (todo_count);
912 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 912 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
913 a = gcry_mpi_new (0); 913 a = gcry_mpi_new (0);
914 for (i = off; i < todo_count; i++) 914 for (i = off; i < off + todo_count; i++)
915 { 915 {
916 gcry_mpi_add (a, 916 gcry_mpi_add (a,
917 s->sorted_elements[i].value, 917 s->sorted_elements[i].value,
918 my_offset); 918 my_offset);
919 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, 919 GNUNET_assert (3 ==
920 a, 920 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey,
921 3, 921 a,
922 &payload[i - off]); 922 3,
923 &payload[i - off]));
923 } 924 }
924 gcry_mpi_release (a); 925 gcry_mpi_release (a);
925 off += todo_count; 926 off += todo_count;
@@ -1321,6 +1322,7 @@ shutdown_task (void *cls,
1321{ 1322{
1322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1323 "Shutting down, initiating cleanup.\n"); 1324 "Shutting down, initiating cleanup.\n");
1325 // FIXME: we have to cut our connections to CADET first!
1324 if (NULL != my_cadet) 1326 if (NULL != my_cadet)
1325 { 1327 {
1326 GNUNET_CADET_disconnect (my_cadet); 1328 GNUNET_CADET_disconnect (my_cadet);
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c
index 2c6d607e5..e4ceecc4e 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c
@@ -542,7 +542,7 @@ bob_cadet_done_cb (void *cls)
542/** 542/**
543 * Maximum count of elements we can put into a multipart message 543 * Maximum count of elements we can put into a multipart message
544 */ 544 */
545#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - sizeof (struct BobCryptodataMultipartMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) 545#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct BobCryptodataMultipartMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
546 546
547 547
548/** 548/**
@@ -615,8 +615,9 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s)
615 struct GNUNET_CRYPTO_PaillierCiphertext *payload; 615 struct GNUNET_CRYPTO_PaillierCiphertext *payload;
616 unsigned int i; 616 unsigned int i;
617 617
618 s->cadet_transmitted_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct BobCryptodataMessage)) / 618 s->cadet_transmitted_element_count
619 (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 2) - 2; 619 = ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct BobCryptodataMessage))
620 / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) / 2) - 1;
620 if (s->cadet_transmitted_element_count > s->used_element_count) 621 if (s->cadet_transmitted_element_count > s->used_element_count)
621 s->cadet_transmitted_element_count = s->used_element_count; 622 s->cadet_transmitted_element_count = s->used_element_count;
622 623
@@ -659,6 +660,7 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s)
659 e); 660 e);
660 transmit_bobs_cryptodata_message_multipart (s); 661 transmit_bobs_cryptodata_message_multipart (s);
661} 662}
663#undef ELEMENT_CAPACITY
662 664
663 665
664/** 666/**
@@ -697,8 +699,9 @@ compute_square_sum (const gcry_mpi_t *vector,
697 * S': $S' := E_A(sum r_i^2)$ 699 * S': $S' := E_A(sum r_i^2)$
698 * 700 *
699 * @param request the requesting session + bob's requesting peer 701 * @param request the requesting session + bob's requesting peer
702 * @return #GNUNET_OK on success
700 */ 703 */
701static void 704static int
702compute_service_response (struct BobServiceSession *session) 705compute_service_response (struct BobServiceSession *session)
703{ 706{
704 uint32_t i; 707 uint32_t i;
@@ -751,16 +754,22 @@ compute_service_response (struct BobServiceSession *session)
751 // E(S - r_pi - b_pi) 754 // E(S - r_pi - b_pi)
752 gcry_mpi_sub (tmp, my_offset, rand[p[i]]); 755 gcry_mpi_sub (tmp, my_offset, rand[p[i]]);
753 gcry_mpi_sub (tmp, tmp, b[p[i]].value); 756 gcry_mpi_sub (tmp, tmp, b[p[i]].value);
754 GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey, 757 GNUNET_assert (2 ==
755 tmp, 758 GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey,
756 2, 759 tmp,
757 &r[i]); 760 2,
761 &r[i]));
758 762
759 // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b) 763 // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b)
760 GNUNET_CRYPTO_paillier_hom_add (&session->cadet->remote_pubkey, 764 if (GNUNET_OK !=
761 &r[i], 765 GNUNET_CRYPTO_paillier_hom_add (&session->cadet->remote_pubkey,
762 &a[p[i]], 766 &r[i],
763 &r[i]); 767 &a[p[i]],
768 &r[i]))
769 {
770 GNUNET_break_op (0);
771 return GNUNET_SYSERR;
772 }
764 } 773 }
765 774
766 // Calculate Kq = E(S + a_qi) (+) E(S - r_qi) 775 // Calculate Kq = E(S + a_qi) (+) E(S - r_qi)
@@ -768,35 +777,43 @@ compute_service_response (struct BobServiceSession *session)
768 { 777 {
769 // E(S - r_qi) 778 // E(S - r_qi)
770 gcry_mpi_sub (tmp, my_offset, rand[q[i]]); 779 gcry_mpi_sub (tmp, my_offset, rand[q[i]]);
771 GNUNET_assert (2 == GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey, 780 GNUNET_assert (2 ==
772 tmp, 781 GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey,
773 2, 782 tmp,
774 &r_prime[i])); 783 2,
784 &r_prime[i]));
775 785
776 // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi) 786 // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi)
777 GNUNET_assert (1 == GNUNET_CRYPTO_paillier_hom_add (&session->cadet->remote_pubkey, 787 if (GNUNET_OK !=
778 &r_prime[i], 788 GNUNET_CRYPTO_paillier_hom_add (&session->cadet->remote_pubkey,
779 &a[q[i]], 789 &r_prime[i],
780 &r_prime[i])); 790 &a[q[i]],
791 &r_prime[i]))
792 {
793 GNUNET_break_op (0);
794 return GNUNET_SYSERR;
795 }
781 } 796 }
782 gcry_mpi_release (tmp); 797 gcry_mpi_release (tmp);
783 798
784 // Calculate S' = E(SUM( r_i^2 )) 799 // Calculate S' = E(SUM( r_i^2 ))
785 tmp = compute_square_sum (rand, count); 800 tmp = compute_square_sum (rand, count);
786 GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey, 801 GNUNET_assert (1 ==
787 tmp, 802 GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey,
788 1, 803 tmp,
789 &session->s_prime); 804 1,
805 &session->s_prime));
790 gcry_mpi_release (tmp); 806 gcry_mpi_release (tmp);
791 807
792 // Calculate S = E(SUM( (r_i + b_i)^2 )) 808 // Calculate S = E(SUM( (r_i + b_i)^2 ))
793 for (i = 0; i < count; i++) 809 for (i = 0; i < count; i++)
794 gcry_mpi_add (rand[i], rand[i], b[i].value); 810 gcry_mpi_add (rand[i], rand[i], b[i].value);
795 tmp = compute_square_sum (rand, count); 811 tmp = compute_square_sum (rand, count);
796 GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey, 812 GNUNET_assert (1 ==
797 tmp, 813 GNUNET_CRYPTO_paillier_encrypt (&session->cadet->remote_pubkey,
798 1, 814 tmp,
799 &session->s); 815 1,
816 &session->s));
800 gcry_mpi_release (tmp); 817 gcry_mpi_release (tmp);
801 818
802 session->r = r; 819 session->r = r;
@@ -810,8 +827,7 @@ compute_service_response (struct BobServiceSession *session)
810 GNUNET_free (p); 827 GNUNET_free (p);
811 GNUNET_free (q); 828 GNUNET_free (q);
812 GNUNET_free (rand); 829 GNUNET_free (rand);
813 830 return GNUNET_OK;
814 // copy the r[], r_prime[], S and Stick into a new message, prepare_service_response frees these
815} 831}
816 832
817 833
@@ -877,6 +893,8 @@ element_cmp (const void *a,
877static void 893static void
878transmit_cryptographic_reply (struct BobServiceSession *s) 894transmit_cryptographic_reply (struct BobServiceSession *s)
879{ 895{
896 struct GNUNET_CADET_Channel *channel;
897
880 /* TODO: code duplication with Alice! */ 898 /* TODO: code duplication with Alice! */
881 LOG (GNUNET_ERROR_TYPE_DEBUG, 899 LOG (GNUNET_ERROR_TYPE_DEBUG,
882 "Received everything, building reply for Alice\n"); 900 "Received everything, building reply for Alice\n");
@@ -891,7 +909,14 @@ transmit_cryptographic_reply (struct BobServiceSession *s)
891 s->used_element_count, 909 s->used_element_count,
892 sizeof (struct MpiElement), 910 sizeof (struct MpiElement),
893 &element_cmp); 911 &element_cmp);
894 compute_service_response (s); 912 if (GNUNET_OK !=
913 compute_service_response (s))
914 {
915 channel = s->cadet->channel;
916 s->cadet->channel = NULL;
917 GNUNET_CADET_channel_destroy (channel);
918 return;
919 }
895 transmit_bobs_cryptodata_message (s); 920 transmit_bobs_cryptodata_message (s);
896} 921}
897 922
@@ -1421,7 +1446,7 @@ shutdown_task (void *cls,
1421{ 1446{
1422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1423 "Shutting down, initiating cleanup.\n"); 1448 "Shutting down, initiating cleanup.\n");
1424 // FIXME: do we have to cut our connections to CADET first? 1449 // FIXME: we have to cut our connections to CADET first!
1425 if (NULL != my_cadet) 1450 if (NULL != my_cadet)
1426 { 1451 {
1427 GNUNET_CADET_disconnect (my_cadet); 1452 GNUNET_CADET_disconnect (my_cadet);
diff --git a/src/scalarproduct/perf_scalarproduct.sh b/src/scalarproduct/perf_scalarproduct.sh
index 8e356dbc2..29b7b0f3f 100755
--- a/src/scalarproduct/perf_scalarproduct.sh
+++ b/src/scalarproduct/perf_scalarproduct.sh
@@ -2,13 +2,15 @@
2# Computes a simple scalar product, with configurable vector size. 2# Computes a simple scalar product, with configurable vector size.
3# 3#
4# Some results: 4# Some results:
5# SIZE TIME(s) 5# SIZE TIME-H(s) TIME-O(s)
6# 25 10 6# 25 10
7# 50 17 7# 50 17
8# 100 32 8# 100 32 39
9# 200 77
10#
9# 11#
10# Configure benchmark size: 12# Configure benchmark size:
11SIZE=1000 13SIZE=400
12# 14#
13# Construct input vectors: 15# Construct input vectors:
14INPUTALICE="-k CCC -e '" 16INPUTALICE="-k CCC -e '"
@@ -45,6 +47,8 @@ PEERIDBOB=`gnunet-peerinfo -qs $CFGBOB`
45echo "Running problem of size $SIZE" 47echo "Running problem of size $SIZE"
46gnunet-scalarproduct $CFGBOB $INPUTBOB & 48gnunet-scalarproduct $CFGBOB $INPUTBOB &
47time RESULT=`gnunet-scalarproduct $CFGALICE $INPUTALICE -p $PEERIDBOB` 49time RESULT=`gnunet-scalarproduct $CFGALICE $INPUTALICE -p $PEERIDBOB`
50gnunet-statistics $CFGALICE -s core | grep "bytes encrypted"
51gnunet-statistics $CFGBOB -s core | grep "bytes encrypted"
48 52
49echo "Terminating testbed..." 53echo "Terminating testbed..."
50# terminate the testbed 54# terminate the testbed
diff --git a/src/scalarproduct/test_scalarproduct.conf b/src/scalarproduct/test_scalarproduct.conf
index ffa6336af..1df495bba 100644
--- a/src/scalarproduct/test_scalarproduct.conf
+++ b/src/scalarproduct/test_scalarproduct.conf
@@ -1,3 +1,5 @@
1@INLINE@ ../../contrib/no_forcestart.conf
2
1[PATHS] 3[PATHS]
2GNUNET_TEST_HOME = /tmp/test-scalarproduct/ 4GNUNET_TEST_HOME = /tmp/test-scalarproduct/
3 5