diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..418705c --- /dev/null +++ b/.clang-format @@ -0,0 +1,138 @@ +--- +Language: Cpp +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Latest +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +--- +Language: Json +BasedOnStyle: LLVM +... diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..5f8379e --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,86 @@ + +--- +Checks: '-*, + bugprone-*, + -bugprone-easily-swappable-parameters, + -bugprone-implicit-widening-of-multiplication-result, + performance-*, + -performance-unnecessary-value-param, + ccpcoreguidelines-*, + misc-static-assert, + misc-throw-by-value-catch-by-reference, + misc-unconventional-assign-operator, + misc-definitions-in-headers, + misc-misplaced-const, + misc-no-recursion, + misc-non-copyable-objects, + misc-redundant-expression, + misc-non-private-member-variables-in-classes, + modernize-*, + -modernize-use-nodiscard, + -modernize-use-trailing-return-type, + -modernize-raw-string-literal, + readability-*, + -readability-convert-member-functions-to-static, + -readability-suspicious-call-argument, + -readability-function-cognitive-complexity, + -readability-identifier-naming, + -readability-implicit-bool-conversion, + -readability-identifier-length, + -readability-magic-numbers, + -readability-braces-around-statements, + -readability-uppercase-literal-suffix, + -readability-isolate-declaration, + -readability-avoid-const-params-in-decls' +WarningsAsErrors: '*' + +CheckOptions: + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.ClassMemberCase + value: lower_case + - key: readability-identifier-naming.ConstexprVariableCase + value: UPPER_CASE + - key: readability-identifier-naming.EnumCase + value: CamelCase + - key: readability-identifier-naming.EnumConstantCase + value: aNy_CasE + - key: readability-identifier-naming.FunctionCase + value: camelBack + - key: readability-identifier-naming.GlobalConstantCase + value: UPPER_CASE + - key: readability-identifier-naming.StaticConstantCase + value: UPPER_CASE + - key: readability-identifier-naming.StaticVariableCase + value: lower_case + - key: readability-identifier-naming.MacroDefinitionCase + value: UPPER_CASE + - key: readability-identifier-naming.MacroDefinitionIgnoredRegexp + value: '^[A-Z]+(_[A-Z]+)*_$' + - key: readability-identifier-naming.MemberCase + value: lower_case + - key: readability-identifier-naming.PrivateMemberCase + value: lower_case + - key: readability-identifier-naming.PrivateMemberSuffix + value: _ + - key: readability-identifier-naming.PublicMemberSuffix + value: '' + - key: readability-identifier-naming.NamespaceCase + value: aNy_CasE + - key: readability-identifier-naming.ParameterCase + value: lower_case + - key: readability-identifier-naming.TypeAliasCase + value: CamelCase + - key: readability-identifier-naming.TypedefCase + value: CamelCase + - key: readability-identifier-naming.VariableCase + value: lower_case + - key: readability-identifier-naming.IgnoreMainLikeFunctions + value: 1 + - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: 1 + +HeaderFilterRegex: 'deb/(benchmark|include|src|test)' +AnalyzeTemporaryDtors: false +FormatStyle: file +... diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..492008e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,94 @@ +# ~~~ +# Copyright 2025 CryptoLab, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ~~~ + +name: main + +on: + push: + branches: + - main + pull_request: + +concurrency: + group: ${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - name: Install pre-commit + run: | + pip install --upgrade pip + pip install pre-commit + + - uses: actions/checkout@v4 + with: + # Include previous commit + fetch-depth: 2 + + - name: Select target SHA to compare and fetch if required + run: | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + TARGET_SHA=${{ github.event.pull_request.base.sha }} + # Additionally, as checkout action does not fetch the target PR, we do. + git fetch --no-tags --prune --depth=1 origin $TARGET_SHA + else + TARGET_SHA=$( git rev-parse HEAD^ ) + fi + echo "TARGET_SHA=$TARGET_SHA" >> $GITHUB_ENV + + - name: Generate compile commands + shell: bash -l {0} + run: cmake --preset ci + + - name: Build for generated headers + shell: bash -l {0} + run: cmake --build --preset ci + + - name: Run pre-commit for commit and push stages. + shell: bash -l {0} + run: pre-commit install && pre-commit run -s $TARGET_SHA -o HEAD --hook-stage commit --hook-stage push + + build-and-test: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + include: + - os: ubuntu-latest + preset: ci + - os: macos-latest + preset: ci-mac + + steps: + - uses: actions/checkout@v3 + + - name: Configure CMake + run: cmake --preset ${{ matrix.preset }} + + - name: Build + run: cmake --build --preset ${{ matrix.preset }} + + - name: Test operations + run: ctest --preset all-test --output-on-failure + + - name: Test Custom Params + run: | + rm -rf build/CMakeCache.txt + cmake --preset ${{ matrix.preset }}-custom-param + cmake --build --preset ${{ matrix.preset }}-custom-param + ctest --preset all-test --output-on-failure diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d0190e --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +Doxyfile +build/ +include/generated/** +install/ +cmake/launch-cxx +cmake/launch-cuda +.vscode +*.egg-info +*.whl +.cache/ +.compdb/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..68e1d7e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,23 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +fail_fast: false +default_install_hook_types: [pre-push, pre-commit] +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + args: [--allow-multiple-documents] # for .clang-format + - id: check-added-large-files +- repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v14.0.5 + hooks: + - id: clang-format + files: ^(src|include|prebuild|test)/ + exclude: ^external/ # exclude json.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0435c42..93ffde0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,9 @@ add_dependencies(${PROJECT_NAME}_obj generate_flatbuffers set_my_project_warnings(${PROJECT_NAME}_obj) set_property(TARGET ${PROJECT_NAME}_obj PROPERTY POSITION_INDEPENDENT_CODE ON) -target_compile_options(${PROJECT_NAME}_obj PUBLIC -Wno-pedantic) +if(NOT MSVC) + target_compile_options(${PROJECT_NAME}_obj PRIVATE -Wno-pedantic) +endif() target_link_libraries( ${PROJECT_NAME}_obj PRIVATE $ diff --git a/CMakePresets.json b/CMakePresets.json index edf7f56..5c5e59f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -19,6 +19,48 @@ "CMAKE_BUILD_TYPE": "Release" } }, + { + "name": "ci", + "inherits": "release", + "installDir": "${sourceDir}/build/install", + "cacheVariables": { + "DEB_BUILD_TEST": "ON", + "DEB_BUILD_BENCHMARK": "ON", + "DEB_BUILD_WITH_OMP": "ON" + } + }, + { + "name": "ci-mac", + "inherits": "ci", + "cacheVariables": { + "DEB_BUILD_WITH_OMP": "OFF" + } + }, + { + "name": "ci-custom-param", + "inherits": "ci", + "cacheVariables": { + "DEB_PARAMETER_JSON": "${sourceDir}/prebuild/DebCustomParamPreset.json" + } + }, + { + "name": "ci-mac-custom-param", + "inherits": "ci-mac", + "cacheVariables": { + "DEB_PARAMETER_JSON": "${sourceDir}/prebuild/DebCustomParamPreset.json" + } + }, + { + "name": "clang-ci", + "inherits": "ci", + "cacheVariables": { + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_C_COMPILER": "clang", + "DEB_BUILD_TEST": "ON", + "DEB_BUILD_BENCHMARK": "ON", + "DEB_BUILD_WITH_OMP": "ON" + } + }, { "name": "benchmark", "inherits": "release", @@ -39,6 +81,36 @@ "name": "release", "configurePreset": "release", "configuration": "release" + }, + { + "name": "ci", + "configurePreset": "ci", + "configuration": "release", + "jobs": 4 + }, + { + "name": "ci-mac", + "configurePreset": "ci-mac", + "configuration": "release", + "jobs": 4 + }, + { + "name": "ci-custom-param", + "configurePreset": "ci-custom-param", + "configuration": "release", + "jobs": 4 + }, + { + "name": "ci-mac-custom-param", + "configurePreset": "ci-mac-custom-param", + "configuration": "release", + "jobs": 4 + }, + { + "name": "clang-ci", + "configurePreset": "clang-ci", + "configuration": "release", + "jobs": 4 } ], "testPresets": [ @@ -58,7 +130,7 @@ { "name": "all-test", "inherits": "test-base", - "configurePreset": "release", + "configurePreset": "ci", "configuration": "release" } ] diff --git a/README.md b/README.md index 8e41512..a462130 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ ![DEB LOGO](https://files.slack.com/files-pri/TQZR8FFK4-F0A1JC6NBDW/gemini_generated_image_m8vwx5m8vwx5m8vw.png?pub_secret=0baa8f9dd6) *Logo created with [nanobanana](https://github.com/CryptoLabInc/nanobanana)* -DEB is a homomorphic encryption, decryption, and key generation library implementing the CKKS scheme. +DEB is a homomorphic encryption, decryption, and key generation library implementing the CKKS scheme. ## Features - Secret-key generation and management - Encryption and decryption operations -- Evaluation(public)-key generation and management +- Evaluation(public)-key generation and management - Serialization support for encrypted objects and keys ## Build @@ -81,7 +81,7 @@ The `examples/` directory contains sample programs demonstrating various feature ./build/examples/EnDecryption ``` -- **EnDecryption-MultiSecret.cpp**: Demonstrates encryption and decryption with multi-secret parameter +- **EnDecryption-MultiSecret.cpp**: Demonstrates encryption and decryption with multi-secret parameter ```sh ./build/examples/EnDecryption-MultiSecret ``` diff --git a/include/generated/DebFBType.h b/include/generated/DebFBType.h deleted file mode 100644 index e7702b4..0000000 --- a/include/generated/DebFBType.h +++ /dev/null @@ -1,1048 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - - -#ifndef FLATBUFFERS_GENERATED_DEBFBTYPE_DEB_FB_H_ -#define FLATBUFFERS_GENERATED_DEBFBTYPE_DEB_FB_H_ - -#include "flatbuffers/flatbuffers.h" - -// Ensure the included flatbuffers.h is the same version as when this file was -// generated, otherwise it may not be compatible. -static_assert(FLATBUFFERS_VERSION_MAJOR == 25 && - FLATBUFFERS_VERSION_MINOR == 2 && - FLATBUFFERS_VERSION_REVISION == 10, - "Non-compatible flatbuffers version included"); - -namespace deb_fb { - -struct Complex; - -struct Complex32; - -struct Message; -struct MessageBuilder; - -struct Message32; -struct Message32Builder; - -struct Coeff; -struct CoeffBuilder; - -struct Coeff32; -struct Coeff32Builder; - -struct PolyUnit; -struct PolyUnitBuilder; - -struct Poly; -struct PolyBuilder; - -struct Cipher; -struct CipherBuilder; - -struct Sk; -struct SkBuilder; - -struct Swk; -struct SwkBuilder; - -struct Deb; -struct DebBuilder; - -enum DebUnion : uint8_t { - DebUnion_NONE = 0, - DebUnion_Swk = 1, - DebUnion_Sk = 2, - DebUnion_Cipher = 3, - DebUnion_Poly = 4, - DebUnion_PolyUnit = 5, - DebUnion_Message = 6, - DebUnion_Message32 = 7, - DebUnion_Coeff = 8, - DebUnion_Coeff32 = 9, - DebUnion_MIN = DebUnion_NONE, - DebUnion_MAX = DebUnion_Coeff32 -}; - -inline const DebUnion (&EnumValuesDebUnion())[10] { - static const DebUnion values[] = { - DebUnion_NONE, - DebUnion_Swk, - DebUnion_Sk, - DebUnion_Cipher, - DebUnion_Poly, - DebUnion_PolyUnit, - DebUnion_Message, - DebUnion_Message32, - DebUnion_Coeff, - DebUnion_Coeff32 - }; - return values; -} - -inline const char * const *EnumNamesDebUnion() { - static const char * const names[11] = { - "NONE", - "Swk", - "Sk", - "Cipher", - "Poly", - "PolyUnit", - "Message", - "Message32", - "Coeff", - "Coeff32", - nullptr - }; - return names; -} - -inline const char *EnumNameDebUnion(DebUnion e) { - if (::flatbuffers::IsOutRange(e, DebUnion_NONE, DebUnion_Coeff32)) return ""; - const size_t index = static_cast(e); - return EnumNamesDebUnion()[index]; -} - -template struct DebUnionTraits { - static const DebUnion enum_value = DebUnion_NONE; -}; - -template<> struct DebUnionTraits { - static const DebUnion enum_value = DebUnion_Swk; -}; - -template<> struct DebUnionTraits { - static const DebUnion enum_value = DebUnion_Sk; -}; - -template<> struct DebUnionTraits { - static const DebUnion enum_value = DebUnion_Cipher; -}; - -template<> struct DebUnionTraits { - static const DebUnion enum_value = DebUnion_Poly; -}; - -template<> struct DebUnionTraits { - static const DebUnion enum_value = DebUnion_PolyUnit; -}; - -template<> struct DebUnionTraits { - static const DebUnion enum_value = DebUnion_Message; -}; - -template<> struct DebUnionTraits { - static const DebUnion enum_value = DebUnion_Message32; -}; - -template<> struct DebUnionTraits { - static const DebUnion enum_value = DebUnion_Coeff; -}; - -template<> struct DebUnionTraits { - static const DebUnion enum_value = DebUnion_Coeff32; -}; - -bool VerifyDebUnion(::flatbuffers::Verifier &verifier, const void *obj, DebUnion type); -bool VerifyDebUnionVector(::flatbuffers::Verifier &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset> *values, const ::flatbuffers::Vector *types); - -FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Complex FLATBUFFERS_FINAL_CLASS { - private: - double real_; - double imag_; - - public: - Complex() - : real_(0), - imag_(0) { - } - Complex(double _real, double _imag) - : real_(::flatbuffers::EndianScalar(_real)), - imag_(::flatbuffers::EndianScalar(_imag)) { - } - double real() const { - return ::flatbuffers::EndianScalar(real_); - } - double imag() const { - return ::flatbuffers::EndianScalar(imag_); - } -}; -FLATBUFFERS_STRUCT_END(Complex, 16); - -FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Complex32 FLATBUFFERS_FINAL_CLASS { - private: - float real_; - float imag_; - - public: - Complex32() - : real_(0), - imag_(0) { - } - Complex32(float _real, float _imag) - : real_(::flatbuffers::EndianScalar(_real)), - imag_(::flatbuffers::EndianScalar(_imag)) { - } - float real() const { - return ::flatbuffers::EndianScalar(real_); - } - float imag() const { - return ::flatbuffers::EndianScalar(imag_); - } -}; -FLATBUFFERS_STRUCT_END(Complex32, 8); - -struct Message FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef MessageBuilder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_SIZE = 4, - VT_DATA = 6 - }; - uint32_t size() const { - return GetField(VT_SIZE, 0); - } - const ::flatbuffers::Vector *data() const { - return GetPointer *>(VT_DATA); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_SIZE, 4) && - VerifyOffset(verifier, VT_DATA) && - verifier.VerifyVector(data()) && - verifier.EndTable(); - } -}; - -struct MessageBuilder { - typedef Message Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_size(uint32_t size) { - fbb_.AddElement(Message::VT_SIZE, size, 0); - } - void add_data(::flatbuffers::Offset<::flatbuffers::Vector> data) { - fbb_.AddOffset(Message::VT_DATA, data); - } - explicit MessageBuilder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreateMessage( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t size = 0, - ::flatbuffers::Offset<::flatbuffers::Vector> data = 0) { - MessageBuilder builder_(_fbb); - builder_.add_data(data); - builder_.add_size(size); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreateMessageDirect( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t size = 0, - const std::vector *data = nullptr) { - auto data__ = data ? _fbb.CreateVectorOfStructs(*data) : 0; - return deb_fb::CreateMessage( - _fbb, - size, - data__); -} - -struct Message32 FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef Message32Builder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_SIZE = 4, - VT_DATA = 6 - }; - uint32_t size() const { - return GetField(VT_SIZE, 0); - } - const ::flatbuffers::Vector *data() const { - return GetPointer *>(VT_DATA); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_SIZE, 4) && - VerifyOffset(verifier, VT_DATA) && - verifier.VerifyVector(data()) && - verifier.EndTable(); - } -}; - -struct Message32Builder { - typedef Message32 Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_size(uint32_t size) { - fbb_.AddElement(Message32::VT_SIZE, size, 0); - } - void add_data(::flatbuffers::Offset<::flatbuffers::Vector> data) { - fbb_.AddOffset(Message32::VT_DATA, data); - } - explicit Message32Builder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreateMessage32( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t size = 0, - ::flatbuffers::Offset<::flatbuffers::Vector> data = 0) { - Message32Builder builder_(_fbb); - builder_.add_data(data); - builder_.add_size(size); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreateMessage32Direct( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t size = 0, - const std::vector *data = nullptr) { - auto data__ = data ? _fbb.CreateVectorOfStructs(*data) : 0; - return deb_fb::CreateMessage32( - _fbb, - size, - data__); -} - -struct Coeff FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef CoeffBuilder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_SIZE = 4, - VT_DATA = 6 - }; - uint32_t size() const { - return GetField(VT_SIZE, 0); - } - const ::flatbuffers::Vector *data() const { - return GetPointer *>(VT_DATA); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_SIZE, 4) && - VerifyOffset(verifier, VT_DATA) && - verifier.VerifyVector(data()) && - verifier.EndTable(); - } -}; - -struct CoeffBuilder { - typedef Coeff Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_size(uint32_t size) { - fbb_.AddElement(Coeff::VT_SIZE, size, 0); - } - void add_data(::flatbuffers::Offset<::flatbuffers::Vector> data) { - fbb_.AddOffset(Coeff::VT_DATA, data); - } - explicit CoeffBuilder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreateCoeff( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t size = 0, - ::flatbuffers::Offset<::flatbuffers::Vector> data = 0) { - CoeffBuilder builder_(_fbb); - builder_.add_data(data); - builder_.add_size(size); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreateCoeffDirect( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t size = 0, - const std::vector *data = nullptr) { - auto data__ = data ? _fbb.CreateVector(*data) : 0; - return deb_fb::CreateCoeff( - _fbb, - size, - data__); -} - -struct Coeff32 FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef Coeff32Builder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_SIZE = 4, - VT_DATA = 6 - }; - uint32_t size() const { - return GetField(VT_SIZE, 0); - } - const ::flatbuffers::Vector *data() const { - return GetPointer *>(VT_DATA); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_SIZE, 4) && - VerifyOffset(verifier, VT_DATA) && - verifier.VerifyVector(data()) && - verifier.EndTable(); - } -}; - -struct Coeff32Builder { - typedef Coeff32 Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_size(uint32_t size) { - fbb_.AddElement(Coeff32::VT_SIZE, size, 0); - } - void add_data(::flatbuffers::Offset<::flatbuffers::Vector> data) { - fbb_.AddOffset(Coeff32::VT_DATA, data); - } - explicit Coeff32Builder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreateCoeff32( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t size = 0, - ::flatbuffers::Offset<::flatbuffers::Vector> data = 0) { - Coeff32Builder builder_(_fbb); - builder_.add_data(data); - builder_.add_size(size); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreateCoeff32Direct( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t size = 0, - const std::vector *data = nullptr) { - auto data__ = data ? _fbb.CreateVector(*data) : 0; - return deb_fb::CreateCoeff32( - _fbb, - size, - data__); -} - -struct PolyUnit FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef PolyUnitBuilder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_PRIME = 4, - VT_DEGREE = 6, - VT_NTT_STATE = 8, - VT_ARRAY = 10 - }; - uint64_t prime() const { - return GetField(VT_PRIME, 0); - } - uint32_t degree() const { - return GetField(VT_DEGREE, 0); - } - bool ntt_state() const { - return GetField(VT_NTT_STATE, 0) != 0; - } - const ::flatbuffers::Vector *array() const { - return GetPointer *>(VT_ARRAY); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_PRIME, 8) && - VerifyField(verifier, VT_DEGREE, 4) && - VerifyField(verifier, VT_NTT_STATE, 1) && - VerifyOffset(verifier, VT_ARRAY) && - verifier.VerifyVector(array()) && - verifier.EndTable(); - } -}; - -struct PolyUnitBuilder { - typedef PolyUnit Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_prime(uint64_t prime) { - fbb_.AddElement(PolyUnit::VT_PRIME, prime, 0); - } - void add_degree(uint32_t degree) { - fbb_.AddElement(PolyUnit::VT_DEGREE, degree, 0); - } - void add_ntt_state(bool ntt_state) { - fbb_.AddElement(PolyUnit::VT_NTT_STATE, static_cast(ntt_state), 0); - } - void add_array(::flatbuffers::Offset<::flatbuffers::Vector> array) { - fbb_.AddOffset(PolyUnit::VT_ARRAY, array); - } - explicit PolyUnitBuilder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreatePolyUnit( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint64_t prime = 0, - uint32_t degree = 0, - bool ntt_state = false, - ::flatbuffers::Offset<::flatbuffers::Vector> array = 0) { - PolyUnitBuilder builder_(_fbb); - builder_.add_prime(prime); - builder_.add_array(array); - builder_.add_degree(degree); - builder_.add_ntt_state(ntt_state); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreatePolyUnitDirect( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint64_t prime = 0, - uint32_t degree = 0, - bool ntt_state = false, - const std::vector *array = nullptr) { - auto array__ = array ? _fbb.CreateVector(*array) : 0; - return deb_fb::CreatePolyUnit( - _fbb, - prime, - degree, - ntt_state, - array__); -} - -struct Poly FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef PolyBuilder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_SIZE = 4, - VT_RNSPOLYS = 6 - }; - uint32_t size() const { - return GetField(VT_SIZE, 0); - } - const ::flatbuffers::Vector<::flatbuffers::Offset> *rnspolys() const { - return GetPointer> *>(VT_RNSPOLYS); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_SIZE, 4) && - VerifyOffset(verifier, VT_RNSPOLYS) && - verifier.VerifyVector(rnspolys()) && - verifier.VerifyVectorOfTables(rnspolys()) && - verifier.EndTable(); - } -}; - -struct PolyBuilder { - typedef Poly Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_size(uint32_t size) { - fbb_.AddElement(Poly::VT_SIZE, size, 0); - } - void add_rnspolys(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> rnspolys) { - fbb_.AddOffset(Poly::VT_RNSPOLYS, rnspolys); - } - explicit PolyBuilder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreatePoly( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t size = 0, - ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> rnspolys = 0) { - PolyBuilder builder_(_fbb); - builder_.add_rnspolys(rnspolys); - builder_.add_size(size); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreatePolyDirect( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t size = 0, - const std::vector<::flatbuffers::Offset> *rnspolys = nullptr) { - auto rnspolys__ = rnspolys ? _fbb.CreateVector<::flatbuffers::Offset>(*rnspolys) : 0; - return deb_fb::CreatePoly( - _fbb, - size, - rnspolys__); -} - -struct Cipher FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef CipherBuilder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_PRESET = 4, - VT_ENCODING = 6, - VT_SIZE = 8, - VT_BIGPOLYS = 10 - }; - uint32_t preset() const { - return GetField(VT_PRESET, 0); - } - uint32_t encoding() const { - return GetField(VT_ENCODING, 0); - } - uint32_t size() const { - return GetField(VT_SIZE, 0); - } - const ::flatbuffers::Vector<::flatbuffers::Offset> *bigpolys() const { - return GetPointer> *>(VT_BIGPOLYS); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_PRESET, 4) && - VerifyField(verifier, VT_ENCODING, 4) && - VerifyField(verifier, VT_SIZE, 4) && - VerifyOffset(verifier, VT_BIGPOLYS) && - verifier.VerifyVector(bigpolys()) && - verifier.VerifyVectorOfTables(bigpolys()) && - verifier.EndTable(); - } -}; - -struct CipherBuilder { - typedef Cipher Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_preset(uint32_t preset) { - fbb_.AddElement(Cipher::VT_PRESET, preset, 0); - } - void add_encoding(uint32_t encoding) { - fbb_.AddElement(Cipher::VT_ENCODING, encoding, 0); - } - void add_size(uint32_t size) { - fbb_.AddElement(Cipher::VT_SIZE, size, 0); - } - void add_bigpolys(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> bigpolys) { - fbb_.AddOffset(Cipher::VT_BIGPOLYS, bigpolys); - } - explicit CipherBuilder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreateCipher( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t preset = 0, - uint32_t encoding = 0, - uint32_t size = 0, - ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> bigpolys = 0) { - CipherBuilder builder_(_fbb); - builder_.add_bigpolys(bigpolys); - builder_.add_size(size); - builder_.add_encoding(encoding); - builder_.add_preset(preset); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreateCipherDirect( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t preset = 0, - uint32_t encoding = 0, - uint32_t size = 0, - const std::vector<::flatbuffers::Offset> *bigpolys = nullptr) { - auto bigpolys__ = bigpolys ? _fbb.CreateVector<::flatbuffers::Offset>(*bigpolys) : 0; - return deb_fb::CreateCipher( - _fbb, - preset, - encoding, - size, - bigpolys__); -} - -struct Sk FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef SkBuilder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_PRESET = 4, - VT_SEEDS = 6, - VT_COEFFS = 8, - VT_BIGPOLYS = 10 - }; - uint32_t preset() const { - return GetField(VT_PRESET, 0); - } - const ::flatbuffers::Vector *seeds() const { - return GetPointer *>(VT_SEEDS); - } - const ::flatbuffers::Vector *coeffs() const { - return GetPointer *>(VT_COEFFS); - } - const ::flatbuffers::Vector<::flatbuffers::Offset> *bigpolys() const { - return GetPointer> *>(VT_BIGPOLYS); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_PRESET, 4) && - VerifyOffset(verifier, VT_SEEDS) && - verifier.VerifyVector(seeds()) && - VerifyOffset(verifier, VT_COEFFS) && - verifier.VerifyVector(coeffs()) && - VerifyOffset(verifier, VT_BIGPOLYS) && - verifier.VerifyVector(bigpolys()) && - verifier.VerifyVectorOfTables(bigpolys()) && - verifier.EndTable(); - } -}; - -struct SkBuilder { - typedef Sk Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_preset(uint32_t preset) { - fbb_.AddElement(Sk::VT_PRESET, preset, 0); - } - void add_seeds(::flatbuffers::Offset<::flatbuffers::Vector> seeds) { - fbb_.AddOffset(Sk::VT_SEEDS, seeds); - } - void add_coeffs(::flatbuffers::Offset<::flatbuffers::Vector> coeffs) { - fbb_.AddOffset(Sk::VT_COEFFS, coeffs); - } - void add_bigpolys(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> bigpolys) { - fbb_.AddOffset(Sk::VT_BIGPOLYS, bigpolys); - } - explicit SkBuilder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreateSk( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t preset = 0, - ::flatbuffers::Offset<::flatbuffers::Vector> seeds = 0, - ::flatbuffers::Offset<::flatbuffers::Vector> coeffs = 0, - ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> bigpolys = 0) { - SkBuilder builder_(_fbb); - builder_.add_bigpolys(bigpolys); - builder_.add_coeffs(coeffs); - builder_.add_seeds(seeds); - builder_.add_preset(preset); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreateSkDirect( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t preset = 0, - const std::vector *seeds = nullptr, - const std::vector *coeffs = nullptr, - const std::vector<::flatbuffers::Offset> *bigpolys = nullptr) { - auto seeds__ = seeds ? _fbb.CreateVector(*seeds) : 0; - auto coeffs__ = coeffs ? _fbb.CreateVector(*coeffs) : 0; - auto bigpolys__ = bigpolys ? _fbb.CreateVector<::flatbuffers::Offset>(*bigpolys) : 0; - return deb_fb::CreateSk( - _fbb, - preset, - seeds__, - coeffs__, - bigpolys__); -} - -struct Swk FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef SwkBuilder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_PRESET = 4, - VT_TYPE = 6, - VT_ROT_IDX = 8, - VT_DNUM = 10, - VT_AX = 12, - VT_BX = 14 - }; - uint32_t preset() const { - return GetField(VT_PRESET, 0); - } - uint32_t type() const { - return GetField(VT_TYPE, 0); - } - uint32_t rot_idx() const { - return GetField(VT_ROT_IDX, 0); - } - uint32_t dnum() const { - return GetField(VT_DNUM, 0); - } - const ::flatbuffers::Vector<::flatbuffers::Offset> *ax() const { - return GetPointer> *>(VT_AX); - } - const ::flatbuffers::Vector<::flatbuffers::Offset> *bx() const { - return GetPointer> *>(VT_BX); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_PRESET, 4) && - VerifyField(verifier, VT_TYPE, 4) && - VerifyField(verifier, VT_ROT_IDX, 4) && - VerifyField(verifier, VT_DNUM, 4) && - VerifyOffset(verifier, VT_AX) && - verifier.VerifyVector(ax()) && - verifier.VerifyVectorOfTables(ax()) && - VerifyOffset(verifier, VT_BX) && - verifier.VerifyVector(bx()) && - verifier.VerifyVectorOfTables(bx()) && - verifier.EndTable(); - } -}; - -struct SwkBuilder { - typedef Swk Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_preset(uint32_t preset) { - fbb_.AddElement(Swk::VT_PRESET, preset, 0); - } - void add_type(uint32_t type) { - fbb_.AddElement(Swk::VT_TYPE, type, 0); - } - void add_rot_idx(uint32_t rot_idx) { - fbb_.AddElement(Swk::VT_ROT_IDX, rot_idx, 0); - } - void add_dnum(uint32_t dnum) { - fbb_.AddElement(Swk::VT_DNUM, dnum, 0); - } - void add_ax(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> ax) { - fbb_.AddOffset(Swk::VT_AX, ax); - } - void add_bx(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> bx) { - fbb_.AddOffset(Swk::VT_BX, bx); - } - explicit SwkBuilder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreateSwk( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t preset = 0, - uint32_t type = 0, - uint32_t rot_idx = 0, - uint32_t dnum = 0, - ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> ax = 0, - ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> bx = 0) { - SwkBuilder builder_(_fbb); - builder_.add_bx(bx); - builder_.add_ax(ax); - builder_.add_dnum(dnum); - builder_.add_rot_idx(rot_idx); - builder_.add_type(type); - builder_.add_preset(preset); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreateSwkDirect( - ::flatbuffers::FlatBufferBuilder &_fbb, - uint32_t preset = 0, - uint32_t type = 0, - uint32_t rot_idx = 0, - uint32_t dnum = 0, - const std::vector<::flatbuffers::Offset> *ax = nullptr, - const std::vector<::flatbuffers::Offset> *bx = nullptr) { - auto ax__ = ax ? _fbb.CreateVector<::flatbuffers::Offset>(*ax) : 0; - auto bx__ = bx ? _fbb.CreateVector<::flatbuffers::Offset>(*bx) : 0; - return deb_fb::CreateSwk( - _fbb, - preset, - type, - rot_idx, - dnum, - ax__, - bx__); -} - -struct Deb FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef DebBuilder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_LIST_TYPE = 4, - VT_LIST = 6 - }; - const ::flatbuffers::Vector *list_type() const { - return GetPointer *>(VT_LIST_TYPE); - } - const ::flatbuffers::Vector<::flatbuffers::Offset> *list() const { - return GetPointer> *>(VT_LIST); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyOffset(verifier, VT_LIST_TYPE) && - verifier.VerifyVector(list_type()) && - VerifyOffset(verifier, VT_LIST) && - verifier.VerifyVector(list()) && - VerifyDebUnionVector(verifier, list(), list_type()) && - verifier.EndTable(); - } -}; - -struct DebBuilder { - typedef Deb Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_list_type(::flatbuffers::Offset<::flatbuffers::Vector> list_type) { - fbb_.AddOffset(Deb::VT_LIST_TYPE, list_type); - } - void add_list(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> list) { - fbb_.AddOffset(Deb::VT_LIST, list); - } - explicit DebBuilder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreateDeb( - ::flatbuffers::FlatBufferBuilder &_fbb, - ::flatbuffers::Offset<::flatbuffers::Vector> list_type = 0, - ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> list = 0) { - DebBuilder builder_(_fbb); - builder_.add_list(list); - builder_.add_list_type(list_type); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreateDebDirect( - ::flatbuffers::FlatBufferBuilder &_fbb, - const std::vector *list_type = nullptr, - const std::vector<::flatbuffers::Offset> *list = nullptr) { - auto list_type__ = list_type ? _fbb.CreateVector(*list_type) : 0; - auto list__ = list ? _fbb.CreateVector<::flatbuffers::Offset>(*list) : 0; - return deb_fb::CreateDeb( - _fbb, - list_type__, - list__); -} - -inline bool VerifyDebUnion(::flatbuffers::Verifier &verifier, const void *obj, DebUnion type) { - switch (type) { - case DebUnion_NONE: { - return true; - } - case DebUnion_Swk: { - auto ptr = reinterpret_cast(obj); - return verifier.VerifyTable(ptr); - } - case DebUnion_Sk: { - auto ptr = reinterpret_cast(obj); - return verifier.VerifyTable(ptr); - } - case DebUnion_Cipher: { - auto ptr = reinterpret_cast(obj); - return verifier.VerifyTable(ptr); - } - case DebUnion_Poly: { - auto ptr = reinterpret_cast(obj); - return verifier.VerifyTable(ptr); - } - case DebUnion_PolyUnit: { - auto ptr = reinterpret_cast(obj); - return verifier.VerifyTable(ptr); - } - case DebUnion_Message: { - auto ptr = reinterpret_cast(obj); - return verifier.VerifyTable(ptr); - } - case DebUnion_Message32: { - auto ptr = reinterpret_cast(obj); - return verifier.VerifyTable(ptr); - } - case DebUnion_Coeff: { - auto ptr = reinterpret_cast(obj); - return verifier.VerifyTable(ptr); - } - case DebUnion_Coeff32: { - auto ptr = reinterpret_cast(obj); - return verifier.VerifyTable(ptr); - } - default: return true; - } -} - -inline bool VerifyDebUnionVector(::flatbuffers::Verifier &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset> *values, const ::flatbuffers::Vector *types) { - if (!values || !types) return !values && !types; - if (values->size() != types->size()) return false; - for (::flatbuffers::uoffset_t i = 0; i < values->size(); ++i) { - if (!VerifyDebUnion( - verifier, values->Get(i), types->GetEnum(i))) { - return false; - } - } - return true; -} - -inline const deb_fb::Deb *GetDeb(const void *buf) { - return ::flatbuffers::GetRoot(buf); -} - -inline const deb_fb::Deb *GetSizePrefixedDeb(const void *buf) { - return ::flatbuffers::GetSizePrefixedRoot(buf); -} - -inline bool VerifyDebBuffer( - ::flatbuffers::Verifier &verifier) { - return verifier.VerifyBuffer(nullptr); -} - -inline bool VerifySizePrefixedDebBuffer( - ::flatbuffers::Verifier &verifier) { - return verifier.VerifySizePrefixedBuffer(nullptr); -} - -inline void FinishDebBuffer( - ::flatbuffers::FlatBufferBuilder &fbb, - ::flatbuffers::Offset root) { - fbb.Finish(root); -} - -inline void FinishSizePrefixedDebBuffer( - ::flatbuffers::FlatBufferBuilder &fbb, - ::flatbuffers::Offset root) { - fbb.FinishSizePrefixed(root); -} - -} // namespace deb_fb - -#endif // FLATBUFFERS_GENERATED_DEBFBTYPE_DEB_FB_H_ diff --git a/include/generated/DebParam.hpp b/include/generated/DebParam.hpp deleted file mode 100644 index a570dd3..0000000 --- a/include/generated/DebParam.hpp +++ /dev/null @@ -1,237 +0,0 @@ -// Auto-generated by DebGenParam.cpp — DO NOT EDIT -#pragma once - -#include -#include -#include -#include -#include - -#include "Types.hpp" -#define PRESET_LIST X(FGb) X(FGbD12L0) X(FGbMS) -namespace deb { - -enum Preset { - PRESET_FGb, - PRESET_FGbD12L0, - PRESET_FGbMS, - PRESET_EMPTY -}; - -struct FGb { -inline static constexpr Preset preset = PRESET_FGb; -inline static constexpr Preset parent = PRESET_FGb; -inline static constexpr const char* preset_name = "FGb"; -inline static constexpr Size rank = 1; -inline static constexpr Size num_secret = 1; -inline static constexpr Size log_degree = 16; -inline static constexpr Size degree = 65536; -inline static constexpr Size num_slots = 32768; -inline static constexpr Size gadget_rank = 5; -inline static constexpr Size num_base = 1; -inline static constexpr Size num_qp = 24; -inline static constexpr Size num_tp = 5; -inline static constexpr Size num_p = 30; -inline static constexpr Size encryption_level = 12; -inline static constexpr Size hamming_weight = 192; -inline static constexpr Real gaussian_error_stdev = 3.2; -inline static constexpr u64 primes[] = { - UINT64_C(288230376147386369), // 0 - UINT64_C(4398044938241), // 1 - UINT64_C(4398043496449), // 2 - UINT64_C(4398042972161), // 3 - UINT64_C(4398042185729), // 4 - UINT64_C(4398034845697), // 5 - UINT64_C(4398029340673), // 6 - UINT64_C(4398028029953), // 7 - UINT64_C(4398021869569), // 8 - UINT64_C(4398021476353), // 9 - UINT64_C(4398021345281), // 10 - UINT64_C(4398018723841), // 11 - UINT64_C(4398018592769), // 12 - UINT64_C(288230376115535873), // 13 - UINT64_C(288230376138735617), // 14 - UINT64_C(288230376135196673), // 15 - UINT64_C(288230376132182017), // 16 - UINT64_C(288230376131788801), // 17 - UINT64_C(288230376129691649), // 18 - UINT64_C(288230376128643073), // 19 - UINT64_C(288230376126545921), // 20 - UINT64_C(288230376122613761), // 21 - UINT64_C(288230376121434113), // 22 - UINT64_C(288230376121040897), // 23 - UINT64_C(288230376118026241), // 24 - UINT64_C(576460752300015617), // 25 - UINT64_C(576460752298835969), // 26 - UINT64_C(576460752298180609), // 27 - UINT64_C(1152921504606584833), // 28 - UINT64_C(1152921504598720513), // 29 -}; -inline static constexpr Real scale_factors[] = { - 42.038389957315403, // 0 - 42.019194720683842, // 1 - 42.009596865891794, // 2 - 42.004797852504382, // 3 - 42.002398216823572, // 4 - 42.001197195102421, // 5 - 42.00059578132997, // 6 - 42.00029485946456, // 7 - 42.000143388128826, // 8 - 42.000067587967102, // 9 - 42.000029666388286, // 10 - 42.00001027563966, // 11 - 42.000000558767383, // 12 - 0, // 13 - 0, // 14 - 0, // 15 - 0, // 16 - 0, // 17 - 0, // 18 - 0, // 19 - 0, // 20 - 0, // 21 - 0, // 22 - 0, // 23 - 0, // 24 - 0, // 25 - 0, // 26 - 0, // 27 - 0, // 28 - 0, // 29 -}; -}; - -struct FGbD12L0 { -inline static constexpr Preset preset = PRESET_FGbD12L0; -inline static constexpr Preset parent = PRESET_FGb; -inline static constexpr const char* preset_name = "FGbD12L0"; -inline static constexpr Size rank = 1; -inline static constexpr Size num_secret = 1; -inline static constexpr Size log_degree = 12; -inline static constexpr Size degree = 4096; -inline static constexpr Size num_slots = 2048; -inline static constexpr Size gadget_rank = 1; -inline static constexpr Size num_base = 1; -inline static constexpr Size num_qp = 0; -inline static constexpr Size num_tp = 1; -inline static constexpr Size num_p = 2; -inline static constexpr Size encryption_level = 0; -inline static constexpr Size hamming_weight = 2730; -inline static constexpr Real gaussian_error_stdev = 3.2; -inline static constexpr u64 primes[] = { - UINT64_C(288230376147386369), // 0 - UINT64_C(2251799810670593), // 1 -}; -inline static constexpr Real scale_factors[] = { - 0, // 0 - 0, // 1 -}; -}; - -struct FGbMS { -inline static constexpr Preset preset = PRESET_FGbMS; -inline static constexpr Preset parent = PRESET_FGb; -inline static constexpr const char* preset_name = "FGbMS"; -inline static constexpr Size rank = 1; -inline static constexpr Size num_secret = 4; -inline static constexpr Size log_degree = 16; -inline static constexpr Size degree = 65536; -inline static constexpr Size num_slots = 32768; -inline static constexpr Size gadget_rank = 5; -inline static constexpr Size num_base = 1; -inline static constexpr Size num_qp = 24; -inline static constexpr Size num_tp = 5; -inline static constexpr Size num_p = 30; -inline static constexpr Size encryption_level = 12; -inline static constexpr Size hamming_weight = 192; -inline static constexpr Real gaussian_error_stdev = 3.2; -inline static constexpr u64 primes[] = { - UINT64_C(288230376147386369), // 0 - UINT64_C(4398044938241), // 1 - UINT64_C(4398043496449), // 2 - UINT64_C(4398042972161), // 3 - UINT64_C(4398042185729), // 4 - UINT64_C(4398034845697), // 5 - UINT64_C(4398029340673), // 6 - UINT64_C(4398028029953), // 7 - UINT64_C(4398021869569), // 8 - UINT64_C(4398021476353), // 9 - UINT64_C(4398021345281), // 10 - UINT64_C(4398018723841), // 11 - UINT64_C(4398018592769), // 12 - UINT64_C(288230376115535873), // 13 - UINT64_C(288230376138735617), // 14 - UINT64_C(288230376135196673), // 15 - UINT64_C(288230376132182017), // 16 - UINT64_C(288230376131788801), // 17 - UINT64_C(288230376129691649), // 18 - UINT64_C(288230376128643073), // 19 - UINT64_C(288230376126545921), // 20 - UINT64_C(288230376122613761), // 21 - UINT64_C(288230376121434113), // 22 - UINT64_C(288230376121040897), // 23 - UINT64_C(288230376118026241), // 24 - UINT64_C(576460752300015617), // 25 - UINT64_C(576460752298835969), // 26 - UINT64_C(576460752298180609), // 27 - UINT64_C(1152921504606584833), // 28 - UINT64_C(1152921504598720513), // 29 -}; -inline static constexpr Real scale_factors[] = { - 42.038389957315403, // 0 - 42.019194720683842, // 1 - 42.009596865891794, // 2 - 42.004797852504382, // 3 - 42.002398216823572, // 4 - 42.001197195102421, // 5 - 42.00059578132997, // 6 - 42.00029485946456, // 7 - 42.000143388128826, // 8 - 42.000067587967102, // 9 - 42.000029666388286, // 10 - 42.00001027563966, // 11 - 42.000000558767383, // 12 - 0, // 13 - 0, // 14 - 0, // 15 - 0, // 16 - 0, // 17 - 0, // 18 - 0, // 19 - 0, // 20 - 0, // 21 - 0, // 22 - 0, // 23 - 0, // 24 - 0, // 25 - 0, // 26 - 0, // 27 - 0, // 28 - 0, // 29 -}; -}; - -struct EMPTY { -inline static constexpr Preset preset = PRESET_EMPTY; -inline static constexpr Preset parent = PRESET_EMPTY; -inline static constexpr const char* preset_name = "EMPTY"; -inline static constexpr Size rank = 1; -inline static constexpr Size num_secret = 1; -inline static constexpr Size log_degree = 0; -inline static constexpr Size degree = 1; -inline static constexpr Size num_slots = 0; -inline static constexpr Size gadget_rank = 1; -inline static constexpr Size num_base = 1; -inline static constexpr Size num_qp = 0; -inline static constexpr Size num_tp = 0; -inline static constexpr Size num_p = 1; -inline static constexpr Size encryption_level = 0; -inline static constexpr Size hamming_weight = 0; -inline static constexpr Real gaussian_error_stdev = 3.2; -inline static constexpr u64 primes[] = { -}; -inline static constexpr Real scale_factors[] = { -}; -}; - -} // namespace deb diff --git a/prebuild/DebPreComputeUtils.hpp b/prebuild/DebPreComputeUtils.hpp index 70431fe..49b68cf 100644 --- a/prebuild/DebPreComputeUtils.hpp +++ b/prebuild/DebPreComputeUtils.hpp @@ -548,6 +548,8 @@ static void write_header(const std::string &out_path, }; FinalPreset empty_preset; empty_preset.NAME = empty_preset.PARENT = "EMPTY"; + empty_preset.PRIMES = {2}; + empty_preset.SCALE_FACTORS = {1}; std::vector finals_copy = finals; finals_copy.push_back(std::move(empty_preset)); for (const auto &p : finals_copy) { diff --git a/test/KeyGen-test.cpp b/test/KeyGen-test.cpp index 46e24d2..5184343 100644 --- a/test/KeyGen-test.cpp +++ b/test/KeyGen-test.cpp @@ -84,7 +84,7 @@ TEST_P(KeyGen, GenConjugationKey) { TEST_P(KeyGen, GenRotationKeys) { const Size num_slots = context->get_num_slots(); - const Size rot = rand() % (num_slots - 1) + 1; + const Size rot = dist_u64(gen) % (num_slots - 1) + 1; const RNGSeed seed = SeedGenerator::Gen(); KeyGenerator keygen_same1(sk, seed); @@ -118,7 +118,7 @@ TEST_P(KeyGen, GenRotationKeys) { } TEST_P(KeyGen, GenAutomorphismKey) { - const Size sig = rand() % (degree - 1) + 1; + const Size sig = dist_u64(gen) % (degree - 1) + 1; SwitchKey autokey(context, SwitchKeyKind::SWK_AUTO); ASSERT_NO_THROW(autokey = keygen.genAutoKey(sig)); ASSERT_NO_THROW(keygen.genAutoKeyInplace(sig, autokey)); @@ -141,7 +141,8 @@ TEST_P(KeyGen, GenModPackKeySelf) { GTEST_SKIP() << "MODPACK_SELF key generation is only for single secret."; } - const Size pad_rank = 1U << (rand() % (context->get_log_degree() / 2)); + const Size pad_rank = 1U + << (dist_u64(gen) % (context->get_log_degree() / 2)); SwitchKey modevikey(context, SwitchKeyKind::SWK_MODPACK_SELF); ASSERT_NO_THROW(modevikey = keygen.genModPackKeyBundle(pad_rank)); ASSERT_NO_THROW(keygen.genModPackKeyBundleInplace(pad_rank, modevikey)); diff --git a/test/NTT-test.cpp b/test/NTT-test.cpp index 6ce8085..762bd2e 100644 --- a/test/NTT-test.cpp +++ b/test/NTT-test.cpp @@ -17,6 +17,7 @@ #include "utils/Basic.hpp" #include "utils/NTT.hpp" +#include #include #include @@ -24,26 +25,24 @@ using namespace deb; using namespace std; -namespace { -void getRandomU64RangeIter(Size range, u64 *begin, const u64 *end) { - for (u64 *it = begin; it != end; ++it) { - *it = static_cast(rand()) % range; - } -} -} // namespace - class NttTest : public ::testing::TestWithParam> { public: const u64 degree{get<0>(GetParam())}; const u64 prime{get<1>(GetParam())}; - auto getRandomVector(Size size = 0) const { + std::random_device rd; + std::mt19937 gen{rd()}; + std::uniform_int_distribution dist{0, UINT64_MAX}; + + inline auto getRandomVector(Size size = 0) { if (size == 0) size = degree; // std::vector v(size); auto *v = static_cast( ::operator new[](sizeof(u64) * size, std::align_val_t(256))); - getRandomU64RangeIter(prime, v, v + size); + for (u64 *it = v; it != v + size; ++it) { + *it = dist(gen) % prime; + } return v; } }; diff --git a/test/Serialize-test.cpp b/test/Serialize-test.cpp index 2e8130e..39bde28 100644 --- a/test/Serialize-test.cpp +++ b/test/Serialize-test.cpp @@ -156,28 +156,27 @@ TEST_P(Serialize, SecretKeySerializationTest) { } TEST_P(Serialize, SwkSerializationTest) { - SwitchKey swk(context, static_cast(rand() % 7), rand() % 10); - const auto num_pieces = rand() % 10 + 1; - for (Size i = 0; i < num_pieces; ++i) { - swk.addAx(2, 2); - swk.addBx(2, 2); - for (Size j = 0; j < 2; ++j) { - for (Size k = 0; k < 2; ++k) { - for (Size d = 0; d < degree; ++d) { - swk.ax(j)[k][d] = rand(); - swk.bx(j)[k][d] = rand(); - } + const SwitchKeyKind kind = SWK_ROT; + SwitchKey swk(context, kind, dist_u64(gen) % ((degree >> 1) - 1) + 1); + + for (Size i = 0; i < swk.axSize(); ++i) { + for (Size j = 0; j < swk.ax(i).size(); ++j) { + for (Size d = 0; d < degree; ++d) { + swk.ax(i)[j][d] = dist_u64(gen); + swk.bx(i)[j][d] = dist_u64(gen); } } } + std::ostringstream os; serializeToStream(swk, os); std::istringstream is(os.str()); - SwitchKey deserialized_swk(context, SWK_CONJ); + SwitchKey deserialized_swk(context, kind); deserializeFromStream(is, deserialized_swk); EXPECT_EQ(swk.preset(), deserialized_swk.preset()); EXPECT_EQ(swk.type(), deserialized_swk.type()); + EXPECT_EQ(swk.rotIdx(), deserialized_swk.rotIdx()); EXPECT_EQ(swk.dnum(), deserialized_swk.dnum()); EXPECT_EQ(swk.axSize(), deserialized_swk.axSize()); EXPECT_EQ(swk.bxSize(), deserialized_swk.bxSize()); diff --git a/test/TestBase.hpp b/test/TestBase.hpp index 9edad77..b2bf629 100644 --- a/test/TestBase.hpp +++ b/test/TestBase.hpp @@ -56,6 +56,7 @@ class DebTestBase : public ::testing::TestWithParam { std::random_device rd; std::mt19937 gen{rd()}; std::uniform_real_distribution dist{-1.0, 1.0}; + std::uniform_int_distribution dist_u64{0, UINT64_MAX}; // Adjusted error tolerances based on bitwidth of the first prime // 60 bit prime -> sk_err = 2^-28, enc_err = 2^-15 // 50 bit prime -> sk_err = 2^-26.3, enc_err = 2^-13.3