From 70eb75867e9ec1244d4b3d4b947c176269453b48 Mon Sep 17 00:00:00 2001 From: Michael Zohner Date: Fri, 22 May 2015 16:24:54 +0200 Subject: [PATCH] Integrated server-aided PSI protocol --- README.md | 2 +- src/util/crypto/crypto.cpp | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ca8194d..f526bc1 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ This should print the following output in the second terminal: These commands will run the naive hashing protocol and compute the intersection on the 1024 randomly generated emails in sample_sets/emails_alice.txt and sample_sets/emails_bob.txt (where 3 intersecting elements were altered). To use a different protocol, the ['-p'] option can be varied as follows: * `-p 0`: the naive hashing protocol - * `-p 1`: the server-aided protocol of [2]. CURRENTLY NOT WORKING + * `-p 1`: the server-aided protocol of [2] * `-p 2`: the Diffie-Hellman-based PSI protocol of [3] * `-p 3`: the OT-based PSI protocol of [1] diff --git a/src/util/crypto/crypto.cpp b/src/util/crypto/crypto.cpp index 4e0148e..b465c0c 100644 --- a/src/util/crypto/crypto.cpp +++ b/src/util/crypto/crypto.cpp @@ -110,11 +110,23 @@ void crypto::gen_rnd(uint8_t* resbuf, uint32_t nbytes) { free(tmpbuf);*/ } - - - void crypto::gen_rnd_uniform(uint8_t* resbuf, uint64_t mod) { - //TODO: implement + //pad to multiple of 4 bytes for uint32_t length + uint32_t nrndbytes = pad_to_multiple(ceil_divide(secparam.symbits, 8) + ceil_log2(mod), sizeof(uint32_t)); + uint64_t bitsint = (8*sizeof(uint32_t)); + uint32_t rnditers = ceil_divide(nrndbytes * 8, bitsint); + + uint32_t* rndbuf = (uint32_t*) malloc(nrndbytes); + gen_rnd((uint8_t*) rndbuf, nrndbytes); + + uint64_t tmpval = 0, tmpmod = mod; + + for(uint32_t i = 0; i < rnditers; i++) { + tmpval = (((uint64_t) (tmpval << bitsint)) | ((uint64_t)rndbuf[i])); + tmpval %= tmpmod; + } + *res = (uint32_t) tmpval; + free(rndbuf); } void crypto::encrypt(AES_KEY_CTX* enc_key, uint8_t* resbuf, uint8_t* inbuf, uint32_t ninbytes) {