...
 
Commits (5)
......@@ -23,7 +23,6 @@
#POSSIBILITY OF SUCH DAMAGE.
#
################
# Makefile contains core definitions and then includes build instructions
# for making all the palisade components
......@@ -59,12 +58,6 @@ ifdef BACKEND
CPPFLAGS += -DMATHBACKEND=$(BACKEND)
endif
## turn on openmp loop parallelization in the library code
## currently turns on loop parallelization only for the Matrix class
ifdef OMP
CPPFLAGS += -DOMP=$(OMP)
endif
#CPPFLAGS += -Wall -O3 -w -fopenmp -m64 -DNDEBUG ##undefine for parallel best performance operation with no debug
#THE OPTIONS BELOW SHOULD BE USED WITH CARE AS THEY USE A LOT OF AGGRESSIVE OPTIMIZATION OPTIONS
......@@ -73,7 +66,11 @@ endif
#CPPFLAGS += -Wall -Werror -m64 -Ofast -flto -march=native -funroll-loops -fopenmp -DNDEBUG ##undefine for multithread really best performance operation
#CPPFLAGS += -Wall -Werror -m64 -Ofast -flto -march=native -funroll-loops -fopenmp ##undefine for multithread really best performance operation
# base directory of project
ROOTDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PROJECT := palisade
VERSION := 1.3.0
#build directory
BUILDDIR := build
......@@ -92,16 +89,30 @@ HDREXT := h
$(objects) : %.o : %.cpp
THIRDPARTYINCLUDE := -I third-party/include -I third-party/include/rapidjson
# sub makefiles: each src subdirectory needs to be here
SUBMAKEFILES := core pke
# third party directories
THIRDPARTYDIR := third-party
THIRDPARTYLIBDIR := $(THIRDPARTYDIR)/lib
THIRDPARTYINCLUDE := -I $(THIRDPARTYDIR)/include -I $(THIRDPARTYDIR)/include/rapidjson
# dynamic lib directories on system
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
LIB_DEST := $(PREFIX)/lib/$(PROJECT)/$(VERSION)
EXTLIB := -L$(EXTLIBDIR) $(TEST_LIB) #no profiling
INC := -I src -I src/core/lib -I src/pke/lib -I test $(OMPINCLUDE) $(THIRDPARTYINCLUDE)
INC := -I src $(patsubst %,-Isrc/%/lib,$(SUBMAKEFILES)) -I test $(OMPINCLUDE) $(THIRDPARTYINCLUDE)
#the name of the shared object library for palisade objects.
PALISADECORELIB := libPALISADEcore$(LIBSUFFIX)
PALISADEPKELIB := libPALISADEpke$(LIBSUFFIX)
PALISADEPYLIB := pycrypto$(LIBSUFFIX)
# run make for all components. you can run any individual component separately
# by invoking "make allxxx" for example, make allcore makes everything in core only
......@@ -112,22 +123,37 @@ all:
docs: apidocs
alljava: allcore allpke jwrapper
allpython: allcore allpke pywrapper
alldemos: allcoredemos allpkedemos
testall: $(CORE_TEST_TARGET) $(PKE_TEST_TARGET) utall
$(BINDIR)/unittest/tests$(EXESUFFIX) -t
testall: $(CORE_TEST_TARGET) $(PKE_TEST_TARGET) $(TRAPDOOR_TEST_TARGET) $(WIP_TEST_TARGET) $(CIRCUIT_TEST_TARGET) $(ABE_TEST_TARGET) $(SIGNATURE_TEST_TARGET) utall
LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(ROOTDIR)/$(THIRDPARTYLIBDIR):$(ROOTDIR)/$(EXTLIBDIR) $(BINDIR)/unittest/tests$(EXESUFFIX) -t
# clean up all components. you can clean any individual compoenent separately
# by invoking "make cleantargets" for example
# each corresponding makefile will make the cleanxxxx target
.PHONY: clean clobber
clean: cleancore cleanpke cleandocs cleanbenchmark
.PHONY: clean
clean: cleancore cleanpke cleandocs cleanbenchmark
@echo 'Cleaning top level autogenerated directories'
$(RM) -rf $(BINDIR)
$(RM) -rf src/*/bin
.PHONY: clobber
clobber: clean clean_gmp clean_ntl
.PHONY: libdir
libdir:
install --directory $(LIB_DEST)
.PHONY: install
install: installcore installpke
.PHONY: uninstall
uninstall: uninstallcore uninstallpke
UNITTESTMAINOBJ := $(BINDIR)/unittest/Main_TestAll.o
$(UNITTESTMAINOBJ): test/include/gtest/Main_TestAll.cpp src/core/lib/math/backend.h
......
......@@ -48,8 +48,8 @@ CORE_TEST_TARGET := $(EXTTESTDIR)/core/tests$(EXESUFFIX)
-include $(COREUNITOBJECTS:.o=.d)
-include $(COREDEMOOBJECTS:.o=.d)
.PHONY:allcore
allcore: $(EXTLIBDIR)/$(PALISADECORELIB) $(CORE_TEST_TARGET) allcoredemos
.PHONY: allcore
allcore: ntl_all $(EXTLIBDIR)/$(PALISADECORELIB) $(CORE_TEST_TARGET) allcoredemos
allcoredemos: $(EXTLIBDIR)/$(PALISADECORELIB) $(patsubst $(COREBINDIR)/demo/%,$(BINDIR)/demo/core/%,$(patsubst %.o,%$(EXESUFFIX),$(COREDEMOOBJECTS)))
......@@ -95,7 +95,15 @@ $(CORE_TEST_TARGET): $(UNITTESTMAINOBJ) $(COREUNITOBJECTS) $(EXTLIBDIR)/$(PALISA
#used to run tests from make
.PHONY: testcore
testcore: $(CORE_TEST_TARGET)
$(CORE_TEST_TARGET)
LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(ROOTDIR)/$(THIRDPARTYLIBDIR):$(ROOTDIR)/$(EXTLIBDIR) $(CORE_TEST_TARGET)
.PHONY: installcore
installcore: libdir
install -t $(LIB_DEST) $(EXTLIBDIR)/$(PALISADECORELIB)
.PHONY: uninstallcore
uninstallcore:
rm $(LIB_DEST)/$(PALISADECORELIB)
corestrings:
@echo $(CORESOURCES)
......
......@@ -25,7 +25,7 @@
INDEXFILE := doc/apidocs/html/index.html
.PHONEY: apidocs
.PHONY: apidocs
apidocs: $(INDEXFILE)
$(INDEXFILE):
......@@ -34,7 +34,7 @@ $(INDEXFILE):
doxygen lbcrypto-doxy-config
@echo
.PHONEY: cleandocs
.PHONY: cleandocs
cleandocs:
@echo " Cleaning docs..."
rm -rf doc/apidocs
......
......@@ -18,7 +18,8 @@ else
endif
CPPSTD := -std=gnu++11 -fPIC
##CPPSTD := -std=gnu++11 -fPIC
CPPSTD := -std=gnu++11 -fPIC ##-mcmodel=large ## static allocator requires this memory model
CC := g++ $(CPPSTD)
LIBSUFFIX := .so
......@@ -35,3 +36,4 @@ LIBPYTHON := -lpython2.7
COMPTHREADFLAG := -pthread
LOADTHREADFLAG := -pthread
......@@ -96,5 +96,12 @@ $(PKE_TEST_TARGET): $(UNITTESTMAINOBJ) $(PKEUNITOBJECTS) $(EXTLIBDIR)/$(PALISADE
#used to run tests from make
.PHONY: testpke
testpke: $(PKE_TEST_TARGET)
$(PKE_TEST_TARGET)
LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(ROOTDIR)/$(THIRDPARTYLIBDIR):$(ROOTDIR)/$(EXTLIBDIR) $(PKE_TEST_TARGET)
.PHONY: installpke
installpke: libdir
install -t $(LIB_DEST) $(EXTLIBDIR)/$(PALISADEPKELIB)
.PHONY: uninstallpke
uninstallpke:
rm $(LIB_DEST)/$(PALISADEPKELIB)
PUG.png

52.6 KB

10/17/2018: PALISADE v1.3.0 is released
* Added support for the security levels/tables specified by the HomorphicEncryption.org security standard to all variants of the BFV scheme
* Optimized the packed encoding (batching)
* Simplified the signatures of classes and methods at multiple layers
* Fixed bugs that were brought to our attention
6/15/2018: PALISADE v1.2 is released
PALISADE v1.2 provides several important advancements and improvements to the library. Most notably, we provide:
......
......@@ -44,25 +44,4 @@
using namespace std;
using namespace lbcrypto;
using BE2Integer = cpu_int::BigInteger<integral_dtype,BigIntegerBitLength>;
using BE2ILParams = ILParamsImpl<BE2Integer>;
using BE2ILDCRTParams = ILDCRTParams<BE2Integer>;
using BE2Vector = cpu_int::BigVectorImpl<BE2Integer>;
using BE2Poly = PolyImpl<BE2Integer, BE2Integer, BE2Vector, BE2ILParams>;
using BE2DCRTPoly = DCRTPolyImpl<BE2Integer, BE2Integer, BE2Vector, BE2ILDCRTParams>;
using BE4Integer = exp_int::xubint;
using BE4ILParams = ILParamsImpl<BE4Integer>;
using BE4ILDCRTParams = ILDCRTParams<BE4Integer>;
using BE4Vector = exp_int::xmubintvec;
using BE4Poly = PolyImpl<BE4Integer, BE4Integer, BE4Vector, BE4ILParams>;
using BE4DCRTPoly = DCRTPolyImpl<BE4Integer, BE4Integer, BE4Vector, BE4ILDCRTParams>;
using BE6Integer = NTL::myZZ;
using BE6ILParams = ILParamsImpl<BE6Integer>;
using BE6ILDCRTParams = ILDCRTParams<BE6Integer>;
using BE6Vector = NTL::myVecP<NTL::myZZ>;
using BE6Poly = PolyImpl<BE6Integer, BE6Integer, BE6Vector, BE6ILParams>;
using BE6DCRTPoly = DCRTPolyImpl<BE6Integer, BE6Integer, BE6Vector, BE6ILDCRTParams>;
#endif /* BENCHMARK_SRC_ALLBACKENDS_H_ */
......@@ -72,7 +72,7 @@ void BM_keygen(benchmark::State& state) { // benchmark
}
try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
ChineseRemainderTransformFTT<BigVector>::PreCompute(cc->GetRootOfUnity(),
cc->GetCyclotomicOrder(),
cc->GetModulus());
} catch( ... ) {}
......@@ -108,7 +108,7 @@ void BM_encrypt(benchmark::State& state) { // benchmark
}
try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
ChineseRemainderTransformFTT<BigVector>::PreCompute(cc->GetRootOfUnity(),
cc->GetCyclotomicOrder(),
cc->GetModulus());
} catch( ... ) {}
......@@ -147,7 +147,7 @@ void BM_decrypt(benchmark::State& state) { // benchmark
}
try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
ChineseRemainderTransformFTT<BigVector>::PreCompute(cc->GetRootOfUnity(),
cc->GetCyclotomicOrder(),
cc->GetModulus());
} catch( ... ) {}
......@@ -185,7 +185,7 @@ void BM_rekeygen(benchmark::State& state) { // benchmark
}
try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
ChineseRemainderTransformFTT<BigVector>::PreCompute(cc->GetRootOfUnity(),
cc->GetCyclotomicOrder(),
cc->GetModulus());
} catch( ... ) {
......@@ -229,7 +229,7 @@ void BM_reencrypt(benchmark::State& state) { // benchmark
}
try {
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(cc->GetRootOfUnity(),
ChineseRemainderTransformFTT<BigVector>::PreCompute(cc->GetRootOfUnity(),
cc->GetCyclotomicOrder(),
cc->GetModulus());
} catch( ... ) {}
......
......@@ -110,8 +110,8 @@ void BM_encoding_PackedIntPlaintext(benchmark::State& state) {
BigInteger bigmodulus("80899135611688102162227204937217");
BigInteger bigroot("77936753846653065954043047918387");
auto cycloPoly = GetCyclotomicPolynomial<BigVector, BigInteger>(m, modulusQ);
ChineseRemainderTransformArb<BigInteger, BigVector>::SetCylotomicPolynomial(cycloPoly, modulusQ);
auto cycloPoly = GetCyclotomicPolynomial<BigVector>(m, modulusQ);
ChineseRemainderTransformArb<BigVector>::SetCylotomicPolynomial(cycloPoly, modulusQ);
lp.reset(new ILParams(m, modulusQ, squareRootOfRoot, bigmodulus, bigroot));
ep.reset(new EncodingParamsImpl(p,8));
......@@ -142,8 +142,8 @@ void BM_encoding_PackedIntPlaintext_SetParams(benchmark::State& state) {
BigInteger bigmodulus("80899135611688102162227204937217");
BigInteger bigroot("77936753846653065954043047918387");
auto cycloPoly = GetCyclotomicPolynomial<BigVector, BigInteger>(m, modulusQ);
ChineseRemainderTransformArb<BigInteger, BigVector>::SetCylotomicPolynomial(cycloPoly, modulusQ);
auto cycloPoly = GetCyclotomicPolynomial<BigVector>(m, modulusQ);
ChineseRemainderTransformArb<BigVector>::SetCylotomicPolynomial(cycloPoly, modulusQ);
lp.reset(new ILParams(m, modulusQ, squareRootOfRoot, bigmodulus, bigroot));
......
......@@ -57,9 +57,9 @@ void BM_BigInt_constants(benchmark::State& state) { // benchmark
}
}
DO_BENCHMARK_TEMPLATE(BM_BigInt_constants,BE2Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_constants,BE4Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_constants,BE6Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_constants,M2Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_constants,M4Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_constants,M6Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_constants,NativeInteger)
template<typename I>
......@@ -75,9 +75,9 @@ void BM_BigInt_small_variables(benchmark::State& state) { // benchmark
}
}
DO_BENCHMARK_TEMPLATE(BM_BigInt_small_variables,BE2Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_small_variables,BE4Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_small_variables,BE6Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_small_variables,M2Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_small_variables,M4Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_small_variables,M6Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_small_variables,NativeInteger)
template<typename I>
......@@ -92,9 +92,9 @@ void BM_BigInt_large_variables(benchmark::State& state) { // benchmark
}
}
DO_BENCHMARK_TEMPLATE(BM_BigInt_large_variables,BE2Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_large_variables,BE4Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_large_variables,BE6Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_large_variables,M2Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_large_variables,M4Integer)
DO_BENCHMARK_TEMPLATE(BM_BigInt_large_variables,M6Integer)
static string smalla("10403"), smallb("103");
static string largea("18446744073709551616"), largeb("18446744073709551617");
......@@ -116,12 +116,12 @@ static void BM_BigInt_Add(benchmark::State& state) { // benchmark
}
}
BENCHMARK_TEMPLATE(BM_BigInt_Add,BE2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Add,BE2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Add,BE4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Add,BE4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Add,BE6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Add,BE6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Add,M2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Add,M2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Add,M4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Add,M4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Add,M6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Add,M6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Add,NativeInteger)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
// +=
......@@ -140,12 +140,12 @@ static void BM_BigInt_Addeq(benchmark::State& state) { // benchmark
}
}
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,BE2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,BE2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,BE4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,BE4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,BE6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,BE6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,M2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,M2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,M4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,M4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,M6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,M6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Addeq,NativeInteger)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
// mult
......@@ -164,12 +164,12 @@ static void BM_BigInt_Mult(benchmark::State& state) { // benchmark
}
}
BENCHMARK_TEMPLATE(BM_BigInt_Mult,BE2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,BE2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,BE4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,BE4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,BE6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,BE6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,M2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,M2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,M4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,M4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,M6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,M6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Mult,NativeInteger)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
// *=
......@@ -188,12 +188,12 @@ static void BM_BigInt_Multeq(benchmark::State& state) { // benchmark
}
}
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,BE2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,BE2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,BE4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,BE4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,BE6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,BE6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,M2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,M2Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,M4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,M4Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,M6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,M6Integer)->Unit(benchmark::kMicrosecond)->ArgName("Large")->Arg(1);
BENCHMARK_TEMPLATE(BM_BigInt_Multeq,NativeInteger)->Unit(benchmark::kMicrosecond)->ArgName("Small")->Arg(0);
//execute the benchmarks
......
This diff is collapsed.
......@@ -81,9 +81,9 @@ static void BM_BigVec_Add(benchmark::State& state) { // benchmark
}
DO_NATIVEVECTOR_BENCHMARK(BM_BigVec_Add)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Add, BE2Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Add, BE4Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Add, BE6Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Add, M2Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Add, M4Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Add, M6Vector)
// +=
template <typename V>
......@@ -105,9 +105,9 @@ static void BM_BigVec_Addeq(benchmark::State& state) { // benchmark
}
DO_NATIVEVECTOR_BENCHMARK(BM_BigVec_Addeq)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Addeq, BE2Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Addeq, BE4Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Addeq, BE6Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Addeq, M2Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Addeq, M4Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Addeq, M6Vector)
// mult
template <typename V>
......@@ -129,9 +129,9 @@ static void BM_BigVec_Mult(benchmark::State& state) { // benchmark
}
DO_NATIVEVECTOR_BENCHMARK(BM_BigVec_Mult)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Mult, BE2Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Mult, BE4Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Mult, BE6Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Mult, M2Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Mult, M4Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Mult, M6Vector)
// mult
template <typename V>
......@@ -153,9 +153,9 @@ static void BM_BigVec_Multeq(benchmark::State& state) { // benchmark
}
DO_NATIVEVECTOR_BENCHMARK(BM_BigVec_Multeq)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Multeq, BE2Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Multeq, BE4Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Multeq, BE6Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Multeq, M2Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Multeq, M4Vector)
DO_VECTOR_BENCHMARK_TEMPLATE(BM_BigVec_Multeq, M6Vector)
//execute the benchmarks
BENCHMARK_MAIN()
......@@ -34,14 +34,14 @@ using namespace lbcrypto;
template<typename V>
inline V makeVector(usint ringdim, const typename V::Integer& mod) {
DiscreteUniformGeneratorImpl<typename V::Integer,V> dug;
DiscreteUniformGeneratorImpl<V> dug;
dug.SetModulus(mod);
return dug.GenerateVector(ringdim);
}
inline NativeVector makeNativeVector(usint ringdim, const NativeInteger& mod) {
DiscreteUniformGeneratorImpl<NativeInteger,NativeVector> dug;
DiscreteUniformGeneratorImpl<NativeVector> dug;
dug.SetModulus(mod);
return dug.GenerateVector(ringdim);
......
No preview for this file type
......@@ -51,7 +51,7 @@ PROJECT_BRIEF = "A lattice crypto library for software engineers by sof
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
# the logo to the output directory.
PROJECT_LOGO = "PALISADE_badger.jpg"
PROJECT_LOGO = "PUG.png"
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
# into which the generated documentation will be written. If a relative path is
......
......@@ -23,7 +23,7 @@
*
*/
#include "../lib/math/transfrm.h"
#include "../lib/math/dftransfrm.h"
using namespace lbcrypto;
......@@ -110,4 +110,4 @@ int main() {
std::cin.ignore();
std::cin.get();
}
\ No newline at end of file
}
......@@ -42,16 +42,13 @@
#include <chrono>
#include <exception>
#include "utils/debug.h"
#include <omp.h> //open MP header
using namespace std;
using namespace lbcrypto;
//define the main sections of the test
void test_BigVector(usint nloop); // test old version of big int vector
void test_ubintvec(usint nloop); // test new vector version
//main() need this for Kurts' makefile to ignore this.
......
......@@ -51,7 +51,6 @@
#include <chrono>
#include <exception>
#include "utils/debug.h"
#include <omp.h> //open MP header
using namespace std;
using namespace lbcrypto;
......
......@@ -44,7 +44,6 @@
#include <chrono>
#include <exception>
#include "utils/debug.h"
#include <omp.h> //open MP header
using namespace std;
using namespace lbcrypto;
......@@ -209,11 +208,11 @@ void test_NTT (const usint level, const usint nloop) {
//Precomputations for FTT
TIC(t_setup);
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(rootOfUnity1, m, q1);
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(rootOfUnity2, m, q2);
ChineseRemainderTransformFTT<BigVector>::PreCompute(rootOfUnity1, m, q1);
ChineseRemainderTransformFTT<BigVector>::PreCompute(rootOfUnity2, m, q2);
cout<<"CRT 2 setup time "<<TOC_US(t_setup)<<" usec"<<endl;
TIC(t_setup);
ChineseRemainderTransformFTT<BigInteger,BigVector>::PreCompute(rootOfUnity3, m, q3);
ChineseRemainderTransformFTT<BigVector>::PreCompute(rootOfUnity3, m, q3);
cout<<"CRT 3 setup time "<<TOC_US(t_setup)<<" usec"<<endl;
time1af = 0.0;
......
......@@ -33,10 +33,7 @@
#include <chrono>
#include <thread>
#include "utils/debug.h"
#include <omp.h> //open MP header
//using namespace std;
//using namespace lbcrypto;
#include "utils/parallel.h"
//function to verify our generated array
void verify(float *foo, uint32_t array_size){
......@@ -64,6 +61,8 @@ int main(int argc, char* argv[]){
// note if you set dbg_flag = true then all the following DEBUG() statments print to stdout.
bool dbg_flag = true;
lbcrypto::PalisadeParallelControls.Enable();
uint32_t array_size = 1000;
DEBUGEXP(argc);
DEBUGEXP(argv[0]);
......
......@@ -40,8 +40,17 @@ bool PackedEncoding::Encode() {
if( this->isEncoded ) return true;
auto mod = this->encodingParams->GetPlaintextModulus();
if( this->typeFlag == IsNativePoly ) {
NativeVector temp(this->GetElementRingDimension(), this->GetElementModulus().ConvertToInt());
if (( this->typeFlag == IsNativePoly ) || (this->typeFlag == IsDCRTPoly )) {
NativeVector temp;
if ( this->typeFlag == IsNativePoly )
temp = NativeVector(this->GetElementRingDimension(), this->GetElementModulus().ConvertToInt());
else {
NativeInteger q0 = this->encodedVectorDCRT.GetParams()->GetParams()[0]->GetModulus().ConvertToInt();
temp = NativeVector(this->GetElementRingDimension(), q0);
if( q0 < mod )
throw std::logic_error("the plaintext modulus size is larger than the size of CRT moduli; either decrease the plaintext modulus or increase the CRT moduli.");
}
size_t i;
for( i=0; i < value.size(); i++ ) {
......@@ -59,9 +68,28 @@ bool PackedEncoding::Encode() {
temp[i] = NativeInteger(0);
this->isEncoded = true;
this->GetElement<NativePoly>().SetValues(temp, Format::EVALUATION); //output was in coefficient format
if ( this->typeFlag == IsNativePoly ) {
this->GetElement<NativePoly>().SetValues(temp, Format::EVALUATION); //the input plaintext data is in the evaluation format
this->Pack(&this->GetElement<NativePoly>(), this->encodingParams->GetPlaintextModulus());//ilVector coefficients are packed and resulting ilVector is in COEFFICIENT form.
}
else
{
NativePoly firstElement = this->GetElement<DCRTPoly>().GetElementAtIndex(0);
firstElement.SetValues(temp, Format::EVALUATION); //the input plaintext data is in the evaluation format
this->Pack(&firstElement, this->encodingParams->GetPlaintextModulus());//ilVector coefficients are packed and resulting ilVector is in COEFFICIENT form.
this->encodedVectorDCRT.SetElementAtIndex(0,firstElement);
const shared_ptr<ILDCRTParams<BigInteger>> params = this->encodedVectorDCRT.GetParams();
const std::vector<std::shared_ptr<ILNativeParams>> &nativeParams = params->GetParams();
for (size_t i = 1; i < nativeParams.size(); i++ ) {
NativePoly temp(firstElement);
temp.SwitchModulus(nativeParams[i]->GetModulus(),nativeParams[i]->GetRootOfUnity());
this->encodedVectorDCRT.SetElementAtIndex(i,temp);
}
}
this->Pack(&this->GetElement<NativePoly>(), this->encodingParams->GetPlaintextModulus());//ilVector coefficients are packed and resulting ilVector is in COEFFICIENT form.
}
else {
BigVector temp(this->GetElementRingDimension(), BigInteger(this->GetElementModulus()));
......@@ -82,16 +110,11 @@ bool PackedEncoding::Encode() {
temp[i] = BigInteger(0);
this->isEncoded = true;
this->GetElement<Poly>().SetValues(temp, Format::EVALUATION); //output was in coefficient format
this->GetElement<Poly>().SetValues(temp, Format::EVALUATION); //the input plaintext data is in the evaluation format
this->Pack(&this->GetElement<Poly>(), this->encodingParams->GetPlaintextModulus());//ilVector coefficients are packed and resulting ilVector is in COEFFICIENT form.
}
if( this->typeFlag == IsDCRTPoly ) {
this->encodedVectorDCRT = this->encodedVector;
}
return true;
}
......@@ -107,9 +130,17 @@ bool PackedEncoding::Decode() {
auto ptm = this->encodingParams->GetPlaintextModulus();
if( this->typeFlag == IsNativePoly ) {
this->Unpack(&this->GetElement<NativePoly>(), ptm);
fillVec(this->encodedNativeVector, this->value);
if (( this->typeFlag == IsNativePoly ) || (this->typeFlag == IsDCRTPoly )) {
if ( this->typeFlag == IsNativePoly ) {
this->Unpack(&this->GetElement<NativePoly>(), ptm);
fillVec(this->encodedNativeVector, this->value);
}
else
{
NativePoly firstElement = this->GetElement<DCRTPoly>().GetElementAtIndex(0);
this->Unpack(&firstElement, ptm);
fillVec(firstElement, this->value);
}
}
else {
this->Unpack(&this->GetElement<Poly>(), ptm);
......@@ -251,11 +282,11 @@ void PackedEncoding::Pack(P *ring, const PlaintextModulus &modulus) const {
for (usint i = 0; i < phim; i++) {
permutedSlots[i] = slotValues[m_toCRTPerm[m][i]];
}
ChineseRemainderTransformFTT<NativeInteger, NativeVector>::InverseTransform(permutedSlots, m_initRoot[modulusM], m, &slotValues);
ChineseRemainderTransformFTT<NativeVector>::InverseTransform(permutedSlots, m_initRoot[modulusM], m, &slotValues);
}
else
{
ChineseRemainderTransformFTT<NativeInteger, NativeVector>::InverseTransform(slotValues, m_initRoot[modulusM], m, &slotValues);
ChineseRemainderTransformFTT<NativeVector>::InverseTransform(slotValues, m_initRoot[modulusM], m, &slotValues);
}
} else { // Arbitrary cyclotomic
......@@ -271,7 +302,7 @@ void PackedEncoding::Pack(P *ring, const PlaintextModulus &modulus) const {
DEBUG("m_bigModulus[modulusM] " << m_bigModulus[modulusM]);
DEBUG("m_bigRoot[modulusM] " << m_bigRoot[modulusM]);
slotValues = ChineseRemainderTransformArb<NativeInteger, NativeVector>::
slotValues = ChineseRemainderTransformArb<NativeVector>::
InverseTransform(permutedSlots, m_initRoot[modulusM], m_bigModulus[modulusM], m_bigRoot[modulusM], m);
}
......@@ -316,9 +347,9 @@ void PackedEncoding::Unpack(P *ring, const PlaintextModulus &modulus) const {
// Transform Coeff to Eval
NativeVector permutedSlots(phim, modulusNI);
if (!(m & (m-1))) { // Check if m is a power of 2
ChineseRemainderTransformFTT<NativeInteger, NativeVector>::ForwardTransform(packedVector, m_initRoot[modulusM], m, &permutedSlots);
ChineseRemainderTransformFTT<NativeVector>::ForwardTransform(packedVector, m_initRoot[modulusM], m, &permutedSlots);
} else { // Arbitrary cyclotomic
permutedSlots = ChineseRemainderTransformArb<NativeInteger, NativeVector>::
permutedSlots = ChineseRemainderTransformArb<NativeVector>::
ForwardTransform(packedVector, m_initRoot[modulusM], m_bigModulus[modulusM], m_bigRoot[modulusM], m);
}
......@@ -363,7 +394,7 @@ void PackedEncoding::SetParams_2n(usint m, const NativeInteger &modulusNI) {
m_toCRTPerm[m][(curr_index - 1) / 2] = i;
m_fromCRTPerm[m][i] = (curr_index - 1) / 2;
usint cofactor_index = curr_index * 3 % m;
usint cofactor_index = curr_index * (m-1) % m;
m_toCRTPerm[m][(cofactor_index - 1) / 2] = i + phim_by_2;
m_fromCRTPerm[m][i + phim_by_2] = (cofactor_index - 1) / 2;
......@@ -402,7 +433,7 @@ void PackedEncoding::SetParams_2n(usint m, EncodingParams params){
m_toCRTPerm[m][(curr_index - 1) / 2] = i;
m_fromCRTPerm[m][i] = (curr_index - 1) / 2;
usint cofactor_index = curr_index * 3 % m;
usint cofactor_index = curr_index * (m-1) % m;
m_toCRTPerm[m][(cofactor_index - 1) / 2] = i + phim_by_2;
m_fromCRTPerm[m][i + phim_by_2] = (cofactor_index - 1) / 2;
......
/**
* @file plaintext-impl.cpp This file contains template instantiations for plaintext matrixes
*
* @author TPOC: palisade@njit.edu
*
* @copyright Copyright (c) 2017, New Jersey Institute of Technology (NJIT)
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "math/backend.h"
#include "lattice/backend.h"
#include "math/matrix.cpp"
namespace lbcrypto {
MATRIX_NOT_SERIALIZABLE(Plaintext)
}
......@@ -30,26 +30,26 @@
#include <vector>
#include <initializer_list>
#include <iostream>
#include "encodingparams.h"
#include "../utils/inttypes.h"
#include "../math/backend.h"
#include "../lattice/elemparams.h"
#include "../lattice/dcrtpoly.h"
#include "../lattice/ilparams.h"
#include "../lattice/ildcrtparams.h"
#include "../lattice/poly.h"
#include "../lattice/backend.h"
using std::shared_ptr;
namespace lbcrypto
{
enum PlaintextEncodings {
Unknown,
Unknown = 0,
Scalar,
Integer,
CoefPacked,
Packed,
String,
Fractional,
//MaxKnownEncoding = 7
};
inline std::ostream& operator<<(std::ostream& out, const PlaintextEncodings p) {
......@@ -100,9 +100,10 @@ class PlaintextImpl
protected:
bool isEncoded;
PtxtPolyType typeFlag;
EncodingParams encodingParams;
EncodingParams encodingParams;
//mutable ILElement *vec;
mutable Poly encodedVector;
mutable NativePoly encodedNativeVector;
mutable NativePoly encodedNativeVector;
mutable DCRTPoly encodedVectorDCRT;
public:
......
PALISADE Lattice Cryptography Library
=====================================
[License Information](License.md)
[Contact Information](Contact.md)
[Library Contributors](Contributors.md)
Document Description
===================
This document is intended to describe the overall design, design considerations and structure of the lattice directory in the PALISADE lattice crypto library.
Lattice Directory Description
=============================
Directory Objective
-------------------
The files in the lattice directory support the lattice layer operations in the library. The layer is used to represent polynomial rings
and support operations over polynomial rings.
This lattice layer is a middle layer in the library.
The lattice layer supports higher-level calls for operations on ring elements necessary for lattice cryptography.
The lattice layer is intended to make calls to lower layers that support math operations, such as modulus and ring arithmetic.
File Listing
------------
* Parameter classes files
- [elemparams.h](src/lib/lattice/elemparams.h): This header file is a simple class to contain ring element parameters.
- [ilparams.h](src/lib/lattice/ilparams.h), [ilparams.cpp](src/lib/lattice/ilparams.cpp): This pair of files represents a parameter class for the basic single-CRT lattice parameters. This class inherits from the class in [elemparams.h](src/lib/lattice/elemparams.h).
- [ildcrtparams.h](src/lib/lattice/ildcrtparams.h): This file represents a parameter class for the more advanced and computationally efficient double-CRT lattice parameters. This class inherits from the class in [ilparams.h](src/lib/lattice/ilparams.h), [ilparams.cpp](src/lib/lattice/ilparams.cpp).
* Element classes files
- [ilelement.h](src/lib/lattice/ilelement.h): This file presents a basic interface class for elements from ideal lattices.
- [poly.h](src/lib/lattice/poly.h), [poly.cpp](src/lib/lattice/poly.cpp): These files present a basic class for Poly, elements from ideal lattices using a single-CRT representation. This class inherits from the class in [ilelement.h](src/lib/lattice/ilelement.h). This file also defines a NativePoly, which is simply a Poly using NativeInteger coefficients. A NativePoly is an important part of a DCRTPoly.
- [dcrtpoly.h](src/lib/lattice/dcrtpoly.h), [dcrtpoly.cpp](src/lib/lattice/dcrtpoly.cpp): These files present a basic class for DCRTPoly, elements from ideal lattices using a double-CRT representation. This class inherits from the class in [ilelement.h](src/lib/lattice/ilelement.h).
* Documentation files
- [README.md](src/lib/lattice/README.md): This file.
Directory Description
=====================
The primary objective of the code in this directory is to represent polynomial ring elements and manipulations on these elements. The current implementations support polynomial rings that are of dimension a power of two (e.g. x^n + 1 where n is a power of 2). A polynomial ring is defined as Rq := R/qR = Zq[X]/(f(X)), with f(X) a mononic irreducable polynomial of degree n, and q an integer modulus.
Support for arbitrary cyclotomic rings is also available but in experimental mode. The case of m = p and m = 2*p, where m is a cyclotomic order and p is a prime, have been tested relatively well. Other cases of m have not been tested.
The three main data classes in this layer are Poly, NativePoly and DCRTPoly.
A Poly is a single-CRT representation using BigInteger types as coefficients, and supporting a large modulus q.
A NativePoly is a single-CRT representation using NativeInteger types, which limites the size of the coefficients and the modulus q to 64 bits.
A DCRTPoly is a double-CRT representation. In practice, this means that Poly uses a single large modulus q, while DCRTPoly uses multiple smaller moduli. Hence, Poly runs slower than DCRTPoly because DCRTPoly operations can be easier to fit into the native bitwidths of commodity processors.
Poly, NativePoly and DCRTPoly all implement the interface ILElement. Any new ring polynomial classes should be built to conform to this interface.
The classes ILParams and ILDCRTParams contain parameters for the ring element representations. In the case of Poly and NativePoly, this includes the order, modulus and root of unity. In the case of DCRTPoly, this includes the order, double-CRT width, moduli and roots of unity.
ILParams and ILDCRTParams implement the interface ElemParams. Any new parameter should be built to conform to this interface.
FORMAT
------
The coefficients of the polynomial ring, in their initial form, are just coefficients.
Translated into one of Poly or DCRTPoly, can be simply seen
as vector's representing polynomial rings.
We internally represent polynomial ring elements as being either in coefficient or evaluation format. The initial or raw format, is noted as COEFFICIENT throughout the code. By applying the Chinese-Remainder-Transform (CRT), which is a Number Theoretic Transform (NTT) and variant of the Discrete Fourier Transform (DFT), we convert the ring elements into the EVALUATION format. The EVALUATION format, with respect to multiplying two or more ring polynomials, allows us to do element-wise multiplication on the vectors.
Note that it is generally computationally less expensive to carry on all operations in the evaluation former. However, the CRT and inverse CRT operations take O(nlogn) time using current best known algorithms, where n is the ring dimension.
ASSUMPTIONS
===========
* It is assumed that any scalar or vector operation such as multiplication, addition etc. done on one or more operations contain the same params.
- Checks need to be added to the code to test the compatibility of parameters.
* Multiplication is currently only implemented in the EVALUATION format.
- Code needs to be added to implement COEFFICIENT format multiplication, if desired.
/**
* @file backend.h This file contains the functionality to switch between lattice backends
*
* @author TPOC: palisade@njit.edu
*
* @copyright Copyright (c) 2017, New Jersey Institute of Technology (NJIT)
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef LBCRYPTO_LATTICE_BACKEND_H
#define LBCRYPTO_LATTICE_BACKEND_H
#include "../lattice/elemparams.h"
#include "../lattice/ilparams.h"
#include "../lattice/ildcrtparams.h"
#include "../lattice/ilelement.h"
#include "../lattice/poly.h"
namespace lbcrypto {
template<typename IntType> class ILParamsImpl;
template<typename VecType> class PolyImpl;
using M2Poly = PolyImpl<M2Vector>;
using M4Poly = PolyImpl<M4Vector>;
using M6Poly = PolyImpl<M6Vector>;
using NativePoly = PolyImpl<NativeVector>;
using M2Params = ILParamsImpl<M2Integer>;
using M4Params = ILParamsImpl<M4Integer>;
using M6Params = ILParamsImpl<M6Integer>;
using ILNativeParams = ILParamsImpl<NativeInteger>;
// the default for the backend...
using ILParams = ILParamsImpl<BigInteger>;
using Poly = PolyImpl<BigVector>;
} // namespace lbcrypto ends
#include "../lattice/dcrtpoly.h"
namespace lbcrypto {
template<typename IntType> class ILDCRTParams;
template<typename VecType> class DCRTPolyImpl;
using M2DCRTPoly = DCRTPolyImpl<M2Vector>;
using M4DCRTPoly = DCRTPolyImpl<M4Vector>;
using M6DCRTPoly = DCRTPolyImpl<M6Vector>;
using M2DCRTParams = ILDCRTParams<M2Integer>;
using M4DCRTParams = ILDCRTParams<M4Integer>;
using M6DCRTParams = ILDCRTParams<M6Integer>;
// the default for the backend...
using DCRTPoly = DCRTPolyImpl<BigVector>;
} // namespace lbcrypto ends
#endif
#define RUN_BIG_POLYS(FUNCTION, MESSAGE) { \
if( TestB2 ) { using V = M2Poly; FUNCTION<V>("BE2Poly " MESSAGE); } \
if( TestB4 ) { using V = M4Poly; FUNCTION<V>("BE4Poly " MESSAGE); } \
if( TestB6 ) { using V = M6Poly; FUNCTION<V>("BE6Poly " MESSAGE); } \
}
#define RUN_BIG_DCRTPOLYS(FUNCTION, MESSAGE) { \
if( TestB2 ) { using V = M2DCRTPoly; FUNCTION<V>("BE2DCRTPoly " MESSAGE); } \
if( TestB4 ) { using V = M4DCRTPoly; FUNCTION<V>("BE4DCRTPoly " MESSAGE); } \
if( TestB6 ) { using V = M6DCRTPoly; FUNCTION<V>("BE6DCRTPoly " MESSAGE); } \
}
#define RUN_ALL_POLYS(FUNCTION, MESSAGE) { \
RUN_BIG_POLYS(FUNCTION,MESSAGE) \
if( TestNative ) { using V = NativePoly; FUNCTION<V>("Native " MESSAGE); } \
}
/**
* @file be2-poly-impl.cpp This file contains template instantiations for all classes using math be2
*
* @author TPOC: palisade@njit.edu
*
* @copyright Copyright (c) 2017, New Jersey Institute of Technology (NJIT)
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "math/backend.h"
#include "lattice/backend.h"
#include "math/matrix.cpp"
#include "matrix-lattice-impl.cpp"
#include "elemparams.cpp"
#include "ilparams.cpp"
#include "poly.cpp"
namespace lbcrypto {
template class ElemParams<M2Integer>;
template class ILParamsImpl<M2Integer>;
template class PolyImpl<M2Vector>;
template class DCRTPolyImpl<M2Vector>;
template class Matrix<M2Poly>;
ONES_FOR_TYPE(M2Poly)
IDENTITY_FOR_TYPE(M2Poly)
GADGET_FOR_TYPE(M2Poly)
NORM_FOR_TYPE(M2Poly)
MATRIX_NOT_SERIALIZABLE(M2Poly)
SPLIT64_FOR_TYPE(M2Poly)
SPLIT64ALT_FOR_TYPE(M2Poly)
SPLIT32ALT_FOR_TYPE(M2Poly)
template Matrix<M2Vector> RotateVecResult(Matrix<M2Poly> const& inMat);
template Matrix<M2Integer> Rotate(Matrix<M2Poly> const& inMat);
template class Matrix<M2DCRTPoly>;
ONES_FOR_TYPE(M2DCRTPoly)
IDENTITY_FOR_TYPE(M2DCRTPoly)
GADGET_FOR_TYPE(M2DCRTPoly)
NORM_FOR_TYPE(M2DCRTPoly)
MATRIX_NOT_SERIALIZABLE(M2DCRTPoly)
SPLIT64_FOR_TYPE(M2DCRTPoly)
SPLIT64ALT_FOR_TYPE(M2DCRTPoly)
SPLIT32ALT_FOR_TYPE(M2DCRTPoly)
template Matrix<M2Vector> RotateVecResult(Matrix<M2DCRTPoly> const& inMat);
template Matrix<M2Integer> Rotate(Matrix<M2DCRTPoly> const& inMat);
}
/**
* @file be4-poly-impl.cpp This file contains template instantiations for all classes using math be4
*
* @author TPOC: palisade@njit.edu
*
* @copyright Copyright (c) 2017, New Jersey Institute of Technology (NJIT)
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "math/backend.h"
#include "lattice/backend.h"
#include "math/matrix.cpp"
#include "matrix-lattice-impl.cpp"
#include "elemparams.cpp"
#include "ilparams.cpp"
#include "poly.cpp"
namespace lbcrypto {
template class ElemParams<M4Integer>;
template class ILParamsImpl<M4Integer>;
template class PolyImpl<M4Vector>;
template class DCRTPolyImpl<M4Vector>;
template class Matrix<M4Poly>;
ONES_FOR_TYPE(M4Poly)
IDENTITY_FOR_TYPE(M4Poly)
GADGET_FOR_TYPE(M4Poly)
NORM_FOR_TYPE(M4Poly)
MATRIX_NOT_SERIALIZABLE(M4Poly)
SPLIT64_FOR_TYPE(M4Poly)
SPLIT64ALT_FOR_TYPE(M4Poly)
SPLIT32ALT_FOR_TYPE(M4Poly)
template Matrix<M4Vector> RotateVecResult(Matrix<M4Poly> const& inMat);
template Matrix<M4Integer> Rotate(Matrix<M4Poly> const& inMat);
template class Matrix<M4DCRTPoly>;
ONES_FOR_TYPE(M4DCRTPoly)
IDENTITY_FOR_TYPE(M4DCRTPoly)
GADGET_FOR_TYPE(M4DCRTPoly)
NORM_FOR_TYPE(M4DCRTPoly)
MATRIX_NOT_SERIALIZABLE(M4DCRTPoly)
SPLIT64_FOR_TYPE(M4DCRTPoly)
SPLIT64ALT_FOR_TYPE(M4DCRTPoly)
SPLIT32ALT_FOR_TYPE(M4DCRTPoly)
template Matrix<M4Vector> RotateVecResult(Matrix<M4DCRTPoly> const& inMat);
template Matrix<M4Integer> Rotate(Matrix<M4DCRTPoly> const& inMat);
}
/**
* @file be6-poly-impl.cpp This file contains template instantiations for all classes using math be6
*
* @author TPOC: palisade@njit.edu
*
* @copyright Copyright (c) 2017, New Jersey Institute of Technology (NJIT)
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "math/backend.h"
#include "lattice/backend.h"
#include "math/matrix.cpp"
#include "matrix-lattice-impl.cpp"
#include "elemparams.cpp"
#include "ilparams.cpp"
#include "poly.cpp"
namespace lbcrypto {
template class ElemParams<M6Integer>;
template class ILParamsImpl<M6Integer>;
template class PolyImpl<M6Vector>;
template class DCRTPolyImpl<M6Vector>;
template class Matrix<M6Poly>;
ONES_FOR_TYPE(M6Poly)
IDENTITY_FOR_TYPE(M6Poly)
GADGET_FOR_TYPE(M6Poly)
NORM_FOR_TYPE(M6Poly)
MATRIX_NOT_SERIALIZABLE(M6Poly)
SPLIT64_FOR_TYPE(M6Poly)
SPLIT64ALT_FOR_TYPE(M6Poly)
SPLIT32ALT_FOR_TYPE(M6Poly)
template Matrix<M6Vector> RotateVecResult(Matrix<M6Poly> const& inMat);
template Matrix<M6Integer> Rotate(Matrix<M6Poly> const& inMat);
template class Matrix<M6DCRTPoly>;
ONES_FOR_TYPE(M6DCRTPoly)
IDENTITY_FOR_TYPE(M6DCRTPoly)
GADGET_FOR_TYPE(M6DCRTPoly)
NORM_FOR_TYPE(M6DCRTPoly)
MATRIX_NOT_SERIALIZABLE(M6DCRTPoly)
SPLIT64_FOR_TYPE(M6DCRTPoly)
SPLIT64ALT_FOR_TYPE(M6DCRTPoly)
SPLIT32ALT_FOR_TYPE(M6DCRTPoly)
template Matrix<M6Vector> RotateVecResult(Matrix<M6DCRTPoly> const& inMat);
template Matrix<M6Integer> Rotate(Matrix<M6DCRTPoly> const& inMat);
}
......@@ -23,14 +23,11 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "../math/backend.h"
#include "../math/native_int/binint.h"
#include "../math/native_int/binvect.cpp"
#include "../math/discretegaussiangenerator.cpp"
#include "../math/discreteuniformgenerator.cpp"
#include "../math/binaryuniformgenerator.cpp"
#include "../math/ternaryuniformgenerator.cpp"
#define BLOCK_VECTOR_IMPLEMENT
#include "math/backend.h"
#include "lattice/backend.h"
#include "math/matrix.cpp"
#include "matrix-lattice-impl.cpp"
#include "elemparams.cpp"
#include "ilparams.cpp"
......@@ -38,12 +35,21 @@
namespace lbcrypto
{
template class DiscreteGaussianGeneratorImpl<NativeInteger,NativeVector>;
template class BinaryUniformGeneratorImpl<NativeInteger,NativeVector>;
template class TernaryUniformGeneratorImpl<NativeInteger,NativeVector>;
template class DiscreteUniformGeneratorImpl<NativeInteger,NativeVector>;
template class ElemParams<NativeInteger>;
template class ILParamsImpl<NativeInteger>;
template class PolyImpl<NativeInteger,NativeInteger,NativeVector,ILNativeParams>;
template class PolyImpl<NativeVector>;
template class Matrix<NativePoly>;
ONES_FOR_TYPE(NativePoly)
IDENTITY_FOR_TYPE(NativePoly)
GADGET_FOR_TYPE(NativePoly)
NORM_FOR_TYPE(NativePoly)
MATRIX_NOT_SERIALIZABLE(NativePoly)
SPLIT64_FOR_TYPE(NativePoly)
SPLIT64ALT_FOR_TYPE(NativePoly)
SPLIT32ALT_FOR_TYPE(NativePoly)
template Matrix<NativeVector> RotateVecResult(Matrix<NativePoly> const& inMat);
template Matrix<NativeInteger> Rotate(Matrix<NativePoly> const& inMat);
}
......@@ -25,8 +25,6 @@
*/
#include "../math/backend.h"
#include "../math/cpu_int/binint.cpp"
#include "../math/cpu_int/binvect.cpp"
#include "elemparams.cpp"
#include "ildcrtparams.cpp"
#include "../math/discretegaussiangenerator.cpp"
......@@ -41,8 +39,11 @@
namespace lbcrypto
{
template class ElemParams<NativeInteger>;
template class ILDCRTParams<BigInteger>;
template class DCRTPolyImpl<BigInteger, BigInteger, BigVector, ILDCRTParams<BigInteger>>;
template class ILDCRTParams<M2Integer>;
template class DCRTPolyImpl<M2Vector>;
template class ILDCRTParams<M4Integer>;
template class DCRTPolyImpl<M4Vector>;
template class ILDCRTParams<M6Integer>;
template class DCRTPolyImpl<M6Vector>;
}
This diff is collapsed.
This diff is collapsed.
/**
* @file plaintext.h Represents and defines plaintext objects in Palisade.
* @file elemparamfactory.cpp - constructs element parameters
* @author TPOC: palisade@njit.edu
*
* @copyright Copyright (c) 2017, New Jersey Institute of Technology (NJIT)
......
/**
* @file plaintext.h Represents and defines plaintext objects in Palisade.
* @file elemparams.h base class for parameters for a lattice element
* @author TPOC: palisade@njit.edu
*
* @copyright Copyright (c) 2017, New Jersey Institute of Technology (NJIT)
......
......@@ -26,10 +26,11 @@
#ifndef _SRC_LIB_LATTICE_SIGNATURE_FIELD2N_H
#define _SRC_LIB_LATTICE_SIGNATURE_FIELD2N_H
#include "poly.h"
#include "../math/backend.h"
#include "../lattice/backend.h"
#include "../math/transfrm.h"
#include "../math/dftransfrm.h"
#include "../math/matrix.h"
#include "dcrtpoly.h"
namespace lbcrypto
{
......@@ -45,6 +46,8 @@ public:
*/
Field2n() : format(COEFFICIENT) {};
Field2n(Format f) : format(f) {};
/**
* @brief Constructor for field element
* @param size element size
......@@ -221,6 +224,83 @@ public:
}
/**
* @brief In-place addition operation for field elements
*
* @param &element right hand side element for operation
* @return result of the operation
*/
const Field2n& operator+=(const Field2n &element) {
return *this = this->Plus(element);
}
/**
* @brief In-place subtraction operation for field elements
*
* @param &element right hand side element for operation
* @return result of the operation
*/
const Field2n& operator-=(const Field2n &element) {
return *this = this->Minus(element);
}
/**
* @brief Unary minus on a field element.
* @return negation of the field element.
*/
Field2n operator-() const {
Field2n all0(size(), this->GetFormat(), true);
return all0 - *this;
}