Skip to content
Draft
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
19 changes: 11 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ set(OPENFHE_VERSION_MINOR 5)
set(OPENFHE_VERSION_PATCH 1)
set(OPENFHE_VERSION ${OPENFHE_VERSION_MAJOR}.${OPENFHE_VERSION_MINOR}.${OPENFHE_VERSION_PATCH})

set(CMAKE_CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#--------------------------------------------------------------------
# Build options
Expand Down Expand Up @@ -128,12 +128,12 @@ message(STATUS "USE_MACPORTS: ${USE_MACPORTS}")
# Compiler logic
#--------------------------------------------------------------------
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
message(WARNING "GCC version should be at least 9.0.")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0)
message(WARNING "GCC version should be at least 13.0 for reliable C++23 support.")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10)
message(WARNING "Clang version should be at least 10.0.")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0)
message(WARNING "Clang version should be at least 17.0 for reliable C++23 support.")
endif()
else()
message(WARNING "You are using ${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION}, which is unsupported.")
Expand Down Expand Up @@ -169,13 +169,16 @@ endif()
set(IGNORE_WARNINGS "") # initialize IGNORE_WARNINGS
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# Add -Wno-parentheses for compatibility with g++
set (IGNORE_WARNINGS "-Wno-parentheses")
# Add -Wno-volatile to suppress C++20 deprecated-volatile warnings for intentional
# security-related volatile uses (e.g., secure_memset, blake2 memset_v)
set (IGNORE_WARNINGS "-Wno-parentheses -Wno-volatile")
# We can use GNU built-in functions provided by GCC for debugging. ex: __builtin_LINE (), __builtin_FUNCTION (), __builtin_FILE ()
add_definitions(-DBUILTIN_INFO_AVAILABLE)
message(STATUS "BUILTIN_INFO_AVAILABLE is defined")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set (IGNORE_WARNINGS "-Wno-parentheses")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(IGNORE_WARNINGS "-Wno-unused-private-field -Wno-shift-op-parentheses")
string(APPEND IGNORE_WARNINGS " -Wno-unused-private-field -Wno-shift-op-parentheses")
endif()
endif()
if(IGNORE_WARNINGS)
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/lattice/field2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class Field2n : public std::vector<std::complex<double>>, public Serializable {
std::string SerializedObjectName() const override {
return "Field2n";
}
static uint32_t SerializedVersion() {
static constexpr uint32_t SerializedVersion() {
return 1;
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/core/include/lattice/hal/default/dcrtpoly.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ class DCRTPolyImpl final : public DCRTPolyInterface<DCRTPolyImpl<VecType>, VecTy
return "DCRTPoly";
}

static uint32_t SerializedVersion() {
static constexpr uint32_t SerializedVersion() {
return 1;
}

inline Format GetFormat() const final {
constexpr Format GetFormat() const final {
return m_format;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/include/lattice/hal/default/ildcrtparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class ILDCRTParams final : public ElemParams<IntType> {
std::string SerializedObjectName() const override {
return "DCRTParams";
}
static uint32_t SerializedVersion() {
static constexpr uint32_t SerializedVersion() {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/include/lattice/hal/default/ilparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ILParamsImpl final : public ElemParams<IntType> {
return "ILParms";
}

static uint32_t SerializedVersion() {
static constexpr uint32_t SerializedVersion() {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/include/lattice/hal/default/poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class PolyImpl final : public PolyInterface<PolyImpl<VecType>, VecType, PolyImpl
return "Poly";
}

static uint32_t SerializedVersion() {
static constexpr uint32_t SerializedVersion() {
return 1;
}

Expand Down
14 changes: 7 additions & 7 deletions src/core/include/lattice/hal/elemparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class ElemParams : public Serializable {
* @brief Simple getter method for cyclotomic order.
* @return The cyclotomic order.
*/
uint32_t GetCyclotomicOrder() const {
constexpr uint32_t GetCyclotomicOrder() const {
return m_cyclotomicOrder;
}

Expand All @@ -156,7 +156,7 @@ class ElemParams : public Serializable {
* evaluation of the totient function of the cyclotomic order.
* @return the ring dimension.
*/
uint32_t GetRingDimension() const {
constexpr uint32_t GetRingDimension() const {
return m_ringDimension;
}

Expand All @@ -165,7 +165,7 @@ class ElemParams : public Serializable {
* ciphertext modulus.
* @return The ciphertext modulus, not the big ciphertext modulus.
*/
const IntegerType& GetModulus() const {
constexpr const IntegerType& GetModulus() const {
return m_ciphertextModulus;
}

Expand All @@ -174,7 +174,7 @@ class ElemParams : public Serializable {
* This is not relevant for all applications.
* @return The big ciphertext modulus.
*/
const IntegerType& GetBigModulus() const {
constexpr const IntegerType& GetBigModulus() const {
return m_bigCiphertextModulus;
}

Expand All @@ -183,15 +183,15 @@ class ElemParams : public Serializable {
* unity.
* @return The root of unity, not the big root of unity.
*/
const IntegerType& GetRootOfUnity() const {
constexpr const IntegerType& GetRootOfUnity() const {
return m_rootOfUnity;
}

/**
* @brief Simple getter method for the big root of unity.
* @return The the big root of unity.
*/
const IntegerType& GetBigRootOfUnity() const {
constexpr const IntegerType& GetBigRootOfUnity() const {
return m_bigRootOfUnity;
}

Expand Down Expand Up @@ -251,7 +251,7 @@ class ElemParams : public Serializable {
std::string SerializedObjectName() const override {
return "ElemParams";
}
static uint32_t SerializedVersion() {
static constexpr uint32_t SerializedVersion() {
return 1;
}

Expand Down
193 changes: 170 additions & 23 deletions src/core/include/lattice/stdlatticeparms.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "utils/inttypes.h"

#include <array>
#include <iosfwd>
#include <map>
#include <string>
Expand Down Expand Up @@ -96,25 +97,18 @@ class StdLatticeParm {
// will suffer MAKE SURE that the number of entries in the DistributionType
// enum is == the first index, and MAKE SURE that the number of entries in the
// SecurityLevel enum is == the second index
static std::map<uint32_t, StdLatticeParm*> byRing[3][6];
static std::map<uint32_t, StdLatticeParm*> byLogQ[3][6];
static std::map<uint32_t, const StdLatticeParm*> byRing[3][6];
static std::map<uint32_t, const StdLatticeParm*> byLogQ[3][6];

static std::vector<StdLatticeParm> StandardLatticeParmSets;
static bool initialized;

// defined out-of-class below, after the anonymous namespace that holds the constexpr data
static void initializeLookups();

public:
StdLatticeParm(DistributionType distType, uint32_t ringDim, SecurityLevel minSecLev, uint32_t maxLogQ)
constexpr StdLatticeParm(DistributionType distType, uint32_t ringDim, SecurityLevel minSecLev, uint32_t maxLogQ)
: distType(distType), ringDim(ringDim), minSecLev(minSecLev), maxLogQ(maxLogQ) {}

static void initializeLookups() {
for (size_t i = 0; i < StandardLatticeParmSets.size(); i++) {
StdLatticeParm& s = StandardLatticeParmSets[i];
byRing[static_cast<int>(s.distType)][static_cast<int>(s.minSecLev)][s.ringDim] = &s;
byLogQ[static_cast<int>(s.distType)][static_cast<int>(s.minSecLev)][s.maxLogQ] = &s;
}
initialized = true;
}

static uint32_t FindMaxQ(DistributionType distType, SecurityLevel minSecLev, uint32_t ringDim) {
int distTypeIdx = static_cast<int>(distType);
int minSecLevIdx = static_cast<int>(minSecLev);
Expand All @@ -133,30 +127,183 @@ class StdLatticeParm {

int distTypeIdx = static_cast<int>(distType);
int minSecLevIdx = static_cast<int>(minSecLev);
uint32_t n = 0;
for (std::pair<const unsigned int, StdLatticeParm*>& it : byLogQ[distTypeIdx][minSecLevIdx]) {
if ((curLogQ <= it.second->getMaxLogQ()) && (curLogQ > prev))
return it.second->getRingDim();
prev = it.second->getMaxLogQ();
n = it.second->getRingDim();
uint32_t n = 0;
for (const auto& [key, parm] : byLogQ[distTypeIdx][minSecLevIdx]) {
if ((curLogQ <= parm->getMaxLogQ()) && (curLogQ > prev))
return parm->getRingDim();
prev = parm->getMaxLogQ();
n = parm->getRingDim();
}
return 2 * n;
}

DistributionType getDistType() const {
constexpr DistributionType getDistType() const {
return distType;
}
uint32_t getRingDim() const {
constexpr uint32_t getRingDim() const {
return ringDim;
}
SecurityLevel getMinSecLev() const {
constexpr SecurityLevel getMinSecLev() const {
return minSecLev;
}
uint32_t getMaxLogQ() const {
constexpr uint32_t getMaxLogQ() const {
return maxLogQ;
}
};

// Anonymous namespace gives internal linkage (one copy per TU, like static).
// StdLatticeParm is complete here so std::vector<StdLatticeParm> can be initialized.
namespace {
constexpr auto StandardLatticeParmSets = std::to_array<StdLatticeParm>({
StdLatticeParm(HEStd_uniform, 1024, HEStd_128_classic, 29),
StdLatticeParm(HEStd_uniform, 1024, HEStd_192_classic, 21),
StdLatticeParm(HEStd_uniform, 1024, HEStd_256_classic, 16),
StdLatticeParm(HEStd_uniform, 2048, HEStd_128_classic, 56),
StdLatticeParm(HEStd_uniform, 2048, HEStd_192_classic, 39),
StdLatticeParm(HEStd_uniform, 2048, HEStd_256_classic, 31),
StdLatticeParm(HEStd_uniform, 4096, HEStd_128_classic, 111),
StdLatticeParm(HEStd_uniform, 4096, HEStd_192_classic, 77),
StdLatticeParm(HEStd_uniform, 4096, HEStd_256_classic, 60),
StdLatticeParm(HEStd_uniform, 8192, HEStd_128_classic, 220),
StdLatticeParm(HEStd_uniform, 8192, HEStd_192_classic, 154),
StdLatticeParm(HEStd_uniform, 8192, HEStd_256_classic, 120),
StdLatticeParm(HEStd_uniform, 16384, HEStd_128_classic, 440),
StdLatticeParm(HEStd_uniform, 16384, HEStd_192_classic, 307),
StdLatticeParm(HEStd_uniform, 16384, HEStd_256_classic, 239),
StdLatticeParm(HEStd_uniform, 32768, HEStd_128_classic, 880),
StdLatticeParm(HEStd_uniform, 32768, HEStd_192_classic, 612),
StdLatticeParm(HEStd_uniform, 32768, HEStd_256_classic, 478),

StdLatticeParm(HEStd_error, 1024, HEStd_128_classic, 29),
StdLatticeParm(HEStd_error, 1024, HEStd_192_classic, 21),
StdLatticeParm(HEStd_error, 1024, HEStd_256_classic, 16),
StdLatticeParm(HEStd_error, 2048, HEStd_128_classic, 56),
StdLatticeParm(HEStd_error, 2048, HEStd_192_classic, 39),
StdLatticeParm(HEStd_error, 2048, HEStd_256_classic, 31),
StdLatticeParm(HEStd_error, 4096, HEStd_128_classic, 111),
StdLatticeParm(HEStd_error, 4096, HEStd_192_classic, 77),
StdLatticeParm(HEStd_error, 4096, HEStd_256_classic, 60),
StdLatticeParm(HEStd_error, 8192, HEStd_128_classic, 220),
StdLatticeParm(HEStd_error, 8192, HEStd_192_classic, 154),
StdLatticeParm(HEStd_error, 8192, HEStd_256_classic, 120),
StdLatticeParm(HEStd_error, 16384, HEStd_128_classic, 440),
StdLatticeParm(HEStd_error, 16384, HEStd_192_classic, 307),
StdLatticeParm(HEStd_error, 16384, HEStd_256_classic, 239),
StdLatticeParm(HEStd_error, 32768, HEStd_128_classic, 883),
StdLatticeParm(HEStd_error, 32768, HEStd_192_classic, 613),
StdLatticeParm(HEStd_error, 32768, HEStd_256_classic, 478),
StdLatticeParm(HEStd_error, 65536, HEStd_128_classic, 1749),
StdLatticeParm(HEStd_error, 65536, HEStd_192_classic, 1201),
StdLatticeParm(HEStd_error, 65536, HEStd_256_classic, 931),
StdLatticeParm(HEStd_error, 131072, HEStd_128_classic, 3525),
StdLatticeParm(HEStd_error, 131072, HEStd_192_classic, 2413),
StdLatticeParm(HEStd_error, 131072, HEStd_256_classic, 1868),

StdLatticeParm(HEStd_ternary, 1024, HEStd_128_classic, 27),
StdLatticeParm(HEStd_ternary, 1024, HEStd_192_classic, 19),
StdLatticeParm(HEStd_ternary, 1024, HEStd_256_classic, 14),
StdLatticeParm(HEStd_ternary, 2048, HEStd_128_classic, 54),
StdLatticeParm(HEStd_ternary, 2048, HEStd_192_classic, 37),
StdLatticeParm(HEStd_ternary, 2048, HEStd_256_classic, 29),
StdLatticeParm(HEStd_ternary, 4096, HEStd_128_classic, 109),
StdLatticeParm(HEStd_ternary, 4096, HEStd_192_classic, 75),
StdLatticeParm(HEStd_ternary, 4096, HEStd_256_classic, 58),
StdLatticeParm(HEStd_ternary, 8192, HEStd_128_classic, 218),
StdLatticeParm(HEStd_ternary, 8192, HEStd_192_classic, 152),
StdLatticeParm(HEStd_ternary, 8192, HEStd_256_classic, 118),
StdLatticeParm(HEStd_ternary, 16384, HEStd_128_classic, 438),
StdLatticeParm(HEStd_ternary, 16384, HEStd_192_classic, 305),
StdLatticeParm(HEStd_ternary, 16384, HEStd_256_classic, 237),
StdLatticeParm(HEStd_ternary, 32768, HEStd_128_classic, 881),
StdLatticeParm(HEStd_ternary, 32768, HEStd_192_classic, 611),
StdLatticeParm(HEStd_ternary, 32768, HEStd_256_classic, 476),
StdLatticeParm(HEStd_ternary, 65536, HEStd_128_classic, 1747),
StdLatticeParm(HEStd_ternary, 65536, HEStd_192_classic, 1199),
StdLatticeParm(HEStd_ternary, 65536, HEStd_256_classic, 929),
StdLatticeParm(HEStd_ternary, 131072, HEStd_128_classic, 3523),
StdLatticeParm(HEStd_ternary, 131072, HEStd_192_classic, 2411),
StdLatticeParm(HEStd_ternary, 131072, HEStd_256_classic, 1866),

StdLatticeParm(HEStd_uniform, 1024, HEStd_128_quantum, 27),
StdLatticeParm(HEStd_uniform, 1024, HEStd_192_quantum, 19),
StdLatticeParm(HEStd_uniform, 1024, HEStd_256_quantum, 15),
StdLatticeParm(HEStd_uniform, 2048, HEStd_128_quantum, 53),
StdLatticeParm(HEStd_uniform, 2048, HEStd_192_quantum, 37),
StdLatticeParm(HEStd_uniform, 2048, HEStd_256_quantum, 29),
StdLatticeParm(HEStd_uniform, 4096, HEStd_128_quantum, 103),
StdLatticeParm(HEStd_uniform, 4096, HEStd_192_quantum, 72),
StdLatticeParm(HEStd_uniform, 4096, HEStd_256_quantum, 56),
StdLatticeParm(HEStd_uniform, 8192, HEStd_128_quantum, 206),
StdLatticeParm(HEStd_uniform, 8192, HEStd_192_quantum, 143),
StdLatticeParm(HEStd_uniform, 8192, HEStd_256_quantum, 111),
StdLatticeParm(HEStd_uniform, 16384, HEStd_128_quantum, 413),
StdLatticeParm(HEStd_uniform, 16384, HEStd_192_quantum, 286),
StdLatticeParm(HEStd_uniform, 16384, HEStd_256_quantum, 222),
StdLatticeParm(HEStd_uniform, 32768, HEStd_128_quantum, 829),
StdLatticeParm(HEStd_uniform, 32768, HEStd_192_quantum, 573),
StdLatticeParm(HEStd_uniform, 32768, HEStd_256_quantum, 445),

StdLatticeParm(HEStd_error, 1024, HEStd_128_quantum, 27),
StdLatticeParm(HEStd_error, 1024, HEStd_192_quantum, 19),
StdLatticeParm(HEStd_error, 1024, HEStd_256_quantum, 15),
StdLatticeParm(HEStd_error, 2048, HEStd_128_quantum, 53),
StdLatticeParm(HEStd_error, 2048, HEStd_192_quantum, 37),
StdLatticeParm(HEStd_error, 2048, HEStd_256_quantum, 29),
StdLatticeParm(HEStd_error, 4096, HEStd_128_quantum, 103),
StdLatticeParm(HEStd_error, 4096, HEStd_192_quantum, 72),
StdLatticeParm(HEStd_error, 4096, HEStd_256_quantum, 56),
StdLatticeParm(HEStd_error, 8192, HEStd_128_quantum, 206),
StdLatticeParm(HEStd_error, 8192, HEStd_192_quantum, 143),
StdLatticeParm(HEStd_error, 8192, HEStd_256_quantum, 111),
StdLatticeParm(HEStd_error, 16384, HEStd_128_quantum, 413),
StdLatticeParm(HEStd_error, 16384, HEStd_192_quantum, 286),
StdLatticeParm(HEStd_error, 16384, HEStd_256_quantum, 222),
StdLatticeParm(HEStd_error, 32768, HEStd_128_quantum, 829),
StdLatticeParm(HEStd_error, 32768, HEStd_192_quantum, 573),
StdLatticeParm(HEStd_error, 32768, HEStd_256_quantum, 445),
StdLatticeParm(HEStd_error, 65536, HEStd_128_quantum, 1665),
StdLatticeParm(HEStd_error, 65536, HEStd_192_quantum, 1147),
StdLatticeParm(HEStd_error, 65536, HEStd_256_quantum, 890),
StdLatticeParm(HEStd_error, 131072, HEStd_128_quantum, 3351),
StdLatticeParm(HEStd_error, 131072, HEStd_192_quantum, 2304),
StdLatticeParm(HEStd_error, 131072, HEStd_256_quantum, 1786),

StdLatticeParm(HEStd_ternary, 1024, HEStd_128_quantum, 25),
StdLatticeParm(HEStd_ternary, 1024, HEStd_192_quantum, 17),
StdLatticeParm(HEStd_ternary, 1024, HEStd_256_quantum, 13),
StdLatticeParm(HEStd_ternary, 2048, HEStd_128_quantum, 51),
StdLatticeParm(HEStd_ternary, 2048, HEStd_192_quantum, 35),
StdLatticeParm(HEStd_ternary, 2048, HEStd_256_quantum, 27),
StdLatticeParm(HEStd_ternary, 4096, HEStd_128_quantum, 101),
StdLatticeParm(HEStd_ternary, 4096, HEStd_192_quantum, 70),
StdLatticeParm(HEStd_ternary, 4096, HEStd_256_quantum, 54),
StdLatticeParm(HEStd_ternary, 8192, HEStd_128_quantum, 202),
StdLatticeParm(HEStd_ternary, 8192, HEStd_192_quantum, 141),
StdLatticeParm(HEStd_ternary, 8192, HEStd_256_quantum, 109),
StdLatticeParm(HEStd_ternary, 16384, HEStd_128_quantum, 411),
StdLatticeParm(HEStd_ternary, 16384, HEStd_192_quantum, 284),
StdLatticeParm(HEStd_ternary, 16384, HEStd_256_quantum, 220),
StdLatticeParm(HEStd_ternary, 32768, HEStd_128_quantum, 827),
StdLatticeParm(HEStd_ternary, 32768, HEStd_192_quantum, 571),
StdLatticeParm(HEStd_ternary, 32768, HEStd_256_quantum, 443),
StdLatticeParm(HEStd_ternary, 65536, HEStd_128_quantum, 1663),
StdLatticeParm(HEStd_ternary, 65536, HEStd_192_quantum, 1145),
StdLatticeParm(HEStd_ternary, 65536, HEStd_256_quantum, 888),
StdLatticeParm(HEStd_ternary, 131072, HEStd_128_quantum, 3348),
StdLatticeParm(HEStd_ternary, 131072, HEStd_192_quantum, 2301),
StdLatticeParm(HEStd_ternary, 131072, HEStd_256_quantum, 1784),
});
} // anonymous namespace

// Out-of-class definition placed here so it can see StandardLatticeParmSets above.
inline void StdLatticeParm::initializeLookups() {
for (const StdLatticeParm& s : StandardLatticeParmSets) {
byRing[static_cast<int>(s.distType)][static_cast<int>(s.minSecLev)][s.ringDim] = &s;
byLogQ[static_cast<int>(s.distType)][static_cast<int>(s.minSecLev)][s.maxLogQ] = &s;
}
initialized = true;
}

} /* namespace lbcrypto */

#endif
Loading
Loading