mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-13 00:28:24 -05:00
Compare commits
24 Commits
create-pul
...
release/0.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99da16b8ad | ||
|
|
b80e09f9d2 | ||
|
|
aae5b45047 | ||
|
|
c0240af4ca | ||
|
|
0578c2ab1d | ||
|
|
d1abdc081d | ||
|
|
44ff195704 | ||
|
|
1fb65f1f6e | ||
|
|
e1f54981bf | ||
|
|
621cbcb14a | ||
|
|
0898268733 | ||
|
|
6ec7f7e405 | ||
|
|
16ad67ace3 | ||
|
|
c949256323 | ||
|
|
7ae5f65909 | ||
|
|
4a2e9e5064 | ||
|
|
3ae27e79d0 | ||
|
|
2332f89aa0 | ||
|
|
3f9603a75c | ||
|
|
848cc37300 | ||
|
|
2f4d00b13a | ||
|
|
2f295ea467 | ||
|
|
fa54a02c01 | ||
|
|
646b644728 |
4
.github/workflows/aws_tfhe_fast_tests.yml
vendored
4
.github/workflows/aws_tfhe_fast_tests.yml
vendored
@@ -114,6 +114,10 @@ jobs:
|
||||
run: |
|
||||
make test_safe_deserialization
|
||||
|
||||
- name: Run forward compatibility tests
|
||||
run: |
|
||||
make test_forward_compatibility
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ always() }}
|
||||
continue-on-error: true
|
||||
|
||||
4
.github/workflows/aws_tfhe_tests.yml
vendored
4
.github/workflows/aws_tfhe_tests.yml
vendored
@@ -81,6 +81,10 @@ jobs:
|
||||
run: |
|
||||
make test_c_api
|
||||
|
||||
- name: Run C API tests with forward_compatibility
|
||||
run: |
|
||||
FORWARD_COMPAT=ON make test_c_api
|
||||
|
||||
- name: Run user docs tests
|
||||
run: |
|
||||
make test_user_doc
|
||||
|
||||
153
Makefile
153
Makefile
@@ -6,7 +6,7 @@ TARGET_ARCH_FEATURE:=$(shell ./scripts/get_arch_feature.sh)
|
||||
RS_BUILD_TOOLCHAIN:=stable
|
||||
CARGO_RS_BUILD_TOOLCHAIN:=+$(RS_BUILD_TOOLCHAIN)
|
||||
CARGO_PROFILE?=release
|
||||
MIN_RUST_VERSION:=$(shell grep rust-version tfhe/Cargo.toml | cut -d '=' -f 2 | xargs)
|
||||
MIN_RUST_VERSION:=$(shell grep '^rust-version[[:space:]]*=' tfhe/Cargo.toml | cut -d '=' -f 2 | xargs)
|
||||
AVX512_SUPPORT?=OFF
|
||||
WASM_RUSTFLAGS:=
|
||||
BIG_TESTS_INSTANCE?=FALSE
|
||||
@@ -16,6 +16,12 @@ PARSE_INTEGER_BENCH_CSV_FILE?=tfhe_rs_integer_benches.csv
|
||||
FAST_TESTS?=FALSE
|
||||
FAST_BENCH?=FALSE
|
||||
BENCH_OP_FLAVOR?=DEFAULT
|
||||
NODE_VERSION=20
|
||||
FORWARD_COMPAT?=OFF
|
||||
TFHE_CURRENT_VERSION:=$(shell grep '^version[[:space:]]*=' tfhe/Cargo.toml | cut -d '=' -f 2 | xargs)
|
||||
# Cargo has a hard time distinguishing between our package from the workspace and a package that
|
||||
# could be a dependency, so we build an unambiguous spec here
|
||||
TFHE_SPEC:=tfhe@$(TFHE_CURRENT_VERSION)
|
||||
# This is done to avoid forgetting it, we still precise the RUSTFLAGS in the commands to be able to
|
||||
# copy paste the command in the terminal and change them if required without forgetting the flags
|
||||
export RUSTFLAGS?=-C target-cpu=native
|
||||
@@ -38,6 +44,12 @@ else
|
||||
COVERAGE_ONLY=
|
||||
endif
|
||||
|
||||
ifeq ($(FORWARD_COMPAT),ON)
|
||||
FORWARD_COMPAT_FEATURE=forward_compatibility
|
||||
else
|
||||
FORWARD_COMPAT_FEATURE=
|
||||
endif
|
||||
|
||||
# Variables used only for regex_engine example
|
||||
REGEX_STRING?=''
|
||||
REGEX_PATTERN?=''
|
||||
@@ -99,7 +111,7 @@ install_wasm_pack: install_rs_build_toolchain
|
||||
install_node:
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | $(SHELL)
|
||||
source ~/.bashrc
|
||||
$(SHELL) -i -c 'nvm install node' || \
|
||||
$(SHELL) -i -c 'nvm install $(NODE_VERSION)' || \
|
||||
( echo "Unable to install node, unknown error." && exit 1 )
|
||||
|
||||
.PHONY: install_dieharder # Install dieharder for apt distributions or macOS
|
||||
@@ -142,46 +154,52 @@ check_newline: check_linelint_installed
|
||||
clippy_core: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE) \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),nightly-avx512 \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,nightly-avx512 \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_boolean # Run clippy lints enabling the boolean features
|
||||
clippy_boolean: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_shortint # Run clippy lints enabling the shortint features
|
||||
clippy_shortint: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_integer # Run clippy lints enabling the integer features
|
||||
clippy_integer: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),integer \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy # Run clippy lints enabling the boolean, shortint, integer
|
||||
clippy: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_c_api # Run clippy lints enabling the boolean, shortint and the C API
|
||||
clippy_c_api: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_js_wasm_api # Run clippy lints enabling the boolean, shortint, integer and the js wasm API
|
||||
clippy_js_wasm_api: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_tasks # Run clippy lints on helper tasks crate.
|
||||
clippy_tasks:
|
||||
@@ -190,15 +208,20 @@ clippy_tasks:
|
||||
|
||||
.PHONY: clippy_trivium # Run clippy lints on Trivium app
|
||||
clippy_trivium: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy -p tfhe-trivium \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
-p tfhe-trivium -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_all_targets # Run clippy lints on all targets (benches, examples, etc.)
|
||||
clippy_all_targets:
|
||||
clippy_all_targets: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,safe-deserialization \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_all_targets_forward_compatibility # Run clippy lints on all targets (benches, examples, etc.)
|
||||
clippy_all_targets_forward_compatibility: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,safe-deserialization,forward_compatibility \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_concrete_csprng # Run clippy lints on concrete-csprng
|
||||
clippy_concrete_csprng:
|
||||
@@ -208,7 +231,8 @@ clippy_concrete_csprng:
|
||||
|
||||
.PHONY: clippy_all # Run all clippy targets
|
||||
clippy_all: clippy clippy_boolean clippy_shortint clippy_integer clippy_all_targets clippy_c_api \
|
||||
clippy_js_wasm_api clippy_tasks clippy_core clippy_concrete_csprng clippy_trivium
|
||||
clippy_js_wasm_api clippy_tasks clippy_core clippy_concrete_csprng clippy_trivium \
|
||||
clippy_all_targets_forward_compatibility
|
||||
|
||||
.PHONY: clippy_fast # Run main clippy targets
|
||||
clippy_fast: clippy clippy_all_targets clippy_c_api clippy_js_wasm_api clippy_tasks clippy_core \
|
||||
@@ -218,58 +242,66 @@ clippy_concrete_csprng
|
||||
gen_key_cache: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) run --profile $(CARGO_PROFILE) \
|
||||
--example generates_test_keys \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,internal-keycache -p tfhe -- \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,internal-keycache -- \
|
||||
$(MULTI_BIT_ONLY) $(COVERAGE_ONLY)
|
||||
|
||||
.PHONY: build_core # Build core_crypto without experimental features
|
||||
build_core: install_rs_build_toolchain install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE) -p tfhe
|
||||
--features=$(TARGET_ARCH_FEATURE) -p $(TFHE_SPEC)
|
||||
@if [[ "$(AVX512_SUPPORT)" == "ON" ]]; then \
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),$(AVX512_FEATURE) -p tfhe; \
|
||||
--features=$(TARGET_ARCH_FEATURE),$(AVX512_FEATURE) -p $(TFHE_SPEC); \
|
||||
fi
|
||||
|
||||
.PHONY: build_core_experimental # Build core_crypto with experimental features
|
||||
build_core_experimental: install_rs_build_toolchain install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental -p tfhe
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental -p $(TFHE_SPEC)
|
||||
@if [[ "$(AVX512_SUPPORT)" == "ON" ]]; then \
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,$(AVX512_FEATURE) -p tfhe; \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,$(AVX512_FEATURE) -p $(TFHE_SPEC); \
|
||||
fi
|
||||
|
||||
.PHONY: build_boolean # Build with boolean enabled
|
||||
build_boolean: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean -p tfhe --all-targets
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean -p $(TFHE_SPEC) --all-targets
|
||||
|
||||
.PHONY: build_shortint # Build with shortint enabled
|
||||
build_shortint: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint -p tfhe --all-targets
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint -p $(TFHE_SPEC) --all-targets
|
||||
|
||||
.PHONY: build_integer # Build with integer enabled
|
||||
build_integer: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),integer -p tfhe --all-targets
|
||||
--features=$(TARGET_ARCH_FEATURE),integer -p $(TFHE_SPEC) --all-targets
|
||||
|
||||
.PHONY: build_tfhe_full # Build with boolean, shortint and integer enabled
|
||||
build_tfhe_full: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer -p tfhe --all-targets
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer -p $(TFHE_SPEC) --all-targets
|
||||
|
||||
.PHONY: symlink_c_libs_without_fingerprint # Link the .a and .so files without the changing hash part in target
|
||||
symlink_c_libs_without_fingerprint:
|
||||
@./scripts/symlink_c_libs_without_fingerprint.sh \
|
||||
--cargo-profile "$(CARGO_PROFILE)" \
|
||||
--lib-name tfhe-c-api-dynamic-buffer
|
||||
|
||||
.PHONY: build_c_api # Build the C API for boolean, shortint and integer
|
||||
build_c_api: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api,high-level-c-api,safe-deserialization \
|
||||
-p tfhe
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api,high-level-c-api,safe-deserialization,$(FORWARD_COMPAT_FEATURE) \
|
||||
-p $(TFHE_SPEC)
|
||||
@"$(MAKE)" symlink_c_libs_without_fingerprint
|
||||
|
||||
.PHONY: build_c_api_experimental_deterministic_fft # Build the C API for boolean, shortint and integer with experimental deterministic FFT
|
||||
build_c_api_experimental_deterministic_fft: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api,high-level-c-api,safe-deserialization,experimental-force_fft_algo_dif4 \
|
||||
-p tfhe
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api,high-level-c-api,safe-deserialization,experimental-force_fft_algo_dif4,$(FORWARD_COMPAT_FEATURE) \
|
||||
-p $(TFHE_SPEC)
|
||||
@"$(MAKE)" symlink_c_libs_without_fingerprint
|
||||
|
||||
.PHONY: build_web_js_api # Build the js API targeting the web browser
|
||||
build_web_js_api: install_rs_build_toolchain install_wasm_pack
|
||||
@@ -302,16 +334,16 @@ build_concrete_csprng: install_rs_build_toolchain
|
||||
.PHONY: test_core_crypto # Run the tests of the core_crypto module including experimental ones
|
||||
test_core_crypto: install_rs_build_toolchain install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental -p tfhe -- core_crypto::
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental -p $(TFHE_SPEC) -- core_crypto::
|
||||
@if [[ "$(AVX512_SUPPORT)" == "ON" ]]; then \
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,$(AVX512_FEATURE) -p tfhe -- core_crypto::; \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,$(AVX512_FEATURE) -p $(TFHE_SPEC) -- core_crypto::; \
|
||||
fi
|
||||
|
||||
.PHONY: test_boolean # Run the tests of the boolean module
|
||||
test_boolean: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean -p tfhe -- boolean::
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean -p $(TFHE_SPEC) -- boolean::
|
||||
|
||||
.PHONY: test_boolean_cov # Run the tests of the boolean module with code coverage
|
||||
test_boolean_cov: install_rs_check_toolchain install_tarpaulin
|
||||
@@ -319,18 +351,18 @@ test_boolean_cov: install_rs_check_toolchain install_tarpaulin
|
||||
--out xml --output-dir coverage/boolean --line --engine llvm --timeout 500 \
|
||||
$(COVERAGE_EXCLUDED_FILES) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,internal-keycache,__coverage \
|
||||
-p tfhe -- boolean::
|
||||
-p $(TFHE_SPEC) -- boolean::
|
||||
|
||||
.PHONY: test_c_api_rs # Run the rust tests for the C API
|
||||
test_c_api_rs: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api,high-level-c-api,safe-deserialization \
|
||||
-p tfhe \
|
||||
-p $(TFHE_SPEC) \
|
||||
c_api
|
||||
|
||||
.PHONY: test_c_api_c # Run the C tests for the C API
|
||||
test_c_api_c: build_c_api
|
||||
./scripts/c_api_tests.sh
|
||||
./scripts/c_api_tests.sh --forward-compat "$(FORWARD_COMPAT)"
|
||||
|
||||
.PHONY: test_c_api # Run all the tests for the C API
|
||||
test_c_api: test_c_api_rs test_c_api_c
|
||||
@@ -340,19 +372,19 @@ test_shortint_ci: install_rs_build_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/shortint-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)"
|
||||
--cargo-profile "$(CARGO_PROFILE)" --tfhe-package "$(TFHE_SPEC)"
|
||||
|
||||
.PHONY: test_shortint_multi_bit_ci # Run the tests for shortint ci running only multibit tests
|
||||
test_shortint_multi_bit_ci: install_rs_build_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/shortint-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --multi-bit
|
||||
--cargo-profile "$(CARGO_PROFILE)" --multi-bit --tfhe-package "$(TFHE_SPEC)"
|
||||
|
||||
.PHONY: test_shortint # Run all the tests for shortint
|
||||
test_shortint: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache -p tfhe -- shortint::
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache -p $(TFHE_SPEC) -- shortint::
|
||||
|
||||
.PHONY: test_shortint_cov # Run the tests of the shortint module with code coverage
|
||||
test_shortint_cov: install_rs_check_toolchain install_tarpaulin
|
||||
@@ -360,42 +392,48 @@ test_shortint_cov: install_rs_check_toolchain install_tarpaulin
|
||||
--out xml --output-dir coverage/shortint --line --engine llvm --timeout 500 \
|
||||
$(COVERAGE_EXCLUDED_FILES) \
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache,__coverage \
|
||||
-p tfhe -- shortint::
|
||||
-p $(TFHE_SPEC) -- shortint::
|
||||
|
||||
.PHONY: test_integer_ci # Run the tests for integer ci
|
||||
test_integer_ci: install_rs_build_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)"
|
||||
--cargo-profile "$(CARGO_PROFILE)" --tfhe-package "$(TFHE_SPEC)"
|
||||
|
||||
.PHONY: test_integer_multi_bit_ci # Run the tests for integer ci running only multibit tests
|
||||
test_integer_multi_bit_ci: install_rs_build_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --multi-bit
|
||||
--cargo-profile "$(CARGO_PROFILE)" --multi-bit --tfhe-package "$(TFHE_SPEC)"
|
||||
|
||||
.PHONY: test_safe_deserialization # Run the tests for safe deserialization
|
||||
test_safe_deserialization: install_rs_build_toolchain install_cargo_nextest
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,safe-deserialization -p tfhe -- safe_deserialization::
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,safe-deserialization -p $(TFHE_SPEC) -- safe_deserialization::
|
||||
|
||||
.PHONY: test_integer # Run all the tests for integer
|
||||
test_integer: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),integer,internal-keycache -p tfhe -- integer::
|
||||
--features=$(TARGET_ARCH_FEATURE),integer,internal-keycache -p $(TFHE_SPEC) -- integer::
|
||||
|
||||
.PHONY: test_high_level_api # Run all the tests for high_level_api
|
||||
test_high_level_api: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache -p tfhe \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache -p $(TFHE_SPEC) \
|
||||
-- high_level_api::
|
||||
|
||||
.PHONY: test_forward_compatibility # Run forward compatibility tests
|
||||
test_forward_compatibility: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --tests --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,forward_compatibility,internal-keycache -p $(TFHE_SPEC) \
|
||||
-- forward_compatibility::
|
||||
|
||||
.PHONY: test_user_doc # Run tests from the .md documentation
|
||||
test_user_doc: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) --doc \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache -p tfhe \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache -p $(TFHE_SPEC) \
|
||||
-- test_user_docs::
|
||||
|
||||
.PHONY: test_regex_engine # Run tests for regex_engine example
|
||||
@@ -459,17 +497,19 @@ format_doc_latex:
|
||||
check_compile_tests:
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --no-run \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,boolean,shortint,integer,internal-keycache,safe-deserialization \
|
||||
-p tfhe
|
||||
-p $(TFHE_SPEC)
|
||||
|
||||
@if [[ "$(OS)" == "Linux" || "$(OS)" == "Darwin" ]]; then \
|
||||
"$(MAKE)" build_c_api; \
|
||||
./scripts/c_api_tests.sh --build-only; \
|
||||
"$(MAKE)" build_c_api && \
|
||||
./scripts/c_api_tests.sh --build-only --forward-compat "$(FORWARD_COMPAT)" && \
|
||||
FORWARD_COMPAT=ON "$(MAKE)" build_c_api && \
|
||||
./scripts/c_api_tests.sh --build-only --forward-compat "$(FORWARD_COMPAT)"; \
|
||||
fi
|
||||
|
||||
.PHONY: build_nodejs_test_docker # Build a docker image with tools to run nodejs tests for wasm API
|
||||
build_nodejs_test_docker:
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg RUST_TOOLCHAIN="$(RS_BUILD_TOOLCHAIN)" \
|
||||
-f docker/Dockerfile.wasm_tests -t tfhe-wasm-tests .
|
||||
-f docker/Dockerfile.wasm_tests --build-arg NODE_VERSION=$(NODE_VERSION) -t tfhe-wasm-tests .
|
||||
|
||||
.PHONY: test_nodejs_wasm_api_in_docker # Run tests for the nodejs on wasm API in a docker container
|
||||
test_nodejs_wasm_api_in_docker: build_nodejs_test_docker
|
||||
@@ -493,7 +533,8 @@ test_web_js_api_parallel: build_web_js_api_parallel
|
||||
.PHONY: ci_test_web_js_api_parallel # Run tests for the web wasm api
|
||||
ci_test_web_js_api_parallel: build_web_js_api_parallel
|
||||
source ~/.nvm/nvm.sh && \
|
||||
nvm use node && \
|
||||
nvm install $(NODE_VERSION) && \
|
||||
nvm use $(NODE_VERSION) && \
|
||||
$(MAKE) -C tfhe/web_wasm_parallel_tests test-ci
|
||||
|
||||
.PHONY: no_tfhe_typo # Check we did not invert the h and f in tfhe
|
||||
@@ -517,7 +558,7 @@ bench_integer: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) __TFHE_RS_FAST_BENCH=$(FAST_BENCH) \
|
||||
cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench integer-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,$(AVX512_FEATURE) -p tfhe --
|
||||
--features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_SPEC) --
|
||||
|
||||
.PHONY: bench_integer_multi_bit # Run benchmarks for integer using multi-bit parameters
|
||||
bench_integer_multi_bit: install_rs_check_toolchain
|
||||
@@ -525,14 +566,14 @@ bench_integer_multi_bit: install_rs_check_toolchain
|
||||
__TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) __TFHE_RS_FAST_BENCH=$(FAST_BENCH) \
|
||||
cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench integer-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,$(AVX512_FEATURE) -p tfhe --
|
||||
--features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_SPEC) --
|
||||
|
||||
.PHONY: bench_shortint # Run benchmarks for shortint
|
||||
bench_shortint: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) \
|
||||
cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench shortint-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache,$(AVX512_FEATURE) -p tfhe
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_SPEC)
|
||||
|
||||
.PHONY: bench_shortint_multi_bit # Run benchmarks for shortint using multi-bit parameters
|
||||
bench_shortint_multi_bit: install_rs_check_toolchain
|
||||
@@ -540,20 +581,20 @@ bench_shortint_multi_bit: install_rs_check_toolchain
|
||||
__TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) \
|
||||
cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench shortint-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache,$(AVX512_FEATURE) -p tfhe --
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_SPEC) --
|
||||
|
||||
|
||||
.PHONY: bench_boolean # Run benchmarks for boolean
|
||||
bench_boolean: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench boolean-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,internal-keycache,$(AVX512_FEATURE) -p tfhe
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_SPEC)
|
||||
|
||||
.PHONY: bench_pbs # Run benchmarks for PBS
|
||||
bench_pbs: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench pbs-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,internal-keycache,$(AVX512_FEATURE) -p tfhe
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_SPEC)
|
||||
|
||||
.PHONY: bench_web_js_api_parallel # Run benchmarks for the web wasm api
|
||||
bench_web_js_api_parallel: build_web_js_api_parallel
|
||||
|
||||
@@ -11,6 +11,7 @@ RUN sed -i 's|^deb http://archive.ubuntu.com/ubuntu/|deb http://mirror.ubuntu.ik
|
||||
ENV CARGO_TARGET_DIR=/root/tfhe-rs-target
|
||||
|
||||
ARG RUST_TOOLCHAIN="stable"
|
||||
ARG NODE_VERSION
|
||||
|
||||
WORKDIR /tfhe-wasm-tests
|
||||
|
||||
@@ -34,6 +35,6 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > install-rustup.s
|
||||
chmod +x install-node.sh && \
|
||||
./install-node.sh && \
|
||||
. "$HOME/.nvm/nvm.sh" && \
|
||||
bash -i -c 'nvm install node && nvm use node'
|
||||
bash -i -c 'nvm install ${NODE_VERSION} && nvm use ${NODE_VERSION}'
|
||||
|
||||
WORKDIR /tfhe-wasm-tests/tfhe-rs/
|
||||
|
||||
@@ -7,10 +7,12 @@ function usage() {
|
||||
echo
|
||||
echo "--help Print this message"
|
||||
echo "--build-only Pass to only build the tests without running them"
|
||||
echo "--forward-compat Indicate if we have forward compatibility enabled"
|
||||
echo
|
||||
}
|
||||
|
||||
BUILD_ONLY=0
|
||||
forward_compat="OFF"
|
||||
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
@@ -24,6 +26,11 @@ do
|
||||
BUILD_ONLY=1
|
||||
;;
|
||||
|
||||
"--forward-compat" )
|
||||
shift
|
||||
forward_compat="$1"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown param : $1"
|
||||
exit 1
|
||||
@@ -35,12 +42,18 @@ done
|
||||
CURR_DIR="$(dirname "$0")"
|
||||
REPO_ROOT="${CURR_DIR}/.."
|
||||
TFHE_BUILD_DIR="${REPO_ROOT}/tfhe/build/"
|
||||
DEFINE_FORWARD_COMPAT="OFF"
|
||||
|
||||
if [[ "${forward_compat}" == "ON" ]]; then
|
||||
DEFINE_FORWARD_COMPAT="ON"
|
||||
fi
|
||||
|
||||
mkdir -p "${TFHE_BUILD_DIR}"
|
||||
|
||||
cd "${TFHE_BUILD_DIR}"
|
||||
|
||||
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCARGO_PROFILE="${CARGO_PROFILE}"
|
||||
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCARGO_PROFILE="${CARGO_PROFILE}" \
|
||||
"-DWITH_FORWARD_COMPATIBILITY=${DEFINE_FORWARD_COMPAT}"
|
||||
|
||||
make -j
|
||||
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
set -e
|
||||
|
||||
function usage() {
|
||||
echo "$0: shortint test runner"
|
||||
echo "$0: integer test runner"
|
||||
echo
|
||||
echo "--help Print this message"
|
||||
echo "--rust-toolchain The toolchain to run the tests with default: stable"
|
||||
echo "--multi-bit Run multi-bit tests only: default off"
|
||||
echo "--cargo-profile The cargo profile used to build tests"
|
||||
echo "--tfhe-package The package spec like tfhe@0.4.2, default=tfhe"
|
||||
echo
|
||||
}
|
||||
|
||||
@@ -16,6 +17,7 @@ RUST_TOOLCHAIN="+stable"
|
||||
multi_bit=""
|
||||
not_multi_bit="_multi_bit"
|
||||
cargo_profile="release"
|
||||
tfhe_package="tfhe"
|
||||
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
@@ -40,6 +42,11 @@ do
|
||||
cargo_profile="$1"
|
||||
;;
|
||||
|
||||
"--tfhe-package" )
|
||||
shift
|
||||
tfhe_package="$1"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown param : $1"
|
||||
exit 1
|
||||
@@ -102,7 +109,7 @@ and not test(/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs
|
||||
cargo "${RUST_TOOLCHAIN}" nextest run \
|
||||
--tests \
|
||||
--cargo-profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--package "${tfhe_package}" \
|
||||
--profile ci \
|
||||
--features="${ARCH_FEATURE}",integer,internal-keycache \
|
||||
--test-threads "${n_threads}" \
|
||||
@@ -111,7 +118,7 @@ and not test(/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs
|
||||
if [[ "${multi_bit}" == "" ]]; then
|
||||
cargo "${RUST_TOOLCHAIN}" test \
|
||||
--profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--package "${tfhe_package}" \
|
||||
--features="${ARCH_FEATURE}",integer,internal-keycache \
|
||||
--doc \
|
||||
-- integer::
|
||||
@@ -146,7 +153,7 @@ and not test(/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs
|
||||
cargo "${RUST_TOOLCHAIN}" nextest run \
|
||||
--tests \
|
||||
--cargo-profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--package "${tfhe_package}" \
|
||||
--profile ci \
|
||||
--features="${ARCH_FEATURE}",integer,internal-keycache \
|
||||
--test-threads $num_threads \
|
||||
@@ -155,7 +162,7 @@ and not test(/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs
|
||||
if [[ "${multi_bit}" == "" ]]; then
|
||||
cargo "${RUST_TOOLCHAIN}" test \
|
||||
--profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--package "${tfhe_package}" \
|
||||
--features="${ARCH_FEATURE}",integer,internal-keycache \
|
||||
--doc \
|
||||
-- --test-threads="$(${nproc_bin})" integer::
|
||||
|
||||
@@ -9,12 +9,14 @@ function usage() {
|
||||
echo "--rust-toolchain The toolchain to run the tests with default: stable"
|
||||
echo "--multi-bit Run multi-bit tests only: default off"
|
||||
echo "--cargo-profile The cargo profile used to build tests"
|
||||
echo "--tfhe-package The package spec like tfhe@0.4.2, default=tfhe"
|
||||
echo
|
||||
}
|
||||
|
||||
RUST_TOOLCHAIN="+stable"
|
||||
multi_bit=""
|
||||
cargo_profile="release"
|
||||
tfhe_package="tfhe"
|
||||
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
@@ -38,6 +40,11 @@ do
|
||||
cargo_profile="$1"
|
||||
;;
|
||||
|
||||
"--tfhe-package" )
|
||||
shift
|
||||
tfhe_package="$1"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown param : $1"
|
||||
exit 1
|
||||
@@ -110,7 +117,7 @@ and not test(~smart_add_and_mul)""" # This test is too slow
|
||||
cargo "${RUST_TOOLCHAIN}" nextest run \
|
||||
--tests \
|
||||
--cargo-profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--package "${tfhe_package}" \
|
||||
--profile ci \
|
||||
--features="${ARCH_FEATURE}",shortint,internal-keycache \
|
||||
--test-threads "${n_threads_small}" \
|
||||
@@ -127,7 +134,7 @@ and not test(~smart_add_and_mul)"""
|
||||
cargo "${RUST_TOOLCHAIN}" nextest run \
|
||||
--tests \
|
||||
--cargo-profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--package "${tfhe_package}" \
|
||||
--profile ci \
|
||||
--features="${ARCH_FEATURE}",shortint,internal-keycache \
|
||||
--test-threads "${n_threads_big}" \
|
||||
@@ -136,7 +143,7 @@ and not test(~smart_add_and_mul)"""
|
||||
if [[ "${multi_bit}" == "" ]]; then
|
||||
cargo "${RUST_TOOLCHAIN}" test \
|
||||
--profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--package "${tfhe_package}" \
|
||||
--features="${ARCH_FEATURE}",shortint,internal-keycache \
|
||||
--doc \
|
||||
-- shortint::
|
||||
@@ -175,7 +182,7 @@ and not test(~smart_add_and_mul)""" # This test is too slow
|
||||
cargo "${RUST_TOOLCHAIN}" nextest run \
|
||||
--tests \
|
||||
--cargo-profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--package "${tfhe_package}" \
|
||||
--profile ci \
|
||||
--features="${ARCH_FEATURE}",shortint,internal-keycache \
|
||||
--test-threads "$(${nproc_bin})" \
|
||||
@@ -184,7 +191,7 @@ and not test(~smart_add_and_mul)""" # This test is too slow
|
||||
if [[ "${multi_bit}" == "" ]]; then
|
||||
cargo "${RUST_TOOLCHAIN}" test \
|
||||
--profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--package "${tfhe_package}" \
|
||||
--features="${ARCH_FEATURE}",shortint,internal-keycache \
|
||||
--doc \
|
||||
-- --test-threads="$(${nproc_bin})" shortint::
|
||||
|
||||
90
scripts/symlink_c_libs_without_fingerprint.sh
Executable file
90
scripts/symlink_c_libs_without_fingerprint.sh
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
function usage() {
|
||||
echo "$0: symlink C libs to names without the variable fingerprint part"
|
||||
echo
|
||||
echo "--help Print this message"
|
||||
echo "--cargo-profile The cargo profile used"
|
||||
echo "--lib-name The lib name without the lib prefix, '-' will be converted to '_'"
|
||||
echo
|
||||
}
|
||||
|
||||
CARGO_PROFILE=""
|
||||
LIBNAME=""
|
||||
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
case "$1" in
|
||||
"--help" | "-h" )
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
|
||||
"--cargo-profile" )
|
||||
shift
|
||||
CARGO_PROFILE="$1"
|
||||
;;
|
||||
|
||||
"--lib-name" )
|
||||
shift
|
||||
LIBNAME="$1"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown param : $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ "${CARGO_PROFILE}" == "" ]]; then
|
||||
echo "CARGO_PROFILE is not set, aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
UNAME="$(uname)"
|
||||
if [[ "${UNAME}" != "Linux" && "${UNAME}" != "Darwin" ]]; then
|
||||
echo "This script is compatible with Linux and macOS and may not work for your system"
|
||||
fi
|
||||
|
||||
# Add the lib prefix
|
||||
LIB_OF_INTEREST="lib${LIBNAME}"
|
||||
LIB_OF_INTEREST_UNDERSCORE="${LIB_OF_INTEREST//-/_}"
|
||||
|
||||
CURR_DIR="$(dirname "$0")"
|
||||
REPO_DIR="${CURR_DIR}/.."
|
||||
OUTPUT_TARGET_DIR="${REPO_DIR}/target/${CARGO_PROFILE}"
|
||||
OUTPUT_DEPS_DIR="${OUTPUT_TARGET_DIR}/deps"
|
||||
|
||||
cd "${OUTPUT_DEPS_DIR}"
|
||||
echo "In ${PWD}"
|
||||
# Find most recent file with similar name
|
||||
MAYBE_STATIC_LIB="$(find . -maxdepth 1 -type f -name "${LIB_OF_INTEREST_UNDERSCORE}*.a")"
|
||||
if [[ "${MAYBE_STATIC_LIB}" != "" ]]; then
|
||||
STATIC_LIB="$(find . -maxdepth 1 -type f -name "${LIB_OF_INTEREST_UNDERSCORE}*.a" -print0 \
|
||||
| xargs -0 ls -t | head -n 1)"
|
||||
echo "Symlinking ${STATIC_LIB} to ${LIB_OF_INTEREST_UNDERSCORE}.a"
|
||||
ln -snf "${STATIC_LIB}" "${LIB_OF_INTEREST_UNDERSCORE}.a"
|
||||
else
|
||||
echo "Could not find static lib that might correspond to $1, is there a typo in the lib name?"
|
||||
fi
|
||||
|
||||
DYNAMIC_LIB_EXT="so"
|
||||
if [[ "${UNAME}" == "Darwin" ]]; then
|
||||
DYNAMIC_LIB_EXT="dylib"
|
||||
fi
|
||||
|
||||
DYNAMIC_LIB_PATTERN="${LIB_OF_INTEREST_UNDERSCORE}*.${DYNAMIC_LIB_EXT}"
|
||||
|
||||
MAYBE_DYNAMIC_LIB="$(find . -maxdepth 1 -type f -name "${DYNAMIC_LIB_PATTERN}")"
|
||||
if [[ "${MAYBE_DYNAMIC_LIB}" != "" ]]; then
|
||||
DYNAMIC_LIB="$(find . -maxdepth 1 -type f -name "${DYNAMIC_LIB_PATTERN}" -print0 \
|
||||
| xargs -0 ls -t | head -n 1)"
|
||||
echo "Symlinking ${DYNAMIC_LIB} to ${LIB_OF_INTEREST_UNDERSCORE}.${DYNAMIC_LIB_EXT}"
|
||||
ln -snf "${DYNAMIC_LIB}" "${LIB_OF_INTEREST_UNDERSCORE}.${DYNAMIC_LIB_EXT}"
|
||||
else
|
||||
echo "Could not find dynamic lib that might correspond to $1, is there a typo in the lib name?"
|
||||
fi
|
||||
@@ -196,7 +196,7 @@ fn find_contiguous_doc_test<'a>(
|
||||
|
||||
fn find_contiguous_part_in_doc_test_or_comment(
|
||||
part_is_code_block: bool,
|
||||
full_doc_comment_content: &Vec<CommentContent>,
|
||||
full_doc_comment_content: &[CommentContent],
|
||||
part_start_idx: usize,
|
||||
) -> (usize, usize) {
|
||||
let mut next_line_idx = part_start_idx + 1;
|
||||
@@ -348,7 +348,7 @@ fn process_doc_lines_until_impossible<'a>(
|
||||
}
|
||||
|
||||
fn process_non_doc_lines_until_impossible(
|
||||
lines: &Vec<&str>,
|
||||
lines: &[&str],
|
||||
rewritten_content: &mut String,
|
||||
mut line_idx: usize,
|
||||
) -> usize {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tfhe"
|
||||
version = "0.4.0"
|
||||
version = "0.4.4"
|
||||
edition = "2021"
|
||||
readme = "../README.md"
|
||||
keywords = ["fully", "homomorphic", "encryption", "fhe", "cryptography"]
|
||||
@@ -46,10 +46,10 @@ log = "0.4.19"
|
||||
# End regex-engine deps
|
||||
|
||||
[build-dependencies]
|
||||
cbindgen = { version = "0.26.0", optional = true }
|
||||
cbindgen = { package = "tfhe-c-api-bindgen", version = "0.26.1", optional = true }
|
||||
|
||||
[dependencies]
|
||||
concrete-csprng = { version = "0.4.0", path= "../concrete-csprng", features = [
|
||||
concrete-csprng = { version = "0.4.0", path = "../concrete-csprng", features = [
|
||||
"generator_fallback",
|
||||
"parallel",
|
||||
] }
|
||||
@@ -57,14 +57,18 @@ lazy_static = { version = "1.4.0", optional = true }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
rayon = { version = "1.5.0" }
|
||||
bincode = { version = "1.3.3", optional = true }
|
||||
concrete-fft = { version = "0.3.0", features = ["serde", "fft128"] }
|
||||
pulp = "0.13"
|
||||
concrete-fft = { version = "0.4.0", features = ["serde", "fft128"] }
|
||||
pulp = "0.18.8"
|
||||
aligned-vec = { version = "0.5", features = ["serde"] }
|
||||
dyn-stack = { version = "0.9" }
|
||||
paste = { version = "1.0.7", optional = true }
|
||||
fs2 = { version = "0.4.3", optional = true }
|
||||
# While we wait for repeat_n in rust standard library
|
||||
itertools = "0.11.0"
|
||||
tfhe-c-api-dynamic-buffer = { version = "0.1.0", optional = true, features = [
|
||||
"c_api",
|
||||
] }
|
||||
next_tfhe = { package = "tfhe", version = "0.5.0", optional = true }
|
||||
|
||||
# wasm deps
|
||||
wasm-bindgen = { version = "0.2.86", features = [
|
||||
@@ -75,32 +79,52 @@ js-sys = { version = "0.3", optional = true }
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
serde-wasm-bindgen = { version = "0.6.0", optional = true }
|
||||
getrandom = { version = "0.2.8", optional = true }
|
||||
bytemuck = "1.13.1"
|
||||
bytemuck = "1.14.3"
|
||||
|
||||
[features]
|
||||
forward_compatibility = [
|
||||
"dep:bincode",
|
||||
"dep:tfhe-c-api-dynamic-buffer",
|
||||
"dep:next_tfhe",
|
||||
"dep:paste",
|
||||
]
|
||||
|
||||
# paste is used by the HL API
|
||||
boolean = ["dep:paste"]
|
||||
shortint = ["dep:paste"]
|
||||
integer = ["shortint", "dep:paste"]
|
||||
internal-keycache = ["lazy_static", "dep:fs2", "dep:bincode", "dep:paste"]
|
||||
boolean = ["dep:paste", "next_tfhe?/boolean"]
|
||||
shortint = ["dep:paste", "next_tfhe?/shortint"]
|
||||
integer = ["shortint", "dep:paste", "next_tfhe?/integer"]
|
||||
internal-keycache = [
|
||||
"dep:lazy_static",
|
||||
"dep:fs2",
|
||||
"dep:bincode",
|
||||
"dep:paste",
|
||||
"next_tfhe?/internal-keycache",
|
||||
]
|
||||
safe-deserialization = ["dep:bincode"]
|
||||
|
||||
# Experimental section
|
||||
experimental = []
|
||||
experimental-force_fft_algo_dif4 = []
|
||||
experimental = ["next_tfhe?/experimental"]
|
||||
experimental-force_fft_algo_dif4 = [
|
||||
"next_tfhe?/experimental-force_fft_algo_dif4",
|
||||
]
|
||||
# End experimental section
|
||||
|
||||
__c_api = ["cbindgen", "dep:bincode", "dep:paste"]
|
||||
__c_api = [
|
||||
"dep:cbindgen",
|
||||
"dep:bincode",
|
||||
"dep:paste",
|
||||
"next_tfhe?/__force_skip_cbindgen",
|
||||
]
|
||||
boolean-c-api = ["boolean", "__c_api"]
|
||||
shortint-c-api = ["shortint", "__c_api"]
|
||||
high-level-c-api = ["boolean-c-api", "shortint-c-api", "integer", "__c_api"]
|
||||
|
||||
__wasm_api = [
|
||||
"wasm-bindgen",
|
||||
"js-sys",
|
||||
"console_error_panic_hook",
|
||||
"serde-wasm-bindgen",
|
||||
"getrandom",
|
||||
"dep:wasm-bindgen",
|
||||
"dep:js-sys",
|
||||
"dep:console_error_panic_hook",
|
||||
"dep:serde-wasm-bindgen",
|
||||
"dep:getrandom",
|
||||
"getrandom/js",
|
||||
"dep:bincode",
|
||||
"safe-deserialization",
|
||||
@@ -109,34 +133,47 @@ boolean-client-js-wasm-api = ["boolean", "__wasm_api"]
|
||||
shortint-client-js-wasm-api = ["shortint", "__wasm_api"]
|
||||
integer-client-js-wasm-api = ["integer", "__wasm_api"]
|
||||
high-level-client-js-wasm-api = ["boolean", "shortint", "integer", "__wasm_api"]
|
||||
parallel-wasm-api = ["wasm-bindgen-rayon"]
|
||||
parallel-wasm-api = ["dep:wasm-bindgen-rayon"]
|
||||
|
||||
nightly-avx512 = ["concrete-fft/nightly", "pulp/nightly"]
|
||||
nightly-avx512 = [
|
||||
"concrete-fft/nightly",
|
||||
"pulp/nightly",
|
||||
"next_tfhe?/nightly-avx512",
|
||||
]
|
||||
|
||||
# Enable the x86_64 specific accelerated implementation of the random generator for the default
|
||||
# backend
|
||||
generator_x86_64_aesni = ["concrete-csprng/generator_x86_64_aesni"]
|
||||
generator_x86_64_aesni = [
|
||||
"concrete-csprng/generator_x86_64_aesni",
|
||||
"next_tfhe?/generator_x86_64_aesni",
|
||||
]
|
||||
|
||||
# Enable the aarch64 specific accelerated implementation of the random generator for the default
|
||||
# backend
|
||||
generator_aarch64_aes = ["concrete-csprng/generator_aarch64_aes"]
|
||||
generator_aarch64_aes = [
|
||||
"concrete-csprng/generator_aarch64_aes",
|
||||
"next_tfhe?/generator_aarch64_aes",
|
||||
]
|
||||
|
||||
# Private features
|
||||
__profiling = []
|
||||
__coverage = []
|
||||
|
||||
seeder_unix = ["concrete-csprng/seeder_unix"]
|
||||
seeder_x86_64_rdseed = ["concrete-csprng/seeder_x86_64_rdseed"]
|
||||
seeder_unix = ["concrete-csprng/seeder_unix", "next_tfhe?/seeder_unix"]
|
||||
seeder_x86_64_rdseed = [
|
||||
"concrete-csprng/seeder_x86_64_rdseed",
|
||||
"next_tfhe?/seeder_x86_64_rdseed",
|
||||
]
|
||||
|
||||
# These target_arch features enable a set of public features for tfhe if users want a known
|
||||
# good/working configuration for tfhe.
|
||||
# For a target_arch that does not yet have such a feature, one can still enable features manually or
|
||||
# create a feature for said target_arch to make its use simpler.
|
||||
x86_64 = ["generator_x86_64_aesni", "seeder_x86_64_rdseed"]
|
||||
x86_64-unix = ["x86_64", "seeder_unix"]
|
||||
x86_64 = ["generator_x86_64_aesni", "seeder_x86_64_rdseed", "next_tfhe?/x86_64"]
|
||||
x86_64-unix = ["x86_64", "seeder_unix", "next_tfhe?/x86_64-unix"]
|
||||
|
||||
aarch64 = ["generator_aarch64_aes"]
|
||||
aarch64-unix = ["aarch64", "seeder_unix"]
|
||||
aarch64 = ["generator_aarch64_aes", "next_tfhe?/aarch64"]
|
||||
aarch64-unix = ["aarch64", "seeder_unix", "next_tfhe?/aarch64-unix"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
# TODO: manage builds for docs.rs based on their documentation https://docs.rs/about
|
||||
|
||||
@@ -393,7 +393,7 @@ fn _bench_wopbs_param_message_8_norm2_5(c: &mut Criterion) {
|
||||
let mut bench_group = c.benchmark_group("programmable_bootstrap");
|
||||
|
||||
let param = WOPBS_PARAM_MESSAGE_4_NORM2_6_KS_PBS;
|
||||
let param_set: ShortintParameterSet = param.try_into().unwrap();
|
||||
let param_set: ShortintParameterSet = param.into();
|
||||
let pbs_params = param_set.pbs_parameters().unwrap();
|
||||
|
||||
let keys = KEY_CACHE_WOPBS.get_from_param((pbs_params, param));
|
||||
|
||||
@@ -32,12 +32,9 @@ fn gen_c_api() {
|
||||
}
|
||||
|
||||
extern crate cbindgen;
|
||||
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let crate_dir: PathBuf = env::var("CARGO_MANIFEST_DIR").unwrap().into();
|
||||
let package_name = env::var("CARGO_PKG_NAME").unwrap();
|
||||
let output_file = target_dir()
|
||||
.join(format!("{package_name}.h"))
|
||||
.display()
|
||||
.to_string();
|
||||
let output_file = target_dir().join(format!("{package_name}.h"));
|
||||
|
||||
let parse_expand_features_vec = vec![
|
||||
#[cfg(feature = "__c_api")]
|
||||
@@ -54,6 +51,8 @@ fn gen_c_api() {
|
||||
"shortint",
|
||||
#[cfg(feature = "integer")]
|
||||
"integer",
|
||||
#[cfg(feature = "forward_compatibility")]
|
||||
"forward_compatibility",
|
||||
];
|
||||
|
||||
let parse_expand_vec = if parse_expand_features_vec.is_empty() {
|
||||
@@ -62,14 +61,16 @@ fn gen_c_api() {
|
||||
vec![package_name.as_str()]
|
||||
};
|
||||
|
||||
cbindgen::Builder::new()
|
||||
.with_crate(crate_dir.clone())
|
||||
.with_config(cbindgen::Config::from_root_or_default(crate_dir))
|
||||
let builder = cbindgen::Builder::new()
|
||||
.with_crate(crate_dir.as_path())
|
||||
.with_config(cbindgen::Config::from_file(crate_dir.join("cbindgen.toml")).unwrap())
|
||||
.with_parse_expand(&parse_expand_vec)
|
||||
.with_parse_expand_features(&parse_expand_features_vec)
|
||||
.generate()
|
||||
.unwrap()
|
||||
.write_to_file(output_file);
|
||||
.with_parse_expand_features(&parse_expand_features_vec);
|
||||
|
||||
#[cfg(feature = "forward_compatibility")]
|
||||
let builder = builder.with_include("tfhe-c-api-dynamic-buffer.h");
|
||||
|
||||
builder.generate().unwrap().write_to_file(output_file);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
@@ -8,8 +8,14 @@ endif()
|
||||
set(TFHE_C_API_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../target/${CARGO_PROFILE}")
|
||||
|
||||
include_directories(${TFHE_C_API_RELEASE})
|
||||
include_directories(${TFHE_C_API_RELEASE}/deps)
|
||||
add_library(Tfhe STATIC IMPORTED)
|
||||
set_target_properties(Tfhe PROPERTIES IMPORTED_LOCATION ${TFHE_C_API_RELEASE}/libtfhe.a)
|
||||
if("${WITH_FORWARD_COMPATIBILITY}" STREQUAL "ON")
|
||||
add_definitions(-DWITH_FORWARD_COMPATIBILITY)
|
||||
add_library(TfheDynamicBuffer STATIC IMPORTED)
|
||||
set_target_properties(TfheDynamicBuffer PROPERTIES IMPORTED_LOCATION ${TFHE_C_API_RELEASE}/deps/libtfhe_c_api_dynamic_buffer.a)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
find_library(SECURITY_FRAMEWORK Security)
|
||||
@@ -30,6 +36,9 @@ foreach (testsourcefile ${TEST_CASES})
|
||||
)
|
||||
target_include_directories(${testname} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(${testname} LINK_PUBLIC Tfhe m pthread dl)
|
||||
if("${WITH_FORWARD_COMPATIBILITY}" STREQUAL "ON")
|
||||
target_link_libraries(${testname} LINK_PUBLIC TfheDynamicBuffer)
|
||||
endif()
|
||||
if(APPLE)
|
||||
target_link_libraries(${testname} LINK_PUBLIC ${SECURITY_FRAMEWORK})
|
||||
endif()
|
||||
|
||||
68
tfhe/c_api_tests/test_c_doc.c
Normal file
68
tfhe/c_api_tests/test_c_doc.c
Normal file
@@ -0,0 +1,68 @@
|
||||
// If this test break the c_api doc needs to be updated
|
||||
|
||||
#include <tfhe.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ok = 0;
|
||||
// Prepare the config builder for the high level API and choose which types to enable
|
||||
ConfigBuilder *builder;
|
||||
Config *config;
|
||||
|
||||
// Put the builder in a default state without any types enabled
|
||||
config_builder_all_disabled(&builder);
|
||||
// Enable the uint128 type using the small LWE key for encryption
|
||||
config_builder_enable_default_integers_small(&builder);
|
||||
// Populate the config
|
||||
config_builder_build(builder, &config);
|
||||
|
||||
ClientKey *client_key = NULL;
|
||||
ServerKey *server_key = NULL;
|
||||
|
||||
// Generate the keys using the config
|
||||
generate_keys(config, &client_key, &server_key);
|
||||
// Set the server key for the current thread
|
||||
set_server_key(server_key);
|
||||
|
||||
FheUint128 *lhs = NULL;
|
||||
FheUint128 *rhs = NULL;
|
||||
FheUint128 *result = NULL;
|
||||
// A 128-bit unsigned integer containing value: 20 << 64 | 10
|
||||
U128 clear_lhs = { .w0 = 10, .w1 = 20 };
|
||||
// A 128-bit unsigned integer containing value: 2 << 64 | 1
|
||||
U128 clear_rhs = { .w0 = 1, .w1 = 2 };
|
||||
|
||||
ok = fhe_uint128_try_encrypt_with_client_key_u128(clear_lhs, client_key, &lhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_uint128_try_encrypt_with_client_key_u128(clear_rhs, client_key, &rhs);
|
||||
assert(ok == 0);
|
||||
|
||||
// Compute the subtraction
|
||||
ok = fhe_uint128_sub(lhs, rhs, &result);
|
||||
assert(ok == 0);
|
||||
|
||||
U128 clear_result;
|
||||
// Decrypt
|
||||
ok = fhe_uint128_decrypt(result, client_key, &clear_result);
|
||||
assert(ok == 0);
|
||||
|
||||
// Here the subtraction allows us to compare each word
|
||||
assert(clear_result.w0 == 9);
|
||||
assert(clear_result.w1 == 18);
|
||||
|
||||
// Destroy the ciphertexts
|
||||
fhe_uint128_destroy(lhs);
|
||||
fhe_uint128_destroy(rhs);
|
||||
fhe_uint128_destroy(result);
|
||||
|
||||
// Destroy the keys
|
||||
client_key_destroy(client_key);
|
||||
server_key_destroy(server_key);
|
||||
|
||||
printf("FHE computation successful!\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
120
tfhe/c_api_tests/test_forward_compatibility.c
Normal file
120
tfhe/c_api_tests/test_forward_compatibility.c
Normal file
@@ -0,0 +1,120 @@
|
||||
#include <tfhe.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef WITH_FORWARD_COMPATIBILITY
|
||||
int uint8_format_update(const ClientKey *client_key, const ServerKey *server_key) {
|
||||
int ok;
|
||||
FheUint8 *lhs = NULL;
|
||||
FheUint8 *deserialized_lhs = NULL;
|
||||
FheUint8 *result = NULL;
|
||||
Buffer value_buffer = {.pointer = NULL, .length = 0};
|
||||
Buffer conformant_value_buffer = {.pointer = NULL, .length = 0};
|
||||
Buffer cks_buffer = {.pointer = NULL, .length = 0};
|
||||
BufferView deser_view = {.pointer = NULL, .length = 0};
|
||||
ClientKey *deserialized_client_key = NULL;
|
||||
DynamicBuffer out_buffer = {.pointer = NULL, .length = 0};
|
||||
|
||||
const uint64_t max_serialization_size = UINT64_C(1) << UINT64_C(20);
|
||||
|
||||
uint8_t lhs_clear = 123;
|
||||
|
||||
ok = client_key_serialize(client_key, &cks_buffer);
|
||||
assert(ok == 0);
|
||||
|
||||
deser_view.pointer = cks_buffer.pointer;
|
||||
deser_view.length = cks_buffer.length;
|
||||
|
||||
ok = client_key_update_serialization_from_0_4_to_0_5(deser_view, &out_buffer);
|
||||
assert(ok == 0);
|
||||
|
||||
destroy_dynamic_buffer(&out_buffer);
|
||||
|
||||
deser_view.pointer = cks_buffer.pointer;
|
||||
deser_view.length = cks_buffer.length;
|
||||
ok = client_key_deserialize(deser_view, &deserialized_client_key);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_uint8_try_encrypt_with_client_key_u8(lhs_clear, deserialized_client_key, &lhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_uint8_serialize(lhs, &value_buffer);
|
||||
assert(ok == 0);
|
||||
|
||||
deser_view.pointer = value_buffer.pointer;
|
||||
deser_view.length = value_buffer.length;
|
||||
|
||||
ok = fhe_uint8_update_serialization_from_0_4_to_0_5(deser_view, &out_buffer);
|
||||
assert(ok == 0);
|
||||
|
||||
destroy_dynamic_buffer(&out_buffer);
|
||||
|
||||
ok = fhe_uint8_safe_serialize(lhs, &conformant_value_buffer, max_serialization_size);
|
||||
assert(ok == 0);
|
||||
|
||||
deser_view.pointer = conformant_value_buffer.pointer;
|
||||
deser_view.length = conformant_value_buffer.length;
|
||||
|
||||
ok = fhe_uint8_safe_update_serialization_conformant_from_0_4_to_0_5(
|
||||
deser_view, max_serialization_size, server_key, &out_buffer);
|
||||
assert(ok == 0);
|
||||
|
||||
destroy_dynamic_buffer(&out_buffer);
|
||||
|
||||
deser_view.pointer = value_buffer.pointer;
|
||||
deser_view.length = value_buffer.length;
|
||||
ok = fhe_uint8_deserialize(deser_view, &deserialized_lhs);
|
||||
assert(ok == 0);
|
||||
|
||||
uint8_t clear;
|
||||
ok = fhe_uint8_decrypt(deserialized_lhs, deserialized_client_key, &clear);
|
||||
assert(ok == 0);
|
||||
|
||||
assert(clear == lhs_clear);
|
||||
|
||||
if (value_buffer.pointer != NULL) {
|
||||
destroy_buffer(&value_buffer);
|
||||
}
|
||||
if (conformant_value_buffer.pointer != NULL) {
|
||||
destroy_buffer(&conformant_value_buffer);
|
||||
}
|
||||
fhe_uint8_destroy(lhs);
|
||||
fhe_uint8_destroy(deserialized_lhs);
|
||||
fhe_uint8_destroy(result);
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
int ok = 0;
|
||||
|
||||
#ifdef WITH_FORWARD_COMPATIBILITY
|
||||
{
|
||||
ConfigBuilder *builder;
|
||||
Config *config;
|
||||
|
||||
ok = config_builder_all_disabled(&builder);
|
||||
assert(ok == 0);
|
||||
ok = config_builder_enable_default_integers(&builder);
|
||||
assert(ok == 0);
|
||||
ok = config_builder_build(builder, &config);
|
||||
assert(ok == 0);
|
||||
|
||||
ClientKey *client_key = NULL;
|
||||
ServerKey *server_key = NULL;
|
||||
PublicKey *public_key = NULL;
|
||||
|
||||
ok = generate_keys(config, &client_key, &server_key);
|
||||
assert(ok == 0);
|
||||
ok = uint8_format_update(client_key, server_key);
|
||||
|
||||
client_key_destroy(client_key);
|
||||
public_key_destroy(public_key);
|
||||
server_key_destroy(server_key);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -46,6 +46,7 @@ usize_is_size_t = true
|
||||
[defines]
|
||||
# "target_os = freebsd" = "DEFINE_FREEBSD"
|
||||
# "feature = serde" = "DEFINE_SERDE"
|
||||
"feature = forward_compatibility" = "WITH_FORWARD_COMPATIBILITY"
|
||||
|
||||
|
||||
[export]
|
||||
@@ -114,8 +115,8 @@ bitflags = false
|
||||
############## Options for How Your Rust library Should Be Parsed ##############
|
||||
|
||||
[parse]
|
||||
parse_deps = true
|
||||
include = ["tfhe"]
|
||||
parse_deps = false
|
||||
include = []
|
||||
exclude = []
|
||||
clean = false
|
||||
extra_bindings = []
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
## How To
|
||||
* [Configure Rust](how_to/rust_configuration.md)
|
||||
* [Serialize/Deserialize](how_to/serialization.md)
|
||||
* [Migrate Data to Newer Versions of TFHE-rs](how_to/migrate_data.md)
|
||||
* [Compress Ciphertexts/Keys](how_to/compress.md)
|
||||
* [Use Public Key Encryption](how_to/public_key.md)
|
||||
* [Use Trivial Ciphertext](how_to/trivial_ciphertext.md)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Quick Start
|
||||
|
||||
The `core_crypto` module from `TFHE-rs` is dedicated to the implementation of the cryptographic tools related to TFHE. To construct an FHE application, the [shortint](../fine_grained_api/shortint/tutorial.md) and/or [Boolean](../fine_grained_api/Boolean/tutorial.md) modules (based on `core_crypto`) are recommended.
|
||||
The `core_crypto` module from `TFHE-rs` is dedicated to the implementation of the cryptographic tools related to TFHE. To construct an FHE application, the [shortint](../fine_grained_api/shortint/readme.md) and/or [Boolean](../fine_grained_api/Boolean/readme.md) modules (based on `core_crypto`) are recommended.
|
||||
|
||||
The `core_crypto` module offers an API to low-level cryptographic primitives and objects, like `lwe_encryption` or `rlwe_ciphertext`. The goal is to propose an easy-to-use API for cryptographers.
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ Welcome to this tutorial about `TFHE-rs` `core_crypto` module.
|
||||
To use `TFHE-rs`, it first has to be added as a dependency in the `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
tfhe = { version = "0.4.0", features = [ "x86_64-unix" ] }
|
||||
tfhe = { version = "0.4.4", features = [ "x86_64-unix" ] }
|
||||
```
|
||||
|
||||
This enables the `x86_64-unix` feature to have efficient implementations of various algorithms for `x86_64` CPUs on a Unix-like system. The 'unix' suffix indicates that the `UnixSeeder`, which uses `/dev/random` to generate random numbers, is activated as a fallback if no hardware number generator is available (like `rdseed` on `x86_64` or if the [`Randomization Services`](https://developer.apple.com/documentation/security/1399291-secrandomcopybytes?language=objc) on Apple platforms are not available). To avoid having the `UnixSeeder` as a potential fallback or to run on non-Unix systems (e.g., Windows), the `x86_64` feature is sufficient.
|
||||
@@ -19,19 +19,19 @@ For Apple Silicon, the `aarch64-unix` or `aarch64` feature should be enabled. `a
|
||||
In short: For `x86_64`-based machines running Unix-like OSes:
|
||||
|
||||
```toml
|
||||
tfhe = { version = "0.4.0", features = ["x86_64-unix"] }
|
||||
tfhe = { version = "0.4.4", features = ["x86_64-unix"] }
|
||||
```
|
||||
|
||||
For Apple Silicon or aarch64-based machines running Unix-like OSes:
|
||||
|
||||
```toml
|
||||
tfhe = { version = "0.4.0", features = ["aarch64-unix"] }
|
||||
tfhe = { version = "0.4.4", features = ["aarch64-unix"] }
|
||||
```
|
||||
|
||||
For `x86_64`-based machines with the [`rdseed instruction`](https://en.wikipedia.org/wiki/RDRAND) running Windows:
|
||||
|
||||
```toml
|
||||
tfhe = { version = "0.4.0", features = ["x86_64"] }
|
||||
tfhe = { version = "0.4.4", features = ["x86_64"] }
|
||||
```
|
||||
|
||||
### Commented code to double a 2-bit message in a leveled fashion and using a PBS with the `core_crypto` module.
|
||||
|
||||
@@ -8,12 +8,12 @@ To use `TFHE-rs` in your project, you first need to add it as a dependency in yo
|
||||
|
||||
If you are using an `x86` machine:
|
||||
```toml
|
||||
tfhe = { version = "0.4.0", features = [ "boolean", "shortint", "integer", "x86_64-unix" ] }
|
||||
tfhe = { version = "0.4.4", features = [ "boolean", "shortint", "integer", "x86_64-unix" ] }
|
||||
```
|
||||
|
||||
If you are using an `ARM` machine:
|
||||
```toml
|
||||
tfhe = { version = "0.4.0", features = [ "boolean", "shortint", "integer", "aarch64-unix" ] }
|
||||
tfhe = { version = "0.4.4", features = [ "boolean", "shortint", "integer", "aarch64-unix" ] }
|
||||
```
|
||||
|
||||
{% hint style="info" %}
|
||||
|
||||
@@ -46,7 +46,7 @@ fn main() {
|
||||
|
||||
The default configuration for x86 Unix machines:
|
||||
```toml
|
||||
tfhe = { version = "0.4.0", features = ["integer", "x86_64-unix"]}
|
||||
tfhe = { version = "0.4.4", features = ["integer", "x86_64-unix"]}
|
||||
```
|
||||
|
||||
Configuration options for different platforms can be found [here](../getting_started/installation.md). Other rust and homomorphic types features can be found [here](../how_to/rust_configuration.md).
|
||||
|
||||
@@ -68,7 +68,7 @@ $ cmake .. -DCMAKE_BUILD_TYPE=RELEASE
|
||||
$ make
|
||||
...
|
||||
$ ./my-executable
|
||||
Result: 2
|
||||
FHE computation successful!
|
||||
$
|
||||
```
|
||||
|
||||
@@ -76,7 +76,6 @@ $
|
||||
#include <tfhe.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
@@ -89,7 +88,7 @@ int main(void)
|
||||
// Put the builder in a default state without any types enabled
|
||||
config_builder_all_disabled(&builder);
|
||||
// Enable the uint128 type using the small LWE key for encryption
|
||||
config_builder_enable_default_uint128_small(&builder);
|
||||
config_builder_enable_default_integers_small(&builder);
|
||||
// Populate the config
|
||||
config_builder_build(builder, &config);
|
||||
|
||||
@@ -104,27 +103,29 @@ int main(void)
|
||||
FheUint128 *lhs = NULL;
|
||||
FheUint128 *rhs = NULL;
|
||||
FheUint128 *result = NULL;
|
||||
// A 128-bit unsigned integer containing value: 20 << 64 | 10
|
||||
U128 clear_lhs = { .w0 = 10, .w1 = 20 };
|
||||
// A 128-bit unsigned integer containing value: 2 << 64 | 1
|
||||
U128 clear_rhs = { .w0 = 1, .w1 = 2 };
|
||||
|
||||
// Encrypt a u128 using 64 bits words, we encrypt 20 << 64 | 10
|
||||
ok = fhe_uint128_try_encrypt_with_client_key_u128(10, 20, client_key, &lhs);
|
||||
ok = fhe_uint128_try_encrypt_with_client_key_u128(clear_lhs, client_key, &lhs);
|
||||
assert(ok == 0);
|
||||
|
||||
// Encrypt a u128 using words, we encrypt 2 << 64 | 1
|
||||
ok = fhe_uint128_try_encrypt_with_client_key_u128(1, 2, client_key, &rhs);
|
||||
ok = fhe_uint128_try_encrypt_with_client_key_u128(clear_rhs, client_key, &rhs);
|
||||
assert(ok == 0);
|
||||
|
||||
// Compute the subtraction
|
||||
ok = fhe_uint128_sub(lhs, rhs, &result);
|
||||
assert(ok == 0);
|
||||
|
||||
uint64_t w0, w1;
|
||||
U128 clear_result;
|
||||
// Decrypt
|
||||
ok = fhe_uint128_decrypt(result, client_key, &w0, &w1);
|
||||
ok = fhe_uint128_decrypt(result, client_key, &clear_result);
|
||||
assert(ok == 0);
|
||||
|
||||
// Here the subtraction allows us to compare each word
|
||||
assert(w0 == 9);
|
||||
assert(w1 == 18);
|
||||
assert(clear_result.w0 == 9);
|
||||
assert(clear_result.w1 == 18);
|
||||
|
||||
// Destroy the ciphertexts
|
||||
fhe_uint128_destroy(lhs);
|
||||
@@ -134,6 +135,8 @@ int main(void)
|
||||
// Destroy the keys
|
||||
client_key_destroy(client_key);
|
||||
server_key_destroy(server_key);
|
||||
|
||||
printf("FHE computation successful!\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
142
tfhe/docs/how_to/migrate_data.md
Normal file
142
tfhe/docs/how_to/migrate_data.md
Normal file
@@ -0,0 +1,142 @@
|
||||
# Managing Data Through Various TFHE-rs Versions
|
||||
|
||||
In what follows, the process to manage data when upgrading the TFHE-rs version (starting from the 0.4.4 release) is given. This page details the methods to make data, which have initially been generated with an older version of TFHE-rs, usable with a newer version.
|
||||
|
||||
## Forward Compatibility Strategy
|
||||
|
||||
The current strategy that has been adopted for TFHE-rs is the following:
|
||||
|
||||
- TFHE-rs has a global `SERIALIZATION_VERSION` constant;
|
||||
- When breaking serialization changes are introduced, this global version is bumped;
|
||||
- Safe serialization primitives check this constant upon deserialization, if the data is incompatible, these primitives return an error.
|
||||
|
||||
To be able to use older serialized data with newer versions, the following is done on new major TFHE-rs releases:
|
||||
|
||||
- A minor update is done to the previously released branch to add the new release as an optional dependency;
|
||||
- Conversion code is added to the previous branch to be able to load old data and convert it to the new data format.
|
||||
|
||||
In practice, if we take the 0.5 release as a concrete example, here is what will happen:
|
||||
|
||||
- 0.5.0 is released with breaking changes to the serialization;
|
||||
- 0.4.4 has tfhe@0.5.0 as optional dependency gated by the `forward_compatibility` feature;
|
||||
- Conversion code is added to 0.4.4, if possible without any user input, but some data migration will likely require some information to be provided by the developer writing the migration code;
|
||||
- 0.4.4 is released.
|
||||
|
||||
{% hint style="info" %}
|
||||
Note that if you do not need forward compatibility 0.4.4 will be equivalent to 0.4.1 from a usability perspective and you can safely update.
|
||||
Note also that the 0.5.0 has no knowledge of previous releases.
|
||||
{% endhint %}
|
||||
|
||||
## What it means from a developer perspective
|
||||
|
||||
A set of generic tooling is given to allow migrating data by using several workflows. The data migration is considered to be an application/protocol layer concern to avoid imposing design choices.
|
||||
|
||||
Examples to migrate data:
|
||||
|
||||
An `Application` uses TFHE-rs 0.4.1 and needs/wants to upgrade to 0.5.0 to benefit from various improvements.
|
||||
|
||||
Example timeline of the data migration or `Bulk Data Migration`:
|
||||
- A new transition version of the `Application` is compiled with the 0.4.4 release of TFHE-rs;
|
||||
- The transition version of the `Application` adds code to read previously stored data, convert it to the proper format for 0.5.0 and save it back to disk;
|
||||
- The service enters a maintenance period (if relevant);
|
||||
- Migration of data from 0.4.4 to 0.5.0 is done with the transition version of the `Application`, note that depending on the volume of data this transition can take a significant amount of time;
|
||||
- The updated version of the `Application` is compiled with the 0.5.0 release of TFHE-rs and put in production;
|
||||
- Service is resumed with the updated `Application` (if relevant).
|
||||
|
||||
The above case is describing a simple use case, where only a single version of data has to be managed. Moreover, the above strategy is not relevant in the case where the data is so large that migrating it in one go is not doable, or if the service cannot suffer any interruption.
|
||||
|
||||
In order to manage more complicated cases, another method called `Migrate On Read` can be used.
|
||||
|
||||
Here is an example timeline where data is migrated only as needed with the `Migrate On Read` approach:
|
||||
- A new version of the `Application` is compiled, it has tfhe@0.4.4 as dependency (the dependency will have to be renamed to avoid conflicts, a possible name is to use the major version like `tfhe_0_4`) and tfhe@0.5.0 which will not be renamed and can be accessed as `tfhe`
|
||||
- Code to manage reading the data is added to the `Application`:
|
||||
- The code determines whether the data was saved with the 0.4 `Application` or the 0.5 `Application`, if the data is already up to date with the 0.5 format it can be loaded right away, if it's in the 0.4 format the `Application` can check if an updated version of the data is already available in the 0.5 format and loads that if it's available, otherwise it converts the data to 0.5, saves the converted data to avoid having to convert it every time it is accessed and continue processing with the 0.5 data
|
||||
|
||||
The above is more complicated to manage as data will be present on disk with several versions, however it allows to run the service continuously or near-continuously once the new `Application` is deployed (it will require careful routing or error handling as nodes with outdated `Application` won't be able to process the 0.5 data).
|
||||
|
||||
Also, if required, several version of TFHE-rs can be "chained" to upgrade very old data to newer formats.
|
||||
The above pattern can be extended to have `tfhe_0_4` (tfhe@0.4.4 renamed), `tfhe_0_5` (tfhe@0.5.0 renamed) and `tfhe` being tfhe@0.6.0, this will require special handling from the developers so that their protocol can handle data from 0.4.4, 0.5.0 and 0.6.0 using all the conversion tooling from the relevant version.
|
||||
|
||||
E.g., if some computation requires data from version 0.4.4 a conversion function could be called `upgrade_data_from_0_4_to_0_6` and do:
|
||||
|
||||
- read data from 0.4.4
|
||||
- convert to 0.5.0 format using `tfhe_0_4`
|
||||
- convert to 0.6.0 format using `tfhe_0_5`
|
||||
- save to disk in 0.6.0 format
|
||||
- process 0.6.0 data with `tfhe` which is tfhe@0.6.0
|
||||
|
||||
## A concrete example for shortint
|
||||
|
||||
The following very small sample project shows how some data can be migrated in a project following the pattern explained above:
|
||||
|
||||
Cargo.toml:
|
||||
|
||||
```toml
|
||||
[package]
|
||||
name = "data_migration_tfhe"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# The project used tfhe 0.4.1, it now depends on the 0.4.4 with the forward compatibility code
|
||||
tfhe_0_4 = { package = "tfhe", version = "0.4.4", features = [
|
||||
"x86_64-unix",
|
||||
"boolean",
|
||||
"shortint",
|
||||
"integer",
|
||||
"forward_compatibility",
|
||||
] }
|
||||
# The project now uses tfhe 0.5.0 as it's "normal/default" tfhe version for all processing except
|
||||
# data upgrade, as only old versions will be retrofitted with code to migrate code to newer versions
|
||||
tfhe = { version = "0.5", features = [
|
||||
"x86_64-unix",
|
||||
"boolean",
|
||||
"shortint",
|
||||
"integer",
|
||||
] }
|
||||
```
|
||||
|
||||
src/main.rs:
|
||||
|
||||
```rust
|
||||
fn old_tfhe_data_generation() -> tfhe_0_4::shortint::Ciphertext {
|
||||
use tfhe_0_4::shortint::gen_keys;
|
||||
use tfhe_0_4::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
let (cks, sks) = gen_keys(PARAM_MESSAGE_2_CARRY_2_KS_PBS);
|
||||
let ct = cks.encrypt(2);
|
||||
|
||||
ct
|
||||
}
|
||||
|
||||
fn data_migration(old_ciphertext: tfhe_0_4::shortint::Ciphertext) {
|
||||
use tfhe::shortint::Ciphertext;
|
||||
use tfhe_0_4::forward_compatibility::ConvertInto;
|
||||
|
||||
// Here as tfhe_0_4 depends on tfhe 0.5.0 and tfhe 0.5.0 is a dependency of our project the
|
||||
// forward compatibility works out of the box using tfhe types and the tfhe_0_4 conversion code
|
||||
let new_ct: Ciphertext = old_ciphertext.convert_into();
|
||||
|
||||
println!("{:?}", new_ct.noise_level())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
data_migration(old_tfhe_data_generation())
|
||||
}
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
```console
|
||||
NoiseLevel(18446744073709551615)
|
||||
```
|
||||
|
||||
The noise level here is set at `usize::MAX` on a 64 bits system, it corresponds to the constant `NoiseLevel::UNKNOWN` from shortint, as the noise level was not a value that was directly tracked in TFHE-rs the noise level is set to this unknown constant when migrating the ciphertext. It is recommended to first apply a PBS to reset the noise level to a known nominal level as some algorithms will always clean ciphertexts which are not at the nominal noise level.
|
||||
|
||||
## Breaking changes and additional migration information
|
||||
|
||||
The main breaking change going from 0.4.4 to 0.5.0 with respect to data migration is that the High Level API dropped support for `shortint`. The `boolean` format has changed to use `integer`'s `BooleanBlock` under the hood.
|
||||
|
||||
This means that any data coming from the High Level API which previously used `boolean` or `shortint` is not supported for the data migration.
|
||||
@@ -11,7 +11,7 @@ To serialize our data, a [data format](https://serde.rs/#data-formats) should be
|
||||
|
||||
[dependencies]
|
||||
# ...
|
||||
tfhe = { version = "0.4.0", features = ["integer","x86_64-unix"]}
|
||||
tfhe = { version = "0.4.4", features = ["integer","x86_64-unix"]}
|
||||
bincode = "1.3.3"
|
||||
```
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ To use the `FheUint8` type, the `integer` feature must be activated:
|
||||
|
||||
[dependencies]
|
||||
# Default configuration for x86 Unix machines:
|
||||
tfhe = { version = "0.4.0", features = ["integer", "x86_64-unix"]}
|
||||
tfhe = { version = "0.4.4", features = ["integer", "x86_64-unix"]}
|
||||
```
|
||||
|
||||
Other configurations can be found [here](../getting_started/installation.md).
|
||||
|
||||
@@ -21,7 +21,7 @@ To use Booleans, the `booleans` feature in our Cargo.toml must be enabled:
|
||||
# Cargo.toml
|
||||
|
||||
# Default configuration for x86 Unix machines:
|
||||
tfhe = { version = "0.4.0", features = ["boolean", "x86_64-unix"]}
|
||||
tfhe = { version = "0.4.4", features = ["boolean", "x86_64-unix"]}
|
||||
```
|
||||
|
||||
Other configurations can be found [here](../getting_started/installation.md).
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn has_match(
|
||||
|
||||
let res = if branches.len() <= 1 {
|
||||
branches
|
||||
.get(0)
|
||||
.first()
|
||||
.map_or(exec.ct_false(), |branch| branch(&mut exec))
|
||||
.0
|
||||
} else {
|
||||
|
||||
43
tfhe/js_on_wasm_tests/test-hlapi-panic.js
Normal file
43
tfhe/js_on_wasm_tests/test-hlapi-panic.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert').strict;
|
||||
const {
|
||||
init_panic_hook,
|
||||
TfheClientKey,
|
||||
TfheConfigBuilder,
|
||||
FheUint8,
|
||||
} = require("../pkg/tfhe.js");
|
||||
|
||||
|
||||
const U256_MAX = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935");
|
||||
const U128_MAX = BigInt("340282366920938463463374607431768211455");
|
||||
const U32_MAX = 4294967295;
|
||||
|
||||
// This is useful to debug test
|
||||
//
|
||||
// Note that the test hlapi_panic
|
||||
// purposefully creates a panic, to some panic message
|
||||
// will be printed and tess will be ok
|
||||
init_panic_hook();
|
||||
|
||||
// Here integers are not enabled
|
||||
// but we try to use them, so an error should be returned
|
||||
// as the underlying panic should have been trapped
|
||||
|
||||
// Put in its own file as some async access is causing panics, to be investigated
|
||||
test('hlapi_panic', (t) => {
|
||||
let config = TfheConfigBuilder.all_disabled()
|
||||
.build();
|
||||
|
||||
let clientKey = TfheClientKey.generate(config);
|
||||
|
||||
let clear = 73;
|
||||
|
||||
console.log("\nThe following log is an expected error log:\n=======================\n")
|
||||
|
||||
try {
|
||||
let _ = FheUint8.encrypt_with_client_key(clear, clientKey);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(true);
|
||||
}
|
||||
});
|
||||
@@ -36,27 +36,6 @@ const U32_MAX = 4294967295;
|
||||
// will be printed and tess will be ok
|
||||
init_panic_hook();
|
||||
|
||||
// Here integers are not enabled
|
||||
// but we try to use them, so an error should be returned
|
||||
// as the underlying panic should have been trapped
|
||||
test('hlapi_panic', (t) => {
|
||||
let config = TfheConfigBuilder.all_disabled()
|
||||
.build();
|
||||
|
||||
let clientKey = TfheClientKey.generate(config);
|
||||
|
||||
let clear = 73;
|
||||
|
||||
console.log("\nThe following log is an expected error log:\n=======================\n")
|
||||
|
||||
try {
|
||||
let _ = FheUint8.encrypt_with_client_key(clear, clientKey);
|
||||
assert(false);
|
||||
} catch (e) {
|
||||
assert(true);
|
||||
}
|
||||
});
|
||||
|
||||
test('hlapi_key_gen_big', (t) => {
|
||||
let config = TfheConfigBuilder.all_disabled()
|
||||
.enable_default_integers()
|
||||
|
||||
@@ -134,4 +134,92 @@ impl ClientKey {
|
||||
pub fn new(parameter_set: &BooleanParameters) -> ClientKey {
|
||||
BooleanEngine::with_thread_local_mut(|engine| engine.create_client_key(*parameter_set))
|
||||
}
|
||||
|
||||
/// Deconstruct a [`ClientKey`] into its constituants.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() {
|
||||
/// use tfhe::boolean::client_key::ClientKey;
|
||||
/// use tfhe::boolean::parameters::PARAMETERS_ERROR_PROB_2_POW_MINUS_165;
|
||||
/// use tfhe::boolean::prelude::*;
|
||||
///
|
||||
/// // Generate the client key:
|
||||
/// let cks = ClientKey::new(&PARAMETERS_ERROR_PROB_2_POW_MINUS_165);
|
||||
/// let raw_parts = cks.into_raw_parts();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn into_raw_parts(
|
||||
self,
|
||||
) -> (
|
||||
LweSecretKeyOwned<u32>,
|
||||
GlweSecretKeyOwned<u32>,
|
||||
BooleanParameters,
|
||||
) {
|
||||
let Self {
|
||||
lwe_secret_key,
|
||||
glwe_secret_key,
|
||||
parameters,
|
||||
} = self;
|
||||
|
||||
(lwe_secret_key, glwe_secret_key, parameters)
|
||||
}
|
||||
|
||||
/// Construct a [`ClientKey`] from its constituants.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the provided raw parts are not compatible with the provided parameters.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # fn main() {
|
||||
/// use tfhe::boolean::client_key::ClientKey;
|
||||
/// use tfhe::boolean::parameters::PARAMETERS_ERROR_PROB_2_POW_MINUS_165;
|
||||
/// use tfhe::boolean::prelude::*;
|
||||
///
|
||||
/// // Generate the client key:
|
||||
/// let cks = ClientKey::new(&PARAMETERS_ERROR_PROB_2_POW_MINUS_165);
|
||||
/// let (lwe_secret_key, glwe_secret_key, parameters) = cks.into_raw_parts();
|
||||
/// let reconstructed_cks = ClientKey::new_from_raw_parts(lwe_secret_key, glwe_secret_key, parameters);
|
||||
/// # }
|
||||
pub fn new_from_raw_parts(
|
||||
lwe_secret_key: LweSecretKeyOwned<u32>,
|
||||
glwe_secret_key: GlweSecretKeyOwned<u32>,
|
||||
parameters: BooleanParameters,
|
||||
) -> Self {
|
||||
assert_eq!(
|
||||
lwe_secret_key.lwe_dimension(),
|
||||
parameters.lwe_dimension,
|
||||
"Mismatch between the LweSecretKey LweDimension ({:?}) \
|
||||
and the parameters LweDimension ({:?})",
|
||||
lwe_secret_key.lwe_dimension(),
|
||||
parameters.lwe_dimension
|
||||
);
|
||||
assert_eq!(
|
||||
glwe_secret_key.glwe_dimension(),
|
||||
parameters.glwe_dimension,
|
||||
"Mismatch between the GlweSecretKey GlweDimension ({:?}) \
|
||||
and the parameters GlweDimension ({:?})",
|
||||
glwe_secret_key.glwe_dimension(),
|
||||
parameters.glwe_dimension
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
glwe_secret_key.polynomial_size(),
|
||||
parameters.polynomial_size,
|
||||
"Mismatch between the GlweSecretKey PolynomialSize ({:?}) \
|
||||
and the parameters PolynomialSize ({:?})",
|
||||
glwe_secret_key.polynomial_size(),
|
||||
parameters.polynomial_size
|
||||
);
|
||||
|
||||
Self {
|
||||
lwe_secret_key,
|
||||
glwe_secret_key,
|
||||
parameters,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,6 @@ macro_rules! create_integer_wrapper_type {
|
||||
|
||||
impl_safe_deserialize_conformant_integer!($name, crate::high_level_api::safe_deserialize_conformant_integer);
|
||||
|
||||
|
||||
// The compressed version of the ciphertext type
|
||||
::paste::paste! {
|
||||
pub struct [<Compressed $name>]($crate::high_level_api::[<Compressed $name>]);
|
||||
@@ -357,6 +356,257 @@ create_integer_wrapper_type!(name: FheUint64, clear_scalar_type: u64);
|
||||
create_integer_wrapper_type!(name: FheUint128, clear_scalar_type: U128);
|
||||
create_integer_wrapper_type!(name: FheUint256, clear_scalar_type: U256);
|
||||
|
||||
#[cfg(feature = "forward_compatibility")]
|
||||
pub mod forward_compatibility {
|
||||
use super::*;
|
||||
|
||||
// FheInt don't have the 10, 12, 14 variants so we define the impl here
|
||||
impl_update_serialization_format_on_type!(FheUint8);
|
||||
impl_update_serialization_format_on_type!(FheUint10);
|
||||
impl_update_serialization_format_on_type!(FheUint12);
|
||||
impl_update_serialization_format_on_type!(FheUint14);
|
||||
impl_update_serialization_format_on_type!(FheUint16);
|
||||
impl_update_serialization_format_on_type!(FheUint32);
|
||||
impl_update_serialization_format_on_type!(FheUint64);
|
||||
impl_update_serialization_format_on_type!(FheUint128);
|
||||
impl_update_serialization_format_on_type!(FheUint256);
|
||||
impl_update_serialization_format_on_type!(CompressedFheUint8);
|
||||
impl_update_serialization_format_on_type!(CompressedFheUint10);
|
||||
impl_update_serialization_format_on_type!(CompressedFheUint12);
|
||||
impl_update_serialization_format_on_type!(CompressedFheUint14);
|
||||
impl_update_serialization_format_on_type!(CompressedFheUint16);
|
||||
impl_update_serialization_format_on_type!(CompressedFheUint32);
|
||||
impl_update_serialization_format_on_type!(CompressedFheUint64);
|
||||
impl_update_serialization_format_on_type!(CompressedFheUint128);
|
||||
impl_update_serialization_format_on_type!(CompressedFheUint256);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint8);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint10);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint12);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint14);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint16);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint32);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint64);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint128);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint256);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint8List);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint10List);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint12List);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint14List);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint16List);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint32List);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint64List);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint128List);
|
||||
impl_update_serialization_format_on_type!(CompactFheUint256List);
|
||||
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheUint8,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheUint10,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheUint12,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheUint14,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheUint16,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheUint32,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheUint64,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheUint128,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheUint256,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheUint8,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheUint10,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheUint12,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheUint14,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheUint16,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheUint32,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheUint64,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheUint128,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheUint256,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheUint8,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheUint10,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheUint12,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheUint14,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheUint16,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheUint32,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheUint64,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheUint128,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheUint256,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
|
||||
// FheInt don't have the 10, 12, 14 variants so we define the impl here
|
||||
impl_update_serialization_format_on_type!(FheInt8);
|
||||
impl_update_serialization_format_on_type!(FheInt16);
|
||||
impl_update_serialization_format_on_type!(FheInt32);
|
||||
impl_update_serialization_format_on_type!(FheInt64);
|
||||
impl_update_serialization_format_on_type!(FheInt128);
|
||||
impl_update_serialization_format_on_type!(FheInt256);
|
||||
impl_update_serialization_format_on_type!(CompressedFheInt8);
|
||||
impl_update_serialization_format_on_type!(CompressedFheInt16);
|
||||
impl_update_serialization_format_on_type!(CompressedFheInt32);
|
||||
impl_update_serialization_format_on_type!(CompressedFheInt64);
|
||||
impl_update_serialization_format_on_type!(CompressedFheInt128);
|
||||
impl_update_serialization_format_on_type!(CompressedFheInt256);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt8);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt16);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt32);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt64);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt128);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt256);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt8List);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt16List);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt32List);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt64List);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt128List);
|
||||
impl_update_serialization_format_on_type!(CompactFheInt256List);
|
||||
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheInt8,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheInt16,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheInt32,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheInt64,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheInt128,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
FheInt256,
|
||||
crate::high_level_api::safe_deserialize_conformant_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheInt8,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheInt16,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheInt32,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheInt64,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheInt128,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompressedFheInt256,
|
||||
crate::high_level_api::safe_deserialize_conformant_compressed_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheInt8,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheInt16,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheInt32,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheInt64,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheInt128,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
impl_safe_update_serialization_format_conformant_on_type!(
|
||||
CompactFheInt256,
|
||||
crate::high_level_api::safe_deserialize_conformant_compact_integer
|
||||
);
|
||||
}
|
||||
|
||||
impl_decrypt_on_type!(FheUint8, u8);
|
||||
impl_try_encrypt_trivial_on_type!(FheUint8{crate::high_level_api::FheUint8}, u8);
|
||||
impl_try_encrypt_with_client_key_on_type!(FheUint8{crate::high_level_api::FheUint8}, u8);
|
||||
|
||||
@@ -19,6 +19,17 @@ impl_serialize_deserialize_on_type!(CompactPublicKey);
|
||||
impl_serialize_deserialize_on_type!(CompressedCompactPublicKey);
|
||||
impl_serialize_deserialize_on_type!(ServerKey);
|
||||
|
||||
#[cfg(feature = "forward_compatibility")]
|
||||
mod forward_compatibility {
|
||||
use super::*;
|
||||
|
||||
impl_update_serialization_format_on_type!(ClientKey);
|
||||
impl_update_serialization_format_on_type!(PublicKey);
|
||||
impl_update_serialization_format_on_type!(CompactPublicKey);
|
||||
impl_update_serialization_format_on_type!(CompressedCompactPublicKey);
|
||||
impl_update_serialization_format_on_type!(ServerKey);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn generate_keys(
|
||||
config: *mut super::config::Config,
|
||||
|
||||
@@ -326,6 +326,69 @@ macro_rules! impl_safe_deserialize_conformant_integer {
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "forward_compatibility")]
|
||||
macro_rules! impl_update_serialization_format_on_type {
|
||||
($wrapper_type:ty) => {
|
||||
::paste::paste! {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn [<$wrapper_type:snake _update_serialization_from_0_4_to_0_5>](
|
||||
buffer_view: crate::c_api::buffer::BufferView,
|
||||
result: *mut tfhe_c_api_dynamic_buffer::DynamicBuffer,
|
||||
) -> ::std::os::raw::c_int {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
crate::c_api::utils::catch_panic(|| {
|
||||
let object: $wrapper_type = $wrapper_type(bincode::deserialize(buffer_view.into()).unwrap());
|
||||
|
||||
let next_object: next_tfhe::$wrapper_type = (object.0).convert_into();
|
||||
|
||||
let buffer = bincode::serialize(&next_object).unwrap();
|
||||
|
||||
*result = buffer.into();
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "forward_compatibility")]
|
||||
macro_rules! impl_safe_update_serialization_format_conformant_on_type {
|
||||
($wrapper_type:ty, $function_name:path) => {
|
||||
::paste::paste! {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn [<$wrapper_type:snake _safe_update_serialization_conformant_from_0_4_to_0_5>](
|
||||
buffer_view: crate::c_api::buffer::BufferView,
|
||||
serialized_size_limit: u64,
|
||||
server_key: *const crate::c_api::high_level_api::keys::ServerKey,
|
||||
result: *mut tfhe_c_api_dynamic_buffer::DynamicBuffer,
|
||||
) -> ::std::os::raw::c_int {
|
||||
crate::c_api::utils::catch_panic(|| {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
crate::c_api::utils::check_ptr_is_non_null_and_aligned(result).unwrap();
|
||||
|
||||
let sk = crate::c_api::utils::get_ref_checked(server_key).unwrap();
|
||||
|
||||
let buffer_view: &[u8] = buffer_view.into();
|
||||
|
||||
let object: $wrapper_type = $wrapper_type(
|
||||
$function_name(
|
||||
buffer_view,
|
||||
serialized_size_limit,
|
||||
&sk.0,
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let next_object: next_tfhe::$wrapper_type = (object.0).convert_into();
|
||||
|
||||
let buffer = bincode::serialize(&next_object).unwrap();
|
||||
|
||||
*result = buffer.into();
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! impl_binary_fn_on_type {
|
||||
// More general binary fn case,
|
||||
// where the type of the left-hand side can be different
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use dyn_stack::{GlobalPodBuffer, PodStack, ReborrowMut};
|
||||
|
||||
use super::super::super::{fft128, fft128_u128};
|
||||
#[allow(unused_imports)]
|
||||
use super::super::math::fft::{Fft128, Fft128View};
|
||||
use crate::core_crypto::prelude::*;
|
||||
use aligned_vec::CACHELINE_ALIGN;
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
use crate::core_crypto::commons::utils::izip;
|
||||
#[allow(unused_imports)]
|
||||
pub use crate::core_crypto::fft_impl::fft128::math::fft::{Fft128, Fft128View};
|
||||
use concrete_fft::fft128::f128;
|
||||
use dyn_stack::PodStack;
|
||||
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
use pulp::x86::{f64x4, u64x4, V3};
|
||||
use pulp::{f64x4, u64x4, x86::V3};
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
#[cfg(feature = "nightly-avx512")]
|
||||
use pulp::x86::{f64x8, u64x8, V4};
|
||||
use pulp::{f64x8, u64x8, x86::V4};
|
||||
|
||||
#[inline(always)]
|
||||
pub fn zeroing_shl(x: u64, shift: u64) -> u64 {
|
||||
|
||||
@@ -671,7 +671,7 @@ pub(crate) fn update_with_fmadd(
|
||||
let lhs = S::c64s_as_simd(ggsw_poly).0;
|
||||
|
||||
for (out, &lhs, &rhs) in izip!(out, lhs, rhs) {
|
||||
*out = simd.c64s_mul_adde(lhs, rhs, *out);
|
||||
*out = simd.c64s_mul_add_e(lhs, rhs, *out);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -737,7 +737,7 @@ pub(crate) fn update_with_fmadd_factor(
|
||||
} else {
|
||||
for (out, &lhs, &rhs) in izip!(out, lhs, rhs) {
|
||||
// NOTE: see above
|
||||
*out = simd.c64s_mul_adde(factor, simd.c64s_mul(lhs, rhs), *out);
|
||||
*out = simd.c64s_mul_add_e(factor, simd.c64s_mul(lhs, rhs), *out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
64
tfhe/src/forward_compatibility/boolean/ciphertext/mod.rs
Normal file
64
tfhe/src/forward_compatibility/boolean/ciphertext/mod.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::boolean::ciphertext::CompressedCiphertext;
|
||||
use next_tfhe::boolean::ciphertext::CompressedCiphertext as NextCompressedCiphertext;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CompressedCiphertext> for NextCompressedCiphertext {
|
||||
#[inline]
|
||||
fn convert_from(value: CompressedCiphertext) -> Self {
|
||||
let CompressedCiphertext { ciphertext } = value;
|
||||
|
||||
Self::from_raw_parts(ciphertext.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
use crate::boolean::ciphertext::Ciphertext;
|
||||
use next_tfhe::boolean::ciphertext::Ciphertext as NextCiphertext;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<Ciphertext> for NextCiphertext {
|
||||
#[inline]
|
||||
fn convert_from(value: Ciphertext) -> Self {
|
||||
match value {
|
||||
Ciphertext::Encrypted(encrypted) => NextCiphertext::Encrypted(encrypted.convert_into()),
|
||||
Ciphertext::Trivial(trivial) => NextCiphertext::Trivial(trivial),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_ciphertext() {
|
||||
use next_tfhe::boolean::ciphertext::Ciphertext as NextCiphertext;
|
||||
|
||||
use crate::boolean::gen_keys;
|
||||
|
||||
let (cks, sks) = gen_keys();
|
||||
|
||||
{
|
||||
let tfhe_struct = cks.encrypt(true);
|
||||
let _next_tfhe_struct: NextCiphertext = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
{
|
||||
let tfhe_struct = sks.trivial_encrypt(true);
|
||||
let _next_tfhe_struct: NextCiphertext = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_compressed_ciphertext() {
|
||||
use next_tfhe::boolean::ciphertext::CompressedCiphertext as NextCompressedCiphertext;
|
||||
|
||||
use crate::boolean::gen_keys;
|
||||
|
||||
let (cks, _sks) = gen_keys();
|
||||
|
||||
{
|
||||
let tfhe_struct = cks.encrypt_compressed(true);
|
||||
let _next_tfhe_struct: NextCompressedCiphertext = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
}
|
||||
33
tfhe/src/forward_compatibility/boolean/client_key/mod.rs
Normal file
33
tfhe/src/forward_compatibility/boolean/client_key/mod.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::boolean::client_key::ClientKey;
|
||||
use next_tfhe::boolean::client_key::ClientKey as NextClientKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<ClientKey> for NextClientKey {
|
||||
#[inline]
|
||||
fn convert_from(value: ClientKey) -> Self {
|
||||
let (lwe_secret_key, glwe_secret_key, parameters) = value.into_raw_parts();
|
||||
|
||||
Self::new_from_raw_parts(
|
||||
lwe_secret_key.convert_into(),
|
||||
glwe_secret_key.convert_into(),
|
||||
parameters.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_client_key() {
|
||||
use crate::boolean::client_key::ClientKey;
|
||||
use next_tfhe::boolean::client_key::ClientKey as NextClientKey;
|
||||
|
||||
use crate::boolean::parameters::DEFAULT_PARAMETERS_KS_PBS;
|
||||
|
||||
let tfhe_struct = ClientKey::new(&DEFAULT_PARAMETERS_KS_PBS);
|
||||
let _next_tfhe_struct: NextClientKey = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::boolean::engine::bootstrapping::ServerKey;
|
||||
use next_tfhe::boolean::engine::bootstrapping::ServerKey as NextServerKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<ServerKey> for NextServerKey {
|
||||
#[inline]
|
||||
fn convert_from(value: ServerKey) -> Self {
|
||||
let ServerKey {
|
||||
bootstrapping_key,
|
||||
key_switching_key,
|
||||
pbs_order,
|
||||
} = value;
|
||||
|
||||
Self::from_raw_parts(
|
||||
bootstrapping_key.convert_into(),
|
||||
key_switching_key.convert_into(),
|
||||
pbs_order.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::boolean::engine::bootstrapping::CompressedServerKey;
|
||||
use next_tfhe::boolean::engine::bootstrapping::CompressedServerKey as NextCompressedServerKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CompressedServerKey> for NextCompressedServerKey {
|
||||
#[inline]
|
||||
fn convert_from(value: CompressedServerKey) -> Self {
|
||||
let CompressedServerKey {
|
||||
bootstrapping_key,
|
||||
key_switching_key,
|
||||
pbs_order,
|
||||
} = value;
|
||||
|
||||
Self::from_raw_parts(
|
||||
bootstrapping_key.convert_into(),
|
||||
key_switching_key.convert_into(),
|
||||
pbs_order.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_server_key() {
|
||||
use next_tfhe::boolean::engine::bootstrapping::ServerKey as NextServerKey;
|
||||
|
||||
use crate::boolean::gen_keys;
|
||||
|
||||
let (_cks, tfhe_struct) = gen_keys();
|
||||
let _next_tfhe_struct: NextServerKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_compressed_server_key() {
|
||||
use crate::boolean::engine::bootstrapping::CompressedServerKey;
|
||||
use next_tfhe::boolean::engine::bootstrapping::CompressedServerKey as NextCompressedServerKey;
|
||||
|
||||
use crate::boolean::client_key::ClientKey;
|
||||
use crate::boolean::parameters::DEFAULT_PARAMETERS_KS_PBS;
|
||||
|
||||
let cks = ClientKey::new(&DEFAULT_PARAMETERS_KS_PBS);
|
||||
let tfhe_struct = CompressedServerKey::new(&cks);
|
||||
let _next_tfhe_struct: NextCompressedServerKey = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
1
tfhe/src/forward_compatibility/boolean/engine/mod.rs
Normal file
1
tfhe/src/forward_compatibility/boolean/engine/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod bootstrapping;
|
||||
@@ -0,0 +1,38 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::boolean::key_switching_key::KeySwitchingKey;
|
||||
use next_tfhe::boolean::key_switching_key::KeySwitchingKey as NextKeySwitchingKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<KeySwitchingKey> for NextKeySwitchingKey {
|
||||
#[inline]
|
||||
fn convert_from(value: KeySwitchingKey) -> Self {
|
||||
let KeySwitchingKey { key_switching_key } = value;
|
||||
|
||||
Self::from_raw_parts(key_switching_key.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_key_switching_key() {
|
||||
use crate::boolean::key_switching_key::KeySwitchingKey;
|
||||
use next_tfhe::boolean::key_switching_key::KeySwitchingKey as NextKeySwitchingKey;
|
||||
|
||||
use crate::boolean::gen_keys;
|
||||
use crate::boolean::parameters::BooleanKeySwitchingParameters;
|
||||
|
||||
let (cks1, _sks1) = gen_keys();
|
||||
let (cks2, _sks2) = gen_keys();
|
||||
|
||||
let ksk_params = BooleanKeySwitchingParameters::new(
|
||||
cks2.parameters.ks_base_log,
|
||||
cks2.parameters.ks_level,
|
||||
);
|
||||
|
||||
let tfhe_struct = KeySwitchingKey::new(&cks1, &cks2, ksk_params);
|
||||
let _next_tfhe_struct: NextKeySwitchingKey = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
6
tfhe/src/forward_compatibility/boolean/mod.rs
Normal file
6
tfhe/src/forward_compatibility/boolean/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
pub mod ciphertext;
|
||||
pub mod client_key;
|
||||
pub mod engine;
|
||||
pub mod key_switching_key;
|
||||
pub mod parameters;
|
||||
pub mod public_key;
|
||||
104
tfhe/src/forward_compatibility/boolean/parameters/mod.rs
Normal file
104
tfhe/src/forward_compatibility/boolean/parameters/mod.rs
Normal file
@@ -0,0 +1,104 @@
|
||||
use crate::boolean::parameters::BooleanParameters;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::boolean::parameters::BooleanParameters as NextBooleanParameters;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<BooleanParameters> for NextBooleanParameters {
|
||||
#[inline]
|
||||
fn convert_from(value: BooleanParameters) -> Self {
|
||||
let BooleanParameters {
|
||||
lwe_dimension,
|
||||
glwe_dimension,
|
||||
polynomial_size,
|
||||
lwe_modular_std_dev,
|
||||
glwe_modular_std_dev,
|
||||
pbs_base_log,
|
||||
pbs_level,
|
||||
ks_base_log,
|
||||
ks_level,
|
||||
encryption_key_choice,
|
||||
} = value;
|
||||
NextBooleanParameters {
|
||||
lwe_dimension: lwe_dimension.convert_into(),
|
||||
glwe_dimension: glwe_dimension.convert_into(),
|
||||
polynomial_size: polynomial_size.convert_into(),
|
||||
lwe_modular_std_dev: lwe_modular_std_dev.convert_into(),
|
||||
glwe_modular_std_dev: glwe_modular_std_dev.convert_into(),
|
||||
pbs_base_log: pbs_base_log.convert_into(),
|
||||
pbs_level: pbs_level.convert_into(),
|
||||
ks_base_log: ks_base_log.convert_into(),
|
||||
ks_level: ks_level.convert_into(),
|
||||
encryption_key_choice: encryption_key_choice.convert_into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use crate::boolean::parameters::BooleanKeySwitchingParameters;
|
||||
use next_tfhe::boolean::parameters::BooleanKeySwitchingParameters as NextBooleanKeySwitchingParameters;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<BooleanKeySwitchingParameters>
|
||||
for NextBooleanKeySwitchingParameters
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: BooleanKeySwitchingParameters) -> Self {
|
||||
let BooleanKeySwitchingParameters {
|
||||
ks_base_log,
|
||||
ks_level,
|
||||
} = value;
|
||||
NextBooleanKeySwitchingParameters {
|
||||
ks_base_log: ks_base_log.convert_into(),
|
||||
ks_level: ks_level.convert_into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_boolean_parameters() {
|
||||
use crate::boolean::parameters::BooleanParameters;
|
||||
use crate::core_crypto::commons::dispersion::StandardDev;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
use next_tfhe::boolean::parameters::BooleanParameters as NextBooleanParameters;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
for encryption_key_choice in [EncryptionKeyChoice::Big, EncryptionKeyChoice::Small] {
|
||||
let tfhe_struct = BooleanParameters {
|
||||
lwe_dimension: LweDimension(rng.gen()),
|
||||
glwe_dimension: GlweDimension(rng.gen()),
|
||||
polynomial_size: PolynomialSize(rng.gen()),
|
||||
lwe_modular_std_dev: StandardDev(rng.gen()),
|
||||
glwe_modular_std_dev: StandardDev(rng.gen()),
|
||||
pbs_base_log: DecompositionBaseLog(rng.gen()),
|
||||
pbs_level: DecompositionLevelCount(rng.gen()),
|
||||
ks_base_log: DecompositionBaseLog(rng.gen()),
|
||||
ks_level: DecompositionLevelCount(rng.gen()),
|
||||
encryption_key_choice,
|
||||
};
|
||||
|
||||
let _next_tfhe_struct: NextBooleanParameters = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_boolean_key_switching_parameters() {
|
||||
use crate::boolean::parameters::BooleanKeySwitchingParameters;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
use next_tfhe::boolean::parameters::BooleanKeySwitchingParameters as NextBooleanKeySwitchingParameters;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = BooleanKeySwitchingParameters {
|
||||
ks_base_log: DecompositionBaseLog(rng.gen()),
|
||||
ks_level: DecompositionLevelCount(rng.gen()),
|
||||
};
|
||||
|
||||
let _next_tfhe_struct: NextBooleanKeySwitchingParameters = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
65
tfhe/src/forward_compatibility/boolean/public_key/mod.rs
Normal file
65
tfhe/src/forward_compatibility/boolean/public_key/mod.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::boolean::public_key::CompressedPublicKey;
|
||||
use next_tfhe::boolean::public_key::CompressedPublicKey as NextCompressedPublicKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CompressedPublicKey> for NextCompressedPublicKey {
|
||||
#[inline]
|
||||
fn convert_from(value: CompressedPublicKey) -> Self {
|
||||
let CompressedPublicKey {
|
||||
compressed_lwe_public_key,
|
||||
parameters,
|
||||
} = value;
|
||||
|
||||
Self::from_raw_parts(
|
||||
compressed_lwe_public_key.convert_into(),
|
||||
parameters.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::boolean::public_key::PublicKey;
|
||||
use next_tfhe::boolean::public_key::PublicKey as NextPublicKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<PublicKey> for NextPublicKey {
|
||||
#[inline]
|
||||
fn convert_from(value: PublicKey) -> Self {
|
||||
let PublicKey {
|
||||
lwe_public_key,
|
||||
parameters,
|
||||
} = value;
|
||||
|
||||
Self::from_raw_parts(lwe_public_key.convert_into(), parameters.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_compressed_public_key() {
|
||||
use crate::boolean::public_key::CompressedPublicKey;
|
||||
use next_tfhe::boolean::public_key::CompressedPublicKey as NextCompressedPublicKey;
|
||||
|
||||
use crate::boolean::client_key::ClientKey;
|
||||
use crate::boolean::parameters::DEFAULT_PARAMETERS_KS_PBS;
|
||||
|
||||
let cks = ClientKey::new(&DEFAULT_PARAMETERS_KS_PBS);
|
||||
let tfhe_struct = CompressedPublicKey::new(&cks);
|
||||
let _next_tfhe_struct: NextCompressedPublicKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_public_key() {
|
||||
use crate::boolean::public_key::PublicKey;
|
||||
use next_tfhe::boolean::public_key::PublicKey as NextPublicKey;
|
||||
|
||||
use crate::boolean::client_key::ClientKey;
|
||||
use crate::boolean::parameters::DEFAULT_PARAMETERS_KS_PBS;
|
||||
|
||||
let cks = ClientKey::new(&DEFAULT_PARAMETERS_KS_PBS);
|
||||
let tfhe_struct = PublicKey::new(&cks);
|
||||
let _next_tfhe_struct: NextPublicKey = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
use crate::core_crypto::commons::ciphertext_modulus::CiphertextModulus;
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
|
||||
use next_tfhe::core_crypto::commons::ciphertext_modulus::CiphertextModulus as NextCiphertextModulus;
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
|
||||
impl<Scalar> crate::forward_compatibility::ConvertFrom<CiphertextModulus<Scalar>>
|
||||
for NextCiphertextModulus<Scalar>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: CiphertextModulus<Scalar>) -> Self {
|
||||
if value.is_native_modulus() {
|
||||
Self::new_native()
|
||||
} else {
|
||||
Self::new(value.get_custom_modulus())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_ciphertext_modulus() {
|
||||
use crate::core_crypto::commons::ciphertext_modulus::CiphertextModulus;
|
||||
use next_tfhe::core_crypto::commons::ciphertext_modulus::CiphertextModulus as NextCiphertextModulus;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = CiphertextModulus::new(0);
|
||||
let _next_tfhe_struct: NextCiphertextModulus<u64> = tfhe_struct.convert_into();
|
||||
|
||||
let tfhe_struct = CiphertextModulus::new(rng.gen_range(0..=(1 << 64)));
|
||||
let _next_tfhe_struct: NextCiphertextModulus<u64> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
use crate::core_crypto::commons::dispersion::StandardDev;
|
||||
use next_tfhe::core_crypto::commons::dispersion::StandardDev as NextStandardDev;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<StandardDev> for NextStandardDev {
|
||||
#[inline]
|
||||
fn convert_from(value: StandardDev) -> Self {
|
||||
let StandardDev(field_0) = value;
|
||||
NextStandardDev(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
#[test]
|
||||
fn test_conversion_standard_dev() {
|
||||
use crate::core_crypto::commons::dispersion::StandardDev;
|
||||
use next_tfhe::core_crypto::commons::dispersion::StandardDev as NextStandardDev;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = StandardDev(rng.gen());
|
||||
let _next_tfhe_struct: NextStandardDev = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod random;
|
||||
@@ -0,0 +1,45 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use next_tfhe::core_crypto::commons::math::random::Seed as NextSeed;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<Seed> for NextSeed {
|
||||
#[inline]
|
||||
fn convert_from(value: Seed) -> Self {
|
||||
let Seed(seed) = value;
|
||||
Self(seed)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::math::random::CompressionSeed;
|
||||
use next_tfhe::core_crypto::commons::math::random::CompressionSeed as NextCompressionSeed;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CompressionSeed> for NextCompressionSeed {
|
||||
#[inline]
|
||||
fn convert_from(value: CompressionSeed) -> Self {
|
||||
let CompressionSeed { seed } = value;
|
||||
NextCompressionSeed {
|
||||
seed: seed.convert_into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_compression_seed() {
|
||||
use crate::core_crypto::commons::math::random::{CompressionSeed, Seed};
|
||||
use next_tfhe::core_crypto::commons::math::random::CompressionSeed as NextCompressionSeed;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = CompressionSeed {
|
||||
seed: Seed(rng.gen()),
|
||||
};
|
||||
let _next_tfhe_struct: NextCompressionSeed = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
pub mod ciphertext_modulus;
|
||||
pub mod dispersion;
|
||||
pub mod math;
|
||||
pub mod parameters;
|
||||
@@ -0,0 +1,790 @@
|
||||
use crate::core_crypto::commons::parameters::PlaintextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::PlaintextCount as NextPlaintextCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<PlaintextCount> for NextPlaintextCount {
|
||||
#[inline]
|
||||
fn convert_from(value: PlaintextCount) -> Self {
|
||||
let PlaintextCount(field_0) = value;
|
||||
NextPlaintextCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::CleartextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::CleartextCount as NextCleartextCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CleartextCount> for NextCleartextCount {
|
||||
#[inline]
|
||||
fn convert_from(value: CleartextCount) -> Self {
|
||||
let CleartextCount(field_0) = value;
|
||||
NextCleartextCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::CiphertextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::CiphertextCount as NextCiphertextCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CiphertextCount> for NextCiphertextCount {
|
||||
#[inline]
|
||||
fn convert_from(value: CiphertextCount) -> Self {
|
||||
let CiphertextCount(field_0) = value;
|
||||
NextCiphertextCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::LweCiphertextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweCiphertextCount as NextLweCiphertextCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<LweCiphertextCount> for NextLweCiphertextCount {
|
||||
#[inline]
|
||||
fn convert_from(value: LweCiphertextCount) -> Self {
|
||||
let LweCiphertextCount(field_0) = value;
|
||||
NextLweCiphertextCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::GlweCiphertextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::GlweCiphertextCount as NextGlweCiphertextCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<GlweCiphertextCount> for NextGlweCiphertextCount {
|
||||
#[inline]
|
||||
fn convert_from(value: GlweCiphertextCount) -> Self {
|
||||
let GlweCiphertextCount(field_0) = value;
|
||||
NextGlweCiphertextCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::GswCiphertextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::GswCiphertextCount as NextGswCiphertextCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<GswCiphertextCount> for NextGswCiphertextCount {
|
||||
#[inline]
|
||||
fn convert_from(value: GswCiphertextCount) -> Self {
|
||||
let GswCiphertextCount(field_0) = value;
|
||||
NextGswCiphertextCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::GgswCiphertextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::GgswCiphertextCount as NextGgswCiphertextCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<GgswCiphertextCount> for NextGgswCiphertextCount {
|
||||
#[inline]
|
||||
fn convert_from(value: GgswCiphertextCount) -> Self {
|
||||
let GgswCiphertextCount(field_0) = value;
|
||||
NextGgswCiphertextCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::LweSize;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweSize as NextLweSize;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<LweSize> for NextLweSize {
|
||||
#[inline]
|
||||
fn convert_from(value: LweSize) -> Self {
|
||||
let LweSize(field_0) = value;
|
||||
NextLweSize(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::LweDimension;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweDimension as NextLweDimension;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<LweDimension> for NextLweDimension {
|
||||
#[inline]
|
||||
fn convert_from(value: LweDimension) -> Self {
|
||||
let LweDimension(field_0) = value;
|
||||
NextLweDimension(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::LwePublicKeyZeroEncryptionCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::LwePublicKeyZeroEncryptionCount as NextLwePublicKeyZeroEncryptionCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<LwePublicKeyZeroEncryptionCount>
|
||||
for NextLwePublicKeyZeroEncryptionCount
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LwePublicKeyZeroEncryptionCount) -> Self {
|
||||
let LwePublicKeyZeroEncryptionCount(field_0) = value;
|
||||
NextLwePublicKeyZeroEncryptionCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::LweMaskCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweMaskCount as NextLweMaskCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<LweMaskCount> for NextLweMaskCount {
|
||||
#[inline]
|
||||
fn convert_from(value: LweMaskCount) -> Self {
|
||||
let LweMaskCount(field_0) = value;
|
||||
NextLweMaskCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::LweBodyCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweBodyCount as NextLweBodyCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<LweBodyCount> for NextLweBodyCount {
|
||||
#[inline]
|
||||
fn convert_from(value: LweBodyCount) -> Self {
|
||||
let LweBodyCount(field_0) = value;
|
||||
NextLweBodyCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::GlweSize;
|
||||
use next_tfhe::core_crypto::commons::parameters::GlweSize as NextGlweSize;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<GlweSize> for NextGlweSize {
|
||||
#[inline]
|
||||
fn convert_from(value: GlweSize) -> Self {
|
||||
let GlweSize(field_0) = value;
|
||||
NextGlweSize(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::GlweDimension;
|
||||
use next_tfhe::core_crypto::commons::parameters::GlweDimension as NextGlweDimension;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<GlweDimension> for NextGlweDimension {
|
||||
#[inline]
|
||||
fn convert_from(value: GlweDimension) -> Self {
|
||||
let GlweDimension(field_0) = value;
|
||||
NextGlweDimension(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::PolynomialSize;
|
||||
use next_tfhe::core_crypto::commons::parameters::PolynomialSize as NextPolynomialSize;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<PolynomialSize> for NextPolynomialSize {
|
||||
#[inline]
|
||||
fn convert_from(value: PolynomialSize) -> Self {
|
||||
let PolynomialSize(field_0) = value;
|
||||
NextPolynomialSize(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::FourierPolynomialSize;
|
||||
use next_tfhe::core_crypto::commons::parameters::FourierPolynomialSize as NextFourierPolynomialSize;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<FourierPolynomialSize>
|
||||
for NextFourierPolynomialSize
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: FourierPolynomialSize) -> Self {
|
||||
let FourierPolynomialSize(field_0) = value;
|
||||
NextFourierPolynomialSize(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::PolynomialSizeLog;
|
||||
use next_tfhe::core_crypto::commons::parameters::PolynomialSizeLog as NextPolynomialSizeLog;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<PolynomialSizeLog> for NextPolynomialSizeLog {
|
||||
#[inline]
|
||||
fn convert_from(value: PolynomialSizeLog) -> Self {
|
||||
let PolynomialSizeLog(field_0) = value;
|
||||
NextPolynomialSizeLog(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::PolynomialCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::PolynomialCount as NextPolynomialCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<PolynomialCount> for NextPolynomialCount {
|
||||
#[inline]
|
||||
fn convert_from(value: PolynomialCount) -> Self {
|
||||
let PolynomialCount(field_0) = value;
|
||||
NextPolynomialCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::MonomialDegree;
|
||||
use next_tfhe::core_crypto::commons::parameters::MonomialDegree as NextMonomialDegree;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<MonomialDegree> for NextMonomialDegree {
|
||||
#[inline]
|
||||
fn convert_from(value: MonomialDegree) -> Self {
|
||||
let MonomialDegree(field_0) = value;
|
||||
NextMonomialDegree(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::DecompositionBaseLog;
|
||||
use next_tfhe::core_crypto::commons::parameters::DecompositionBaseLog as NextDecompositionBaseLog;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<DecompositionBaseLog> for NextDecompositionBaseLog {
|
||||
#[inline]
|
||||
fn convert_from(value: DecompositionBaseLog) -> Self {
|
||||
let DecompositionBaseLog(field_0) = value;
|
||||
NextDecompositionBaseLog(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::DecompositionLevelCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::DecompositionLevelCount as NextDecompositionLevelCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<DecompositionLevelCount>
|
||||
for NextDecompositionLevelCount
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: DecompositionLevelCount) -> Self {
|
||||
let DecompositionLevelCount(field_0) = value;
|
||||
NextDecompositionLevelCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::LutCountLog;
|
||||
use next_tfhe::core_crypto::commons::parameters::LutCountLog as NextLutCountLog;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<LutCountLog> for NextLutCountLog {
|
||||
#[inline]
|
||||
fn convert_from(value: LutCountLog) -> Self {
|
||||
let LutCountLog(field_0) = value;
|
||||
NextLutCountLog(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::ModulusSwitchOffset;
|
||||
use next_tfhe::core_crypto::commons::parameters::ModulusSwitchOffset as NextModulusSwitchOffset;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<ModulusSwitchOffset> for NextModulusSwitchOffset {
|
||||
#[inline]
|
||||
fn convert_from(value: ModulusSwitchOffset) -> Self {
|
||||
let ModulusSwitchOffset(field_0) = value;
|
||||
NextModulusSwitchOffset(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::DeltaLog;
|
||||
use next_tfhe::core_crypto::commons::parameters::DeltaLog as NextDeltaLog;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<DeltaLog> for NextDeltaLog {
|
||||
#[inline]
|
||||
fn convert_from(value: DeltaLog) -> Self {
|
||||
let DeltaLog(field_0) = value;
|
||||
NextDeltaLog(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::ExtractedBitsCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::ExtractedBitsCount as NextExtractedBitsCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<ExtractedBitsCount> for NextExtractedBitsCount {
|
||||
#[inline]
|
||||
fn convert_from(value: ExtractedBitsCount) -> Self {
|
||||
let ExtractedBitsCount(field_0) = value;
|
||||
NextExtractedBitsCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::FunctionalPackingKeyswitchKeyCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::FunctionalPackingKeyswitchKeyCount as NextFunctionalPackingKeyswitchKeyCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<FunctionalPackingKeyswitchKeyCount>
|
||||
for NextFunctionalPackingKeyswitchKeyCount
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: FunctionalPackingKeyswitchKeyCount) -> Self {
|
||||
let FunctionalPackingKeyswitchKeyCount(field_0) = value;
|
||||
NextFunctionalPackingKeyswitchKeyCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::CiphertextModulusLog;
|
||||
use next_tfhe::core_crypto::commons::parameters::CiphertextModulusLog as NextCiphertextModulusLog;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CiphertextModulusLog> for NextCiphertextModulusLog {
|
||||
#[inline]
|
||||
fn convert_from(value: CiphertextModulusLog) -> Self {
|
||||
let CiphertextModulusLog(field_0) = value;
|
||||
NextCiphertextModulusLog(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::ThreadCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::ThreadCount as NextThreadCount;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<ThreadCount> for NextThreadCount {
|
||||
#[inline]
|
||||
fn convert_from(value: ThreadCount) -> Self {
|
||||
let ThreadCount(field_0) = value;
|
||||
NextThreadCount(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::LweBskGroupingFactor;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweBskGroupingFactor as NextLweBskGroupingFactor;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<LweBskGroupingFactor> for NextLweBskGroupingFactor {
|
||||
#[inline]
|
||||
fn convert_from(value: LweBskGroupingFactor) -> Self {
|
||||
let LweBskGroupingFactor(field_0) = value;
|
||||
NextLweBskGroupingFactor(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::GgswPerLweMultiBitBskElement;
|
||||
use next_tfhe::core_crypto::commons::parameters::GgswPerLweMultiBitBskElement as NextGgswPerLweMultiBitBskElement;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<GgswPerLweMultiBitBskElement>
|
||||
for NextGgswPerLweMultiBitBskElement
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: GgswPerLweMultiBitBskElement) -> Self {
|
||||
let GgswPerLweMultiBitBskElement(field_0) = value;
|
||||
NextGgswPerLweMultiBitBskElement(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::EncryptionKeyChoice;
|
||||
use next_tfhe::core_crypto::commons::parameters::EncryptionKeyChoice as NextEncryptionKeyChoice;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<EncryptionKeyChoice> for NextEncryptionKeyChoice {
|
||||
#[inline]
|
||||
fn convert_from(value: EncryptionKeyChoice) -> Self {
|
||||
match value {
|
||||
EncryptionKeyChoice::Big => NextEncryptionKeyChoice::Big,
|
||||
EncryptionKeyChoice::Small => NextEncryptionKeyChoice::Small,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::commons::parameters::PBSOrder;
|
||||
use next_tfhe::core_crypto::commons::parameters::PBSOrder as NextPBSOrder;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<PBSOrder> for NextPBSOrder {
|
||||
#[inline]
|
||||
fn convert_from(value: PBSOrder) -> Self {
|
||||
match value {
|
||||
PBSOrder::KeyswitchBootstrap => NextPBSOrder::KeyswitchBootstrap,
|
||||
PBSOrder::BootstrapKeyswitch => NextPBSOrder::BootstrapKeyswitch,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_plaintext_count() {
|
||||
use crate::core_crypto::commons::parameters::PlaintextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::PlaintextCount as NextPlaintextCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = PlaintextCount(rng.gen());
|
||||
let _next_tfhe_struct: NextPlaintextCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_cleartext_count() {
|
||||
use crate::core_crypto::commons::parameters::CleartextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::CleartextCount as NextCleartextCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = CleartextCount(rng.gen());
|
||||
let _next_tfhe_struct: NextCleartextCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_ciphertext_count() {
|
||||
use crate::core_crypto::commons::parameters::CiphertextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::CiphertextCount as NextCiphertextCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = CiphertextCount(rng.gen());
|
||||
let _next_tfhe_struct: NextCiphertextCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_ciphertext_count() {
|
||||
use crate::core_crypto::commons::parameters::LweCiphertextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweCiphertextCount as NextLweCiphertextCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = LweCiphertextCount(rng.gen());
|
||||
let _next_tfhe_struct: NextLweCiphertextCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_glwe_ciphertext_count() {
|
||||
use crate::core_crypto::commons::parameters::GlweCiphertextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::GlweCiphertextCount as NextGlweCiphertextCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = GlweCiphertextCount(rng.gen());
|
||||
let _next_tfhe_struct: NextGlweCiphertextCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_gsw_ciphertext_count() {
|
||||
use crate::core_crypto::commons::parameters::GswCiphertextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::GswCiphertextCount as NextGswCiphertextCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = GswCiphertextCount(rng.gen());
|
||||
let _next_tfhe_struct: NextGswCiphertextCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_ggsw_ciphertext_count() {
|
||||
use crate::core_crypto::commons::parameters::GgswCiphertextCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::GgswCiphertextCount as NextGgswCiphertextCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = GgswCiphertextCount(rng.gen());
|
||||
let _next_tfhe_struct: NextGgswCiphertextCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_size() {
|
||||
use crate::core_crypto::commons::parameters::LweSize;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweSize as NextLweSize;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = LweSize(rng.gen());
|
||||
let _next_tfhe_struct: NextLweSize = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_dimension() {
|
||||
use crate::core_crypto::commons::parameters::LweDimension;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweDimension as NextLweDimension;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = LweDimension(rng.gen());
|
||||
let _next_tfhe_struct: NextLweDimension = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_public_key_zero_encryption_count() {
|
||||
use crate::core_crypto::commons::parameters::LwePublicKeyZeroEncryptionCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::LwePublicKeyZeroEncryptionCount as NextLwePublicKeyZeroEncryptionCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = LwePublicKeyZeroEncryptionCount(rng.gen());
|
||||
let _next_tfhe_struct: NextLwePublicKeyZeroEncryptionCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_mask_count() {
|
||||
use crate::core_crypto::commons::parameters::LweMaskCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweMaskCount as NextLweMaskCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = LweMaskCount(rng.gen());
|
||||
let _next_tfhe_struct: NextLweMaskCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_body_count() {
|
||||
use crate::core_crypto::commons::parameters::LweBodyCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweBodyCount as NextLweBodyCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = LweBodyCount(rng.gen());
|
||||
let _next_tfhe_struct: NextLweBodyCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_glwe_size() {
|
||||
use crate::core_crypto::commons::parameters::GlweSize;
|
||||
use next_tfhe::core_crypto::commons::parameters::GlweSize as NextGlweSize;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = GlweSize(rng.gen());
|
||||
let _next_tfhe_struct: NextGlweSize = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_glwe_dimension() {
|
||||
use crate::core_crypto::commons::parameters::GlweDimension;
|
||||
use next_tfhe::core_crypto::commons::parameters::GlweDimension as NextGlweDimension;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = GlweDimension(rng.gen());
|
||||
let _next_tfhe_struct: NextGlweDimension = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_polynomial_size() {
|
||||
use crate::core_crypto::commons::parameters::PolynomialSize;
|
||||
use next_tfhe::core_crypto::commons::parameters::PolynomialSize as NextPolynomialSize;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = PolynomialSize(rng.gen());
|
||||
let _next_tfhe_struct: NextPolynomialSize = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_fourier_polynomial_size() {
|
||||
use crate::core_crypto::commons::parameters::FourierPolynomialSize;
|
||||
use next_tfhe::core_crypto::commons::parameters::FourierPolynomialSize as NextFourierPolynomialSize;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = FourierPolynomialSize(rng.gen());
|
||||
let _next_tfhe_struct: NextFourierPolynomialSize = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_polynomial_size_log() {
|
||||
use crate::core_crypto::commons::parameters::PolynomialSizeLog;
|
||||
use next_tfhe::core_crypto::commons::parameters::PolynomialSizeLog as NextPolynomialSizeLog;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = PolynomialSizeLog(rng.gen());
|
||||
let _next_tfhe_struct: NextPolynomialSizeLog = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_polynomial_count() {
|
||||
use crate::core_crypto::commons::parameters::PolynomialCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::PolynomialCount as NextPolynomialCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = PolynomialCount(rng.gen());
|
||||
let _next_tfhe_struct: NextPolynomialCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_monomial_degree() {
|
||||
use crate::core_crypto::commons::parameters::MonomialDegree;
|
||||
use next_tfhe::core_crypto::commons::parameters::MonomialDegree as NextMonomialDegree;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = MonomialDegree(rng.gen());
|
||||
let _next_tfhe_struct: NextMonomialDegree = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_decomposition_base_log() {
|
||||
use crate::core_crypto::commons::parameters::DecompositionBaseLog;
|
||||
use next_tfhe::core_crypto::commons::parameters::DecompositionBaseLog as NextDecompositionBaseLog;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = DecompositionBaseLog(rng.gen());
|
||||
let _next_tfhe_struct: NextDecompositionBaseLog = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_decomposition_level_count() {
|
||||
use crate::core_crypto::commons::parameters::DecompositionLevelCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::DecompositionLevelCount as NextDecompositionLevelCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = DecompositionLevelCount(rng.gen());
|
||||
let _next_tfhe_struct: NextDecompositionLevelCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lut_count_log() {
|
||||
use crate::core_crypto::commons::parameters::LutCountLog;
|
||||
use next_tfhe::core_crypto::commons::parameters::LutCountLog as NextLutCountLog;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = LutCountLog(rng.gen());
|
||||
let _next_tfhe_struct: NextLutCountLog = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_modulus_switch_offset() {
|
||||
use crate::core_crypto::commons::parameters::ModulusSwitchOffset;
|
||||
use next_tfhe::core_crypto::commons::parameters::ModulusSwitchOffset as NextModulusSwitchOffset;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = ModulusSwitchOffset(rng.gen());
|
||||
let _next_tfhe_struct: NextModulusSwitchOffset = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_delta_log() {
|
||||
use crate::core_crypto::commons::parameters::DeltaLog;
|
||||
use next_tfhe::core_crypto::commons::parameters::DeltaLog as NextDeltaLog;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = DeltaLog(rng.gen());
|
||||
let _next_tfhe_struct: NextDeltaLog = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_extracted_bits_count() {
|
||||
use crate::core_crypto::commons::parameters::ExtractedBitsCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::ExtractedBitsCount as NextExtractedBitsCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = ExtractedBitsCount(rng.gen());
|
||||
let _next_tfhe_struct: NextExtractedBitsCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_functional_packing_keyswitch_key_count() {
|
||||
use crate::core_crypto::commons::parameters::FunctionalPackingKeyswitchKeyCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::FunctionalPackingKeyswitchKeyCount as NextFunctionalPackingKeyswitchKeyCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = FunctionalPackingKeyswitchKeyCount(rng.gen());
|
||||
let _next_tfhe_struct: NextFunctionalPackingKeyswitchKeyCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_ciphertext_modulus_log() {
|
||||
use crate::core_crypto::commons::parameters::CiphertextModulusLog;
|
||||
use next_tfhe::core_crypto::commons::parameters::CiphertextModulusLog as NextCiphertextModulusLog;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = CiphertextModulusLog(rng.gen());
|
||||
let _next_tfhe_struct: NextCiphertextModulusLog = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_thread_count() {
|
||||
use crate::core_crypto::commons::parameters::ThreadCount;
|
||||
use next_tfhe::core_crypto::commons::parameters::ThreadCount as NextThreadCount;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = ThreadCount(rng.gen());
|
||||
let _next_tfhe_struct: NextThreadCount = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_bsk_grouping_factor() {
|
||||
use crate::core_crypto::commons::parameters::LweBskGroupingFactor;
|
||||
use next_tfhe::core_crypto::commons::parameters::LweBskGroupingFactor as NextLweBskGroupingFactor;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = LweBskGroupingFactor(rng.gen());
|
||||
let _next_tfhe_struct: NextLweBskGroupingFactor = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_ggsw_per_lwe_multi_bit_bsk_element() {
|
||||
use crate::core_crypto::commons::parameters::GgswPerLweMultiBitBskElement;
|
||||
use next_tfhe::core_crypto::commons::parameters::GgswPerLweMultiBitBskElement as NextGgswPerLweMultiBitBskElement;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let tfhe_struct = GgswPerLweMultiBitBskElement(rng.gen());
|
||||
let _next_tfhe_struct: NextGgswPerLweMultiBitBskElement = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_encryption_key_choice() {
|
||||
use crate::core_crypto::commons::parameters::EncryptionKeyChoice;
|
||||
use next_tfhe::core_crypto::commons::parameters::EncryptionKeyChoice as NextEncryptionKeyChoice;
|
||||
|
||||
let enum_val_big = EncryptionKeyChoice::Big;
|
||||
let enum_val_small = EncryptionKeyChoice::Small;
|
||||
|
||||
let next_enum_val_big: NextEncryptionKeyChoice = enum_val_big.convert_into();
|
||||
let next_enum_val_small: NextEncryptionKeyChoice = enum_val_small.convert_into();
|
||||
|
||||
assert_eq!(next_enum_val_big, NextEncryptionKeyChoice::Big);
|
||||
assert_eq!(next_enum_val_small, NextEncryptionKeyChoice::Small);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_pbs_order() {
|
||||
use crate::core_crypto::commons::parameters::PBSOrder;
|
||||
use next_tfhe::core_crypto::commons::parameters::PBSOrder as NextPBSOrder;
|
||||
|
||||
let enum_val_pbs_ks = PBSOrder::BootstrapKeyswitch;
|
||||
let enum_val_ks_pbs = PBSOrder::KeyswitchBootstrap;
|
||||
|
||||
let next_enum_val_pbs_ks: NextPBSOrder = enum_val_pbs_ks.convert_into();
|
||||
let next_enum_val_ls_pbs: NextPBSOrder = enum_val_ks_pbs.convert_into();
|
||||
|
||||
assert_eq!(next_enum_val_pbs_ks, NextPBSOrder::BootstrapKeyswitch);
|
||||
assert_eq!(next_enum_val_ls_pbs, NextPBSOrder::KeyswitchBootstrap);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
use crate::core_crypto::entities::cleartext::Cleartext;
|
||||
use next_tfhe::core_crypto::entities::cleartext::Cleartext as NextCleartext;
|
||||
|
||||
use crate::core_crypto::commons::numeric::Numeric;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::Numeric as NextNumeric;
|
||||
|
||||
impl<Scalar> crate::forward_compatibility::ConvertFrom<Cleartext<Scalar>> for NextCleartext<Scalar>
|
||||
where
|
||||
Scalar: Numeric + NextNumeric,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: Cleartext<Scalar>) -> Self {
|
||||
let Cleartext(field_0) = value;
|
||||
NextCleartext(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_cleartext() {
|
||||
use crate::core_crypto::entities::cleartext::Cleartext;
|
||||
use next_tfhe::core_crypto::entities::cleartext::Cleartext as NextCleartext;
|
||||
|
||||
use rand::Rng;
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let tfhe_struct = Cleartext(rng.gen::<u64>());
|
||||
let _next_tfhe_struct: NextCleartext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::entities::ggsw_ciphertext::GgswCiphertext;
|
||||
use next_tfhe::core_crypto::entities::ggsw_ciphertext::GgswCiphertext as NextGgswCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<GgswCiphertext<C>>
|
||||
for NextGgswCiphertext<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: GgswCiphertext<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
NextGgswCiphertext::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomp_base_log.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_ggsw_ciphertext() {
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
use crate::core_crypto::entities::ggsw_ciphertext::GgswCiphertext;
|
||||
use next_tfhe::core_crypto::entities::ggsw_ciphertext::GgswCiphertext as NextGgswCiphertext;
|
||||
|
||||
let glwe_size = GlweSize(2);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let decomp_base_log = DecompositionBaseLog(23);
|
||||
let container = vec![0u64; glwe_size.0 * glwe_size.0 * polynomial_size.0];
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
let tfhe_struct = GgswCiphertext::from_container(
|
||||
container,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
decomp_base_log,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextGgswCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
use crate::core_crypto::entities::ggsw_ciphertext_list::GgswCiphertextList;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::ggsw_ciphertext_list::GgswCiphertextList as NextGgswCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<GgswCiphertextList<C>>
|
||||
for NextGgswCiphertextList<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: GgswCiphertextList<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_ggsw_ciphertext_list() {
|
||||
use crate::core_crypto::entities::ggsw_ciphertext_list::GgswCiphertextList;
|
||||
use next_tfhe::core_crypto::entities::ggsw_ciphertext_list::GgswCiphertextList as NextGgswCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let glwe_size = GlweSize(2);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let decomp_base_log = DecompositionBaseLog(23);
|
||||
let decomp_level_count = DecompositionLevelCount(1);
|
||||
let ciphertext_count = GgswCiphertextCount(100);
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = GgswCiphertextList::new(
|
||||
0u64,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
decomp_base_log,
|
||||
decomp_level_count,
|
||||
ciphertext_count,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextGgswCiphertextList<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
use crate::core_crypto::entities::glwe_ciphertext::GlweCiphertext;
|
||||
use next_tfhe::core_crypto::entities::glwe_ciphertext::GlweCiphertext as NextGlweCiphertext;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<GlweCiphertext<C>>
|
||||
for NextGlweCiphertext<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: GlweCiphertext<C>) -> Self {
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
polynomial_size.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_glwe_ciphertext() {
|
||||
use crate::core_crypto::entities::glwe_ciphertext::GlweCiphertext;
|
||||
use next_tfhe::core_crypto::entities::glwe_ciphertext::GlweCiphertext as NextGlweCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let glwe_size = GlweSize(2);
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = GlweCiphertext::new(0u64, glwe_size, polynomial_size, ciphertext_modulus);
|
||||
let _next_tfhe_struct: NextGlweCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
use crate::core_crypto::entities::glwe_ciphertext_list::GlweCiphertextList;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::glwe_ciphertext_list::GlweCiphertextList as NextGlweCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<GlweCiphertextList<C>>
|
||||
for NextGlweCiphertextList<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: GlweCiphertextList<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_glwe_ciphertext_list() {
|
||||
use crate::core_crypto::entities::glwe_ciphertext_list::GlweCiphertextList;
|
||||
use next_tfhe::core_crypto::entities::glwe_ciphertext_list::GlweCiphertextList as NextGlweCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let glwe_size = GlweSize(2);
|
||||
let glwe_ciphertext_count = GlweCiphertextCount(10);
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = GlweCiphertextList::new(
|
||||
0u64,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
glwe_ciphertext_count,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
let _next_tfhe_struct: NextGlweCiphertextList<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::entities::glwe_secret_key::GlweSecretKey;
|
||||
use next_tfhe::core_crypto::entities::glwe_secret_key::GlweSecretKey as NextGlweSecretKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<GlweSecretKey<C>> for NextGlweSecretKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: GlweSecretKey<C>) -> Self {
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(container, polynomial_size.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_glwe_secret_key() {
|
||||
use crate::core_crypto::entities::glwe_secret_key::GlweSecretKey;
|
||||
use next_tfhe::core_crypto::entities::glwe_secret_key::GlweSecretKey as NextGlweSecretKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let glwe_dimension = GlweDimension(1);
|
||||
|
||||
let tfhe_struct = GlweSecretKey::new_empty_key(0u64, glwe_dimension, polynomial_size);
|
||||
let _next_tfhe_struct: NextGlweSecretKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
use crate::core_crypto::entities::lwe_bootstrap_key::LweBootstrapKey;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::lwe_bootstrap_key::LweBootstrapKey as NextLweBootstrapKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<LweBootstrapKey<C>>
|
||||
for NextLweBootstrapKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LweBootstrapKey<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_bootstrap_key() {
|
||||
use crate::core_crypto::entities::lwe_bootstrap_key::LweBootstrapKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_bootstrap_key::LweBootstrapKey as NextLweBootstrapKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let input_lwe_dimension = LweDimension(100);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let glwe_size = GlweSize(2);
|
||||
let decomp_base_log = DecompositionBaseLog(23);
|
||||
let decomp_level_count = DecompositionLevelCount(1);
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = LweBootstrapKey::new(
|
||||
0u64,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
decomp_base_log,
|
||||
decomp_level_count,
|
||||
input_lwe_dimension,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
let _next_tfhe_struct: NextLweBootstrapKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::entities::lwe_ciphertext::LweCiphertext;
|
||||
use next_tfhe::core_crypto::entities::lwe_ciphertext::LweCiphertext as NextLweCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<LweCiphertext<C>> for NextLweCiphertext<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LweCiphertext<C>) -> Self {
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let data = value.into_container();
|
||||
NextLweCiphertext::from_container(data, ciphertext_modulus.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_ciphertext() {
|
||||
use crate::core_crypto::entities::lwe_ciphertext::LweCiphertext;
|
||||
use next_tfhe::core_crypto::entities::lwe_ciphertext::LweCiphertext as NextLweCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let lwe_size = LweSize(101);
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = LweCiphertext::new(0u64, lwe_size, ciphertext_modulus);
|
||||
let _next_tfhe_struct: NextLweCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
use crate::core_crypto::entities::lwe_ciphertext_list::LweCiphertextList;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::lwe_ciphertext_list::LweCiphertextList as NextLweCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<LweCiphertextList<C>>
|
||||
for NextLweCiphertextList<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LweCiphertextList<C>) -> Self {
|
||||
let lwe_size = value.lwe_size();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
lwe_size.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_ciphertext_list() {
|
||||
use crate::core_crypto::entities::lwe_ciphertext_list::LweCiphertextList;
|
||||
use next_tfhe::core_crypto::entities::lwe_ciphertext_list::LweCiphertextList as NextLweCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let lwe_size = LweSize(101);
|
||||
let lwe_ciphertext_count = LweCiphertextCount(10);
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct =
|
||||
LweCiphertextList::new(0u64, lwe_size, lwe_ciphertext_count, ciphertext_modulus);
|
||||
let _next_tfhe_struct: NextLweCiphertextList<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::entities::lwe_compact_ciphertext_list::LweCompactCiphertextList;
|
||||
use next_tfhe::core_crypto::entities::lwe_compact_ciphertext_list::LweCompactCiphertextList as NextLweCompactCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<LweCompactCiphertextList<C>>
|
||||
for NextLweCompactCiphertextList<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LweCompactCiphertextList<C>) -> Self {
|
||||
let lwe_size = value.lwe_size();
|
||||
let lwe_ciphertext_count = value.lwe_ciphertext_count();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
lwe_size.convert_into(),
|
||||
lwe_ciphertext_count.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_compact_ciphertext_list() {
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
use crate::core_crypto::entities::lwe_compact_ciphertext_list::LweCompactCiphertextList;
|
||||
use next_tfhe::core_crypto::entities::lwe_compact_ciphertext_list::LweCompactCiphertextList as NextLweCompactCiphertextList;
|
||||
|
||||
let tfhe_struct = LweCompactCiphertextList::new(
|
||||
0u64,
|
||||
LweSize(101),
|
||||
LweCiphertextCount(10),
|
||||
CiphertextModulus::new_native(),
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextLweCompactCiphertextList<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::entities::lwe_compact_public_key::LweCompactPublicKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_compact_public_key::LweCompactPublicKey as NextLweCompactPublicKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<LweCompactPublicKey<C>>
|
||||
for NextLweCompactPublicKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LweCompactPublicKey<C>) -> Self {
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(container, ciphertext_modulus.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_compact_public_key() {
|
||||
use crate::core_crypto::entities::lwe_compact_public_key::LweCompactPublicKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_compact_public_key::LweCompactPublicKey as NextLweCompactPublicKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct =
|
||||
LweCompactPublicKey::new(0u64, LweDimension(1024), CiphertextModulus::new_native());
|
||||
let _next_tfhe_struct: NextLweCompactPublicKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
use crate::core_crypto::entities::lwe_keyswitch_key::LweKeyswitchKey;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::lwe_keyswitch_key::LweKeyswitchKey as NextLweKeyswitchKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<LweKeyswitchKey<C>>
|
||||
for NextLweKeyswitchKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LweKeyswitchKey<C>) -> Self {
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let output_lwe_size = value.output_lwe_size();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
output_lwe_size.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_keyswitch_key() {
|
||||
use crate::core_crypto::entities::lwe_keyswitch_key::LweKeyswitchKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_keyswitch_key::LweKeyswitchKey as NextLweKeyswitchKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = LweKeyswitchKey::new(
|
||||
0u64,
|
||||
DecompositionBaseLog(5),
|
||||
DecompositionLevelCount(3),
|
||||
LweDimension(200),
|
||||
LweDimension(100),
|
||||
CiphertextModulus::new_native(),
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextLweKeyswitchKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::entities::lwe_multi_bit_bootstrap_key::LweMultiBitBootstrapKey;
|
||||
use crate::core_crypto::fft_impl::fft64::math::fft::FourierPolynomialList;
|
||||
use next_tfhe::core_crypto::entities::lwe_multi_bit_bootstrap_key::LweMultiBitBootstrapKey as NextLweMultiBitBootstrapKey;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::math::fft::FourierPolynomialList as NextFourierPolynomialList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<LweMultiBitBootstrapKey<C>>
|
||||
for NextLweMultiBitBootstrapKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LweMultiBitBootstrapKey<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let grouping_factor = value.grouping_factor();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
grouping_factor.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::core_crypto::entities::lwe_multi_bit_bootstrap_key::FourierLweMultiBitBootstrapKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_multi_bit_bootstrap_key::FourierLweMultiBitBootstrapKey as NextFourierLweMultiBitBootstrapKey;
|
||||
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::{c64 as NextC64, ABox as NextABox};
|
||||
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
use crate::core_crypto::fft_impl::fft64::c64;
|
||||
|
||||
impl<C> crate::forward_compatibility::ConvertFrom<FourierLweMultiBitBootstrapKey<C>>
|
||||
for NextFourierLweMultiBitBootstrapKey<NextABox<[NextC64]>>
|
||||
where
|
||||
C: Container<Element = c64> + NextContainer<Element = NextC64>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: FourierLweMultiBitBootstrapKey<C>) -> Self {
|
||||
let input_lwe_dimension = value.input_lwe_dimension();
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomposition_base_log = value.decomposition_base_log();
|
||||
let decomposition_level_count = value.decomposition_level_count();
|
||||
let grouping_factor = value.grouping_factor();
|
||||
let data = value.data();
|
||||
|
||||
let poly_list = FourierPolynomialList {
|
||||
data,
|
||||
polynomial_size,
|
||||
};
|
||||
|
||||
let next_poly_list: NextFourierPolynomialList<_> = poly_list.convert_into();
|
||||
let data = next_poly_list.data;
|
||||
|
||||
Self::from_container(
|
||||
data,
|
||||
input_lwe_dimension.convert_into(),
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomposition_base_log.convert_into(),
|
||||
decomposition_level_count.convert_into(),
|
||||
grouping_factor.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_multi_bit_bootstrap_key() {
|
||||
use crate::core_crypto::entities::lwe_multi_bit_bootstrap_key::LweMultiBitBootstrapKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_multi_bit_bootstrap_key::LweMultiBitBootstrapKey as NextLweMultiBitBootstrapKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let input_lwe_dimension = LweDimension(100);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let glwe_size = GlweSize(2);
|
||||
let decomp_base_log = DecompositionBaseLog(23);
|
||||
let decomp_level_count = DecompositionLevelCount(1);
|
||||
let grouping_factor = LweBskGroupingFactor(2);
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = LweMultiBitBootstrapKey::new(
|
||||
0u64,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
decomp_base_log,
|
||||
decomp_level_count,
|
||||
input_lwe_dimension,
|
||||
grouping_factor,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
let _next_tfhe_struct: NextLweMultiBitBootstrapKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_fourier_lwe_multi_bit_bootstrap_key() {
|
||||
use crate::core_crypto::entities::lwe_multi_bit_bootstrap_key::{
|
||||
FourierLweMultiBitBootstrapKey, LweMultiBitBootstrapKey,
|
||||
};
|
||||
use next_tfhe::core_crypto::entities::lwe_multi_bit_bootstrap_key::FourierLweMultiBitBootstrapKey as NextFourierLweMultiBitBootstrapKey;
|
||||
|
||||
use crate::core_crypto::algorithms::par_convert_standard_lwe_multi_bit_bootstrap_key_to_fourier;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let input_lwe_dimension = LweDimension(100);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let glwe_size = GlweSize(2);
|
||||
let decomp_base_log = DecompositionBaseLog(23);
|
||||
let decomp_level_count = DecompositionLevelCount(1);
|
||||
let grouping_factor = LweBskGroupingFactor(2);
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let bsk = LweMultiBitBootstrapKey::new(
|
||||
0u64,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
decomp_base_log,
|
||||
decomp_level_count,
|
||||
input_lwe_dimension,
|
||||
grouping_factor,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
let mut tfhe_struct = FourierLweMultiBitBootstrapKey::new(
|
||||
bsk.input_lwe_dimension(),
|
||||
bsk.glwe_size(),
|
||||
bsk.polynomial_size(),
|
||||
bsk.decomposition_base_log(),
|
||||
bsk.decomposition_level_count(),
|
||||
bsk.grouping_factor(),
|
||||
);
|
||||
|
||||
par_convert_standard_lwe_multi_bit_bootstrap_key_to_fourier(&bsk, &mut tfhe_struct);
|
||||
|
||||
let _next_tfhe_struct: NextFourierLweMultiBitBootstrapKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::entities::lwe_packing_keyswitch_key::LwePackingKeyswitchKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_packing_keyswitch_key::LwePackingKeyswitchKey as NextLwePackingKeyswitchKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<LwePackingKeyswitchKey<C>>
|
||||
for NextLwePackingKeyswitchKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LwePackingKeyswitchKey<C>) -> Self {
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let output_glwe_size = value.output_glwe_size();
|
||||
let output_polynomial_size = value.output_polynomial_size();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
output_glwe_size.convert_into(),
|
||||
output_polynomial_size.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_packing_keyswitch_key() {
|
||||
use crate::core_crypto::entities::lwe_packing_keyswitch_key::LwePackingKeyswitchKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_packing_keyswitch_key::LwePackingKeyswitchKey as NextLwePackingKeyswitchKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let decomp_base_log = DecompositionBaseLog(23);
|
||||
let decomp_level_count = DecompositionLevelCount(1);
|
||||
let input_key_lwe_dimension = LweDimension(100);
|
||||
let output_key_glwe_dimension = GlweDimension(2);
|
||||
let output_key_polynomial_size = PolynomialSize(2048);
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = LwePackingKeyswitchKey::new(
|
||||
0u64,
|
||||
decomp_base_log,
|
||||
decomp_level_count,
|
||||
input_key_lwe_dimension,
|
||||
output_key_glwe_dimension,
|
||||
output_key_polynomial_size,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
let _next_tfhe_struct: NextLwePackingKeyswitchKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::entities::lwe_private_functional_packing_keyswitch_key::LwePrivateFunctionalPackingKeyswitchKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_private_functional_packing_keyswitch_key::LwePrivateFunctionalPackingKeyswitchKey as NextLwePrivateFunctionalPackingKeyswitchKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C>
|
||||
crate::forward_compatibility::ConvertFrom<LwePrivateFunctionalPackingKeyswitchKey<C>>
|
||||
for NextLwePrivateFunctionalPackingKeyswitchKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LwePrivateFunctionalPackingKeyswitchKey<C>) -> Self {
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let output_glwe_size = value.output_glwe_size();
|
||||
let output_polynomial_size = value.output_polynomial_size();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
output_glwe_size.convert_into(),
|
||||
output_polynomial_size.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_private_functional_packing_keyswitch_key() {
|
||||
use crate::core_crypto::entities::lwe_private_functional_packing_keyswitch_key::LwePrivateFunctionalPackingKeyswitchKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_private_functional_packing_keyswitch_key::LwePrivateFunctionalPackingKeyswitchKey as NextLwePrivateFunctionalPackingKeyswitchKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let decomp_base_log = DecompositionBaseLog(23);
|
||||
let decomp_level_count = DecompositionLevelCount(1);
|
||||
let input_key_lwe_dimension = LweDimension(100);
|
||||
let output_key_glwe_size = GlweSize(2);
|
||||
let output_key_polynomial_size = PolynomialSize(2048);
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = LwePrivateFunctionalPackingKeyswitchKey::new(
|
||||
0u64,
|
||||
decomp_base_log,
|
||||
decomp_level_count,
|
||||
input_key_lwe_dimension,
|
||||
output_key_glwe_size,
|
||||
output_key_polynomial_size,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
let _next_tfhe_struct: NextLwePrivateFunctionalPackingKeyswitchKey<_> =
|
||||
tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
use crate::core_crypto::entities::lwe_private_functional_packing_keyswitch_key_list::LwePrivateFunctionalPackingKeyswitchKeyList;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::lwe_private_functional_packing_keyswitch_key_list::LwePrivateFunctionalPackingKeyswitchKeyList as NextLwePrivateFunctionalPackingKeyswitchKeyList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C>
|
||||
crate::forward_compatibility::ConvertFrom<LwePrivateFunctionalPackingKeyswitchKeyList<C>>
|
||||
for NextLwePrivateFunctionalPackingKeyswitchKeyList<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LwePrivateFunctionalPackingKeyswitchKeyList<C>) -> Self {
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let input_lwe_size = value.input_lwe_size();
|
||||
let output_glwe_size = value.output_glwe_size();
|
||||
let output_polynomial_size = value.output_polynomial_size();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
input_lwe_size.convert_into(),
|
||||
output_glwe_size.convert_into(),
|
||||
output_polynomial_size.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_private_functional_packing_keyswitch_key_list() {
|
||||
use crate::core_crypto::entities::lwe_private_functional_packing_keyswitch_key_list::LwePrivateFunctionalPackingKeyswitchKeyList;
|
||||
use next_tfhe::core_crypto::entities::lwe_private_functional_packing_keyswitch_key_list::LwePrivateFunctionalPackingKeyswitchKeyList as NextLwePrivateFunctionalPackingKeyswitchKeyList;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = LwePrivateFunctionalPackingKeyswitchKeyList::new(
|
||||
0u64,
|
||||
DecompositionBaseLog(12),
|
||||
DecompositionLevelCount(2),
|
||||
LweDimension(100),
|
||||
GlweSize(2),
|
||||
PolynomialSize(1024),
|
||||
FunctionalPackingKeyswitchKeyCount(2),
|
||||
CiphertextModulus::new_native(),
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextLwePrivateFunctionalPackingKeyswitchKeyList<_> =
|
||||
tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::entities::lwe_public_key::LwePublicKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_public_key::LwePublicKey as NextLwePublicKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<LwePublicKey<C>> for NextLwePublicKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LwePublicKey<C>) -> Self {
|
||||
let lwe_size = value.lwe_size();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
lwe_size.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_public_key() {
|
||||
use crate::core_crypto::entities::lwe_public_key::LwePublicKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_public_key::LwePublicKey as NextLwePublicKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = LwePublicKey::new(
|
||||
0u64,
|
||||
LweSize(101),
|
||||
LwePublicKeyZeroEncryptionCount(10),
|
||||
CiphertextModulus::new_native(),
|
||||
);
|
||||
let _next_tfhe_struct: NextLwePublicKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
use crate::core_crypto::entities::lwe_secret_key::LweSecretKey;
|
||||
|
||||
use next_tfhe::core_crypto::entities::lwe_secret_key::LweSecretKey as NextLweSecretKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<LweSecretKey<C>> for NextLweSecretKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: LweSecretKey<C>) -> Self {
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(container)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_lwe_secret_key() {
|
||||
use crate::core_crypto::entities::lwe_secret_key::LweSecretKey;
|
||||
use next_tfhe::core_crypto::entities::lwe_secret_key::LweSecretKey as NextLweSecretKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = LweSecretKey::new_empty_key(0u64, LweDimension(100));
|
||||
let _next_tfhe_struct: NextLweSecretKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
34
tfhe/src/forward_compatibility/core_crypto/entities/mod.rs
Normal file
34
tfhe/src/forward_compatibility/core_crypto/entities/mod.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
pub mod cleartext;
|
||||
pub mod ggsw_ciphertext;
|
||||
pub mod ggsw_ciphertext_list;
|
||||
pub mod glwe_ciphertext;
|
||||
pub mod glwe_ciphertext_list;
|
||||
pub mod glwe_secret_key;
|
||||
pub mod lwe_bootstrap_key;
|
||||
pub mod lwe_ciphertext;
|
||||
pub mod lwe_ciphertext_list;
|
||||
pub mod lwe_compact_ciphertext_list;
|
||||
pub mod lwe_compact_public_key;
|
||||
pub mod lwe_keyswitch_key;
|
||||
pub mod lwe_multi_bit_bootstrap_key;
|
||||
pub mod lwe_packing_keyswitch_key;
|
||||
pub mod lwe_private_functional_packing_keyswitch_key;
|
||||
pub mod lwe_private_functional_packing_keyswitch_key_list;
|
||||
pub mod lwe_public_key;
|
||||
pub mod lwe_secret_key;
|
||||
pub mod plaintext;
|
||||
pub mod plaintext_list;
|
||||
pub mod polynomial;
|
||||
pub mod polynomial_list;
|
||||
pub mod seeded_ggsw_ciphertext;
|
||||
pub mod seeded_ggsw_ciphertext_list;
|
||||
pub mod seeded_glwe_ciphertext;
|
||||
pub mod seeded_glwe_ciphertext_list;
|
||||
pub mod seeded_lwe_bootstrap_key;
|
||||
pub mod seeded_lwe_ciphertext;
|
||||
pub mod seeded_lwe_ciphertext_list;
|
||||
pub mod seeded_lwe_compact_public_key;
|
||||
pub mod seeded_lwe_keyswitch_key;
|
||||
pub mod seeded_lwe_multi_bit_bootstrap_key;
|
||||
pub mod seeded_lwe_packing_keyswitch_key;
|
||||
pub mod seeded_lwe_public_key;
|
||||
@@ -0,0 +1,31 @@
|
||||
use crate::core_crypto::entities::plaintext::Plaintext;
|
||||
use next_tfhe::core_crypto::entities::plaintext::Plaintext as NextPlaintext;
|
||||
|
||||
use crate::core_crypto::commons::numeric::Numeric;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::Numeric as NextNumeric;
|
||||
|
||||
impl<Scalar> crate::forward_compatibility::ConvertFrom<Plaintext<Scalar>> for NextPlaintext<Scalar>
|
||||
where
|
||||
Scalar: Numeric + NextNumeric,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: Plaintext<Scalar>) -> Self {
|
||||
let Plaintext(field_0) = value;
|
||||
NextPlaintext(field_0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_plaintext() {
|
||||
use crate::core_crypto::entities::plaintext::Plaintext;
|
||||
use next_tfhe::core_crypto::entities::plaintext::Plaintext as NextPlaintext;
|
||||
|
||||
let tfhe_struct = Plaintext(42u64);
|
||||
let _next_tfhe_struct: NextPlaintext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
use crate::core_crypto::entities::plaintext_list::PlaintextList;
|
||||
use next_tfhe::core_crypto::entities::plaintext_list::PlaintextList as NextPlaintextList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<PlaintextList<C>> for NextPlaintextList<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: PlaintextList<C>) -> Self {
|
||||
Self::from_container(value.into_container())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_plaintext_list() {
|
||||
use crate::core_crypto::entities::plaintext_list::PlaintextList;
|
||||
use next_tfhe::core_crypto::entities::plaintext_list::PlaintextList as NextPlaintextList;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = PlaintextList::new(0u64, PlaintextCount(10));
|
||||
let _next_tfhe_struct: NextPlaintextList<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
use crate::core_crypto::entities::polynomial::Polynomial;
|
||||
|
||||
use next_tfhe::core_crypto::entities::polynomial::Polynomial as NextPolynomial;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<Polynomial<C>> for NextPolynomial<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: Polynomial<C>) -> Self {
|
||||
Self::from_container(value.into_container())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_polynomial() {
|
||||
use crate::core_crypto::entities::polynomial::Polynomial;
|
||||
use next_tfhe::core_crypto::entities::polynomial::Polynomial as NextPolynomial;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = Polynomial::new(0u64, PolynomialSize(2048));
|
||||
let _next_tfhe_struct: NextPolynomial<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
use crate::core_crypto::entities::polynomial_list::PolynomialList;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::polynomial_list::PolynomialList as NextPolynomialList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<PolynomialList<C>>
|
||||
for NextPolynomialList<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: PolynomialList<C>) -> Self {
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(container, polynomial_size.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_polynomial_list() {
|
||||
use crate::core_crypto::entities::polynomial_list::PolynomialList;
|
||||
use next_tfhe::core_crypto::entities::polynomial_list::PolynomialList as NextPolynomialList;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = PolynomialList::new(0u64, PolynomialSize(2048), PolynomialCount(10));
|
||||
let _next_tfhe_struct: NextPolynomialList<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
use crate::core_crypto::entities::seeded_ggsw_ciphertext::SeededGgswCiphertext;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_ggsw_ciphertext::SeededGgswCiphertext as NextSeededGgswCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededGgswCiphertext<C>>
|
||||
for NextSeededGgswCiphertext<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededGgswCiphertext<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomp_base_log.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_ggsw_ciphertext() {
|
||||
use crate::core_crypto::entities::seeded_ggsw_ciphertext::SeededGgswCiphertext;
|
||||
use next_tfhe::core_crypto::entities::seeded_ggsw_ciphertext::SeededGgswCiphertext as NextSeededGgswCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let glwe_size = GlweSize(2);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let decomp_base_log = DecompositionBaseLog(23);
|
||||
let decomp_level_count = DecompositionLevelCount(1);
|
||||
let compression_seed = Seed(42).into();
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = SeededGgswCiphertext::new(
|
||||
0u64,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
decomp_base_log,
|
||||
decomp_level_count,
|
||||
compression_seed,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextSeededGgswCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
use crate::core_crypto::entities::seeded_ggsw_ciphertext_list::SeededGgswCiphertextList;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_ggsw_ciphertext_list::SeededGgswCiphertextList as NextSeededGgswCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededGgswCiphertextList<C>>
|
||||
for NextSeededGgswCiphertextList<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededGgswCiphertextList<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_ggsw_ciphertext_list() {
|
||||
use crate::core_crypto::entities::seeded_ggsw_ciphertext_list::SeededGgswCiphertextList;
|
||||
use next_tfhe::core_crypto::entities::seeded_ggsw_ciphertext_list::SeededGgswCiphertextList as NextSeededGgswCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let glwe_size = GlweSize(2);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let decomp_base_log = DecompositionBaseLog(23);
|
||||
let decomp_level_count = DecompositionLevelCount(1);
|
||||
let ciphertext_count = GgswCiphertextCount(10);
|
||||
let compression_seed = Seed(42).into();
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = SeededGgswCiphertextList::new(
|
||||
0u64,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
decomp_base_log,
|
||||
decomp_level_count,
|
||||
ciphertext_count,
|
||||
compression_seed,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextSeededGgswCiphertextList<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
use crate::core_crypto::entities::seeded_glwe_ciphertext::SeededGlweCiphertext;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_glwe_ciphertext::SeededGlweCiphertext as NextSeededGlweCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededGlweCiphertext<C>>
|
||||
for NextSeededGlweCiphertext<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededGlweCiphertext<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_glwe_ciphertext() {
|
||||
use crate::core_crypto::entities::seeded_glwe_ciphertext::SeededGlweCiphertext;
|
||||
use next_tfhe::core_crypto::entities::seeded_glwe_ciphertext::SeededGlweCiphertext as NextSeededGlweCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let glwe_size = GlweSize(2);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let compression_seed = Seed(42).into();
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = SeededGlweCiphertext::new(
|
||||
0u64,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
compression_seed,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextSeededGlweCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
use crate::core_crypto::entities::seeded_glwe_ciphertext_list::SeededGlweCiphertextList;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_glwe_ciphertext_list::SeededGlweCiphertextList as NextSeededGlweCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededGlweCiphertextList<C>>
|
||||
for NextSeededGlweCiphertextList<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededGlweCiphertextList<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
#[test]
|
||||
fn test_conversion_seeded_glwe_ciphertext_list() {
|
||||
use crate::core_crypto::entities::seeded_glwe_ciphertext_list::SeededGlweCiphertextList;
|
||||
use next_tfhe::core_crypto::entities::seeded_glwe_ciphertext_list::SeededGlweCiphertextList as NextSeededGlweCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let glwe_size = GlweSize(2);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let ciphertext_count = GlweCiphertextCount(10);
|
||||
let compression_seed = Seed(42).into();
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = SeededGlweCiphertextList::new(
|
||||
0u64,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
ciphertext_count,
|
||||
compression_seed,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextSeededGlweCiphertextList<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
use crate::core_crypto::entities::seeded_lwe_bootstrap_key::SeededLweBootstrapKey;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_bootstrap_key::SeededLweBootstrapKey as NextSeededLweBootstrapKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededLweBootstrapKey<C>>
|
||||
for NextSeededLweBootstrapKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededLweBootstrapKey<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_lwe_bootstrap_key() {
|
||||
use crate::core_crypto::entities::seeded_lwe_bootstrap_key::SeededLweBootstrapKey;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_bootstrap_key::SeededLweBootstrapKey as NextSeededLweBootstrapKey;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = SeededLweBootstrapKey::new(
|
||||
0u64,
|
||||
GlweSize(2),
|
||||
PolynomialSize(2048),
|
||||
DecompositionBaseLog(23),
|
||||
DecompositionLevelCount(1),
|
||||
LweDimension(100),
|
||||
Seed(42).into(),
|
||||
CiphertextModulus::new_native(),
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextSeededLweBootstrapKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
use crate::core_crypto::entities::seeded_lwe_ciphertext::SeededLweCiphertext;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_ciphertext::SeededLweCiphertext as NextSeededLweCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
|
||||
impl<Scalar> crate::forward_compatibility::ConvertFrom<SeededLweCiphertext<Scalar>>
|
||||
for NextSeededLweCiphertext<Scalar>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededLweCiphertext<Scalar>) -> Self {
|
||||
let lwe_size = value.lwe_size();
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let scalar = value.into_scalar();
|
||||
|
||||
Self::from_scalar(
|
||||
scalar,
|
||||
lwe_size.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_lwe_ciphertext() {
|
||||
use crate::core_crypto::commons::math::random::CompressionSeed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
use crate::core_crypto::entities::seeded_lwe_ciphertext::SeededLweCiphertext;
|
||||
use crate::core_crypto::seeders::new_seeder;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_ciphertext::SeededLweCiphertext as NextSeededLweCiphertext;
|
||||
|
||||
let mut seeder = new_seeder();
|
||||
|
||||
let tfhe_struct = SeededLweCiphertext::new(
|
||||
0u64,
|
||||
LweSize(101),
|
||||
CompressionSeed {
|
||||
seed: seeder.seed(),
|
||||
},
|
||||
CiphertextModulus::new_native(),
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextSeededLweCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
use crate::core_crypto::entities::seeded_lwe_ciphertext_list::SeededLweCiphertextList;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_ciphertext_list::SeededLweCiphertextList as NextSeededLweCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededLweCiphertextList<C>>
|
||||
for NextSeededLweCiphertextList<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededLweCiphertextList<C>) -> Self {
|
||||
let lwe_size = value.lwe_size();
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
lwe_size.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_lwe_ciphertext_list() {
|
||||
use crate::core_crypto::entities::seeded_lwe_ciphertext_list::SeededLweCiphertextList;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_ciphertext_list::SeededLweCiphertextList as NextSeededLweCiphertextList;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let lwe_size = LweSize(101);
|
||||
let ciphertext_count = LweCiphertextCount(10);
|
||||
let compression_seed = Seed(42).into();
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = SeededLweCiphertextList::new(
|
||||
0u64,
|
||||
lwe_size,
|
||||
ciphertext_count,
|
||||
compression_seed,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextSeededLweCiphertextList<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
use crate::core_crypto::entities::seeded_lwe_compact_public_key::SeededLweCompactPublicKey;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_compact_public_key::SeededLweCompactPublicKey as NextSeededLweCompactPublicKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededLweCompactPublicKey<C>>
|
||||
for NextSeededLweCompactPublicKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededLweCompactPublicKey<C>) -> Self {
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_lwe_compact_public_key() {
|
||||
use crate::core_crypto::entities::seeded_lwe_compact_public_key::SeededLweCompactPublicKey;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_compact_public_key::SeededLweCompactPublicKey as NextSeededLweCompactPublicKey;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let lwe_dimension = LweDimension(1024);
|
||||
let compression_seed = Seed(42).into();
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = SeededLweCompactPublicKey::new(
|
||||
0u64,
|
||||
lwe_dimension,
|
||||
compression_seed,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextSeededLweCompactPublicKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::core_crypto::entities::seeded_lwe_keyswitch_key::SeededLweKeyswitchKey;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_keyswitch_key::SeededLweKeyswitchKey as NextSeededLweKeyswitchKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededLweKeyswitchKey<C>>
|
||||
for NextSeededLweKeyswitchKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededLweKeyswitchKey<C>) -> Self {
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let output_lwe_size = value.output_lwe_size();
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
output_lwe_size.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_lwe_keyswitch_key() {
|
||||
use crate::core_crypto::entities::seeded_lwe_keyswitch_key::SeededLweKeyswitchKey;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_keyswitch_key::SeededLweKeyswitchKey as NextSeededLweKeyswitchKey;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = SeededLweKeyswitchKey::new(
|
||||
0u64,
|
||||
DecompositionBaseLog(5),
|
||||
DecompositionLevelCount(3),
|
||||
LweDimension(200),
|
||||
LweDimension(100),
|
||||
Seed(42).into(),
|
||||
CiphertextModulus::new_native(),
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextSeededLweKeyswitchKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
use crate::core_crypto::entities::seeded_lwe_multi_bit_bootstrap_key::SeededLweMultiBitBootstrapKey;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_multi_bit_bootstrap_key::SeededLweMultiBitBootstrapKey as NextSeededLweMultiBitBootstrapKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededLweMultiBitBootstrapKey<C>>
|
||||
for NextSeededLweMultiBitBootstrapKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededLweMultiBitBootstrapKey<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let compression_seed = value.compression_seed();
|
||||
let grouping_factor = value.grouping_factor();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
grouping_factor.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_lwe_multi_bit_bootstrap_key() {
|
||||
use crate::core_crypto::entities::seeded_lwe_multi_bit_bootstrap_key::SeededLweMultiBitBootstrapKey;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_multi_bit_bootstrap_key::SeededLweMultiBitBootstrapKey as NextSeededLweMultiBitBootstrapKey;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = SeededLweMultiBitBootstrapKey::new(
|
||||
0u64,
|
||||
GlweSize(2),
|
||||
PolynomialSize(2048),
|
||||
DecompositionBaseLog(23),
|
||||
DecompositionLevelCount(1),
|
||||
LweDimension(100),
|
||||
LweBskGroupingFactor(2),
|
||||
Seed(42).into(),
|
||||
CiphertextModulus::new_native(),
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextSeededLweMultiBitBootstrapKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
use crate::core_crypto::entities::seeded_lwe_packing_keyswitch_key::SeededLwePackingKeyswitchKey;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_packing_keyswitch_key::SeededLwePackingKeyswitchKey as NextSeededLwePackingKeyswitchKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededLwePackingKeyswitchKey<C>>
|
||||
for NextSeededLwePackingKeyswitchKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededLwePackingKeyswitchKey<C>) -> Self {
|
||||
let decomp_base_log = value.decomposition_base_log();
|
||||
let decomp_level_count = value.decomposition_level_count();
|
||||
let output_glwe_size = value.output_glwe_size();
|
||||
let output_polynomial_size = value.output_polynomial_size();
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
Self::from_container(
|
||||
container,
|
||||
decomp_base_log.convert_into(),
|
||||
decomp_level_count.convert_into(),
|
||||
output_glwe_size.convert_into(),
|
||||
output_polynomial_size.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_lwe_packing_keyswitch_key() {
|
||||
use crate::core_crypto::entities::seeded_lwe_packing_keyswitch_key::SeededLwePackingKeyswitchKey;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_packing_keyswitch_key::SeededLwePackingKeyswitchKey as NextSeededLwePackingKeyswitchKey;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let decomp_base_log = DecompositionBaseLog(23);
|
||||
let decomp_level_count = DecompositionLevelCount(1);
|
||||
let input_key_lwe_dimension = LweDimension(100);
|
||||
let output_key_glwe_dimension = GlweDimension(2);
|
||||
let output_key_polynomial_size = PolynomialSize(2048);
|
||||
let compression_seed = Seed(42).into();
|
||||
let ciphertext_modulus = CiphertextModulus::new_native();
|
||||
|
||||
let tfhe_struct = SeededLwePackingKeyswitchKey::new(
|
||||
0u64,
|
||||
decomp_base_log,
|
||||
decomp_level_count,
|
||||
input_key_lwe_dimension,
|
||||
output_key_glwe_dimension,
|
||||
output_key_polynomial_size,
|
||||
compression_seed,
|
||||
ciphertext_modulus,
|
||||
);
|
||||
let _next_tfhe_struct: NextSeededLwePackingKeyswitchKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
use crate::core_crypto::entities::seeded_lwe_public_key::SeededLwePublicKey;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_public_key::SeededLwePublicKey as NextSeededLwePublicKey;
|
||||
|
||||
use crate::core_crypto::commons::numeric::UnsignedInteger;
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
|
||||
use next_tfhe::core_crypto::commons::numeric::UnsignedInteger as NextUnsignedInteger;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
|
||||
impl<Scalar, C> crate::forward_compatibility::ConvertFrom<SeededLwePublicKey<C>>
|
||||
for NextSeededLwePublicKey<C>
|
||||
where
|
||||
Scalar: UnsignedInteger + NextUnsignedInteger,
|
||||
C: Container<Element = Scalar> + NextContainer<Element = Scalar>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: SeededLwePublicKey<C>) -> Self {
|
||||
let lwe_size = value.lwe_size();
|
||||
let compression_seed = value.compression_seed();
|
||||
let ciphertext_modulus = value.ciphertext_modulus();
|
||||
let container = value.into_container();
|
||||
|
||||
NextSeededLwePublicKey::from_container(
|
||||
container,
|
||||
lwe_size.convert_into(),
|
||||
compression_seed.convert_into(),
|
||||
ciphertext_modulus.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_seeded_lwe_public_key() {
|
||||
use crate::core_crypto::entities::seeded_lwe_public_key::SeededLwePublicKey;
|
||||
use next_tfhe::core_crypto::entities::seeded_lwe_public_key::SeededLwePublicKey as NextSeededLwePublicKey;
|
||||
|
||||
use crate::core_crypto::commons::math::random::Seed;
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let tfhe_struct = SeededLwePublicKey::new(
|
||||
0u64,
|
||||
LweSize(101),
|
||||
LwePublicKeyZeroEncryptionCount(10),
|
||||
Seed(42).into(),
|
||||
CiphertextModulus::new_native(),
|
||||
);
|
||||
let _next_tfhe_struct: NextSeededLwePublicKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
use crate::core_crypto::fft_impl::fft128::crypto::bootstrap::Fourier128LweBootstrapKey;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
use next_tfhe::core_crypto::fft_impl::fft128::crypto::bootstrap::Fourier128LweBootstrapKey as NextFourier128LweBootstrapKey;
|
||||
|
||||
impl<C> crate::forward_compatibility::ConvertFrom<Fourier128LweBootstrapKey<C>>
|
||||
for NextFourier128LweBootstrapKey<C>
|
||||
where
|
||||
C: Container<Element = f64> + NextContainer<Element = f64>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: Fourier128LweBootstrapKey<C>) -> Self {
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let input_lwe_dimension = value.input_lwe_dimension();
|
||||
let glwe_size = value.glwe_size();
|
||||
let decomposition_base_log = value.decomposition_base_log();
|
||||
let decomposition_level_count = value.decomposition_level_count();
|
||||
|
||||
let (data_re0, data_re1, data_im0, data_im1) = value.data();
|
||||
|
||||
Self::from_container(
|
||||
data_re0,
|
||||
data_re1,
|
||||
data_im0,
|
||||
data_im1,
|
||||
polynomial_size.convert_into(),
|
||||
input_lwe_dimension.convert_into(),
|
||||
glwe_size.convert_into(),
|
||||
decomposition_base_log.convert_into(),
|
||||
decomposition_level_count.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_fourier128_lwe_bootstrap_key() {
|
||||
use crate::core_crypto::fft_impl::fft128::crypto::bootstrap::Fourier128LweBootstrapKey;
|
||||
use next_tfhe::core_crypto::fft_impl::fft128::crypto::bootstrap::Fourier128LweBootstrapKey as NextFourier128LweBootstrapKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let input_lwe_dimension = LweDimension(100);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let glwe_size = GlweSize(2);
|
||||
let decomposition_level_count = DecompositionLevelCount(1);
|
||||
let decomposition_base_log = DecompositionBaseLog(23);
|
||||
|
||||
let container_len = input_lwe_dimension.0
|
||||
* polynomial_size.to_fourier_polynomial_size().0
|
||||
* glwe_size.0
|
||||
* glwe_size.0
|
||||
* decomposition_level_count.0;
|
||||
|
||||
let data_re0 = vec![0.0f64; container_len];
|
||||
let data_re1 = vec![1.0f64; container_len];
|
||||
let data_im0 = vec![2.0f64; container_len];
|
||||
let data_im1 = vec![3.0f64; container_len];
|
||||
|
||||
let tfhe_struct = Fourier128LweBootstrapKey::from_container(
|
||||
data_re0,
|
||||
data_re1,
|
||||
data_im0,
|
||||
data_im1,
|
||||
polynomial_size,
|
||||
input_lwe_dimension,
|
||||
glwe_size,
|
||||
decomposition_base_log,
|
||||
decomposition_level_count,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextFourier128LweBootstrapKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
use crate::core_crypto::fft_impl::fft128::crypto::ggsw::Fourier128GgswCiphertext;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
use next_tfhe::core_crypto::fft_impl::fft128::crypto::ggsw::Fourier128GgswCiphertext as NextFourier128GgswCiphertext;
|
||||
|
||||
impl<C> crate::forward_compatibility::ConvertFrom<Fourier128GgswCiphertext<C>>
|
||||
for NextFourier128GgswCiphertext<C>
|
||||
where
|
||||
C: Container<Element = f64> + NextContainer<Element = f64>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: Fourier128GgswCiphertext<C>) -> Self {
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let glwe_size = value.glwe_size();
|
||||
let decomposition_base_log = value.decomposition_base_log();
|
||||
let decomposition_level_count = value.decomposition_level_count();
|
||||
|
||||
let (data_re0, data_re1, data_im0, data_im1) = value.data();
|
||||
|
||||
Self::from_container(
|
||||
data_re0,
|
||||
data_re1,
|
||||
data_im0,
|
||||
data_im1,
|
||||
polynomial_size.convert_into(),
|
||||
glwe_size.convert_into(),
|
||||
decomposition_base_log.convert_into(),
|
||||
decomposition_level_count.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_fourier128_ggsw_ciphertext() {
|
||||
use crate::core_crypto::fft_impl::fft128::crypto::ggsw::Fourier128GgswCiphertext;
|
||||
use next_tfhe::core_crypto::fft_impl::fft128::crypto::ggsw::Fourier128GgswCiphertext as NextFourier128GgswCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let glwe_size = GlweSize(2);
|
||||
let decomposition_level_count = DecompositionLevelCount(1);
|
||||
let decomposition_base_log = DecompositionBaseLog(23);
|
||||
|
||||
let container_len = polynomial_size.to_fourier_polynomial_size().0
|
||||
* glwe_size.0
|
||||
* glwe_size.0
|
||||
* decomposition_level_count.0;
|
||||
|
||||
let data_re0 = vec![0.0f64; container_len];
|
||||
let data_re1 = vec![1.0f64; container_len];
|
||||
let data_im0 = vec![2.0f64; container_len];
|
||||
let data_im1 = vec![3.0f64; container_len];
|
||||
|
||||
let tfhe_struct = Fourier128GgswCiphertext::from_container(
|
||||
data_re0,
|
||||
data_re1,
|
||||
data_im0,
|
||||
data_im1,
|
||||
polynomial_size,
|
||||
glwe_size,
|
||||
decomposition_base_log,
|
||||
decomposition_level_count,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextFourier128GgswCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod bootstrap;
|
||||
pub mod ggsw;
|
||||
@@ -0,0 +1 @@
|
||||
pub mod crypto;
|
||||
@@ -0,0 +1,83 @@
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
use crate::core_crypto::fft_impl::fft64::c64;
|
||||
use crate::core_crypto::fft_impl::fft64::crypto::bootstrap::FourierLweBootstrapKey;
|
||||
use crate::core_crypto::fft_impl::fft64::math::fft::FourierPolynomialList;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::crypto::bootstrap::FourierLweBootstrapKey as NextFourierLweBootstrapKey;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::math::fft::FourierPolynomialList as NextFourierPolynomialList;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::{c64 as NextC64, ABox as NextABox};
|
||||
|
||||
impl<C> crate::forward_compatibility::ConvertFrom<FourierLweBootstrapKey<C>>
|
||||
for NextFourierLweBootstrapKey<NextABox<[NextC64]>>
|
||||
where
|
||||
C: Container<Element = c64> + NextContainer<Element = NextC64>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: FourierLweBootstrapKey<C>) -> Self {
|
||||
let input_lwe_dimension = value.input_lwe_dimension();
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomposition_base_log = value.decomposition_base_log();
|
||||
let decomposition_level_count = value.decomposition_level_count();
|
||||
let data = value.data();
|
||||
|
||||
let poly_list = FourierPolynomialList {
|
||||
data,
|
||||
polynomial_size,
|
||||
};
|
||||
|
||||
let next_poly_list: NextFourierPolynomialList<_> = poly_list.convert_into();
|
||||
let data = next_poly_list.data;
|
||||
|
||||
Self::from_container(
|
||||
data,
|
||||
input_lwe_dimension.convert_into(),
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomposition_base_log.convert_into(),
|
||||
decomposition_level_count.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_fourier_lwe_bootstrap_key() {
|
||||
use crate::core_crypto::fft_impl::fft64::crypto::bootstrap::FourierLweBootstrapKey;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::crypto::bootstrap::FourierLweBootstrapKey as NextFourierLweBootstrapKey;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
use crate::core_crypto::fft_impl::fft64::c64;
|
||||
use aligned_vec::avec;
|
||||
|
||||
let input_lwe_dimension = LweDimension(100);
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let glwe_size = GlweSize(2);
|
||||
let decomposition_level_count = DecompositionLevelCount(1);
|
||||
let decomposition_base_log = DecompositionBaseLog(23);
|
||||
let container = avec![
|
||||
c64::new(0.0, 0.0);
|
||||
input_lwe_dimension.0
|
||||
* polynomial_size.to_fourier_polynomial_size().0
|
||||
* glwe_size.0
|
||||
* glwe_size.0
|
||||
* decomposition_level_count.0
|
||||
]
|
||||
.into_boxed_slice();
|
||||
|
||||
let tfhe_struct = FourierLweBootstrapKey::from_container(
|
||||
container,
|
||||
input_lwe_dimension,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
decomposition_base_log,
|
||||
decomposition_level_count,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextFourierLweBootstrapKey<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
use crate::core_crypto::fft_impl::fft64::c64;
|
||||
use crate::core_crypto::fft_impl::fft64::crypto::ggsw::FourierGgswCiphertext;
|
||||
use crate::core_crypto::fft_impl::fft64::math::fft::FourierPolynomialList;
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use next_tfhe::core_crypto::commons::traits::Container as NextContainer;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::crypto::ggsw::FourierGgswCiphertext as NextFourierGgswCiphertext;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::math::fft::FourierPolynomialList as NextFourierPolynomialList;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::{c64 as NextC64, ABox as NextABox};
|
||||
|
||||
impl<C> crate::forward_compatibility::ConvertFrom<FourierGgswCiphertext<C>>
|
||||
for NextFourierGgswCiphertext<NextABox<[NextC64]>>
|
||||
where
|
||||
C: Container<Element = c64> + NextContainer<Element = NextC64>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: FourierGgswCiphertext<C>) -> Self {
|
||||
let glwe_size = value.glwe_size();
|
||||
let polynomial_size = value.polynomial_size();
|
||||
let decomposition_base_log = value.decomposition_base_log();
|
||||
let decomposition_level_count = value.decomposition_level_count();
|
||||
let data = value.data();
|
||||
|
||||
let poly_list = FourierPolynomialList {
|
||||
data,
|
||||
polynomial_size,
|
||||
};
|
||||
|
||||
let next_poly_list: NextFourierPolynomialList<_> = poly_list.convert_into();
|
||||
let data = next_poly_list.data;
|
||||
|
||||
Self::from_container(
|
||||
data,
|
||||
glwe_size.convert_into(),
|
||||
polynomial_size.convert_into(),
|
||||
decomposition_base_log.convert_into(),
|
||||
decomposition_level_count.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_fourier_ggsw_ciphertext() {
|
||||
use crate::core_crypto::fft_impl::fft64::crypto::ggsw::FourierGgswCiphertext;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::crypto::ggsw::FourierGgswCiphertext as NextFourierGgswCiphertext;
|
||||
|
||||
use crate::core_crypto::commons::parameters::*;
|
||||
use crate::core_crypto::fft_impl::fft64::c64;
|
||||
use aligned_vec::avec;
|
||||
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
let glwe_size = GlweSize(2);
|
||||
let decomposition_level_count = DecompositionLevelCount(1);
|
||||
let decomposition_base_log = DecompositionBaseLog(23);
|
||||
let container = avec![
|
||||
c64::new(0.0, 0.0);
|
||||
polynomial_size.to_fourier_polynomial_size().0
|
||||
* glwe_size.0
|
||||
* glwe_size.0
|
||||
* decomposition_level_count.0
|
||||
]
|
||||
.into_boxed_slice();
|
||||
|
||||
let tfhe_struct = FourierGgswCiphertext::from_container(
|
||||
container,
|
||||
glwe_size,
|
||||
polynomial_size,
|
||||
decomposition_base_log,
|
||||
decomposition_level_count,
|
||||
);
|
||||
|
||||
let _next_tfhe_struct: NextFourierGgswCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod bootstrap;
|
||||
pub mod ggsw;
|
||||
@@ -0,0 +1,48 @@
|
||||
use crate::core_crypto::commons::traits::Container;
|
||||
use crate::core_crypto::fft_impl::fft64::c64;
|
||||
use crate::core_crypto::fft_impl::fft64::math::fft::FourierPolynomialList;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::math::fft::FourierPolynomialList as NextFourierPolynomialList;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::{c64 as NextC64, ABox as NextABox};
|
||||
|
||||
impl<C> crate::forward_compatibility::ConvertFrom<FourierPolynomialList<C>>
|
||||
for NextFourierPolynomialList<NextABox<[NextC64]>>
|
||||
where
|
||||
C: Container<Element = c64>,
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: FourierPolynomialList<C>) -> Self {
|
||||
// As fft plans are unique per TFHE-rs instance, we need to convert to a common format then
|
||||
// convert back, for now we go through serialization, otherwise coefficients will be
|
||||
// completely in the wrong order
|
||||
let serialized = bincode::serialize(&value).unwrap();
|
||||
drop(value);
|
||||
|
||||
bincode::deserialize(&serialized).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_fourier_polynomial_list() {
|
||||
use crate::core_crypto::commons::parameters::PolynomialSize;
|
||||
use crate::core_crypto::fft_impl::fft64::c64;
|
||||
use crate::core_crypto::fft_impl::fft64::math::fft::FourierPolynomialList;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::math::fft::FourierPolynomialList as NextFourierPolynomialList;
|
||||
use next_tfhe::core_crypto::fft_impl::fft64::{c64 as NextC64, ABox as NextABox};
|
||||
|
||||
let polynomial_size = PolynomialSize(2048);
|
||||
|
||||
let tfhe_struct = FourierPolynomialList {
|
||||
data: vec![c64::new(0.0, 0.0); polynomial_size.0],
|
||||
polynomial_size,
|
||||
};
|
||||
|
||||
let next_tfhe_struct: NextFourierPolynomialList<NextABox<[NextC64]>> =
|
||||
tfhe_struct.convert_into();
|
||||
|
||||
assert_eq!(next_tfhe_struct.polynomial_size.0, polynomial_size.0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod fft;
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod crypto;
|
||||
pub mod math;
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod fft128;
|
||||
pub mod fft64;
|
||||
3
tfhe/src/forward_compatibility/core_crypto/mod.rs
Normal file
3
tfhe/src/forward_compatibility/core_crypto/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod commons;
|
||||
pub mod entities;
|
||||
pub mod fft_impl;
|
||||
350
tfhe/src/forward_compatibility/high_level_api/mod.rs
Normal file
350
tfhe/src/forward_compatibility/high_level_api/mod.rs
Normal file
@@ -0,0 +1,350 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::high_level_api::ClientKey;
|
||||
use next_tfhe::ClientKey as NextClientKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<ClientKey> for NextClientKey {
|
||||
#[inline]
|
||||
fn convert_from(value: ClientKey) -> Self {
|
||||
let ClientKey { integer_key, .. } = value;
|
||||
|
||||
let crate::high_level_api::integers::keys::IntegerClientKey {
|
||||
key,
|
||||
wopbs_block_parameters,
|
||||
} = integer_key;
|
||||
Self::from_raw_parts(
|
||||
key.expect(
|
||||
"No tfhe 0.4 integer client key in tfhe::high_level_api::ClientKey, \
|
||||
unable to convert to tfhe 0.5",
|
||||
)
|
||||
.convert_into(),
|
||||
wopbs_block_parameters.map(|p| p.convert_into()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::high_level_api::CompactPublicKey;
|
||||
use next_tfhe::CompactPublicKey as NextCompactPublicKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CompactPublicKey> for NextCompactPublicKey {
|
||||
#[inline]
|
||||
fn convert_from(value: CompactPublicKey) -> Self {
|
||||
let integer_key = value
|
||||
.into_raw_parts()
|
||||
.expect("Conversion requires an integer public key in the input CompactPublicKey");
|
||||
|
||||
Self::from_raw_parts(integer_key.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
use crate::high_level_api::CompressedCompactPublicKey;
|
||||
use next_tfhe::CompressedCompactPublicKey as NextCompressedCompactPublicKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CompressedCompactPublicKey>
|
||||
for NextCompressedCompactPublicKey
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: CompressedCompactPublicKey) -> Self {
|
||||
let key = value.into_raw_parts().expect(
|
||||
"Conversion requires an integer public key in the input CompressedCompactPublicKey",
|
||||
);
|
||||
|
||||
Self::from_raw_parts(key.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
use crate::high_level_api::CompressedPublicKey;
|
||||
use next_tfhe::CompressedPublicKey as NextCompressedPublicKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CompressedPublicKey> for NextCompressedPublicKey {
|
||||
#[inline]
|
||||
fn convert_from(value: CompressedPublicKey) -> Self {
|
||||
let base_integer_key = value
|
||||
.base_integer_key()
|
||||
.expect("Conversion requires an integer public key in the input CompressedPublicKey")
|
||||
.to_owned();
|
||||
|
||||
Self::from_raw_parts(base_integer_key.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
use crate::high_level_api::CompressedServerKey;
|
||||
use next_tfhe::CompressedServerKey as NextCompressedServerKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CompressedServerKey> for NextCompressedServerKey {
|
||||
#[inline]
|
||||
fn convert_from(value: CompressedServerKey) -> Self {
|
||||
let CompressedServerKey { integer_key, .. } = value;
|
||||
|
||||
let key = integer_key.key.expect(
|
||||
"Conversion requires an integer compressed server key \
|
||||
in the input CompressedServerKey",
|
||||
);
|
||||
|
||||
Self::from_raw_parts(key.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
use crate::high_level_api::PublicKey;
|
||||
use next_tfhe::PublicKey as NextPublicKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<PublicKey> for NextPublicKey {
|
||||
#[inline]
|
||||
fn convert_from(value: PublicKey) -> Self {
|
||||
let base_integer_key = value
|
||||
.base_integer_key()
|
||||
.expect("Conversion requires an integer public key in the input PublicKey")
|
||||
.to_owned();
|
||||
|
||||
Self::from_raw_parts(base_integer_key.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
use crate::high_level_api::ServerKey;
|
||||
use next_tfhe::ServerKey as NextServerKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<ServerKey> for NextServerKey {
|
||||
#[inline]
|
||||
fn convert_from(value: ServerKey) -> Self {
|
||||
let ServerKey { integer_key, .. } = value;
|
||||
|
||||
let crate::high_level_api::integers::keys::IntegerServerKey { key, wopbs_key } =
|
||||
(*integer_key).clone();
|
||||
|
||||
let key = key
|
||||
.expect("Conversion requires an integer server key in the input ServerKey")
|
||||
.to_owned();
|
||||
|
||||
Self::from_raw_parts(key.convert_into(), wopbs_key.map(|k| k.convert_into()))
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_convert_from_uint_hl_type {
|
||||
($($num_bits: literal),* $(,)?) => {
|
||||
$(
|
||||
::paste::paste! {
|
||||
impl_convert_from_uint_hl_type!(
|
||||
[<CompactFheUint $num_bits>] {
|
||||
[<FheUint $num_bits Id>]
|
||||
}
|
||||
);
|
||||
impl_convert_from_uint_hl_type!(
|
||||
[<CompactFheUint $num_bits List>] {
|
||||
[<FheUint $num_bits Id>]
|
||||
}
|
||||
);
|
||||
impl_convert_from_uint_hl_type!(
|
||||
[<FheUint $num_bits>] {
|
||||
[<FheUint $num_bits Id>]
|
||||
}
|
||||
);
|
||||
impl_convert_from_uint_hl_type!(
|
||||
[<CompressedFheUint $num_bits>] {
|
||||
[<FheUint $num_bits Id>]
|
||||
}
|
||||
);
|
||||
}
|
||||
)*
|
||||
};
|
||||
($old_ty: ident { $old_id: ident } ) => {
|
||||
impl crate::forward_compatibility::ConvertFrom<crate::high_level_api::$old_ty>
|
||||
for next_tfhe::$old_ty
|
||||
{
|
||||
fn convert_from(value: crate::high_level_api::$old_ty) -> Self {
|
||||
let (inner, _id) = value.into_raw_parts();
|
||||
|
||||
Self::from_raw_parts(inner.convert_into(), next_tfhe::$old_id)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_convert_from_uint_hl_type!(8, 10, 12, 14, 16, 32, 64, 128, 256);
|
||||
|
||||
macro_rules! impl_convert_from_int_hl_type {
|
||||
($($num_bits: literal),* $(,)?) => {
|
||||
$(
|
||||
::paste::paste! {
|
||||
impl_convert_from_int_hl_type!(
|
||||
[<CompactFheInt $num_bits>] {
|
||||
[<FheInt $num_bits Id>]
|
||||
}
|
||||
);
|
||||
impl_convert_from_int_hl_type!(
|
||||
[<CompactFheInt $num_bits List>] {
|
||||
[<FheInt $num_bits Id>]
|
||||
}
|
||||
);
|
||||
impl_convert_from_int_hl_type!(
|
||||
[<FheInt $num_bits>] {
|
||||
[<FheInt $num_bits Id>]
|
||||
}
|
||||
);
|
||||
impl_convert_from_int_hl_type!(
|
||||
[<CompressedFheInt $num_bits>] {
|
||||
[<FheInt $num_bits Id>]
|
||||
}
|
||||
);
|
||||
}
|
||||
)*
|
||||
};
|
||||
($old_ty: ident { $old_id: ident } ) => {
|
||||
impl crate::forward_compatibility::ConvertFrom<crate::high_level_api::$old_ty>
|
||||
for next_tfhe::$old_ty
|
||||
{
|
||||
fn convert_from(value: crate::high_level_api::$old_ty) -> Self {
|
||||
let (inner, _id) = value.into_raw_parts();
|
||||
|
||||
Self::from_raw_parts(inner.convert_into(), next_tfhe::$old_id)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_convert_from_int_hl_type!(8, 16, 32, 64, 128, 256);
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_client_key() {
|
||||
use crate::{ClientKey, ConfigBuilder};
|
||||
use next_tfhe::ClientKey as NextClientKey;
|
||||
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers();
|
||||
let tfhe_struct = ClientKey::generate(config);
|
||||
|
||||
let _next_tfhe_struct: NextClientKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_compact_public_key() {
|
||||
use crate::{ClientKey, CompactPublicKey, ConfigBuilder};
|
||||
use next_tfhe::CompactPublicKey as NextCompactPublicKey;
|
||||
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers();
|
||||
let cks = ClientKey::generate(config);
|
||||
|
||||
let tfhe_struct = CompactPublicKey::new(&cks);
|
||||
let _next_tfhe_struct: NextCompactPublicKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_compressed_compact_public_key() {
|
||||
use crate::{ClientKey, CompressedCompactPublicKey, ConfigBuilder};
|
||||
use next_tfhe::CompressedCompactPublicKey as NextCompressedCompactPublicKey;
|
||||
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers();
|
||||
let cks = ClientKey::generate(config);
|
||||
|
||||
let tfhe_struct = CompressedCompactPublicKey::new(&cks);
|
||||
let _next_tfhe_struct: NextCompressedCompactPublicKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_compressed_public_key() {
|
||||
use crate::{ClientKey, CompressedPublicKey, ConfigBuilder};
|
||||
use next_tfhe::CompressedPublicKey as NextCompressedPublicKey;
|
||||
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers();
|
||||
let cks = ClientKey::generate(config);
|
||||
|
||||
let tfhe_struct = CompressedPublicKey::new(&cks);
|
||||
let _next_tfhe_struct: NextCompressedPublicKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_compressed_server_key() {
|
||||
use crate::{ClientKey, CompressedServerKey, ConfigBuilder};
|
||||
use next_tfhe::CompressedServerKey as NextCompressedServerKey;
|
||||
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers();
|
||||
let cks = ClientKey::generate(config);
|
||||
|
||||
let tfhe_struct = CompressedServerKey::new(&cks);
|
||||
let _next_tfhe_struct: NextCompressedServerKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_public_key() {
|
||||
use crate::{ClientKey, ConfigBuilder, PublicKey};
|
||||
use next_tfhe::PublicKey as NextPublicKey;
|
||||
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers();
|
||||
let cks = ClientKey::generate(config);
|
||||
|
||||
let tfhe_struct = PublicKey::new(&cks);
|
||||
let _next_tfhe_struct: NextPublicKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_server_key() {
|
||||
use crate::{ClientKey, ConfigBuilder, ServerKey};
|
||||
use next_tfhe::ServerKey as NextServerKey;
|
||||
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers();
|
||||
let cks = ClientKey::generate(config);
|
||||
|
||||
let tfhe_struct = ServerKey::new(&cks);
|
||||
let _next_tfhe_struct: NextServerKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_ciphertexts() {
|
||||
use crate::prelude::*;
|
||||
use crate::*;
|
||||
use next_tfhe::{
|
||||
CompactFheInt64 as NextCompactFheInt64, CompactFheInt64List as NextCompactFheInt64List,
|
||||
CompactFheUint64 as NextCompactFheUint64,
|
||||
CompactFheUint64List as NextCompactFheUint64List,
|
||||
CompressedFheInt64 as NextCompressedFheInt64,
|
||||
CompressedFheUint64 as NextCompressedFheUint64, FheInt64 as NextFheInt64,
|
||||
FheUint64 as NextFheUint64,
|
||||
};
|
||||
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers();
|
||||
let cks = ClientKey::generate(config);
|
||||
let cpk = CompactPublicKey::new(&cks);
|
||||
|
||||
{
|
||||
let tfhe_struct = FheUint64::encrypt(42u64, &cks);
|
||||
let _next_tfhe_struct: NextFheUint64 = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
{
|
||||
let tfhe_struct = FheInt64::encrypt(-42i64, &cks);
|
||||
let _next_tfhe_struct: NextFheInt64 = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
{
|
||||
let tfhe_struct = CompressedFheUint64::encrypt(42u64, &cks);
|
||||
let _next_tfhe_struct: NextCompressedFheUint64 = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
{
|
||||
let tfhe_struct = CompressedFheInt64::encrypt(-42i64, &cks);
|
||||
let _next_tfhe_struct: NextCompressedFheInt64 = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
{
|
||||
let tfhe_struct = CompactFheUint64::encrypt(42u64, &cpk);
|
||||
let _next_tfhe_struct: NextCompactFheUint64 = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
{
|
||||
let tfhe_struct = CompactFheInt64::encrypt(-42i64, &cpk);
|
||||
let _next_tfhe_struct: NextCompactFheInt64 = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
{
|
||||
let tfhe_struct = CompactFheUint64List::encrypt(&[42u64], &cpk);
|
||||
let _next_tfhe_struct: NextCompactFheUint64List = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
{
|
||||
let tfhe_struct = CompactFheInt64List::encrypt(&[-42i64], &cpk);
|
||||
let _next_tfhe_struct: NextCompactFheInt64List = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
}
|
||||
189
tfhe/src/forward_compatibility/integer/ciphertext/mod.rs
Normal file
189
tfhe/src/forward_compatibility/integer/ciphertext/mod.rs
Normal file
@@ -0,0 +1,189 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
use crate::integer::ciphertext::IntegerCiphertext;
|
||||
use crate::shortint::{Ciphertext, CompressedCiphertext};
|
||||
use next_tfhe::shortint::{
|
||||
Ciphertext as NextCiphertext, CompressedCiphertext as NextCompressedCiphertext,
|
||||
};
|
||||
|
||||
use crate::integer::ciphertext::BaseRadixCiphertext;
|
||||
use next_tfhe::integer::ciphertext::BaseRadixCiphertext as NextBaseRadixCiphertext;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<BaseRadixCiphertext<Ciphertext>>
|
||||
for NextBaseRadixCiphertext<NextCiphertext>
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: BaseRadixCiphertext<Ciphertext>) -> Self {
|
||||
let blocks: Vec<NextCiphertext> = value
|
||||
.blocks()
|
||||
.iter()
|
||||
.map(|block| block.clone().convert_into())
|
||||
.collect();
|
||||
blocks.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<BaseRadixCiphertext<CompressedCiphertext>>
|
||||
for NextBaseRadixCiphertext<NextCompressedCiphertext>
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: BaseRadixCiphertext<CompressedCiphertext>) -> Self {
|
||||
let blocks: Vec<NextCompressedCiphertext> = value
|
||||
.blocks
|
||||
.into_iter()
|
||||
.map(|block| block.convert_into())
|
||||
.collect();
|
||||
blocks.into()
|
||||
}
|
||||
}
|
||||
|
||||
use crate::integer::ciphertext::CompactCiphertextList;
|
||||
use next_tfhe::integer::ciphertext::CompactCiphertextList as NextCompactCiphertextList;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CompactCiphertextList>
|
||||
for NextCompactCiphertextList
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: CompactCiphertextList) -> Self {
|
||||
let CompactCiphertextList {
|
||||
ct_list,
|
||||
num_blocks_per_integer,
|
||||
} = value;
|
||||
|
||||
Self::from_raw_parts(
|
||||
ct_list.convert_into(),
|
||||
num_blocks_per_integer.convert_into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
use crate::integer::ciphertext::BaseSignedRadixCiphertext;
|
||||
use next_tfhe::integer::ciphertext::BaseSignedRadixCiphertext as NextBaseSignedRadixCiphertext;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<BaseSignedRadixCiphertext<Ciphertext>>
|
||||
for NextBaseSignedRadixCiphertext<NextCiphertext>
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: BaseSignedRadixCiphertext<Ciphertext>) -> Self {
|
||||
let blocks: Vec<NextCiphertext> = value
|
||||
.blocks()
|
||||
.iter()
|
||||
.map(|block| block.clone().convert_into())
|
||||
.collect();
|
||||
blocks.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<BaseSignedRadixCiphertext<CompressedCiphertext>>
|
||||
for NextBaseSignedRadixCiphertext<NextCompressedCiphertext>
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: BaseSignedRadixCiphertext<CompressedCiphertext>) -> Self {
|
||||
let blocks: Vec<NextCompressedCiphertext> = value
|
||||
.blocks
|
||||
.into_iter()
|
||||
.map(|block| block.convert_into())
|
||||
.collect();
|
||||
blocks.into()
|
||||
}
|
||||
}
|
||||
|
||||
use crate::integer::ciphertext::BaseCrtCiphertext;
|
||||
use next_tfhe::integer::ciphertext::BaseCrtCiphertext as NextBaseCrtCiphertext;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<BaseCrtCiphertext<Ciphertext>>
|
||||
for NextBaseCrtCiphertext<Ciphertext>
|
||||
{
|
||||
#[inline]
|
||||
fn convert_from(value: BaseCrtCiphertext<Ciphertext>) -> Self {
|
||||
let moduli = value.moduli();
|
||||
let blocks = value.blocks().to_vec();
|
||||
|
||||
(blocks, moduli).into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_base_radix_ciphertext() {
|
||||
use next_tfhe::integer::ciphertext::BaseRadixCiphertext as NextBaseRadixCiphertext;
|
||||
|
||||
use crate::integer::gen_keys_radix;
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
let (cks, _sks) = gen_keys_radix(PARAM_MESSAGE_2_CARRY_2_KS_PBS, 4);
|
||||
let tfhe_struct = cks.encrypt(42u64);
|
||||
let _next_tfhe_struct: NextBaseRadixCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_base_compressed_radix_ciphertext() {
|
||||
use next_tfhe::integer::ciphertext::BaseRadixCiphertext as NextBaseRadixCiphertext;
|
||||
|
||||
use crate::integer::{gen_keys_radix, CompressedPublicKey};
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
let (cks, _sks) = gen_keys_radix(PARAM_MESSAGE_2_CARRY_2_KS_PBS, 4);
|
||||
let cpk = CompressedPublicKey::new(&cks);
|
||||
let tfhe_struct = cpk.encrypt_radix(42u64, 4);
|
||||
let _next_tfhe_struct: NextBaseRadixCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_compact_ciphertext_list() {
|
||||
use next_tfhe::integer::ciphertext::CompactCiphertextList as NextCompactCiphertextList;
|
||||
|
||||
use crate::integer::gen_keys_radix;
|
||||
use crate::integer::public_key::CompactPublicKey;
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS;
|
||||
|
||||
let (cks, _sks) = gen_keys_radix(PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS, 4);
|
||||
let cpk = CompactPublicKey::new(cks.as_ref());
|
||||
|
||||
let tfhe_struct = cpk.encrypt_radix_compact(42u64, 4);
|
||||
let _next_tfhe_struct: NextCompactCiphertextList = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_base_signed_radix_ciphertext() {
|
||||
use next_tfhe::integer::ciphertext::BaseSignedRadixCiphertext as NextBaseSignedRadixCiphertext;
|
||||
|
||||
use crate::integer::gen_keys_radix;
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
let (cks, _sks) = gen_keys_radix(PARAM_MESSAGE_2_CARRY_2_KS_PBS, 4);
|
||||
let tfhe_struct = cks.encrypt_signed(-42i64);
|
||||
let _next_tfhe_struct: NextBaseSignedRadixCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_base_signed_compressed_radix_ciphertext() {
|
||||
use next_tfhe::integer::ciphertext::BaseSignedRadixCiphertext as NextBaseSignedRadixCiphertext;
|
||||
|
||||
use crate::integer::{gen_keys_radix, CompressedPublicKey};
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
let (cks, _sks) = gen_keys_radix(PARAM_MESSAGE_2_CARRY_2_KS_PBS, 4);
|
||||
let cpk = CompressedPublicKey::new(&cks);
|
||||
let tfhe_struct = cpk.encrypt_signed_radix(-42i64, 4);
|
||||
let _next_tfhe_struct: NextBaseSignedRadixCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_base_crt_ciphertext() {
|
||||
use next_tfhe::integer::ciphertext::BaseCrtCiphertext as NextBaseCrtCiphertext;
|
||||
|
||||
use crate::integer::gen_keys_crt;
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
let (cks, _sks) = gen_keys_crt(
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||
vec![3u64, 11, 13, 19, 23, 29, 31, 32],
|
||||
);
|
||||
|
||||
let tfhe_struct = cks.encrypt(32);
|
||||
let _next_tfhe_struct: NextBaseCrtCiphertext<_> = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
77
tfhe/src/forward_compatibility/integer/client_key/mod.rs
Normal file
77
tfhe/src/forward_compatibility/integer/client_key/mod.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
use crate::integer::client_key::CrtClientKey;
|
||||
use next_tfhe::integer::client_key::CrtClientKey as NextCrtClientKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<CrtClientKey> for NextCrtClientKey {
|
||||
#[inline]
|
||||
fn convert_from(value: CrtClientKey) -> Self {
|
||||
let key = value.as_ref().to_owned();
|
||||
let moduli = value.moduli().to_vec();
|
||||
|
||||
Self::from((key.convert_into(), moduli))
|
||||
}
|
||||
}
|
||||
|
||||
use crate::integer::client_key::RadixClientKey;
|
||||
use next_tfhe::integer::client_key::RadixClientKey as NextRadixClientKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<RadixClientKey> for NextRadixClientKey {
|
||||
#[inline]
|
||||
fn convert_from(value: RadixClientKey) -> Self {
|
||||
let key = value.as_ref().to_owned();
|
||||
let num_blocks = value.num_blocks();
|
||||
|
||||
Self::from((key.convert_into(), num_blocks))
|
||||
}
|
||||
}
|
||||
|
||||
use crate::integer::client_key::ClientKey;
|
||||
use next_tfhe::integer::client_key::ClientKey as NextClientKey;
|
||||
|
||||
impl crate::forward_compatibility::ConvertFrom<ClientKey> for NextClientKey {
|
||||
#[inline]
|
||||
fn convert_from(value: ClientKey) -> Self {
|
||||
let ClientKey { key } = value;
|
||||
|
||||
Self::from_raw_parts(key.convert_into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::forward_compatibility::ConvertInto;
|
||||
|
||||
#[test]
|
||||
fn test_conversion_crt_client_key() {
|
||||
use crate::integer::client_key::CrtClientKey;
|
||||
use next_tfhe::integer::client_key::CrtClientKey as NextCrtClientKey;
|
||||
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
let tfhe_struct = CrtClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS, vec![2u64, 3u64]);
|
||||
let _next_tfhe_struct: NextCrtClientKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_radix_client_key() {
|
||||
use crate::integer::client_key::RadixClientKey;
|
||||
use next_tfhe::integer::client_key::RadixClientKey as NextRadixClientKey;
|
||||
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
let tfhe_struct = RadixClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS, 32);
|
||||
let _next_tfhe_struct: NextRadixClientKey = tfhe_struct.convert_into();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conversion_client_key() {
|
||||
use crate::integer::client_key::ClientKey;
|
||||
use next_tfhe::integer::client_key::ClientKey as NextClientKey;
|
||||
|
||||
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
|
||||
|
||||
let tfhe_struct = ClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS);
|
||||
let _next_tfhe_struct: NextClientKey = tfhe_struct.convert_into();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user