Commit fe46ed85 authored by Gerard Ryan's avatar Gerard Ryan

version 1.5.0

parent bc702883
......@@ -50,3 +50,10 @@ src/circuit/lib/scan.cpp
src/circuit/lib/parse.cpp
src/circuit/lib/parse.hpp
src/circuit/lib/*.hh
# vagrant output
.vagrant/
*.log
# gtest output files
test_detail.xml
......@@ -75,7 +75,7 @@ endif
ROOTDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PACKAGE := palisade
VERSION := 1.4.1
VERSION := 1.5.0
#build directory
BUILDDIR := build
......@@ -184,7 +184,7 @@ uninstall: uninstallcore uninstallpke uninstallabe uninstallsignature
UNITTESTMAINOBJ := $(BINDIR)/unittest/Main_TestAll.o
$(UNITTESTMAINOBJ): test/include/gtest/Main_TestAll.cpp src/core/lib/math/backend.h
$(UNITTESTMAINOBJ): test/include/gtest/Main_TestAll.cpp src/core/lib/math/backend.h src/version.h
@mkdir -p $(BINDIR)/unittest
$(CC) -c $(CPPFLAGS) $(INC) -o $@ $<
......
3/20/2019: PALISADE v1.5.0 is released
Fixes the vulnerability found in https://eprint.iacr.org/2017/785 (PKC'19) for the PRE schemes based on BGV/BFV
Adds PRE modes for BGV/BFV that are secure under honest re-reencryption attacks (recommended security for practical use)
Adds support for splitting lattice trapdoor sampling into offline and online phases (used by digital signatures, IBE, and ABE constructions)
Fixes bugs related to the multi-threaded mode of operation
02/11/2018: PALISADE v1.4.1 is released
Fixes a bug affecting the IBE and CP-ABE implementations (some unit tests for IBE/CP-ABE were entering in an infinite loop in about 10% of the runs).
......
......@@ -111,34 +111,6 @@ static void GeneratePolys(map<usint,shared_ptr<P>>& parmArray, map<usint,vector<
}
}
// the ifdefs below are a hack to make sure this compiles in all backends
// when backend is == 2, BigInteger is the same as M2Integer... and so these methods
// will have duplicate instantiations... which is bad
// FIXME later
#if MATHBACKEND != 2
template<>
inline shared_ptr<ILDCRTParams<M2Integer>>
ElemParamFactory::GenElemParams<ILDCRTParams<M2Integer>>(usint m, usint bits, usint towersize) {
return GenerateDCRTParams<M2Integer>(m, towersize, bits);
}
#endif
#if MATHBACKEND != 4
template<>
inline shared_ptr<ILDCRTParams<M4Integer>>
ElemParamFactory::GenElemParams<ILDCRTParams<M4Integer>>(usint m, usint bits, usint towersize) {
return GenerateDCRTParams<M4Integer>(m, towersize, bits);
}
#endif
#if MATHBACKEND != 6
template<>
inline shared_ptr<ILDCRTParams<M6Integer>>
ElemParamFactory::GenElemParams<ILDCRTParams<M6Integer>>(usint m, usint bits, usint towersize) {
return GenerateDCRTParams<M6Integer>(m, towersize, bits);
}
#endif
}
map<usint,shared_ptr<ILNativeParams>> Nativeparms;
......
......@@ -86,3 +86,9 @@ echo OpenMP OK
MINGWREGEX="-Lc:/Mingw64/mingw64/opt/lib -lregex -lshlwapi"
OMPINCLUDE="-I /opt/local/include/libomp -fopenmp"
lzip -V >/dev/null 2>&1
[ $? -ne 0 ] && echo lzip is not available installed -- needed for gmp install && exit 1
echo lzip OK -- needed for gmp install
......@@ -38,7 +38,7 @@ PROJECT_NAME = "PALISADE Lattice Crypto Library"
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = "v1.4.1"
PROJECT_NUMBER = "v1.5.0"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
......
/**
* @file CPABETwoPhaseDemo.cpp - Demo file for ciphertext-policy attribute based encryption utilizing two-phase approach in key generation
* @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 "palisade.h"
#include "../lib/abecontext.h"
using namespace lbcrypto;
int main(){
//Create context under security level and number of attributes
std::cout<<"This is a demo file of the CPABE scheme with two-phase key generation"<<std::endl<<std::endl;
usint ringsize = 1024;
usint numAttributes = 6;
usint base = 64;
TimeVar t1;
std::cout<<"Used parameters:"<<std::endl;
std::cout<<"Ring size: "<<ringsize<<std::endl;
std::cout<<"Number of attributes: "<<numAttributes<<std::endl;
std::cout<<"Base: "<<base<<std::endl<<std::endl;
ABEContext<NativePoly> context;
std::cout<<"Generating a context under these parameters"<<std::endl<<std::endl;
context.GenerateCPABEContext(numAttributes,ringsize,base);
std::cout<<"Generating master secret key and master public key"<<std::endl;
//Generate master keys
TIC(t1);
CPABEMasterPublicKey<NativePoly> mpk;
CPABEMasterSecretKey<NativePoly> msk;
context.Setup(&mpk,&msk);
double duration = TOC(t1);
std::cout<<"Setup: "<<duration<<" ms"<<std::endl<<std::endl;
//Create a random access policy and user attribute set
std::cout<<" Creating access policy and user attribute sets"<<std::endl;
std::vector<usint> s(6);
std::vector<int> w(6);
for(usint j=0; j<6; j++)
s[j] = rand()%2;
for(usint j=0; j<6; j++)
w[j] = s[j];
for(usint j=0; j<6; j++)
if(w[j]==1) {
w[j] = 0;
break;
}
for(usint j=0; j<6; j++)
if(s[j]==0) {
w[j] = -1;
break;
}
std::cout<<"User attribute set: "<<s<<std::endl;
std::cout<<"Access policy defined:"<<w<<std::endl<<std::endl;
CPABEUserAccess<NativePoly> ua(s);
CPABEAccessPolicy<NativePoly> ap(w);
//Create the key corresponding to the access policy
CPABESecretKey<NativePoly> sk;
std::cout<<"Creating secret key for the attribute set"<<std::endl;
PerturbationVector<NativePoly> pv;
TIC(t1);
context.KeyGenOfflinePhase(msk,pv);
duration = TOC(t1);
std::cout<<"KeyGen (Offline): "<<duration<<" ms"<<std::endl;
TIC(t1);
context.KeyGenOnlinePhase(msk,mpk,ua,pv,&sk);
duration = TOC(t1);
std::cout<<"KeyGen (Online): "<<duration<<" ms"<<std::endl<<std::endl;
//Create a plaintext
std::vector<int64_t> vectorOfInts = { 1,0,0,1,1,0,1,0, 1, 0};
Plaintext pt = context.MakeCoefPackedPlaintext(vectorOfInts);
std::cout<<"Plaintext vector of bits: "<<vectorOfInts<<std::endl<<std::endl;
//Encrypt the plaintext
std::cout<<"Encrypting the plaintext under the access policy"<<std::endl;
TIC(t1);
CPABECiphertext<NativePoly> ct;
context.Encrypt(mpk,ap,pt,&ct);
duration = TOC(t1);
std::cout<<"Encryption: "<<duration<<" ms"<<std::endl<<std::endl;
//Decrypt the ciphertext
std::cout<<"Decrpyting the ciphertext"<<std::endl;
TIC(t1);
Plaintext dt = context.Decrypt(ap,ua,sk,ct);
duration = TOC(t1);
std::cout<<"Decryption: "<<duration<<" ms"<<std::endl<<std::endl;
std::cout<<"Checking if the plaintext & decrypted text match"<<std::endl;
//Check if original plaintext and decrypted plaintext match
if(pt->GetElement<NativePoly>() == dt->GetElement<NativePoly>()){
std::cout<<"Encryption & decryption successful"<<std::endl;
}else{
std::cout<<"Encryption & decryption failed"<<std::endl;
}
}
/**
* @file IBETwoPhaseDemo.cpp - Demo file for identity based encryption utilizing a two-phase approach for key generation
* @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 "../lib/abecontext.h"
#include "palisade.h"
using namespace lbcrypto;
int main(){
//Create context under given ringsize and base
//Create context under security level and number of attributes
std::cout<<"This is a demo file of the IBE scheme with two-phase key generation"<<std::endl<<std::endl;
usint ringsize = 1024;
usint base = 4;
TimeVar t1;
std::cout<<"Used parameters:"<<std::endl;
std::cout<<"Ring size: "<<ringsize<<std::endl;
std::cout<<"Base: "<<base<<std::endl<<std::endl;
ABEContext<NativePoly> context;
std::cout<<"Generating a context under these parameters"<<std::endl<<std::endl;
context.GenerateIBEContext(ringsize,base);
//Generate master keys
std::cout<<"Generating master secret and public keys"<<std::endl;
IBEMasterPublicKey<NativePoly> mpk;
IBEMasterSecretKey<NativePoly> msk;
TIC(t1);
context.Setup(&mpk,&msk);
double duration = TOC(t1);
std::cout<<"Setup: "<<duration<<" ms"<<std::endl<<std::endl;
std::cout<<"Creating a random identifier for the user"<<std::endl<<std::endl;
//Generate a random identifier for the user
IBEUserIdentifier<NativePoly> id(context.GenerateRandomElement());
std::cout<<"Generating the secret key for the user"<<std::endl;
//Generate the secret key for the user
IBESecretKey<NativePoly> sk;
PerturbationVector<NativePoly> pv;
TIC(t1);
context.KeyGenOfflinePhase(msk,pv);
duration = TOC(t1);
std::cout<<"KeyGen (Offline): "<<duration<<" ms"<<std::endl;
TIC(t1);
context.KeyGenOnlinePhase(msk,mpk,id,pv,&sk);
duration = TOC(t1);
std::cout<<"KeyGen (Online): "<<duration<<" ms"<<std::endl<<std::endl;
//Generate a plaintext
std::vector<int64_t> vectorOfInts = { 1,0,0,1,1,0,1,0, 1, 0};
Plaintext pt = context.MakeCoefPackedPlaintext(vectorOfInts);
std::cout<<"Plaintext vector of bits:"<<vectorOfInts<<std::endl<<std::endl;
//Encrypt the plaintext
std::cout<<"Encrypting the plaintext for the user with the id"<<std::endl;
IBECiphertext<NativePoly> ct;
TIC(t1);
context.Encrypt(mpk,id,pt,&ct);
duration = TOC(t1);
std::cout<<"Encryption: "<<duration<<" ms"<<std::endl<<std::endl;
//Decrypt the ciphertext
std::cout<<"Decrypting the ciphertext"<<std::endl;
TIC(t1);
Plaintext dt = context.Decrypt(id,id,sk,ct);
duration = TOC(t1);
std::cout<<"Decryption: "<<duration<<" ms"<<std::endl<<std::endl;
std::cout<<"Checking if plaintext & decrypted text match"<<std::endl;
//Check if original plaintext and decrypted plaintext match
if(pt->GetElement<NativePoly>() == dt->GetElement<NativePoly>()){
std::cout<<"Encryption & decryption successful"<<std::endl;
}else{
std::cout<<"Encryption & decryption failed"<<std::endl;
}
return 0;
}
......@@ -76,6 +76,16 @@ namespace lbcrypto{
void ABEContext<Element>::KeyGen(const ABECoreMasterSecretKey<Element> & msk,const ABECoreMasterPublicKey<Element>& mpk, const ABECoreAccessPolicy<Element> & ap,ABECoreSecretKey<Element>* sk){
m_scheme->KeyGen(m_params,msk,mpk,ap,sk);
}
//Method for offline phase of individual/policy specific key generation for decryption
template <class Element>
void ABEContext<Element>::KeyGenOfflinePhase(const ABECoreMasterSecretKey<Element> & msk,PerturbationVector<Element>& pv){
pv = m_scheme->KeyGenOffline(m_params,msk);
}
//Method for online phase individual/policy specific key generation for decryption
template <class Element>
void ABEContext<Element>::KeyGenOnlinePhase(const ABECoreMasterSecretKey<Element> & msk,const ABECoreMasterPublicKey<Element>& mpk, const ABECoreAccessPolicy<Element> & ap,const PerturbationVector<Element> & pv,ABECoreSecretKey<Element>* sk){
m_scheme->KeyGenOnline(m_params,msk,mpk,ap,pv,sk);
}
//Method for encryption
template <class Element>
void ABEContext<Element>::Encrypt(const ABECoreMasterPublicKey<Element> & mpk,const ABECoreAccessPolicy<Element> & ap,const Plaintext & ptext,ABECoreCiphertext<Element>* ct){
......
......@@ -86,6 +86,21 @@
*@param sk Secret key defined for the given policy/identifier - Output
*/
void KeyGen(const ABECoreMasterSecretKey<Element> & msk,const ABECoreMasterPublicKey<Element>& mpk, const ABECoreAccessPolicy<Element> & ap,ABECoreSecretKey<Element>* sk);
/**
*@brief Method for offline phase of individual/policy specific key generation for decryption
*@param msk Master secret key
*@param pv Perturbation vector sampled - Output
*/
void KeyGenOfflinePhase(const ABECoreMasterSecretKey<Element> & msk,PerturbationVector<Element>& pv);
/**
*@brief Method for online phase individual/policy specific key generation for decryption
*@param msk Master secret key
*@param mpk Master public key
*@param ap Access policy/user identifier
*@param pv Perturbation vector sampled in the offline phase of key generation
*@param sk Secret key defined for the given policy/identifier - Output
*/
void KeyGenOnlinePhase(const ABECoreMasterSecretKey<Element> & msk,const ABECoreMasterPublicKey<Element>& mpk, const ABECoreAccessPolicy<Element> & ap,const PerturbationVector<Element> & pv,ABECoreSecretKey<Element>* sk);
/**
*@brief Method for encryption
*@param mpk Master public key
......
......@@ -322,7 +322,34 @@ namespace lbcrypto{
const ABECoreMasterSecretKey<Element> & msk,
const ABECoreMasterPublicKey<Element> & mpk,
ABECoreSecretKey<Element>* sk){};
/*
/*
*@brief Method for offline sampling for key generation phase of an ABE cycle
*@param m_params Parameters used in operations
*@param msk Master secret key
*@return Perturbation vector sampled
*/
virtual PerturbationVector<Element> KeyGenOffline(
shared_ptr<ABECoreParams<Element>> m_params,
const ABECoreMasterSecretKey<Element> & msk){ return PerturbationVector<Element>();};
/*
*@brief Method for online phase for key generation phase of an IBE cycle without sampling
*@param m_params Parameters used in operations
*@param msk Master secret key
*@param mpk Master public key
*@param ap Access policy defining who will be able to decrypt
*@param pvector Perturbation vector sampled before hand
*@param sk Secret key for decryption - Output
*/
virtual void KeyGenOnline(
shared_ptr<ABECoreParams<Element>> m_params,
const ABECoreMasterSecretKey<Element> & msk,
const ABECoreMasterPublicKey<Element> & mpk,
const ABECoreAccessPolicy<Element> & ap,
const PerturbationVector<Element> & pvector,
ABECoreSecretKey<Element>* sk){};
/*
*@brief Method for encryption phase of an ABE cycle
*@param mpk Master public key
*@param ap Access policy defining who will be able to decrypt
......
......@@ -127,9 +127,7 @@ namespace lbcrypto{
y = pubElemD - y;
Matrix<Element> skA(Element::Allocator(m_params->GetTrapdoorParams()->GetElemParams(), EVALUATION), m_m, 1);
skA = RLWETrapdoorUtility<Element>::GaussSamp(m_N, m_k, mpk.GetA(), msk.GetTA(), y, m_params->GetTrapdoorParams()->GetDGG(), m_params->GetTrapdoorParams()->GetDGGLargeSigma(), m_base);
Matrix<Element> sk(Element::Allocator(ep, COEFFICIENT), m_m, m_ell+1);
for(usint i=0; i<m_m; i++)
(sk)(i, 0) = skA(i, 0);
......@@ -143,14 +141,23 @@ namespace lbcrypto{
}
//Method for offline sampling for key generation phase of an CPABE cycle
template <class Element>
PerturbationVector<Element> KeyGenOffline(shared_ptr<CPABEParams<Element>> m_params,const CPABEMasterSecretKey<Element> & msk){
shared_ptr<Matrix<Element>> pertubationVector = RLWETrapdoorUtility<Element>::GaussSampOffline(m_params->GetTrapdoorParams()->GetN(), m_params()->GetTrapdoorParams()->GetK(), msk.GetTA(), m_params->GetTrapdoorParams()->GetDGG(), m_params->GetTrapdoorParams()->GetDGGLargeSigma(), m_params->GetTrapdoorParams()->GetBase());
PerturbationVector<Element> CPABEScheme<Element>::KeyGenOffline(shared_ptr<ABECoreParams<Element>> cm_params,const ABECoreMasterSecretKey<Element> & cmsk){
shared_ptr<CPABEParams<Element>> m_params = dynamic_pointer_cast<CPABEParams<Element>>(cm_params);
const CPABEMasterSecretKey<Element> & msk = dynamic_cast<const CPABEMasterSecretKey<Element> &>(cmsk);
shared_ptr<Matrix<Element>> pertubationVector = RLWETrapdoorUtility<Element>::GaussSampOffline(m_params->GetTrapdoorParams()->GetN(), m_params->GetTrapdoorParams()->GetK(), msk.GetTA(), m_params->GetTrapdoorParams()->GetDGG(), m_params->GetTrapdoorParams()->GetDGGLargeSigma(), m_params->GetTrapdoorParams()->GetBase());
PerturbationVector<Element> pvector(pertubationVector);
return pvector;
}
//Method for online phase for key generation phase of an CPABE cycle without sampling
template <class Element>
void KeyGenOnline(shared_ptr<CPABEParams<Element>> m_params,const CPABEMasterSecretKey<Element> & msk,const CPABEMasterPublicKey<Element> & mpk, const CPABEUserAccess<Element> & id,const PerturbationVector<Element> & pvector,CPABESecretKey<Element>* usk){
void CPABEScheme<Element>::KeyGenOnline(shared_ptr<ABECoreParams<Element>> cm_params,const ABECoreMasterSecretKey<Element> & cmsk,const ABECoreMasterPublicKey<Element> & cmpk, const ABECoreAccessPolicy<Element> & cid,const PerturbationVector<Element> & pvector,ABECoreSecretKey<Element>* cusk){
shared_ptr<CPABEParams<Element>> m_params = dynamic_pointer_cast<CPABEParams<Element>>(cm_params);
const CPABEMasterSecretKey<Element> & msk = dynamic_cast<const CPABEMasterSecretKey<Element> &>(cmsk);
const CPABEMasterPublicKey<Element> & mpk = dynamic_cast<const CPABEMasterPublicKey<Element> &>(cmpk);
const CPABEUserAccess<Element> & id = dynamic_cast<const CPABEUserAccess<Element> &>(cid);
CPABESecretKey<Element>* usk = dynamic_cast<CPABESecretKey<Element>*>(cusk);
usint m_ell = m_params->GetEll();
usint m_k = m_params->GetTrapdoorParams()->GetK();
usint m_m = m_k+2;
......@@ -174,7 +181,7 @@ namespace lbcrypto{
const Matrix<Element> & pubElemBPos = mpk.GetBPos();
const Matrix<Element> & pubElemBNeg = mpk.GetBNeg();
usint *s = id.GetS();
const std::vector<usint> s = id.GetS();
const Element & pubElemD = mpk.GetPubElemD();
//#pragma omp parallel for firstprivate(z) num_threads(4)
for(usint i=0; i<m_ell; i++) {
......
......@@ -355,8 +355,8 @@ namespace lbcrypto{
*@param msk Master secret key
*@return Perturbation vector sampled
*/
PerturbationVector<Element> KeyGenOffline(shared_ptr<CPABEParams<Element>> m_params,
const CPABEMasterSecretKey<Element> & msk);
PerturbationVector<Element> KeyGenOffline(shared_ptr<ABECoreParams<Element>> m_params,
const ABECoreMasterSecretKey<Element> & msk);
/*
*@brief Method for online phase for key generation phase of an CPABE cycle without sampling
*@param m_params Parameters used in operations
......@@ -366,12 +366,12 @@ namespace lbcrypto{
*@param pvector Perturbation vector sampled before hand
*@param usk Secret key for decryption - Output
*/
void KeyGenOnline(shared_ptr<CPABEParams<Element>> m_params,
const CPABEMasterSecretKey<Element> & msk,
const CPABEMasterPublicKey<Element> & mpk,
const CPABEUserAccess<Element> & id,
void KeyGenOnline(shared_ptr<ABECoreParams<Element>> m_params,
const ABECoreMasterSecretKey<Element> & msk,
const ABECoreMasterPublicKey<Element> & mpk,
const ABECoreAccessPolicy<Element> & id,
const PerturbationVector<Element> & pvector,
CPABESecretKey<Element>* usk);
ABECoreSecretKey<Element>* usk);
/*
*@brief Method for encryption phase of a CPABE cycle
......
......@@ -50,22 +50,34 @@ namespace lbcrypto{
}
//Method for offline sampling for key generation phase of an IBE cycle
template<class Element>
PerturbationVector<Element> KeyGenOffline(shared_ptr<IBEParams<Element>> m_params,const IBEMasterSecretKey<Element> & msk){
shared_ptr<Matrix<Element>> pertubationVector = RLWETrapdoorUtility<Element>::GaussSampOffline(m_params->GetTrapdoorParams()->GetN(), m_params()->GetTrapdoorParams()->GetK(), msk.GetTA(), m_params->GetTrapdoorParams()->GetDGG(), m_params->GetTrapdoorParams()->GetDGGLargeSigma(), m_params->GetTrapdoorParams()->GetBase());
PerturbationVector<Element> IBEScheme<Element>::KeyGenOffline(
shared_ptr<ABECoreParams<Element>> cm_params,
const ABECoreMasterSecretKey<Element> & cmsk){
shared_ptr<IBEParams<Element>> m_params = dynamic_pointer_cast<IBEParams<Element>>(cm_params);
const IBEMasterSecretKey<Element>& msk = dynamic_cast<const IBEMasterSecretKey<Element>&>(cmsk);
shared_ptr<Matrix<Element>> pertubationVector = RLWETrapdoorUtility<Element>::GaussSampOffline(m_params->GetTrapdoorParams()->GetN(), m_params->GetTrapdoorParams()->GetK(), msk.GetTA(), m_params->GetTrapdoorParams()->GetDGG(), m_params->GetTrapdoorParams()->GetDGGLargeSigma(), m_params->GetTrapdoorParams()->GetBase());
PerturbationVector<Element> pvector(pertubationVector);
return pvector;
}
//Method for online phase for key generation phase of an IBE cycle without sampling
template<class Element>
void KeyGenOnline(
shared_ptr<IBEParams<Element>> m_params,
const IBEMasterSecretKey<Element> & msk,
const IBEMasterPublicKey<Element> & mpk,
const IBEUserIdentifier<Element> & id,
const PerturbationVector<Element> & pvector,
IBESecretKey<Element>* sk){
sk->SetSK(RLWETrapdoorUtility<Element>::GaussSampOnline(m_params->GetTrapdoorParams()->GetN(), m_params->GetTrapdoorParams()->GetK(), mpk.GetA(), msk.GetTA(), id.GetID(), m_params->GetTrapdoorParams()->GetDGG(), pvector.GetVector(), m_params->GetTrapdoorParams()->GetBase()));
void IBEScheme<Element>::KeyGenOnline(
shared_ptr<ABECoreParams<Element>> cm_params,
const ABECoreMasterSecretKey<Element> & cmsk,
const ABECoreMasterPublicKey<Element> & cmpk,
const ABECoreAccessPolicy<Element> & cid,
const PerturbationVector<Element> & pvector,
ABECoreSecretKey<Element>* csk){
shared_ptr<IBEParams<Element>> m_params = dynamic_pointer_cast<IBEParams<Element>>(cm_params);
const IBEMasterPublicKey<Element> & mpk = dynamic_cast<const IBEMasterPublicKey<Element>&>(cmpk);
const IBEMasterSecretKey<Element>& msk = dynamic_cast<const IBEMasterSecretKey<Element>&>(cmsk);
const IBEUserIdentifier<Element> & id = dynamic_cast<const IBEUserIdentifier<Element> &>(cid);
IBESecretKey<Element>* sk = dynamic_cast<IBESecretKey<Element>*>(csk);
Matrix<Element> key = RLWETrapdoorUtility<Element>::GaussSampOnline(m_params->GetTrapdoorParams()->GetN(), m_params->GetTrapdoorParams()->GetK(), mpk.GetA(), msk.GetTA(), id.GetID(), m_params->GetTrapdoorParams()->GetDGG(), pvector.GetVector(), m_params->GetTrapdoorParams()->GetBase());
sk->SetSK(std::make_shared<Matrix<Element>>(key));
}
//Method for encryption phase of an IBE cycle
template<class Element>
......
......@@ -280,8 +280,8 @@ namespace lbcrypto{
*@return Perturbation vector sampled
*/
PerturbationVector<Element> KeyGenOffline(
shared_ptr<IBEParams<Element>> m_params,
const IBEMasterSecretKey<Element> & msk);
shared_ptr<ABECoreParams<Element>> m_params,
const ABECoreMasterSecretKey<Element> & msk);
/*
*@brief Method for online phase for key generation phase of an IBE cycle without sampling
*@param m_params Parameters used in operations
......@@ -292,12 +292,12 @@ namespace lbcrypto{
*@param sk Secret key for decryption - Output
*/
void KeyGenOnline(
shared_ptr<IBEParams<Element>> m_params,
const IBEMasterSecretKey<Element> & msk,
const IBEMasterPublicKey<Element> & mpk,
const IBEUserIdentifier<Element> & id,
const PerturbationVector<Element> & pvector,
IBESecretKey<Element>* sk);
shared_ptr<ABECoreParams<Element>> m_params,
const ABECoreMasterSecretKey<Element> & msk,
const ABECoreMasterPublicKey<Element> & mpk,
const ABECoreAccessPolicy<Element> & ap,
const PerturbationVector<Element> & pvector,
ABECoreSecretKey<Element>* sk);
/*
*@brief Method for encryption phase of an IBE cycle
*@param m_params Parameters used in operations
......
......@@ -63,7 +63,6 @@ void UnitTestCPABE(SecurityLevel level,usint ell){
CPABEMasterPublicKey<Element> mpk;
CPABEMasterSecretKey<Element> msk;
context.Setup(&mpk,&msk);
std::vector<usint> s(ell);
std::vector<int> w(ell);
......@@ -95,6 +94,48 @@ void UnitTestCPABE(SecurityLevel level,usint ell){
context.Encrypt(mpk,ap,pt,&ct);
Plaintext dt = context.Decrypt(ap,ua,sk,ct);
EXPECT_EQ(pt->GetElement<Element>(),dt->GetElement<Element>());
}
template <class Element>
void UnitTestCPABETwoPhase(SecurityLevel level,usint ell){
ABEContext<Element> context;
context.GenerateCPABEContext(level,ell);
CPABEMasterPublicKey<Element> mpk;
CPABEMasterSecretKey<Element> msk;
context.Setup(&mpk,&msk);
std::vector<usint> s(ell);
std::vector<int> w(ell);
for(usint j=0; j<ell; j++)
s[j] = rand()%2;
for(usint j=0; j<ell; j++)
w[j] = s[j];
for(usint j=0; j<ell; j++)
if(w[j]==1) {
w[j] = 0;
break;
}
for(usint j=0; j<ell; j++)
if(s[j]==0) {
w[j] = -1;
break;
}
CPABEUserAccess<Element> ua(s);
CPABEAccessPolicy<Element> ap(w);
CPABESecretKey<Element> sk;
PerturbationVector<Element> pv;
context.KeyGenOfflinePhase(msk,pv);
context.KeyGenOnlinePhase(msk,mpk,ua,pv,&sk);
std::vector<int64_t> vectorOfInts = { 1,0,0,1,1,0,1,0, 1, 0};
Plaintext pt = context.MakeCoefPackedPlaintext(vectorOfInts);
CPABECiphertext<Element> ct;
context.Encrypt(mpk,ap,pt,&ct);
Plaintext dt = context.Decrypt(ap,ua,sk,ct);
EXPECT_EQ(pt->GetElement<Element>(),dt->GetElement<Element>());
......@@ -153,3 +194,6 @@ TEST(UTCPABE, cp_abe_256_native_20) {
TEST(UTCPABE, cp_abe_256_native_32) {
UnitTestCPABE<NativePoly>(HEStd_256_classic,32);
}
TEST(UTCPABE, cp_abe_two_phase) {
UnitTestCPABETwoPhase<NativePoly>(HEStd_192_classic,6);
}
......@@ -76,6 +76,28 @@ void UnitTestIBE(SecurityLevel level){
EXPECT_EQ(pt->GetElement<Element>(),dt->GetElement<Element>());
}
template <class Element>
void UnitTestIBETwoPhase(SecurityLevel level){
ABEContext<Element> context;
context.GenerateIBEContext(level);
IBEMasterPublicKey<Element> mpk;
IBEMasterSecretKey<Element> msk;
context.Setup(&mpk,&msk);
IBEUserIdentifier<Element> id(context.GenerateRandomElement());
IBESecretKey<Element> sk;
PerturbationVector<Element> pv;
context.KeyGenOfflinePhase(msk,pv);
context.KeyGenOnlinePhase(msk,mpk,id,pv,&sk);
std::vector<int64_t> vectorOfInts = { 1,0,0,1,1,0,1,0, 1, 0};
Plaintext pt = context.MakeCoefPackedPlaintext(vectorOfInts);
IBECiphertext<Element> ct;
context.Encrypt(mpk,id,pt,&ct);
Plaintext dt = context.Decrypt(sk,ct);
EXPECT_EQ(pt->GetElement<Element>(),dt->GetElement<Element>());
}
//Tests for 128 bit security
TEST(UTIBE, ibe_128_poly) {
UnitTestIBE<Poly>(HEStd_128_classic);
......@@ -97,4 +119,8 @@ TEST(UTIBE, ibe_256_poly) {
TEST(UTIBE, ibe_256_native) {
UnitTestIBE<NativePoly>(HEStd_256_classic);
}
//Test for two-phase key generation
TEST(UTIBE, ibe_two_phase) {
UnitTestIBETwoPhase<NativePoly>(HEStd_192_classic);
}
\ No newline at end of file
This diff is collapsed.
......@@ -285,6 +285,15 @@ public:
return m_params->GetModulus();
}
/**
* @brief returns the element's original modulus, derived from Poly
* @return returns the modulus of the element.