├── src ├── pke │ ├── include │ │ ├── scheme │ │ │ ├── README.md │ │ │ ├── ckksrns │ │ │ │ ├── README.md │ │ │ │ └── ckksrns-ser.h │ │ │ ├── bfvrns │ │ │ │ └── bfvrns-ser.h │ │ │ ├── gen-cryptocontext-params-validation.h │ │ │ ├── bgvrns │ │ │ │ └── bgvrns-ser.h │ │ │ └── scheme-utils.h │ │ ├── key │ │ │ ├── README.md │ │ │ ├── evalkey-fwd.h │ │ │ ├── publickey-fwd.h │ │ │ ├── privatekey-fwd.h │ │ │ ├── evalkeyrelin-fwd.h │ │ │ ├── key-ser.h │ │ │ └── keypair.h │ │ ├── encoding │ │ │ ├── README.md │ │ │ ├── encodings.h │ │ │ └── plaintext-fwd.h │ │ ├── keyswitch │ │ │ └── README.md │ │ ├── metadata-ser.h │ │ ├── cryptocontext-fwd.h │ │ └── schemerns │ │ │ └── rns-ser.h │ ├── README.md │ ├── examples │ │ └── INTERACTIVE_BOOTSTRAPPING.md │ ├── lib │ │ ├── schemebase │ │ │ ├── base-fhe.cpp │ │ │ ├── base-parametergeneration.cpp │ │ │ ├── rlwe-cryptoparameters-impl.cpp │ │ │ └── base-cryptoparameters.cpp │ │ ├── key │ │ │ ├── evalkey.cpp │ │ │ ├── publickey.cpp │ │ │ ├── privatekey.cpp │ │ │ └── evalkeyrelin.cpp │ │ ├── encoding │ │ │ └── encodingparams.cpp │ │ ├── cryptoobject-impl.cpp │ │ ├── keyswitch │ │ │ └── keyswitch-base.cpp │ │ └── globals-impl.cpp │ └── unittest │ │ └── utils │ │ ├── UnitTestMetadataTestSer.h │ │ ├── UnitTestCryptoContext.h │ │ └── UnitTestReadCSVData.h ├── core │ ├── lib │ │ └── utils │ │ │ ├── prng │ │ │ └── CPPLINT.cfg │ │ │ ├── parallel.cpp │ │ │ ├── openfhebase64.cpp │ │ │ ├── memory.cpp │ │ │ ├── inttypes.cpp │ │ │ ├── utilities.cpp │ │ │ └── debug.cpp │ ├── include │ │ ├── utils │ │ │ ├── prng │ │ │ │ ├── CPPLINT.cfg │ │ │ │ └── README.md │ │ │ ├── README.md │ │ │ ├── blockAllocator │ │ │ │ ├── README.md │ │ │ │ ├── xlist.h │ │ │ │ ├── xqueue.h │ │ │ │ ├── xstring.h │ │ │ │ ├── xset.h │ │ │ │ ├── xmap.h │ │ │ │ ├── xsstream.h │ │ │ │ └── xvector.h │ │ │ ├── demangle.h │ │ │ ├── get-call-stack.h │ │ │ └── sertype.h │ │ ├── lattice │ │ │ ├── hal │ │ │ │ └── README.md │ │ │ └── lat-hal.h │ │ ├── README.md │ │ ├── openfhecore.h │ │ ├── math │ │ │ ├── hal │ │ │ │ └── nativeintbackend.h │ │ │ └── distrgen.h │ │ └── version.h │ └── unittest │ │ └── UnitTestUtils.cpp ├── binfhe │ ├── README.md │ └── include │ │ ├── lwe-keypair-fwd.h │ │ ├── lwe-publickey-fwd.h │ │ ├── lwe-ciphertext-fwd.h │ │ ├── lwe-privatekey-fwd.h │ │ └── lwe-keyswitchkey-fwd.h └── README.md ├── test └── CPPLINT.cfg ├── third-party └── .clang-format ├── logo.png ├── docs ├── genindex.rst ├── sphinx_rsts │ ├── contributing │ │ ├── ci_cd_assets │ │ │ ├── manual_workflow_options.png │ │ │ ├── run_manual_workflow_step2.png │ │ │ ├── run_manual_workflow_step3.png │ │ │ ├── run_manual_workflow_step5.png │ │ │ ├── github_add_self_hosted_server.png │ │ │ └── switch_default_branch_diagram.png │ │ ├── contributing.rst │ │ └── rebasing_off_main.rst │ ├── intro │ │ ├── get_started.rst │ │ ├── tutorials.rst │ │ ├── directory_structure.rst │ │ ├── exceptions_in_openfhe.rst │ │ ├── security.rst │ │ ├── building_user_applications.rst │ │ └── using_the_library.rst │ ├── modules │ │ ├── core │ │ │ ├── utils │ │ │ │ ├── core_utils.rst │ │ │ │ └── block_allocator.rst │ │ │ ├── core.rst │ │ │ └── lattice │ │ │ │ └── hal.rst │ │ ├── pke │ │ │ ├── pke_scheme.rst │ │ │ └── pke_keys.rst │ │ └── modules.rst │ └── misc │ │ └── license.rst ├── static_docs │ ├── README.md │ ├── Webinars.md │ ├── Security.md │ └── Examples.md ├── README.md ├── conf_theme.rst ├── requirements.txt ├── the_requirements.rst └── Makefile ├── demoData └── .gitignore ├── scripts ├── maint │ └── apply-code-format.sh └── setup │ ├── NTL_and_GMP_install.sh │ └── linux_platform_packages.sh ├── docker ├── 000-default.conf ├── benchmark.sh ├── upload-tagged-docker.sh └── Dockerfile ├── Makefile ├── configure ├── setup-eclipse-cmake.sh └── config_core.in ├── PreLoad.cmake ├── .pydevproject ├── OpenFHEConfigVersion.cmake.in ├── .gitmodules ├── cicd └── github-runner │ └── user-data.txt ├── CPPLINT.cfg ├── .gitattributes ├── .readthedocs.yaml ├── .pre-commit-config.yaml ├── .gitignore ├── .clang-format ├── LICENSE ├── .github └── workflows │ └── pull-request.yml ├── benchmark ├── CMakeLists.txt └── src │ ├── poly-benchmark-1k.cpp │ ├── poly-benchmark-4k.cpp │ ├── poly-benchmark-8k.cpp │ ├── poly-benchmark-16k.cpp │ └── poly-benchmark-64k.cpp └── CMakeLists.User.txt /src/pke/include/scheme/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # Ignore for now 2 | exclude_files=Main_TestAll.cpp 3 | -------------------------------------------------------------------------------- /third-party/.clang-format: -------------------------------------------------------------------------------- 1 | DisableFormat: true 2 | SortIncludes: false 3 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfheorg/openfhe-development/HEAD/logo.png -------------------------------------------------------------------------------- /src/core/lib/utils/prng/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # Ignore third-party files 2 | exclude_files=blake2(x|)b-ref.c 3 | -------------------------------------------------------------------------------- /src/core/include/utils/prng/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # Ignore third-party files 2 | exclude_files=blake2(-impl|).h 3 | -------------------------------------------------------------------------------- /docs/genindex.rst: -------------------------------------------------------------------------------- 1 | .. 2 | [COMMENT] This file is a placeholder and will be replaced 3 | 4 | Index 5 | ====== -------------------------------------------------------------------------------- /demoData/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | !*.csv 6 | -------------------------------------------------------------------------------- /scripts/maint/apply-code-format.sh: -------------------------------------------------------------------------------- 1 | find ./ -type f -and \( -name '*.cpp' -or -name '*.c' -or -name '*.h' \) | xargs clang-format -i --assume-filename=.clang-format 2 | -------------------------------------------------------------------------------- /docker/000-default.conf: -------------------------------------------------------------------------------- 1 | 2 | ServerAdmin webmaster@localhost 3 | DocumentRoot /var/www/html 4 | ServerName localhost 5 | 6 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/contributing/ci_cd_assets/manual_workflow_options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfheorg/openfhe-development/HEAD/docs/sphinx_rsts/contributing/ci_cd_assets/manual_workflow_options.png -------------------------------------------------------------------------------- /docs/sphinx_rsts/contributing/ci_cd_assets/run_manual_workflow_step2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfheorg/openfhe-development/HEAD/docs/sphinx_rsts/contributing/ci_cd_assets/run_manual_workflow_step2.png -------------------------------------------------------------------------------- /docs/sphinx_rsts/contributing/ci_cd_assets/run_manual_workflow_step3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfheorg/openfhe-development/HEAD/docs/sphinx_rsts/contributing/ci_cd_assets/run_manual_workflow_step3.png -------------------------------------------------------------------------------- /docs/sphinx_rsts/contributing/ci_cd_assets/run_manual_workflow_step5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfheorg/openfhe-development/HEAD/docs/sphinx_rsts/contributing/ci_cd_assets/run_manual_workflow_step5.png -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | @echo "OpenFHE has converted to CMake" 3 | @echo "Try this:" 4 | @echo mkdir build 5 | @echo cd build 6 | @echo cmake .. 7 | @echo make 8 | @echo make install \(to install in 'installed'\) 9 | -------------------------------------------------------------------------------- /configure/setup-eclipse-cmake.sh: -------------------------------------------------------------------------------- 1 | cmake -G "Eclipse CDT4 - Unix Makefile"s -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE -DCMAKE_ECLIPSE_MAKE_ARGUMENTS=-j3 -DCMAKE_ECLIPSE_VERSION=4.7.3 $* 2 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/contributing/ci_cd_assets/github_add_self_hosted_server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfheorg/openfhe-development/HEAD/docs/sphinx_rsts/contributing/ci_cd_assets/github_add_self_hosted_server.png -------------------------------------------------------------------------------- /docs/sphinx_rsts/contributing/ci_cd_assets/switch_default_branch_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfheorg/openfhe-development/HEAD/docs/sphinx_rsts/contributing/ci_cd_assets/switch_default_branch_diagram.png -------------------------------------------------------------------------------- /docs/static_docs/README.md: -------------------------------------------------------------------------------- 1 | # Purpose 2 | 3 | This folder, `static_docs` exists to host the various `md` pages that are linked to. This is used primarily for doxygen, as well as ease of navigation in a markdown render -------------------------------------------------------------------------------- /PreLoad.cmake: -------------------------------------------------------------------------------- 1 | # if(WIN32) 2 | if($ENV{MSYSTEM} MATCHES "MINGW") 3 | # message(WARNING "======================= Linking for MINGW") 4 | set(CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE) 5 | endif() 6 | -------------------------------------------------------------------------------- /src/pke/include/scheme/ckksrns/README.md: -------------------------------------------------------------------------------- 1 | # Security Considerations: 2 | 3 | See our [security notes](https://openfhe-development.readthedocs.io/en/latest/sphinx_rsts/intro/security.html) for a discussion on 4 | the CKKS scheme and important security notes. 5 | -------------------------------------------------------------------------------- /.pydevproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | Default 4 | python interpreter 5 | 6 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/contributing/contributing.rst: -------------------------------------------------------------------------------- 1 | Contributing to OpenFHE 2 | ==================================== 3 | 4 | .. toctree:: 5 | :maxdepth: 1 6 | :caption: Contents: 7 | 8 | developer_ci_cd_docs.rst 9 | user_ci_cd_docs.rst 10 | contributing_workflow.rst 11 | rebasing_off_main.rst 12 | style_guide.rst 13 | -------------------------------------------------------------------------------- /OpenFHEConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | set(PACKAGE_VERSION "@OPENFHE_VERSION@") 2 | 3 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 4 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 5 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 6 | else() 7 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 8 | if("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 9 | set(PACKAGE_VERSION_EXACT TRUE) 10 | endif() 11 | endif() 12 | -------------------------------------------------------------------------------- /src/pke/README.md: -------------------------------------------------------------------------------- 1 | # Directory Structure 2 | 3 | ## Examples: 4 | 5 | We provide the following examples: 6 | 7 | - various operations across the various schemes including CKKS, BGV, BFV. 8 | 9 | - serialization of ciphertexts, and cryptocontexts (Cryptocontexts are the main object we use to interact with the 10 | various crypto objects) 11 | 12 | - threshold FHE 13 | 14 | ## include 15 | 16 | - Header files 17 | 18 | ## lib 19 | 20 | - implementation of the header files 21 | 22 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third-party/google-benchmark"] 2 | path = third-party/google-benchmark 3 | url = https://github.com/google/benchmark.git 4 | [submodule "third-party/google-test"] 5 | path = third-party/google-test 6 | url = https://github.com/google/googletest.git 7 | [submodule "third-party/gperftools"] 8 | path = third-party/gperftools 9 | url = https://github.com/gperftools/gperftools.git 10 | [submodule "third-party/cereal"] 11 | path = third-party/cereal 12 | url = https://github.com/openfheorg/cereal.git 13 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/intro/get_started.rst: -------------------------------------------------------------------------------- 1 | Getting Started 2 | ==================================== 3 | 4 | Welcome to the OpenFHE webpage! 5 | 6 | .. note:: If you're looking to get up to speed quickly, visit our :ref:`quickstart ` page. 7 | 8 | .. toctree:: 9 | :maxdepth: 1 10 | :caption: Contents: 11 | 12 | directory_structure.rst 13 | security.rst 14 | installation/installation.rst 15 | using_the_library.rst 16 | building_user_applications.rst 17 | editor_setup.rst 18 | exceptions_in_openfhe.rst 19 | -------------------------------------------------------------------------------- /cicd/github-runner/user-data.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | update 4 | sudo apt update 5 | 6 | # install cmake 7 | sudo apt install cmake=3.16.3-1ubuntu1 8 | 9 | # install clagn 10 | sudo apt-get install clang-10 11 | 12 | # install required packages 13 | sudo apt-get install build-essential 14 | sudo apt-get install autoconf -y 15 | sudo apt-get install -y libntl-dev -y 16 | sudo apt-get install -y libgmp-dev -y 17 | sudo apt-get install libtool -y 18 | 19 | # for documen 20 | sudo apt-get install doxygen -y 21 | sudo apt-get install graphviz -y 22 | -------------------------------------------------------------------------------- /src/core/include/lattice/hal/README.md: -------------------------------------------------------------------------------- 1 | # Hardware Abstraction Layer (HAL) 2 | 3 | ```mermaid 4 | graph BT 5 | a[DCRTPolyInterface] --> |Inherited by|b[DCRTPoly - HAL Default]; 6 | ``` 7 | 8 | This hardware abstraction layer allows OpenFHE to use a variety of device backends while still allowing for high performance. As of March 31st 2022, we have the default backend, and the [Intel HEXL](https://github.com/intel/hexl) backend. 9 | 10 | ## Note: 11 | 12 | Follow the convention set by the [hexl](hexl) implementation to extend the supported backends. 13 | -------------------------------------------------------------------------------- /CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # Ignore all filters: 2 | #filter=-whitespace 3 | filter=-whitespace/line_length 4 | filter=-whitespace/newline 5 | filter=-whitespace/indent 6 | 7 | #filter=-build 8 | filter=-build/include_subdir 9 | filter=-build/include_order 10 | filter=-build/header_guard 11 | filter=-build/c++11 12 | filter=-build/namespaces 13 | 14 | #filter=-readability 15 | filter=-readability/braces 16 | filter=-readability/todo 17 | filter=-readability/fn_size 18 | 19 | #filter=-runtime 20 | filter=-runtime/references 21 | filter=-runtime/string 22 | 23 | #filter=-legal 24 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Documentation 2 | 3 | ## Local Builds 4 | 5 | - This is meant for testing locally, particularly if you do not have admin access on the [readthedocs](https://readthedocs.org/) 6 | 7 | - Building: run `make html` while in this directory. 8 | 9 | ## Testing Changes 10 | 11 | 1) run `pip install restview` 12 | 13 | 2) run `restivew X.rst` which will render that file. 14 | 15 | 16 | ## Remote Builds 17 | 18 | - Specifically for readthedocs, the system will automatically handle the builds for the `main` and `latest` branches. For anything else, reach 19 | out to the admins for permissions. 20 | 21 | -------------------------------------------------------------------------------- /docker/benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Pablo Echegorri 4 | # 5-3-2020 5 | # pabloechegorri@gmail.com 6 | 7 | ## 8 | ## Copy disclaimer here below 9 | 10 | # benchmark examples extras 11 | 12 | BENCHMARKS=/openfhe-development/build/bin/benchmark/* 13 | RESULTS=/var/www/html/benchmark.html 14 | 15 | echo "" >> $RESULTS 16 | echo "" >> $RESULTS 17 | for benchmark in $BENCHMARKS 18 | do 19 | echo "Running $benchmark" 20 | echo "
" >> $RESULTS
21 |     $benchmark > >(tee -a $RESULTS) 2> >(tee -a $RESULTS >&2)
22 |     echo -e "\n
" >> $RESULTS 23 | 24 | done 25 | echo "" >> $RESULTS 26 | 27 | -------------------------------------------------------------------------------- /docs/conf_theme.rst: -------------------------------------------------------------------------------- 1 | .. code-block:: py 2 | 3 | # The name of the Pygments (syntax highlighting) style to use. 4 | # `sphinx` works very well with the RTD theme, but you can always change it 5 | pygments_style = 'sphinx' 6 | 7 | # on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org 8 | on_rtd = os.environ.get('READTHEDOCS', None) == 'True' 9 | 10 | if not on_rtd: # only import and set the theme if we're building docs locally 11 | import sphinx_rtd_theme 12 | html_theme = 'sphinx_rtd_theme' 13 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] 14 | 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files you want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.c text 7 | *.cc text 8 | *.cpp text 9 | *.h text 10 | *.y text 11 | *.l text 12 | *.java text 13 | *.mac text 14 | *.txt text 15 | *.sh text 16 | *.py text 17 | Makefile* text 18 | 19 | # Declare files that will always have CRLF line endings on checkout. 20 | *.sln text eol=crlf 21 | 22 | # Denote all files that are truly binary and should not be modified. 23 | *.png binary 24 | *.jpg binary 25 | *.xlsx binary 26 | *.lz binary 27 | *.gz binary 28 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/modules/core/utils/core_utils.rst: -------------------------------------------------------------------------------- 1 | Core Utils Documentation 2 | ==================================== 3 | 4 | Documentation for `core/include/utils/ `_ 5 | 6 | .. toctree:: 7 | :maxdepth: 3 8 | :caption: Sub-Contents: 9 | 10 | block_allocator.rst 11 | prng.rst 12 | 13 | .. contents:: Page Contents 14 | :local: 15 | 16 | 17 | Core Utils 18 | ------------------------ 19 | 20 | Contains utils for the underlying math layer including the following capabilities: 21 | 22 | - debugging utilities 23 | 24 | - memory management utilities 25 | 26 | - parallel operations 27 | 28 | - serialization 29 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Set the version of Python and other tools you might need 9 | build: 10 | os: ubuntu-22.04 11 | tools: 12 | python: "3.11" 13 | apt_packages: 14 | - graphviz 15 | 16 | # Build documentation in the docs/ directory with Sphinx 17 | sphinx: 18 | configuration: docs/conf.py 19 | 20 | # We recommend specifying your dependencies to enable reproducible builds: 21 | # https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 22 | python: 23 | install: 24 | - requirements: docs/requirements.txt 25 | -------------------------------------------------------------------------------- /src/core/include/utils/README.md: -------------------------------------------------------------------------------- 1 | # Misc. Utils 2 | 3 | ## Block Allocator 4 | 5 | - Utility for allocating and freeing fixed blocks of memory memory. 6 | 7 | - Prevents memory faults by using a heap 8 | 9 | - Basically a custom memory management system. 10 | 11 | ## PRNG 12 | 13 | - Our cryptographic hash function is based off of [Blake2b](https://blake2.net), which allows fast hashing. 14 | 15 | - To define new `PRNG` engines, refer to [blake2engine.h](prng/blake2engine.h). 16 | 17 | - Additionally, we refer users to [sampling-readme](https://openfhe-development.readthedocs.io/en/latest/assets/sphinx_rsts/modules/core/math/sampling.html) for more information about sampling in OpenFHE, as well as how to use these samplers. -------------------------------------------------------------------------------- /src/core/include/utils/prng/README.md: -------------------------------------------------------------------------------- 1 | # PRNG Engine(s) 2 | 3 | Refer to our [readthedocs - PRNG Engine(s)](https://openfhe-development.readthedocs.io/en/latest/sphinx_rsts/modules/core/utils/prng.html) for more information. 4 | 5 | Additionally, we refer users to [sampling documentation](https://openfhe-development.readthedocs.io/en/latest/sphinx_rsts/modules/core/math/sampling.html) for 6 | more information about sampling in OpenFHE, as well as how to use these samplers. 7 | 8 | ## Blake2 9 | 10 | - Our cryptographic hash function is based off of [Blake2b](https://blake2.net), which allows fast hashing. 11 | 12 | ## Using a custom PRNG Engine 13 | 14 | To define new `PRNG` engines, refer to [blake2engine.h](blake2engine.h). 15 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | alabaster==0.7.12 2 | Babel==2.9.1 3 | breathe==4.33.1 4 | certifi>=2023.7.22 5 | charset-normalizer==2.0.12 6 | docutils==0.17.1 7 | exhale>=0.3.0 8 | idna>=3.7 9 | imagesize==1.3.0 10 | importlib-metadata>=4.0.0 11 | jinja2>=3.1.3 12 | MarkupSafe>=2.0.0 13 | packaging==21.3 14 | Pygments>=2.15.0 15 | pyparsing==3.0.7 16 | pytz==2021.3 17 | requests>=2.31.0 18 | snowballstemmer==2.2.0 19 | Sphinx==4.4.0 20 | sphinx-rtd-theme==1.0.0 21 | sphinxcontrib-applehelp==1.0.2 22 | sphinxcontrib-devhelp==1.0.2 23 | sphinxcontrib-htmlhelp==2.0.0 24 | sphinxcontrib-jsmath==1.0.1 25 | sphinxcontrib-mermaid==0.7.1 26 | sphinxcontrib-qthelp==1.0.3 27 | sphinxcontrib-serializinghtml==1.1.5 28 | urllib3>=1.26.18 29 | zipp>=3.19.1 30 | -------------------------------------------------------------------------------- /configure/config_core.in: -------------------------------------------------------------------------------- 1 | //================================================== 2 | // DO NOT TOUCH THIS FILE! It is generated by cmake 3 | //================================================== 4 | #ifndef __CMAKE_GENERATED_CONFIG_CORE_H__ 5 | #define __CMAKE_GENERATED_CONFIG_CORE_H__ 6 | 7 | #cmakedefine WITH_BE2 8 | #cmakedefine WITH_BE4 9 | #cmakedefine WITH_NOISE_DEBUG 10 | #cmakedefine WITH_REDUCED_NOISE 11 | #cmakedefine WITH_NTL 12 | #cmakedefine WITH_TCM 13 | #cmakedefine WITH_OPENMP 14 | #cmakedefine WITH_NATIVEOPT 15 | 16 | #cmakedefine CKKS_M_FACTOR @CKKS_M_FACTOR@ 17 | #cmakedefine HAVE_INT128 @HAVE_INT128@ 18 | #cmakedefine HAVE_INT64 @HAVE_INT64@ 19 | #cmakedefine MATHBACKEND @MATHBACKEND@ 20 | #cmakedefine NATIVEINT @NATIVEINT@ 21 | 22 | #endif // __CMAKE_GENERATED_CONFIG_CORE_H__ 23 | -------------------------------------------------------------------------------- /docker/upload-tagged-docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | while getopts ":r:j:t:" OPTION 3 | do 4 | case $OPTION in 5 | t) 6 | TAG=$OPTARG;; 7 | j) 8 | THREADS=$OPTARG;; 9 | r) 10 | REPOSITORY=$OPTARG;; 11 | 12 | \?) 13 | echo "Please use the -r tag to set a repository, -j tag to set the number of threads for make and -t flag to set a tag" 14 | exit 15 | ;; 16 | esac 17 | done 18 | 19 | docker build -t $REPOSITORY . --build-arg no_threads=$THREADS --build-arg repository=$REPOSITORY --build-arg tag=$TAG 20 | docker run -dit --name openfhe -p 80:80 $REPOSITORY 21 | docker commit openfhe openfhe:$TAG 22 | docker login registry.github.com 23 | docker image tag openfhe:$TAG registry.github.com/openfheorg/$REPOSITORY/$TAG:$TAG 24 | docker push registry.github.com/openfheorg/$REPOSITORY/$TAG:$TAG 25 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/modules/core/core.rst: -------------------------------------------------------------------------------- 1 | Core Library Documentation 2 | ==================================== 3 | 4 | `Github Src `_ 5 | 6 | File Listings 7 | ----------------------- 8 | 9 | `OpenFHE Core Top-Level Include (openfhecore.h) `_ 10 | 11 | - Top-level ``#include`` for access to all capabilities 12 | 13 | `Unit Test Definitions (testdefs.h) `_ 14 | 15 | - Defines various macros for unit testing 16 | 17 | `Version (version.h) `_ 18 | 19 | - Get the current `OpenFHE` version by parsing the `CMAKE` version 20 | -------------------------------------------------------------------------------- /docs/the_requirements.rst: -------------------------------------------------------------------------------- 1 | .. code-block:: nginx 2 | 3 | alabaster==0.7.12 4 | Babel==2.9.1 5 | breathe==4.33.1 6 | certifi==2021.10.8 7 | charset-normalizer==2.0.12 8 | docutils==0.17.1 9 | exhale>=0.3.0 10 | idna==3.3 11 | imagesize==1.3.0 12 | importlib-metadata>=4.0.0 13 | Jinja2==3.0.3 14 | MarkupSafe>=2.0.0 15 | packaging==21.3 16 | Pygments==2.11.2 17 | pyparsing==3.0.7 18 | pytz==2021.3 19 | requests==2.27.1 20 | snowballstemmer==2.2.0 21 | Sphinx==4.4.0 22 | sphinx-rtd-theme==1.0.0 23 | sphinxcontrib-applehelp==1.0.2 24 | sphinxcontrib-devhelp==1.0.2 25 | sphinxcontrib-htmlhelp==2.0.0 26 | sphinxcontrib-jsmath==1.0.1 27 | sphinxcontrib-mermaid==0.7.1 28 | sphinxcontrib-qthelp==1.0.3 29 | sphinxcontrib-serializinghtml==1.1.5 30 | urllib3==1.26.9 31 | zipp==3.7.0 32 | 33 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # To check files before committing them: 2 | # pre-commit run --files [file1] [file2] ... 3 | repos: 4 | - repo: https://github.com/pre-commit/pre-commit-hooks 5 | rev: v2.5.0 6 | hooks: 7 | - id: trailing-whitespace 8 | - id: end-of-file-fixer 9 | - id: check-merge-conflict 10 | - id: mixed-line-ending 11 | - id: check-byte-order-marker 12 | - repo: local 13 | hooks: 14 | - id: clang-format 15 | name: clang-format 16 | entry: clang-format 17 | language: system 18 | files: \.(c|cc|cxx|cpp|h|hpp|hxx|js|proto)$ 19 | args: ["-i"] 20 | - id: cpplint 21 | name: cpplint 22 | entry: cpplint 23 | language: system 24 | files: \.(c|cc|cxx|cpp|h|hpp|hxx)$ 25 | args: ["--recursive"] 26 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = ExhaleCompanion 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile clean 16 | 17 | clean: 18 | rm -rf doxyoutput/ api/ 19 | # these are specific to the companion site, ignore this rm 20 | rm -f conf_extensions.rst conf_theme.rst 21 | @$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 22 | 23 | # Catch-all target: route all unknown targets to Sphinx using the new 24 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 25 | %: Makefile 26 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 27 | 28 | -------------------------------------------------------------------------------- /scripts/setup/NTL_and_GMP_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # required tools curl, tar, lzip 4 | # 5 | # sudo apt-get install -y curl tar lzip 6 | 7 | ## GMP AND NTL INSTALL 8 | ### GMP 9 | curl -O https://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.lz 10 | tar --lzip -xvf gmp-6.1.2.tar.lz 11 | ( \ 12 | pushd ./gmp-6.1.2 || exit -1; \ 13 | ./configure && \ 14 | make -j `nproc` && \ 15 | make check && \ 16 | sudo make install || exit -1 \ 17 | popd; \ 18 | ) 19 | 20 | rm gmp-6.1.2.tar.lz 21 | rm -rf gmp-6.1.2 22 | 23 | ### NTL 24 | curl -O https://libntl.org/ntl-10.5.0.tar.gz 25 | tar -xvf ntl-10.5.0.tar.gz 26 | ( \ 27 | pushd ./ntl-10.5.0/src || exit -1; \ 28 | ./configure NTL_THREADS=on NTL_THREAD_BOOST=on NTL_EXCEPTIONS=on SHARED=on NTL_STD_CXX11=on NTL_SAFE_VECTORS=off TUNE=generic && \ 29 | make -j `nproc` && \ 30 | make check && \ 31 | sudo make install || exit -1; \ 32 | popd; \ 33 | ) 34 | 35 | rm ntl-10.5.0.tar.gz 36 | rm -rf ntl-10.5.0 37 | -------------------------------------------------------------------------------- /src/binfhe/README.md: -------------------------------------------------------------------------------- 1 | # Directory Structure 2 | 3 | ## Examples: 4 | 5 | We provide the following classes of examples for symmetric encryption and public-key encryption: 6 | 7 | ### Simple Boolean 8 | 9 | - evaluation of binary gates and multi-input gates 10 | - bootstrapping for `AP` (DM) and `GINX` (CGGI) and `LMKCDEY` 11 | - serialization to binary and json formats 12 | 13 | ### Evaluation of functions 14 | 15 | The supported function evaluations are based on the functionalities described 16 | in [Large-Precision Homomorphic Sign Evaluation using FHEW/TFHE Bootstrapping](https://eprint.iacr.org/2021/1337). 17 | 18 | - digit decomposition 19 | - floor function (reduce by a certain number of bits) 20 | - arbitrary function(lookup table) _f: Zp -> Zp_ on the input ciphertext 21 | - sign function to get the MSB of an input 22 | 23 | ## include 24 | 25 | - Header files 26 | 27 | ## lib 28 | 29 | - implementation of the header files 30 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/modules/pke/pke_scheme.rst: -------------------------------------------------------------------------------- 1 | PKE Scheme documentation 2 | ==================================== 3 | 4 | This is comprised of 3 folders: 5 | 6 | - `scheme `_, which contains the specifications of the different RNS implementations 7 | 8 | - `schemebase `_, which contains the base implementations of various functionalities 9 | 10 | - `schemerns `_, which contains the base RNS scheme implementation. 11 | 12 | At a high level, this can be thought of as: 13 | 14 | .. mermaid:: 15 | 16 | graph BT 17 | A[Scheme Base] --> |Inherited by|B[Scheme RNS]; 18 | B[Scheme RNS] --> |Inherited by|D[Scheme: CKKS-RNS]; 19 | B[Scheme RNS] --> |Inherited by|E[Scheme: BGV-RNS]; 20 | B[Scheme RNS] --> |Inherited by|F[Scheme: BFV-RNS]; 21 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/modules/modules.rst: -------------------------------------------------------------------------------- 1 | OpenFHE Modules 2 | ================================================= 3 | 4 | Understanding the various Modules 5 | ------------------------------------ 6 | 7 | .. mermaid:: 8 | 9 | graph BT 10 | A[CORE
- math implementation
- lattice implementation
- serialization] --> B[PKE
-generalized FHE]; 11 | A --> C[BINFHE
- boolean FHE]; 12 | B --> D[Application
- encrypted data analysis
- privacy-compliant data sharing]; 13 | C --> D; 14 | 15 | Boolean FHE 16 | ---------------------------- 17 | .. toctree:: 18 | :maxdepth: 2 19 | 20 | binfhe.rst 21 | 22 | 23 | Core 24 | ---------------------------- 25 | .. toctree:: 26 | :maxdepth: 2 27 | 28 | core/core.rst 29 | core/lattice/core_lattice.rst 30 | core/lattice/hal.rst 31 | core/math/core_math.rst 32 | core/utils/core_utils.rst 33 | 34 | 35 | Public-Key Encryption (PKE) 36 | ---------------------------- 37 | .. toctree:: 38 | :maxdepth: 2 39 | 40 | pke/pke.rst 41 | pke/pke_encoding.rst 42 | pke/pke_keys.rst 43 | pke/pke_keyswitch.rst 44 | pke/pke_scheme.rst 45 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/intro/tutorials.rst: -------------------------------------------------------------------------------- 1 | Tutorials on Cryptographic Capabilities 2 | ==================================== 3 | 4 | - `Description of the CryptoContext parameters for BGV, BFV, and CKKS `_ 5 | 6 | - `CKKS Noise Flooding `_ 7 | 8 | - `Smooth Arbitrary Function Evaluation in CKKS `_ 9 | 10 | - `Scheme Switching between CKKS and FHEW/TFHE `_ 11 | 12 | - `Threshold FHE for BGV, BFV, and CKKS `_ 13 | 14 | - `Interactive CKKS Bootstrapping `_ 15 | 16 | - `CKKS Composite Scaling `_ 17 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # OpenFHE Code Components 2 | 3 | ```mermaid 4 | flowchart BT 5 | A[CORE
- math implementation
- lattice implementation
- serialization] --> B[PKE
-SIMD FHE]; 6 | A --> C[BINFHE
- binary FHE]; 7 | B --> D[Application
- encrypted data analysis
- privacy-compliant data sharing]; 8 | C --> D; 9 | ``` 10 | 11 | # binFHE 12 | 13 | - Boolean arithmetic, comparisons, and aribtrary function evaluation based on DM and CGGI schemes 14 | 15 | # core 16 | 17 | - underlying implementation providing the base that `binFHE` and `pke` are built off of 18 | 19 | # pke 20 | 21 | - integer and real-number arithmetic based on BGV, BFV, and CKKS schemes 22 | 23 | ## Warning 24 | 25 | Although the OpenFHE team has provided various utility functions to make OpenFHE accessible to 26 | non-cryptographers, it is still necessary for the end-users to carefully consider how they are using the code. Improper 27 | use can result in leaked information. 28 | Use of OpenFHE in production environments should be reviewed by homomorphic encryption experts. 29 | 30 | Additionally, see our [Security Considerations](../docs/static_docs/Security.md) for considerations that should be taken into account 31 | in your work. 32 | -------------------------------------------------------------------------------- /src/core/include/utils/blockAllocator/README.md: -------------------------------------------------------------------------------- 1 | # Block Allocator 2 | 3 | ## Motivation 4 | 5 | We create stl-compatible custom block allocators for various types which allows for fast allocation and free-ing. 6 | 7 | **Note**: the `xY.h` is such that the `x` describes that we are using the custom allocator class, and the `Y` describes the underlying type e.g: `list` or `map`, etc. 8 | 9 | ## References 10 | 11 | For more context, read: 12 | 13 | 1) [An Efficient C++ Fixed Block Memory Allocator]( http://www.codeproject.com/Articles/1083210/An-efficient-Cplusplus-fixed-block-memory-allocato) 14 | 15 | TL;DR global heap allocation can be slow and nondeterministic. Also, this eliminates the possibility of memory allocation fault caused by a fragmented heap. 16 | 17 | 2) [Replace malloc/free with a Fast Fixed Block Memory Allocator](https://www.codeproject.com/Articles/1084801/Replace-malloc-free-with-a-fast-fixed-block-memory) 18 | 19 | TL;DR replaces `malloc` and `free` with `xmalloc` and `xfree` which take advantage of the `Allocator` from above 20 | 21 | 3) [A Custom STL std::allocator Replacement Improves Performance](https://www.codeproject.com/Articles/1089905/A-Custom-STL-std-allocator-Replacement-Improves-Pe) 22 | 23 | TL;DR describes how to create a STL-compatible version of the above code. -------------------------------------------------------------------------------- /scripts/setup/linux_platform_packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script can be used to install all of the requistes for the Linux Platform 4 | # 5 | 6 | # run update before installing every package 7 | 8 | # install cmake 9 | sudo apt-get update 10 | sudo apt-get install -y cmake 11 | 12 | # install required packages 13 | sudo apt-get update 14 | sudo apt-get install -y build-essential 15 | sudo apt-get update 16 | sudo apt-get install -y autoconf 17 | sudo apt-get update 18 | sudo apt-get install -y libtool 19 | sudo apt-get update 20 | sudo apt-get install -y libgmp-dev 21 | sudo apt-get update 22 | sudo apt-get install -y libntl-dev 23 | 24 | # install all necessary and additional compilers 25 | sudo apt-get update 26 | sudo apt-get install -y g++-9 g++-10 g++-11 g++-12 27 | sudo apt-get update 28 | sudo apt-get install -y clang-12 clang-13 clang-14 clang-15 29 | 30 | # for documentation 31 | sudo apt-get update 32 | sudo apt-get install -y doxygen 33 | sudo apt-get update 34 | sudo apt-get install -y graphviz 35 | 36 | # python packages 37 | sudo apt-get update 38 | sudo apt-get install -y python3-pip 39 | sudo apt-get update 40 | sudo pip install pybind11[global] 41 | sudo apt-get update 42 | sudo apt-get install -y python3-pytest 43 | # to verify pytest installation: python3 -m pip show pytest -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | *~ 3 | *.o 4 | *.o.d 5 | *.gcov 6 | bin/ 7 | build*/ 8 | cmake-build-debug 9 | docs/doxygen 10 | docs/sphinx 11 | _build/ 12 | embuild 13 | api/ 14 | doxyoutput/ 15 | 16 | 17 | .ipynb_checkpoints 18 | 19 | test/build 20 | test/bin 21 | output.txt 22 | Doxyfile 23 | apidoc_warning_logfile.txt 24 | third-party/distros/gmp-6.1.1 25 | third-party/distros/gmp-6.1.2 26 | third-party/distros/ntl-10.3.0 27 | third-party/distros/ntl-10.5.0 28 | third-party/include/NTL 29 | third-party/include/gmp.h 30 | third-party/lib 31 | third-party/share 32 | **/gmp-* 33 | **/ntl-* 34 | timing/ 35 | gmon.out 36 | ## .gitattributes 37 | # Except this file 38 | !.gitignore 39 | 40 | .idea 41 | */**/*.gch 42 | *.a 43 | *.class 44 | 45 | ## for the moment 46 | .cproject 47 | .metadata/ 48 | .project 49 | .settings/ 50 | RemoteSystemTempFiles/ 51 | .classpath 52 | .externalToolBuilders/ 53 | /Default/ 54 | 55 | .DS_Store 56 | 57 | # Ignore intellij project files/cmake files 58 | # CMakeLists.txt 59 | .idea/ 60 | 61 | src/circuit/lib/scan.cpp 62 | src/circuit/lib/parse.cpp 63 | src/circuit/lib/parse.hpp 64 | src/circuit/lib/*.hh 65 | 66 | # vagrant output 67 | .vagrant/ 68 | *.log 69 | 70 | # gtest output files 71 | test_detail.xml 72 | 73 | # Visual Studio Code 74 | .vscode 75 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | # https://clang.llvm.org/docs/ClangFormatStyleOptions.html 2 | # Manual run to reformat a file "foo.cpp": clang-format -i --style=file foo.cpp 3 | ####################################################################### 4 | BasedOnStyle: Google 5 | ####################################################################### 6 | Language: Cpp 7 | # DisableFormat: true 8 | AccessModifierOffset: -4 9 | # AlignArrayOfStructures: Right (enable this if clang-format-13 or newer is installed) 10 | AlignConsecutiveMacros: true 11 | AlignConsecutiveAssignments: true 12 | #AlignConsecutiveDeclarations: true 13 | AlignEscapedNewlines: Left 14 | AlignOperands: true 15 | AllowShortFunctionsOnASingleLine: Empty 16 | AllowShortIfStatementsOnASingleLine: Never 17 | AllowShortLambdasOnASingleLine: Inline 18 | AllowShortLoopsOnASingleLine: false 19 | BreakBeforeBraces: Custom 20 | BraceWrapping: 21 | BeforeCatch: true 22 | BeforeElse: true 23 | BreakBeforeTernaryOperators: false 24 | BreakStringLiterals: false 25 | ColumnLimit: 120 26 | DerivePointerAlignment: false 27 | #EmptyLineBeforeAccessModifier: true (enable this if clang-format-13 or newer is installed) 28 | IndentPPDirectives: BeforeHash 29 | IndentWidth: 4 30 | PointerAlignment: Left 31 | ReflowComments: false 32 | SortIncludes: false 33 | UseTab: Never 34 | -------------------------------------------------------------------------------- /src/pke/include/key/README.md: -------------------------------------------------------------------------------- 1 | # Keys 2 | 3 | This folder contains the header files of the various keys that are defined within `Open-FHE`. Refer to [OpenFHE PKE Keys](https://openfhe-development.readthedocs.io/en/latest/assets/sphinx_rsts/modules/pke/pke_keys.html) 4 | 5 | ## Key Class Inheritance 6 | ```mermaid 7 | graph TD 8 | Key[Key: Base Class] --> |Inherits|EvalKeyImpl 9 | EvalKeyImpl --> |Inherits|EvalKeyRelinImpl 10 | ``` 11 | 12 | ## KeyPair 13 | 14 | ```mermaid 15 | graph TD 16 | PrivKey[Private Key] --> |container|KP[Key Pair] 17 | PubKey[Public Key] --> |container|KP[Key Pair] 18 | ``` 19 | 20 | [All Key](allkey.h) 21 | - Top-level `#include` for access to all capabilities 22 | 23 | [Eval Key](evalkey.h) 24 | - Inherits from the base [Key](key.h) class. 25 | - Serves as base class for [Eval Key Relin](evalkeyrelin.h) 26 | 27 | [Eval Key Relin](evalkeyrelin.h) 28 | - Get and set relinearization elements 29 | - Inherits from [Eval Key](evalkey.h) 30 | 31 | [Key](key.h) 32 | - Base Key class 33 | 34 | 35 | [Key Serialization](key-ser.h) 36 | - Capabilities for serializing the keys using [Cereal](https://github.com/USCiLab/cereal) 37 | 38 | [Key Pair](keypair.h) 39 | - Container for the [private key](privatekey.h) and [public key](publickey.h) 40 | 41 | [Private Key](privatekey.h) 42 | 43 | 44 | [Public Key](publickey.h) 45 | -------------------------------------------------------------------------------- /src/core/include/README.md: -------------------------------------------------------------------------------- 1 | # Core Library Implementation 2 | 3 | ```mermaid 4 | flowchart BT 5 | A[Math
- Provides base math operations
- Supports various math backends] --> B[Lattice
- Represent polynomial rings
- support operations over polynomial rings.
- calls math layer for lower-level math ops]; 6 | B[Lattice
- Represent polynomial rings
- support operations over polynomial rings.
- calls math layer for lower-level math ops] --> C[Core Layer]; 7 | ``` 8 | 9 | Contains the underlying primitives that are used in both `pke` and `binfhe`. 10 | 11 | ## [Lattice](lattice) 12 | 13 | - Contains files that support lattice/polynomial-layer operations in OpenFHE. This layer is used to represent polynomial rings and support operations over those rings. 14 | 15 | - As can be seen above, this is the "middle" layer between higher-level lattice cryptography elements, and the lower level math operations. 16 | 17 | 18 | ## [Math](math) 19 | 20 | Contains various files describing the mathematical functionality supported in OpenFHE. For example: 21 | 22 | - modular arithmeric 23 | - sampling functions 24 | 25 | In addition, the hardware abstraction layer (HAL) is defined here. 26 | 27 | 28 | ## [Utils](utils) 29 | 30 | Contains various utilities: 31 | 32 | - debugging utilities 33 | - memory management utilities 34 | - parallel operations 35 | - serialization 36 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/intro/directory_structure.rst: -------------------------------------------------------------------------------- 1 | Directory Structure 2 | ==================================== 3 | 4 | The high-level structure of the OpenFHE library is as follows. 5 | 6 | Several of these directories may contain a README file with more specific information about the files in the directory. 7 | 8 | :: 9 | 10 | . 11 | ├── benchmark 12 | ├── build 13 | ├── doc 14 | ├── src 15 | ├────── binfhe 16 | ├────── core 17 | ├────── pke 18 | ├── test 19 | └── third-party 20 | 21 | The descriptions of library components are as follows: 22 | 23 | .. csv-table:: components 24 | :header: "Directory", "Description" 25 | 26 | "benchmark","Code for benchmarking OpenFHE library components, using the Google Benchmark frameworks" 27 | "build","Binaries and build scripts (this folder is created by the user)" 28 | "doc","Documentation of library components." 29 | "docker","Docker file and documentation." 30 | "src","Library source code. Each subcomponent has four or five subdirectories: include (for library header files), lib (for library source files), unittest (for google test cases), examples (for code samples), and optionally extras (for additional code samples)." 31 | "third-party","Code for distributions from third parties (includes NTL/GMP + git submodules for tcmalloc, cereal, google test, and google benchmark)" 32 | "test","Google unit test code" 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2022, OpenFHE 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | ARG repository="openfhe-development" 4 | ARG branch=main 5 | ARG tag=v0.9.1 6 | ARG CC_param=/usr/bin/gcc-10 7 | ARG CXX_param=/usr/bin/g++-10 8 | ARG no_threads=1 9 | 10 | ENV DEBIAN_FRONTEND=noninteractive 11 | ENV CC $CC_param 12 | ENV CXX $CXX_param 13 | 14 | #install pre-requisites for OpenFHE 15 | RUN apt update && apt install -y git \ 16 | build-essential \ 17 | gcc-10 \ 18 | g++-10 \ 19 | cmake \ 20 | autoconf \ 21 | clang-10 \ 22 | libomp5 \ 23 | libomp-dev \ 24 | doxygen \ 25 | graphviz \ 26 | libboost-all-dev=1.71.0.0ubuntu2 27 | 28 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* 29 | 30 | #git clone the openfhe-development repository and its submodules (this always clones the most latest commit) 31 | RUN git clone https://github.com/openfheorg/$repository.git && cd $repository && git checkout $branch && git checkout $tag && git submodule sync --recursive && git submodule update --init --recursive 32 | 33 | #installing OpenFHE and running tests 34 | RUN mkdir /$repository/build && cd /$repository/build && cmake .. && make -j $no_threads && make install && make testall 35 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/misc/license.rst: -------------------------------------------------------------------------------- 1 | OpenFHE License 2 | ================ 3 | 4 | BSD 2-Clause License 5 | 6 | Copyright (c) 2022, OpenFHE 7 | 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright notice, this 14 | list of conditions and the following disclaimer. 15 | 16 | 2. Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /.github/workflows/pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Pull-Request 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | - dev 8 | 9 | jobs: 10 | call: 11 | uses: openfheorg/openfhe-development/.github/workflows/generic_workflow.yml@github-ci 12 | with: 13 | runner: ${{ vars.RUNNER }} 14 | compiler: "GCC-14" 15 | native_backend: "all" 16 | mb2_jobs: "mb2" 17 | mb4_jobs: "mb4_tcm" 18 | mb6_jobs: "mb6" 19 | # cmake_args_map holds job specific additional cmake options. compiler flags, native_backend flag and 20 | # OpenMP flag are set in generic_workflow.yml 21 | cmake_args_map: '{ 22 | "default" : "-DBUILD_EXTRAS=ON", 23 | "mb2" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=2", 24 | "mb2_tcm" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=2 -DWITH_TCM=ON", 25 | "mb2_debug" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=2 -DCMAKE_BUILD_TYPE=Debug", 26 | "mb4" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=4", 27 | "mb4_tcm" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=4 -DWITH_TCM=ON", 28 | "mb4_debug" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=4 -DCMAKE_BUILD_TYPE=Debug", 29 | "mb6_ntl" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=6 -DWITH_NTL=ON", 30 | "mb6_ntl_tcm" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=6 -DWITH_NTL=ON -DWITH_TCM=ON", 31 | "mb6_ntl_debug_tcm" : "-DBUILD_EXTRAS=ON -DMATHBACKEND=6 -DWITH_NTL=ON -DWITH_TCM=ON -DCMAKE_BUILD_TYPE=Debug", 32 | }' 33 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/intro/exceptions_in_openfhe.rst: -------------------------------------------------------------------------------- 1 | Throwing Exceptions in OpenFHE 2 | =============================== 3 | 4 | The OpenFHE library will throw an OpenFHEException exception in the event of an unrecoverable error. A openfhe_error is a subclass of ``std::exception``. 5 | 6 | 7 | Programmers use the OPENFHE_THROW macro in exception.h to generate an exception. Each exception includes the filename, the function name and line number at which the exception was thrown as well as a programmer-defined message. 8 | 9 | 10 | OpenFHEException is defined in ``src/core/include/utils/exception.h``. 11 | 12 | 13 | Exceptions in critical regions and OMP threads 14 | ----------------------------------------------- 15 | 16 | An exception that is thrown in a critical region, or that is thrown within an OMP thread, must be caught in the same region where it is thrown. The program will abort if this is not done. 17 | 18 | If an exception must be thrown in a critical region or OMP thread, but must be caught in another thread, then it is necessary to catch the exception and re-throw it. Classes and sample code is provided in ``src/core/include/utils/exception.h`` to show how this is done. 19 | 20 | For example, the following code will catch and rethrow an exception thrown inside of a thread 21 | 22 | .. code-block:: c++ 23 | :linenos: 24 | 25 | ThreadException e; 26 | #pragma omp parallel for 27 | for(unsigned i=0; i`_ 5 | 6 | .. contents:: Page Contents 7 | :local: 8 | :backlinks: none 9 | 10 | Motivation 11 | ---------- 12 | 13 | We create stl-compatible custom block allocators for various types which allows for fast allocation and free-ing. 14 | 15 | .. note:: ``xY.h`` is such that the ``x`` describes that we are using the custom allocator class, and the ``Y`` describes the underlying type e.g: ``list`` or ``map``, etc. 16 | 17 | References 18 | ------------- 19 | 20 | For more context, read: 21 | 22 | 1) `An Efficient C++ Fixed Block Memory Allocator `_ 23 | 24 | TL;DR global heap allocation can be slow and nondeterministic. Also, this eliminates the possibility of memory allocation fault caused by a fragmented heap. 25 | 26 | 2) `Replace malloc/free with a Fast Fixed Block Memory Allocator `_ 27 | 28 | TL;DR replaces `malloc` and `free` with `xmalloc` and `xfree` which take advantage of the `Allocator` from above 29 | 30 | 3) `A Custom STL std::allocator Replacement Improves Performance `_ 31 | 32 | TL;DR describes how to create a STL-compatible version of the above code. 33 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/modules/core/lattice/hal.rst: -------------------------------------------------------------------------------- 1 | .. _hal: 2 | 3 | Core Lattice Hardware Abstraction Layer Documentation 4 | ====================================================== 5 | 6 | 7 | .. contents:: Page Contents 8 | :local: 9 | :backlinks: none 10 | 11 | Lattice HAL Introduction 12 | ---------------------------- 13 | 14 | .. mermaid:: 15 | 16 | graph BT 17 | a[DCRTPolyInterface] --> |Inherited by|b[DCRTPoly - HAL Default]; 18 | 19 | This hardware abstraction layer allows OpenFHE to use a variety of hardware-integrated backends while still allowing for high performance. As of March 31st 2022, we have the: 20 | 21 | - default backend 22 | 23 | - `Intel Hexl `_ backend 24 | 25 | .. note:: Follow the convention set by the the `OpenFHE HEXL code `_ to extend the supported backends. 26 | 27 | File Listing 28 | --------------- 29 | 30 | `DCRTPolyInterface (dcrtpoly-interface.h) `_ 31 | 32 | - Base class for ``DCRTPoly`` 33 | 34 | `DCRTPoly Interface Aliases (lat-backend-default.h) `_ 35 | 36 | - Defines aliases for the lattice default backend 37 | 38 | `Integer Lattice Double CRT Params (ildcrtparams.h) `_ 39 | 40 | - Inherits from ``DCRTPolyInterface`` and provides a public-facing interface used downstream by the various schemes. 41 | -------------------------------------------------------------------------------- /docs/static_docs/Webinars.md: -------------------------------------------------------------------------------- 1 | OpenFHE Webinars 2 | ================= 3 | 4 | The OpenFHE library has a YouTube channel! Full of rich detailed content on repository, examples, and general homomorphic encryption! Please visit [OpenFHE/PALISADE Homomorphic Encryption Library](https://www.youtube.com/channel/UC1qByOsQina1rpZ8AGl5TZw) and subscribe for the latest videos! 5 | 6 | Webinar List 7 | ------------ 8 | 9 | - [OpenFHE/PALISADE Webinar #1 - Introducing OpenFHE/PALISADE](https://youtu.be/FLGeMd3eiQY) 10 | - [OpenFHE/PALISADE Webinar #2 A - HE Tutorial Series Part 1: Introduction to Homomorphic Encryption](https://youtu.be/rMDoZdH53ZM) 11 | - [OpenFHE/PALISADE Webinar #2 B - HE Tutorial Series Part 2: Boolean Arithmetic with Applications](https://youtu.be/aKcf5vd8lLs) 12 | - [OpenFHE/PALISADE Webinar #3 A - HE Tutorial Series Part 3: Integer Arithmetic](https://youtu.be/1a7yxnLj4PE) 13 | - [OpenFHE/PALISADE Webinar #3 B - HE Tutorial Series Part 4: Integer Applications](https://youtu.be/7Rpeb1YNSRs) 14 | - [OpenFHE/PALISADE Webinar #4 - HE Tutorial Series Part 5: Introduction to Multiparty Homomorphic Encryption](https://youtu.be/9Fa6rFUyQ_w) 15 | - [OpenFHE/PALISADE Webinar #5 - HE Serialization for Applications](https://youtu.be/-2zaJ2C4Guo) 16 | - [OpenFHE/PALISADE Webinar #6 - HE Tutorial Series Part 6: Introduction to Approximate Homomorphic Encryption](https://youtu.be/_s1B128sqaI) 17 | - [OpenFHE/PALISADE Webinar #7 A - Secure Large-Scale Genome-Wide Association Studies using Homomorphic Encryption](https://youtu.be/rTmL1Iaoslo) 18 | - [OpenFHE/PALISADE Webinar #7 B - Best Practices for Building Efficient Homomorphic Encryption Solutions](https://youtu.be/oxJGOhqLd-E) 19 | -------------------------------------------------------------------------------- /benchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( ../src/core/include ) 2 | include_directories( ../src/core/lib ) 3 | include_directories( ../src/pke/include ) 4 | include_directories( ../src/binfhe/include ) 5 | 6 | set( REGEX_FLAG -DHAVE_STD_REGEX ) 7 | 8 | if ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) 9 | set( WARNING_FLAG "" ) 10 | else() 11 | set( WARNING_FLAG -Wno-unused-but-set-variable ) 12 | endif() 13 | 14 | if( BUILD_SHARED ) 15 | set (BMLIBS PUBLIC OPENFHEpke PUBLIC OPENFHEbinfhe PUBLIC OPENFHEcore ${THIRDPARTYLIBS} PUBLIC benchmark ${OpenMP_CXX_FLAGS}) 16 | endif() 17 | 18 | if( BUILD_STATIC ) 19 | set (BMLIBS ${BMLIBS} PUBLIC OPENFHEpke_static PUBLIC OPENFHEbinfhe_static PUBLIC OPENFHEcore_static ${THIRDPARTYSTATICLIBS} PUBLIC benchmark ${OpenMP_CXX_FLAGS}) 20 | endif() 21 | 22 | set (BMAPPS "") 23 | file (GLOB BMARK_SRC_FILES CONFIGURE_DEPENDS src/*.cpp) 24 | foreach (app ${BMARK_SRC_FILES}) 25 | get_filename_component ( exe ${app} NAME_WE ) 26 | add_executable ( ${exe} ${app} ) 27 | set_property(TARGET ${exe} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/benchmark) 28 | target_include_directories( ${exe} PUBLIC ../third-party/google-benchmark/include ) 29 | set_target_properties( ${exe} PROPERTIES COMPILE_FLAGS 30 | "${REGEX_FLAG} -DHAVE_STEADY_CLOCK -DNDEBUG ${WARNING_FLAG}" ) 31 | target_link_libraries ( ${exe} ${BMLIBS} ${ADDITIONAL_LIBS}) 32 | set (BMAPPS ${BMAPPS} ${exe}) 33 | endforeach() 34 | 35 | add_custom_target( allbenchmark ) 36 | add_dependencies( allbenchmark ${BMAPPS} ) 37 | 38 | add_custom_command( OUTPUT benchmarkinfocmd COMMAND echo Builds benchmark lib and these apps: ${BMAPPS} ) 39 | add_custom_target( benchmarkinfo DEPENDS benchmarkinfocmd ) 40 | -------------------------------------------------------------------------------- /src/pke/examples/INTERACTIVE_BOOTSTRAPPING.md: -------------------------------------------------------------------------------- 1 | OpenFHE Library - Interactive Bootstrapping 2 | ===================================================================================================== 3 | 4 | OpenFHE provides two methods for interactive CKKS bootstrapping: 5 | * The $n$-party method described in Appendix E of https://eprint.iacr.org/2023/1203. This method is an optimized version of the method originally proposed in https://eprint.iacr.org/2020/304 and https://arxiv.org/abs/2009.00349. 6 | * The 2-party method proposed in Appendix D of https://eprint.iacr.org/2023/1203, which is based on the idea of distributed rounding. 7 | 8 | The 2-party method is more efficient than the $n$-party method for the case when $n=2$. It requires only one extra RNS limb in contrast to 2-3 extra RNS limbs for the $n$-party bootstrapping for the FIXED* modes, and an exra RNS limb for both methods for the FLEXIBLE* modes of CKKS. Moreover, the computational and communication complexity of the $2$-party interactive bootstrapping is smaller than for the $n$-party method. 9 | 10 | ## Examples for the $2$-party interactive bootstrapping 11 | 12 | - [interactive-bootstrapping.cpp](interactive-bootstrapping.cpp) shows two examples of $2$-party interactive bootstrapping: interactive bootstrapping without a computation and interactive bootstrapping together with a Chebyshev interpolation 13 | 14 | ## Examples for the $n$-party interactive bootstrapping 15 | 16 | - [tckks-interactive-mp-bootstrapping.cpp](tckks-interactive-mp-bootstrapping.cpp): An example of $n$-party interactive bootstrapping by itself 17 | - [tckks-interactive-mp-bootstrapping-Chebyshev.cpp](tckks-interactive-mp-bootstrapping-Chebyshev.cpp): An example of $n$-party interactive bootstrapping together with Chebyshev interpolation 18 | -------------------------------------------------------------------------------- /src/pke/include/encoding/README.md: -------------------------------------------------------------------------------- 1 | # Encodings 2 | 3 | This folder contains the header files of the various encoding formats. Broadly speaking, an encoding is the intermediate transformation between a plaintext and a ciphertext. 4 | 5 | ```mermaid 6 | flowchart BT 7 | A[Input Plaintext] --> |"1) Encode"| B(Encoded Plaintext); 8 | B(Encoded Plaintext) --> |"2) Encrypt"| C(Ciphertext); 9 | C(Ciphertext) --> |"3) Decrypt"| B(Encoded Plaintext); 10 | B(Encoded Plaintext) --> |"4) SetLength"| D(Homomorphically Transformed Plaintext); 11 | ``` 12 | 13 | We provide a brief overview of the files below. However, we recommend referring to our [ReadTheDocs - PKE/Encoding Headers](https://openfhe-development.readthedocs.io/en/latest/assets/sphinx_rsts/modules/pke/pke_encoding.html) for more in-depth information. 14 | 15 | [CKKS Packed Encoding](ckkspackedencoding.h) 16 | - Describes the CKKS packing. Accepts a `std::vector` unlike the other schemes. 17 | 18 | [Coef Packed Encoding](coefpackedencoding.h) 19 | - Accepts plaintext data and packs the data into coefficients of a polynomial. 20 | - Note: is rarely used 21 | - Note: only supports element-wise addition, so ensure that you need this before using 22 | 23 | [Encoding Params](encodingparams.h) 24 | - The object containing the parameters for encoding. These parameters are kept and continually reused (can be modified) during the encoding of new values 25 | 26 | [Encodings](encodings.h) 27 | - "import" file which can be used for a single `#include` 28 | 29 | [Packed Encoding](packedencoding.h) 30 | - Packs integers into a vector 31 | - Note: is almost always what you want to use (other than if you want to deal with floating numbers) 32 | 33 | [Plaintext](plaintext.h) 34 | - The base plaintext implementation 35 | 36 | [Plaintext Factory](plaintextfactory.h) 37 | - Factory class that instantiates plaintexts 38 | 39 | [String Encoding](stringencoding.h) 40 | - Encodes strings -------------------------------------------------------------------------------- /src/core/include/lattice/lat-hal.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2023, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef LBCRYPTO_INC_LATTICE_LAT_HAL_H 33 | #define LBCRYPTO_INC_LATTICE_LAT_HAL_H 34 | 35 | #include "lattice/hal/lat-backend.h" 36 | 37 | #endif // __LAT_HAL_H__ 38 | -------------------------------------------------------------------------------- /src/core/include/utils/demangle.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #ifndef __DEMANGLE_H__ 32 | #define __DEMANGLE_H__ 33 | 34 | #include 35 | 36 | std::string demangle(const char* name) noexcept; 37 | 38 | #endif // __DEMANGLE_H__ 39 | -------------------------------------------------------------------------------- /src/pke/lib/schemebase/base-fhe.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #include "cryptocontext.h" 33 | #include "schemebase/base-fhe.h" 34 | 35 | namespace lbcrypto { 36 | 37 | template class FHEBase; 38 | 39 | } // namespace lbcrypto 40 | -------------------------------------------------------------------------------- /src/pke/lib/key/evalkey.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #include "cryptocontext.h" 32 | #include "key/evalkey.h" 33 | 34 | // the code below is from evalkey-impl.cpp 35 | namespace lbcrypto { 36 | template class EvalKeyImpl; 37 | } // namespace lbcrypto 38 | -------------------------------------------------------------------------------- /src/pke/lib/key/publickey.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #include "cryptocontext.h" 32 | #include "key/publickey.h" 33 | 34 | // the code below is from publickey-impl.cpp 35 | namespace lbcrypto { 36 | template class PublicKeyImpl; 37 | } // namespace lbcrypto 38 | -------------------------------------------------------------------------------- /src/pke/lib/key/privatekey.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #include "cryptocontext.h" 32 | #include "key/privatekey.h" 33 | 34 | // the code below is from privatekey-impl.cpp 35 | namespace lbcrypto { 36 | template class PrivateKeyImpl; 37 | } // namespace lbcrypto 38 | -------------------------------------------------------------------------------- /src/core/lib/utils/parallel.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | This file contains the functionality for parallel operation 34 | */ 35 | 36 | #include "utils/parallel.h" 37 | 38 | namespace lbcrypto { 39 | 40 | ParallelControls OpenFHEParallelControls; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/pke/lib/key/evalkeyrelin.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #include "cryptocontext.h" 32 | #include "key/evalkeyrelin.h" 33 | 34 | // the code below is from evalkeyrelin-impl.cpp 35 | namespace lbcrypto { 36 | template class EvalKeyRelinImpl; 37 | } // namespace lbcrypto 38 | -------------------------------------------------------------------------------- /docs/static_docs/Security.md: -------------------------------------------------------------------------------- 1 | # General Notes on Homomorphic Encryption 2 | 3 | All homomorphic encryption schemes implemented in OpenFHE are IND-CPA secure, and hence are expected to be used under the honest-but-curios (a.k.a., semi-honest) model. In this model, the adversary cannot corrupt/tamper with ciphertexts (and perform related active attacks) but can only use the API of OpenFHE to perform valid operations. 4 | 5 | # Notes specific to the CKKS scheme 6 | 7 | Li and Micciancio recently showed that the IND-CPA model may not be sufficient for the CKKS scheme in some scenarios because a decryption result can be used to perform a key recovery attack. This attack applies to the setting where decryption results need to be shared between multiple parties, e.g., in the the threshold FHE setting. To mitigate the Li-Micciancio attack, we extended the original CKKS (starting with v1.10.6) to a stronger adversarial model where decryption results may still be shared between multiple parties. By default, OpenFHE chooses a configuration where a relatively large number of decryption queries of the same or related ciphertexts can be tolerated. The lower bound for the tolerated number of such decryption queries is N_d = 128 (but in practical computations, N_d is at least 10,000). We consider this default setting sufficient to prevent passive attacks (where a normal homomorphic encryption computation protocol is followed). 8 | 9 | In scenarios where an even stronger adversarial model is needed (uncommon scenarios), the user can increase the number of shared decryptions of the same or related ciphertexts to a higher number by increasing the `CKKS_M_FACTOR` CMake parameter (a compile-level flag). The minimum number of decryption results in this case becomes N_d x (`CKKS_M_FACTOR` + 1) / 2. Please note that increasing `CKKS_M_FACTOR` from the default value of 1 will decrease the precision of CKKS ciphertexts by 0.5 x (log2(`CKKS_M_FACTOR` + 1) - 1) bits. Hence increasing `CKKS_M_FACTOR` is only suggested when a stronger adversarial model is needed. -------------------------------------------------------------------------------- /src/core/include/utils/blockAllocator/xlist.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef _XLIST_H 33 | #define _XLIST_H 34 | 35 | #include 36 | #include "stl_allocator.h" 37 | 38 | template > 39 | class xlist : public std::list<_Ty, _Ax> {}; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/pke/lib/encoding/encodingparams.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | Represents and defines parameters for plaintext encoding 34 | */ 35 | 36 | #include "encoding/encodingparams.h" 37 | 38 | CEREAL_CLASS_VERSION(lbcrypto::EncodingParamsImpl, lbcrypto::EncodingParamsImpl::SerializedVersion()); 39 | -------------------------------------------------------------------------------- /src/core/lib/utils/openfhebase64.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | OpenFHE native base 64 utlities 34 | */ 35 | 36 | #include "utils/openfhebase64.h" 37 | 38 | namespace lbcrypto { 39 | 40 | const char to_base64_char[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 41 | 42 | } /* namespace lbcrypto */ 43 | -------------------------------------------------------------------------------- /src/pke/lib/schemebase/base-parametergeneration.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #include "cryptocontext.h" 32 | #include "schemebase/base-parametergeneration.h" 33 | 34 | // the code below is from base-parametergeneration-impl.cpp 35 | namespace lbcrypto { 36 | template class ParameterGenerationBase; 37 | } // namespace lbcrypto 38 | -------------------------------------------------------------------------------- /src/pke/include/keyswitch/README.md: -------------------------------------------------------------------------------- 1 | # Key Switching 2 | 3 | This folder contains the header files of the various key-switchung capabilities that are defined within `Open-FHE`. 4 | Refer 5 | to [OpenFHE PKE Keys](https://openfhe-development.readthedocs.io/en/latest/assets/sphinx_rsts/modules/pke/pke_keyswitch.html) 6 | 7 | The documentation here is based off 8 | of [Revisiting Homomorphic Encryption Schemes for Finite Fields](https://eprint.iacr.org/2021/204.pdf) 9 | 10 | At a high level, key switching allows transforming a given ciphertext into another ciphertext that can be decrypted with 11 | a separate secret key. This is necessary for computing automorphisms and for relinearizing ciphertexts. 12 | 13 | ## Key Class Inheritance 14 | 15 | ```mermaid 16 | graph BT 17 | Key[Keyswitch: Base Class] --> |Inherited by|KeyRNS[Keyswitch: RNS]; 18 | KeyRNS[Keyswitch: RNS] --> |Inherited by|KeyBV[Keyswitch: BV]; 19 | KeyRNS[Keyswitch: RNS] --> |Inherited by|KeyHybrid[Keyswitch: Hybrid]; 20 | ``` 21 | 22 | [Key-switch Base](keyswitch-base.h) 23 | 24 | - Base class for key switching algorithms. 25 | 26 | [Key-switch RNS](keyswitch-rns.h) 27 | 28 | - Abstract interface class for RNS variants of key switching algorithms 29 | 30 | [Key-switch BV](keyswitch-bv.h) 31 | 32 | - Inherits from [key-switch base](keyswitch-base.h) 33 | - Implements BV key switching method from [Fully Homomorphic Encryption from 34 | Ring-LWE and Security for Key Dependent Messages (BVScheme)]( 35 | https://www.wisdom.weizmann.ac.il/~zvikab/localpapers/IdealHom.pdf 36 | ) 37 | - See the Appendix of https://eprint.iacr.org/2021/204 for more detailed description. 38 | - Requires the computation of a quadratic number of NTTs. 39 | 40 | [Key-switch Hybrid](keyswitch-hybrid.h) 41 | 42 | - Inherits from [key-switch base](keyswitch-base.h) 43 | - Hybrid key switching method first introduced in https://eprint.iacr.org/2012/099.pdf 44 | - RNS version was introduced in https://eprint.iacr.org/2019/688. 45 | - See the Appendix of https://eprint.iacr.org/2021/204 for more detailed description. 46 | -------------------------------------------------------------------------------- /src/core/lib/utils/memory.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2024, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #include "utils/memory.h" 32 | 33 | namespace lbcrypto { 34 | 35 | void secure_memset(volatile void* mem, uint8_t c, size_t len) { 36 | volatile uint8_t* ptr = (volatile uint8_t*)mem; 37 | for (size_t i = 0; i < len; ++i) 38 | *(ptr + i) = c; 39 | } 40 | 41 | } // namespace lbcrypto 42 | -------------------------------------------------------------------------------- /src/core/include/utils/blockAllocator/xqueue.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef _XQUEUE_H 33 | #define _XQUEUE_H 34 | 35 | #include 36 | #include 37 | #include "stl_allocator.h" 38 | 39 | template > > 40 | class xqueue : public std::queue<_Tp, _Sequence> {}; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/pke/include/metadata-ser.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef LBCRYPTO_CRYPTO_METADATASER_H 33 | #define LBCRYPTO_CRYPTO_METADATASER_H 34 | 35 | #include "metadata.h" 36 | #include "utils/serial.h" 37 | 38 | CEREAL_CLASS_VERSION(lbcrypto::Metadata, lbcrypto::Metadata::SerializedVersion()); 39 | CEREAL_REGISTER_TYPE(lbcrypto::Metadata); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/pke/lib/schemebase/rlwe-cryptoparameters-impl.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #include "cryptocontext.h" 33 | #include "schemebase/rlwe-cryptoparameters.h" 34 | 35 | namespace lbcrypto { 36 | 37 | // template class CryptoParametersRLWE; 38 | // template class CryptoParametersRLWE; 39 | template class CryptoParametersRLWE; 40 | 41 | } // namespace lbcrypto 42 | -------------------------------------------------------------------------------- /src/core/include/utils/blockAllocator/xstring.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef _XSTRING_H 33 | #define _XSTRING_H 34 | 35 | #include 36 | #include "stl_allocator.h" 37 | 38 | typedef std::basic_string, stl_allocator> xstring; 39 | typedef std::basic_string, stl_allocator> xwstring; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/intro/security.rst: -------------------------------------------------------------------------------- 1 | Security Notes for Homomorphic Encryption 2 | ================================================== 3 | 4 | All homomorphic encryption schemes implemented in OpenFHE are IND-CPA secure, and hence are expected to be used under the honest-but-curios (a.k.a., semi-honest) model. In this model, the adversary cannot corrupt/tamper with ciphertexts (and perform related active attacks) but can only use the API of OpenFHE to perform valid operations. 5 | 6 | Notes specific to the CKKS scheme 7 | ----------------------------------- 8 | 9 | Li and Micciancio recently showed that the IND-CPA model may not be sufficient for the CKKS scheme in some scenarios because a decryption result can be used to perform a key recovery attack. This attack applies to the setting where decryption results need to be shared between multiple parties, e.g., in the the threshold FHE setting. To mitigate the Li-Micciancio attack, we extended the original CKKS (starting with v1.10.6) to a stronger adversarial model where decryption results may still be shared between multiple parties. By default, OpenFHE chooses a configuration where a relatively large number of decryption queries of the same or related ciphertexts can be tolerated. The lower bound for the tolerated number of such decryption queries is N_d = 128 (but in practical computations, N_d is at least 10,000). We consider this default setting sufficient to prevent passive attacks (where a normal homomorphic encryption computation protocol is followed). 10 | 11 | In scenarios where an even stronger adversarial model is needed (uncommon scenarios), the user can increase the number of shared decryptions of the same or related ciphertexts to a higher number by increasing the `CKKS_M_FACTOR` CMake parameter (a compile-level flag). The minimum number of decryption results in this case becomes N_d x (`CKKS_M_FACTOR` + 1) / 2. Please note that increasing `CKKS_M_FACTOR` from the default value of 1 will decrease the precision of CKKS ciphertexts by 0.5 x (log2(`CKKS_M_FACTOR` + 1) - 1) bits. Hence increasing `CKKS_M_FACTOR` is only suggested when a stronger adversarial model is needed. 12 | -------------------------------------------------------------------------------- /src/pke/unittest/utils/UnitTestMetadataTestSer.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #ifndef __UNITTESTMETADATATESTSER_H__ 32 | #define __UNITTESTMETADATATESTSER_H__ 33 | 34 | #include "UnitTestMetadataTest.h" 35 | #include "utils/serial.h" 36 | 37 | CEREAL_REGISTER_TYPE(lbcrypto::MetadataTest); 38 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::Metadata, lbcrypto::MetadataTest); 39 | 40 | #endif // __UNITTESTMETADATATESTSER_H__ 41 | -------------------------------------------------------------------------------- /src/binfhe/include/lwe-keypair-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #ifndef __LWE_KEYPAIR_FWD_H__ 32 | #define __LWE_KEYPAIR_FWD_H__ 33 | 34 | #include 35 | 36 | namespace lbcrypto { 37 | 38 | class LWEKeyPairImpl; 39 | 40 | using LWEKeyPair = std::shared_ptr; 41 | using ConstLWEKeyPair = const std::shared_ptr; 42 | 43 | } // namespace lbcrypto 44 | 45 | #endif // __LWE_KEYPAIR_FWD_H__ 46 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/intro/building_user_applications.rst: -------------------------------------------------------------------------------- 1 | Building User Applications 2 | ########################## 3 | 4 | How might you integrate OpenFHE into your projects? 5 | 6 | 7 | OpenFHE provides a sample CMake file for building your own C++ project that links to the OpenFHE library. 8 | 9 | The high-level instructions for building projects that use OpenFHE are as follows: 10 | 11 | 1. Build and install OpenFHE using "make install". This will copy the OpenFHE library files and header files to the directory chosen for installation. 12 | 13 | 2. Create the folder for your project on your system. 14 | 15 | 3. Copy CMakeLists.User.txt from the root directory of the git repo to the folder for your project. 16 | 17 | 4. Rename CMakeLists.User.txt to CMakeLists.txt. 18 | 19 | 5. Update CMakeLists.txt to specify the name of the executable and the source code files. For example, include the following line 20 | 21 | :: 22 | 23 | add_executable( fhe-demo simple-integers.cpp ) 24 | 25 | 5. If using MinGW/Windows (skip this step for other platforms), copy PreLoad.cmake from the root directory of the git repo to the folder of your project. 26 | 27 | 6. Create the build directory and cd to it. 28 | 29 | :: 30 | 31 | mkdir build 32 | cd build 33 | 34 | 7. Run 35 | 36 | :: 37 | 38 | cmake .. 39 | 40 | If OpenFHE is installed in a different location than the default one or you have different versions of OpenFHE installed, then you should specify the path to the desired location by running cmake with an option:: 41 | 42 | cmake .. -DCMAKE_PREFIX_PATH=/openfhe/location/path 43 | 44 | 8. Run "make" to build the executable. 45 | 46 | 9. In order to run the executable, add the absolute path to the location of the openfhe libraries to ``PATH``:: 47 | 48 | export PATH=$PATH:/openfhe/location/path/lib 49 | 50 | To include a specific module, e.g., core or pke, in your C++ demo, use the main header file for that module, e.g., ``openfhecore.h`` or ``openfhe.h``. Please see the demos provided for that module for more examples. If your application uses serialization, additional header files will be needed (see the demos with serialization for more details). 51 | -------------------------------------------------------------------------------- /src/pke/lib/schemebase/base-cryptoparameters.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #include "cryptocontext.h" 32 | #include "schemebase/base-cryptoparameters.h" 33 | 34 | // the code below is from base-cryptoparameters-impl.cpp 35 | namespace lbcrypto { 36 | 37 | // template class CryptoParametersBase; 38 | // template class CryptoParametersBase; 39 | template class CryptoParametersBase; 40 | 41 | } // namespace lbcrypto 42 | -------------------------------------------------------------------------------- /src/binfhe/include/lwe-publickey-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #ifndef __LWE_PUBLICKEY_FWD_H__ 32 | #define __LWE_PUBLICKEY_FWD_H__ 33 | 34 | #include 35 | 36 | namespace lbcrypto { 37 | 38 | class LWEPublicKeyImpl; 39 | 40 | using LWEPublicKey = std::shared_ptr; 41 | using ConstLWEPublicKey = const std::shared_ptr; 42 | 43 | } // namespace lbcrypto 44 | 45 | #endif // __LWE_PUBLICKEY_FWD_H__ 46 | -------------------------------------------------------------------------------- /src/binfhe/include/lwe-ciphertext-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #ifndef __LWE_CIPHERTEXT_FWD_H__ 32 | #define __LWE_CIPHERTEXT_FWD_H__ 33 | 34 | #include 35 | 36 | namespace lbcrypto { 37 | 38 | class LWECiphertextImpl; 39 | 40 | using LWECiphertext = std::shared_ptr; 41 | using ConstLWECiphertext = const std::shared_ptr; 42 | 43 | } // namespace lbcrypto 44 | 45 | #endif // __LWE_CIPHERTEXT_FWD_H__ 46 | -------------------------------------------------------------------------------- /src/binfhe/include/lwe-privatekey-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #ifndef __LWE_PRIVATEKEY_FWD_H__ 32 | #define __LWE_PRIVATEKEY_FWD_H__ 33 | 34 | #include 35 | 36 | namespace lbcrypto { 37 | 38 | class LWEPrivateKeyImpl; 39 | 40 | using LWEPrivateKey = std::shared_ptr; 41 | using ConstLWEPrivateKey = const std::shared_ptr; 42 | 43 | } // namespace lbcrypto 44 | 45 | #endif // __LWE_PRIVATEKEY_FWD_H__ 46 | -------------------------------------------------------------------------------- /src/binfhe/include/lwe-keyswitchkey-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #ifndef __LWE_KEYSWITCHKEY_FWD_H__ 32 | #define __LWE_KEYSWITCHKEY_FWD_H__ 33 | 34 | #include 35 | 36 | namespace lbcrypto { 37 | 38 | class LWESwitchingKeyImpl; 39 | 40 | using LWESwitchingKey = std::shared_ptr; 41 | using ConstLWESwitchingKey = const std::shared_ptr; 42 | 43 | } // namespace lbcrypto 44 | 45 | #endif // __LWE_KEYSWITCHKEY_FWD_H__ 46 | -------------------------------------------------------------------------------- /src/core/include/openfhecore.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | OpenFHE version strings 34 | */ 35 | 36 | #ifndef SRC_CORE_INCLUDE_OPENFHECORE_H_ 37 | #define SRC_CORE_INCLUDE_OPENFHECORE_H_ 38 | 39 | #include "lattice/lat-hal.h" 40 | #include "lattice/stdlatticeparms.h" 41 | 42 | #include "math/distrgen.h" 43 | #include "math/math-hal.h" 44 | #include "math/nbtheory.h" 45 | 46 | #include "utils/debug.h" 47 | 48 | #include "version.h" 49 | 50 | #endif /* SRC_CORE_INCLUDE_OPENFHECORE_H_ */ 51 | -------------------------------------------------------------------------------- /src/core/include/utils/get-call-stack.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2023, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #ifndef __GET_CALL_STACK_H__ 32 | #define __GET_CALL_STACK_H__ 33 | 34 | #include 35 | #include 36 | 37 | /** 38 | * @brief get_call_stack() is a function to get the call stack. 39 | * @attention it must not throw an exception as it is called from OpenFHEException 40 | * @return a vector with call stack (demangled function names) 41 | */ 42 | std::vector get_call_stack() noexcept; 43 | 44 | #endif // __GET_CALL_STACK_H__ 45 | -------------------------------------------------------------------------------- /src/pke/include/key/evalkey-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | /* 32 | * It is a lightweight file to be included where we need the declaration of EvalKey only 33 | * 34 | */ 35 | #ifndef __EVALKEY_FWD_H__ 36 | #define __EVALKEY_FWD_H__ 37 | 38 | #include 39 | 40 | namespace lbcrypto { 41 | 42 | template 43 | class EvalKeyImpl; 44 | 45 | template 46 | using EvalKey = std::shared_ptr>; 47 | 48 | } // namespace lbcrypto 49 | 50 | #endif // __EVALKEY_FWD_H__ 51 | -------------------------------------------------------------------------------- /src/pke/include/key/publickey-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | /* 32 | * It is a lightweight file to be included where we need the declaration of PublicKey only 33 | * 34 | */ 35 | #ifndef __PUBLICKEY_FWD_H__ 36 | #define __PUBLICKEY_FWD_H__ 37 | 38 | #include 39 | 40 | namespace lbcrypto { 41 | 42 | template 43 | class PublicKeyImpl; 44 | 45 | template 46 | using PublicKey = std::shared_ptr>; 47 | 48 | } // namespace lbcrypto 49 | 50 | #endif // __PUBLICKEY_FWD_H__ 51 | -------------------------------------------------------------------------------- /src/core/include/utils/blockAllocator/xset.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef _XSET_H 33 | #define _XSET_H 34 | 35 | #include 36 | #include 37 | #include "stl_allocator.h" 38 | 39 | template , class _Alloc = stl_allocator<_Kty> > 40 | class xset : public std::set<_Kty, _Pr, _Alloc> {}; 41 | 42 | /// @see xset 43 | template , class _Alloc = stl_allocator<_Kty> > 44 | class xmultiset : public std::multiset<_Kty, _Pr, _Alloc> {}; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/pke/include/key/privatekey-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | /* 32 | * It is a lightweight file to be included where we need the declaration of PrivateKey only 33 | * 34 | */ 35 | #ifndef __PRIVATEKEY_FWD_H__ 36 | #define __PRIVATEKEY_FWD_H__ 37 | 38 | #include 39 | 40 | namespace lbcrypto { 41 | 42 | template 43 | class PrivateKeyImpl; 44 | 45 | template 46 | using PrivateKey = std::shared_ptr>; 47 | 48 | } // namespace lbcrypto 49 | 50 | #endif // __PRIVATEKEY_FWD_H__ 51 | -------------------------------------------------------------------------------- /src/pke/include/encoding/encodings.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | all supported encodings of plaintext objects in OpenFHE 34 | */ 35 | 36 | #ifndef SRC_CORE_LIB_ENCODING_ENCODINGS_H_ 37 | #define SRC_CORE_LIB_ENCODING_ENCODINGS_H_ 38 | 39 | #include "encoding/ckkspackedencoding.h" 40 | #include "encoding/coefpackedencoding.h" 41 | #include "encoding/encodingparams.h" 42 | #include "encoding/packedencoding.h" 43 | #include "encoding/plaintext.h" 44 | #include "encoding/stringencoding.h" 45 | 46 | #endif /* SRC_CORE_LIB_ENCODING_ENCODINGS_H_ */ 47 | -------------------------------------------------------------------------------- /src/pke/include/key/evalkeyrelin-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | /* 32 | * It is a lightweight file to be included where we need the declaration of EvalKeyRelin only 33 | * 34 | */ 35 | #ifndef __EVALKEYRELIN_FWD_H__ 36 | #define __EVALKEYRELIN_FWD_H__ 37 | 38 | #include 39 | 40 | namespace lbcrypto { 41 | 42 | template 43 | class EvalKeyRelinImpl; 44 | 45 | template 46 | using EvalKeyRelin = std::shared_ptr>; 47 | 48 | } // namespace lbcrypto 49 | 50 | #endif // __EVALKEYRELIN_FWD_H__ 51 | -------------------------------------------------------------------------------- /src/core/include/utils/sertype.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | Definition of serialization type 34 | */ 35 | 36 | #ifndef LBCRYPTO_SERTYPE_H 37 | #define LBCRYPTO_SERTYPE_H 38 | 39 | namespace lbcrypto { 40 | 41 | namespace SerType { 42 | 43 | class SERJSON {}; 44 | static const SERJSON JSON; // should be const static to avoid compilation failure 45 | 46 | class SERBINARY {}; 47 | static const SERBINARY BINARY; // should be const static to avoid compilation failure 48 | 49 | } // namespace SerType 50 | 51 | } // namespace lbcrypto 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/core/lib/utils/inttypes.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | This code provides basic integer types and enums 34 | */ 35 | 36 | #include "utils/inttypes.h" 37 | #include 38 | 39 | std::ostream& operator<<(std::ostream& s, Format f) { 40 | switch (f) { 41 | case EVALUATION: 42 | s << "EVALUATION"; 43 | break; 44 | case COEFFICIENT: 45 | s << "COEFFICIENT"; 46 | break; 47 | default: 48 | s << "UNKNOWN"; 49 | break; 50 | } 51 | return s; 52 | } 53 | -------------------------------------------------------------------------------- /src/pke/include/cryptocontext-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | * It is a lightweight file to be included where we need the declaration of CryptoContext only 34 | * 35 | */ 36 | #ifndef __CRYPTOCONTEXT_FWD_H__ 37 | #define __CRYPTOCONTEXT_FWD_H__ 38 | 39 | #include 40 | 41 | namespace lbcrypto { 42 | 43 | template 44 | class CryptoContextImpl; 45 | 46 | template 47 | using CryptoContext = std::shared_ptr>; 48 | 49 | } // namespace lbcrypto 50 | 51 | #endif // __CRYPTOCONTEXT_FWD_H__ 52 | 53 | -------------------------------------------------------------------------------- /src/pke/unittest/utils/UnitTestCryptoContext.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef __UNITTESTCRYPTOCONTEXT_H__ 33 | #define __UNITTESTCRYPTOCONTEXT_H__ 34 | 35 | #include "BaseTestCase.h" 36 | #include "UnitTestCCParams.h" 37 | #include "cryptocontext.h" 38 | #include "schemebase/base-scheme.h" 39 | 40 | using Element = lbcrypto::DCRTPoly; 41 | 42 | lbcrypto::CryptoContext UnitTestGenerateContext(const UnitTestCCParams& testData); 43 | lbcrypto::CryptoContext UnitTestGenerateContext(const BaseTestCase& testCase); 44 | 45 | #endif // __UNITTESTCRYPTOCONTEXT_H__ 46 | -------------------------------------------------------------------------------- /src/core/lib/utils/utilities.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | This file contains utility functions 34 | */ 35 | 36 | #include "utils/utilities.h" 37 | 38 | namespace lbcrypto { 39 | 40 | // auxiliary function to replace a specific character "in" with another character "out" 41 | std::string replaceChar(std::string str, char in, char out) { 42 | size_t found = str.find_first_of(in); 43 | while (found != std::string::npos) { 44 | str[found] = out; 45 | found = str.find_first_of(in, found + 1); 46 | } 47 | return str; 48 | } 49 | 50 | } // namespace lbcrypto 51 | -------------------------------------------------------------------------------- /src/core/include/math/hal/nativeintbackend.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef __NATIVEINTBACKEND_H__ 33 | #define __NATIVEINTBACKEND_H__ 34 | 35 | #include "math/hal/basicint.h" 36 | #include "math/hal/intnat/ubintnat.h" 37 | #include "math/hal/intnat/mubintvecnat.h" 38 | #include "math/hal/intnat/transformnat.h" 39 | 40 | namespace lbcrypto { 41 | 42 | using NativeInteger = intnat::NativeInteger; 43 | using NativeVector = intnat::NativeVector; 44 | 45 | } // namespace lbcrypto 46 | 47 | using NativeInteger = lbcrypto::NativeInteger; 48 | using NativeVector = lbcrypto::NativeVector; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/pke/include/encoding/plaintext-fwd.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | /* 32 | * It is a lightweight file to be included where we need the declaration of Plaintext only 33 | * 34 | */ 35 | #ifndef __PLAINTEXT_FWD_H__ 36 | #define __PLAINTEXT_FWD_H__ 37 | 38 | #include 39 | 40 | namespace lbcrypto { 41 | 42 | class PlaintextImpl; 43 | 44 | using Plaintext = std::shared_ptr; 45 | using ConstPlaintext = const std::shared_ptr; 46 | 47 | using ReadOnlyPlaintext = std::shared_ptr; 48 | 49 | } // namespace lbcrypto 50 | 51 | #endif // __PLAINTEXT_FWD_H__ 52 | -------------------------------------------------------------------------------- /src/pke/lib/cryptoobject-impl.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #include "cryptoobject.h" 32 | 33 | #include "cryptocontext.h" 34 | 35 | namespace lbcrypto { 36 | 37 | template 38 | const std::shared_ptr> CryptoObject::GetCryptoParameters() const { 39 | return context->GetCryptoParameters(); 40 | } 41 | 42 | template 43 | const EncodingParams CryptoObject::GetEncodingParameters() const { 44 | return context->GetCryptoParameters()->GetEncodingParams(); 45 | } 46 | 47 | template class CryptoObject; 48 | 49 | } // namespace lbcrypto 50 | -------------------------------------------------------------------------------- /src/core/include/utils/blockAllocator/xmap.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef _XMAP_H 33 | #define _XMAP_H 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "stl_allocator.h" 40 | 41 | template , 42 | class _Alloc = stl_allocator > > 43 | class xmap : public std::map<_Kty, _Ty, _Pr, _Alloc> {}; 44 | 45 | template , 46 | class _Alloc = stl_allocator > > 47 | class xmultimap : public std::multimap<_Kty, _Ty, _Pr, _Alloc> {}; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/pke/include/key/key-ser.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | serialize keys; include this in any app that needs to serialize these objects 34 | */ 35 | 36 | #ifndef LBCRYPTO_CRYPTO_KEY_KEY_SER_H 37 | #define LBCRYPTO_CRYPTO_KEY_KEY_SER_H 38 | 39 | #include "key/evalkeyrelin.h" 40 | #include "utils/serial.h" 41 | 42 | CEREAL_REGISTER_TYPE(lbcrypto::EvalKeyImpl); 43 | CEREAL_REGISTER_TYPE(lbcrypto::EvalKeyRelinImpl); 44 | 45 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::EvalKeyImpl, 46 | lbcrypto::EvalKeyRelinImpl); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/core/include/utils/blockAllocator/xsstream.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef _XSSTREAM_H 33 | #define _XSSTREAM_H 34 | 35 | #include 36 | #include 37 | 38 | #include "stl_allocator.h" 39 | 40 | typedef std::basic_stringstream, stl_allocator> xstringstream; 41 | typedef std::basic_ostringstream, stl_allocator> xostringstream; 42 | 43 | typedef std::basic_stringstream, stl_allocator> xwstringstream; 44 | typedef std::basic_ostringstream, stl_allocator> xwostringstream; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/core/include/version.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | OpenFHE version strings 34 | */ 35 | 36 | #ifndef SRC_VERSION_H_ 37 | #define SRC_VERSION_H_ 38 | 39 | #include 40 | 41 | // version string is passed as a preprocessor define, which gets macro'd up into 42 | // a string 43 | #define STR_EXPAND(tok) #tok 44 | #define STR(tok) STR_EXPAND(tok) 45 | #ifndef OPENFHE_VERSION 46 | #define OPENFHE_VERSION BASE_OPENFHE_VERSION 47 | #endif 48 | 49 | /** 50 | * GetOPENFHEVersion - Returns OpenFHE Version string 51 | * @return 52 | */ 53 | inline std::string GetOPENFHEVersion() { 54 | return STR(OPENFHE_VERSION); 55 | } 56 | 57 | #endif /* SRC_VERSION_H_ */ 58 | -------------------------------------------------------------------------------- /src/pke/include/schemerns/rns-ser.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | serialize ckks; include this in any app that needs to serialize this scheme 34 | */ 35 | 36 | #ifndef LBCRYPTO_CRYPTO_RNS_SER_H 37 | #define LBCRYPTO_CRYPTO_RNS_SER_H 38 | 39 | #include "schemerns/rns-scheme.h" 40 | #include "utils/serial.h" 41 | 42 | CEREAL_REGISTER_TYPE(lbcrypto::CryptoParametersRNS); 43 | CEREAL_REGISTER_TYPE(lbcrypto::SchemeRNS); 44 | CEREAL_REGISTER_TYPE(lbcrypto::FHERNS); 45 | 46 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::FHEBase, lbcrypto::FHERNS); 47 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::CryptoParametersRLWE, lbcrypto::CryptoParametersRNS); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/core/include/math/distrgen.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2023, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | This code provides basic noise generation functionality 34 | */ 35 | 36 | #ifndef LBCRYPTO_INC_MATH_DISTRGEN_H_ 37 | #define LBCRYPTO_INC_MATH_DISTRGEN_H_ 38 | 39 | #define _USE_MATH_DEFINES 40 | // #include 41 | // #include 42 | // #include 43 | // #include 44 | #include "math/binaryuniformgenerator.h" 45 | #include "math/discretegaussiangenerator.h" 46 | #include "math/discretegaussiangeneratorgeneric.h" 47 | #include "math/discreteuniformgenerator.h" 48 | #include "math/distributiongenerator.h" 49 | #include "math/ternaryuniformgenerator.h" 50 | 51 | #endif // LBCRYPTO_INC_MATH_DISTRGEN_H_ 52 | -------------------------------------------------------------------------------- /src/pke/include/scheme/bfvrns/bfvrns-ser.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | serialize BFVrns; include this in any app that needs to serialize this scheme 34 | */ 35 | 36 | #ifndef LBCRYPTO_CRYPTO_BFVRNSSER_H 37 | #define LBCRYPTO_CRYPTO_BFVRNSSER_H 38 | 39 | #include "scheme/bfvrns/bfvrns-scheme.h" 40 | #include "utils/serial.h" 41 | 42 | CEREAL_REGISTER_TYPE(lbcrypto::CryptoParametersBFVRNS); 43 | CEREAL_REGISTER_TYPE(lbcrypto::SchemeBFVRNS); 44 | CEREAL_REGISTER_TYPE(lbcrypto::FHEBFVRNS); 45 | 46 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::CryptoParametersRNS, lbcrypto::CryptoParametersBFVRNS); 47 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::FHERNS, lbcrypto::FHEBFVRNS); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/pke/include/scheme/gen-cryptocontext-params-validation.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2024, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #ifndef __GEN_CRYPTOCONTEXT_PARAMS_VALIDATION_H__ 32 | #define __GEN_CRYPTOCONTEXT_PARAMS_VALIDATION_H__ 33 | 34 | #include "scheme/gen-cryptocontext-params.h" 35 | 36 | namespace lbcrypto { 37 | /** 38 | * @brief Validate parameters for generating cryptocontext. Doesn't validate the parameters which set functions 39 | * are disabled as they cannot be set by users 40 | * @param parameters scheme-specific parameters to generate cryptocontext 41 | */ 42 | void validateParametersForCryptocontext(const Params& parameters); 43 | 44 | } // namespace lbcrypto 45 | 46 | #endif // __GEN_CRYPTOCONTEXT_PARAMS_VALIDATION_H__ 47 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/modules/pke/pke_keys.rst: -------------------------------------------------------------------------------- 1 | PKE Keys documentation 2 | ==================================== 3 | 4 | `Github Source `_: This folder contains the header files of the various keys that are defined within ``Open-FHE``. 5 | 6 | 7 | .. contents:: Page Contents 8 | :local: 9 | 10 | 11 | File Listings 12 | ------------- 13 | 14 | `All Key Top-Level Include (allkey.h) `_ 15 | 16 | - Top-level ``#include`` for access to all capabilities 17 | 18 | 19 | Keys Class Inheritance 20 | ----------------------- 21 | 22 | .. mermaid:: 23 | 24 | graph BT 25 | Key[Key: Base Class] --> |Inherited by|EvalKeyImpl; 26 | EvalKeyImpl --> |Inherited by|EvalKeyRelinImpl; 27 | 28 | 29 | Key Class File Listings 30 | ----------------------- 31 | 32 | `Eval Key (evalkey.h) `_ 33 | 34 | - Inherits from the base ``Key`` class. 35 | 36 | - Serves as base class for ``Eval Key Relin`` 37 | 38 | `Eval Key Relin (evalkeyrelin.h) `_ 39 | 40 | - Get and set relinearization elements 41 | 42 | - Inherits from ``Eval Key`` 43 | 44 | `Key (key.h) `_ 45 | 46 | - Base Key class 47 | 48 | `Key Serialization (key-ser.h) `_ 49 | 50 | - Capabilities for serializing the keys using `Cereal `__ 51 | 52 | Key Pair 53 | -------- 54 | 55 | .. mermaid:: 56 | 57 | graph BT 58 | PrivKey[Private Key] --> |container|KP(Key Pair); 59 | PubKey[Public Key] --> |container|KP(Key Pair); 60 | 61 | Key Pair File Listings 62 | ----------------------- 63 | 64 | `Key Pair (keypair.h) `_ 65 | 66 | - Container for the ``private key`` and ``public key`` implementations 67 | 68 | `Private Key (privatekey.h) `_ 69 | 70 | `Public Key (publickey.h) `_ 71 | -------------------------------------------------------------------------------- /src/core/include/utils/blockAllocator/xvector.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | See http://www.codeproject.com/Articles/1089905/A-Custom-STL-std-allocator-Replacement-Improves-Performance- 34 | dcousins 35 | */ 36 | 37 | #ifndef _XVECTOR_H 38 | #define _XVECTOR_H 39 | 40 | #include 41 | #include "stl_allocator.h" 42 | 43 | template > 44 | class xvector : public std::vector<_Ty, _Ax> { 45 | public: 46 | constexpr xvector() noexcept : std::vector<_Ty, _Ax>() {} 47 | explicit constexpr xvector(usint length) noexcept : std::vector<_Ty, _Ax>(length) {} 48 | constexpr xvector(usint length, const _Ty& val) noexcept : std::vector<_Ty, _Ax>(length, val) {} 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/contributing/rebasing_off_main.rst: -------------------------------------------------------------------------------- 1 | .. _rebasing: 2 | 3 | Rebasing 4 | ==================================== 5 | 6 | When working on the library one should be working on a feature branch, and submit merge requests to move one's code onto the main branch. 7 | 8 | Periodically the main branch will evolve and improve before a feature branch, and the feature branch should updated with changes in the main to test that this code works well together before a merge request is submitted. 9 | 10 | There are multiple ways to move code updates from a main to a feature, but I'm going to describe the method that works for me. 11 | As an example, suppose one is working on the branch ``issue-123``, and there have been improvements to the main branch. Generally one can rebase by doing the following: 12 | 13 | 1) Pull the latest code from both the ``issue-123`` and ``main`` branches with the following commands: 14 | 15 | :: 16 | 17 | git checkout main 18 | 19 | git pull origin main 20 | git checkout issue-123 21 | 22 | git pull origin issue-123 23 | 24 | Make sure both of branches build properly before going any further. Correct any bugs on the feature branch and commit that branch. Also check the main branch and notify the OpenFHE team if there is an error in the main branch. 25 | 26 | 2) Run the following rebase operation: ``git rebase main issue-123`` 27 | 28 | - The changes are rebased into the feature branch one-by-one. Often there are conflicts. Suppose there is a conflict in `nbtheory.h`. In this example, manually inspect `nbtheory.h` and resolve the conflict. 29 | 30 | 3) When you are done working on the conflict, you would add the file back to the branch as follows: ``git add src/core/include/math/nbtheory.h`` 31 | 32 | 4) As soon as you resolve conflicts, continue the rebase: ``git rebase --continue`` 33 | 34 | 5) Repeat the process of conflict resolution and continue until the rebase is finished. Then build one final time as a sanity check, commit code, and push to the feature branch: 35 | 36 | :: 37 | 38 | git commit -m "finalized rebase" 39 | 40 | git push --force-with-lease origin issue-123 41 | 42 | 43 | .. note:: The ``--force-with-lease`` (force) flag is needed to overwrite the git commit history 44 | If ``--force-with-lease`` is not supplied, the push will be declined. 45 | 46 | You can then create a merge request here: 47 | 48 | `OpenFHE Development Pull Requests `_ 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/core/unittest/UnitTestUtils.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | This file tests utilities functions 34 | */ 35 | 36 | #include 37 | #include 38 | #include "include/gtest/gtest.h" 39 | 40 | #include "utils/utilities.h" 41 | 42 | using namespace lbcrypto; 43 | 44 | TEST(Utilities, IsPowerOfTwo) { 45 | std::vector powers_of_two{1, 2, 4, 8, 16, 32, 512, 1024, 2048, 4096, 16384, 32768}; 46 | std::vector not_powers_of_two{0, 3, 5, 7, 9, 31, 33, 1025, 4095}; 47 | 48 | for (auto power_of_two : powers_of_two) { 49 | EXPECT_TRUE(IsPowerOfTwo(power_of_two)); 50 | } 51 | 52 | for (auto not_power_of_two : not_powers_of_two) { 53 | EXPECT_FALSE(IsPowerOfTwo(not_power_of_two)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /docs/static_docs/Examples.md: -------------------------------------------------------------------------------- 1 | OpenFHE Examples 2 | ================= 3 | 4 | To support users in understanding and integration OpenFHE provides a number of examples. There are a few examples inside 5 | this repository but also independent repositories. 6 | 7 | --- 8 | 9 | **Table of Contents** 10 | 11 | - [OpenFHE/PALISADE Integer Examples](#OpenFHE-integer-examples) 12 | - [OpenFHE/PALISADE Encrypted Circuit Emulator](#OpenFHE-encrypted-circuit-emulator) 13 | - [OpenFHE/PALISADE Python 3 Demos](#OpenFHE-python-3-demos) 14 | - [OpenFHE/PALISADE Serial examples](#OpenFHE-serial-examples) 15 | - [Local Examples](#local-examples) 16 | 17 | --- 18 | 19 | [OpenFHE Integer Examples](https://gitlab.com/palisade/palisade-integer-examples) 20 | --------------------------- 21 | 22 | This repository has a number of examples related to FHE integer operations. Check out 23 | the [README](https://gitlab.com/palisade/palisade-integer-examples/-/blob/master/README.md) in the repository for more 24 | details. 25 | 26 | 27 | [OpenFHE Encrypted Circuit Emulator](https://gitlab.com/palisade/palisade-encrypted-circuit-emulator) 28 | ------------------------------------- 29 | 30 | This is a demonstration application using OpenFHE's binfhe module for encrypted boolean logic. Check out 31 | the [README](https://gitlab.com/palisade/palisade-encrypted-circuit-emulator/-/blob/master/README.md) in the repository 32 | for more details. 33 | 34 | [OpenFHE Python 3 Demos](https://gitlab.com/palisade/palisade-python-demo) 35 | ------------------------- 36 | 37 | This repository contains an example python 3 wrapper for OpenFHE. It does not expose all functionality of OpenFHE, 38 | rather it is an example of how to build a specific python application program using a python wrapper, Boost/python 39 | bindings and an installed OpenFHE library. Check out 40 | the [README](https://gitlab.com/palisade/palisade-python-demo/-/blob/master/README.md) in the repository for more 41 | details. 42 | 43 | [OpenFHE serial examples](https://gitlab.com/palisade/palisade-serial-examples) 44 | -------------------------- 45 | 46 | Sample programs for Encrypted Processing between cooperating processes. Check out 47 | the [README](https://gitlab.com/palisade/palisade-serial-examples/-/blob/master/README.md) in the repository for more 48 | details. 49 | 50 | Local Examples 51 | -------------- 52 | 53 | The examples included with the OpenFHE lattice crypto library. Check out the [README](../../src/pke/examples/README.md) 54 | in the repository for more details. 55 | -------------------------------------------------------------------------------- /src/pke/include/scheme/bgvrns/bgvrns-ser.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | serialize bgvrns; include this in any app that needs to serialize this scheme 34 | */ 35 | 36 | #ifndef LBCRYPTO_CRYPTO_BGVRNSSER_H 37 | #define LBCRYPTO_CRYPTO_BGVRNSSER_H 38 | 39 | #include "scheme/bgvrns/bgvrns-scheme.h" 40 | #include "scheme/bgvrns/bgvrns-fhe.h" 41 | #include "scheme/bgvrns/bgvrns-cryptoparameters.h" 42 | #include "utils/serial.h" 43 | 44 | CEREAL_REGISTER_TYPE(lbcrypto::CryptoParametersBGVRNS); 45 | CEREAL_REGISTER_TYPE(lbcrypto::SchemeBGVRNS); 46 | CEREAL_REGISTER_TYPE(lbcrypto::FHEBGVRNS); 47 | 48 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::FHERNS, lbcrypto::FHEBGVRNS); 49 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::CryptoParametersRNS, lbcrypto::CryptoParametersBGVRNS); 50 | #endif 51 | -------------------------------------------------------------------------------- /src/pke/lib/keyswitch/keyswitch-base.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /** 33 | Base class for Lattice-based cryptography(LBC) Somewhat Homomorphic Encryption(SHE) algorithms. 34 | */ 35 | 36 | #include "keyswitch/keyswitch-base.h" 37 | 38 | #include "lattice/lat-hal.h" 39 | #include "ciphertext.h" 40 | #include "key/evalkey.h" 41 | 42 | namespace lbcrypto { 43 | 44 | template 45 | Ciphertext KeySwitchBase::KeySwitch(ConstCiphertext ciphertext, 46 | const EvalKey evalKey) const { 47 | Ciphertext result = ciphertext->Clone(); 48 | KeySwitchInPlace(result, evalKey); 49 | return result; 50 | } 51 | 52 | template class KeySwitchBase; 53 | 54 | } // namespace lbcrypto 55 | -------------------------------------------------------------------------------- /src/pke/unittest/utils/UnitTestReadCSVData.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | #ifndef __UNITTESTREADCSVDATA_H__ 32 | #define __UNITTESTREADCSVDATA_H__ 33 | 34 | #include 35 | #include 36 | 37 | /** 38 | * createDataFileName() builds the name of the test data file. It should have the same name as sourceFileName, but 39 | * the extension is "csv". 40 | * @param sourceFileName is the source file name 41 | * @return test data file name 42 | */ 43 | std::string createDataFileName(const std::string& sourceFileName); 44 | std::string createDataFileName(const char* sourceFileName); 45 | 46 | std::vector tokenize(const std::string& str, const char delim); 47 | 48 | std::vector> readDataFile(const std::string& dataFileName); 49 | 50 | #endif // __UNITTESTREADCSVDATA_H__ 51 | -------------------------------------------------------------------------------- /src/pke/include/scheme/scheme-utils.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2024, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef _SCHEME_UTILS_H_ 33 | #define _SCHEME_UTILS_H_ 34 | 35 | inline uint32_t ComputeNumLargeDigits(uint32_t numLargeDigits, uint32_t multDepth) { 36 | if (numLargeDigits > 0) 37 | return numLargeDigits; 38 | if (multDepth > 3) // if more than 4 towers, use 3 digits 39 | return 3; 40 | if (multDepth > 0) // if 2, 3 or 4 towers, use 2 digits 41 | return 2; 42 | return 1; // if 1 tower, use one digit 43 | } 44 | 45 | inline uint32_t ComputeNumLargeDigitsPRE(uint32_t numLargeDigits, uint32_t numHops) { 46 | if (numLargeDigits > 0) 47 | return numLargeDigits; 48 | if (numHops > 4) 49 | return 3; 50 | if (numHops > 1) 51 | return 2; 52 | return 1; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /benchmark/src/poly-benchmark-1k.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2023, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | * This code benchmarks polynomial operations for ring dimension of 1k. 34 | */ 35 | 36 | #include "math/hal/basicint.h" 37 | #include "poly-benchmark.h" 38 | #include 39 | 40 | constexpr uint32_t RING_DIM_LOG = 10; 41 | constexpr uint32_t DCRTBITS = MAX_MODULUS_SIZE; 42 | 43 | class Setup { 44 | public: 45 | Setup() { 46 | std::cerr << "Generating polynomials for the benchmark..." << std::endl; 47 | GeneratePolys((1 << (RING_DIM_LOG + 1)), DCRTBITS, NativepolysEval, NativepolysCoef); 48 | GenerateDCRTPolys((1 << (RING_DIM_LOG + 1)), DCRTBITS, DCRTpolysEval, DCRTpolysCoef); 49 | std::cerr << "Polynomials for the benchmark are generated" << std::endl; 50 | } 51 | } TestParameters; 52 | 53 | BENCHMARK_MAIN(); 54 | -------------------------------------------------------------------------------- /benchmark/src/poly-benchmark-4k.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2023, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | * This code benchmarks polynomial operations for ring dimension of 4k. 34 | */ 35 | 36 | #include "math/hal/basicint.h" 37 | #include "poly-benchmark.h" 38 | #include 39 | 40 | constexpr uint32_t RING_DIM_LOG = 12; 41 | constexpr uint32_t DCRTBITS = MAX_MODULUS_SIZE; 42 | 43 | class Setup { 44 | public: 45 | Setup() { 46 | std::cerr << "Generating polynomials for the benchmark..." << std::endl; 47 | GeneratePolys((1 << (RING_DIM_LOG + 1)), DCRTBITS, NativepolysEval, NativepolysCoef); 48 | GenerateDCRTPolys((1 << (RING_DIM_LOG + 1)), DCRTBITS, DCRTpolysEval, DCRTpolysCoef); 49 | std::cerr << "Polynomials for the benchmark are generated" << std::endl; 50 | } 51 | } TestParameters; 52 | 53 | BENCHMARK_MAIN(); 54 | -------------------------------------------------------------------------------- /benchmark/src/poly-benchmark-8k.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2023, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | * This code benchmarks polynomial operations for ring dimension of 8k. 34 | */ 35 | 36 | #include "math/hal/basicint.h" 37 | #include "poly-benchmark.h" 38 | #include 39 | 40 | constexpr uint32_t RING_DIM_LOG = 13; 41 | constexpr uint32_t DCRTBITS = MAX_MODULUS_SIZE; 42 | 43 | class Setup { 44 | public: 45 | Setup() { 46 | std::cerr << "Generating polynomials for the benchmark..." << std::endl; 47 | GeneratePolys((1 << (RING_DIM_LOG + 1)), DCRTBITS, NativepolysEval, NativepolysCoef); 48 | GenerateDCRTPolys((1 << (RING_DIM_LOG + 1)), DCRTBITS, DCRTpolysEval, DCRTpolysCoef); 49 | std::cerr << "Polynomials for the benchmark are generated" << std::endl; 50 | } 51 | } TestParameters; 52 | 53 | BENCHMARK_MAIN(); 54 | -------------------------------------------------------------------------------- /benchmark/src/poly-benchmark-16k.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2023, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | * This code benchmarks polynomial operations for ring dimension of 16k. 34 | */ 35 | 36 | #include "math/hal/basicint.h" 37 | #include "poly-benchmark.h" 38 | #include 39 | 40 | constexpr uint32_t RING_DIM_LOG = 14; 41 | constexpr uint32_t DCRTBITS = MAX_MODULUS_SIZE; 42 | 43 | class Setup { 44 | public: 45 | Setup() { 46 | std::cerr << "Generating polynomials for the benchmark..." << std::endl; 47 | GeneratePolys((1 << (RING_DIM_LOG + 1)), DCRTBITS, NativepolysEval, NativepolysCoef); 48 | GenerateDCRTPolys((1 << (RING_DIM_LOG + 1)), DCRTBITS, DCRTpolysEval, DCRTpolysCoef); 49 | std::cerr << "Polynomials for the benchmark are generated" << std::endl; 50 | } 51 | } TestParameters; 52 | 53 | BENCHMARK_MAIN(); 54 | -------------------------------------------------------------------------------- /benchmark/src/poly-benchmark-64k.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2023, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | * This code benchmarks polynomial operations for ring dimension of 64k. 34 | */ 35 | 36 | #include "math/hal/basicint.h" 37 | #include "poly-benchmark.h" 38 | #include 39 | 40 | constexpr uint32_t RING_DIM_LOG = 16; 41 | constexpr uint32_t DCRTBITS = MAX_MODULUS_SIZE; 42 | 43 | class Setup { 44 | public: 45 | Setup() { 46 | std::cerr << "Generating polynomials for the benchmark..." << std::endl; 47 | GeneratePolys((1 << (RING_DIM_LOG + 1)), DCRTBITS, NativepolysEval, NativepolysCoef); 48 | GenerateDCRTPolys((1 << (RING_DIM_LOG + 1)), DCRTBITS, DCRTpolysEval, DCRTpolysCoef); 49 | std::cerr << "Polynomials for the benchmark are generated" << std::endl; 50 | } 51 | } TestParameters; 52 | 53 | BENCHMARK_MAIN(); 54 | -------------------------------------------------------------------------------- /docs/sphinx_rsts/intro/using_the_library.rst: -------------------------------------------------------------------------------- 1 | Using The Library 2 | ==================================== 3 | 4 | OpenFHE consists of a number of library objects that can be linked into lattice cryptography applications. 5 | 6 | The source files in the demo directories, particularly those in src/examples/pke, illustrate the use of the library. 7 | 8 | To use OpenFHE, you must 9 | 10 | * select a scheme to use 11 | 12 | * ``BFVrns`` 13 | 14 | * ``BGVrns`` 15 | 16 | * ``CKKSrns`` 17 | 18 | * create a CryptoContext for the scheme. This requires that you: 19 | 20 | * run a parameter generation function or, alternatively, 21 | 22 | * decide on lattice parameters (ring dimension, size of moduli) 23 | 24 | * decide on encoding parameters (plaintext modulus) 25 | 26 | * decide on scheme-specific parameters 27 | 28 | * enable the algorithms that you want to use, e.g., 29 | 30 | * Enable(ENCRYPTION) - allows for key generation and encrypt/decrypt 31 | 32 | * Enable(PRE) - allows for the use of proxy re-encryption 33 | 34 | * Enable(SHE) - enables SHE operations such as EvalAdd and EvalMult 35 | 36 | * Enable(MULTIPARTY) - enables threshold FHE operations 37 | 38 | In order to make this easier for the user, there are several CryptoContextFactory methods for the various schemes. 39 | 40 | Streamlining and improving the process of parameter selection and CryptoContext generation is an area that is being actively worked. 41 | 42 | Anything done in OpenFHE is done through the CryptoContext. All operations are CryptoContext methods. The code only allows operations between objects that were created in the same context, and will generate an error if it finds that this is not the case. 43 | 44 | Saving to string or disk file 45 | ----------------------------- 46 | 47 | Serialization and Deserialization 48 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 49 | 50 | An object created by a CryptoContext usually has a ``Serialize`` method that converts the object into a cereal object that can be saved to a string or to a disk file: 51 | 52 | * Serial::Serialize() 53 | 54 | * Serial::SerializeToFile() 55 | 56 | A serialized object can be ``Deserialized`` using the following functions, respectively: 57 | 58 | * Serial::Deserialize() 59 | 60 | * Serial::DeserializeFromFile() 61 | 62 | The Deserialize process will ensure that the serialized object's parameters match the CryptoContext. If they do, then 63 | the new object "belongs to" the CryptoContext and can be used with other objects from the same CryptoContext. 64 | 65 | .. note:: A mismatch of parameters will cause the deserialization to fail. 66 | -------------------------------------------------------------------------------- /src/pke/include/scheme/ckksrns/ckksrns-ser.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | serialize ckks; include this in any app that needs to serialize this scheme 34 | */ 35 | 36 | #ifndef LBCRYPTO_CRYPTO_CKKSRNS_SER_H 37 | #define LBCRYPTO_CRYPTO_CKKSRNS_SER_H 38 | 39 | #include "scheme/ckksrns/ckksrns-scheme.h" 40 | #include "utils/serial.h" 41 | 42 | CEREAL_REGISTER_TYPE(lbcrypto::CryptoParametersCKKSRNS); 43 | CEREAL_REGISTER_TYPE(lbcrypto::SchemeCKKSRNS); 44 | CEREAL_REGISTER_TYPE(lbcrypto::CKKSBootstrapPrecom); 45 | CEREAL_REGISTER_TYPE(lbcrypto::FHECKKSRNS); 46 | CEREAL_REGISTER_TYPE(lbcrypto::SWITCHCKKSRNS); 47 | 48 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::CryptoParametersRNS, lbcrypto::CryptoParametersCKKSRNS); 49 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::FHERNS, lbcrypto::FHECKKSRNS); 50 | CEREAL_REGISTER_POLYMORPHIC_RELATION(lbcrypto::FHERNS, lbcrypto::SWITCHCKKSRNS); 51 | #endif 52 | -------------------------------------------------------------------------------- /src/pke/lib/globals-impl.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #include "globals.h" 33 | 34 | namespace lbcrypto { 35 | 36 | struct GLOBALS { 37 | static bool precomputeCRTTables; 38 | }; 39 | bool GLOBALS::precomputeCRTTables = true; 40 | //============================================================================= 41 | void EnablePrecomputeCRTTablesAfterDeserializaton() { 42 | GLOBALS::precomputeCRTTables = true; 43 | } 44 | //============================================================================= 45 | void DisablePrecomputeCRTTablesAfterDeserializaton() { 46 | GLOBALS::precomputeCRTTables = false; 47 | } 48 | //============================================================================= 49 | bool PrecomputeCRTTablesAfterDeserializaton() { 50 | return GLOBALS::precomputeCRTTables; 51 | } 52 | //============================================================================= 53 | 54 | } // namespace lbcrypto 55 | -------------------------------------------------------------------------------- /src/core/lib/utils/debug.cpp: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | /* 33 | This file contains macros and associated helper functions for quick cerr oriented debugging that can be 34 | quickly enabled and disabled. It also contains functions for timing code 35 | */ 36 | 37 | #include 38 | #include 39 | #include 40 | #include "time.h" 41 | #include "utils/debug.h" 42 | 43 | double currentDateTime() { 44 | std::chrono::time_point now = std::chrono::system_clock::now(); 45 | 46 | time_t tnow = std::chrono::system_clock::to_time_t(now); 47 | tm* date = localtime(&tnow); // todo: dperecated use localtime_s // NOLINT 48 | date->tm_hour = 0; 49 | date->tm_min = 0; 50 | date->tm_sec = 0; 51 | 52 | auto midnight = std::chrono::system_clock::from_time_t(mktime(date)); 53 | 54 | return std::chrono::duration(now - midnight).count(); 55 | } 56 | -------------------------------------------------------------------------------- /CMakeLists.User.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16.3) 2 | 3 | ### To use gcc/g++ on a Macintosh, you must set the Compilers 4 | ### here, not inside the project 5 | ##if(APPLE) 6 | ## set(CMAKE_C_COMPILER "/usr/local/bin/gcc-7") 7 | ## set(CMAKE_CXX_COMPILER "/usr/local/bin/g++-7") 8 | ##endif() 9 | ### TODO: for now, we use CLang for Mac 10 | ### 11 | ### In order to create OpenFHE's static libraries you should enable 12 | ### the BUILD_STATIC option. For that, you run "cmake .. -DBUILD_STATIC=ON". 13 | ### After having your link completed you will find static libs 14 | ### with the suffix "_static" in ./build/libs/. 15 | ### Examples: OPENFHEpke_static.a, OPENFHEcore_static.a, etc. 16 | ### After you run "make install" in your build directory, you can build your custom application. 17 | ### If you need your application to be linked statically, then run "cmake .. -DBUILD_STATIC=ON" 18 | 19 | project(demo CXX) 20 | set(CMAKE_CXX_STANDARD 17) 21 | option(BUILD_STATIC "Set to ON to include static versions of the library" OFF) 22 | 23 | find_package(OpenFHE CONFIG REQUIRED) 24 | if(OpenFHE_FOUND) 25 | message(STATUS "FOUND PACKAGE OpenFHE") 26 | message(STATUS "OpenFHE Version: ${BASE_OPENFHE_VERSION}") 27 | message(STATUS "OpenFHE installed as shared libraries: ${OpenFHE_SHARED}") 28 | message(STATUS "OpenFHE include files location: ${OpenFHE_INCLUDE}") 29 | message(STATUS "OpenFHE lib files location: ${OpenFHE_LIBDIR}") 30 | message(STATUS "OpenFHE Native Backend size: ${OpenFHE_NATIVE_SIZE}") 31 | else() 32 | message(FATAL_ERROR "PACKAGE OpenFHE NOT FOUND") 33 | endif() 34 | 35 | set(CMAKE_CXX_FLAGS ${OpenFHE_CXX_FLAGS}) 36 | 37 | include_directories(${OPENMP_INCLUDES}) 38 | include_directories(${OpenFHE_INCLUDE}) 39 | include_directories(${OpenFHE_INCLUDE}/third-party/include) 40 | include_directories(${OpenFHE_INCLUDE}/core) 41 | include_directories(${OpenFHE_INCLUDE}/pke) 42 | include_directories(${OpenFHE_INCLUDE}/binfhe) 43 | ### add directories for other OpenFHE modules as needed for your project 44 | 45 | if(UNIX AND NOT APPLE) 46 | add_link_options(-Wl,--no-as-needed) 47 | endif() 48 | 49 | link_directories(${OpenFHE_LIBDIR}) 50 | link_directories(${OPENMP_LIBRARIES}) 51 | if(BUILD_STATIC) 52 | set(CMAKE_EXE_LINKER_FLAGS "${OpenFHE_EXE_LINKER_FLAGS} -static") 53 | link_libraries(${OpenFHE_STATIC_LIBRARIES}) 54 | else() 55 | set(CMAKE_EXE_LINKER_FLAGS ${OpenFHE_EXE_LINKER_FLAGS}) 56 | link_libraries(${OpenFHE_SHARED_LIBRARIES}) 57 | endif() 58 | 59 | ### ADD YOUR EXECUTABLE(s) HERE 60 | ### add_executable(EXECUTABLE-NAME SOURCES) 61 | ### 62 | ### EXAMPLE: 63 | ### add_executable(test demo-simple-example.cpp) 64 | -------------------------------------------------------------------------------- /src/pke/include/key/keypair.h: -------------------------------------------------------------------------------- 1 | //================================================================================== 2 | // BSD 2-Clause License 3 | // 4 | // Copyright (c) 2014-2022, NJIT, Duality Technologies Inc. and other contributors 5 | // 6 | // All rights reserved. 7 | // 8 | // Author TPOC: contact@openfhe.org 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions are met: 12 | // 13 | // 1. Redistributions of source code must retain the above copyright notice, this 14 | // list of conditions and the following disclaimer. 15 | // 16 | // 2. Redistributions in binary form must reproduce the above copyright notice, 17 | // this list of conditions and the following disclaimer in the documentation 18 | // and/or other materials provided with the distribution. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | //================================================================================== 31 | 32 | #ifndef LBCRYPTO_CRYPTO_KEY_KEYPAIR_H 33 | #define LBCRYPTO_CRYPTO_KEY_KEYPAIR_H 34 | 35 | #include "key/privatekey.h" 36 | #include "key/publickey.h" 37 | 38 | /** 39 | * @namespace lbcrypto 40 | * The namespace of lbcrypto 41 | */ 42 | namespace lbcrypto { 43 | 44 | template 45 | class KeyPair { 46 | public: 47 | PublicKey publicKey; 48 | PrivateKey secretKey; 49 | 50 | KeyPair(const PublicKey& a, const PrivateKey& b) : publicKey(a), secretKey(b) {} 51 | 52 | explicit KeyPair(PublicKeyImpl* a = nullptr, PrivateKeyImpl* b = nullptr) 53 | : publicKey(a), secretKey(b) {} 54 | 55 | bool good() const { 56 | return publicKey && secretKey; 57 | } 58 | 59 | bool is_allocated() const { 60 | return good(); 61 | } 62 | }; 63 | 64 | } // namespace lbcrypto 65 | 66 | #endif 67 | --------------------------------------------------------------------------------