Skip to content

Commit

Permalink
final version of Table-Based OPPRF
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrieu committed Mar 17, 2017
1 parent 882e0f4 commit 4c63aba
Show file tree
Hide file tree
Showing 38 changed files with 3,801 additions and 2,052 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.6)
cmake_minimum_required (VERSION 2.8)

project("libPSI")

Expand Down
2 changes: 1 addition & 1 deletion cryptoTools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ target_link_libraries(cryptoTools ${MIRACL_LIB})
target_link_libraries(cryptoTools ${Boost_LIBRARIES})


#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
67 changes: 43 additions & 24 deletions cryptoTools/Common/ArrayView.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace osuCrypto {
:mBegin(begin), mCur(cur), mEnd(end)
{
if (mCur > mEnd) throw std::runtime_error("iter went past end. " LOCATION);
if (mCur < mBegin - 1) throw std::runtime_error("iter went past begin. " LOCATION);
if (mCur && mCur < mBegin - 1) throw std::runtime_error("iter went past begin. " LOCATION);
}
T* mBegin, *mCur, *mEnd;

Expand All @@ -28,17 +28,6 @@ namespace osuCrypto {
++mCur;
return ArrayIterator<T>(mBegin, mCur - 1, mEnd);
}

ArrayIterator<T> operator+(int i) {
return ArrayIterator<T>(mBegin, mCur + i, mEnd);
}

ArrayIterator<T>& operator+=(int i) {
mCur += i;
if (mCur > mEnd) throw std::runtime_error("iter went past end. " LOCATION);
return *this;
}

ArrayIterator<T>& operator--() {
--mCur;
if (mCur < mBegin - 1) throw std::runtime_error("iter went past end. " LOCATION);
Expand All @@ -50,20 +39,33 @@ namespace osuCrypto {
return ArrayIterator<T>(mBegin, mCur + 1, mEnd);
}

ArrayIterator<T> operator-(int i) {
ArrayIterator<T> operator+(i64 i) {
return ArrayIterator<T>(mBegin, mCur + i, mEnd);
}

ArrayIterator<T>& operator+=(i64 i) {
mCur += i;
if (mCur > mEnd) throw std::runtime_error("iter went past end. " LOCATION);
return *this;
}

ArrayIterator<T> operator-(i64 i) {
return ArrayIterator<T>(mBegin, mCur - i, mEnd);
}

ArrayIterator<T>& operator-=(int i) {
ArrayIterator<T>& operator-=(i64 i) {
mCur -= i;
if (mCur < mBegin - 1) throw std::runtime_error("iter went past end. " LOCATION);
return *this;
}

i64 operator-(T* i) {
return mCur - i;
}

T& operator*() {
if (mCur >= mEnd || mCur < mBegin)throw std::runtime_error("deref past begin or end. " LOCATION);
return *mCur;
return *mCur;
}

T* operator->()
Expand All @@ -83,7 +85,7 @@ namespace osuCrypto {
bool operator==(const ArrayIterator<T>& cmp) { return mCur == cmp.mCur; }
bool operator!=(const ArrayIterator<T>& cmp) { return mCur != cmp.mCur; }

ArrayIterator<T>* operator=(const ArrayIterator<T>& cmp)
ArrayIterator<T>& operator=(const ArrayIterator<T>& cmp)
{
mBegin = cmp.mBegin; mCur = cmp.mCur; mEnd = cmp.mEnd; return *this;
}
Expand All @@ -95,12 +97,13 @@ namespace osuCrypto {
template<class T>
class ArrayView
{

T* mData;
u64 mSize;
bool mOwner;
public:
public:

typedef T value_type;

ArrayView()
:mData(nullptr),
Expand Down Expand Up @@ -138,13 +141,17 @@ namespace osuCrypto {
{}

//template<typename Container>

template <class Iter>
ArrayView(Iter start, Iter end, typename Iter::iterator_category *p = 0) :
mData(&*start),
mSize(end - start),
mOwner(false)
{
//static_assert(std::is_same<typename Iter::value_type, T>::value, "Iter iter must have the same value_type as ArrayView");
//(void*)p;
std::ignore = p;

}

ArrayView(T* begin, T* end, bool owner) :
Expand All @@ -153,14 +160,26 @@ namespace osuCrypto {
mOwner(owner)
{}

ArrayView(std::vector<T>& container)
: mData(container.data()),
mSize(container.size()),

template<template<typename, typename...> class C, typename... Args>
ArrayView(const C<T, Args...>& cont, typename C<T, Args...>::value_type* p = 0) :
mData(((C<T, Args...>&)cont).data()),
mSize((((C<T, Args...>&)cont).end() - ((C<T, Args...>&)cont).begin())),
mOwner(false)
{
std::ignore = p;
//static_assert(std::is_same<typename C<T, Args...>::value_type, T>::value, "Container cont must have the same value_type as ArrayView");
//(void*)p;
}

template<u64 n>
//ArrayView(std::vector<T>& container)
// : mData(container.data()),
// mSize(container.size()),
// mOwner(false)
//{
//}

template<size_t n>
ArrayView(std::array<T,n>& container)
: mData(container.data()),
mSize(container.size()),
Expand Down Expand Up @@ -210,7 +229,7 @@ namespace osuCrypto {
inline T& operator[](u64 idx) const
{
#ifndef NDEBUG
if (idx >= mSize) throw std::runtime_error(LOCATION);
if (idx >= mSize) throw std::runtime_error(LOCATION);
#endif

return mData[idx];
Expand Down
2 changes: 1 addition & 1 deletion cryptoTools/Common/ByteStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace osuCrypto {
{
if (loc > mCapacity) throw std::runtime_error("rt error at " LOCATION);
mPutHead = loc;
mGetHead = std::min(mGetHead, mPutHead);
mGetHead = std::min<u64>(mGetHead, mPutHead);
}

u64 ByteStream::tellg()const
Expand Down
2 changes: 1 addition & 1 deletion cryptoTools/Common/Defines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace osuCrypto {

Timer gTimer;
Timer gTimer(true);
const block ZeroBlock = _mm_set_epi64x(0, 0);
const block OneBlock = _mm_set_epi64x(0, 1);
const block AllOneBlock = _mm_set_epi64x(u64(-1), u64(-1));
Expand Down
19 changes: 11 additions & 8 deletions cryptoTools/Common/Defines.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
// This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use.
// This file and the associated implementation has been placed in the public domain, waiving all copyright. No restrictions are placed on its use.

#include <cinttypes>
#include <iomanip>
Expand All @@ -20,13 +20,13 @@
#pragma GCC diagnostic ignored "-Wignored-attributes"
#endif

#ifdef _MSC_VER
#ifdef _MSC_VER
#define __STR2__(x) #x
#define __STR1__(x) __STR2__(x)
#define TODO(x) __pragma(message (__FILE__ ":"__STR1__(__LINE__) " Warning:TODO - " #x))
#define ALIGNED(__Declaration, __alignment) __declspec(align(__alignment)) __Declaration
#define ALIGNED(__Declaration, __alignment) __declspec(align(__alignment)) __Declaration
#else
#define TODO(x)
#define TODO(x)
#define ALIGNED(__Declaration, __alignment) __Declaration __attribute__((aligned (16)))
#endif

Expand Down Expand Up @@ -64,8 +64,11 @@ namespace osuCrypto {
}

typedef __m128i block;
inline block toBlock(u8*data)
{ return _mm_set_epi64x(((u64*)data)[1], ((u64*)data)[0]);}

inline block toBlock(u8*data) { return _mm_set_epi64x(((u64*)data)[1], ((u64*)data)[0]);}

inline block toBlock(u64 x) { return _mm_set_epi64x(0,x); }
inline block toBlock(u64 x, u64 y) { return _mm_set_epi64x(x,y); }

template <size_t N>
using MultiBlock = std::array<block, N>;
Expand Down Expand Up @@ -93,7 +96,7 @@ namespace osuCrypto {
return _mm_add_epi64(lhs, rhs);
}


#endif

template <size_t N>
Expand Down Expand Up @@ -141,7 +144,7 @@ namespace osuCrypto {
}

std::ostream& operator<<(std::ostream& out, const block& block);

template <size_t N>
std::ostream& operator<<(std::ostream& out, const MultiBlock<N>& block);

Expand Down
1 change: 1 addition & 0 deletions cryptoTools/Common/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace osuCrypto
{



std::mutex gIoStreamMtx;

void setThreadName(const std::string name)
Expand Down
6 changes: 2 additions & 4 deletions cryptoTools/Common/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace osuCrypto
{


enum class Color {
LightGreen = 2,
LightGrey = 3,
Expand Down Expand Up @@ -41,8 +42,5 @@ namespace osuCrypto

void setThreadName(const std::string name);
void setThreadName(const char* name);

}



}
37 changes: 26 additions & 11 deletions cryptoTools/Common/MatrixView.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace osuCrypto

public:


typedef T value_type;

MatrixView()
:mData(nullptr),
Expand All @@ -48,11 +48,7 @@ namespace osuCrypto


MatrixView(u64 rowSize, u64 columnSize) :
#ifdef NDEBUG
mData(new T[rowSize * columnSize]),
#else
mData(new T[rowSize * columnSize]()),
#endif
mSize({ rowSize, columnSize }),
mOwner(true)
{ }
Expand All @@ -77,13 +73,32 @@ namespace osuCrypto
mSize({ (end - start) / numColumns, numColumns }),
mOwner(false)
{
//static_assert(std::is_same<Iter::value_type, T>::value, "Iter iter must have the same value_type as ArrayView");
std::ignore = p;

}

//MatrixView(T* data, u64 rowSize, u64 columnSize) :
// mData(data),
// mSize({ rowSize, columnSize }),
//template<class C>
//MatrixView(const C& cont, u64 numColumns, typename C::value_type* p = 0) :
// mData(&*((C&)cont).begin()),
// mSize({ (((C&)cont).end() - ((C&)cont).begin()) / numColumns, numColumns }),
// mOwner(false)
//{}
//{
// static_assert(std::is_same<C::value_type, T>::value, "Container cont must have the same value_type as ArrayView");

// (void*)p;
//}

template<template<typename, typename...> class C, typename... Args>
MatrixView(const C<T, Args...>& cont, u64 numColumns, typename C<T, Args...>::value_type* p = 0) :
mData(&*((C<T, Args...>&)cont).begin()),
mSize({ (((C<T, Args...>&)cont).end() - ((C<T, Args...>&)cont).begin()) / numColumns, numColumns }),
mOwner(false)
{
//static_assert(std::is_same<C::value_type, T>::value, "Container cont must have the same value_type as ArrayView");
std::ignore = p;

}


~MatrixView()
Expand Down Expand Up @@ -129,11 +144,11 @@ namespace osuCrypto
};
ArrayIterator<T> end() const {
T* e = (T*)mData + (mSize[0] * mSize[1]);
return ArrayIterator<T>(mData, e, e);
return ArrayIterator<T>(mData, e, e);
}
#else
T* begin() const { return mData; };
T* end() const { return mData + mSize; }
T* end() const { return mData + mSize[0] * mSize[1]; }
#endif

ArrayView<T> operator[](u64 rowIdx) const
Expand Down
10 changes: 6 additions & 4 deletions cryptoTools/Common/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ namespace osuCrypto

const Timer::timeUnit& Timer::setTimePoint(const std::string& msg)
{
//if (mLocking) mMtx.lock();
mTimes.push_back(std::make_pair(timeUnit::clock::now(), msg));

auto& ret = mTimes.back().first;
//if (mLocking) mMtx.unlock();
//std::cout << msg << " " << std::chrono::duration_cast<std::chrono::milliseconds>(mTimes.back().first - mStart).count() << std::endl;

return mTimes.back().first;
return ret;
//return mStart;
}

Expand All @@ -30,7 +32,7 @@ namespace osuCrypto
auto iter = timer.mTimes.begin();
out << iter->second;

u64 tabs = std::min((u64)4, (u64)4 - (iter->second.size() / 8));
u64 tabs = std::min<u64>((u64)4, (u64)4 - (iter->second.size() / 8));

for (u64 i = 0; i < tabs; ++i)
out << "\t";
Expand All @@ -42,7 +44,7 @@ namespace osuCrypto
{
out << iter->second;

tabs = std::min((u64)4, (u64)4 - (iter->second.size() / 8));
tabs = std::min<u64>((u64)4, (u64)4 - (iter->second.size() / 8));

for (u64 i = 0; i < tabs ; ++i)
out << "\t";
Expand Down
8 changes: 5 additions & 3 deletions cryptoTools/Common/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <list>
#include <chrono>
#include <string>

#include <mutex>
namespace osuCrypto
{

Expand All @@ -14,10 +14,12 @@ namespace osuCrypto

timeUnit mStart;
std::list< std::pair<timeUnit, std::string>> mTimes;

bool mLocking;
//std::mutex mMtx;
public:
Timer()
Timer(bool locking = false)
:mStart(Timer::timeUnit::clock::now())
, mLocking(locking)
{}
//Timer(const Timer&);

Expand Down
Loading

0 comments on commit 4c63aba

Please sign in to comment.