Commit e649dda7 authored by Jerry Ryan's avatar Jerry Ryan
Browse files

ildcrtparams for everyone

parent 93df7cda
......@@ -205,6 +205,11 @@ public:
GeneratePolys<BE2ILDCRTParams,BE2DCRTPoly>(BE2dcrtparms, BE2DCRTpolys);
GeneratePolys<BE4ILDCRTParams,BE4DCRTPoly>(BE4dcrtparms, BE4DCRTpolys);
GeneratePolys<BE6ILDCRTParams,BE6DCRTPoly>(BE6dcrtparms, BE6DCRTpolys);
cout << *BE2dcrtparms[16] << endl;
cout << *BE4dcrtparms[16] << endl;
cout << *BE6dcrtparms[16] << endl;
cout << BE6DCRTpolys[16][0] << endl;
}
template<typename P>
......
......@@ -79,7 +79,7 @@ public:
* @param m - order
* @return new params
*/
template<typename P, typename I>
template<typename P>
static shared_ptr<P> GenElemParams(usint m) {
size_t sIdx = 0;
if( DefaultSet[0].m < m ) {
......@@ -91,7 +91,7 @@ public:
if( DefaultSet[sIdx].m == 0 )
sIdx--;
return shared_ptr<P>( new P(DefaultSet[sIdx].m, I(DefaultSet[sIdx].q), I(DefaultSet[sIdx].ru)) );
return shared_ptr<P>( new P(DefaultSet[sIdx].m, typename P::Integer(DefaultSet[sIdx].q), typename P::Integer(DefaultSet[sIdx].ru)) );
}
/**
......@@ -102,10 +102,10 @@ public:
* @param bits # of bits in q
* @return new params
*/
template<typename P, typename I>
template<typename P>
static shared_ptr<P> GenElemParams(usint m, usint bits, usint towersize = 0) {
I q = FirstPrime<I>(bits,m);
I ru = RootOfUnity<I>(m, q);
typename P::Integer q = FirstPrime<typename P::Integer>(bits,m);
typename P::Integer ru = RootOfUnity<typename P::Integer>(m, q);
return shared_ptr<P>( new P(m, q, ru) );
}
......@@ -117,16 +117,16 @@ public:
* @param rootUnity - root of unity
* @return
*/
template<typename P, typename I>
static shared_ptr<P> GenElemParams(usint m, const I& ctModulus, const I& rootUnity) {
template<typename P>
static shared_ptr<P> GenElemParams(usint m, const typename P::Integer& ctModulus, const typename P::Integer& rootUnity) {
return shared_ptr<P>( new P(m, ctModulus, rootUnity) );
}
};
template<>
inline shared_ptr<ILDCRTParams<BigInteger>>
ElemParamFactory::GenElemParams<ILDCRTParams<BigInteger>,BigInteger>(usint m, usint bits, usint towersize) {
return GenerateDCRTParams(m, towersize, bits);
ElemParamFactory::GenElemParams<ILDCRTParams<BigInteger>>(usint m, usint bits, usint towersize) {
return GenerateDCRTParams<BigInteger>(m, towersize, bits);
}
} /* namespace lbcrypto */
......
......@@ -53,6 +53,7 @@ template<typename IntType>
class ILDCRTParams : public ElemParams<IntType>
{
public:
typedef IntType Integer;
/**
* @brief Constructor with basic parameter set.
......
......@@ -51,6 +51,7 @@ template<typename IntType>
class ILParamsImpl : public ElemParams<IntType>
{
public:
typedef IntType Integer;
/**
* Constructor that initializes nothing.
......
......@@ -50,7 +50,8 @@ using namespace lbcrypto;
* @param pbits - number of bits in the prime, to start with
* @return
*/
inline shared_ptr<ILDCRTParams<BigInteger>> GenerateDCRTParams(usint m, usint numOfTower, usint pbits) {
template<typename I>
inline shared_ptr<ILDCRTParams<I>> GenerateDCRTParams(usint m, usint numOfTower, usint pbits) {
if( numOfTower == 0 )
throw std::logic_error("Can't make parms with numOfTower == 0 ");
......@@ -59,7 +60,7 @@ inline shared_ptr<ILDCRTParams<BigInteger>> GenerateDCRTParams(usint m, usint nu
std::vector<NativeInteger> rootsOfUnity(numOfTower);
NativeInteger q = FirstPrime<NativeInteger>(pbits, m);
BigInteger modulus(1);
I modulus(1);
usint j = 0;
for(;;) {
......@@ -72,7 +73,7 @@ inline shared_ptr<ILDCRTParams<BigInteger>> GenerateDCRTParams(usint m, usint nu
q = NextPrime(q, m);
}
shared_ptr<ILDCRTParams<BigInteger>> params(new ILDCRTParams<BigInteger>(m, moduli, rootsOfUnity));
shared_ptr<ILDCRTParams<I>> params(new ILDCRTParams<I>(m, moduli, rootsOfUnity));
return params;
}
......
......@@ -59,7 +59,7 @@ TEST_F(UTEncoding,scalar_encoding) {
usint m = 8;
PlaintextModulus ptm = 128;
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams,BigInteger>(m);
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParamsImpl<BigInteger>>(m);
EncodingParams ep( new EncodingParamsImpl( ptm ) );
ScalarEncoding se(lp, ep, value);
......@@ -96,7 +96,7 @@ TEST_F(UTEncoding,coef_packed_encoding) {
vector<int64_t> value = {32, 17, 8, -12, -32, 22, -101, 6 };
usint m = 16;
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams,BigInteger>(m);
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParamsImpl<BigInteger>>(m);
EncodingParams ep( new EncodingParamsImpl(256) );
CoefPackedEncoding se(lp, ep, value);
......@@ -134,7 +134,7 @@ TEST_F(UTEncoding,string_encoding) {
usint m = 64;
shared_ptr<ILParams> lp =
ElemParamFactory::GenElemParams<ILParams,BigInteger>(m);
ElemParamFactory::GenElemParams<ILParamsImpl<BigInteger>>(m);
EncodingParams ep( new EncodingParamsImpl(256) );
StringEncoding se(lp, ep, value);
se.Encode();
......@@ -143,7 +143,7 @@ TEST_F(UTEncoding,string_encoding) {
// truncate!
shared_ptr<ILParams> lp2 =
ElemParamFactory::GenElemParams<ILParams,BigInteger>(4);
ElemParamFactory::GenElemParams<ILParamsImpl<BigInteger>>(4);
StringEncoding se2(lp2, ep, value);
se2.Encode();
se2.Decode();
......@@ -153,7 +153,7 @@ TEST_F(UTEncoding,string_encoding) {
TEST_F(UTEncoding,integer_encoding){
int m = 64;
PlaintextModulus ptm = ((uint64_t)1<<30);
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParams,BigInteger>(m);
shared_ptr<ILParams> lp = ElemParamFactory::GenElemParams<ILParamsImpl<BigInteger>>(m);
EncodingParams ep( new EncodingParamsImpl(ptm) );
int64_t mv = ((uint64_t)1<<20) + (uint64_t)1;
......
......@@ -160,7 +160,7 @@ TEST(UTPoly, ops_tests) {
Poly::Integer primitiveRootOfUnity("22");
operators_tests<BigInteger, BigVector, ILParams, Poly>(
ElemParamFactory::GenElemParams<ILParams,BigInteger>(m) );
ElemParamFactory::GenElemParams<ILParamsImpl<BigInteger>>(m) );
}
TEST(UTNativePoly, ops_tests) {
......@@ -169,12 +169,12 @@ TEST(UTNativePoly, ops_tests) {
NativeInteger primitiveRootOfUnity("22");
operators_tests<NativeInteger, NativeVector, ILNativeParams, NativePoly>(
ElemParamFactory::GenElemParams<ILNativeParams,NativeInteger>(m) );
ElemParamFactory::GenElemParams<ILParamsImpl<NativeInteger>>(m) );
}
TEST(UTDCRTPoly, ops_tests) {
operators_tests<BigInteger, BigVector, ILDCRTParams<BigInteger>, DCRTPoly>(
GenerateDCRTParams(8, 3, 20) );
GenerateDCRTParams<BigInteger>(8, 3, 20) );
}
// template for rounding_operations tests
......@@ -1479,7 +1479,7 @@ TEST(UTDCRTPoly, decompose_test) {
float stdDev = 4;
DCRTPoly::DggType dgg(stdDev);
shared_ptr<ILDCRTParams<BigInteger>> params = GenerateDCRTParams(order, towersize, nBits);
shared_ptr<ILDCRTParams<BigInteger>> params = GenerateDCRTParams<BigInteger>(order, towersize, nBits);
DCRTPoly DCRTPolyFirst(dgg, params, Format::COEFFICIENT);
DCRTPoly DCRTPolyOriginal(DCRTPolyFirst);
......@@ -1554,7 +1554,7 @@ TEST(UTDCRTPoly, ensures_mod_operation_during_ops_on_two_DCRTPolys){
usint nBits = 24;
usint towersize = 3;
shared_ptr<ILDCRTParams<BigInteger>> ildcrtparams = GenerateDCRTParams(order, towersize, nBits);
shared_ptr<ILDCRTParams<BigInteger>> ildcrtparams = GenerateDCRTParams<BigInteger>(order, towersize, nBits);
DCRTPoly::DugType dug;
......
......@@ -201,7 +201,7 @@ TEST(UTSer,ilparams_test) {
TEST(UTSer,ildcrtparams_test) {
shared_ptr<ILDCRTParams<BigInteger>> p = GenerateDCRTParams(1024, 5, 30);
shared_ptr<ILDCRTParams<BigInteger>> p = GenerateDCRTParams<BigInteger>(1024, 5, 30);
Serialized ser;
ser.SetObject();
ASSERT_TRUE( p->Serialize(&ser) ) << "Serialization failed";
......@@ -229,7 +229,7 @@ TEST(UTSer,ilvector_test) {
}
TEST(UTSer,ildcrtpoly_test) {
shared_ptr<ILDCRTParams<BigInteger>> p = GenerateDCRTParams(1024, 5, 30);
shared_ptr<ILDCRTParams<BigInteger>> p = GenerateDCRTParams<BigInteger>(1024, 5, 30);
DCRTPoly::DugType dug;
DCRTPoly vec(dug, p);
......
......@@ -41,7 +41,7 @@ static const usint DefaultT = 3;
template<typename Element>
inline CryptoContext<Element>
GenCryptoContextNull(usint ORDER, PlaintextModulus ptm, usint bits=DefaultQbits, usint towers=DefaultT) {
shared_ptr<typename Element::Params> p = ElemParamFactory::GenElemParams<typename Element::Params,typename Element::Integer>(ORDER, bits, towers);
shared_ptr<typename Element::Params> p = ElemParamFactory::GenElemParams<typename Element::Params>(ORDER, bits, towers);
CryptoContext<Element> cc = CryptoContextFactory<Element>::genCryptoContextNull(ORDER, ptm);
cc->Enable(ENCRYPTION);
......@@ -54,7 +54,7 @@ GenCryptoContextNull(usint ORDER, PlaintextModulus ptm, usint bits=DefaultQbits,
template<typename Element>
inline CryptoContext<Element>
GenCryptoContextLTV(usint ORDER, PlaintextModulus ptm, usint bits=DefaultQbits, usint towers=DefaultT) {
shared_ptr<typename Element::Params> p = ElemParamFactory::GenElemParams<typename Element::Params,typename Element::Integer>(ORDER, bits, towers);
shared_ptr<typename Element::Params> p = ElemParamFactory::GenElemParams<typename Element::Params>(ORDER, bits, towers);
CryptoContext<Element> cc = CryptoContextFactory<Element>::genCryptoContextLTV(p, ptm, 1, 4);
cc->Enable(ENCRYPTION);
......@@ -100,7 +100,7 @@ template<>
inline CryptoContext<Poly>
GenCryptoContextBFV(usint ORDER, PlaintextModulus ptm, usint bits, usint towers, MODE mode) {
shared_ptr<typename Poly::Params> p = ElemParamFactory::GenElemParams<typename Poly::Params,typename Poly::Integer>(ORDER, bits, towers);
shared_ptr<typename Poly::Params> p = ElemParamFactory::GenElemParams<typename Poly::Params>(ORDER, bits, towers);
CryptoContext<Poly> cc = CryptoContextFactory<Poly>::genCryptoContextBFV(ptm, 1.006, 1, 4, 0, 2, 0, mode);
cc->Enable(ENCRYPTION);
......@@ -159,7 +159,7 @@ GenCryptoContextBFVrns(PlaintextModulus ptm, MODE mode) {
template<typename Element>
inline CryptoContext<Element>
GenTestCryptoContext(const string& name, usint ORDER, PlaintextModulus ptm, usint bits=DefaultQbits, usint towers=DefaultT) {
shared_ptr<typename Element::Params> p = ElemParamFactory::GenElemParams<typename Element::Params,typename Element::Integer>(ORDER, bits, towers);
shared_ptr<typename Element::Params> p = ElemParamFactory::GenElemParams<typename Element::Params>(ORDER, bits, towers);
CryptoContext<Element> cc;
if( name == "Null" ) {
......
......@@ -282,7 +282,7 @@ CryptoContextHelper::getNewDCRTContext(const string& parmset, usint numTowers, u
return 0;
}
parms = GenerateDCRTParams(stoul(ring), numTowers, primeBits);
parms = GenerateDCRTParams<DCRTPoly::Integer>(stoul(ring), numTowers, primeBits);
}
return buildContextFromSerialized<DCRTPoly>(it->second, parms);
......
......@@ -63,7 +63,7 @@ TEST_F(UTBGVDCRT, Poly_bgv_DCRT_MODREDUCE) {
float stdDev = 4;
shared_ptr<ILDCRTParams<BigInteger>> params = GenerateDCRTParams(m, numOfTower, 48);
shared_ptr<ILDCRTParams<BigInteger>> params = GenerateDCRTParams<BigInteger>(m, numOfTower, 48);
CryptoContext<DCRTPoly> cc = CryptoContextFactory<DCRTPoly>::genCryptoContextBGV(params, plaintextModulus, m, stdDev);
cc->Enable(ENCRYPTION);
......
......@@ -262,7 +262,7 @@ TEST_F(UTSHE, keyswitch_SingleCRT) {
float stdDev = 4;
shared_ptr<Poly::Params> params = ElemParamFactory::GenElemParams<Poly::Params,Poly::Integer>(m, 50);
shared_ptr<Poly::Params> params = ElemParamFactory::GenElemParams<Poly::Params>(m, 50);
CryptoContext<Poly> cc = CryptoContextFactory<Poly>::genCryptoContextLTV(params, 256, 1, stdDev);
cc->Enable(ENCRYPTION);
......@@ -295,7 +295,7 @@ TEST_F(UTSHE, sparsekeygen_single_crt_encrypt_decrypt) {
float stdDev = 4;
shared_ptr<Poly::Params> params = ElemParamFactory::GenElemParams<Poly::Params,Poly::Integer>(m);
shared_ptr<Poly::Params> params = ElemParamFactory::GenElemParams<Poly::Params>(m);
CryptoContext<Poly> cc = CryptoContextFactory<Poly>::genCryptoContextLTV(params, 256, 1, stdDev);
cc->Enable(ENCRYPTION);
......@@ -332,7 +332,7 @@ TEST_F(UTSHE, keyswitch_ModReduce_DCRT) {
usint plaintextmodulus = 256;
usint relinWindow = 1;
shared_ptr<ILDCRTParams<BigInteger>> params = GenerateDCRTParams( m, size, 30 );
shared_ptr<ILDCRTParams<BigInteger>> params = GenerateDCRTParams<BigInteger>( m, size, 30 );
CryptoContext<DCRTPoly> cc = CryptoContextFactory<DCRTPoly>::genCryptoContextLTV(params, plaintextmodulus, relinWindow, stdDev);
......@@ -380,7 +380,7 @@ TEST_F(UTSHE, ringreduce_single_crt) {
float stdDev = 4;
shared_ptr<Poly::Params> params = ElemParamFactory::GenElemParams<Poly::Params,Poly::Integer>(m);
shared_ptr<Poly::Params> params = ElemParamFactory::GenElemParams<Poly::Params>(m);
CryptoContext<Poly> cc = CryptoContextFactory<Poly>::genCryptoContextLTV(params, 2, 1, stdDev);
cc->Enable(ENCRYPTION);
......@@ -431,7 +431,7 @@ TEST_F(UTSHE, ringreduce_double_crt) {
usint relinWindow = 1;
usint size = 3;
shared_ptr<ILDCRTParams<BigInteger>> params = GenerateDCRTParams( m, size, 30 );
shared_ptr<ILDCRTParams<BigInteger>> params = GenerateDCRTParams<BigInteger>( m, size, 30 );
CryptoContext<DCRTPoly> cc = CryptoContextFactory<DCRTPoly>::genCryptoContextLTV(params, plaintextmodulus, relinWindow, stdDev);
cc->Enable(ENCRYPTION);
......
......@@ -69,7 +69,7 @@ TEST_F(UTSHEAdvanced, test_eval_mult_single_crt) {
float stdDev = 4;
PlaintextModulus ptm = 20;
shared_ptr<Poly::Params> parms = ElemParamFactory::GenElemParams<Poly::Params,Poly::Integer>(m, 50);
shared_ptr<Poly::Params> parms = ElemParamFactory::GenElemParams<Poly::Params>(m, 50);
CryptoContext<Poly> cc = CryptoContextFactory<Poly>::genCryptoContextLTV(parms, ptm, relin, stdDev);
cc->Enable(ENCRYPTION);
......@@ -190,7 +190,7 @@ TEST_F(UTSHEAdvanced, test_eval_add_single_crt) {
float stdDev = 4;
shared_ptr<Poly::Params> parms = ElemParamFactory::GenElemParams<Poly::Params,Poly::Integer>(m);
shared_ptr<Poly::Params> parms = ElemParamFactory::GenElemParams<Poly::Params>(m);
CryptoContext<Poly> cc = CryptoContextFactory<Poly>::genCryptoContextLTV(parms, ptm, 1, stdDev);
......@@ -317,7 +317,7 @@ TEST_F(UTSHEAdvanced, test_composed_eval_mult_two_towers) {
PlaintextModulus ptm = 16;
shared_ptr<ILDCRTParams<BigInteger>> params = GenerateDCRTParams( init_m, init_size, dcrtBits );
shared_ptr<ILDCRTParams<BigInteger>> params = GenerateDCRTParams<BigInteger>( init_m, init_size, dcrtBits );
shared_ptr<ILDCRTParams<BigInteger>> paramsSmall( new ILDCRTParams<BigInteger>( *params ) );
paramsSmall->PopLastParam();
......
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