├── cmake-build-debug
├── .cmake
│ └── api
│ │ └── v1
│ │ └── query
│ │ ├── cache-v2
│ │ ├── cmakeFiles-v1
│ │ ├── codemodel-v2
│ │ └── toolchains-v1
└── CMakeFiles
│ ├── cmake.check_cache
│ ├── 3.27.8
│ ├── CompilerIdC
│ │ └── a.exe
│ ├── CompilerIdCXX
│ │ └── a.exe
│ ├── CMakeSystem.cmake
│ ├── CMakeCCompiler.cmake
│ └── CMakeCXXCompiler.cmake
│ ├── clion-environment.txt
│ ├── clion-Debug-log.txt
│ └── CMakeConfigureLog.yaml
├── native
├── examples
│ ├── build
│ │ ├── CMakeFiles
│ │ │ ├── Progress
│ │ │ │ ├── 2
│ │ │ │ └── count.txt
│ │ │ ├── progress.marks
│ │ │ ├── 3.18.3
│ │ │ │ ├── CompilerIdCUDA
│ │ │ │ │ ├── tmp
│ │ │ │ │ │ ├── a_dlink.reg.c
│ │ │ │ │ │ ├── CMakeCUDACompilerId.module_id
│ │ │ │ │ │ ├── a_dlink.o
│ │ │ │ │ │ ├── a_dlink.fatbin
│ │ │ │ │ │ ├── CMakeCUDACompilerId.o
│ │ │ │ │ │ ├── a_dlink.sm_52.cubin
│ │ │ │ │ │ ├── CMakeCUDACompilerId.fatbin
│ │ │ │ │ │ ├── CMakeCUDACompilerId.sm_52.cubin
│ │ │ │ │ │ ├── CMakeCUDACompilerId.ptx
│ │ │ │ │ │ ├── CMakeCUDACompilerId.cudafe1.gpu
│ │ │ │ │ │ ├── CMakeCUDACompilerId.cudafe1.stub.c
│ │ │ │ │ │ ├── CMakeCUDACompilerId.cudafe1.c
│ │ │ │ │ │ ├── CMakeCUDACompilerId.fatbin.c
│ │ │ │ │ │ └── a_dlink.fatbin.c
│ │ │ │ │ └── a.out
│ │ │ │ ├── CompilerIdCXX
│ │ │ │ │ └── a.out
│ │ │ │ ├── CMakeDetermineCompilerABI_CUDA.bin
│ │ │ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ │ │ ├── CMakeSystem.cmake
│ │ │ │ └── CMakeCUDACompiler.cmake
│ │ │ ├── sealexamples.dir
│ │ │ │ ├── progress.make
│ │ │ │ ├── 2_encoders.cpp.o
│ │ │ │ ├── link.txt
│ │ │ │ ├── flags.make
│ │ │ │ ├── cmake_clean.cmake
│ │ │ │ ├── DependInfo.cmake
│ │ │ │ ├── depend.internal
│ │ │ │ └── build.make
│ │ │ ├── cmake.check_cache
│ │ │ ├── TargetDirectories.txt
│ │ │ ├── FindThreads
│ │ │ │ └── CheckForPthreads.cxx
│ │ │ ├── CMakeDirectoryInformation.cmake
│ │ │ ├── CMakeError.log
│ │ │ ├── Makefile.cmake
│ │ │ └── Makefile2
│ │ └── cmake_install.cmake
│ ├── CMakeLists.txt
│ └── examples.cpp
├── tests
│ ├── seal
│ │ ├── testrunner.cpp
│ │ ├── util
│ │ │ ├── CMakeLists.txt
│ │ │ ├── hash.cpp
│ │ │ ├── clipnormal.cpp
│ │ │ └── galois.cpp
│ │ ├── CMakeLists.txt
│ │ ├── randomtostd.cpp
│ │ ├── secretkey.cpp
│ │ ├── memorymanager.cpp
│ │ ├── publickey.cpp
│ │ └── batchencoder.cpp
│ └── CMakeLists.txt
├── src
│ └── seal
│ │ ├── util
│ │ ├── fips202.h
│ │ ├── cgmanifest.json
│ │ ├── iterator.cpp
│ │ ├── clipnormal.cpp
│ │ ├── hash.cpp
│ │ ├── croots.h
│ │ ├── common.cpp
│ │ ├── hash.h
│ │ ├── scalingvariant.h
│ │ ├── config.h.in
│ │ ├── common.cuh
│ │ ├── gpu_data.h
│ │ ├── croots.cpp
│ │ ├── clipnormal.h
│ │ ├── msvc.h
│ │ ├── ntt_helper.cuh
│ │ ├── globals.h
│ │ ├── helper.cu
│ │ ├── ztools.h
│ │ ├── clang.h
│ │ ├── uintcore.cpp
│ │ ├── gcc.h
│ │ ├── blake2-impl.h
│ │ ├── hestdparms.h
│ │ └── helper.cuh
│ │ ├── memorymanager.cpp
│ │ ├── seal.h
│ │ ├── version.h
│ │ ├── randomtostd.h
│ │ ├── galoiskeys.h
│ │ ├── CMakeLists.txt
│ │ ├── relinkeys.h
│ │ └── kswitchkeys.cpp
└── bench
│ ├── keygen.cpp
│ ├── CMakeLists.txt
│ └── ntt.cpp
├── image.png
├── .idea
├── misc.xml
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
├── .gitignore
└── modules.xml
├── pkgconfig
├── seal_msgsl.pc.in
├── seal_shared.pc.in
└── seal.pc.in
├── tools
└── Makefile
├── cmake
├── CheckMemset.cmake
├── ExternalMSGSL.cmake
├── ExternalGTest.cmake
├── CleanArtifacts.cmake
├── EnableCXXCompilerFlags.cmake
├── CheckCXXIntrinsicsHeader.cmake
├── ExternalIntelHEXL.cmake
├── ExternalZSTD.cmake
├── functions.iOS.cmake
├── ExternalZLIB.cmake
├── EnableCXX17.cmake
├── ExternalBenchmark.cmake
├── CheckCXXIntrinsicsSpecific.cmake
└── SEALMacros.cmake
├── LICENSE
├── README.md
├── Dockerfile
├── NOTICE
└── .clang-format
/cmake-build-debug/.cmake/api/v1/query/cache-v2:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/Progress/2:
--------------------------------------------------------------------------------
1 | empty
--------------------------------------------------------------------------------
/cmake-build-debug/.cmake/api/v1/query/cmakeFiles-v1:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/cmake-build-debug/.cmake/api/v1/query/codemodel-v2:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/cmake-build-debug/.cmake/api/v1/query/toolchains-v1:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/progress.marks:
--------------------------------------------------------------------------------
1 | 2
2 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/Progress/count.txt:
--------------------------------------------------------------------------------
1 | 2
2 |
--------------------------------------------------------------------------------
/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/image.png
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/a_dlink.reg.c:
--------------------------------------------------------------------------------
1 | #define NUM_PRELINKED_OBJECTS 0
2 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/sealexamples.dir/progress.make:
--------------------------------------------------------------------------------
1 | CMAKE_PROGRESS_1 = 1
2 | CMAKE_PROGRESS_2 = 2
3 |
4 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.module_id:
--------------------------------------------------------------------------------
1 | _84c43d9c_22_CMakeCUDACompilerId_cu_bd57c623
--------------------------------------------------------------------------------
/cmake-build-debug/CMakeFiles/cmake.check_cache:
--------------------------------------------------------------------------------
1 | # This file is generated by cmake for dependency checking of the CMakeCache.txt file
2 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/cmake.check_cache:
--------------------------------------------------------------------------------
1 | # This file is generated by cmake for dependency checking of the CMakeCache.txt file
2 |
--------------------------------------------------------------------------------
/cmake-build-debug/CMakeFiles/3.27.8/CompilerIdC/a.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/cmake-build-debug/CMakeFiles/3.27.8/CompilerIdC/a.exe
--------------------------------------------------------------------------------
/cmake-build-debug/CMakeFiles/3.27.8/CompilerIdCXX/a.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/cmake-build-debug/CMakeFiles/3.27.8/CompilerIdCXX/a.exe
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/a.out
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCXX/a.out:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/3.18.3/CompilerIdCXX/a.out
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/sealexamples.dir/2_encoders.cpp.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/sealexamples.dir/2_encoders.cpp.o
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/a_dlink.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/a_dlink.o
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/sealexamples.dir/link.txt:
--------------------------------------------------------------------------------
1 | /usr/bin/c++ -static CMakeFiles/sealexamples.dir/2_encoders.cpp.o -o bin/sealexamples /usr/local/lib/libseal-4.1.a -pthread
2 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CMakeDetermineCompilerABI_CUDA.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/3.18.3/CMakeDetermineCompilerABI_CUDA.bin
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CMakeDetermineCompilerABI_CXX.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/3.18.3/CMakeDetermineCompilerABI_CXX.bin
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/a_dlink.fatbin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/a_dlink.fatbin
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.o
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/a_dlink.sm_52.cubin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/a_dlink.sm_52.cubin
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.fatbin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.fatbin
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.sm_52.cubin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rayman96/CAT/HEAD/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.sm_52.cubin
--------------------------------------------------------------------------------
/cmake-build-debug/CMakeFiles/clion-environment.txt:
--------------------------------------------------------------------------------
1 | ToolSet: 11.0 w64 (local)@C:\Program Files\JetBrains\CLion 2023.3.4\bin\mingw
2 | Options:
3 |
4 | Options:-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2023.3.4/bin/ninja/win/x64/ninja.exe
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/TargetDirectories.txt:
--------------------------------------------------------------------------------
1 | /home/liqirui/SEAL/native/examples/build/CMakeFiles/rebuild_cache.dir
2 | /home/liqirui/SEAL/native/examples/build/CMakeFiles/edit_cache.dir
3 | /home/liqirui/SEAL/native/examples/build/CMakeFiles/sealexamples.dir
4 |
--------------------------------------------------------------------------------
/pkgconfig/seal_msgsl.pc.in:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | Name: Microsoft GSL for IDEA SEAL_GPU
5 | Version: @Microsoft.GSL_VERSION@
6 | Description: Guidelines Support Library
7 |
8 | Cflags: -I@SEAL_PKGCONFIG_MSGSL_INCLUDE_DIR@
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/sealexamples.dir/flags.make:
--------------------------------------------------------------------------------
1 | # CMAKE generated file: DO NOT EDIT!
2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.18
3 |
4 | # compile CXX with /usr/bin/c++
5 | CXX_DEFINES =
6 |
7 | CXX_INCLUDES = -isystem /usr/local/include/SEAL-4.1
8 |
9 | CXX_FLAGS = -pthread -std=gnu++17
10 |
11 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.ptx:
--------------------------------------------------------------------------------
1 | //
2 | // Generated by NVIDIA NVVM Compiler
3 | //
4 | // Compiler Build ID: CL-31294372
5 | // Cuda compilation tools, release 11.7, V11.7.64
6 | // Based on NVVM 7.0.1
7 | //
8 |
9 | .version 7.7
10 | .target sm_52
11 | .address_size 64
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/native/tests/seal/testrunner.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "gtest/gtest.h"
5 |
6 | /**
7 | Main entry point for Google Test unit tests.
8 | */
9 | int main(int argc, char **argv)
10 | {
11 | testing::InitGoogleTest(&argc, argv);
12 | return RUN_ALL_TESTS();
13 | }
14 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/sealexamples.dir/cmake_clean.cmake:
--------------------------------------------------------------------------------
1 | file(REMOVE_RECURSE
2 | "CMakeFiles/sealexamples.dir/2_encoders.cpp.o"
3 | "bin/sealexamples"
4 | "bin/sealexamples.pdb"
5 | )
6 |
7 | # Per-language clean rules from dependency scanning.
8 | foreach(lang CXX)
9 | include(CMakeFiles/sealexamples.dir/cmake_clean_${lang}.cmake OPTIONAL)
10 | endforeach()
11 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/FindThreads/CheckForPthreads.cxx:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void* start_routine(void* args)
4 | {
5 | return args;
6 | }
7 |
8 | int main(void)
9 | {
10 | /* This is a compile and link test, no code to actually run things. */
11 | pthread_t thread;
12 | pthread_create(&thread, 0, start_routine, 0);
13 | pthread_join(thread, 0);
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.cudafe1.gpu:
--------------------------------------------------------------------------------
1 | typedef char __nv_bool;
2 | # 216 "/usr/local/gcc-8.2/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include/stddef.h" 3
3 | typedef unsigned long size_t;
4 | #include "crt/device_runtime.h"
5 | # 238 "/usr/local/gcc-8.2/include/c++/8.2.0/x86_64-pc-linux-gnu/bits/c++config.h" 3
6 | typedef unsigned long _ZSt6size_t;
7 | #include "common_functions.h"
8 |
--------------------------------------------------------------------------------
/native/src/seal/util/fips202.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 |
9 | #if defined(__cplusplus)
10 | extern "C"
11 | {
12 | #endif
13 |
14 | void shake256(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen);
15 |
16 | #if defined(__cplusplus)
17 | }
18 | #endif
19 |
--------------------------------------------------------------------------------
/native/src/seal/memorymanager.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/memorymanager.h"
5 |
6 | using namespace std;
7 |
8 | namespace seal
9 | {
10 | #ifndef _M_CEE
11 | mutex MemoryManager::switch_mutex_;
12 | #else
13 | #pragma message("WARNING: MemoryManager compiled thread-unsafe and MMProfGuard disabled to support /clr")
14 | #endif
15 | } // namespace seal
16 |
--------------------------------------------------------------------------------
/tools/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | SHELL=/bin/bash
5 | COMPR_SYSTEM_INFO_ARCHIVE=../system_info.tar.gz
6 |
7 | .PHONY: system_info clean
8 |
9 | system_info: clean $(COMPR_SYSTEM_INFO_ARCHIVE)
10 |
11 | $(COMPR_SYSTEM_INFO_ARCHIVE): scripts/collect_system_info.sh
12 | @$(SHELL) scripts/collect_system_info.sh
13 |
14 | clean:
15 | @rm -f $(COMPR_SYSTEM_INFO_ARCHIVE)
16 |
--------------------------------------------------------------------------------
/cmake-build-debug/CMakeFiles/3.27.8/CMakeSystem.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_HOST_SYSTEM "Windows-10.0.22631")
2 | set(CMAKE_HOST_SYSTEM_NAME "Windows")
3 | set(CMAKE_HOST_SYSTEM_VERSION "10.0.22631")
4 | set(CMAKE_HOST_SYSTEM_PROCESSOR "AMD64")
5 |
6 |
7 |
8 | set(CMAKE_SYSTEM "Windows-10.0.22631")
9 | set(CMAKE_SYSTEM_NAME "Windows")
10 | set(CMAKE_SYSTEM_VERSION "10.0.22631")
11 | set(CMAKE_SYSTEM_PROCESSOR "AMD64")
12 |
13 | set(CMAKE_CROSSCOMPILING "FALSE")
14 |
15 | set(CMAKE_SYSTEM_LOADED 1)
16 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CMakeSystem.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_HOST_SYSTEM "Linux-5.4.0-42-generic")
2 | set(CMAKE_HOST_SYSTEM_NAME "Linux")
3 | set(CMAKE_HOST_SYSTEM_VERSION "5.4.0-42-generic")
4 | set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64")
5 |
6 |
7 |
8 | set(CMAKE_SYSTEM "Linux-5.4.0-42-generic")
9 | set(CMAKE_SYSTEM_NAME "Linux")
10 | set(CMAKE_SYSTEM_VERSION "5.4.0-42-generic")
11 | set(CMAKE_SYSTEM_PROCESSOR "x86_64")
12 |
13 | set(CMAKE_CROSSCOMPILING "FALSE")
14 |
15 | set(CMAKE_SYSTEM_LOADED 1)
16 |
--------------------------------------------------------------------------------
/cmake/CheckMemset.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | # Check for memset_s
5 | check_cxx_source_runs("
6 | #define __STDC_WANT_LIB_EXT1__ 1
7 | #include
8 | int main(void)
9 | {
10 | char str[] = \"ghghghghghghghghghghgh\";
11 | int r = memset_s(str, sizeof(str), 'a', 5);
12 | return r;
13 | }"
14 | SEAL_MEMSET_S_FOUND)
15 |
16 | # Check for explicit_bzero
17 | check_symbol_exists(explicit_bzero "string.h" SEAL_EXPLICIT_BZERO_FOUND)
18 |
19 | # Check for explicit_memset
20 | check_symbol_exists(explicit_memset "string.h" SEAL_EXPLICIT_MEMSET_FOUND)
21 |
--------------------------------------------------------------------------------
/native/src/seal/util/cgmanifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/component-detection-manifest.json",
3 | "Registrations": [
4 | {
5 | "component": {
6 | "type": "git",
7 | "git": {
8 | "repositoryUrl": "https://github.com/BLAKE2/BLAKE2",
9 | "commitHash": "997fa5ba1e14b52c554fb03ce39e579e6f27b90c"
10 | }
11 | }
12 | },
13 | {
14 | "component": {
15 | "type": "git",
16 | "git": {
17 | "repositoryUrl": "https://github.com/pq-crystals/kyber",
18 | "commitHash": "844057468e69527bd15b17fbe03f4b61f9a22065"
19 | }
20 | }
21 | }
22 | ]
23 | }
24 |
--------------------------------------------------------------------------------
/pkgconfig/seal_shared.pc.in:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | prefix=@CMAKE_INSTALL_PREFIX@
5 | libdir=${prefix}/lib
6 | includedir=${prefix}/@SEAL_INCLUDES_INSTALL_DIR@
7 |
8 | Name: IDEA SEAL_GPU
9 | Version: @SEAL_VERSION_MAJOR@.@SEAL_VERSION_MINOR@
10 | Description: An easy-to-use homomorphic encryption library
11 |
12 | Requires: @SEAL_PKGCONFIG_MSGSL_REQUIRES_STRING@
13 | Requires: @SEAL_PKGCONFIG_ZLIB_REQUIRES_STRING@
14 | Requires: @SEAL_PKGCONFIG_ZSTD_REQUIRES_STRING@
15 | Requires: @SEAL_PKGCONFIG_INTEL_HEXL_REQUIRES_STRING@
16 |
17 | Libs: -L${libdir} -lseal
18 | Cflags: @SEAL_LANG_FLAG@ -I${includedir}
19 |
--------------------------------------------------------------------------------
/pkgconfig/seal.pc.in:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | prefix=@CMAKE_INSTALL_PREFIX@
5 | libdir=${prefix}/lib
6 | includedir=${prefix}/@SEAL_INCLUDES_INSTALL_DIR@
7 |
8 | Name: IDEA SEAL_GPU
9 | Version: @SEAL_VERSION@
10 | Description: An easy-to-use homomorphic encryption library
11 |
12 | Requires: @SEAL_PKGCONFIG_MSGSL_REQUIRES_STRING@
13 | Requires: @SEAL_PKGCONFIG_ZLIB_REQUIRES_STRING@
14 | Requires: @SEAL_PKGCONFIG_ZSTD_REQUIRES_STRING@
15 | Requires: @SEAL_PKGCONFIG_INTEL_HEXL_REQUIRES_STRING@
16 |
17 | Libs: -L${libdir} -lseal-@SEAL_VERSION_MAJOR@.@SEAL_VERSION_MINOR@
18 | Cflags: @SEAL_LANG_FLAG@ -I${includedir}
19 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/CMakeDirectoryInformation.cmake:
--------------------------------------------------------------------------------
1 | # CMAKE generated file: DO NOT EDIT!
2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.18
3 |
4 | # Relative path conversion top directories.
5 | set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/liqirui/SEAL/native/examples")
6 | set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/liqirui/SEAL/native/examples/build")
7 |
8 | # Force unix paths in dependencies.
9 | set(CMAKE_FORCE_UNIX_PATHS 1)
10 |
11 |
12 | # The C and CXX include file regular expressions for this directory.
13 | set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$")
14 | set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$")
15 | set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})
16 | set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN})
17 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/sealexamples.dir/DependInfo.cmake:
--------------------------------------------------------------------------------
1 | # The set of languages for which implicit dependencies are needed:
2 | set(CMAKE_DEPENDS_LANGUAGES
3 | "CXX"
4 | )
5 | # The set of files for implicit dependencies of each language:
6 | set(CMAKE_DEPENDS_CHECK_CXX
7 | "/home/liqirui/SEAL/native/examples/2_encoders.cpp" "/home/liqirui/SEAL/native/examples/build/CMakeFiles/sealexamples.dir/2_encoders.cpp.o"
8 | )
9 | set(CMAKE_CXX_COMPILER_ID "GNU")
10 |
11 | # The include file search paths:
12 | set(CMAKE_CXX_TARGET_INCLUDE_PATH
13 | "/usr/local/include/SEAL-4.1"
14 | )
15 |
16 | # Targets to which this target links.
17 | set(CMAKE_TARGET_LINKED_INFO_FILES
18 | )
19 |
20 | # Fortran module output directory.
21 | set(CMAKE_Fortran_TARGET_MODULE_DIR "")
22 |
--------------------------------------------------------------------------------
/native/src/seal/util/iterator.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/ciphertext.cuh"
5 | #include "seal/util/iterator.h"
6 |
7 | namespace seal
8 | {
9 | namespace util
10 | {
11 | PolyIter::PolyIter(Ciphertext &ct) : self_type(ct.data(), ct.poly_modulus_degree(), ct.coeff_modulus_size())
12 | {}
13 |
14 | ConstPolyIter::ConstPolyIter(const Ciphertext &ct)
15 | : self_type(ct.data(), ct.poly_modulus_degree(), ct.coeff_modulus_size())
16 | {}
17 |
18 | ConstPolyIter::ConstPolyIter(Ciphertext &ct)
19 | : self_type(ct.data(), ct.poly_modulus_degree(), ct.coeff_modulus_size())
20 | {}
21 | } // namespace util
22 | } // namespace seal
23 |
--------------------------------------------------------------------------------
/cmake/ExternalMSGSL.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | FetchContent_Declare(
5 | msgsl
6 | GIT_REPOSITORY https://github.com/microsoft/GSL.git
7 | GIT_TAG a3534567187d2edc428efd3f13466ff75fe5805c # 4.0.0
8 | )
9 | FetchContent_GetProperties(msgsl)
10 |
11 | if(NOT msgsl_POPULATED)
12 | FetchContent_Populate(msgsl)
13 |
14 | set(GSL_CXX_STANDARD "14" CACHE STRING "" FORCE)
15 | set(GSL_TEST OFF CACHE BOOL "" FORCE)
16 | mark_as_advanced(GSL_CXX_STANDARD )
17 | mark_as_advanced(GSL_TEST)
18 | mark_as_advanced(FETCHCONTENT_SOURCE_DIR_MSGSL)
19 | mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_MSGSL)
20 |
21 | add_subdirectory(
22 | ${msgsl_SOURCE_DIR}
23 | ${msgsl_SOURCE_DIR}/../msgsl-build
24 | EXCLUDE_FROM_ALL)
25 | endif()
26 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.cudafe1.stub.c:
--------------------------------------------------------------------------------
1 | #pragma GCC diagnostic push
2 | #pragma GCC diagnostic ignored "-Wunused-function"
3 | #pragma GCC diagnostic ignored "-Wcast-qual"
4 | #define __NV_CUBIN_HANDLE_STORAGE__ static
5 | #if !defined(__CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__)
6 | #define __CUDA_INCLUDE_COMPILER_INTERNAL_HEADERS__
7 | #endif
8 | #include "crt/host_runtime.h"
9 | #include "CMakeCUDACompilerId.fatbin.c"
10 | static void __nv_cudaEntityRegisterCallback(void **);
11 | static void __sti____cudaRegisterAll(void) __attribute__((__constructor__));
12 | static void __nv_cudaEntityRegisterCallback(void **__T0){__nv_dummy_param_ref(__T0);__nv_save_fatbinhandle_for_managed_rt(__T0);}
13 | static void __sti____cudaRegisterAll(void){__cudaRegisterBinary(__nv_cudaEntityRegisterCallback);}
14 |
15 | #pragma GCC diagnostic pop
16 |
--------------------------------------------------------------------------------
/native/src/seal/seal.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #include "seal/batchencoder.h"
7 | #include "seal/ciphertext.cuh"
8 | #include "seal/ckks.h"
9 | #include "seal/context.cuh"
10 | #include "seal/decryptor.h"
11 | #include "seal/dynarray.h"
12 | #include "seal/encryptionparams.cuh"
13 | #include "seal/encryptor.h"
14 | #include "seal/evaluator.h"
15 | #include "seal/galoiskeys.h"
16 | #include "seal/keygenerator.h"
17 | #include "seal/memorymanager.h"
18 | #include "seal/modulus.h"
19 | #include "seal/plaintext.cuh"
20 | #include "seal/publickey.h"
21 | #include "seal/randomgen.h"
22 | #include "seal/randomtostd.h"
23 | #include "seal/relinkeys.h"
24 | #include "seal/secretkey.cuh"
25 | #include "seal/serializable.h"
26 | #include "seal/serialization.h"
27 | #include "seal/valcheck.h"
28 | #include "seal/version.h"
--------------------------------------------------------------------------------
/native/src/seal/util/clipnormal.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/util/clipnormal.h"
5 | #include
6 |
7 | using namespace std;
8 |
9 | namespace seal
10 | {
11 | namespace util
12 | {
13 | ClippedNormalDistribution::ClippedNormalDistribution(
14 | result_type mean, result_type standard_deviation, result_type max_deviation)
15 | : normal_(mean, standard_deviation), max_deviation_(max_deviation)
16 | {
17 | // Verify arguments.
18 | if (standard_deviation < 0)
19 | {
20 | throw invalid_argument("standard_deviation");
21 | }
22 | if (max_deviation < 0)
23 | {
24 | throw invalid_argument("max_deviation");
25 | }
26 | }
27 | } // namespace util
28 | } // namespace seal
29 |
--------------------------------------------------------------------------------
/cmake/ExternalGTest.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | FetchContent_Declare(
5 | googletest
6 | GIT_REPOSITORY https://github.com/google/googletest.git
7 | GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850 # 1.12.1
8 | )
9 | FetchContent_GetProperties(googletest)
10 |
11 | if(NOT googletest_POPULATED)
12 | FetchContent_Populate(googletest)
13 |
14 | set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
15 | set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
16 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
17 | mark_as_advanced(BUILD_GMOCK)
18 | mark_as_advanced(INSTALL_GTEST)
19 | mark_as_advanced(FETCHCONTENT_SOURCE_DIR_GOOGLETEST)
20 | mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_GOOGLETEST)
21 |
22 | add_subdirectory(
23 | ${googletest_SOURCE_DIR}
24 | ${THIRDPARTY_BINARY_DIR}/googletest-src
25 | EXCLUDE_FROM_ALL)
26 | endif()
27 |
--------------------------------------------------------------------------------
/cmake/CleanArtifacts.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | # Remove native/src/gsl directory which is no longer used in version >= 3.5.0
5 | if(EXISTS ${SEAL_INCLUDES_DIR}/gsl)
6 | message(STATUS "Removing ${SEAL_INCLUDES_DIR}/gsl; this is no longer used by IDEA SEAL_GPU >= 3.5.0")
7 | file(REMOVE_RECURSE ${SEAL_INCLUDES_DIR}/gsl)
8 | endif()
9 |
10 | # Remove thirdparty/zlib/src/CMakeCache.txt: the location changed in SEAL >= 3.5.4
11 | if(EXISTS ${SEAL_THIRDPARTY_DIR}/zlib/src/CMakeCache.txt)
12 | message(STATUS "Removing old ${SEAL_THIRDPARTY_DIR}/zlib/src/CMakeCache.txt")
13 | file(REMOVE ${SEAL_THIRDPARTY_DIR}/zlib/src/CMakeCache.txt)
14 | endif()
15 |
16 | # Remove config.h from source tree
17 | if(EXISTS ${SEAL_INCLUDES_DIR}/seal/util/config.h)
18 | message(STATUS "Removing old ${SEAL_INCLUDES_DIR}/seal/util/config.h")
19 | file(REMOVE ${SEAL_INCLUDES_DIR}/seal/util/config.h)
20 | endif()
21 |
--------------------------------------------------------------------------------
/cmake-build-debug/CMakeFiles/clion-Debug-log.txt:
--------------------------------------------------------------------------------
1 | "C:\Program Files\JetBrains\CLion 2023.3.4\bin\cmake\win\x64\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2023.3.4/bin/ninja/win/x64/ninja.exe" -G Ninja -S C:\Users\IDEA\Downloads\seal_gpu-dev_for_publish\seal_gpu-dev_for_publish -B C:\Users\IDEA\Downloads\seal_gpu-dev_for_publish\seal_gpu-dev_for_publish\cmake-build-debug
2 | -- Build type (CMAKE_BUILD_TYPE): Debug
3 | -- GPU_SUPPORT: ON
4 | -- The CXX compiler identification is GNU 13.1.0
5 | -- The C compiler identification is GNU 13.1.0
6 | CMake Error at C:/Program Files/JetBrains/CLion 2023.3.4/bin/cmake/win/x64/share/cmake-3.27/Modules/CMakeDetermineCUDACompiler.cmake:180 (message):
7 | Failed to find nvcc.
8 |
9 | Compiler requires the CUDA toolkit. Please set the CUDAToolkit_ROOT
10 | variable.
11 | Call Stack (most recent call first):
12 | CMakeLists.txt:37 (project)
13 |
14 |
15 | -- Configuring incomplete, errors occurred!
16 |
--------------------------------------------------------------------------------
/native/src/seal/util/hash.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/util/hash.h"
5 |
6 | using namespace std;
7 |
8 | namespace seal
9 | {
10 | namespace util
11 | {
12 | // Required for C++14 compliance: static constexpr member variables are not necessarily inlined so need to
13 | // ensure symbol is created.
14 | constexpr size_t HashFunction::hash_block_uint64_count;
15 |
16 | // Required for C++14 compliance: static constexpr member variables are not necessarily inlined so need to
17 | // ensure symbol is created.
18 | constexpr size_t HashFunction::hash_block_byte_count;
19 |
20 | // Required for C++14 compliance: static constexpr member variables are not necessarily inlined so need to
21 | // ensure symbol is created.
22 | constexpr HashFunction::hash_block_type HashFunction::hash_zero_block;
23 | } // namespace util
24 | } // namespace seal
25 |
--------------------------------------------------------------------------------
/cmake/EnableCXXCompilerFlags.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | include(CheckCXXCompilerFlag)
5 |
6 | # For easier adding of CXX compiler flags
7 | function(seal_enable_cxx_compiler_flag_if_supported flag)
8 | string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set)
9 | if(flag_already_set EQUAL -1)
10 | message(STATUS "Adding CXX compiler flag: ${flag} ...")
11 | check_cxx_compiler_flag("${flag}" flag_supported)
12 | if(flag_supported)
13 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
14 | endif()
15 | unset(flag_supported CACHE)
16 | endif()
17 | endfunction()
18 |
19 | if(NOT MSVC AND SEAL_DEBUG)
20 | seal_enable_cxx_compiler_flag_if_supported("-Wall")
21 | seal_enable_cxx_compiler_flag_if_supported("-Wextra")
22 | seal_enable_cxx_compiler_flag_if_supported("-Wconversion")
23 | seal_enable_cxx_compiler_flag_if_supported("-Wshadow")
24 | seal_enable_cxx_compiler_flag_if_supported("-pedantic")
25 | endif()
26 |
--------------------------------------------------------------------------------
/native/src/seal/util/croots.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #include "seal/memorymanager.h"
7 | #include "seal/util/defines.h"
8 | #include "seal/util/uintcore.h"
9 | #include
10 | #include
11 | #include
12 |
13 | namespace seal
14 | {
15 | namespace util
16 | {
17 | class ComplexRoots
18 | {
19 | public:
20 | ComplexRoots() = delete;
21 |
22 | ComplexRoots(std::size_t degree_of_roots, MemoryPoolHandle pool);
23 |
24 | SEAL_NODISCARD std::complex get_root(std::size_t index) const;
25 |
26 | private:
27 | static constexpr double PI_ = 3.1415926535897932384626433832795028842;
28 |
29 | // Contains 0~(n/8-1)-th powers of the n-th primitive root.
30 | util::Pointer> roots_;
31 |
32 | std::size_t degree_of_roots_;
33 |
34 | MemoryPoolHandle pool_;
35 | };
36 | } // namespace util
37 | } // namespace seal
38 |
--------------------------------------------------------------------------------
/native/tests/seal/util/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | target_sources(sealtest
5 | PRIVATE
6 | ${CMAKE_CURRENT_LIST_DIR}/clipnormal.cpp
7 | ${CMAKE_CURRENT_LIST_DIR}/common.cpp
8 | ${CMAKE_CURRENT_LIST_DIR}/galois.cpp
9 | ${CMAKE_CURRENT_LIST_DIR}/hash.cpp
10 | ${CMAKE_CURRENT_LIST_DIR}/iterator.cpp
11 | ${CMAKE_CURRENT_LIST_DIR}/locks.cpp
12 | ${CMAKE_CURRENT_LIST_DIR}/mempool.cpp
13 | ${CMAKE_CURRENT_LIST_DIR}/numth.cpp
14 | ${CMAKE_CURRENT_LIST_DIR}/polyarithsmallmod.cpp
15 | ${CMAKE_CURRENT_LIST_DIR}/polycore.cpp
16 | ${CMAKE_CURRENT_LIST_DIR}/rns.cpp
17 | ${CMAKE_CURRENT_LIST_DIR}/ntt.cpp
18 | ${CMAKE_CURRENT_LIST_DIR}/stringtouint64.cpp
19 | ${CMAKE_CURRENT_LIST_DIR}/uint64tostring.cpp
20 | ${CMAKE_CURRENT_LIST_DIR}/uintarith.cpp
21 | ${CMAKE_CURRENT_LIST_DIR}/uintarithmod.cpp
22 | ${CMAKE_CURRENT_LIST_DIR}/uintarithsmallmod.cpp
23 | ${CMAKE_CURRENT_LIST_DIR}/uintcore.cpp
24 | )
25 |
--------------------------------------------------------------------------------
/cmake/CheckCXXIntrinsicsHeader.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | # Check for intrin.h or x86intrin.h
5 | if(SEAL_USE_INTRIN)
6 | set(CMAKE_REQUIRED_QUIET_OLD ${CMAKE_REQUIRED_QUIET})
7 | set(CMAKE_REQUIRED_QUIET ON)
8 |
9 | if(MSVC)
10 | set(SEAL_INTRIN_HEADER "intrin.h")
11 | else()
12 | if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
13 | set(SEAL_ARM64 ON)
14 | else()
15 | set(SEAL_ARM64 OFF)
16 | endif()
17 | if(SEAL_ARM64)
18 | set(SEAL_INTRIN_HEADER "arm_neon.h")
19 | elseif(EMSCRIPTEN)
20 | set(SEAL_INTRIN_HEADER "wasm_simd128.h")
21 | else()
22 | set(SEAL_INTRIN_HEADER "x86intrin.h")
23 | endif()
24 | endif()
25 |
26 | check_include_file_cxx(${SEAL_INTRIN_HEADER} SEAL_INTRIN_HEADER_FOUND)
27 | set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_OLD})
28 |
29 | if(SEAL_INTRIN_HEADER_FOUND)
30 | message(STATUS "${SEAL_INTRIN_HEADER} - found")
31 | else()
32 | message(STATUS "${SEAL_INTRIN_HEADER} - not found")
33 | endif()
34 | endif()
35 |
--------------------------------------------------------------------------------
/cmake/ExternalIntelHEXL.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | FetchContent_Declare(
5 | hexl
6 | PREFIX hexl
7 | GIT_REPOSITORY https://github.com/intel/hexl
8 | GIT_TAG f95acf1 # 1.2.5
9 | )
10 | FetchContent_GetProperties(hexl)
11 |
12 | if(NOT hexl_POPULATED)
13 | FetchContent_Populate(hexl)
14 | set(CMAKE_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING "" FORCE)
15 | set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE STRING "" FORCE)
16 | set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "" FORCE)
17 | set(HEXL_BENCHMARK OFF CACHE BOOL "" FORCE)
18 | set(HEXL_COVERAGE OFF CACHE BOOL "" FORCE)
19 | set(HEXL_TESTING OFF CACHE BOOL "" FORCE)
20 | set(HEXL_SHARED_LIB ${BUILD_SHARED_LIBS} CACHE BOOL "" FORCE)
21 | set(EXCLUDE_FROM_ALL TRUE)
22 |
23 | mark_as_advanced(BUILD_HEXL)
24 | mark_as_advanced(INSTALL_HEXL)
25 | mark_as_advanced(FETCHCONTENT_SOURCE_DIR_HEXL)
26 | mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_HEXL)
27 |
28 | add_subdirectory(
29 | ${hexl_SOURCE_DIR}
30 | ${hexl_SOURCE_DIR}/../hexl-build
31 | EXCLUDE_FROM_ALL
32 | )
33 | endif()
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) IDEA Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/native/tests/seal/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | target_sources(sealtest
5 | PRIVATE
6 | # ${CMAKE_CURRENT_LIST_DIR}/ciphertext.cpp
7 | # ${CMAKE_CURRENT_LIST_DIR}/ckks.cpp
8 | # ${CMAKE_CURRENT_LIST_DIR}/context.cpp
9 | # ${CMAKE_CURRENT_LIST_DIR}/encryptionparams.cpp
10 | # ${CMAKE_CURRENT_LIST_DIR}/encryptor.cpp
11 | ${CMAKE_CURRENT_LIST_DIR}/evaluator.cpp
12 | # ${CMAKE_CURRENT_LIST_DIR}/galoiskeys.cpp
13 | # ${CMAKE_CURRENT_LIST_DIR}/dynarray.cpp
14 | # ${CMAKE_CURRENT_LIST_DIR}/keygenerator.cpp
15 | # ${CMAKE_CURRENT_LIST_DIR}/memorymanager.cpp
16 | # ${CMAKE_CURRENT_LIST_DIR}/modulus.cpp
17 | # ${CMAKE_CURRENT_LIST_DIR}/plaintext.cpp
18 | # ${CMAKE_CURRENT_LIST_DIR}/publickey.cpp
19 | # ${CMAKE_CURRENT_LIST_DIR}/randomgen.cpp
20 | # ${CMAKE_CURRENT_LIST_DIR}/randomtostd.cpp
21 | # ${CMAKE_CURRENT_LIST_DIR}/relinkeys.cpp
22 | # ${CMAKE_CURRENT_LIST_DIR}/secretkey.cpp
23 | # ${CMAKE_CURRENT_LIST_DIR}/serialization.cpp
24 | ${CMAKE_CURRENT_LIST_DIR}/testrunner.cpp
25 | )
26 |
27 | add_subdirectory(util)
28 |
--------------------------------------------------------------------------------
/cmake/ExternalZSTD.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | FetchContent_Declare(
5 | zstd
6 | GIT_REPOSITORY https://github.com/facebook/zstd.git
7 | GIT_TAG e47e674cd09583ff0503f0f6defd6d23d8b718d3 # 1.5.2
8 | )
9 | FetchContent_GetProperties(zstd)
10 | if(NOT zstd_POPULATED)
11 | FetchContent_Populate(zstd)
12 |
13 | set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "" FORCE)
14 | set(ZSTD_BUILD_SHARED OFF CACHE BOOL "" FORCE)
15 | set(ZLIB_BUILD_STATIC ON CACHE BOOL "" FORCE)
16 | set(ZSTD_BUILD_TESTS OFF CACHE BOOL "" FORCE)
17 | set(ZSTD_MULTITHREAD_SUPPORT OFF CACHE BOOL "" FORCE)
18 | mark_as_advanced(ZSTD_BUILD_CONTRIB)
19 | mark_as_advanced(ZSTD_BUILD_PROGRAMS)
20 | mark_as_advanced(ZSTD_BUILD_SHARED)
21 | mark_as_advanced(ZSTD_BUILD_STATIC)
22 | mark_as_advanced(ZSTD_BUILD_TESTS)
23 | mark_as_advanced(ZSTD_LEGACY_SUPPORT)
24 | mark_as_advanced(ZSTD_MULTITHREAD_SUPPORT)
25 | mark_as_advanced(ZSTD_PROGRAMS_LINK_SHARED)
26 | mark_as_advanced(FETCHCONTENT_SOURCE_DIR_ZSTD)
27 | mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_ZSTD)
28 |
29 | add_subdirectory(
30 | ${zstd_SOURCE_DIR}/build/cmake
31 | ${zstd_SOURCE_DIR}/../zstd-build
32 | EXCLUDE_FROM_ALL)
33 | endif()
34 |
--------------------------------------------------------------------------------
/native/src/seal/util/common.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #ifndef __STDC_WANT_LIB_EXT1__
5 | #define __STDC_WANT_LIB_EXT1__ 1
6 | #endif
7 |
8 | #include "seal/util/common.h"
9 | #include
10 |
11 | #if (SEAL_SYSTEM == SEAL_SYSTEM_WINDOWS)
12 | #include
13 | #endif
14 |
15 | using namespace std;
16 |
17 | namespace seal
18 | {
19 | namespace util
20 | {
21 | void seal_memzero(void *data, size_t size)
22 | {
23 | #if (SEAL_SYSTEM == SEAL_SYSTEM_WINDOWS)
24 | SecureZeroMemory(data, size);
25 | #elif defined(SEAL_USE_MEMSET_S)
26 | if (size > 0U && memset_s(data, static_cast(size), 0, static_cast(size)) != 0)
27 | {
28 | throw runtime_error("error calling memset_s");
29 | }
30 | #elif defined(SEAL_USE_EXPLICIT_BZERO)
31 | explicit_bzero(data, size);
32 | #elif defined(SEAL_USE_EXPLICIT_MEMSET)
33 | explicit_memset(data, 0, size);
34 | #else
35 | volatile seal_byte *data_ptr = reinterpret_cast(data);
36 | while (size--)
37 | {
38 | *data_ptr++ = seal_byte{};
39 | }
40 | #endif
41 | }
42 | } // namespace util
43 | } // namespace seal
44 |
--------------------------------------------------------------------------------
/native/src/seal/util/hash.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #include "seal/util/blake2.h"
7 | #include "seal/util/common.h"
8 | #include "seal/util/defines.h"
9 | #include
10 | #include
11 | #include
12 |
13 | namespace seal
14 | {
15 | namespace util
16 | {
17 | class HashFunction
18 | {
19 | public:
20 | HashFunction() = delete;
21 |
22 | static constexpr std::size_t hash_block_uint64_count = 4;
23 |
24 | static constexpr std::size_t hash_block_byte_count = hash_block_uint64_count * bytes_per_uint64;
25 |
26 | using hash_block_type = std::array;
27 |
28 | static constexpr hash_block_type hash_zero_block{ { 0, 0, 0, 0 } };
29 |
30 | inline static void hash(const std::uint64_t *input, std::size_t uint64_count, hash_block_type &destination)
31 | {
32 | if (blake2b(&destination, hash_block_byte_count, input, uint64_count * bytes_per_uint64, nullptr, 0) !=
33 | 0)
34 | {
35 | throw std::runtime_error("blake2b failed");
36 | }
37 | }
38 | };
39 | } // namespace util
40 | } // namespace seal
41 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ***English:***
2 |
3 | # FHE GPU Acceleration Library
4 | **This project is based on the framework of [Microsoft SEAL library](https://github.com/microsoft/SEAL), and the original interface is completely retained**
5 |
6 | Users do not need to modify the code as you are using the original SEAL, and can directly benifit from this project for GPU acceleration calculation.
7 |
8 | ## Acceleration
9 |
10 | More details and test results can be found in our paper.
11 |
12 | ## Preparation
13 | 1. Install CUDA
14 | Download and install CUDA 11.7
15 | https://developer.nvidia.com/cuda-11-7-0-download-archive
16 |
17 | 2. Install CMake
18 | Install CMake 3.18.3
19 |
20 | ## Compilation
21 | Execute in the root directory
22 | ```
23 | cmake -S . -B build
24 | cd build
25 | make
26 | ```
27 |
28 | Test:
29 | ```
30 | cd build/bin
31 | ./sealexamples
32 | ```
33 |
34 | ***中文:***
35 | # FHE GPU加速库
36 | **该项目基于[微软SEAL库](https://github.com/microsoft/SEAL)框架进行完成,完全保留原有接口**
37 |
38 | 用户无需修改原有使用SEAL时的代码,可以直接使用本项目进行GPU加速计算。
39 |
40 |
41 | ## 加速效果
42 | 加速效果和细节在我们的论文中可详细查阅。
43 |
44 | ## 准备操作
45 | 1. 安装CUDA
46 | 下载安装11.7版本CUDA
47 | https://developer.nvidia.com/cuda-11-7-0-download-archive
48 | 2. 安装CMake
49 | 安装3.18.3版本cmake
50 |
51 |
52 | ## 编译方法
53 | 根目录下执行
54 | ```
55 | cmake -S . -B build
56 | cd build
57 | make
58 | ```
59 |
60 | 测试:
61 | ```
62 | cd build/bin
63 | ./sealexamples
64 | ```
65 |
--------------------------------------------------------------------------------
/cmake/functions.iOS.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | # This cache-initialization file will be used to enable functions when cross-compiling
5 | # for iOS, as check_cxx_source_runs fails for cross-compilers.
6 |
7 | set(SEAL_MEMSET_S_FOUND_EXITCODE
8 | "0"
9 | CACHE STRING "Result from TRY_RUN" FORCE)
10 |
11 | set(SEAL_MEMSET_S_FOUND_EXITCODE__TRYRUN_OUTPUT
12 | ""
13 | CACHE STRING "Output from TRY_RUN" FORCE)
14 |
15 | set(SEAL_ARM64_EXITCODE
16 | "0"
17 | CACHE STRING "Result from TRY_RUN" FORCE)
18 |
19 | set (SEAL_ARM64_EXITCODE__TRYRUN_OUTPUT
20 | ""
21 | CACHE STRING "Output from TRY_RUN" FORCE)
22 |
23 | set(SEAL___BUILTIN_CLZLL_FOUND_EXITCODE
24 | "0"
25 | CACHE STRING "Result from TRY_RUN" FORCE)
26 |
27 | set(SEAL___BUILTIN_CLZLL_FOUND_EXITCODE__TRYRUN_OUTPUT
28 | ""
29 | CACHE STRING "Output from TRY_RUN" FORCE)
30 |
31 | set(SEAL__ADDCARRY_U64_FOUND_EXITCODE
32 | "0"
33 | CACHE STRING "Result from TRY_RUN" FORCE)
34 |
35 | set(SEAL__ADDCARRY_U64_FOUND_EXITCODE__TRYRUN_OUTPUT
36 | ""
37 | CACHE STRING "Output from TRY_RUN" FORCE)
38 |
39 | set(SEAL__SUBBORROW_U64_FOUND_EXITCODE
40 | "0"
41 | CACHE STRING "Result from TRY_RUN" FORCE)
42 |
43 | set(SEAL__SUBBORROW_U64_FOUND_EXITCODE__TRYRUN_OUTPUT
44 | ""
45 | CACHE STRING "Output from TRY_RUN" FORCE)
46 |
--------------------------------------------------------------------------------
/native/src/seal/version.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #include "seal/util/defines.h"
7 | #include
8 |
9 | namespace seal
10 | {
11 | /**
12 | Holds IDEA SEAL_GPU version information. A SEALVersion contains four values:
13 |
14 | 1. The major version number;
15 | 2. The minor version number;
16 | 3. The patch version number;
17 | 4. The tweak version number.
18 |
19 | Two versions of the library with the same major and minor versions are fully
20 | compatible with each other. They are guaranteed to have the same public API.
21 | Changes in the patch version number indicate totally internal changes, such
22 | as bug fixes that require no changes to the public API. The tweak version
23 | number is currently not used, and is expected to be 0.
24 | */
25 | struct SEALVersion
26 | {
27 | /**
28 | Holds the major version number.
29 | */
30 | std::uint8_t major = SEAL_VERSION_MAJOR;
31 |
32 | /**
33 | Holds the minor version number.
34 | */
35 | std::uint8_t minor = SEAL_VERSION_MINOR;
36 |
37 | /**
38 | Holds the patch version number.
39 | */
40 | std::uint8_t patch = SEAL_VERSION_PATCH;
41 |
42 | std::uint8_t tweak = 0;
43 | };
44 | } // namespace seal
45 |
--------------------------------------------------------------------------------
/native/src/seal/util/scalingvariant.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #include "seal/context.cuh"
7 | #include "seal/memorymanager.h"
8 | #include "seal/plaintext.cuh"
9 | #include "seal/util/iterator.h"
10 | #include
11 |
12 | namespace seal
13 | {
14 | namespace util
15 | {
16 | void add_plain_without_scaling_variant(
17 | const Plaintext &plain, const SEALContext::ContextData &context_data, RNSIter destination);
18 |
19 | void sub_plain_without_scaling_variant(
20 | const Plaintext &plain, const SEALContext::ContextData &context_data, RNSIter destination);
21 |
22 | void multiply_add_plain_with_scaling_variant(
23 | const Plaintext &plain, const SEALContext::ContextData &context_data, RNSIter destination);
24 |
25 | void multiply_add_plain_with_scaling_variant_cuda(
26 | const Plaintext &plain, const SEALContext::ContextData &context_data, uint64_t *destination);
27 |
28 | void multiply_sub_plain_with_scaling_variant(
29 | const Plaintext &plain, const SEALContext::ContextData &context_data, RNSIter destination);
30 |
31 | void multiply_sub_plain_with_scaling_variant_cuda(
32 | const Plaintext &plain, const SEALContext::ContextData &context_data, uint64_t *destination);
33 | } // namespace util
34 | } // namespace seal
35 |
--------------------------------------------------------------------------------
/cmake/ExternalZLIB.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved. Licensed under the MIT license.
2 |
3 | FetchContent_Declare(
4 | zlib
5 | GIT_REPOSITORY https://github.com/madler/zlib.git
6 | GIT_TAG 04f42ceca40f73e2978b50e93806c2a18c1281fc # 1.2.13
7 | )
8 | FetchContent_GetProperties(zlib)
9 | if(NOT zlib_POPULATED)
10 | FetchContent_Populate(zlib)
11 |
12 | set(SKIP_INSTALL_ALL ON CACHE BOOL "" FORCE)
13 | mark_as_advanced(AMD64)
14 | mark_as_advanced(ASM686)
15 | mark_as_advanced(EXECUTABLE_OUTPUT_PATH)
16 | mark_as_advanced(CMAKE_INSTALL_PREFIX)
17 | mark_as_advanced(INSTALL_BIN_DIR)
18 | mark_as_advanced(INSTALL_INC_DIR)
19 | mark_as_advanced(INSTALL_LIB_DIR)
20 | mark_as_advanced(INSTALL_MAN_DIR)
21 | mark_as_advanced(INSTALL_PKGCONFIG_DIR)
22 | mark_as_advanced(LIBRARY_OUTPUT_PATH)
23 | mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY)
24 | mark_as_advanced(ZLIB_BUILD_STATIC)
25 | mark_as_advanced(SKIP_INSTALL_ALL)
26 | mark_as_advanced(FETCHCONTENT_SOURCE_DIR_ZLIB)
27 | mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_ZLIB)
28 |
29 | # ZLIB has no VERSION given to project(), needs to suppress CMP0048 warning
30 | set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS TRUE CACHE INTERNAL "Suppress CMP0048 warning" FORCE)
31 | add_subdirectory(
32 | ${zlib_SOURCE_DIR}
33 | ${zlib_SOURCE_DIR}/../zlib-build
34 | EXCLUDE_FROM_ALL)
35 | endif()
36 |
--------------------------------------------------------------------------------
/native/tests/seal/util/hash.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/util/hash.h"
5 | #include
6 | #include "gtest/gtest.h"
7 |
8 | using namespace seal::util;
9 | using namespace std;
10 |
11 | namespace sealtest
12 | {
13 | namespace util
14 | {
15 | namespace
16 | {
17 | void hash(uint64_t value, HashFunction::hash_block_type &destination)
18 | {
19 | HashFunction::hash(&value, 1, destination);
20 | }
21 | } // namespace
22 |
23 | TEST(HashTest, Hash)
24 | {
25 | uint64_t input[3]{ 0, 0, 0 };
26 | HashFunction::hash_block_type hash1, hash2;
27 | hash(0, hash1);
28 |
29 | HashFunction::hash(input, 0, hash2);
30 | ASSERT_TRUE(hash1 != hash2);
31 |
32 | HashFunction::hash(input, 1, hash2);
33 | ASSERT_TRUE(hash1 == hash2);
34 |
35 | HashFunction::hash(input, 2, hash2);
36 | ASSERT_TRUE(hash1 != hash2);
37 |
38 | hash(0x123456, hash1);
39 | hash(0x023456, hash2);
40 | ASSERT_TRUE(hash1 != hash2);
41 |
42 | input[0] = 0x123456;
43 | input[1] = 1;
44 | hash(0x123456, hash1);
45 | HashFunction::hash(input, 2, hash2);
46 | ASSERT_TRUE(hash1 != hash2);
47 | }
48 | } // namespace util
49 | } // namespace sealtest
50 |
--------------------------------------------------------------------------------
/cmake/EnableCXX17.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | set(SEAL_USE_STD_BYTE OFF)
5 | set(SEAL_USE_SHARED_MUTEX OFF)
6 | set(SEAL_USE_IF_CONSTEXPR OFF)
7 | set(SEAL_USE_MAYBE_UNUSED OFF)
8 | set(SEAL_USE_NODISCARD OFF)
9 | set(SEAL_USE_STD_FOR_EACH_N OFF)
10 | set(SEAL_LANG_FLAG "-std=c++14")
11 | if(SEAL_USE_CXX17)
12 | set(SEAL_USE_STD_BYTE ON)
13 | set(SEAL_USE_SHARED_MUTEX ON)
14 | set(SEAL_USE_IF_CONSTEXPR ON)
15 | set(SEAL_USE_MAYBE_UNUSED ON)
16 | set(SEAL_USE_NODISCARD ON)
17 | set(SEAL_USE_STD_FOR_EACH_N ON)
18 | set(SEAL_LANG_FLAG "-std=c++17")
19 | endif()
20 |
21 | # In some non-MSVC compilers std::for_each_n is not available even when compiling as C++17
22 | if(SEAL_USE_STD_FOR_EACH_N)
23 | cmake_push_check_state(RESET)
24 | set(CMAKE_REQUIRED_QUIET TRUE)
25 |
26 | if(NOT MSVC)
27 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -O0 ${SEAL_LANG_FLAG}")
28 | check_cxx_source_compiles("
29 | #include
30 | int main() {
31 | int a[1]{ 0 };
32 | volatile auto fun = std::for_each_n(a, 1, [](auto b) {});
33 | return 0;
34 | }"
35 | USE_STD_FOR_EACH_N
36 | )
37 | if(NOT USE_STD_FOR_EACH_N EQUAL 1)
38 | set(SEAL_USE_STD_FOR_EACH_N OFF)
39 | endif()
40 | unset(USE_STD_FOR_EACH_N CACHE)
41 | endif()
42 |
43 | cmake_pop_check_state()
44 | endif()
45 |
--------------------------------------------------------------------------------
/native/src/seal/util/config.h.in:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #define SEAL_VERSION "@SEAL_VERSION@"
7 | #define SEAL_VERSION_MAJOR @SEAL_VERSION_MAJOR@
8 | #define SEAL_VERSION_MINOR @SEAL_VERSION_MINOR@
9 | #define SEAL_VERSION_PATCH @SEAL_VERSION_PATCH@
10 |
11 | // Are we in debug mode?
12 | #cmakedefine SEAL_DEBUG
13 |
14 | // C++17 features
15 | #cmakedefine SEAL_USE_STD_BYTE
16 | #cmakedefine SEAL_USE_ALIGNED_ALLOC
17 | #cmakedefine SEAL_USE_SHARED_MUTEX
18 | #cmakedefine SEAL_USE_IF_CONSTEXPR
19 | #cmakedefine SEAL_USE_MAYBE_UNUSED
20 | #cmakedefine SEAL_USE_NODISCARD
21 | #cmakedefine SEAL_USE_STD_FOR_EACH_N
22 |
23 | // Security
24 | #cmakedefine SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT
25 | #cmakedefine SEAL_USE_GAUSSIAN_NOISE
26 | #cmakedefine SEAL_DEFAULT_PRNG @SEAL_DEFAULT_PRNG@
27 | #cmakedefine SEAL_AVOID_BRANCHING
28 |
29 | // Intrinsics
30 | #cmakedefine SEAL_USE_INTRIN
31 | #cmakedefine SEAL_USE__UMUL128
32 | #cmakedefine SEAL_USE__BITSCANREVERSE64
33 | #cmakedefine SEAL_USE___BUILTIN_CLZLL
34 | #cmakedefine SEAL_USE___INT128
35 | #cmakedefine SEAL_USE__ADDCARRY_U64
36 | #cmakedefine SEAL_USE__SUBBORROW_U64
37 |
38 | // Zero memory functions
39 | #cmakedefine SEAL_USE_EXPLICIT_BZERO
40 | #cmakedefine SEAL_USE_EXPLICIT_MEMSET
41 | #cmakedefine SEAL_USE_MEMSET_S
42 |
43 | // Third-party dependencies
44 | #cmakedefine SEAL_USE_MSGSL
45 | #cmakedefine SEAL_USE_ZLIB
46 | #cmakedefine SEAL_USE_ZSTD
47 | #cmakedefine SEAL_USE_INTEL_HEXL
48 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # 使用Ubuntu 18.04作为基础镜像
2 | FROM ubuntu:18.04
3 |
4 | # 设置环境变量以避免在安装过程中出现交互式提示
5 | ENV DEBIAN_FRONTEND=noninteractive
6 |
7 | # 安装基本工具和依赖
8 | RUN apt-get update && apt-get install -y \
9 | build-essential \
10 | software-properties-common \
11 | git \
12 | wget \
13 | curl \
14 | ca-certificates \
15 | lsb-release \
16 | gnupg \
17 | && rm -rf /var/lib/apt/lists/*
18 |
19 | # 安装CMake 3.18.3
20 | RUN wget https://github.com/Kitware/CMake/releases/download/v3.18.3/cmake-3.18.3-Linux-x86_64.sh \
21 | && chmod +x cmake-3.18.3-Linux-x86_64.sh \
22 | && ./cmake-3.18.3-Linux-x86_64.sh --skip-license --prefix=/usr/local \
23 | && rm cmake-3.18.3-Linux-x86_64.sh
24 |
25 | # 添加NVIDIA GPG key
26 | RUN curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | apt-key add -
27 |
28 | # 添加NVIDIA CUDA repository
29 | RUN echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /" > /etc/apt/sources.list.d/cuda.list
30 |
31 | # 安装CUDA 11.7
32 | RUN apt-get update && apt-get install -y --no-install-recommends \
33 | cuda-toolkit-11-7 \
34 | && rm -rf /var/lib/apt/lists/*
35 |
36 | # 设置CUDA环境变量
37 | ENV CUDA_HOME=/usr/local/cuda
38 | ENV PATH=$CUDA_HOME/bin:$PATH
39 | ENV LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH
40 |
41 | # 复制当前git库的代码到容器中
42 | COPY . /my_project
43 |
44 | # 设置工作目录
45 | WORKDIR /my_project
46 |
47 | # 编译代码
48 | # 假设你的项目有一个名为build.sh的脚本来编译项目
49 | RUN chmod +x build.sh && ./build.sh
50 |
51 | # 设置默认命令
52 | CMD ["bash"]
53 |
--------------------------------------------------------------------------------
/native/tests/seal/randomtostd.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/randomgen.h"
5 | #include "seal/randomtostd.h"
6 | #include
7 | #include
8 | #include "gtest/gtest.h"
9 |
10 | using namespace seal;
11 | using namespace std;
12 |
13 | namespace sealtest
14 | {
15 | TEST(RandomToStandard, RandomToStandardGenerate)
16 | {
17 | shared_ptr generator(UniformRandomGeneratorFactory::DefaultFactory()->create());
18 | RandomToStandardAdapter rand(generator);
19 | ASSERT_TRUE(rand.generator() == generator);
20 | ASSERT_EQ(static_cast(0), rand.min());
21 | ASSERT_EQ(static_cast(UINT32_MAX), rand.max());
22 | bool lower_half = false;
23 | bool upper_half = false;
24 | bool even = false;
25 | bool odd = false;
26 | for (int i = 0; i < 50; i++)
27 | {
28 | uint32_t value = rand();
29 | if (value < UINT32_MAX / 2)
30 | {
31 | lower_half = true;
32 | }
33 | else
34 | {
35 | upper_half = true;
36 | }
37 | if ((value % 2) == 0)
38 | {
39 | even = true;
40 | }
41 | else
42 | {
43 | odd = true;
44 | }
45 | }
46 | ASSERT_TRUE(lower_half);
47 | ASSERT_TRUE(upper_half);
48 | ASSERT_TRUE(even);
49 | ASSERT_TRUE(odd);
50 | }
51 | } // namespace sealtest
52 |
--------------------------------------------------------------------------------
/native/tests/seal/util/clipnormal.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/randomgen.h"
5 | #include "seal/randomtostd.h"
6 | #include "seal/util/clipnormal.h"
7 | #include
8 | #include
9 | #include "gtest/gtest.h"
10 |
11 | using namespace seal::util;
12 | using namespace seal;
13 | using namespace std;
14 |
15 | namespace sealtest
16 | {
17 | namespace util
18 | {
19 | TEST(ClipNormal, ClipNormalGenerate)
20 | {
21 | shared_ptr generator(UniformRandomGeneratorFactory::DefaultFactory()->create());
22 | RandomToStandardAdapter rand(generator);
23 | ClippedNormalDistribution dist(50.0, 10.0, 20.0);
24 |
25 | ASSERT_EQ(50.0, dist.mean());
26 | ASSERT_EQ(10.0, dist.standard_deviation());
27 | ASSERT_EQ(20.0, dist.max_deviation());
28 | ASSERT_EQ(30.0, dist.min());
29 | ASSERT_EQ(70.0, dist.max());
30 | double average = 0;
31 | double stddev = 0;
32 | for (int i = 0; i < 100; ++i)
33 | {
34 | double value = dist(rand);
35 | average += value;
36 | stddev += (value - 50.0) * (value - 50.0);
37 | ASSERT_TRUE(value >= 30.0 && value <= 70.0);
38 | }
39 | average /= 100;
40 | stddev /= 100;
41 | stddev = sqrt(stddev);
42 | ASSERT_TRUE(average >= 40.0 && average <= 60.0);
43 | ASSERT_TRUE(stddev >= 5.0 && stddev <= 15.0);
44 | }
45 | } // namespace util
46 | } // namespace sealtest
47 |
--------------------------------------------------------------------------------
/native/examples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | cmake_minimum_required(VERSION 3.13)
5 |
6 | set(CMAKE_CUDA_STANDARD 17)
7 | set(CMAKE_CUDA_COMPILER "/usr/local/cuda/bin/nvcc")
8 | project(SEALExamples VERSION 4.1.1 LANGUAGES CXX CUDA)
9 |
10 | find_package(CUDA REQUIRED)
11 | include_directories(${CUDA_INCLUDE_DIRS})
12 | # If not called from root CMakeLists.txt
13 | if(NOT DEFINED SEAL_BUILD_EXAMPLES)
14 | set(SEAL_BUILD_EXAMPLES ON)
15 |
16 | # Import IDEA SEAL_GPU
17 | find_package(SEAL 4.1.1 EXACT REQUIRED)
18 |
19 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
20 | endif()
21 |
22 | if(SEAL_BUILD_EXAMPLES)
23 | add_executable(sealexamples)
24 | target_sources(sealexamples
25 | PRIVATE
26 | # ${CMAKE_CURRENT_LIST_DIR}/examples.cpp
27 | # ${CMAKE_CURRENT_LIST_DIR}/1_bfv_basics.cpp
28 | # ${CMAKE_CURRENT_LIST_DIR}/2_encoders.cpp
29 | # ${CMAKE_CURRENT_LIST_DIR}/3_levels.cpp
30 | # ${CMAKE_CURRENT_LIST_DIR}/4_ckks_basics.cpp
31 | # ${CMAKE_CURRENT_LIST_DIR}/5_rotation.cpp
32 | ${CMAKE_CURRENT_LIST_DIR}/6_performance.cpp
33 | )
34 |
35 |
36 | if(TARGET SEAL::seal)
37 | target_link_libraries(sealexamples PRIVATE SEAL::seal)
38 | message(STATUS "Using SEAL::seal")
39 | elseif(TARGET SEAL::seal_shared)
40 | set_target_properties(sealexamples PROPERTIES
41 | CUDA_SEPARABLE_COMPILATION ON
42 | POSITION_INDEPENDENT_CODE ON
43 | )
44 |
45 | target_link_libraries(sealexamples PRIVATE SEAL::seal_shared "/usr/local/cuda-11.7/lib64/libcudart.so.11.0")
46 | else()
47 | message(FATAL_ERROR "Cannot find target SEAL::seal or SEAL::seal_shared")
48 | endif()
49 | endif()
50 |
--------------------------------------------------------------------------------
/native/examples/build/cmake_install.cmake:
--------------------------------------------------------------------------------
1 | # Install script for directory: /home/liqirui/SEAL/native/examples
2 |
3 | # Set the install prefix
4 | if(NOT DEFINED CMAKE_INSTALL_PREFIX)
5 | set(CMAKE_INSTALL_PREFIX "/usr/local")
6 | endif()
7 | string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
8 |
9 | # Set the install configuration name.
10 | if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
11 | if(BUILD_TYPE)
12 | string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
13 | CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
14 | else()
15 | set(CMAKE_INSTALL_CONFIG_NAME "")
16 | endif()
17 | message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
18 | endif()
19 |
20 | # Set the component getting installed.
21 | if(NOT CMAKE_INSTALL_COMPONENT)
22 | if(COMPONENT)
23 | message(STATUS "Install component: \"${COMPONENT}\"")
24 | set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
25 | else()
26 | set(CMAKE_INSTALL_COMPONENT)
27 | endif()
28 | endif()
29 |
30 | # Install shared libraries without execute permission?
31 | if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
32 | set(CMAKE_INSTALL_SO_NO_EXE "1")
33 | endif()
34 |
35 | # Is this installation the result of a crosscompile?
36 | if(NOT DEFINED CMAKE_CROSSCOMPILING)
37 | set(CMAKE_CROSSCOMPILING "FALSE")
38 | endif()
39 |
40 | # Set default install directory permissions.
41 | if(NOT DEFINED CMAKE_OBJDUMP)
42 | set(CMAKE_OBJDUMP "/usr/bin/objdump")
43 | endif()
44 |
45 | if(CMAKE_INSTALL_COMPONENT)
46 | set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
47 | else()
48 | set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
49 | endif()
50 |
51 | string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
52 | "${CMAKE_INSTALL_MANIFEST_FILES}")
53 | file(WRITE "/home/liqirui/SEAL/native/examples/build/${CMAKE_INSTALL_MANIFEST}"
54 | "${CMAKE_INSTALL_MANIFEST_CONTENT}")
55 |
--------------------------------------------------------------------------------
/native/src/seal/util/common.cuh:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "helper.cuh"
3 | #include "ntt_60bit.cuh"
4 | #include "ntt_helper.cuh"
5 |
6 | namespace seal
7 | {
8 | namespace util
9 | {
10 | template || is_uint64_v>>
11 | __device__ inline constexpr T reverse_bits_kernel(T operand) noexcept
12 | {
13 | T temp_result;
14 | if (sizeof(T) == sizeof(std::uint32_t))
15 | {
16 | operand = (((operand & T(0xaaaaaaaa)) >> 1) | ((operand & T(0x55555555)) << 1));
17 | operand = (((operand & T(0xcccccccc)) >> 2) | ((operand & T(0x33333333)) << 2));
18 | operand = (((operand & T(0xf0f0f0f0)) >> 4) | ((operand & T(0x0f0f0f0f)) << 4));
19 | operand = (((operand & T(0xff00ff00)) >> 8) | ((operand & T(0x00ff00ff)) << 8));
20 | return static_cast(operand >> 16) | static_cast(operand << 16);
21 | }
22 | else if (sizeof(T) == sizeof(std::uint64_t))
23 | {
24 | return static_cast(reverse_bits_kernel(static_cast(operand >> 32))) |
25 | (static_cast(reverse_bits_kernel(static_cast(operand & T(0xFFFFFFFF))))
26 | << 32);
27 | }
28 | }
29 |
30 | template || is_uint64_v>>
31 | __device__ inline T reverse_bits_kernel(T operand, int bit_count)
32 | {
33 | int bits_per_byte = 8;
34 | return (bit_count == 0)
35 | ? T(0)
36 | : reverse_bits_kernel(operand) >> (sizeof(T) * static_cast(bits_per_byte) -
37 | static_cast(bit_count));
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/cmake/ExternalBenchmark.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | FetchContent_Declare(
5 | benchmark
6 | GIT_REPOSITORY https://github.com/google/benchmark.git
7 | GIT_TAG d572f4777349d43653b21d6c2fc63020ab326db2 # 1.7.1
8 | )
9 | FetchContent_GetProperties(benchmark)
10 |
11 | if(NOT benchmark)
12 | FetchContent_Populate(benchmark)
13 |
14 | set(LLVMAR_EXECUTABLE ${CMAKE_AR})
15 | set(LLVMNM_EXECUTABLE ${CMAKE_NM})
16 | set(LLVMRANLIB_EXECUTABLE ${CMAKE_RANLIB})
17 | set(LLVM_FILECHECK_EXE ${CMAKE_CXX_COMPILER_AR}/../FileCheck)
18 | set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
19 | set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
20 | set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
21 | set(BENCHMARK_ENABLE_LTO OFF CACHE BOOL "" FORCE)
22 | mark_as_advanced(LIBRT)
23 | mark_as_advanced(LLVM_FILECHECK_EXE)
24 | mark_as_advanced(BENCHMARK_BUILD_32_BITS)
25 | mark_as_advanced(BENCHMARK_DOWNLOAD_DEPENDENCIES)
26 | mark_as_advanced(BENCHMARK_ENABLE_ASSEMBLY_TESTS)
27 | mark_as_advanced(BENCHMARK_ENABLE_EXCEPTIONS)
28 | mark_as_advanced(BENCHMARK_ENABLE_GTEST_TESTS)
29 | mark_as_advanced(BENCHMARK_ENABLE_INSTALL)
30 | mark_as_advanced(BENCHMARK_ENABLE_LTO)
31 | mark_as_advanced(BENCHMARK_ENABLE_TESTING)
32 | mark_as_advanced(BENCHMARK_USE_LIBCXX)
33 | mark_as_advanced(FETCHCONTENT_SOURCE_DIR_BENCHMARK)
34 | mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_BENCHMARK)
35 |
36 | if(NOT WIN32)
37 | # Google Benchmark contains unsafe conversions so force -Wno-conversion temporarily
38 | set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
39 | set(CMAKE_CXX_FLAGS "${OLD_CMAKE_CXX_FLAGS} -Wno-conversion")
40 | endif()
41 |
42 | add_subdirectory(
43 | ${benchmark_SOURCE_DIR}
44 | ${THIRDPARTY_BINARY_DIR}/benchmark-src
45 | EXCLUDE_FROM_ALL)
46 |
47 | if(NOT WIN32)
48 | set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS})
49 | endif()
50 | endif()
51 |
--------------------------------------------------------------------------------
/native/src/seal/util/gpu_data.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "seal/util/common.h"
4 | #include "seal/util/helper.cuh"
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | namespace seal
11 | {
12 | class GPUData
13 | {
14 | public:
15 | GPUData() : data_(nullptr) {}
16 |
17 | GPUData(size_t size) {
18 | d_capacity_ = size;
19 | allocate_gpu(&rawPtr_, d_capacity_);
20 | };
21 |
22 | GPUData(uint64_t* data, size_t size) {
23 | d_capacity_ = size;
24 | allocate_gpu(&rawPtr_, d_capacity_);
25 | cudaMemcpy(rawPtr_, data, d_capacity_ * sizeof(uint64_t), cudaMemcpyHostToDevice);
26 | }
27 |
28 | ~GPUData() {
29 | if (data_ != nullptr) {
30 | deallocate_gpu(&rawPtr_, d_capacity_);
31 | }
32 | }
33 |
34 |
35 | uint64_t* data() {
36 | return data_.get();
37 | }
38 |
39 | uint64_t* data() const {
40 | return data_.get();
41 | }
42 |
43 | void setData(std::shared_ptr newData) {
44 | data_ = newData; // 使用复制构造函数,确保共享所有权
45 | }
46 |
47 | size_t capacity() {
48 | return d_capacity_;
49 | }
50 |
51 | void alloc(size_t size) {
52 | if (size > d_capacity_) {
53 | release();
54 | d_capacity_ = size;
55 | allocate_gpu(&rawPtr_, d_capacity_);
56 | }
57 | }
58 |
59 | void release() {
60 | deallocate_gpu(&rawPtr_, d_capacity_);
61 | d_capacity_ = 0;
62 | }
63 |
64 | std::shared_ptr data_ = nullptr;
65 | size_t d_capacity_ = 0;
66 |
67 | private:
68 | uint64_t* rawPtr_ = data_.get();
69 | };
70 | }
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/CMakeError.log:
--------------------------------------------------------------------------------
1 | Performing C++ SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
2 | Change Dir: /home/liqirui/SEAL/native/examples/build/CMakeFiles/CMakeTmp
3 |
4 | Run Build Command(s):/usr/bin/make cmTC_7972a/fast && /usr/bin/make -f CMakeFiles/cmTC_7972a.dir/build.make CMakeFiles/cmTC_7972a.dir/build
5 | make[1]: Entering directory '/home/liqirui/SEAL/native/examples/build/CMakeFiles/CMakeTmp'
6 | Building CXX object CMakeFiles/cmTC_7972a.dir/src.cxx.o
7 | /usr/bin/c++ -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_7972a.dir/src.cxx.o -c /home/liqirui/SEAL/native/examples/build/CMakeFiles/CMakeTmp/src.cxx
8 | Linking CXX executable cmTC_7972a
9 | /home/cmake-3.18.3-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7972a.dir/link.txt --verbose=1
10 | /usr/bin/c++ -DCMAKE_HAVE_LIBC_PTHREAD CMakeFiles/cmTC_7972a.dir/src.cxx.o -o cmTC_7972a
11 | /usr/local/bin/ld: CMakeFiles/cmTC_7972a.dir/src.cxx.o: in function `main':
12 | src.cxx:(.text+0x2d): undefined reference to `pthread_create'
13 | /usr/local/bin/ld: src.cxx:(.text+0x39): undefined reference to `pthread_detach'
14 | /usr/local/bin/ld: src.cxx:(.text+0x45): undefined reference to `pthread_cancel'
15 | /usr/local/bin/ld: src.cxx:(.text+0x56): undefined reference to `pthread_join'
16 | /usr/local/bin/ld: src.cxx:(.text+0x6a): undefined reference to `pthread_atfork'
17 | collect2: error: ld returned 1 exit status
18 | CMakeFiles/cmTC_7972a.dir/build.make:105: recipe for target 'cmTC_7972a' failed
19 | make[1]: *** [cmTC_7972a] Error 1
20 | make[1]: Leaving directory '/home/liqirui/SEAL/native/examples/build/CMakeFiles/CMakeTmp'
21 | Makefile:140: recipe for target 'cmTC_7972a/fast' failed
22 | make: *** [cmTC_7972a/fast] Error 2
23 |
24 |
25 | Source file was:
26 | #include
27 |
28 | void* test_func(void* data)
29 | {
30 | return data;
31 | }
32 |
33 | int main(void)
34 | {
35 | pthread_t thread;
36 | pthread_create(&thread, NULL, test_func, NULL);
37 | pthread_detach(thread);
38 | pthread_cancel(thread);
39 | pthread_join(thread, NULL);
40 | pthread_atfork(NULL, NULL, NULL);
41 | pthread_exit(NULL);
42 |
43 | return 0;
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CompilerIdCUDA/tmp/CMakeCUDACompilerId.cudafe1.c:
--------------------------------------------------------------------------------
1 | # 1 "CMakeCUDACompilerId.cu"
2 | # 64 "CMakeCUDACompilerId.cu"
3 | extern const char *info_compiler;
4 |
5 | extern const char *info_simulate;
6 | # 305 "CMakeCUDACompilerId.cu"
7 | static const char info_version[50];
8 | # 332 "CMakeCUDACompilerId.cu"
9 | static const char info_simulate_version[41];
10 | # 352 "CMakeCUDACompilerId.cu"
11 | extern const char *info_platform;
12 | extern const char *info_arch;
13 |
14 |
15 |
16 |
17 | extern const char *info_language_dialect_default;
18 | # 64 "CMakeCUDACompilerId.cu"
19 | const char *info_compiler = ((const char *)"INFO:compiler[NVIDIA]");
20 |
21 | const char *info_simulate = ((const char *)"INFO:simulate[GNU]");
22 | # 305 "CMakeCUDACompilerId.cu"
23 | static const char info_version[50] = {((char)73),((char)78),((char)70),((char)79),((char)58),((char)99),((char)111),((char)109),((char)112),((char)105),((char)108),((char)101),((char)114),((char)95),((char)118),((char)101),((char)114),((char)115),((char)105),((char)111),((char)110),((char)91),((char)48),((char)48),((char)48),((char)48),((char)48),((char)48),((char)49),((char)49),((char)46),((char)48),((char)48),((char)48),((char)48),((char)48),((char)48),((char)48),((char)55),((char)46),((char)48),((char)48),((char)48),((char)48),((char)48),((char)48),((char)54),((char)52),((char)93),((char)0)};
24 | # 332 "CMakeCUDACompilerId.cu"
25 | static const char info_simulate_version[41] = {((char)73),((char)78),((char)70),((char)79),((char)58),((char)115),((char)105),((char)109),((char)117),((char)108),((char)97),((char)116),((char)101),((char)95),((char)118),((char)101),((char)114),((char)115),((char)105),((char)111),((char)110),((char)91),((char)48),((char)48),((char)48),((char)48),((char)48),((char)48),((char)48),((char)56),((char)46),((char)48),((char)48),((char)48),((char)48),((char)48),((char)48),((char)48),((char)50),((char)93),((char)0)};
26 | # 352 "CMakeCUDACompilerId.cu"
27 | const char *info_platform = ((const char *)"INFO:platform[Linux]");
28 | const char *info_arch = ((const char *)"INFO:arch[]");
29 |
30 |
31 |
32 |
33 | const char *info_language_dialect_default = ((const char *)"INFO:dialect_default[14]");
34 |
--------------------------------------------------------------------------------
/native/bench/keygen.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/seal.h"
5 | #include "seal/util/rlwe.h"
6 | #include "bench.h"
7 |
8 | using namespace benchmark;
9 | using namespace sealbench;
10 | using namespace seal;
11 | using namespace std;
12 |
13 | /**
14 | This file defines benchmarks for KeyGen-related HE primitives.
15 | */
16 |
17 | namespace seal
18 | {
19 | struct KeyGenerator::KeyGeneratorPrivateHelper
20 | {
21 | static void generate_sk(KeyGenerator *keygen)
22 | {
23 | return keygen->generate_sk();
24 | }
25 | };
26 | } // namespace seal
27 |
28 | namespace sealbench
29 | {
30 | void bm_keygen_secret(State &state, shared_ptr bm_env)
31 | {
32 | KeyGenerator keygen(bm_env->context());
33 | for (auto _ : state)
34 | {
35 | KeyGenerator::KeyGeneratorPrivateHelper::generate_sk(&keygen);
36 | }
37 | }
38 |
39 | void bm_keygen_public(State &state, shared_ptr bm_env)
40 | {
41 | shared_ptr keygen = bm_env->keygen();
42 | PublicKey pk;
43 | for (auto _ : state)
44 | {
45 | keygen->create_public_key(pk);
46 | }
47 | }
48 |
49 | void bm_keygen_relin(State &state, shared_ptr bm_env)
50 | {
51 | shared_ptr keygen = bm_env->keygen();
52 | RelinKeys rlk;
53 | for (auto _ : state)
54 | {
55 | keygen->create_relin_keys(rlk);
56 | }
57 | }
58 |
59 | void bm_keygen_galois(State &state, shared_ptr bm_env)
60 | {
61 | shared_ptr keygen = bm_env->keygen();
62 | GaloisKeys glk;
63 | size_t slot_count = bm_env->parms().poly_modulus_degree() >> 1;
64 |
65 | auto random_one_step = [&]() {
66 | vector res;
67 | res.emplace_back(rand() & static_cast(slot_count - 1));
68 | return res;
69 | };
70 |
71 | for (auto _ : state)
72 | {
73 | keygen->create_galois_keys({ random_one_step() }, glk);
74 | }
75 | }
76 | } // namespace sealbench
77 |
--------------------------------------------------------------------------------
/native/tests/seal/secretkey.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/context.cuh"
5 | #include "seal/keygenerator.h"
6 | #include "seal/modulus.h"
7 | #include "seal/secretkey.cuh"
8 | #include "gtest/gtest.h"
9 |
10 | using namespace seal;
11 | using namespace std;
12 |
13 | namespace sealtest
14 | {
15 | TEST(SecretKeyTest, SaveLoadSecretKey)
16 | {
17 | auto save_load_secret_key = [](scheme_type scheme) {
18 | stringstream stream;
19 | {
20 | EncryptionParameters parms(scheme);
21 | parms.set_poly_modulus_degree(64);
22 | parms.set_plain_modulus(1 << 6);
23 | parms.set_coeff_modulus(CoeffModulus::Create(64, { 60 }));
24 |
25 | SEALContext context(parms, false, sec_level_type::none);
26 | KeyGenerator keygen(context);
27 |
28 | SecretKey sk = keygen.secret_key();
29 | ASSERT_TRUE(sk.parms_id() == context.key_parms_id());
30 | sk.save(stream);
31 |
32 | SecretKey sk2;
33 | sk2.load(context, stream);
34 |
35 | ASSERT_TRUE(sk.data() == sk2.data());
36 | ASSERT_TRUE(sk.parms_id() == sk2.parms_id());
37 | }
38 | {
39 | EncryptionParameters parms(scheme);
40 | parms.set_poly_modulus_degree(256);
41 | parms.set_plain_modulus(1 << 20);
42 | parms.set_coeff_modulus(CoeffModulus::Create(256, { 30, 40 }));
43 |
44 | SEALContext context(parms, false, sec_level_type::none);
45 | KeyGenerator keygen(context);
46 |
47 | SecretKey sk = keygen.secret_key();
48 | ASSERT_TRUE(sk.parms_id() == context.key_parms_id());
49 | sk.save(stream);
50 |
51 | SecretKey sk2;
52 | sk2.load(context, stream);
53 |
54 | ASSERT_TRUE(sk.data() == sk2.data());
55 | ASSERT_TRUE(sk.parms_id() == sk2.parms_id());
56 | }
57 | };
58 |
59 | save_load_secret_key(scheme_type::bfv);
60 | save_load_secret_key(scheme_type::bgv);
61 | }
62 | } // namespace sealtest
63 |
--------------------------------------------------------------------------------
/native/tests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | cmake_minimum_required(VERSION 3.13)
5 |
6 | project(SEALTest VERSION 4.1.1 LANGUAGES CXX C)
7 |
8 | # If not called from root CMakeLists.txt
9 | if(NOT DEFINED SEAL_BUILD_TESTS)
10 | set(SEAL_BUILD_TESTS ON)
11 |
12 | # Import IDEA SEAL_GPU
13 | find_package(SEAL 4.1.1 EXACT REQUIRED)
14 |
15 | # Must define these variables and include macros
16 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${OUTLIB_PATH})
17 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
18 | set(SEAL_THIRDPARTY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../thirdparty)
19 | set(THIRDPARTY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/thirdparty)
20 | include(FetchContent)
21 | mark_as_advanced(FETCHCONTENT_BASE_DIR)
22 | mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED)
23 | mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED)
24 | mark_as_advanced(FETCHCONTENT_QUIET)
25 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake)
26 | include(SEALMacros)
27 | else()
28 | set(THIRDPARTY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../thirdparty)
29 | endif()
30 |
31 | if(NOT DEFINED SEAL_BUILD_DEPS)
32 | # [option] SEAL_BUILD_DEPS (default: ON)
33 | # Download and build missing dependencies, throw error if disabled.
34 | set(SEAL_BUILD_DEPS_OPTION_STR "Automatically download and build unmet dependencies")
35 | option(SEAL_BUILD_DEPS ${SEAL_BUILD_DEPS_OPTION_STR} ON)
36 | endif()
37 |
38 | # if SEAL_BUILD_TESTS is ON, use GoogleTest
39 | if(SEAL_BUILD_TESTS)
40 | if(SEAL_BUILD_DEPS)
41 | seal_fetch_thirdparty_content(ExternalGTest)
42 | add_library(GTest::gtest ALIAS gtest)
43 | else()
44 | find_package(GTest 1 CONFIG)
45 | if(NOT GTest_FOUND)
46 | message(FATAL_ERROR "GoogleTest: not found")
47 | else()
48 | message(STATUS "GoogleTest: found")
49 | endif()
50 | endif()
51 |
52 | add_executable(sealtest "")
53 |
54 | add_subdirectory(seal)
55 |
56 | if(TARGET SEAL::seal)
57 | target_link_libraries(sealtest PRIVATE SEAL::seal GTest::gtest)
58 | elseif(TARGET SEAL::seal_shared)
59 | target_link_libraries(sealtest PRIVATE SEAL::seal_shared GTest::gtest)
60 | else()
61 | message(FATAL_ERROR "Cannot find target SEAL::seal or SEAL::seal_shared")
62 | endif()
63 | endif()
64 |
--------------------------------------------------------------------------------
/native/src/seal/randomtostd.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #include "seal/randomgen.h"
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | namespace seal
13 | {
14 | /**
15 | A simple wrapper class to implement C++ UniformRandomBitGenerator type properties
16 | for a given polymorphic UniformRandomGenerator instance. The resulting object can
17 | be used as a randomness source in C++ standard random number distribution classes,
18 | such as std::uniform_int_distribution, std::normal_distribution, or any of the
19 | standard RandomNumberEngine classes.
20 | */
21 | class RandomToStandardAdapter
22 | {
23 | public:
24 | using result_type = std::uint32_t;
25 |
26 | /**
27 | Creates a new RandomToStandardAdapter backed by a given UniformRandomGenerator.
28 |
29 | @param[in] generator A backing UniformRandomGenerator instance
30 | @throws std::invalid_argument if generator is null
31 | */
32 | RandomToStandardAdapter(std::shared_ptr generator) : generator_(generator)
33 | {
34 | if (!generator_)
35 | {
36 | throw std::invalid_argument("generator cannot be null");
37 | }
38 | }
39 |
40 | /**
41 | Returns a new random number from the backing UniformRandomGenerator.
42 | */
43 | SEAL_NODISCARD inline result_type operator()()
44 | {
45 | return generator_->generate();
46 | }
47 |
48 | /**
49 | Returns the backing UniformRandomGenerator.
50 | */
51 | SEAL_NODISCARD inline auto generator() const noexcept
52 | {
53 | return generator_;
54 | }
55 |
56 | /**
57 | Returns the smallest possible output value.
58 | */
59 | SEAL_NODISCARD inline static constexpr result_type min() noexcept
60 | {
61 | return std::numeric_limits::min();
62 | }
63 |
64 | /**
65 | Returns the largest possible output value.
66 | */
67 | SEAL_NODISCARD static constexpr result_type max() noexcept
68 | {
69 | return std::numeric_limits::max();
70 | }
71 |
72 | private:
73 | std::shared_ptr generator_;
74 | };
75 | } // namespace seal
76 |
--------------------------------------------------------------------------------
/cmake/CheckCXXIntrinsicsSpecific.cmake:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | if(SEAL_USE_INTRIN)
5 | cmake_push_check_state(RESET)
6 | set(CMAKE_REQUIRED_QUIET TRUE)
7 | if(NOT MSVC)
8 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -O0 ${SEAL_LANG_FLAG}")
9 | endif()
10 |
11 | if(MSVC)
12 | # Check for presence of _umul128
13 | check_cxx_source_runs("
14 | #include <${SEAL_INTRIN_HEADER}>
15 | int main() {
16 | unsigned long long a = 0, b = 0;
17 | unsigned long long c;
18 | volatile unsigned long long d;
19 | d = _umul128(a, b, &c);
20 | return 0;
21 | }"
22 | SEAL__UMUL128_FOUND
23 | )
24 |
25 | # Check for _BitScanReverse64
26 | check_cxx_source_runs("
27 | #include <${SEAL_INTRIN_HEADER}>
28 | int main() {
29 | unsigned long a = 0, b = 0;
30 | volatile unsigned char res = _BitScanReverse64(&a, b);
31 | return 0;
32 | }"
33 | SEAL__BITSCANREVERSE64_FOUND
34 | )
35 | else()
36 | # Check for presence of __int128
37 | set(CMAKE_EXTRA_INCLUDE_FILES ${SEAL_INTRIN_HEADER})
38 | check_type_size("__int128" INT128 LANGUAGE CXX)
39 | if(INT128 EQUAL 16)
40 | set(SEAL___INT128_FOUND ON)
41 | else()
42 | set(SEAL___INT128_FOUND OFF)
43 | endif()
44 |
45 | # Check for __builtin_clzll
46 | check_cxx_source_runs("
47 | int main() {
48 | volatile auto res = __builtin_clzll(0);
49 | return 0;
50 | }"
51 | SEAL___BUILTIN_CLZLL_FOUND
52 | )
53 | endif()
54 |
55 | # Check for _addcarry_u64
56 | check_cxx_source_runs("
57 | #include <${SEAL_INTRIN_HEADER}>
58 | int main() {
59 | unsigned long long a;
60 | volatile auto res = _addcarry_u64(0,0,0,&a);
61 | return 0;
62 | }"
63 | SEAL__ADDCARRY_U64_FOUND
64 | )
65 |
66 | # Check for _subborrow_u64
67 | check_cxx_source_runs("
68 | #include <${SEAL_INTRIN_HEADER}>
69 | int main() {
70 | unsigned long long a;
71 | volatile auto res = _subborrow_u64(0,0,0,&a);
72 | return 0;
73 | }"
74 | SEAL__SUBBORROW_U64_FOUND
75 | )
76 |
77 | cmake_pop_check_state()
78 | endif()
79 |
--------------------------------------------------------------------------------
/native/tests/seal/memorymanager.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/dynarray.h"
5 | #include "seal/memorymanager.h"
6 | #include "seal/util/pointer.h"
7 | #include "seal/util/uintcore.h"
8 | #include "gtest/gtest.h"
9 |
10 | using namespace seal;
11 | using namespace seal::util;
12 | using namespace std;
13 |
14 | namespace sealtest
15 | {
16 | TEST(MemoryPoolHandleTest, MemoryPoolHandleConstructAssign)
17 | {
18 | MemoryPoolHandle pool;
19 | ASSERT_FALSE(pool);
20 | pool = MemoryPoolHandle::Global();
21 | ASSERT_TRUE(&static_cast(pool) == global_variables::global_memory_pool.get());
22 | pool = MemoryPoolHandle::New();
23 | ASSERT_FALSE(&pool.operator seal::util::MemoryPool &() == global_variables::global_memory_pool.get());
24 | MemoryPoolHandle pool2 = MemoryPoolHandle::New();
25 | ASSERT_FALSE(pool == pool2);
26 |
27 | pool = pool2;
28 | ASSERT_TRUE(pool == pool2);
29 | pool = MemoryPoolHandle::Global();
30 | ASSERT_FALSE(pool == pool2);
31 | pool2 = MemoryPoolHandle::Global();
32 | ASSERT_TRUE(pool == pool2);
33 | }
34 |
35 | TEST(MemoryPoolHandleTest, MemoryPoolHandleAllocate)
36 | {
37 | MemoryPoolHandle pool = MemoryPoolHandle::New();
38 | ASSERT_TRUE(0LL == pool.alloc_byte_count());
39 | {
40 | auto ptr(allocate_uint(5, pool));
41 | ASSERT_TRUE(5LL * bytes_per_uint64 == pool.alloc_byte_count());
42 | }
43 |
44 | pool = MemoryPoolHandle::New();
45 | ASSERT_TRUE(0LL * bytes_per_uint64 == pool.alloc_byte_count());
46 | {
47 | auto ptr(allocate_uint(5, pool));
48 | ASSERT_TRUE(5LL * bytes_per_uint64 == pool.alloc_byte_count());
49 |
50 | ptr = allocate_uint(8, pool);
51 | ASSERT_TRUE(13LL * bytes_per_uint64 == pool.alloc_byte_count());
52 |
53 | auto ptr2(allocate_uint(2, pool));
54 | ASSERT_TRUE(15LL * bytes_per_uint64 == pool.alloc_byte_count());
55 | }
56 | }
57 |
58 | TEST(MemoryPoolHandleTest, UseCount)
59 | {
60 | MemoryPoolHandle pool = MemoryPoolHandle::New();
61 | ASSERT_EQ(1L, pool.use_count());
62 | {
63 | DynArray arr(pool);
64 | ASSERT_EQ(2L, pool.use_count());
65 | DynArray arr2(pool);
66 | ASSERT_EQ(3L, pool.use_count());
67 | }
68 | ASSERT_EQ(1L, pool.use_count());
69 | }
70 | } // namespace sealtest
71 |
--------------------------------------------------------------------------------
/cmake-build-debug/CMakeFiles/3.27.8/CMakeCCompiler.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_C_COMPILER "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/gcc.exe")
2 | set(CMAKE_C_COMPILER_ARG1 "")
3 | set(CMAKE_C_COMPILER_ID "GNU")
4 | set(CMAKE_C_COMPILER_VERSION "13.1.0")
5 | set(CMAKE_C_COMPILER_VERSION_INTERNAL "")
6 | set(CMAKE_C_COMPILER_WRAPPER "")
7 | set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "17")
8 | set(CMAKE_C_EXTENSIONS_COMPUTED_DEFAULT "ON")
9 | set(CMAKE_C_COMPILE_FEATURES "")
10 | set(CMAKE_C90_COMPILE_FEATURES "")
11 | set(CMAKE_C99_COMPILE_FEATURES "")
12 | set(CMAKE_C11_COMPILE_FEATURES "")
13 | set(CMAKE_C17_COMPILE_FEATURES "")
14 | set(CMAKE_C23_COMPILE_FEATURES "")
15 |
16 | set(CMAKE_C_PLATFORM_ID "MinGW")
17 | set(CMAKE_C_SIMULATE_ID "")
18 | set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU")
19 | set(CMAKE_C_SIMULATE_VERSION "")
20 |
21 |
22 |
23 |
24 | set(CMAKE_AR "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/ar.exe")
25 | set(CMAKE_C_COMPILER_AR "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/gcc-ar.exe")
26 | set(CMAKE_RANLIB "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/ranlib.exe")
27 | set(CMAKE_C_COMPILER_RANLIB "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/gcc-ranlib.exe")
28 | set(CMAKE_LINKER "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/ld.exe")
29 | set(CMAKE_MT "")
30 | set(CMAKE_TAPI "CMAKE_TAPI-NOTFOUND")
31 | set(CMAKE_COMPILER_IS_GNUCC 1)
32 | set(CMAKE_C_COMPILER_LOADED 1)
33 | set(CMAKE_C_COMPILER_WORKS )
34 | set(CMAKE_C_ABI_COMPILED )
35 |
36 | set(CMAKE_C_COMPILER_ENV_VAR "CC")
37 |
38 | set(CMAKE_C_COMPILER_ID_RUN 1)
39 | set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m)
40 | set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC)
41 | set(CMAKE_C_LINKER_PREFERENCE 10)
42 | set(CMAKE_C_LINKER_DEPFILE_SUPPORTED )
43 |
44 | # Save compiler ABI information.
45 | set(CMAKE_C_SIZEOF_DATA_PTR "")
46 | set(CMAKE_C_COMPILER_ABI "")
47 | set(CMAKE_C_BYTE_ORDER "")
48 | set(CMAKE_C_LIBRARY_ARCHITECTURE "")
49 |
50 | if(CMAKE_C_SIZEOF_DATA_PTR)
51 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}")
52 | endif()
53 |
54 | if(CMAKE_C_COMPILER_ABI)
55 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}")
56 | endif()
57 |
58 | if(CMAKE_C_LIBRARY_ARCHITECTURE)
59 | set(CMAKE_LIBRARY_ARCHITECTURE "")
60 | endif()
61 |
62 | set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "")
63 | if(CMAKE_C_CL_SHOWINCLUDES_PREFIX)
64 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}")
65 | endif()
66 |
67 |
68 |
69 |
70 |
71 | set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "")
72 | set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "")
73 | set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "")
74 | set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
75 |
--------------------------------------------------------------------------------
/native/src/seal/util/croots.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/util/croots.h"
5 | #include
6 |
7 | using namespace std;
8 |
9 | namespace seal
10 | {
11 | namespace util
12 | {
13 | // Required for C++14 compliance: static constexpr member variables are not necessarily inlined so need to
14 | // ensure symbol is created.
15 | constexpr double ComplexRoots::PI_;
16 |
17 | ComplexRoots::ComplexRoots(size_t degree_of_roots, MemoryPoolHandle pool)
18 | : degree_of_roots_(degree_of_roots), pool_(move(pool))
19 | {
20 | #ifdef SEAL_DEBUG
21 | int power = util::get_power_of_two(degree_of_roots_);
22 | if (power < 0)
23 | {
24 | throw invalid_argument("degree_of_roots must be a power of two");
25 | }
26 | else if (power < 3)
27 | {
28 | throw invalid_argument("degree_of_roots must be at least 8");
29 | }
30 | #endif
31 | roots_ = allocate>(degree_of_roots_ / 8 + 1, pool_);
32 |
33 | // Generate 1/8 of all roots.
34 | // Alternatively, choose from precomputed high-precision roots in files.
35 | for (size_t i = 0; i <= degree_of_roots_ / 8; i++)
36 | {
37 | roots_[i] =
38 | polar(1.0, 2 * PI_ * static_cast(i) / static_cast(degree_of_roots_));
39 | }
40 | }
41 |
42 | SEAL_NODISCARD complex ComplexRoots::get_root(size_t index) const
43 | {
44 | index &= degree_of_roots_ - 1;
45 | auto mirror = [](complex a) {
46 | return complex{ a.imag(), a.real() };
47 | };
48 |
49 | // This express the 8-fold symmetry of all n-th roots.
50 | if (index <= degree_of_roots_ / 8)
51 | {
52 | return roots_[index];
53 | }
54 | else if (index <= degree_of_roots_ / 4)
55 | {
56 | return mirror(roots_[degree_of_roots_ / 4 - index]);
57 | }
58 | else if (index <= degree_of_roots_ / 2)
59 | {
60 | return -conj(get_root(degree_of_roots_ / 2 - index));
61 | }
62 | else if (index <= 3 * degree_of_roots_ / 4)
63 | {
64 | return -get_root(index - degree_of_roots_ / 2);
65 | }
66 | else
67 | {
68 | return conj(get_root(degree_of_roots_ - index));
69 | }
70 | }
71 | } // namespace util
72 | } // namespace seal
73 |
--------------------------------------------------------------------------------
/native/tests/seal/publickey.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #include "seal/context.cuh"
5 | #include "seal/keygenerator.h"
6 | #include "seal/modulus.h"
7 | #include "seal/publickey.h"
8 | #include "gtest/gtest.h"
9 |
10 | using namespace seal;
11 | using namespace std;
12 |
13 | namespace sealtest
14 | {
15 | TEST(PublicKeyTest, SaveLoadPublicKey)
16 | {
17 | auto save_load_public_key = [](scheme_type scheme) {
18 | stringstream stream;
19 | {
20 | EncryptionParameters parms(scheme);
21 | parms.set_poly_modulus_degree(64);
22 | parms.set_plain_modulus(1 << 6);
23 | parms.set_coeff_modulus(CoeffModulus::Create(64, { 60 }));
24 |
25 | SEALContext context(parms, false, sec_level_type::none);
26 | KeyGenerator keygen(context);
27 |
28 | PublicKey pk;
29 | keygen.create_public_key(pk);
30 | ASSERT_TRUE(pk.parms_id() == context.key_parms_id());
31 | pk.save(stream);
32 |
33 | PublicKey pk2;
34 | pk2.load(context, stream);
35 |
36 | ASSERT_EQ(pk.data().dyn_array().size(), pk2.data().dyn_array().size());
37 | for (size_t i = 0; i < pk.data().dyn_array().size(); i++)
38 | {
39 | ASSERT_EQ(pk.data().data()[i], pk2.data().data()[i]);
40 | }
41 | ASSERT_TRUE(pk.parms_id() == pk2.parms_id());
42 | }
43 | {
44 | EncryptionParameters parms(scheme);
45 | parms.set_poly_modulus_degree(256);
46 | parms.set_plain_modulus(1 << 20);
47 | parms.set_coeff_modulus(CoeffModulus::Create(256, { 30, 40 }));
48 |
49 | SEALContext context(parms, false, sec_level_type::none);
50 | KeyGenerator keygen(context);
51 |
52 | PublicKey pk;
53 | keygen.create_public_key(pk);
54 | ASSERT_TRUE(pk.parms_id() == context.key_parms_id());
55 | pk.save(stream);
56 |
57 | PublicKey pk2;
58 | pk2.load(context, stream);
59 |
60 | ASSERT_EQ(pk.data().dyn_array().size(), pk2.data().dyn_array().size());
61 | for (size_t i = 0; i < pk.data().dyn_array().size(); i++)
62 | {
63 | ASSERT_EQ(pk.data().data()[i], pk2.data().data()[i]);
64 | }
65 | ASSERT_TRUE(pk.parms_id() == pk2.parms_id());
66 | }
67 | };
68 |
69 | save_load_public_key(scheme_type::bfv);
70 | save_load_public_key(scheme_type::bgv);
71 | }
72 | } // namespace sealtest
73 |
--------------------------------------------------------------------------------
/native/src/seal/util/clipnormal.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #include "seal/util/defines.h"
7 | #include
8 | #include
9 |
10 | namespace seal
11 | {
12 | namespace util
13 | {
14 | class ClippedNormalDistribution
15 | {
16 | public:
17 | using result_type = double;
18 |
19 | using param_type = ClippedNormalDistribution;
20 |
21 | ClippedNormalDistribution(result_type mean, result_type standard_deviation, result_type max_deviation);
22 |
23 | template
24 | SEAL_NODISCARD inline result_type operator()(RNG &engine, const param_type &parm) noexcept
25 | {
26 | param(parm);
27 | return operator()(engine);
28 | }
29 |
30 | template
31 | SEAL_NODISCARD inline result_type operator()(RNG &engine) noexcept
32 | {
33 | result_type mean = normal_.mean();
34 | while (true)
35 | {
36 | result_type value = normal_(engine);
37 | result_type deviation = std::abs(value - mean);
38 | if (deviation <= max_deviation_)
39 | {
40 | return value;
41 | }
42 | }
43 | }
44 |
45 | SEAL_NODISCARD inline result_type mean() const noexcept
46 | {
47 | return normal_.mean();
48 | }
49 |
50 | SEAL_NODISCARD inline result_type standard_deviation() const noexcept
51 | {
52 | return normal_.stddev();
53 | }
54 |
55 | SEAL_NODISCARD inline result_type max_deviation() const noexcept
56 | {
57 | return max_deviation_;
58 | }
59 |
60 | SEAL_NODISCARD inline result_type min() const noexcept
61 | {
62 | return normal_.mean() - max_deviation_;
63 | }
64 |
65 | SEAL_NODISCARD inline result_type max() const noexcept
66 | {
67 | return normal_.mean() + max_deviation_;
68 | }
69 |
70 | SEAL_NODISCARD inline param_type param() const noexcept
71 | {
72 | return *this;
73 | }
74 |
75 | inline void param(const param_type &parm) noexcept
76 | {
77 | *this = parm;
78 | }
79 |
80 | inline void reset() noexcept
81 | {
82 | normal_.reset();
83 | }
84 |
85 | private:
86 | std::normal_distribution normal_;
87 |
88 | result_type max_deviation_;
89 | };
90 | } // namespace util
91 | } // namespace seal
92 |
--------------------------------------------------------------------------------
/native/src/seal/util/msvc.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #if SEAL_COMPILER == SEAL_COMPILER_MSVC
7 |
8 | // Require Visual Studio 2017 version 15.3 or newer
9 | #if (_MSC_VER < 1911)
10 | #error "Microsoft Visual Studio 2017 version 15.3 or newer required"
11 | #endif
12 |
13 | // Read in config.h
14 | #include "seal/util/config.h"
15 |
16 | // In Visual Studio redefine std::byte (seal_byte)
17 | #undef SEAL_USE_STD_BYTE
18 |
19 | // In Visual Studio for now we disable the use of std::shared_mutex
20 | #undef SEAL_USE_SHARED_MUTEX
21 |
22 | // Are we compiling with C++17 or newer
23 | #if (_MSVC_LANG >= 201703L)
24 |
25 | // Use `if constexpr'
26 | #define SEAL_USE_IF_CONSTEXPR
27 |
28 | // Use [[maybe_unused]]
29 | #define SEAL_USE_MAYBE_UNUSED
30 |
31 | // Use [[nodiscard]]
32 | #define SEAL_USE_NODISCARD
33 |
34 | #else
35 |
36 | #ifdef SEAL_USE_IF_CONSTEXPR
37 | #pragma message("Disabling `if constexpr` based on _MSVC_LANG value " SEAL_STRINGIZE( \
38 | _MSVC_LANG) ": undefining SEAL_USE_IF_CONSTEXPR")
39 | #undef SEAL_USE_IF_CONSTEXPR
40 | #endif
41 |
42 | #ifdef SEAL_USE_MAYBE_UNUSED
43 | #pragma message("Disabling `[[maybe_unused]]` based on _MSVC_LANG value " SEAL_STRINGIZE( \
44 | _MSVC_LANG) ": undefining SEAL_USE_MAYBE_UNUSED")
45 | #undef SEAL_USE_MAYBE_UNUSED
46 | #endif
47 |
48 | #ifdef SEAL_USE_NODISCARD
49 | #pragma message("Disabling `[[nodiscard]]` based on _MSVC_LANG value " SEAL_STRINGIZE( \
50 | _MSVC_LANG) ": undefining SEAL_USE_NODISCARD")
51 | #undef SEAL_USE_NODISCARD
52 | #endif
53 | #endif
54 |
55 | #ifdef SEAL_USE_ALIGNED_ALLOC
56 | #define SEAL_MALLOC(size) static_cast(_aligned_malloc((size), 64))
57 | #define SEAL_FREE(ptr) _aligned_free(ptr)
58 | #endif
59 |
60 | // X64
61 | #ifdef _M_X64
62 |
63 | #ifdef SEAL_USE_INTRIN
64 | #include
65 |
66 | #ifdef SEAL_USE__UMUL128
67 | #pragma intrinsic(_umul128)
68 | #define SEAL_MULTIPLY_UINT64_HW64(operand1, operand2, hw64) _umul128(operand1, operand2, hw64);
69 |
70 | #define SEAL_MULTIPLY_UINT64(operand1, operand2, result128) result128[0] = _umul128(operand1, operand2, result128 + 1);
71 | #endif
72 |
73 | #ifdef SEAL_USE__BITSCANREVERSE64
74 | #pragma intrinsic(_BitScanReverse64)
75 | #define SEAL_MSB_INDEX_UINT64(result, value) _BitScanReverse64(result, value)
76 | #endif
77 |
78 | #ifdef SEAL_USE__ADDCARRY_U64
79 | #pragma intrinsic(_addcarry_u64)
80 | #define SEAL_ADD_CARRY_UINT64(operand1, operand2, carry, result) _addcarry_u64(carry, operand1, operand2, result)
81 | #endif
82 |
83 | #ifdef SEAL_USE__SUBBORROW_U64
84 | #pragma intrinsic(_subborrow_u64)
85 | #define SEAL_SUB_BORROW_UINT64(operand1, operand2, borrow, result) _subborrow_u64(borrow, operand1, operand2, result)
86 | #endif
87 |
88 | #endif
89 | #else
90 | #undef SEAL_USE_INTRIN
91 |
92 | #endif //_M_X64
93 |
94 | // Force inline
95 | #define SEAL_FORCE_INLINE __forceinline
96 |
97 | #endif
98 |
--------------------------------------------------------------------------------
/native/src/seal/util/ntt_helper.cuh:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "seal/util/common.cuh"
4 | #include "seal/util/common.h"
5 | #include "seal/util/scalingvariant.h"
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | using namespace std;
12 |
13 | namespace seal
14 | {
15 | namespace util
16 | {
17 |
18 | __global__ void matrixMultiplication(
19 | uint64_t *A, uint64_t *B, uint64_t *C, int m, int n, int p, uint64_t modulu, uint64_t ratio0,
20 | uint64_t ratio1);
21 |
22 | __global__ void matrix_multi_transpose(
23 | uint64_t *A, uint64_t *B, uint64_t *C, int m, int n, int p, uint64_t modulu, int bit_count,
24 | uint64_t ratio0, uint64_t ratio1);
25 |
26 | __global__ void elementMulMatrix(
27 | uint64_t *MatA, uint64_t *MatB, uint64_t *MatC, int n1, int n2, uint64_t modulu, uint64_t *ratio1);
28 |
29 | __global__ void matrix_multi_elemul_merge(uint64_t *A, uint64_t *B, uint64_t *C,uint64_t *D, int m, int n, int p, uint64_t modulu, uint64_t ratio0,
30 | uint64_t ratio1);
31 |
32 | __global__ void matrix_multi_elemul_merge_batch(uint64_t *A, uint64_t *B, uint64_t *C, int m, int n, int p, size_t modulu_size, uint64_t *modulu, uint64_t *ratio0,
33 | uint64_t *ratio1, uint64_t *elemul_root);
34 |
35 | __global__ void matrix_multi_elemul_merge_batch_test(uint64_t *A, uint64_t *B, uint64_t *C, uint64_t *D, int m, int n, int p, size_t modulu_size, uint64_t *modulu, uint64_t *ratio0,
36 | uint64_t *ratio1, uint64_t *elemul_root);
37 |
38 | __global__ void matrix_multi_transpose_batch(
39 | uint64_t *A, uint64_t *B, uint64_t *C, int m, int n, int p, size_t modulu_size, uint64_t *modulu, int *bit_count,
40 | uint64_t *ratio0, uint64_t *ratio1);
41 |
42 | void ntt_v3(const SEALContext &context, parms_id_type parms_id, uint64_t *input, size_t modulu_size, int modulu_shift=0, cudaStream_t ntt_stream=0);
43 |
44 | void ntt_v3_key_switch(const SEALContext &context, parms_id_type parms_id, uint64_t *input, size_t modulu_size, cudaStream_t ntt_stream, int modulu_shift);
45 |
46 | void ntt_v1(const SEALContext &context, parms_id_type parms_id, uint64_t *input, size_t modulu_size, int modulu_shift=0, bool fix_root=false);
47 |
48 | void ntt_v1_single(const SEALContext &context, parms_id_type parms_id, uint64_t *input, int modulu_shift, cudaStream_t stream=0);
49 |
50 | void intt_v1_single(const SEALContext &context, parms_id_type parms_id, uint64_t *input, int modulu_shift, cudaStream_t stream=0);
51 |
52 | void ntt_v3_single(uint64_t *input, uint64_t *matrix_n1, uint64_t *matrix_n2, uint64_t *matrix_n12, uint64_t modulu, uint64_t ratio0, uint64_t ratio1,
53 | uint64_t root, int bit, std::pair split_result, uint64_t *ntt_temp);
54 | }
55 | }
--------------------------------------------------------------------------------
/native/bench/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Copyright (c) IDEA Corporation. All rights reserved.
2 | # Licensed under the MIT license.
3 |
4 | cmake_minimum_required(VERSION 3.13)
5 |
6 | project(SEALBench VERSION 4.1.1 LANGUAGES CXX)
7 |
8 | # If not called from root CMakeLists.txt
9 | if(NOT DEFINED SEAL_BUILD_BENCH)
10 | set(SEAL_BUILD_BENCH ON)
11 |
12 | # Import SEAL_GPU
13 | find_package(SEAL 4.1.1 EXACT REQUIRED)
14 |
15 | # Must define these variables and include macros
16 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${OUTLIB_PATH})
17 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
18 | set(SEAL_THIRDPARTY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../thirdparty)
19 | set(THIRDPARTY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/thirdparty)
20 | include(FetchContent)
21 | mark_as_advanced(FETCHCONTENT_BASE_DIR)
22 | mark_as_advanced(FETCHCONTENT_FULLY_DISCONNECTED)
23 | mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED)
24 | mark_as_advanced(FETCHCONTENT_QUIET)
25 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake)
26 | include(SEALMacros)
27 | else()
28 | set(THIRDPARTY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../thirdparty)
29 | endif()
30 |
31 | if(NOT DEFINED SEAL_BUILD_DEPS)
32 | # [option] SEAL_BUILD_DEPS (default: ON)
33 | # Download and build missing dependencies, throw error if disabled.
34 | set(SEAL_BUILD_DEPS_OPTION_STR "Automatically download and build unmet dependencies")
35 | option(SEAL_BUILD_DEPS ${SEAL_BUILD_DEPS_OPTION_STR} ON)
36 | endif()
37 |
38 | # if SEAL_BUILD_BENCH is ON, use GoogleBenchmark
39 | if(SEAL_BUILD_BENCH)
40 | if(SEAL_BUILD_DEPS)
41 | seal_fetch_thirdparty_content(ExternalBenchmark)
42 | else()
43 | find_package(benchmark REQUIRED)
44 | if(NOT benchmark_FOUND)
45 | message(FATAL_ERROR "GoogleBenchmark: not found")
46 | else()
47 | message(STATUS "GoogleBenchmark: found")
48 | endif()
49 | endif()
50 |
51 | add_executable(sealbench)
52 | # If we're targeting WASM, add the appropriate link flags
53 | if(EMSCRIPTEN)
54 | set_target_properties(sealbench PROPERTIES LINK_FLAGS "-flto -O3 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4GB")
55 | endif()
56 | target_sources(sealbench
57 | PRIVATE
58 | ${CMAKE_CURRENT_LIST_DIR}/bench.cpp
59 | ${CMAKE_CURRENT_LIST_DIR}/keygen.cpp
60 | ${CMAKE_CURRENT_LIST_DIR}/ntt.cpp
61 | ${CMAKE_CURRENT_LIST_DIR}/bfv.cpp
62 | ${CMAKE_CURRENT_LIST_DIR}/bgv.cpp
63 | ${CMAKE_CURRENT_LIST_DIR}/ckks.cpp
64 | )
65 |
66 | if(TARGET SEAL::seal)
67 | target_link_libraries(sealbench PRIVATE SEAL::seal benchmark::benchmark)
68 | elseif(TARGET SEAL::seal_shared)
69 | target_link_libraries(sealbench PRIVATE SEAL::seal_shared benchmark::benchmark)
70 | else()
71 | message(FATAL_ERROR "Cannot find target SEAL::seal or SEAL::seal_shared")
72 | endif()
73 | endif()
74 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
2 |
3 | This software incorporates components from the projects listed below. The original copyright notices
4 | and the licenses under which IDEA received such components are set forth below and are provided for
5 | informational purposes only. IDEA reserves all rights not expressly granted herein, whether by
6 | implication, estoppel or otherwise.
7 |
8 | This software includes parts of the BLAKE2 library (https://github.com/BLAKE2/BLAKE2).
9 | The BLAKE2 library is licensed under CC0 Universal, version 1.0. You can find a copy of this license at https://creativecommons.org/publicdomain/zero/1.0/legalcode
10 |
11 | This software includes parts of the Kyber library (https://github.com/pq-crystals/kyber).
12 | The Kyber library is licensed under CC0 Universal, version 1.0. You can find a copy of this license at https://creativecommons.org/publicdomain/zero/1.0/legalcode
13 |
14 | This software includes parts of the SEAL library(https://github.com/microsoft/SEAL).
15 | The SEAL library is licensed under MIT License. You can find a copy of this license at https://opensource.org/licenses/MIT
16 |
17 | This software includes parts of the ZSTD library, version 1.4.5 (https://github.com/facebook/zstd):
18 | ZSTD NOTICES AND INFORMATION BEGIN HERE
19 | ===============================================================================
20 | BSD License
21 |
22 | For Zstandard software
23 |
24 | Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
25 |
26 | Redistribution and use in source and binary forms, with or without modification,
27 | are permitted provided that the following conditions are met:
28 |
29 | * Redistributions of source code must retain the above copyright notice, this
30 | list of conditions and the following disclaimer.
31 |
32 | * Redistributions in binary form must reproduce the above copyright notice,
33 | this list of conditions and the following disclaimer in the documentation
34 | and/or other materials provided with the distribution.
35 |
36 | * Neither the name Facebook nor the names of its contributors may be used to
37 | endorse or promote products derived from this software without specific
38 | prior written permission.
39 |
40 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
41 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
42 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
44 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
45 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
47 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
48 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
49 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 | ===============================================================================
51 | END OF ZSTD NOTICES AND INFORMATION
52 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/3.18.3/CMakeCUDACompiler.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_CUDA_COMPILER "/usr/local/cuda/bin/nvcc")
2 | set(CMAKE_CUDA_HOST_COMPILER "")
3 | set(CMAKE_CUDA_HOST_LINK_LAUNCHER "/usr/local/bin/g++")
4 | set(CMAKE_CUDA_COMPILER_ID "NVIDIA")
5 | set(CMAKE_CUDA_COMPILER_VERSION "11.7.64")
6 | set(CMAKE_CUDA_STANDARD_COMPUTED_DEFAULT "14")
7 | set(CMAKE_CUDA_COMPILE_FEATURES "cuda_std_03;cuda_std_11;cuda_std_14;cuda_std_17")
8 | set(CMAKE_CUDA03_COMPILE_FEATURES "cuda_std_03")
9 | set(CMAKE_CUDA11_COMPILE_FEATURES "cuda_std_11")
10 | set(CMAKE_CUDA14_COMPILE_FEATURES "cuda_std_14")
11 | set(CMAKE_CUDA17_COMPILE_FEATURES "cuda_std_17")
12 | set(CMAKE_CUDA20_COMPILE_FEATURES "")
13 |
14 | set(CMAKE_CUDA_PLATFORM_ID "Linux")
15 | set(CMAKE_CUDA_SIMULATE_ID "GNU")
16 | set(CMAKE_CUDA_COMPILER_FRONTEND_VARIANT "")
17 | set(CMAKE_CUDA_SIMULATE_VERSION "8.2")
18 |
19 |
20 |
21 | set(CMAKE_CUDA_COMPILER_ENV_VAR "CUDACXX")
22 | set(CMAKE_CUDA_HOST_COMPILER_ENV_VAR "CUDAHOSTCXX")
23 |
24 | set(CMAKE_CUDA_COMPILER_LOADED 1)
25 | set(CMAKE_CUDA_COMPILER_ID_RUN 1)
26 | set(CMAKE_CUDA_SOURCE_FILE_EXTENSIONS cu)
27 | set(CMAKE_CUDA_LINKER_PREFERENCE 15)
28 | set(CMAKE_CUDA_LINKER_PREFERENCE_PROPAGATES 1)
29 |
30 | set(CMAKE_CUDA_SIZEOF_DATA_PTR "8")
31 | set(CMAKE_CUDA_COMPILER_ABI "ELF")
32 | set(CMAKE_CUDA_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
33 |
34 | if(CMAKE_CUDA_SIZEOF_DATA_PTR)
35 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_CUDA_SIZEOF_DATA_PTR}")
36 | endif()
37 |
38 | if(CMAKE_CUDA_COMPILER_ABI)
39 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CUDA_COMPILER_ABI}")
40 | endif()
41 |
42 | if(CMAKE_CUDA_LIBRARY_ARCHITECTURE)
43 | set(CMAKE_LIBRARY_ARCHITECTURE "x86_64-linux-gnu")
44 | endif()
45 |
46 | set(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT "/usr/local/cuda")
47 | set(CMAKE_CUDA_COMPILER_LIBRARY_ROOT "")
48 |
49 | set(CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES "/usr/local/cuda/targets/x86_64-linux/include")
50 |
51 | set(CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES "")
52 | set(CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES "/usr/local/cuda/targets/x86_64-linux/lib/stubs;/usr/local/cuda/targets/x86_64-linux/lib")
53 | set(CMAKE_CUDA_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
54 |
55 | set(CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES "/usr/local/gcc-8.2/include/c++/8.2.0;/usr/local/gcc-8.2/include/c++/8.2.0/x86_64-pc-linux-gnu;/usr/local/gcc-8.2/include/c++/8.2.0/backward;/usr/local/gcc-8.2/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include;/usr/local/include;/usr/local/gcc-8.2/include;/usr/local/gcc-8.2/lib/gcc/x86_64-pc-linux-gnu/8.2.0/include-fixed;/usr/include/x86_64-linux-gnu;/usr/include")
56 | set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "stdc++;m;gcc_s;gcc;c;gcc_s;gcc")
57 | set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "/usr/local/cuda/targets/x86_64-linux/lib/stubs;/usr/local/cuda/targets/x86_64-linux/lib;/usr/local/gcc-8.2/lib/gcc/x86_64-pc-linux-gnu/8.2.0;/usr/local/gcc-8.2/lib64;/lib/x86_64-linux-gnu;/lib64;/usr/lib/x86_64-linux-gnu;/usr/local/gcc-8.2/lib")
58 | set(CMAKE_CUDA_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
59 |
60 | set(CMAKE_CUDA_RUNTIME_LIBRARY_DEFAULT "STATIC")
61 |
62 | set(CMAKE_LINKER "/usr/bin/ld")
63 | set(CMAKE_AR "/usr/bin/ar")
64 | set(CMAKE_MT "")
65 |
--------------------------------------------------------------------------------
/native/examples/build/CMakeFiles/sealexamples.dir/depend.internal:
--------------------------------------------------------------------------------
1 | # CMAKE generated file: DO NOT EDIT!
2 | # Generated by "Unix Makefiles" Generator, CMake Version 3.18
3 |
4 | CMakeFiles/sealexamples.dir/2_encoders.cpp.o
5 | /home/liqirui/SEAL/native/examples/2_encoders.cpp
6 | /home/liqirui/SEAL/native/examples/examples.h
7 | /usr/local/include/SEAL-4.1/gsl/assert
8 | /usr/local/include/SEAL-4.1/gsl/byte
9 | /usr/local/include/SEAL-4.1/gsl/span
10 | /usr/local/include/SEAL-4.1/gsl/span_ext
11 | /usr/local/include/SEAL-4.1/gsl/util
12 | /usr/local/include/SEAL-4.1/seal/batchencoder.h
13 | /usr/local/include/SEAL-4.1/seal/ciphertext.h
14 | /usr/local/include/SEAL-4.1/seal/ckks.h
15 | /usr/local/include/SEAL-4.1/seal/context.h
16 | /usr/local/include/SEAL-4.1/seal/decryptor.h
17 | /usr/local/include/SEAL-4.1/seal/dynarray.h
18 | /usr/local/include/SEAL-4.1/seal/encryptionparams.h
19 | /usr/local/include/SEAL-4.1/seal/encryptor.h
20 | /usr/local/include/SEAL-4.1/seal/evaluator.h
21 | /usr/local/include/SEAL-4.1/seal/galoiskeys.h
22 | /usr/local/include/SEAL-4.1/seal/keygenerator.h
23 | /usr/local/include/SEAL-4.1/seal/kswitchkeys.h
24 | /usr/local/include/SEAL-4.1/seal/memorymanager.h
25 | /usr/local/include/SEAL-4.1/seal/modulus.h
26 | /usr/local/include/SEAL-4.1/seal/plaintext.h
27 | /usr/local/include/SEAL-4.1/seal/publickey.h
28 | /usr/local/include/SEAL-4.1/seal/randomgen.h
29 | /usr/local/include/SEAL-4.1/seal/randomtostd.h
30 | /usr/local/include/SEAL-4.1/seal/relinkeys.h
31 | /usr/local/include/SEAL-4.1/seal/seal.h
32 | /usr/local/include/SEAL-4.1/seal/secretkey.h
33 | /usr/local/include/SEAL-4.1/seal/serializable.h
34 | /usr/local/include/SEAL-4.1/seal/serialization.h
35 | /usr/local/include/SEAL-4.1/seal/util/blake2.h
36 | /usr/local/include/SEAL-4.1/seal/util/clang.h
37 | /usr/local/include/SEAL-4.1/seal/util/common.h
38 | /usr/local/include/SEAL-4.1/seal/util/config.h
39 | /usr/local/include/SEAL-4.1/seal/util/croots.h
40 | /usr/local/include/SEAL-4.1/seal/util/defines.h
41 | /usr/local/include/SEAL-4.1/seal/util/dwthandler.h
42 | /usr/local/include/SEAL-4.1/seal/util/galois.h
43 | /usr/local/include/SEAL-4.1/seal/util/gcc.h
44 | /usr/local/include/SEAL-4.1/seal/util/globals.h
45 | /usr/local/include/SEAL-4.1/seal/util/hash.h
46 | /usr/local/include/SEAL-4.1/seal/util/hestdparms.h
47 | /usr/local/include/SEAL-4.1/seal/util/iterator.h
48 | /usr/local/include/SEAL-4.1/seal/util/locks.h
49 | /usr/local/include/SEAL-4.1/seal/util/mempool.h
50 | /usr/local/include/SEAL-4.1/seal/util/msvc.h
51 | /usr/local/include/SEAL-4.1/seal/util/ntt.h
52 | /usr/local/include/SEAL-4.1/seal/util/numth.h
53 | /usr/local/include/SEAL-4.1/seal/util/pointer.h
54 | /usr/local/include/SEAL-4.1/seal/util/polycore.h
55 | /usr/local/include/SEAL-4.1/seal/util/rns.h
56 | /usr/local/include/SEAL-4.1/seal/util/streambuf.h
57 | /usr/local/include/SEAL-4.1/seal/util/uintarith.h
58 | /usr/local/include/SEAL-4.1/seal/util/uintarithsmallmod.h
59 | /usr/local/include/SEAL-4.1/seal/util/uintcore.h
60 | /usr/local/include/SEAL-4.1/seal/util/ztools.h
61 | /usr/local/include/SEAL-4.1/seal/valcheck.h
62 | /usr/local/include/SEAL-4.1/seal/version.h
63 |
--------------------------------------------------------------------------------
/native/src/seal/galoiskeys.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #include "seal/ciphertext.cuh"
7 | #include "seal/kswitchkeys.h"
8 | #include "seal/memorymanager.h"
9 | #include "seal/util/defines.h"
10 | #include "seal/util/galois.h"
11 | #include
12 |
13 | namespace seal
14 | {
15 | /**
16 | Class to store Galois keys.
17 |
18 | @par Slot Rotations
19 | Galois keys are certain types of public keys that are needed to perform encrypted
20 | vector rotation operations on batched ciphertexts. Batched ciphertexts encrypt
21 | a 2-by-(N/2) matrix of modular integers in the BFV scheme, or an N/2-dimensional
22 | vector of complex numbers in the CKKS scheme, where N denotes the degree of the
23 | polynomial modulus. In the BFV scheme Galois keys can enable both cyclic rotations
24 | of the encrypted matrix rows, as well as row swaps (column rotations). In the CKKS
25 | scheme Galois keys can enable cyclic vector rotations, as well as a complex
26 | conjugation operation.
27 |
28 |
29 | @par Thread Safety
30 | In general, reading from GaloisKeys is thread-safe as long as no other thread is
31 | concurrently mutating it. This is due to the underlying data structure storing the
32 | Galois keys not being thread-safe.
33 |
34 | @see RelinKeys for the class that stores the relinearization keys.
35 | @see KeyGenerator for the class that generates the Galois keys.
36 | */
37 | class GaloisKeys : public KSwitchKeys
38 | {
39 | public:
40 | /**
41 | Returns the index of a Galois key in the backing KSwitchKeys instance that
42 | corresponds to the given Galois element, assuming that it exists in the
43 | backing KSwitchKeys.
44 |
45 | @param[in] galois_elt The Galois element
46 | @throws std::invalid_argument if galois_elt is not valid
47 | */
48 | SEAL_NODISCARD inline static std::size_t get_index(std::uint32_t galois_elt)
49 | {
50 | return util::GaloisTool::GetIndexFromElt(galois_elt);
51 | }
52 |
53 | /**
54 | Returns whether a Galois key corresponding to a given Galois element exists.
55 |
56 | @param[in] galois_elt The Galois element
57 | @throws std::invalid_argument if galois_elt is not valid
58 | */
59 | SEAL_NODISCARD inline bool has_key(std::uint32_t galois_elt) const
60 | {
61 | std::size_t index = get_index(galois_elt);
62 | return data().size() > index && !data()[index].empty();
63 | }
64 |
65 | /**
66 | Returns a const reference to a Galois key. The returned Galois key corresponds
67 | to the given Galois element.
68 |
69 | @param[in] galois_elt The Galois element
70 | @throws std::invalid_argument if the key corresponding to galois_elt does not exist
71 | */
72 | SEAL_NODISCARD inline const auto &key(std::uint32_t galois_elt) const
73 | {
74 | return KSwitchKeys::data(get_index(galois_elt));
75 | }
76 | };
77 | } // namespace seal
78 |
--------------------------------------------------------------------------------
/cmake-build-debug/CMakeFiles/3.27.8/CMakeCXXCompiler.cmake:
--------------------------------------------------------------------------------
1 | set(CMAKE_CXX_COMPILER "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/g++.exe")
2 | set(CMAKE_CXX_COMPILER_ARG1 "")
3 | set(CMAKE_CXX_COMPILER_ID "GNU")
4 | set(CMAKE_CXX_COMPILER_VERSION "13.1.0")
5 | set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "")
6 | set(CMAKE_CXX_COMPILER_WRAPPER "")
7 | set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "17")
8 | set(CMAKE_CXX_EXTENSIONS_COMPUTED_DEFAULT "ON")
9 | set(CMAKE_CXX_COMPILE_FEATURES "")
10 | set(CMAKE_CXX98_COMPILE_FEATURES "")
11 | set(CMAKE_CXX11_COMPILE_FEATURES "")
12 | set(CMAKE_CXX14_COMPILE_FEATURES "")
13 | set(CMAKE_CXX17_COMPILE_FEATURES "")
14 | set(CMAKE_CXX20_COMPILE_FEATURES "")
15 | set(CMAKE_CXX23_COMPILE_FEATURES "")
16 |
17 | set(CMAKE_CXX_PLATFORM_ID "MinGW")
18 | set(CMAKE_CXX_SIMULATE_ID "")
19 | set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "GNU")
20 | set(CMAKE_CXX_SIMULATE_VERSION "")
21 |
22 |
23 |
24 |
25 | set(CMAKE_AR "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/ar.exe")
26 | set(CMAKE_CXX_COMPILER_AR "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/gcc-ar.exe")
27 | set(CMAKE_RANLIB "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/ranlib.exe")
28 | set(CMAKE_CXX_COMPILER_RANLIB "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/gcc-ranlib.exe")
29 | set(CMAKE_LINKER "C:/Program Files/JetBrains/CLion 2023.3.4/bin/mingw/bin/ld.exe")
30 | set(CMAKE_MT "")
31 | set(CMAKE_TAPI "CMAKE_TAPI-NOTFOUND")
32 | set(CMAKE_COMPILER_IS_GNUCXX 1)
33 | set(CMAKE_CXX_COMPILER_LOADED 1)
34 | set(CMAKE_CXX_COMPILER_WORKS )
35 | set(CMAKE_CXX_ABI_COMPILED )
36 |
37 | set(CMAKE_CXX_COMPILER_ENV_VAR "CXX")
38 |
39 | set(CMAKE_CXX_COMPILER_ID_RUN 1)
40 | set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;mpp;CPP;ixx;cppm;ccm;cxxm;c++m)
41 | set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC)
42 |
43 | foreach (lang C OBJC OBJCXX)
44 | if (CMAKE_${lang}_COMPILER_ID_RUN)
45 | foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS)
46 | list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension})
47 | endforeach()
48 | endif()
49 | endforeach()
50 |
51 | set(CMAKE_CXX_LINKER_PREFERENCE 30)
52 | set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1)
53 | set(CMAKE_CXX_LINKER_DEPFILE_SUPPORTED )
54 |
55 | # Save compiler ABI information.
56 | set(CMAKE_CXX_SIZEOF_DATA_PTR "")
57 | set(CMAKE_CXX_COMPILER_ABI "")
58 | set(CMAKE_CXX_BYTE_ORDER "")
59 | set(CMAKE_CXX_LIBRARY_ARCHITECTURE "")
60 |
61 | if(CMAKE_CXX_SIZEOF_DATA_PTR)
62 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}")
63 | endif()
64 |
65 | if(CMAKE_CXX_COMPILER_ABI)
66 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}")
67 | endif()
68 |
69 | if(CMAKE_CXX_LIBRARY_ARCHITECTURE)
70 | set(CMAKE_LIBRARY_ARCHITECTURE "")
71 | endif()
72 |
73 | set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "")
74 | if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX)
75 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}")
76 | endif()
77 |
78 |
79 |
80 |
81 |
82 | set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "")
83 | set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
84 | set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
85 | set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "")
86 |
--------------------------------------------------------------------------------
/native/src/seal/util/globals.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) IDEA Corporation. All rights reserved.
2 | // Licensed under the MIT license.
3 |
4 | #pragma once
5 |
6 | #include "seal/util/hestdparms.h"
7 | #include
8 | #include