From 468ddd6b1efe7608c1fc123fd2351c80d0de89fb Mon Sep 17 00:00:00 2001 From: Michael Zohner Date: Tue, 9 Jun 2015 17:46:50 +0200 Subject: [PATCH] Debugging --- Makefile | 2 +- README.md | 2 +- src/hashing/hashing_util.h | 10 +++++++++- src/mains/test_psi.cpp | 15 ++++++--------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 20bef60..0951e70 100644 --- a/Makefile +++ b/Makefile @@ -72,7 +72,7 @@ bench: demo: ${CC} -o demo.exe ${SRC}/mains/psi_demo.cpp ${OBJECTS_DHPSI} ${OBJECTS_OTPSI} ${OBJECTS_NAIVE} ${OBJECTS_SERVERAIDED} ${OBJECTS_UTIL} ${OBJECTS_HASHING} ${OBJECTS_CRYPTO} ${OBJECTS_OT} ${OBJECTS_MIRACL} ${CFLAGS} ${DEBUG_OPTIONS} ${LIBRARIES} ${MIRACL_LIB} ${INCLUDE} ${COMPILER_OPTIONS} -test: +test: core ${CC} -o test.exe ${SRC}/mains/test_psi.cpp ${OBJECTS_DHPSI} ${OBJECTS_OTPSI} ${OBJECTS_NAIVE} ${OBJECTS_SERVERAIDED} ${OBJECTS_UTIL} ${OBJECTS_HASHING} ${OBJECTS_CRYPTO} ${OBJECTS_OT} ${OBJECTS_MIRACL} ${CFLAGS} ${DEBUG_OPTIONS} ${LIBRARIES} ${MIRACL_LIB} ${INCLUDE} ${COMPILER_OPTIONS} ./test.exe -r 0 -t 10 & ./test.exe -r 1 -t 10 diff --git a/README.md b/README.md index aef6297..b973370 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ WARNING: Some tests can still fail since the code is currently being debugged. ### Generating Random Email Adresses -Further random email adresses can be generated by navigating to `/sample_sets/emailgenerator/` and invoking: +Further random email adresses can be generated by navigating to `sample_sets/emailgenerator/` and invoking: ``` ./emailgenerator.py "number_of_emails" diff --git a/src/hashing/hashing_util.h b/src/hashing/hashing_util.h index 99223d1..7e38e99 100644 --- a/src/hashing/hashing_util.h +++ b/src/hashing/hashing_util.h @@ -35,6 +35,7 @@ typedef struct hashing_state_ctx { uint32_t addrbytelen; uint32_t outbytelen; uint32_t* address_used; + uint32_t mask; } hs_t; //TODO: generate these randomly for each execution and communicate them between the parties @@ -102,6 +103,10 @@ static void init_hashing_state(hs_t* hs, uint32_t nelements, uint32_t inbitlen, } //cout << "nhfvals = " << hs->nhfvals << endl; hs->address_used = (uint32_t*) calloc(nbins, sizeof(uint32_t)); + hs->mask = 0xFFFFFFFF; + if(hs->inbytelen < sizeof(uint32_t)) { + hs->mask >>= (sizeof(uint32_t) * 8 - hs->inbitlen - hs->addrbitlen); + } } static void free_hashing_state(hs_t* hs) { @@ -134,6 +139,8 @@ inline void hashElement(uint8_t* element, uint32_t* address, uint8_t* val, hs_t* //Store the remaining hs->outbitlen bits in R and pad correspondingly R = (*((uint32_t*) element) & SELECT_BITS_INV[hs->addrbitlen]) >> (hs->addrbitlen); + R &= hs->mask;//mask = (1<<32-hs->addrbitlen) + //assert(R < (1<outbitlen)); //cout << "R = " << R << endl; @@ -170,7 +177,7 @@ inline void hashElement(uint8_t* element, uint32_t* address, uint8_t* val, hs_t* //TODO copy remaining bits //if(hs->outbytelen >= sizeof(uint32_t)) - if(hs->outbitlen + hs->addrbitlen >= sizeof(uint32_t) * 8) { + if(hs->inbitlen > sizeof(uint32_t) * 8) { //memcpy(val + (sizeof(uint32_t) - hs->addrbytelen), element + sizeof(uint32_t), hs->outbytelen - (sizeof(uint32_t) - hs->addrbytelen)); memcpy(val + (sizeof(uint32_t) - (hs->addrbitlen >>3)), element + sizeof(uint32_t), hs->outbytelen - (sizeof(uint32_t) - (hs->addrbitlen >>3))); @@ -189,6 +196,7 @@ inline void hashElement(uint8_t* element, uint32_t* address, uint8_t* val, hs_t* cout << (dec) << endl;*/ } + #endif //cout << "Address for hfid = " << hfid << ": " << *address << ", L = " << L << ", R = " << R << endl; diff --git a/src/mains/test_psi.cpp b/src/mains/test_psi.cpp index 6079b70..3ab0d35 100644 --- a/src/mains/test_psi.cpp +++ b/src/mains/test_psi.cpp @@ -41,7 +41,7 @@ int32_t main(int32_t argc, char** argv) { if(role == CLIENT) cout << endl; } - cout << "All tests successfully passed" << endl; + if(role == CLIENT) cout << "All tests successfully passed" << endl; } @@ -56,7 +56,7 @@ uint32_t test_psi_prot(role_type role, CSocket* sock, uint32_t nelements, pnelements = set_up_parameters(role, nelements, &elebytelen, &elements, &pelements, sock[0], crypt); - + if(role == CLIENT) cout << " (|A|: " << nelements << ", |B|: " << pnelements << ", b: " << elebytelen << "): " << std::flush; p_inter_size = plaintext_intersect(nelements, pnelements, elebytelen, elements, pelements, @@ -102,13 +102,13 @@ uint32_t test_psi_prot(role_type role, CSocket* sock, uint32_t nelements, cout << "\t" << ot_inter_size << " elements in OT intersection" << endl; cout << "Plaintext intersection (" << p_inter_size << "): " << endl; - plot_set(p_intersection, p_inter_size, elebytelen); + //plot_set(p_intersection, p_inter_size, elebytelen); cout << "Naive intersection (" << n_inter_size << "): " << endl; - plot_set(n_intersection, n_inter_size, elebytelen); + //plot_set(n_intersection, n_inter_size, elebytelen); cout << "DH intersection (" << dh_inter_size << "): " << endl; - plot_set(dh_intersection, dh_inter_size, elebytelen); + //plot_set(dh_intersection, dh_inter_size, elebytelen); cout << "OT intersection: (" << ot_inter_size << "): " << endl; - plot_set(ot_intersection, ot_inter_size, elebytelen); + //plot_set(ot_intersection, ot_inter_size, elebytelen); } if(p_inter_size > 0) @@ -123,7 +123,6 @@ uint32_t test_psi_prot(role_type role, CSocket* sock, uint32_t nelements, assert(success); } - free(elements); free(pelements); @@ -220,8 +219,6 @@ uint32_t set_up_parameters(role_type role, uint32_t myneles, uint32_t* mybytelen sock.Send(*elements, myneles * *mybytelen); } - - //memset(*elements, 0x00, *mybytelen); //memset(*pelements, 0x00, *mybytelen);