Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/pke/include/cryptocontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -2628,10 +2628,11 @@ class CryptoContextImpl : public Serializable {
* @param towersLeft Number of RNS limbs to retain.
* @return Compressed ciphertext.
*/
Ciphertext<Element> Compress(ConstCiphertext<Element>& ciphertext, uint32_t towersLeft = 1) const {
Ciphertext<Element> Compress(ConstCiphertext<Element>& ciphertext, uint32_t towersLeft = 1,
size_t noiseScaleDeg = 1) const {
if (ciphertext == nullptr)
OPENFHE_THROW("input ciphertext is invalid (has no data)");
return GetScheme()->Compress(ciphertext, towersLeft);
return GetScheme()->Compress(ciphertext, towersLeft, noiseScaleDeg);
}

//------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/pke/include/scheme/bfvrns/bfvrns-leveledshe.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class LeveledSHEBFVRNS : public LeveledSHERNS {

uint32_t FindAutomorphismIndex(uint32_t index, uint32_t m) const override;

Ciphertext<DCRTPoly> Compress(ConstCiphertext<DCRTPoly>& ciphertext, size_t towersLeft) const override;
Ciphertext<DCRTPoly> Compress(ConstCiphertext<DCRTPoly>& ciphertext, size_t towersLeft,
size_t noiseScaleDeg) const override;

/////////////////////////////////////
// SERIALIZATION
Expand Down
3 changes: 2 additions & 1 deletion src/pke/include/schemebase/base-leveledshe.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,8 @@ class LeveledSHEBase {
OPENFHE_THROW("LevelReduceInPlace is not supported for this scheme");
}

virtual Ciphertext<Element> Compress(ConstCiphertext<Element>& ciphertext, size_t towersLeft) const {
virtual Ciphertext<Element> Compress(ConstCiphertext<Element>& ciphertext, size_t towersLeft,
size_t noiseScaleDeg) const {
OPENFHE_THROW("Compress is not supported for this scheme");
}

Expand Down
5 changes: 3 additions & 2 deletions src/pke/include/schemebase/base-scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,10 @@ class SchemeBase {
m_LeveledSHE->LevelReduceInternalInPlace(ciphertext, levels);
}

virtual Ciphertext<Element> Compress(ConstCiphertext<Element>& ciphertext, size_t towersLeft) const {
virtual Ciphertext<Element> Compress(ConstCiphertext<Element>& ciphertext, size_t towersLeft,
size_t noiseScaleDeg) const {
VerifyLeveledSHEEnabled(__func__);
return m_LeveledSHE->Compress(ciphertext, towersLeft);
return m_LeveledSHE->Compress(ciphertext, towersLeft, noiseScaleDeg);
}

virtual void AdjustLevelsInPlace(Ciphertext<Element>& ciphertext1, Ciphertext<Element>& ciphertext2) const {
Expand Down
3 changes: 2 additions & 1 deletion src/pke/include/schemerns/rns-leveledshe.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ class LeveledSHERNS : public LeveledSHEBase<DCRTPoly> {
// SHE LEVELED Compress
/////////////////////////////////////////

Ciphertext<DCRTPoly> Compress(ConstCiphertext<DCRTPoly>& ciphertext, size_t towersLeft) const override;
Ciphertext<DCRTPoly> Compress(ConstCiphertext<DCRTPoly>& ciphertext, size_t towersLeft,
size_t noiseScaleDeg) const override;

////////////////////////////////////////
// SHE LEVELED ComposedEvalMult
Expand Down
3 changes: 2 additions & 1 deletion src/pke/lib/scheme/bfvrns/bfvrns-leveledshe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,8 @@ void LeveledSHEBFVRNS::RelinearizeCore(Ciphertext<DCRTPoly>& ciphertext, const E
cv.resize(2);
}

Ciphertext<DCRTPoly> LeveledSHEBFVRNS::Compress(ConstCiphertext<DCRTPoly>& ciphertext, size_t towersLeft) const {
Ciphertext<DCRTPoly> LeveledSHEBFVRNS::Compress(ConstCiphertext<DCRTPoly>& ciphertext, size_t towersLeft,
size_t noiseScaleDeg) const {
const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersBFVRNS>(ciphertext->GetCryptoParameters());

if ((cryptoParams->GetMultiplicationTechnique() == BEHZ) || (cryptoParams->GetMultiplicationTechnique() == HPS)) {
Expand Down
5 changes: 3 additions & 2 deletions src/pke/lib/schemerns/rns-leveledshe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ void LeveledSHERNS::LevelReduceInPlace(Ciphertext<DCRTPoly>& ciphertext, const E
* On COMPOSITESCALING technique, the number of towers to drop passed
* must be a multiple of composite degree.
*/
Ciphertext<DCRTPoly> LeveledSHERNS::Compress(ConstCiphertext<DCRTPoly>& ciphertext, size_t towersLeft) const {
Ciphertext<DCRTPoly> LeveledSHERNS::Compress(ConstCiphertext<DCRTPoly>& ciphertext, size_t towersLeft,
size_t noiseScaleDeg) const {
const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersRNS>(ciphertext->GetCryptoParameters());

uint32_t levelsToDrop = BASE_NUM_LEVELS_TO_DROP;
Expand All @@ -363,7 +364,7 @@ Ciphertext<DCRTPoly> LeveledSHERNS::Compress(ConstCiphertext<DCRTPoly>& cipherte
}

auto result = std::make_shared<CiphertextImpl<DCRTPoly>>(*ciphertext);
while (result->GetNoiseScaleDeg() > 1)
while (result->GetNoiseScaleDeg() > noiseScaleDeg)
ModReduceInternalInPlace(result, levelsToDrop);

size_t sizeQl = result->GetElements()[0].GetNumOfElements();
Expand Down
6 changes: 4 additions & 2 deletions src/pke/unittest/utbgvrns/UnitTestBGVrns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include <iostream>
#include <vector>
#include <memory>
#include <string>
#include "gtest/gtest.h"

using namespace lbcrypto;
Expand Down Expand Up @@ -291,7 +293,7 @@ class UTBGVRNS : public ::testing::TestWithParam<TEST_CASE_UTBGVRNS> {
// std::vector<int64_t> vectorOfIntsSub = { -7,-5,-3,-1,1,3,5,7 };
std::vector<int64_t> vectorOfIntsSub(VECTOR_SIZE);
for (usint i = 0; i < VECTOR_SIZE; i++) {
vectorOfIntsSub[i] = (int64_t)(2 * i) - VECTOR_SIZE + 1;
vectorOfIntsSub[i] = static_cast<int64_t>(2 * i) - VECTOR_SIZE + 1;
}
Plaintext plaintextSub = cc->MakePackedPlaintext(vectorOfIntsSub);

Expand Down Expand Up @@ -889,7 +891,7 @@ class UTBGVRNS : public ::testing::TestWithParam<TEST_CASE_UTBGVRNS> {
Plaintext resultCompressed;
auto algo = cc->GetScheme();
size_t targetTowers = (testData.params.scalTech == FLEXIBLEAUTOEXT) ? 2 : 1;
auto ctCompressed = algo->Compress(ct, targetTowers);
auto ctCompressed = cc->Compress(ct, targetTowers);

size_t towersLeft = ctCompressed->GetElements()[0].GetNumOfElements();
EXPECT_TRUE(towersLeft == targetTowers) << " compress fails";
Expand Down