Skip to content

Commit

Permalink
Helib 2 0 0 (IBM#105)
Browse files Browse the repository at this point in the history
* ML-HElib new version

* deleted old demo

* example renamed

* removed documentation

* fixed minimum required version

* removed unused lines from gitignore

* Changed config of sample code to be Debug so it works with the launch button

* changing where the test script calls cmake

* making the testing changes to the pr script to match what the others are doing

* improved conjugate, improved context init

* small fixes

* presets

* more preset configurations

* documentation

* makefile fix

* added the name change of the image based on which version of the linux is being built to the pr test script

* Mlhelib update (IBM#85)

* improved conjugate, improved context init

* small fixes

* presets

* more preset configurations

* documentation

* makefile fix

* small testing bug fix

* Mlhelib update (IBM#86)

* improved conjugate, improved context init

* small fixes

* presets

* more preset configurations

* documentation

* makefile fix

* small testing bug fix

* changed the script to point to this branch so we can test the jobs

* switching the versions fhe toolkit moving to 2, and helib 1.3.1

* testing code bug fix and added readmes

* bug fix and more documentation

* pointing to helib 2.0.0 to test it

* new HElib ver

* small fix

* missing methods

Co-authored-by: aehud <[email protected]>
  • Loading branch information
boland25 and aehud authored Jan 22, 2021
1 parent 50ad8f1 commit 72fa25e
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 35 deletions.
6 changes: 3 additions & 3 deletions ConfigConstants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
# NTL Library
NTL_version='11.4.3'
#HELib Library
HElib_version='v1.3.1'
HElib_cmake_lists_version='1.3.1'
HElib_version='v2.0.0'
HElib_cmake_lists_version='2.0.0'
# Boost Library
Boost_version='1.72.0'
Boost_filename='1_72_0'
TEST_VAR_NAME='20.1.10'
TOOLKIT_VERSION='2'
TOOLKIT_VERSION='0'
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ void HelibBgvContext::init(const HelibConfig& conf)

config = conf;
traits.setArithmeticModulus(config.p);
context = new Context(config.m, config.p, config.r);
buildModChain(*context, config.L, config.c);

context = ContextBuilder<BGV>()
.m(config.m)
.p(config.p)
.r(config.r)
.c(config.c)
.bits(config.L)
.buildPtr();

// buildModChain(*context, config.L, config.c);
secretKey = new helib::SecKey(*context);
secretKey->GenSecKey();
addSome1DMatrices(*secretKey);
publicKey = secretKey;
ea = context->ea;
ea = &context->getEA();
nslots = ea->size();
}

Expand All @@ -81,7 +89,7 @@ void HelibBgvContext::init(const HelibConfig& conf,
context = userContext;
secretKey = userSecretKey;
publicKey = userPublicKey;
ea = context->ea;
ea = &context->getEA();
nslots = ea->size();
}

Expand Down Expand Up @@ -116,7 +124,7 @@ void HelibBgvContext::printSignature(std::ostream& out) const
void HelibBgvContext::load(std::istream& in)
{
HelibContext::load(in);
ea = context->ea;
ea = &context->getEA();
nslots = ea->size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HelibBgvContext : public HelibContext
{

unsigned long p;
std::shared_ptr<const helib::EncryptedArray> ea = NULL;
const helib::EncryptedArray* ea = NULL;

// double defaultScale = 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "HelibBgvPlaintext.h"
#include "helayers/hebase/utils/BinIoUtils.h"

using namespace std;
using namespace helib;
Expand All @@ -38,7 +39,7 @@ streamoff HelibBgvPlaintext::save(ostream& stream) const
{
streampos streamStartPos = stream.tellp();

serialize<BGV>(stream, pt);
writePtxtToBinary(stream, pt);

streampos streamEndPos = stream.tellp();

Expand All @@ -49,7 +50,7 @@ streamoff HelibBgvPlaintext::load(istream& stream)
{
streampos streamStartPos = stream.tellg();

deserialize<BGV>(stream, pt);
readPtxtFromBinary(stream, pt, heContext.getContext());

streampos streamEndPos = stream.tellg();

Expand All @@ -71,4 +72,21 @@ const helib::Ptxt<helib::BGV>& HelibBgvPlaintext::getPlaintext() const

return pt;
}

void HelibBgvPlaintext::writePtxtToBinary(std::ostream& stream,
const helib::Ptxt<helib::BGV>& pt)
{
stringstream out;
pt.writeToJSON(out);
BinIoUtils::writeString(stream, out.str());
}

void HelibBgvPlaintext::readPtxtFromBinary(std::istream& stream,
helib::Ptxt<helib::BGV>& pt,
const helib::Context& context)
{
string data = BinIoUtils::readString(stream);
stringstream in(data);
pt = Ptxt<BGV>::readFromJSON(in, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class HelibBgvPlaintext : public AbstractPlaintext
int slotCount() const override;

const helib::Ptxt<helib::BGV>& getPlaintext() const;

static void writePtxtToBinary(std::ostream& out,
const helib::Ptxt<helib::BGV>& pt);

static void readPtxtFromBinary(std::istream& out,
helib::Ptxt<helib::BGV>& pt,
const helib::Context& context);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ streamoff HelibCiphertext::save(ostream& stream) const
HELAYERS_TIMER("HelibCiphertext::save");
streampos streamStartPos = stream.tellp();

ctxt.write(stream);
ctxt.writeTo(stream);

streampos streamEndPos = stream.tellp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,15 @@ void HelibCkksContext::init(const HelibConfig& conf)
config = conf;
unsigned long p = -1;

context = new Context(config.m, p, config.r);
buildModChain(*context, config.L, config.c);
context = ContextBuilder<BGV>()
.m(config.m)
.p(config.p)
.r(config.r)
.c(config.c)
.bits(config.L)
.buildPtr();

// buildModChain(*context, config.L, config.c);
secretKey = new helib::SecKey(*context);
secretKey->GenSecKey();
addSome1DMatrices(*secretKey);
Expand Down Expand Up @@ -114,7 +121,7 @@ void HelibCkksContext::init(const HelibConfig& conf,

void HelibCkksContext::initCommon(helib::Context* context)
{
ea = &context->ea->getCx();
ea = &context->getEA().getCx();
nslots = ea->size();
}

Expand All @@ -136,7 +143,7 @@ shared_ptr<AbstractEncoder> HelibCkksContext::getEncoder()
void HelibCkksContext::load(std::istream& in)
{
HelibContext::load(in);
ea = &context->ea->getCx();
ea = &context->getEA().getCx();
nslots = ea->size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "HelibCkksPlaintext.h"
#include "helayers/hebase/utils/BinIoUtils.h"

using namespace std;
using namespace helib;
Expand All @@ -38,7 +39,10 @@ streamoff HelibCkksPlaintext::save(ostream& stream) const
{
streampos streamStartPos = stream.tellp();

serialize<CKKS>(stream, pt);
stringstream out;
pt.writeToJSON(out);

BinIoUtils::writeString(stream, out.str());

streampos streamEndPos = stream.tellp();

Expand All @@ -49,7 +53,10 @@ streamoff HelibCkksPlaintext::load(istream& stream)
{
streampos streamStartPos = stream.tellg();

deserialize<CKKS>(stream, pt);
string data = BinIoUtils::readString(stream);

stringstream in(data);
pt = Ptxt<CKKS>::readFromJSON(in, heContext.getContext());

streampos streamEndPos = stream.tellg();

Expand Down
25 changes: 12 additions & 13 deletions DEPENDENCIES/ML-HElib/src/helayers/hebase/helib/HelibContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,28 @@ void HelibContext::save(std::ostream& out, bool withSecretKey)
config.save(out);
out.write((char*)&withSecretKey, sizeof(withSecretKey));
out.write((char*)&mirrored, sizeof(mirrored));
writeContextBaseBinary(out, *context);
writeContextBinary(out, *context);
context->writeTo(out);
// writeContextBinary(out, *context);
if (withSecretKey)
writeSecKeyBinary(out, *secretKey);
secretKey->writeTo(out);
else
writePubKeyBinary(out, *publicKey);
publicKey->writeTo(out);
}

void HelibContext::saveSecretKey(std::ostream& out)
{
if (!hasSecretKey()) {
throw runtime_error("this HeContext does not have a secret key");
}
writeSecKeyBinary(out, *secretKey);
secretKey->writeTo(out);
}

void HelibContext::loadSecretKey(std::istream& in)
{
if (hasSecretKey()) {
throw runtime_error("this HeContext already has a secret key");
}
secretKey = new SecKey(*context);
readSecKeyBinary(in, *secretKey);
secretKey = new SecKey(SecKey::readFrom(in, *context));
}

void HelibContext::load(std::istream& in)
Expand All @@ -131,16 +130,16 @@ void HelibContext::load(std::istream& in)
bool withSecretKey;
in.read((char*)&withSecretKey, sizeof(withSecretKey));
in.read((char*)&mirrored, sizeof(mirrored));
context = buildContextFromBinary(in).release();
readContextBinary(in, *context);
context = Context::readPtrFrom(in);
// readContextBinary(in, *context);

if (withSecretKey) {
secretKey = new SecKey(*context);
readSecKeyBinary(in, *secretKey);
secretKey = new SecKey(SecKey::readFrom(in, *context));
publicKey = (helib::PubKey*)secretKey;
} else {
publicKey = new PubKey(*context);
readPubKeyBinary(in, *publicKey);

publicKey = new PubKey(PubKey::readFrom(in, *context));
// readPubKeyBinary(in, *publicKey);
secretKey = NULL;
}
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/jenkins/fhe_docker_jenkins_trigger_builds_alpine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ BUILD_TYPE=$3
SLACK_HOOK=$4

# Pull latest from the FHE repo, master branch
git checkout master
git checkout helib_2_0_0

# Build the Docker image for Alpine
./BuildDockerImage.sh alpine
# Shut everything down before we start
Expand Down
3 changes: 2 additions & 1 deletion scripts/jenkins/fhe_docker_jenkins_trigger_builds_centos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ BUILD_TYPE=$3
SLACK_HOOK=$4

# Pull latest from the FHE repo, master branch
git checkout master
git checkout helib_2_0_0

# Build the Docker image for CentOS
./BuildDockerImage.sh centos
# Shut everything down before we start
Expand Down
3 changes: 2 additions & 1 deletion scripts/jenkins/fhe_docker_jenkins_trigger_builds_fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ BUILD_TYPE=$3
SLACK_HOOK=$4

# Pull latest from the FHE repo, master branch
git checkout master
git checkout helib_2_0_0

# Build the Docker image for Fedora
./BuildDockerImage.sh fedora
# Shut everything down before we start
Expand Down
3 changes: 2 additions & 1 deletion scripts/jenkins/fhe_docker_jenkins_trigger_builds_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ BUILD_TYPE=$3
SLACK_HOOK=$4

# Pull latest from the FHE repo, master branch
git checkout master
git checkout helib_2_0_0

# Build the Docker image for Ubuntu
./BuildDockerImage.sh ubuntu
# Shut everything down before we start
Expand Down

0 comments on commit 72fa25e

Please sign in to comment.