mirror of
https://github.com/encryptogroup/PSI.git
synced 2024-03-22 13:30:44 +08:00
Cleaning
This commit is contained in:
parent
d07f0fc7fa
commit
89f56664ed
10
Makefile
10
Makefile
|
@ -44,8 +44,8 @@ OBJECTS_NAIVE=${SRC}/naive-hashing/*.o
|
|||
SOURCES_DHPSI=${SRC}/pk-based/*.cpp
|
||||
OBJECTS_DHPSI=${SRC}/pk-based/*.o
|
||||
# third-party-based PSI
|
||||
SOURCES_THIRDPARTY=${SRC}/thirdparty-based/*.cpp
|
||||
OBJECTS_THIRDPARTY=${SRC}/thirdparty-based/*.o
|
||||
SOURCES_SERVERAIDED=${SRC}/server-aided/*.cpp
|
||||
OBJECTS_SERVERAIDED=${SRC}/server-aided/*.o
|
||||
# OT-based PSI
|
||||
SOURCES_OTPSI=${SRC}/ot-based/*.cpp
|
||||
OBJECTS_OTPSI=${SRC}/ot-based/*.o
|
||||
|
@ -67,10 +67,10 @@ core: ${OBJECTS_CORE}
|
|||
${CC} $< ${COMPILER_OPTIONS} -c ${INCLUDE} ${LIBRARIES} ${CFLAGS} ${BATCH} -o $@
|
||||
|
||||
bench:
|
||||
${CC} -o psi.exe ${SRC}/mains/bench_psi.cpp ${OBJECTS_DHPSI} ${OBJECTS_OTPSI} ${OBJECTS_NAIVE} ${OBJECTS_THIRDPARTY} ${OBJECTS_UTIL} ${OBJECTS_HASHING} ${OBJECTS_CRYPTO} ${OBJECTS_OT} ${OBJECTS_MIRACL} ${CFLAGS} ${DEBUG_OPTIONS} ${LIBRARIES} ${MIRACL_LIB} ${INCLUDE} ${COMPILER_OPTIONS}
|
||||
${CC} -o psi.exe ${SRC}/mains/bench_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}
|
||||
|
||||
demo:
|
||||
${CC} -o demo.exe ${SRC}/mains/psi_demo.cpp ${OBJECTS_DHPSI} ${OBJECTS_OTPSI} ${OBJECTS_NAIVE} ${OBJECTS_THIRDPARTY} ${OBJECTS_UTIL} ${OBJECTS_HASHING} ${OBJECTS_CRYPTO} ${OBJECTS_OT} ${OBJECTS_MIRACL} ${CFLAGS} ${DEBUG_OPTIONS} ${LIBRARIES} ${MIRACL_LIB} ${INCLUDE} ${COMPILER_OPTIONS}
|
||||
${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}
|
||||
|
||||
|
||||
# this will create a copy of the files in ${SOURCES_MIRACL} and its sub-directories and put them into ${MIRACL_LIB_DIR} without sub-directories, then compile it
|
||||
|
@ -83,7 +83,7 @@ ${MIRACL_LIB_DIR}/miracl.a: ${SOURCES_MIRACL}
|
|||
|
||||
# only clean example objects, test object and binaries
|
||||
clean:
|
||||
rm -f ${OBJECTS_EXAMPLE} ${OBJECTS_TEST} *.exe ${OBJECTS_DHPSI} ${OBJECTS_OTPSI} ${OBJECTS_NAIVE} ${OBJECTS_THIRDPARTY} ${OBJECTS_UTIL} ${OBJECTS_CRYPTO} ${OBJECTS_OT}
|
||||
rm -f ${OBJECTS_EXAMPLE} ${OBJECTS_TEST} *.exe ${OBJECTS_DHPSI} ${OBJECTS_OTPSI} ${OBJECTS_NAIVE} ${OBJECTS_SERVERAIDED} ${OBJECTS_UTIL} ${OBJECTS_CRYPTO} ${OBJECTS_OT}
|
||||
|
||||
# this will clean everything: example objects, test object and binaries and the Miracl library
|
||||
cleanall: clean
|
||||
|
|
|
@ -60,9 +60,9 @@ This should print the following output in the second terminal:
|
|||
|
||||
|
||||
|
||||
These commands will run the naive hashing protocol and compute the intersection on the 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:
|
||||
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]. CURRENTLY NOT WORKING
|
||||
* `-p 2`: the Diffie-Hellman-based PSI protocol of [3]
|
||||
* `-p 3`: the OT-based PSI protocol of [1]
|
||||
|
||||
|
|
|
@ -34,23 +34,9 @@ uint8_t* cuckoo_hashing(uint8_t* elements, uint32_t neles, uint32_t nbins, uint3
|
|||
entry_gen_tasks = (pthread_t*) malloc(sizeof(pthread_t) * ntasks);
|
||||
ctx = (cuckoo_entry_gen_ctx*) malloc(sizeof(cuckoo_entry_gen_ctx) * ntasks);
|
||||
|
||||
//use the number of bins as address bits
|
||||
//addr_bits = ceil_log2(nbins);
|
||||
//cout << "Using addr_bits: " << hs.addrbitlen << endl;
|
||||
//cout << "number of bins: " << nbins << ", address bits = " << addr_bits << endl;
|
||||
//the remaining bits form the size of the values
|
||||
|
||||
//inbytelen = ceil_divide(bitlen, 8);
|
||||
//outbytelen = ceil_divide(outbitlen, 8);
|
||||
//dummy_ele = (uint8_t*) malloc(ceil_divide(bitlen, 8));
|
||||
|
||||
for(i = 0; i < ntasks; i++) {
|
||||
ctx[i].elements = elements;
|
||||
ctx[i].cuckoo_entries = cuckoo_entries;
|
||||
//ctx[i].inbitlen = bitlen;
|
||||
// ctx[i].addr_bitlen = addr_bits;
|
||||
//ctx[i].outbitlen = outbitlen;
|
||||
//ctx[i].nbins = nbins;
|
||||
ctx[i].hs = &hs;
|
||||
ctx[i].startpos = i * ceil_divide(neles, ntasks);
|
||||
ctx[i].endpos = min(ctx[i].startpos + ceil_divide(neles, ntasks), neles);
|
||||
|
@ -61,11 +47,6 @@ uint8_t* cuckoo_hashing(uint8_t* elements, uint32_t neles, uint32_t nbins, uint3
|
|||
}
|
||||
}
|
||||
|
||||
//generate the cuckoo entries for all elements
|
||||
//for(i = 0; i < neles; i++) {
|
||||
// gen_cuckoo_entry(elements + inbytelen * i, bitlen, addr_bits, cuckoo_entries + i, outbitlen, nbins, i);
|
||||
//}
|
||||
|
||||
for(i = 0; i < ntasks; i++) {
|
||||
if(pthread_join(entry_gen_tasks[i], NULL)) {
|
||||
cerr << "Error in joining pthread at cuckoo hashing!" << endl;
|
||||
|
|
|
@ -1,154 +0,0 @@
|
|||
// K-ary cuckoo hashing (c) 2002-2003 by Peter Sanders
|
||||
// this is a simple implementation for the purposes
|
||||
// of measuring the performance of cuckoo hashing in abstract
|
||||
// terms (number of probes per insert, storage efficiency)
|
||||
// usage: compile using g++ or another ISO C++ compiler
|
||||
// a.out <K> <n> <r> <repeat> <seed for rng>
|
||||
// there is also a constant tMax that defines the maximum number
|
||||
// of trials for an insertion
|
||||
// allocates space for n elements in K subtables, and repeats
|
||||
// the follwing measurements repeat time:
|
||||
// - find a hash function by filling full lookup tables
|
||||
// with pseudo-random numbers.
|
||||
// - insert elements i=0..n-1 into the table until this fails
|
||||
// for the first time. (The cost of these insertions is not
|
||||
// measured.)
|
||||
// Every n/r successfully inserted elements, the follwing
|
||||
// measurement is repeated n/r times:
|
||||
// * a random element i2 is removed
|
||||
// * the hash table entries for i2 are filled with new random values
|
||||
// * i2 is reinserted.
|
||||
// Note that this is equivalent to removing a random element
|
||||
// inserting a new element that
|
||||
// has never been in the table before.
|
||||
// The output is a table that gives
|
||||
// - x the number of elements in the table at each measuremnt interval
|
||||
// - the average number of probes for an insertion during the measruements
|
||||
// for the given number of inserted elements
|
||||
// - K
|
||||
// - n
|
||||
// - repeat
|
||||
// - seed
|
||||
#define DEBUGLEVEL 1
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include "util.h"
|
||||
#include "mt-real.c"
|
||||
#include <assert.h>
|
||||
|
||||
#define split 1
|
||||
|
||||
|
||||
using namespace std;
|
||||
const int tMax = 10000; // max number of random walk trials
|
||||
int K; // number of probes
|
||||
int n; // number of elements
|
||||
int m; // number of elements per table
|
||||
int **hash; // K times n array
|
||||
int **table; // K times m array
|
||||
|
||||
|
||||
// generate random int in 0..x-1
|
||||
inline int rand0K(int x) { return int(genrand()*x); }
|
||||
|
||||
|
||||
// insert element i into table
|
||||
// return value:
|
||||
// -1 failure
|
||||
// otherwise number of hash function evaluation
|
||||
int insert(int i) {
|
||||
int forbidden = -1;
|
||||
int j = rand0K(K);
|
||||
for (int t = 1; t <= tMax; t++) {
|
||||
int p = hash [j][i];
|
||||
int newI = table[j][p];
|
||||
table[j][p] = i; // play the cuckoo
|
||||
if (newI == -1) return t; // done
|
||||
forbidden = j;
|
||||
i = newI; // find new home for cuckoo victim
|
||||
j = rand0K(K-1);
|
||||
if (j == forbidden) j = K-1;
|
||||
}
|
||||
return tMax + 1; // insertion failed
|
||||
}
|
||||
|
||||
// remove element i from the table
|
||||
void remove(int i) {
|
||||
for (int j = 0; j < K; j++) {
|
||||
int p = hash[j][i];
|
||||
if (table[j][p] == i) {
|
||||
table[j][p] = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*int main(int argc, char **argv) {
|
||||
int i, j;
|
||||
assert(argc == 6);
|
||||
K = atoi(argv[1]); // number of probes
|
||||
n = atoi(argv[2]); // number of elements
|
||||
// double eps = atof(argv[3]); // space slack
|
||||
m = int(n/K + 0.5);
|
||||
int r = atoi(argv[3]); // number of measured densities
|
||||
int step = n/r;
|
||||
int repeat = atoi(argv[4]); // how often to start from scratch
|
||||
int seed = atoi(argv[5]);
|
||||
sgenrand(seed);
|
||||
cout << "# x tAvg(x) K N repeat seed" << endl;
|
||||
|
||||
// allocate hash function and table
|
||||
// and an empty table
|
||||
hash = (int**) malloc(sizeof(int*) * K);
|
||||
table = (int**) malloc(sizeof(int*) * K);
|
||||
for (j = 0; j < K; j++) {
|
||||
hash [j] = new int[n];
|
||||
table[j] = new int[m];
|
||||
}
|
||||
|
||||
// initialize statistics
|
||||
// sumT[i] is the average time for size i*step
|
||||
double *sumT = new double[r+1];
|
||||
int *cf = new int[r+1];
|
||||
for (int i = 0; i < r; i++) {
|
||||
sumT[i] = 0;
|
||||
cf[i] = 0;
|
||||
}
|
||||
|
||||
// main loop
|
||||
for (int rep = 0; rep < repeat; rep++) {
|
||||
// init hash function and empty table
|
||||
for (j = 0; j < K; j++) {
|
||||
for (i = 0; i < n; i++) { hash [j][i] = rand0K(m); }
|
||||
for (i = 0; i < m; i++) { table[j][i] = -1; }
|
||||
}
|
||||
|
||||
// fill table and keep measuring from time to time
|
||||
for (i = 0; i < n; i++) {
|
||||
if (insert(i) > tMax) break; // table is full
|
||||
if (((i+1) % step) == 0) { // measure in detail here
|
||||
for (int i1 = 0; i1 < step; i1++) {
|
||||
// remove and reinsert a random element
|
||||
int i2 = rand0K(i);
|
||||
remove(i2);
|
||||
for (j = 0; j < K; j++) hash[j][i2] = rand0K(m);
|
||||
int t = insert(i2);
|
||||
cf[i/step] += (t > tMax);
|
||||
//cout << t << endl;
|
||||
sumT[i/step] += t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int rep = 0; rep < r; rep++) {
|
||||
cout << rep*step + step << " "
|
||||
<< sumT[rep]/step/repeat << " "
|
||||
<< K << " "
|
||||
<< n << " "
|
||||
<< repeat << " "
|
||||
<< seed << " "
|
||||
<< cf[rep] << endl;
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -1,90 +0,0 @@
|
|||
/* A C-program for MT19937B: Real number version */
|
||||
/* genrand() generate one pseudorandom number with double precision */
|
||||
/* which is uniformly distributed on [0,1]-interval for each call. */
|
||||
/* sgenrand(seed) set initial values to the working area of 624 words.*/
|
||||
/* sgenrand(seed) must be called once before calling genrand() */
|
||||
/* (seed is any integer except 0). */
|
||||
|
||||
/*
|
||||
LICENCE CONDITIONS:
|
||||
|
||||
Matsumoto and Nishimura consent to GNU General
|
||||
Public Licence
|
||||
|
||||
NOTE:
|
||||
When you use it in your program, please let Matsumoto
|
||||
<matumoto@math.keio.ac.jp> know it.
|
||||
|
||||
Because of a machine-trouble, Matsumoto lost emails
|
||||
which arrived during May 28-29.
|
||||
*/
|
||||
|
||||
|
||||
#include<stdio.h>
|
||||
|
||||
/* Period parameters */
|
||||
#define N 624
|
||||
#define M 397
|
||||
#define MATRIX_A 0x9908b0df /* constant vector a */
|
||||
#define UPPER_MASK 0x80000000 /* most significant w-r bits */
|
||||
#define LOWER_MASK 0x7fffffff /* least significant r bits */
|
||||
|
||||
/* for tempering */
|
||||
#define TEMPERING_MASK_B 0x9d2c5680
|
||||
#define TEMPERING_MASK_C 0xefc60000
|
||||
#define TEMPERING_SHIFT_U(y) (y >> 11)
|
||||
#define TEMPERING_SHIFT_S(y) (y << 7)
|
||||
#define TEMPERING_SHIFT_T(y) (y << 15)
|
||||
#define TEMPERING_SHIFT_L(y) (y >> 18)
|
||||
|
||||
static unsigned long ptgfsr[N]; /* set initial seeds: N = 624 words */
|
||||
|
||||
void
|
||||
sgenrand(unsigned long seed) /* seed should not be 0 */
|
||||
{
|
||||
int k;
|
||||
|
||||
/* setting initial seeds to ptgfsr[N] using */
|
||||
/* the generator Line 25 of Table 1 in */
|
||||
/* [KNUTH 1981, The Art of Computer Programming */
|
||||
/* Vol. 2 (2nd Ed.), pp102] */
|
||||
|
||||
ptgfsr[0]= seed & 0xffffffff;
|
||||
for (k=1; k<N; k++)
|
||||
ptgfsr[k] = (69069 * ptgfsr[k-1]) & 0xffffffff;
|
||||
}
|
||||
|
||||
double
|
||||
genrand()
|
||||
{
|
||||
unsigned long y;
|
||||
static int k = 1;
|
||||
static unsigned long mag01[2]={0x0, MATRIX_A};
|
||||
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
||||
|
||||
if(k == N){ /* generate N words at one time */
|
||||
int kk;
|
||||
for (kk=0;kk<N-M;kk++) {
|
||||
y = (ptgfsr[kk]&UPPER_MASK)|(ptgfsr[kk+1]&LOWER_MASK);
|
||||
ptgfsr[kk] = ptgfsr[kk+M] ^ (y >> 1) ^ mag01[y & 0x1];
|
||||
}
|
||||
for (;kk<N-1;kk++) {
|
||||
y = (ptgfsr[kk]&UPPER_MASK)|(ptgfsr[kk+1]&LOWER_MASK);
|
||||
ptgfsr[kk] = ptgfsr[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1];
|
||||
}
|
||||
y = (ptgfsr[N-1]&UPPER_MASK)|(ptgfsr[0]&LOWER_MASK);
|
||||
ptgfsr[N-1] = ptgfsr[M-1] ^ (y >> 1) ^ mag01[y & 0x1];
|
||||
|
||||
k = 0;
|
||||
}
|
||||
|
||||
y = ptgfsr[k++];
|
||||
y ^= TEMPERING_SHIFT_U(y);
|
||||
y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B;
|
||||
y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C;
|
||||
y &= 0xffffffff; /* you may delete this line if word size = 32 */
|
||||
y ^= TEMPERING_SHIFT_L(y);
|
||||
|
||||
return ( (double)y / (unsigned long)0xffffffff );
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
// this files contains all the application independent little
|
||||
// functions and macros used for the optimizer.
|
||||
// In particular Peters debug macros and Dags stuff
|
||||
// from dbasic.h cdefs, random,...
|
||||
|
||||
//////////////// stuff originally from debug.h ///////////////////////////////
|
||||
// (c) 1997 Peter Sanders
|
||||
// some little utilities for debugging adapted
|
||||
// to the paros conventions
|
||||
|
||||
|
||||
#ifndef UTIL
|
||||
#define UTIL
|
||||
|
||||
// default debug level. will be overidden e.g. if debug.h is included
|
||||
#ifndef DEBUGLEVEL
|
||||
#define DEBUGLEVEL 3
|
||||
#endif
|
||||
|
||||
#if DEBUGLEVEL >= 0
|
||||
#define Debug0(A) A
|
||||
#else
|
||||
#define Debug0(A)
|
||||
#endif
|
||||
#if DEBUGLEVEL >= 1
|
||||
#define Debug1(A) A
|
||||
#else
|
||||
#define Debug1(A)
|
||||
#endif
|
||||
#if DEBUGLEVEL >= 2
|
||||
#define Debug2(A) A
|
||||
#else
|
||||
#define Debug2(A)
|
||||
#endif
|
||||
#if DEBUGLEVEL >= 3
|
||||
#define Debug3(A) A
|
||||
#else
|
||||
#define Debug3(A)
|
||||
#endif
|
||||
#if DEBUGLEVEL >= 4
|
||||
#define Debug4(A) A
|
||||
#else
|
||||
#define Debug4(A)
|
||||
#endif
|
||||
#if DEBUGLEVEL >= 5
|
||||
#define Debug5(A) A
|
||||
#else
|
||||
#define Debug5(A)
|
||||
#endif
|
||||
#if DEBUGLEVEL >= 6
|
||||
#define Debug6(A) A
|
||||
#else
|
||||
#define Debug6(A)
|
||||
#endif
|
||||
|
||||
#define Assert(c) if(!(c))\
|
||||
{cout << "\nAssertion violation " << __FILE__ << ":" << __LINE__ << endl;}
|
||||
#define Assert0(C) Debug0(Assert(C))
|
||||
#define Assert1(C) Debug1(Assert(C))
|
||||
#define Assert2(C) Debug2(Assert(C))
|
||||
#define Assert3(C) Debug3(Assert(C))
|
||||
#define Assert4(C) Debug4(Assert(C))
|
||||
#define Assert5(C) Debug5(Assert(C))
|
||||
|
||||
#define Error(s) {cout << "\nError:" << s << " " << __FILE__ << ":" << __LINE__ << endl;}
|
||||
|
||||
////////////// min, max etc. //////////////////////////////////////
|
||||
|
||||
#ifndef Max
|
||||
#define Max(x,y) ((x)>=(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
#ifndef Min
|
||||
#define Min(x,y) ((x)<=(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
#ifndef Abs
|
||||
#define Abs(x) ((x) < 0 ? -(x) : (x))
|
||||
#endif
|
||||
|
||||
#ifndef PI
|
||||
#define PI 3.1415927
|
||||
#endif
|
||||
|
||||
// is this the right definition of limit?
|
||||
inline double limit(double x, double bound)
|
||||
{
|
||||
if (x > bound) { return bound; }
|
||||
else if (x < -bound) { return -bound; }
|
||||
else return x;
|
||||
}
|
||||
|
||||
/////////////////////// timing /////////////////////
|
||||
#include <time.h>
|
||||
|
||||
|
||||
// elapsed CPU time see also /usr/include/sys/time.h
|
||||
inline double cpuTime()
|
||||
{
|
||||
return clock() * 1e-6;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "../pk-based/dh-psi.h"
|
||||
#include "../ot-based/ot-psi.h"
|
||||
#include "../thirdparty-based/shpsi.h"
|
||||
#include "../server-aided/sapsi.h"
|
||||
#include "../naive-hashing/naive-psi.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "../pk-based/dh-psi.h"
|
||||
#include "../ot-based/ot-psi.h"
|
||||
#include "../thirdparty-based/shpsi.h"
|
||||
#include "../server-aided/sapsi.h"
|
||||
#include "../naive-hashing/naive-psi.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
|
|
@ -55,16 +55,12 @@ uint32_t naivepsi(role_type role, uint32_t neles, uint32_t pneles, task_ctx ectx
|
|||
|
||||
maskbytelen = ceil_divide(crypt_env->get_seclvl().statbits + ceil_log2(neles) + ceil_log2(pneles), 8);
|
||||
|
||||
//permeles = (uint8_t*) malloc(sizeof(uint8_t) * neles * elebytelen);
|
||||
hashes = (uint8_t*) malloc(sizeof(uint8_t) * neles * maskbytelen);
|
||||
perm = (uint32_t*) malloc(sizeof(uint32_t) * neles);
|
||||
|
||||
|
||||
/* Generate the random permutation the elements */
|
||||
crypt_env->gen_rnd_perm(perm, neles);
|
||||
//for(i = 0; i < neles; i++) {
|
||||
// memcpy(permeles + perm[i] * elebytelen, elements + i * elebytelen, elebytelen);
|
||||
//}
|
||||
|
||||
/* Hash and permute elements */
|
||||
#ifdef DEBUG
|
||||
|
@ -124,113 +120,3 @@ uint32_t naivepsi(role_type role, uint32_t neles, uint32_t pneles, task_ctx ectx
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*uint32_t find_intersection_naive(uint8_t* hashes, uint32_t neles, uint8_t* phashes, uint32_t pneles,
|
||||
uint32_t hashbytelen, uint32_t* perm, uint32_t* matches) {
|
||||
|
||||
uint32_t* invperm = (uint32_t*) malloc(sizeof(uint32_t) * neles);
|
||||
//uint32_t* matches = (uint32_t*) malloc(sizeof(uint32_t) * neles);
|
||||
uint64_t* tmpval;
|
||||
|
||||
uint32_t size_intersect, i, intersect_ctr;
|
||||
|
||||
for(i = 0; i < neles; i++) {
|
||||
invperm[perm[i]] = i;
|
||||
}
|
||||
//cout << "My number of elements. " << neles << ", partner number of elements: " << pneles << ", maskbytelen: " << hashbytelen << endl;
|
||||
|
||||
GHashTable *map= g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, NULL);
|
||||
for(i = 0; i < neles; i++) {
|
||||
g_hash_table_insert(map,(void*) ((uint64_t*) &(hashes[i*hashbytelen])), &(invperm[i]));
|
||||
}
|
||||
|
||||
//for(i = 0; i < pneles; i++) {
|
||||
// ((uint64_t*) &(phashes[i*hashbytelen]))[0]++;
|
||||
//}
|
||||
|
||||
for(i = 0, intersect_ctr = 0; i < pneles; i++) {
|
||||
|
||||
if(g_hash_table_lookup_extended(map, (void*) ((uint64_t*) &(phashes[i*hashbytelen])),
|
||||
NULL, (void**) &tmpval)) {
|
||||
matches[intersect_ctr] = tmpval[0];
|
||||
intersect_ctr++;
|
||||
assert(intersect_ctr <= min(neles, pneles));
|
||||
}
|
||||
}
|
||||
|
||||
size_intersect = intersect_ctr;
|
||||
|
||||
//result = (uint8_t**) malloc(sizeof(uint8_t*));
|
||||
//(*result) = (uint8_t*) malloc(sizeof(uint8_t) * size_intersect * elebytelen);
|
||||
//for(i = 0; i < size_intersect; i++) {
|
||||
// memcpy((*result) + i * elebytelen, elements + matches[i] * elebytelen, elebytelen);
|
||||
//}
|
||||
|
||||
free(invperm);
|
||||
//free(matches);
|
||||
return size_intersect;
|
||||
}*/
|
||||
|
||||
/*void snd_and_rcv_naive(uint8_t* snd_buf, uint32_t snd_bytes, uint8_t* rcv_buf, uint32_t rcv_bytes, CSocket* sock) {
|
||||
pthread_t snd_task;
|
||||
bool created, joined;
|
||||
snd_ctx ctx;
|
||||
|
||||
//Start new sender thread
|
||||
ctx.sock = sock;
|
||||
ctx.snd_buf = snd_buf;
|
||||
ctx.snd_bytes = snd_bytes;
|
||||
created = !pthread_create(&snd_task, NULL, send_data, (void*) &(ctx));
|
||||
|
||||
//receive
|
||||
sock->Receive(rcv_buf, rcv_bytes);
|
||||
assert(created);
|
||||
|
||||
joined = !pthread_join(snd_task, NULL);
|
||||
assert(joined);
|
||||
}*/
|
||||
|
||||
/*void run_task_naive(uint32_t nthreads, task_ctx context, void* (*func)(void*) ) {
|
||||
|
||||
task_ctx* contexts = (task_ctx*) malloc(sizeof(task_ctx) * nthreads);
|
||||
pthread_t* threads = (pthread_t*) malloc(sizeof(pthread_t) * nthreads);
|
||||
uint32_t i, neles_thread, electr, neles_cur;
|
||||
bool created, joined;
|
||||
|
||||
neles_thread = ceil_divide(context.eles.nelements, nthreads);
|
||||
for(i = 0, electr = 0; i < nthreads; i++) {
|
||||
neles_cur = min(context.eles.nelements - electr, neles_thread);
|
||||
memcpy(contexts + i, &context, sizeof(task_ctx));
|
||||
//contexts[i].eles.nelements = neles_cur;
|
||||
contexts[i].eles.startelement = electr;
|
||||
contexts[i].eles.endelement = electr + neles_cur;
|
||||
//contexts[i].eles.input = context.eles.input + (context.eles.inbytelen * electr);
|
||||
//contexts[i].eles.output = context.eles.output + (context.eles.outbytelen * electr);
|
||||
electr += neles_cur;
|
||||
}
|
||||
|
||||
for(i = 0; i < nthreads; i++) {
|
||||
created = !pthread_create(threads + i, NULL, func, (void*) &(contexts[i]));
|
||||
}
|
||||
|
||||
assert(created);
|
||||
|
||||
for(i = 0; i < nthreads; i++) {
|
||||
joined = !pthread_join(threads[i], NULL);
|
||||
}
|
||||
|
||||
assert(joined);
|
||||
|
||||
free(threads);
|
||||
free(contexts);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/*void *send_data_naive(void* context) {
|
||||
snd_ctx_naive *ctx = (snd_ctx_naive*) context;
|
||||
ctx->sock->Send(ctx->snd_buf, ctx->snd_bytes);
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
|
||||
|
|
|
@ -17,42 +17,6 @@
|
|||
#include "../util/helpers.h"
|
||||
|
||||
|
||||
|
||||
/*struct element_ctx_naive {
|
||||
uint32_t nelements;
|
||||
union {
|
||||
uint32_t fixed;
|
||||
uint32_t* var;
|
||||
} inbytelen;
|
||||
union {
|
||||
uint8_t* onedim;
|
||||
uint8_t** twodim;
|
||||
} inputs;
|
||||
uint32_t outbytelen;
|
||||
uint8_t* output;
|
||||
uint32_t* perm;
|
||||
bool varbytelen;
|
||||
};
|
||||
|
||||
struct hash_ctx_naive {
|
||||
crypto* symcrypt;
|
||||
uint32_t startelement;
|
||||
uint32_t endelement;
|
||||
};*/
|
||||
|
||||
/*struct task_ctx_naive {
|
||||
element_ctx_naive eles;
|
||||
hash_ctx_naive hctx;
|
||||
};*/
|
||||
|
||||
/*struct snd_ctx_naive {
|
||||
uint8_t* snd_buf;
|
||||
uint32_t snd_bytes;
|
||||
CSocket* sock;
|
||||
};*/
|
||||
|
||||
//TODO merge with dhpsi
|
||||
|
||||
void print_naive_psi_usage();
|
||||
uint32_t naivepsi(role_type role, uint32_t neles, uint32_t pneles, uint32_t* elebytelens, uint8_t** elements,
|
||||
uint8_t*** result, uint32_t** resbytelens, crypto* crypt_env, CSocket* sock, uint32_t ntasks);
|
||||
|
@ -61,18 +25,5 @@ uint32_t naivepsi(role_type role, uint32_t neles, uint32_t pneles, uint32_t eleb
|
|||
uint32_t naivepsi(role_type role, uint32_t neles, uint32_t pneles, task_ctx ectx,
|
||||
crypto* crypt_env, CSocket* sock, uint32_t ntasks, uint32_t* matches);
|
||||
|
||||
//void run_task_naive(uint32_t nthreads, task_ctx context, void* (*func)(void*) );
|
||||
//void permute_naive(uint32_t nelements, uint32_t bytelen, uint8_t* elements, uint8_t* result, uint32_t* perm);
|
||||
|
||||
//uint32_t find_intersection_naive(uint8_t* hashes, uint32_t neles, uint8_t* phashes, uint32_t pneles,
|
||||
// uint32_t hashbytelen, uint32_t* perm, uint32_t* matches);
|
||||
|
||||
//void snd_and_rcv_naive(uint8_t* snd_buf, uint32_t snd_bytes, uint8_t* rcv_buf, uint32_t rcv_bytes, CSocket* sock);
|
||||
//void *hash_naive(void* context);
|
||||
//void *send_data_naive(void* context);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* NAIVE_PSI_H_ */
|
||||
|
|
|
@ -65,9 +65,6 @@ uint32_t dhpsi(role_type role, uint32_t neles, uint32_t pneles, task_ctx ectx, c
|
|||
|
||||
/* Generate a random permutation for the elements */
|
||||
crypt_env->gen_rnd_perm(perm, neles);
|
||||
//for(i = 0; i < neles; i++) {
|
||||
// memcpy(permeles + perm[i] * elebytelen, elements + i * elebytelen, elebytelen);
|
||||
//}
|
||||
|
||||
/* Hash elements */
|
||||
ectx.eles.output = hashes;
|
||||
|
@ -106,20 +103,6 @@ uint32_t dhpsi(role_type role, uint32_t neles, uint32_t pneles, task_ctx ectx, c
|
|||
snd_and_rcv(encrypted_eles, neles * fe_bytes, peles, pneles * fe_bytes, tmpsock);
|
||||
|
||||
|
||||
|
||||
/*if(cardinality) {
|
||||
//samle permutation, permute elements, and copy back to original array
|
||||
cardinality_perm = (uint32_t*) malloc(sizeof(uint32_t) * pneles);
|
||||
crypt_env->gen_rnd_perm(cardinality_perm, pneles);
|
||||
perm_peles = (uint8_t*) malloc(pneles * fe_bytes);
|
||||
for(i = 0; i < pneles; i++) {
|
||||
memcpy(perm_peles + cardinality_perm[i] * fe_bytes, peles + i * fe_bytes, fe_bytes);
|
||||
}
|
||||
memcpy(peles, perm_peles, fe_bytes * pneles);
|
||||
free(cardinality_perm);
|
||||
free(perm_peles);
|
||||
}*/
|
||||
|
||||
/* Import and Encrypt elements again */
|
||||
ectx.eles.input1d = peles;
|
||||
ectx.eles.output = peles;
|
||||
|
@ -187,7 +170,6 @@ uint32_t dhpsi(role_type role, uint32_t neles, uint32_t pneles, task_ctx ectx, c
|
|||
cout << "Free-ing allocated memory" << endl;
|
||||
#endif
|
||||
free(perm);
|
||||
//free(permeles);
|
||||
free(encrypted_eles);
|
||||
free(hashes);
|
||||
free(peles);
|
||||
|
@ -196,147 +178,3 @@ uint32_t dhpsi(role_type role, uint32_t neles, uint32_t pneles, task_ctx ectx, c
|
|||
|
||||
return intersect_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*uint32_t find_intersection(uint8_t* elements, uint8_t** result, uint32_t elebytelen, uint8_t* hashes,
|
||||
uint32_t neles, uint8_t* phashes, uint32_t npeles, uint32_t hashbytelen, uint32_t* perm) {
|
||||
|
||||
uint32_t* invperm = (uint32_t*) malloc(sizeof(uint32_t) * neles);
|
||||
uint32_t* matches = (uint32_t*) malloc(sizeof(uint32_t) * neles);
|
||||
uint64_t* tmpinbuf;
|
||||
uint64_t* tmpval;
|
||||
uint32_t size_intersect, i, intersect_ctr, nextrakeysstored, j;
|
||||
bool success;
|
||||
|
||||
|
||||
nextrakeysstored = ceil_divide(hashbytelen, sizeof(uint64_t))-1;
|
||||
cout << "hashbytelen = " << hashbytelen << ", nextrakeysstored = " << nextrakeysstored << endl;
|
||||
|
||||
//store all the extra keys as well as the
|
||||
tmpinbuf = (uint64_t*) malloc(neles * (nextrakeysstored+1) * sizeof(uint64_t));
|
||||
|
||||
for(i = 0; i < neles; i++) {
|
||||
memcpy(tmpinbuf + i * (nextrakeysstored+1), hashes + i * hashbytelen + sizeof(uint64_t),
|
||||
nextrakeysstored*sizeof(uint64_t));
|
||||
tmpinbuf[perm[i] * (nextrakeysstored+1) + nextrakeysstored] = (uint64_t) i;
|
||||
//invperm[perm[i]] = i;
|
||||
}
|
||||
|
||||
|
||||
GHashTable *map= g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, NULL);
|
||||
for(i = 0; i < neles; i++) {
|
||||
// g_hash_table_insert(map,(void*) ((uint64_t*) &(hashes[i*hashbytelen])), &(invperm[i]));
|
||||
g_hash_table_insert(map,(void*) ((uint64_t*) &(hashes[i*hashbytelen])), &(tmpinbuf[i*(nextrakeysstored+1)]));
|
||||
}
|
||||
|
||||
for(i = 0, intersect_ctr = 0; i < npeles; i++) {
|
||||
success = true;
|
||||
if(g_hash_table_lookup_extended(map, (void*) ((uint64_t*) &(phashes[i*hashbytelen])),
|
||||
NULL, (void**) &tmpval)) {
|
||||
for(j = 0; j < nextrakeysstored; j++) {
|
||||
if(((uint64_t*) &(phashes[i*hashbytelen]))[j+1] != tmpval[j]) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if(success) {
|
||||
matches[intersect_ctr] = tmpval[nextrakeysstored];
|
||||
intersect_ctr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_intersect = intersect_ctr;
|
||||
|
||||
//result = (uint8_t**) malloc(sizeof(uint8_t*));
|
||||
(*result) = (uint8_t*) malloc(sizeof(uint8_t) * size_intersect * elebytelen);
|
||||
for(i = 0; i < size_intersect; i++) {
|
||||
memcpy((*result) + i * elebytelen, elements + matches[i] * elebytelen, elebytelen);
|
||||
}
|
||||
|
||||
free(invperm);
|
||||
free(matches);
|
||||
free(tmpinbuf);
|
||||
return size_intersect;
|
||||
}*/
|
||||
|
||||
/*void snd_and_rcv(uint8_t* snd_buf, uint32_t snd_bytes, uint8_t* rcv_buf, uint32_t rcv_bytes, CSocket* sock) {
|
||||
pthread_t snd_task;
|
||||
bool created, joined;
|
||||
snd_ctx ctx;
|
||||
|
||||
//Start new sender thread
|
||||
ctx.sock = sock;
|
||||
ctx.snd_buf = snd_buf;
|
||||
ctx.snd_bytes = snd_bytes;
|
||||
created = !pthread_create(&snd_task, NULL, send_data, (void*) &(ctx));
|
||||
|
||||
//receive
|
||||
sock->Receive(rcv_buf, rcv_bytes);
|
||||
assert(created);
|
||||
|
||||
joined = !pthread_join(snd_task, NULL);
|
||||
assert(joined);
|
||||
}*/
|
||||
|
||||
/*void run_task(uint32_t nthreads, task_ctx context, void* (*func)(void*) ) {
|
||||
task_ctx* contexts = (task_ctx*) malloc(sizeof(task_ctx) * nthreads);
|
||||
pthread_t* threads = (pthread_t*) malloc(sizeof(pthread_t) * nthreads);
|
||||
uint32_t i, neles_thread, electr, neles_cur;
|
||||
bool created, joined;
|
||||
|
||||
neles_thread = ceil_divide(context.eles.nelements, nthreads);
|
||||
for(i = 0, electr = 0; i < nthreads; i++) {
|
||||
neles_cur = min(context.eles.nelements - electr, neles_thread);
|
||||
memcpy(contexts + i, &context, sizeof(task_ctx));
|
||||
contexts[i].eles.nelements = neles_cur;
|
||||
//contexts[i].eles.input = context.eles.input + (context.eles.inbytelen * electr);
|
||||
//contexts[i].eles.output = context.eles.output + (context.eles.outbytelen * electr);
|
||||
contexts[i].eles.startelement = electr;
|
||||
contexts[i].eles.endelement = electr + neles_cur;
|
||||
electr += neles_cur;
|
||||
}
|
||||
|
||||
for(i = 0; i < nthreads; i++) {
|
||||
created = !pthread_create(threads + i, NULL, func, (void*) &(contexts[i]));
|
||||
}
|
||||
|
||||
assert(created);
|
||||
|
||||
for(i = 0; i < nthreads; i++) {
|
||||
joined = !pthread_join(threads[i], NULL);
|
||||
}
|
||||
|
||||
assert(joined);
|
||||
|
||||
free(threads);
|
||||
free(contexts);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*void *hash(void* context) {
|
||||
#ifdef DEBUG
|
||||
cout << "Hashing thread started" << endl;
|
||||
#endif
|
||||
crypto* crypt_env = ((task_ctx*) context)->hctx.symcrypt;
|
||||
element_ctx electx = ((task_ctx*) context)->eles;
|
||||
|
||||
uint8_t *inptr=electx.input, *outptr=electx.output;
|
||||
uint32_t i;
|
||||
|
||||
|
||||
for(i = 0; i < electx.nelements; i++, inptr+=electx.inbytelen, outptr+=electx.outbytelen) {
|
||||
crypt_env->hash(outptr, electx.outbytelen, inptr, electx.inbytelen);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
/*void *send_data(void* context) {
|
||||
snd_ctx *ctx = (snd_ctx*) context;
|
||||
ctx->sock->Send(ctx->snd_buf, ctx->snd_bytes);
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
|
|
|
@ -17,38 +17,6 @@
|
|||
#include "../util/helpers.h"
|
||||
|
||||
|
||||
/*struct element_ctx {
|
||||
uint32_t nelements;
|
||||
uint32_t inbytelen;
|
||||
uint8_t* input;
|
||||
uint32_t outbytelen;
|
||||
uint8_t* output;
|
||||
};*/
|
||||
|
||||
/*struct encrypt_ctx {
|
||||
num* exponent;
|
||||
pk_crypto* field;
|
||||
bool sample;
|
||||
};*/
|
||||
|
||||
//struct hash_ctx {
|
||||
// crypto* symcrypt;
|
||||
//};
|
||||
|
||||
/*struct task_ctx {
|
||||
element_ctx eles;
|
||||
union {
|
||||
hash_ctx hctx;
|
||||
encrypt_ctx ectx;
|
||||
};
|
||||
};*/
|
||||
|
||||
/*struct snd_ctx {
|
||||
uint8_t* snd_buf;
|
||||
uint32_t snd_bytes;
|
||||
CSocket* sock;
|
||||
};*/
|
||||
|
||||
uint32_t dhpsi(role_type role, uint32_t neles, uint32_t pneles, uint32_t* elebytelens, uint8_t** elements,
|
||||
uint8_t*** result, uint32_t** resbytelens, crypto* crypt_env, CSocket* sock, uint32_t ntasks,
|
||||
bool cardinality=false, field_type ftype=ECC_FIELD);
|
||||
|
@ -59,18 +27,7 @@ uint32_t dhpsi(role_type role, uint32_t neles, uint32_t pneles, uint32_t elebyte
|
|||
|
||||
|
||||
uint32_t dhpsi(role_type role, uint32_t neles, uint32_t pneles, task_ctx ectx, crypto* crypt_env, CSocket* sock,
|
||||
uint32_t ntasks, uint32_t* matches, bool cardinality=false, field_type ftype=ECC_FIELD);
|
||||
//void run_task(uint32_t nthreads, task_ctx context, void* (*func)(void*) );
|
||||
//void permute(uint32_t nelements, uint32_t bytelen, uint8_t* elements, uint8_t* result, uint32_t* perm);
|
||||
//uint32_t find_intersection(uint8_t* elements, uint8_t** result, uint32_t elebytelen, uint8_t* hashes,
|
||||
// uint32_t neles, uint8_t* phashes, uint32_t peles, uint32_t hashbytelen, uint32_t* perm);
|
||||
//void snd_and_rcv(uint8_t* snd_buf, uint32_t snd_bytes, uint8_t* rcv_buf, uint32_t rcv_bytes, CSocket* sock);
|
||||
//void *encrypt(void* context);
|
||||
//void *hash(void* context);
|
||||
//void *send_data(void* context);
|
||||
|
||||
|
||||
|
||||
uint32_t ntasks, uint32_t* matches, bool cardinality=false, field_type ftype=ECC_FIELD);
|
||||
|
||||
|
||||
#endif /* DH_PSI_H_ */
|
||||
|
|
|
@ -1,50 +1,4 @@
|
|||
#include "shpsi.h"
|
||||
|
||||
|
||||
|
||||
/*int32_t main(int32_t argc, char** argv) {
|
||||
uint32_t pid, nclients, nelements, elebytelen, symsecbits;
|
||||
uint8_t *elements, *intersection;
|
||||
const char* address;
|
||||
uint16_t port;
|
||||
timeval begin, end;
|
||||
|
||||
if(argc < 2) {
|
||||
print_sh_psi_usage();
|
||||
} else {
|
||||
pid = atoi(argv[1]);
|
||||
if((pid == 0 && argc < 5) || (pid > 0 && argc < 6)) print_sh_psi_usage();
|
||||
}
|
||||
|
||||
if(pid == 0) { // Play as server
|
||||
nclients = atoi(argv[2]);
|
||||
address = argv[3];
|
||||
port = (uint16_t) atoi(argv[4]);
|
||||
server_routine(nclients, address, port);
|
||||
} else { // Play as client
|
||||
nelements = atoi(argv[2]);
|
||||
elebytelen = atoi(argv[3]);
|
||||
symsecbits = atoi(argv[4]);
|
||||
address = argv[5];
|
||||
port = atoi(argv[6]);
|
||||
elements = (uint8_t*) malloc(sizeof(uint8_t) * elebytelen * nelements);
|
||||
crypto crypto(symsecbits);
|
||||
crypto.gen_rnd(elements, elebytelen * nelements);
|
||||
|
||||
#ifdef DEBUG
|
||||
//Load some dummy-values
|
||||
for(uint32_t i = 0; i < nelements; i++) {
|
||||
((uint32_t*) elements)[i] = i+(nelements/pid);
|
||||
}
|
||||
#endif
|
||||
gettimeofday(&begin, NULL);
|
||||
client_routine(nelements, elebytelen, elements, &intersection, symsecbits, address, port);
|
||||
gettimeofday(&end, NULL);
|
||||
cout << "Computing the intersection took " << getMillies(begin, end) << " ms" << endl;
|
||||
}
|
||||
cout << "Program execution finished" << endl;
|
||||
return 0;
|
||||
}*/
|
||||
#include "sapsi.h"
|
||||
|
||||
void server_routine(uint32_t nclients, CSocket* socket, bool cardinality) {
|
||||
//cout << "Starting server for " << nclients << " clients on address " << address << ":" << port << endl;
|
Loading…
Reference in New Issue
Block a user