Commit fd6f7ed5 authored by Gerard Ryan's avatar Gerard Ryan

Merge branch 'polyakov-trapdoor' into 'master'

Polyakov trapdoor

Fixes #786
Adds support of NativePoly to the trapdoor classes
Adds support of NativePoly to the GPV signature
@ss2959

See merge request !354
parents a0a2b8fd 2e3b1e43
......@@ -67,6 +67,7 @@ public:
typedef TernaryUniformGeneratorImpl<IntType,VecType> TugType;
typedef BinaryUniformGeneratorImpl<IntType,VecType> BugType;
typedef PolyImpl<NativeInteger,NativeInteger,NativeVector,ILNativeParams> PolyNative;
typedef PolyImpl<ModType,IntType,VecType,ParmType> PolyLargeType;
/**
* @brief Return the element name.
......
......@@ -144,7 +144,7 @@ namespace lbcrypto {
}
NORM_FOR_TYPE(Poly)
//TODO: note there is no NORM_FOR_TYPE(NativePoly)
NORM_FOR_TYPE(NativePoly)
NORM_FOR_TYPE(DCRTPoly)
//template Matrix<T>::Norm() for types that have NO norm
......@@ -178,6 +178,7 @@ namespace lbcrypto {
}
SPLIT64_FOR_TYPE(Poly)
SPLIT64_FOR_TYPE(NativePoly)
SPLIT64_FOR_TYPE(DCRTPoly)
// split a vector of BigInteger into a vector of ring elements with ring dimension n
......@@ -197,6 +198,7 @@ namespace lbcrypto {
}
SPLIT32ALT_FOR_TYPE(Poly)
SPLIT32ALT_FOR_TYPE(NativePoly)
SPLIT32ALT_FOR_TYPE(DCRTPoly)
template<>
......@@ -208,6 +210,15 @@ namespace lbcrypto {
}
}
template<>
void Matrix<NativePoly>::SetFormat(Format format) {
for (size_t row = 0; row < rows; ++row) {
for (size_t col = 0; col < cols; ++col) {
data[row][col]->SetFormat(format);
}
}
}
Matrix<BigInteger> Rotate(Matrix<Poly> const& inMat) {
Matrix<Poly> mat(inMat);
mat.SetFormat(COEFFICIENT);
......
......@@ -44,7 +44,7 @@ void MultiThreadedRun(int index);
int main() {
for (usint i = 1; i < 2; i++) {
for (usint i = 1; i < 3; i++) {
MultiThreadedRun(i);
}
......
/*
* @file
* @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 "signature/lwesign.h"
#include "signature/lwesign.cpp"
#include "encoding/encodings.h"
#include <omp.h> //open MP header
//#define ONLINE_TIMING 1
//#define OFFLINE_TIMING 1
using namespace lbcrypto;
struct SecureParams {
usint m; ///< The ring parameter.
std::string modulus; ///< The modulus
std::string rootOfUnity; ///< The rootOfUnity
};
void MultiThreadedRun(int index);
int main() {
for (usint i = 1; i < 2; i++) {
MultiThreadedRun(i);
}
DiscreteFourierTransform::Reset();
return 0;
}
void MultiThreadedRun(int index) {
int nthreads, tid;
// Fork a team of threads giving them their own copies of variables
//so we can see how many threads we have to work with
#pragma omp parallel private(nthreads, tid)
{
/* Obtain thread number */
tid = omp_get_thread_num();
/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
std::cout << "Number of threads = " << nthreads << std::endl;
}
}
SecureParams const SECURE_PARAMS[] = {
{ 1024, "8399873", "824894"},
{ 2048, "67127297", "19715182"},
{ 4096, "18014398509506561", "5194839201355896"},
{ 8192, "162259276829213363391578010402817", "66396805305014513556659676765098"},
{ 16384, "13164036458569648337239753460458804039861886925068638906789969921", "146488057101847996735943188821846167958454591207690706445995891"}
};
size_t counter = 20;
double start, finish;
DiscreteGaussianGeneratorImpl<NativeInteger,NativeVector> dgg(SIGMA);
usint sm = SECURE_PARAMS[index].m;
NativeInteger smodulus(SECURE_PARAMS[index].modulus);
NativeInteger srootOfUnity(SECURE_PARAMS[index].rootOfUnity);
ILNative1Params ilParams(sm, smodulus, srootOfUnity);
shared_ptr<ILNative1Params> silParams = std::make_shared<ILNative1Params>(ilParams);
std::cout << "m: " << sm << " q: " << smodulus << " rootOfUnity: " << srootOfUnity << std::endl;
std::cout << "Signature precomputations" << std::endl;
start = currentDateTime();
ChineseRemainderTransformFTT<NativeInteger,NativeVector>::PreCompute(srootOfUnity, sm, smodulus);
DiscreteFourierTransform::PreComputeTable(sm);
finish = currentDateTime();
std::cout << "Precomputation time: " << finish - start << " ms" << std::endl;
silParams = std::make_shared<ILNative1Params>(ilParams);
LPSignatureParameters<NativePoly> signParams(silParams, dgg);
//signParams.SetElemParams(silParams);
std::cout << signParams.GetILParams()->GetCyclotomicOrder() << std::endl << std::endl;
//std::cout << "std = " << signParams.GetDiscreteGaussianGenerator().GetStd() << std::endl;
LPSignKeyGPVGM<NativePoly> s_k_gm(signParams);
LPVerificationKeyGPVGM<NativePoly> v_k_gm(signParams);
LPSignatureSchemeGPVGM<NativePoly> scheme_gm;
vector<Signature<Matrix<NativePoly>>> signature(counter);
scheme_gm.KeyGen(&s_k_gm, &v_k_gm);
start = currentDateTime();
for (usint i = 0; i < 10; i++) {
scheme_gm.KeyGen(&s_k_gm, &v_k_gm);
}
finish = currentDateTime();
std::cout << "Key generation - New : " << "\t" << (finish - start)/10 << " ms" << std::endl;
double signTime = 0;
double verifyTime = 0;
size_t verifyCounter = 0;
bool verifyBool = false;
std::vector<string> text{
"1 Let's spice things up",
"2 Let's spice things up",
"3 Let's spice things up",
"4 Let's spice things up",
"5 Let's spice things up",
"6 Let's spice things up",
"7 Let's spice things up",
"8 Let's spice things up",
"9 Let's spice things up",
"10 Let's spice things up",
};
Signature<Matrix<NativePoly>> precompSignature;
scheme_gm.Sign(s_k_gm, text[5], &precompSignature);
start = currentDateTime();
for (usint i = 0; i < counter; i++) {
scheme_gm.Sign(s_k_gm, text[i % 10], &(signature[i]));
}
finish = currentDateTime();
signTime = finish - start;
std::cout << "Signing - New : " << "\t" << signTime / counter << " ms" << std::endl;
start = currentDateTime();
for (usint i = 0; i < counter; i++) {
verifyBool = scheme_gm.Verify(v_k_gm, signature[i], text[i % 10]);
if (verifyBool)
verifyCounter++;
}
finish = currentDateTime();
verifyTime = finish - start;
std::cout << "Verifying - New : " << "\t" << verifyTime / counter << " ms" << std::endl;
std::cout << "Verification counter : " << "\t" << verifyCounter << "\n" << std::endl;
std::cout << "Execution completed" << std::endl;
}
/*
* @file
* @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 "signature/lwesign.h"
#include "signature/lwesign.cpp"
#include "encoding/encodings.h"
#include <omp.h> //open MP header
//#define ONLINE_TIMING 1
//#define OFFLINE_TIMING 1
using namespace lbcrypto;
struct SecureParams {
usint m; ///< The ring parameter.
std::string modulus; ///< The modulus
std::string rootOfUnity; ///< The rootOfUnity
};
void MultiThreadedRun(int index, usint base);
int main() {
for (usint i = 0; i < 1; i++) {
for (usint j = 2; j < 1024; j = 2*j) {
MultiThreadedRun(i, j);
}
}
DiscreteFourierTransform::Reset();
return 0;
}
void MultiThreadedRun(int index, usint base) {
int nthreads, tid;
// Fork a team of threads giving them their own copies of variables
//so we can see how many threads we have to work with
#pragma omp parallel private(nthreads, tid)
{
/* Obtain thread number */
tid = omp_get_thread_num();
/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
std::cout << "Number of threads = " << nthreads << std::endl;
}
}
SecureParams const SECURE_PARAMS[] = {
{ 1024, "8399873", "824894"},
{ 2048, "67127297", "19715182"},
{ 4096, "18014398509506561", "5194839201355896"},
{ 8192, "162259276829213363391578010402817", "66396805305014513556659676765098"},
{ 16384, "13164036458569648337239753460458804039861886925068638906789969921", "146488057101847996735943188821846167958454591207690706445995891"}
};
size_t counter = 20;
double start, finish;
DiscreteGaussianGeneratorImpl<NativeInteger,NativeVector> dgg(SIGMA);
usint sm = SECURE_PARAMS[index].m;
NativeInteger smodulus(SECURE_PARAMS[index].modulus);
NativeInteger srootOfUnity(SECURE_PARAMS[index].rootOfUnity);
ILNativeParams ilParams(sm, smodulus, srootOfUnity);
shared_ptr<ILNativeParams> silParams = std::make_shared<ILNativeParams>(ilParams);
std::cout << "m: " << sm << " q: " << smodulus << " rootOfUnity: " << srootOfUnity << std::endl;
std::cout << "base: " << base << std::endl;
std::cout << "Signature precomputations" << std::endl;
start = currentDateTime();
ChineseRemainderTransformFTT<NativeInteger,NativeVector>::PreCompute(srootOfUnity, sm, smodulus);
DiscreteFourierTransform::PreComputeTable(sm);
finish = currentDateTime();
std::cout << "Precomputation time: " << finish - start << " ms" << std::endl;
silParams = std::make_shared<ILNativeParams>(ilParams);
LPSignatureParameters<NativePoly> signParams(silParams, dgg, base);
//signParams.SetElemParams(silParams);
std::cout << signParams.GetILParams()->GetCyclotomicOrder() << std::endl << std::endl;
//std::cout << "std = " << signParams.GetDiscreteGaussianGenerator().GetStd() << std::endl;
LPSignKeyGPVGM<NativePoly> s_k_gm(signParams);
LPVerificationKeyGPVGM<NativePoly> v_k_gm(signParams);
LPSignatureSchemeGPVGM<NativePoly> scheme_gm;
vector<Signature<Matrix<NativePoly>>> signature(counter);
scheme_gm.KeyGen(&s_k_gm, &v_k_gm);
start = currentDateTime();
for (usint i = 0; i < 10; i++) {
scheme_gm.KeyGen(&s_k_gm, &v_k_gm);
}
finish = currentDateTime();
std::cout << "Key generation - New : " << "\t" << (finish - start)/10 << " ms" << std::endl;
double signTime = 0;
double verifyTime = 0;
size_t verifyCounter = 0;
bool verifyBool = false;
std::vector<string> text{
"1 Let's spice things up",
"2 Let's spice things up",
"3 Let's spice things up",
"4 Let's spice things up",
"5 Let's spice things up",
"6 Let's spice things up",
"7 Let's spice things up",
"8 Let's spice things up",
"9 Let's spice things up",
"10 Let's spice things up",
};
Signature<Matrix<NativePoly>> precompSignature;
scheme_gm.Sign(s_k_gm, text[5], &precompSignature);
//offline perturbation sampling
std::vector<shared_ptr<Matrix<NativePoly>>> perturbationVectors;
start = currentDateTime();
for (usint i = 0; i < counter; i++) {
perturbationVectors.push_back(scheme_gm.SampleOffline(s_k_gm));
}
finish = currentDateTime();
std::cout << "Offline Perturbation Sampling : " << "\t" << (finish - start) / counter << " ms" << std::endl;
//online signing
start = currentDateTime();
for (usint i = 0; i < counter; i++) {
scheme_gm.SignOnline(s_k_gm, perturbationVectors[i], text[i % 10], &(signature[i]));
}
finish = currentDateTime();
signTime = finish - start;
std::cout << "Online Signing : " << "\t" << signTime / counter << " ms" << std::endl;
start = currentDateTime();
for (usint i = 0; i < counter; i++) {
verifyBool = scheme_gm.Verify(v_k_gm, signature[i], text[i % 10]);
if (verifyBool)
verifyCounter++;
}
finish = currentDateTime();
verifyTime = finish - start;
std::cout << "Verification time : " << "\t" << verifyTime / counter << " ms" << std::endl;
std::cout << "Verification counter : " << "\t" << verifyCounter << "\n" << std::endl;
std::cout << "Execution completed" << std::endl;
}
......@@ -42,7 +42,7 @@ namespace lbcrypto {
{
// If DCRT is used, the polynomial is first converted from DCRT to large polynomial (in COEFFICIENT representation)
Poly u = syndrome.CRTInterpolate();
typename Element::PolyLargeType u = syndrome.CRTInterpolate();
const typename Poly::Integer& modulus = u.GetParams()->GetModulus();
// std::cout << "modulus = " << modulus << std::endl;
......@@ -118,7 +118,7 @@ namespace lbcrypto {
{
// If DCRT is used, the polynomial is first converted from DCRT to large polynomial (in COEFFICIENT representation)
Poly u = syndrome.CRTInterpolate();
typename Element::PolyLargeType u = syndrome.CRTInterpolate();
const typename Poly::Integer& modulus = u.GetParams()->GetModulus();
// std::cout << "modulus = " << modulus << std::endl;
......
......@@ -37,9 +37,9 @@ namespace lbcrypto {
template class RLWETrapdoorUtility<Poly>;
template class Matrix<Poly>;
// template class LatticeGaussSampUtility<NativePoly>;
// template class RLWETrapdoorPair<NativePoly>;
// template class RLWETrapdoorUtility<NativePoly>;
// template class Matrix<NativePoly>;
template class LatticeGaussSampUtility<NativePoly>;
template class RLWETrapdoorPair<NativePoly>;
template class RLWETrapdoorUtility<NativePoly>;
template class Matrix<NativePoly>;
}
......@@ -44,7 +44,7 @@ namespace lbcrypto {
void LPSignatureSchemeGPVGM<Element>::KeyGen(LPSignKeyGPVGM<Element>* signKey,
LPVerificationKeyGPVGM<Element>* verificationKey) {
//Get parameters from keys
shared_ptr<ILParams> params = signKey->GetSignatureParameters().GetILParams();
shared_ptr<typename Element::Params> params = signKey->GetSignatureParameters().GetILParams();
auto stddev = signKey->GetSignatureParameters().GetDiscreteGaussianGenerator().GetStd();
usint base = signKey->GetSignatureParameters().GetBase();
//Generate trapdoor based using parameters and
......@@ -162,7 +162,7 @@ namespace lbcrypto {
//double stddev = signKey.GetSignatureParameters().GetDiscreteGaussianGenerator().GetStd();
typename Element::DggType & dgg = signKey.GetSignatureParameters().GetDiscreteGaussianGenerator();
Matrix<Element> zHat = RLWETrapdoorUtility<Poly>::GaussSampOnline(n, k, A, T, u, dgg, perturbationVector, base);
Matrix<Element> zHat = RLWETrapdoorUtility<Element>::GaussSampOnline(n, k, A, T, u, dgg, perturbationVector, base);
signatureText->SetElement(zHat);
}
......
......@@ -80,6 +80,45 @@ TEST(UTSignatureGPV,simple_sign_verify) {
DEBUG("Step 12");
}
//TEST FOR BASIC SIGNING & VERIFICATION PROCESS
TEST(UTSignatureGPV,simple_sign_verify_native) {
bool dbg_flag = false;
DEBUG("Step 1");
NativePoly::DggType dgg(4);
usint sm = 16;
NativeInteger smodulus("1152921504606847009");
NativeInteger srootOfUnity("405107564542978792");
shared_ptr<ILNativeParams> silParams( new ILNativeParams(sm, smodulus, srootOfUnity) );
DEBUG("Step 2");
ChineseRemainderTransformFTT<NativeInteger,NativeVector>::PreCompute(srootOfUnity, sm, smodulus);
DEBUG("Step 4");
LPSignatureParameters<NativePoly> signParams(silParams, dgg);
DEBUG("Step 5");
LPSignKeyGPVGM<NativePoly> s_k(signParams);
DEBUG("Step 6");
LPVerificationKeyGPVGM<NativePoly> v_k(signParams);
DEBUG("Step 7");
LPSignatureSchemeGPVGM<NativePoly> scheme;
DEBUG("Step 8");
scheme.KeyGen(&s_k, &v_k);
DEBUG("Step 9");
Signature<Matrix<NativePoly>> signature;
DEBUG("Step 10");
string text("Since hashing is integrated now");
DEBUG("Step 11");
scheme.Sign(s_k, text, &signature);
EXPECT_EQ(true, scheme.Verify(v_k, signature, text))
<<"Failed verification";
DEBUG("Step 12");
}
//TEST FOR BASIC SIGNING & VERIFICATION PROCESS - TWO STEP PROCESS
TEST(UTSignatureGPV, simple_sign_verify_two_phase) {
bool dbg_flag = false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment