Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates main to v1.2.1 #866

Merged
merged 17 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
make

- name: deploy_docs
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
21 changes: 11 additions & 10 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
description: 'Compiler type'
type: string
required: true
default: 'CLANG-14'
default: 'CLANG-18'
native_backend:
description: 'Size of NativeInteger'
type: string
Expand All @@ -35,11 +35,11 @@ on:
type: string
required: true
default: 'none'

workflow_dispatch:
inputs:
# # Selects the compiler to use, this choice will be used in the COMPILERS_MAP as the key to
# # retrieve the corresponding cmake compiler options to pass to the action
# Selects the compiler to use, this choice will be used in the COMPILERS_MAP as the key to
# retrieve the corresponding cmake compiler options to pass to the action
compiler:
description: 'Compiler type'
type: choice
Expand All @@ -48,12 +48,15 @@ on:
- 'GCC-10'
- 'GCC-11'
- 'GCC-12'
- 'CLANG-12 (WITH_OPENMP=OFF)'
- 'CLANG-13 (WITH_OPENMP=OFF)'
- 'CLANG-14'
- 'GCC-13'
- 'GCC-14'
- 'CLANG-14 (WITH_OPENMP=OFF)'
- 'CLANG-15 (WITH_OPENMP=OFF)'
- 'CLANG-16 (WITH_OPENMP=OFF)'
- 'CLANG-17 (WITH_OPENMP=OFF)'
- 'CLANG-18'
required: true
default: 'CLANG-14'
default: 'CLANG-18'
native_backend:
description: 'Size of NativeInteger'
type: choice
Expand Down Expand Up @@ -122,5 +125,3 @@ jobs:
"mb6_ntl_tcm" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=6 -DWITH_NTL=ON -DWITH_TCM=ON",
"mb6_ntl_debug_tcm" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=6 -DWITH_NTL=ON -DWITH_TCM=ON -DCMAKE_BUILD_TYPE=Debug",
}'


6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ project (OpenFHE C CXX)

set(OPENFHE_VERSION_MAJOR 1)
set(OPENFHE_VERSION_MINOR 2)
set(OPENFHE_VERSION_PATCH 0)
set(OPENFHE_VERSION_PATCH 1)
set(OPENFHE_VERSION ${OPENFHE_VERSION_MAJOR}.${OPENFHE_VERSION_MINOR}.${OPENFHE_VERSION_PATCH})

set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -154,10 +154,6 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message (STATUS "BUILTIN_INFO_AVAILABLE is defined")
endif()

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(IGNORE_WARNINGS "${IGNORE_WARNINGS} -Wno-unused-private-field -Wno-shift-op-parentheses")
endif()

if( WITH_NATIVEOPT )
set (NATIVE_OPT "-march=native")
else()
Expand Down
1 change: 1 addition & 0 deletions benchmark/src/bfv-mult-method-benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define _USE_MATH_DEFINES
#include "scheme/bfvrns/gen-cryptocontext-bfvrns.h"
#include "gen-cryptocontext.h"
#include "cryptocontext.h"

#include "benchmark/benchmark.h"

Expand Down
1 change: 1 addition & 0 deletions benchmark/src/compare-bfv-hps-leveled-vs-behz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define _USE_MATH_DEFINES
#include "scheme/bfvrns/gen-cryptocontext-bfvrns.h"
#include "gen-cryptocontext.h"
#include "cryptocontext.h"

#include "benchmark/benchmark.h"

Expand Down
1 change: 1 addition & 0 deletions benchmark/src/compare-bfvrns-vs-bgvrns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "scheme/bfvrns/gen-cryptocontext-bfvrns.h"
#include "scheme/bgvrns/gen-cryptocontext-bgvrns.h"
#include "gen-cryptocontext.h"
#include "cryptocontext.h"

#include "benchmark/benchmark.h"

Expand Down
1 change: 1 addition & 0 deletions benchmark/src/lib-benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "scheme/bfvrns/gen-cryptocontext-bfvrns.h"
#include "scheme/bgvrns/gen-cryptocontext-bgvrns.h"
#include "gen-cryptocontext.h"
#include "cryptocontext.h"

#include <fstream>
#include <iostream>
Expand Down
1 change: 1 addition & 0 deletions benchmark/src/mult-vs-square.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "scheme/bgvrns/gen-cryptocontext-bgvrns.h"
#include "scheme/ckksrns/gen-cryptocontext-ckksrns.h"
#include "gen-cryptocontext.h"
#include "cryptocontext.h"

#include "benchmark/benchmark.h"

Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ sphinxcontrib-mermaid==0.7.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
urllib3>=1.26.18
zipp==3.7.0
zipp>=3.19.1
8 changes: 8 additions & 0 deletions docs/static_docs/Release_Notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
09/10/2024: OpenFHE 1.2.1 (stable) is released

* Fixes compilation issues with g++ 14 and clang++ 18 (#822, #835)
* Fixes the parameter estimation bug for HRA-secure PRE when ring dimension is not set by the user (#827)
* Includes several other bug fixes

The detailed list of changes is available at https://github.com/openfheorg/openfhe-development/issues?q=is%3Aissue+milestone%3A%22Release+1.2.1%22

06/25/2024: OpenFHE 1.2.0 (stable) is released

* Updates the lattice parameters tables to support the ring dimension of 2^{16} and 2^{17} for ternary and Gaussian secrets (#806)
Expand Down
2 changes: 1 addition & 1 deletion src/binfhe/lib/binfhe-base-scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ LWECiphertext BinFHEScheme::EvalFunc(const std::shared_ptr<BinFHECryptoParams>&
LWECiphertext BinFHEScheme::EvalFloor(const std::shared_ptr<BinFHECryptoParams>& params, const RingGSWBTKey& EK,
ConstLWECiphertext& ct, const NativeInteger& beta, uint32_t roundbits) const {
const auto& LWEParams = params->GetLWEParams();
NativeInteger q{roundbits == 0 ? LWEParams->Getq() : beta * (1 << roundbits + 1)};
NativeInteger q{roundbits == 0 ? LWEParams->Getq() : beta * (1 << (roundbits + 1))};
NativeInteger mod{ct->GetModulus()};

auto ct1 = std::make_shared<LWECiphertextImpl>(*ct);
Expand Down
9 changes: 5 additions & 4 deletions src/binfhe/lib/rgsw-cryptoparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ namespace lbcrypto {
void RingGSWCryptoParams::PreCompute(bool signEval) {
// Computes baseR^i (only for AP bootstrapping)
if (m_method == BINFHE_METHOD::AP) {
auto&& logq = log(m_q.ConvertToDouble());
auto digitCountR{static_cast<size_t>(std::ceil(logq / log(static_cast<double>(m_baseR))))};
auto&& logq = std::log(m_q.ConvertToDouble());
auto digitCountR{static_cast<size_t>(std::ceil(logq / std::log(static_cast<double>(m_baseR))))};
m_digitsR.clear();
m_digitsR.reserve(digitCountR);
BasicInteger value{1};
Expand All @@ -48,9 +48,10 @@ void RingGSWCryptoParams::PreCompute(bool signEval) {
// Computes baseG^i
if (signEval) {
constexpr uint32_t baseGlist[] = {1 << 14, 1 << 18, 1 << 27};
constexpr double logbaseGlist[] = {noexcept(log(1 << 14)), noexcept(log(1 << 18)), noexcept(log(1 << 27))};
// {log(1 << 14), log(1 << 18), log(1 << 27)}
constexpr double logbaseGlist[] = {0x1.3687a9f1af2b1p+3, 0x1.8f40b5ed9812dp+3, 0x1.2b708872320e2p+4};
constexpr NativeInteger nativebaseGlist[] = {1 << 14, 1 << 18, 1 << 27};
auto logQ{log(m_Q.ConvertToDouble())};
auto logQ{std::log(m_Q.ConvertToDouble())};
for (size_t j = 0; j < 3; ++j) {
NativeInteger vTemp{1};
auto tempdigits{static_cast<size_t>(std::ceil(logQ / logbaseGlist[j]))};
Expand Down
22 changes: 11 additions & 11 deletions src/core/include/math/discretegaussiangenerator-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool DiscreteGaussianGeneratorImpl<VecType>::IsInitialized() const {

template <typename VecType>
void DiscreteGaussianGeneratorImpl<VecType>::SetStd(double std) {
if (log2(m_std) > 59) {
if (std::log2(m_std) > 59) {
// if (lbcrypto::GetMSB(static_cast<uint64_t>(std)) > 59) {
std::string errorMsg(std::string("Standard deviation cannot exceed 59 bits"));
OPENFHE_THROW(errorMsg);
Expand All @@ -77,17 +77,17 @@ double DiscreteGaussianGeneratorImpl<VecType>::GetStd() const {
template <typename VecType>
void DiscreteGaussianGeneratorImpl<VecType>::Initialize() {
// usually the bound of m_std * M is used, where M = 12 .. 40
// we use M = 12 here, which corresponds to the probability of roughly 2^(-100)
constexpr double acc{5e-32};
constexpr double M{noexcept(sqrt(-2 * log(acc)))};
int fin{static_cast<int>(ceil(m_std * M))};
// we use M = std::sqrt(-2. * std::log(5e-32)) = 12.0061 here,
// which corresponds to the probability of roughly 2^(-100)
double M{12.00610553538285};
int fin{static_cast<int>(std::ceil(m_std * M))};

m_vals.clear();
m_vals.reserve(fin);
double variance{2 * m_std * m_std};
double cusum{0.0};
for (int x = 1; x <= fin; ++x) {
cusum += exp(-(static_cast<double>(x * x) / variance));
cusum += std::exp(-(static_cast<double>(x * x) / variance));
m_vals.push_back(cusum);
}
m_a = 1.0 / (2 * cusum + 1.0);
Expand Down Expand Up @@ -172,9 +172,9 @@ VecType DiscreteGaussianGeneratorImpl<VecType>::GenerateVector(const uint32_t si
template <typename VecType>
typename VecType::Integer DiscreteGaussianGeneratorImpl<VecType>::GenerateInteger(
double mean, double stddev, size_t n, const typename VecType::Integer& modulus) const {
double t = log2(n) * stddev;
double t = std::log2(n) * stddev;

std::uniform_int_distribution<int32_t> uniform_int(floor(mean - t), ceil(mean + t));
std::uniform_int_distribution<int32_t> uniform_int(floor(mean - t), std::ceil(mean + t));
std::uniform_real_distribution<double> uniform_real(0.0, 1.0);

int32_t x;
Expand All @@ -197,8 +197,8 @@ int32_t DiscreteGaussianGeneratorImpl<VecType>::GenerateInteger(double mean, dou
OPENFHE_THROW("DiscreteGaussianGeneratorImpl called with stddev == +-inf");

// this representation of log_2 is used for Visual Studio
double t = log2(n) * stddev;
std::uniform_int_distribution<int32_t> uniform_int(floor(mean - t), ceil(mean + t));
double t = std::log2(n) * stddev;
std::uniform_int_distribution<int32_t> uniform_int(floor(mean - t), std::ceil(mean + t));
std::uniform_real_distribution<double> uniform_real(0.0, 1.0);

double sigmaFactor = 1 / (-2. * stddev * stddev);
Expand All @@ -223,7 +223,7 @@ int32_t DiscreteGaussianGeneratorImpl<VecType>::GenerateInteger(double mean, dou
template <typename VecType>
int64_t DiscreteGaussianGeneratorImpl<VecType>::GenerateIntegerKarney(double mean, double stddev) {
std::uniform_int_distribution<int64_t> uniform_sign(0, 1);
std::uniform_int_distribution<int64_t> uniform_j(0, ceil(stddev) - 1);
std::uniform_int_distribution<int64_t> uniform_j(0, std::ceil(stddev) - 1);

PRNG& g = PseudoRandomNumberGenerator::GetPRNG();

Expand Down
10 changes: 5 additions & 5 deletions src/core/include/math/hal/intnat/ubintnat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface<NativeIntegerT
MultD(av.m_value, bv.m_value, tmp);
auto rv = GetD(tmp);
MultD(RShiftD(tmp, n), mu.m_value, tmp);
rv -= DNativeInt(mv) * (GetD(tmp) >> n + 7);
rv -= DNativeInt(mv) * (GetD(tmp) >> (n + 7));
NativeIntegerT r(rv);
if (r.m_value >= mv)
r.m_value -= mv;
Expand Down Expand Up @@ -1211,7 +1211,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface<NativeIntegerT
MultD(av.m_value, bv.m_value, tmp);
auto rv = GetD(tmp);
MultD(RShiftD(tmp, n), muv, tmp);
rv -= DNativeInt(mv) * (GetD(tmp) >> n + 7);
rv -= DNativeInt(mv) * (GetD(tmp) >> (n + 7));
m_value = static_cast<NativeInt>(rv);
if (m_value >= mv)
m_value -= mv;
Expand Down Expand Up @@ -1358,7 +1358,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface<NativeIntegerT
MultD(m_value, b.m_value, tmp);
auto rv = GetD(tmp);
MultD(RShiftD(tmp, n), mu.m_value, tmp);
rv -= DNativeInt(mv) * (GetD(tmp) >> n + 7);
rv -= DNativeInt(mv) * (GetD(tmp) >> (n + 7));
NativeIntegerT r(rv);
if (r.m_value >= mv)
r.m_value -= mv;
Expand Down Expand Up @@ -1399,7 +1399,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface<NativeIntegerT
int64_t n{modulus.GetMSB() - 2};
MultD(RShiftD(tmp, n), mu.m_value, tmp);
auto& mv{modulus.m_value};
rv -= DNativeInt(mv) * (GetD(tmp) >> n + 7);
rv -= DNativeInt(mv) * (GetD(tmp) >> (n + 7));
m_value = NativeInt(rv);
if (m_value >= mv)
m_value -= mv;
Expand Down Expand Up @@ -2051,7 +2051,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface<NativeIntegerT
typename std::enable_if_t<!std::is_same_v<T, DNativeInt>, bool> = true) {
prod = {0, a.m_value};
MultD(RShiftD(prod, n), mu, prod);
a.m_value -= static_cast<NativeInt>((GetD(prod) >> n + 7) * mv);
a.m_value -= static_cast<NativeInt>((GetD(prod) >> (n + 7)) * mv);
if (a.m_value >= mv)
a.m_value -= mv;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/include/math/nbtheory.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ inline usint ReverseBits(usint num, usint msb) {
reverse_byte((num >> 16) & 0xff) << 8 | reverse_byte((num >> 24) & 0xff)) >>
shift_trick[msb & 0x7];
default:
return -1;
// OPENFHE_THROW("msbb value not handled:" +
// std::to_string(msbb));
// ERROR
break;
}
OPENFHE_THROW("msbb value not handled:" + std::to_string(msbb));
}

/**
Expand Down
37 changes: 19 additions & 18 deletions src/core/unittest/UnitTestBlockAllocate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@
/*
This code exercises the block allocator utility of the OpenFHE lattice encryption library.
*/

#if 0
// #define PROFILE //define this is we want profiling output and statistics
#include <assert.h>
#include <stdio.h>
#include <assert.h>
#include <stdio.h>

#include <iostream>
#include <new>
#include <iostream>
#include <new>

#include "gtest/gtest.h"
#include "gtest/gtest.h"

#include "math/math-hal.h"
#include "utils/blockAllocator/blockAllocator.h"
#include "utils/debug.h"
#include "utils/inttypes.h"
#include "utils/utilities.h"
#include "math/math-hal.h"
#include "utils/blockAllocator/blockAllocator.h"
#include "utils/debug.h"
#include "utils/inttypes.h"
#include "utils/utilities.h"

using namespace lbcrypto;

Expand All @@ -64,7 +64,7 @@ class UnitTestBinInt : public ::testing::Test {
/* TESTING METHODS OF Allocator CLASS */
/************************************************/

#define BLOCKSIZE 8192
#define BLOCKSIZE 8192

typedef char Block[BLOCKSIZE]; // define Block as char array of size BLOCKSIZE

Expand All @@ -88,11 +88,11 @@ Allocator allocatorStaticPool(BLOCKSIZE, 20, staticMemoryPool);
AllocatorPool<MyClass, 20> allocatorStaticPool2;

// Benchmark allocators
#ifdef __ANDROID__
#ifdef __ANDROID__
static const int MAX_BLOCKS = 512; // reduce size of pool for limited memory
#else
#else
static const int MAX_BLOCKS = 4096;
#endif
#endif
static const int MAX_BLOCK_SIZE = 8196;
char* memoryPtrs[MAX_BLOCKS];
char* memoryPtrs2[MAX_BLOCKS];
Expand All @@ -103,12 +103,12 @@ static void out_of_memory() {
// new-handler function called by Allocator when pool is out of memory

std::cerr << "out_of_memory in block allocator";
#if 0
#if 0
std::bad_alloc exception;
throw(exception);
#else
#else
assert(0);
#endif
#endif
}

typedef char* (*AllocFunc)(int size);
Expand Down Expand Up @@ -250,3 +250,4 @@ TEST(UTBlockAllocate, block_allocator_test) {
Benchmark("Heap Blocks (Run 2)", AllocHeapBlocks, DeallocHeapBlocks);
Benchmark("Heap Blocks (Run 3)", AllocHeapBlocks, DeallocHeapBlocks);
}
#endif
5 changes: 3 additions & 2 deletions src/pke/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,16 @@ If the set function is called for a parameter which is not available for the giv
- q_i have same number of bits and is equal to scalingModSize
- the prime q' is not explicitly given, but it is used internally in CKKS and BGV schemes (in *EXT scaling methods)
- **firstModSize** is allowed for BGV with **scalTech = FIXEDMANUAL** only
- **scalingModSize** is allowed for BGV with **scalTech = FIXEDMANUAL** and **scalingModSize** must be < 60 for CKKS and NATIVEINT=64.
- **scalingModSize** is allowed for BGV with **scalTech = FIXEDMANUAL** and **scalingModSize** must be < 60 for CKKS and NATIVEINT=64
- **firstModSize and scalingModSize** are not available for BGV if PREMode=NOISE_FLOODING_HRA.

**uint32_t numLargeDigits** - number of digits in HYBRID key switching (see KeySwitchTechnique).

**uint32_t multiplicativeDepth** - the maximum number of multiplications (in a binary tree manner) we can perform before bootstrapping. Must be 0 for BGV if PREMode=NOISE_FLOODING_HRA.

**SecurityLevel securityLevel** - We use the values from the security standard at http://homomorphicencryption.org/wp-content/uploads/2018/11/HomomorphicEncryptionStandardv1.1.pdf. Given the ring dimension and security level, we have upper bound of possible highest modulus (Q for BV or P*Q for HYBRID).

**uint32_t ringDim** - ring dimension N of the scheme : the ring is Z_Q[x] / (X^N+1)
**uint32_t ringDim** - ring dimension N of the scheme : the ring is Z_Q[x] / (X^N+1). Must be > 0 for BGV if PREMode=NOISE_FLOODING_HRA.

**uint32_t evalAddCount (BGV/BFV only)** - maximum number of additions (used for setting noise). In BGV, it is the maximum number of additions at any level.

Expand Down
Loading
Loading