diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-12-03 15:57:46 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-12-03 15:57:46 +0000 |
commit | 7aea8ca731b62c1c80429513f0825310c057e307 (patch) | |
tree | 967ff1477b44e8ce25e435f363549ff688b37270 /src | |
parent | c14a26c3132b1913bb22a2f83a88cf30b8d66de3 (diff) | |
download | gnunet-7aea8ca731b62c1c80429513f0825310c057e307.tar.gz gnunet-7aea8ca731b62c1c80429513f0825310c057e307.zip |
allocate r and r_prime MPIs before use
Diffstat (limited to 'src')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index 39274e4d4..18f243e5d 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -352,7 +352,8 @@ struct ServiceSession | |||
352 | uint32_t total; | 352 | uint32_t total; |
353 | 353 | ||
354 | /** | 354 | /** |
355 | * how many elements actually are used for the scalar product | 355 | * how many elements actually are used for the scalar product. |
356 | * Size of the arrays in @e r and @e r_prime. | ||
356 | */ | 357 | */ |
357 | uint32_t used_element_count; | 358 | uint32_t used_element_count; |
358 | 359 | ||
@@ -497,6 +498,7 @@ static void | |||
497 | free_session_variables (struct ServiceSession *s) | 498 | free_session_variables (struct ServiceSession *s) |
498 | { | 499 | { |
499 | struct SortedValue *e; | 500 | struct SortedValue *e; |
501 | |||
500 | while (NULL != (e = s->a_head)) | 502 | while (NULL != (e = s->a_head)) |
501 | { | 503 | { |
502 | GNUNET_free (e->elem); | 504 | GNUNET_free (e->elem); |
@@ -949,8 +951,8 @@ prepare_bobs_cryptodata_message (void *cls, | |||
949 | struct ServiceSession * s = cls; | 951 | struct ServiceSession * s = cls; |
950 | struct ServiceResponseMessage *msg; | 952 | struct ServiceResponseMessage *msg; |
951 | uint32_t msg_length = 0; | 953 | uint32_t msg_length = 0; |
952 | struct GNUNET_CRYPTO_PaillierCiphertext * payload; | 954 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; |
953 | int i; | 955 | unsigned int i; |
954 | 956 | ||
955 | msg_length = sizeof (struct ServiceResponseMessage) | 957 | msg_length = sizeof (struct ServiceResponseMessage) |
956 | + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); // s, stick | 958 | + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); // s, stick |
@@ -1019,7 +1021,7 @@ prepare_bobs_cryptodata_message (void *cls, | |||
1019 | s->response->client_notification_task = | 1021 | s->response->client_notification_task = |
1020 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1022 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1021 | s->response); | 1023 | s->response); |
1022 | free_session_variables(s); | 1024 | free_session_variables (s); |
1023 | GNUNET_free(s); | 1025 | GNUNET_free(s); |
1024 | return; | 1026 | return; |
1025 | } | 1027 | } |
@@ -1082,12 +1084,11 @@ compute_service_response (struct ServiceSession *session) | |||
1082 | 1084 | ||
1083 | svalue = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1085 | svalue = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1084 | UINT32_MAX); | 1086 | UINT32_MAX); |
1085 | |||
1086 | // long to gcry_mpi_t | 1087 | // long to gcry_mpi_t |
1087 | if (svalue < 0) | 1088 | if (svalue < 0) |
1088 | gcry_mpi_sub_ui (rand[i], | 1089 | gcry_mpi_sub_ui (rand[i], |
1089 | rand[i], | 1090 | rand[i], |
1090 | -svalue); | 1091 | - svalue); |
1091 | else | 1092 | else |
1092 | rand[i] = gcry_mpi_set_ui (rand[i], svalue); | 1093 | rand[i] = gcry_mpi_set_ui (rand[i], svalue); |
1093 | } | 1094 | } |
@@ -1116,7 +1117,8 @@ compute_service_response (struct ServiceSession *session) | |||
1116 | } | 1117 | } |
1117 | 1118 | ||
1118 | // Calculate Kq = E(S + a_qi) (+) E(S - r_qi) | 1119 | // Calculate Kq = E(S + a_qi) (+) E(S - r_qi) |
1119 | for (i = 0; i < count; i++) { | 1120 | for (i = 0; i < count; i++) |
1121 | { | ||
1120 | // E(S - r_qi) | 1122 | // E(S - r_qi) |
1121 | gcry_mpi_sub (tmp, my_offset, rand[q[i]]); | 1123 | gcry_mpi_sub (tmp, my_offset, rand[q[i]]); |
1122 | GNUNET_assert (2 == GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, | 1124 | GNUNET_assert (2 == GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, |
@@ -2026,12 +2028,14 @@ compute_scalar_product (struct ServiceSession *session) | |||
2026 | // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) | 2028 | // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) |
2027 | for (i = 0; i < count; i++) | 2029 | for (i = 0; i < count; i++) |
2028 | { | 2030 | { |
2031 | r[i] = gcry_mpi_new (0); | ||
2029 | GNUNET_CRYPTO_paillier_decrypt (&my_privkey, | 2032 | GNUNET_CRYPTO_paillier_decrypt (&my_privkey, |
2030 | &my_pubkey, | 2033 | &my_pubkey, |
2031 | &session->r[i], | 2034 | &session->r[i], |
2032 | r[i]); | 2035 | r[i]); |
2033 | gcry_mpi_sub (r[i], r[i], my_offset); | 2036 | gcry_mpi_sub (r[i], r[i], my_offset); |
2034 | gcry_mpi_sub (r[i], r[i], my_offset); | 2037 | gcry_mpi_sub (r[i], r[i], my_offset); |
2038 | r_prime[i] = gcry_mpi_new (0); | ||
2035 | GNUNET_CRYPTO_paillier_decrypt (&my_privkey, | 2039 | GNUNET_CRYPTO_paillier_decrypt (&my_privkey, |
2036 | &my_pubkey, | 2040 | &my_pubkey, |
2037 | &session->r_prime[i], | 2041 | &session->r_prime[i], |