diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-09-11 12:34:09 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-09-11 12:34:09 +0000 |
commit | 80a32a99b3710d373581a40ddb98b34546d4b98d (patch) | |
tree | 59fc5618e68fe4d25641ff685dba86b194662a26 /src/scalarproduct | |
parent | 3ff6d178dfd39dd4a3d384f525b241c0064322ca (diff) | |
download | gnunet-80a32a99b3710d373581a40ddb98b34546d4b98d.tar.gz gnunet-80a32a99b3710d373581a40ddb98b34546d4b98d.zip |
SP-service: converted integer types from 16 to 32bit unsigned whereever needed
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index ac2ee5a12..fae568637 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -116,18 +116,18 @@ struct ServiceSession | |||
116 | /** | 116 | /** |
117 | * how many elements we were supplied with from the client | 117 | * how many elements we were supplied with from the client |
118 | */ | 118 | */ |
119 | uint16_t element_count; | 119 | uint32_t element_count; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * how many elements actually are used after applying the mask | 122 | * how many elements actually are used after applying the mask |
123 | */ | 123 | */ |
124 | uint16_t used_element_count; | 124 | uint32_t used_element_count; |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * how many bytes the mask is long. | 127 | * how many bytes the mask is long. |
128 | * just for convenience so we don't have to re-re-re calculate it each time | 128 | * just for convenience so we don't have to re-re-re calculate it each time |
129 | */ | 129 | */ |
130 | uint16_t mask_length; | 130 | uint32_t mask_length; |
131 | 131 | ||
132 | /** | 132 | /** |
133 | * all the vector elements we received | 133 | * all the vector elements we received |
@@ -197,7 +197,7 @@ static unsigned char * my_pubkey_external; | |||
197 | /** | 197 | /** |
198 | * Service's own public key represented as string | 198 | * Service's own public key represented as string |
199 | */ | 199 | */ |
200 | static uint16_t my_pubkey_external_length = 0; | 200 | static uint32_t my_pubkey_external_length = 0; |
201 | 201 | ||
202 | /** | 202 | /** |
203 | * Service's own n | 203 | * Service's own n |
@@ -459,7 +459,7 @@ decrypt_element (gcry_mpi_t m, gcry_mpi_t c, gcry_mpi_t mu, gcry_mpi_t lambda, g | |||
459 | * @return an MPI value containing the calculated sum, never NULL | 459 | * @return an MPI value containing the calculated sum, never NULL |
460 | */ | 460 | */ |
461 | static gcry_mpi_t | 461 | static gcry_mpi_t |
462 | compute_square_sum (gcry_mpi_t * vector, uint16_t length) | 462 | compute_square_sum (gcry_mpi_t * vector, uint32_t length) |
463 | { | 463 | { |
464 | gcry_mpi_t elem; | 464 | gcry_mpi_t elem; |
465 | gcry_mpi_t sum; | 465 | gcry_mpi_t sum; |
@@ -530,7 +530,7 @@ do_send_message (void *cls, size_t size, void *buf) | |||
530 | * @return the initialized vector, never NULL | 530 | * @return the initialized vector, never NULL |
531 | */ | 531 | */ |
532 | static gcry_mpi_t * | 532 | static gcry_mpi_t * |
533 | initialize_mpi_vector (uint16_t length) | 533 | initialize_mpi_vector (uint32_t length) |
534 | { | 534 | { |
535 | uint32_t i; | 535 | uint32_t i; |
536 | gcry_mpi_t * output = GNUNET_malloc (sizeof (gcry_mpi_t) * length); | 536 | gcry_mpi_t * output = GNUNET_malloc (sizeof (gcry_mpi_t) * length); |
@@ -577,7 +577,7 @@ permute_vector (gcry_mpi_t * vector, | |||
577 | * @return an array of MPI values with random values | 577 | * @return an array of MPI values with random values |
578 | */ | 578 | */ |
579 | static gcry_mpi_t * | 579 | static gcry_mpi_t * |
580 | generate_random_vector (uint16_t length) | 580 | generate_random_vector (uint32_t length) |
581 | { | 581 | { |
582 | gcry_mpi_t * random_vector; | 582 | gcry_mpi_t * random_vector; |
583 | int32_t value; | 583 | int32_t value; |
@@ -613,7 +613,7 @@ generate_random_vector (uint16_t length) | |||
613 | static struct ServiceSession * | 613 | static struct ServiceSession * |
614 | find_matching_session (struct ServiceSession * tail, | 614 | find_matching_session (struct ServiceSession * tail, |
615 | const struct GNUNET_HashCode * key, | 615 | const struct GNUNET_HashCode * key, |
616 | uint16_t element_count, | 616 | uint32_t element_count, |
617 | enum SessionState * state, | 617 | enum SessionState * state, |
618 | const struct GNUNET_PeerIdentity * peerid) | 618 | const struct GNUNET_PeerIdentity * peerid) |
619 | { | 619 | { |
@@ -796,7 +796,7 @@ prepare_service_response (gcry_mpi_t * r, | |||
796 | struct ServiceSession * response) | 796 | struct ServiceSession * response) |
797 | { | 797 | { |
798 | struct GNUNET_SCALARPRODUCT_service_response * msg; | 798 | struct GNUNET_SCALARPRODUCT_service_response * msg; |
799 | uint16_t msg_length = 0; | 799 | uint32_t msg_length = 0; |
800 | unsigned char * current = NULL; | 800 | unsigned char * current = NULL; |
801 | unsigned char * element_exported = NULL; | 801 | unsigned char * element_exported = NULL; |
802 | size_t element_length = 0; | 802 | size_t element_length = 0; |
@@ -810,8 +810,8 @@ prepare_service_response (gcry_mpi_t * r, | |||
810 | 810 | ||
811 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_TO_ALICE); | 811 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_TO_ALICE); |
812 | msg->header.size = htons (msg_length); | 812 | msg->header.size = htons (msg_length); |
813 | msg->element_count = htons (request->element_count); | 813 | msg->element_count = htonl (request->element_count); |
814 | msg->used_element_count = htons (request->used_element_count); | 814 | msg->used_element_count = htonl (request->used_element_count); |
815 | memcpy (&msg->key, &request->key, sizeof (struct GNUNET_HashCode)); | 815 | memcpy (&msg->key, &request->key, sizeof (struct GNUNET_HashCode)); |
816 | current = (unsigned char *) &msg[1]; | 816 | current = (unsigned char *) &msg[1]; |
817 | 817 | ||
@@ -925,7 +925,7 @@ compute_service_response (struct ServiceSession * request, | |||
925 | int ret = GNUNET_SYSERR; | 925 | int ret = GNUNET_SYSERR; |
926 | unsigned int * p; | 926 | unsigned int * p; |
927 | unsigned int * q; | 927 | unsigned int * q; |
928 | uint16_t count; | 928 | uint32_t count; |
929 | gcry_mpi_t * rand = NULL; | 929 | gcry_mpi_t * rand = NULL; |
930 | gcry_mpi_t * r = NULL; | 930 | gcry_mpi_t * r = NULL; |
931 | gcry_mpi_t * r_prime = NULL; | 931 | gcry_mpi_t * r_prime = NULL; |
@@ -1134,7 +1134,7 @@ prepare_service_request (void *cls, | |||
1134 | struct GNUNET_SCALARPRODUCT_service_request * msg; | 1134 | struct GNUNET_SCALARPRODUCT_service_request * msg; |
1135 | unsigned int i; | 1135 | unsigned int i; |
1136 | unsigned int j; | 1136 | unsigned int j; |
1137 | uint16_t msg_length; | 1137 | uint32_t msg_length; |
1138 | size_t element_length = 0; // initialized by gcry_mpi_print, but the compiler doesn't know that | 1138 | size_t element_length = 0; // initialized by gcry_mpi_print, but the compiler doesn't know that |
1139 | gcry_mpi_t a; | 1139 | gcry_mpi_t a; |
1140 | uint32_t value; | 1140 | uint32_t value; |
@@ -1163,10 +1163,10 @@ prepare_service_request (void *cls, | |||
1163 | msg = GNUNET_malloc (msg_length); | 1163 | msg = GNUNET_malloc (msg_length); |
1164 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_TO_BOB); | 1164 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_TO_BOB); |
1165 | memcpy (&msg->key, &session->key, sizeof (struct GNUNET_HashCode)); | 1165 | memcpy (&msg->key, &session->key, sizeof (struct GNUNET_HashCode)); |
1166 | msg->mask_length = htons (session->mask_length); | 1166 | msg->mask_length = htonl (session->mask_length); |
1167 | msg->pk_length = htons (my_pubkey_external_length); | 1167 | msg->pk_length = htonl (my_pubkey_external_length); |
1168 | msg->used_element_count = htons (session->used_element_count); | 1168 | msg->used_element_count = htonl (session->used_element_count); |
1169 | msg->element_count = htons (session->element_count); | 1169 | msg->element_count = htonl (session->element_count); |
1170 | msg->header.size = htons (msg_length); | 1170 | msg->header.size = htons (msg_length); |
1171 | 1171 | ||
1172 | // fill in the payload | 1172 | // fill in the payload |
@@ -1257,9 +1257,9 @@ handle_client_request (void *cls, | |||
1257 | { | 1257 | { |
1258 | const struct GNUNET_SCALARPRODUCT_client_request * msg = (const struct GNUNET_SCALARPRODUCT_client_request *) message; | 1258 | const struct GNUNET_SCALARPRODUCT_client_request * msg = (const struct GNUNET_SCALARPRODUCT_client_request *) message; |
1259 | struct ServiceSession * session; | 1259 | struct ServiceSession * session; |
1260 | uint16_t element_count; | 1260 | uint32_t element_count; |
1261 | uint16_t mask_length; | 1261 | uint32_t mask_length; |
1262 | uint16_t msg_type; | 1262 | uint32_t msg_type; |
1263 | int32_t * vector; | 1263 | int32_t * vector; |
1264 | uint32_t i; | 1264 | uint32_t i; |
1265 | 1265 | ||
@@ -1285,8 +1285,8 @@ handle_client_request (void *cls, | |||
1285 | } | 1285 | } |
1286 | 1286 | ||
1287 | msg_type = ntohs (msg->header.type); | 1287 | msg_type = ntohs (msg->header.type); |
1288 | element_count = ntohs (msg->element_count); | 1288 | element_count = ntohl (msg->element_count); |
1289 | mask_length = ntohs (msg->mask_length); | 1289 | mask_length = ntohl (msg->mask_length); |
1290 | 1290 | ||
1291 | //sanity check: is the message as long as the message_count fields suggests? | 1291 | //sanity check: is the message as long as the message_count fields suggests? |
1292 | if (( ntohs (msg->header.size) != (sizeof (struct GNUNET_SCALARPRODUCT_client_request) + element_count * sizeof (int32_t) + mask_length)) | 1292 | if (( ntohs (msg->header.size) != (sizeof (struct GNUNET_SCALARPRODUCT_client_request) + element_count * sizeof (int32_t) + mask_length)) |
@@ -1544,7 +1544,7 @@ static gcry_mpi_t | |||
1544 | compute_scalar_product (struct ServiceSession * session, | 1544 | compute_scalar_product (struct ServiceSession * session, |
1545 | gcry_mpi_t * r, gcry_mpi_t * r_prime, gcry_mpi_t s, gcry_mpi_t s_prime) | 1545 | gcry_mpi_t * r, gcry_mpi_t * r_prime, gcry_mpi_t s, gcry_mpi_t s_prime) |
1546 | { | 1546 | { |
1547 | uint16_t count; | 1547 | uint32_t count; |
1548 | gcry_mpi_t t; | 1548 | gcry_mpi_t t; |
1549 | gcry_mpi_t u; | 1549 | gcry_mpi_t u; |
1550 | gcry_mpi_t utick; | 1550 | gcry_mpi_t utick; |
@@ -1631,7 +1631,7 @@ prepare_client_response (void *cls, | |||
1631 | struct GNUNET_SCALARPRODUCT_client_response * msg; | 1631 | struct GNUNET_SCALARPRODUCT_client_response * msg; |
1632 | unsigned char * product_exported = NULL; | 1632 | unsigned char * product_exported = NULL; |
1633 | size_t product_length = 0; | 1633 | size_t product_length = 0; |
1634 | uint16_t msg_length = 0; | 1634 | uint32_t msg_length = 0; |
1635 | int8_t range = -1; | 1635 | int8_t range = -1; |
1636 | gcry_error_t rc; | 1636 | gcry_error_t rc; |
1637 | int sign; | 1637 | int sign; |
@@ -1729,11 +1729,11 @@ handle_service_request (void *cls, | |||
1729 | { | 1729 | { |
1730 | struct ServiceSession * session; | 1730 | struct ServiceSession * session; |
1731 | const struct GNUNET_SCALARPRODUCT_service_request * msg = (const struct GNUNET_SCALARPRODUCT_service_request *) message; | 1731 | const struct GNUNET_SCALARPRODUCT_service_request * msg = (const struct GNUNET_SCALARPRODUCT_service_request *) message; |
1732 | uint16_t mask_length; | 1732 | uint32_t mask_length; |
1733 | uint16_t pk_length; | 1733 | uint32_t pk_length; |
1734 | uint16_t used_elements; | 1734 | uint32_t used_elements; |
1735 | uint16_t element_count; | 1735 | uint32_t element_count; |
1736 | uint16_t msg_length; | 1736 | uint32_t msg_length; |
1737 | unsigned char * current; | 1737 | unsigned char * current; |
1738 | struct ServiceSession * responder_session; | 1738 | struct ServiceSession * responder_session; |
1739 | int32_t i = -1; | 1739 | int32_t i = -1; |
@@ -1765,10 +1765,10 @@ handle_service_request (void *cls, | |||
1765 | GNUNET_break_op(0); | 1765 | GNUNET_break_op(0); |
1766 | return GNUNET_SYSERR; | 1766 | return GNUNET_SYSERR; |
1767 | } | 1767 | } |
1768 | mask_length = ntohs (msg->mask_length); | 1768 | mask_length = ntohl (msg->mask_length); |
1769 | pk_length = ntohs (msg->pk_length); | 1769 | pk_length = ntohl (msg->pk_length); |
1770 | used_elements = ntohs (msg->used_element_count); | 1770 | used_elements = ntohl (msg->used_element_count); |
1771 | element_count = ntohs (msg->element_count); | 1771 | element_count = ntohl (msg->element_count); |
1772 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_service_request) | 1772 | msg_length = sizeof (struct GNUNET_SCALARPRODUCT_service_request) |
1773 | + mask_length + pk_length + used_elements * PAILLIER_ELEMENT_LENGTH; | 1773 | + mask_length + pk_length + used_elements * PAILLIER_ELEMENT_LENGTH; |
1774 | 1774 | ||
@@ -1794,7 +1794,7 @@ handle_service_request (void *cls, | |||
1794 | 1794 | ||
1795 | memcpy (&session->peer, &session->peer, sizeof (struct GNUNET_PeerIdentity)); | 1795 | memcpy (&session->peer, &session->peer, sizeof (struct GNUNET_PeerIdentity)); |
1796 | session->state = SERVICE_REQUEST_RECEIVED; | 1796 | session->state = SERVICE_REQUEST_RECEIVED; |
1797 | session->element_count = ntohs (msg->element_count); | 1797 | session->element_count = ntohl (msg->element_count); |
1798 | session->used_element_count = used_elements; | 1798 | session->used_element_count = used_elements; |
1799 | session->tunnel = tunnel; | 1799 | session->tunnel = tunnel; |
1800 | 1800 | ||
@@ -1913,12 +1913,12 @@ handle_service_response (void *cls, | |||
1913 | struct ServiceSession * session; | 1913 | struct ServiceSession * session; |
1914 | const struct GNUNET_SCALARPRODUCT_service_response * msg = (const struct GNUNET_SCALARPRODUCT_service_response *) message; | 1914 | const struct GNUNET_SCALARPRODUCT_service_response * msg = (const struct GNUNET_SCALARPRODUCT_service_response *) message; |
1915 | unsigned char * current; | 1915 | unsigned char * current; |
1916 | uint16_t count; | 1916 | uint32_t count; |
1917 | gcry_mpi_t s = NULL; | 1917 | gcry_mpi_t s = NULL; |
1918 | gcry_mpi_t s_prime = NULL; | 1918 | gcry_mpi_t s_prime = NULL; |
1919 | size_t read; | 1919 | size_t read; |
1920 | size_t i; | 1920 | size_t i; |
1921 | uint16_t used_element_count; | 1921 | uint32_t used_element_count; |
1922 | size_t msg_size; | 1922 | size_t msg_size; |
1923 | gcry_mpi_t * r = NULL; | 1923 | gcry_mpi_t * r = NULL; |
1924 | gcry_mpi_t * r_prime = NULL; | 1924 | gcry_mpi_t * r_prime = NULL; |
@@ -1941,7 +1941,7 @@ handle_service_response (void *cls, | |||
1941 | GNUNET_break_op (0); | 1941 | GNUNET_break_op (0); |
1942 | goto invalid_msg; | 1942 | goto invalid_msg; |
1943 | } | 1943 | } |
1944 | used_element_count = ntohs (msg->used_element_count); | 1944 | used_element_count = ntohl (msg->used_element_count); |
1945 | msg_size = sizeof (struct GNUNET_SCALARPRODUCT_service_response) | 1945 | msg_size = sizeof (struct GNUNET_SCALARPRODUCT_service_response) |
1946 | + 2 * used_element_count * PAILLIER_ELEMENT_LENGTH | 1946 | + 2 * used_element_count * PAILLIER_ELEMENT_LENGTH |
1947 | + 2 * PAILLIER_ELEMENT_LENGTH; | 1947 | + 2 * PAILLIER_ELEMENT_LENGTH; |