diff --git a/Makefile b/Makefile index 06ae49b098..4354809dc2 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ SHELL:=$(shell /usr/bin/env which bash) OS:=$(shell uname) RS_CHECK_TOOLCHAIN:=$(shell cat toolchain.txt | tr -d '\n') CARGO_RS_CHECK_TOOLCHAIN:=+$(RS_CHECK_TOOLCHAIN) -TARGET_ARCH_FEATURE:=$(shell ./scripts/get_arch_feature.sh) CPU_COUNT=$(shell ./scripts/cpu_count.sh) RS_BUILD_TOOLCHAIN:=stable CARGO_RS_BUILD_TOOLCHAIN:=+$(RS_BUILD_TOOLCHAIN) @@ -282,14 +281,14 @@ check_typos: install_typos_checker .PHONY: clippy_gpu # Run clippy lints on tfhe with "gpu" enabled clippy_gpu: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,gpu \ + --features=boolean,shortint,integer,internal-keycache,gpu \ --all-targets \ -p $(TFHE_SPEC) -- --no-deps -D warnings .PHONY: check_gpu # Run check on tfhe with "gpu" enabled check_gpu: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" check \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,gpu \ + --features=boolean,shortint,integer,internal-keycache,gpu \ --all-targets \ -p $(TFHE_SPEC) @@ -308,52 +307,51 @@ lint_workflow: check_actionlint_installed .PHONY: clippy_core # Run clippy lints on core_crypto with and without experimental features clippy_core: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=$(TARGET_ARCH_FEATURE) \ -p $(TFHE_SPEC) -- --no-deps -D warnings RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=$(TARGET_ARCH_FEATURE),experimental \ + --features=experimental \ -p $(TFHE_SPEC) -- --no-deps -D warnings RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=$(TARGET_ARCH_FEATURE),nightly-avx512 \ + --features=nightly-avx512 \ -p $(TFHE_SPEC) -- --no-deps -D warnings RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=$(TARGET_ARCH_FEATURE),experimental,nightly-avx512 \ + --features=experimental,nightly-avx512 \ -p $(TFHE_SPEC) -- --no-deps -D warnings RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=$(TARGET_ARCH_FEATURE),zk-pok \ + --features=zk-pok \ -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 \ + --features=boolean \ -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 \ + --features=shortint \ -p $(TFHE_SPEC) -- --no-deps -D warnings RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=$(TARGET_ARCH_FEATURE),shortint,experimental \ + --features=shortint,experimental \ -p $(TFHE_SPEC) -- --no-deps -D warnings RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=$(TARGET_ARCH_FEATURE),zk-pok,shortint \ + --features=zk-pok,shortint \ -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 \ + --features=integer \ -p $(TFHE_SPEC) -- --no-deps -D warnings RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=$(TARGET_ARCH_FEATURE),integer,experimental \ + --features=integer,experimental \ -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 \ + --features=boolean,shortint,integer \ -p $(TFHE_SPEC) -- --no-deps -D warnings .PHONY: clippy_rustdoc # Run clippy lints on doctests enabling the boolean, shortint, integer and zk-pok @@ -364,13 +362,13 @@ clippy_rustdoc: install_rs_check_toolchain fi && \ CLIPPYFLAGS="-D warnings" RUSTDOCFLAGS="--no-run --nocapture --test-builder ./scripts/clippy_driver.sh -Z unstable-options" \ cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" test --doc \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,zk-pok,pbs-stats,strings \ + --features=boolean,shortint,integer,zk-pok,pbs-stats,strings \ -p $(TFHE_SPEC) .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,high-level-c-api \ + --features=boolean-c-api,shortint-c-api,high-level-c-api \ -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 @@ -395,17 +393,16 @@ clippy_trivium: install_rs_check_toolchain .PHONY: clippy_all_targets # Run clippy lints on all targets (benches, examples, etc.) 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,zk-pok,strings \ + --features=boolean,shortint,integer,internal-keycache,zk-pok,strings \ -p $(TFHE_SPEC) -- --no-deps -D warnings RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,zk-pok,strings,experimental \ + --features=boolean,shortint,integer,internal-keycache,zk-pok,strings,experimental \ -p $(TFHE_SPEC) -- --no-deps -D warnings .PHONY: clippy_tfhe_csprng # Run clippy lints on tfhe-csprng clippy_tfhe_csprng: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \ - --features=$(TARGET_ARCH_FEATURE) \ - -p tfhe-csprng -- --no-deps -D warnings + --features=parallel,software-prng -p tfhe-csprng -- --no-deps -D warnings .PHONY: clippy_zk_pok # Run clippy lints on tfhe-zk-pok clippy_zk_pok: install_rs_check_toolchain @@ -444,67 +441,67 @@ check_rust_bindings_did_not_change: .PHONY: tfhe_lints # Run custom tfhe-rs lints tfhe_lints: install_tfhe_lints cd tfhe && RUSTFLAGS="$(RUSTFLAGS)" cargo tfhe-lints \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,zk-pok -- -D warnings + --features=boolean,shortint,integer,zk-pok -- -D warnings .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_SPEC) + -p $(TFHE_SPEC) @if [[ "$(AVX512_SUPPORT)" == "ON" ]]; then \ RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) build --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),nightly-avx512 -p $(TFHE_SPEC); \ + --features=nightly-avx512 -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_SPEC) + --features=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,nightly-avx512 -p $(TFHE_SPEC); \ + --features=experimental,nightly-avx512 -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_SPEC) --all-targets + --features=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_SPEC) --all-targets + --features=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_SPEC) --all-targets + --features=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_SPEC) --all-targets + --features=boolean,shortint,integer -p $(TFHE_SPEC) --all-targets .PHONY: build_tfhe_coverage # Build with test coverage enabled build_tfhe_coverage: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS) --cfg tarpaulin" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache -p $(TFHE_SPEC) --tests + --features=boolean,shortint,integer,internal-keycache -p $(TFHE_SPEC) --tests .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,zk-pok \ + --features=boolean-c-api,shortint-c-api,high-level-c-api,zk-pok \ -p $(TFHE_SPEC) .PHONY: build_c_api_gpu # Build the C API for boolean, shortint and integer build_c_api_gpu: 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,zk-pok,gpu \ + --features=boolean-c-api,shortint-c-api,high-level-c-api,zk-pok,gpu \ -p $(TFHE_SPEC) .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,zk-pok,experimental-force_fft_algo_dif4 \ + --features=boolean-c-api,shortint-c-api,high-level-c-api,zk-pok,experimental-force_fft_algo_dif4 \ -p $(TFHE_SPEC) .PHONY: build_web_js_api # Build the js API targeting the web browser @@ -535,15 +532,15 @@ build_node_js_api: install_rs_build_toolchain install_wasm_pack .PHONY: build_tfhe_csprng # Build tfhe_csprng build_tfhe_csprng: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE) -p tfhe-csprng --all-targets + -p tfhe-csprng --all-targets .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,zk-pok -p $(TFHE_SPEC) -- core_crypto:: + --features=experimental,zk-pok -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,zk-pok,nightly-avx512 -p $(TFHE_SPEC) -- core_crypto::; \ + --features=experimental,zk-pok,nightly-avx512 -p $(TFHE_SPEC) -- core_crypto::; \ fi .PHONY: test_core_crypto_cov # Run the tests of the core_crypto module with code coverage @@ -551,13 +548,13 @@ test_core_crypto_cov: install_rs_build_toolchain install_rs_check_toolchain inst RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) tarpaulin --profile $(CARGO_PROFILE) \ --out xml --output-dir coverage/core_crypto --line --engine llvm --timeout 500 \ --implicit-test-threads $(COVERAGE_EXCLUDED_FILES) \ - --features=$(TARGET_ARCH_FEATURE),experimental,internal-keycache \ + --features=experimental,internal-keycache \ -p $(TFHE_SPEC) -- core_crypto:: @if [[ "$(AVX512_SUPPORT)" == "ON" ]]; then \ RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) tarpaulin --profile $(CARGO_PROFILE) \ --out xml --output-dir coverage/core_crypto_avx512 --line --engine llvm --timeout 500 \ --implicit-test-threads $(COVERAGE_EXCLUDED_FILES) \ - --features=$(TARGET_ARCH_FEATURE),experimental,internal-keycache,nightly-avx512 \ + --features=experimental,internal-keycache,nightly-avx512 \ -p $(TFHE_SPEC) -- -Z unstable-options --report-time core_crypto::; \ fi @@ -575,35 +572,35 @@ test_gpu: test_core_crypto_gpu test_integer_gpu test_cuda_backend .PHONY: test_core_crypto_gpu # Run the tests of the core_crypto module including experimental on the gpu backend test_core_crypto_gpu: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),gpu -p $(TFHE_SPEC) -- core_crypto::gpu:: + --features=gpu -p $(TFHE_SPEC) -- core_crypto::gpu:: RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --doc --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),gpu -p $(TFHE_SPEC) -- core_crypto::gpu:: + --features=gpu -p $(TFHE_SPEC) -- core_crypto::gpu:: .PHONY: test_integer_gpu # Run the tests of the integer module including experimental on the gpu backend test_integer_gpu: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),integer,gpu -p $(TFHE_SPEC) -- integer::gpu::server_key:: --test-threads=6 + --features=integer,gpu -p $(TFHE_SPEC) -- integer::gpu::server_key:: --test-threads=6 RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --doc --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),integer,gpu -p $(TFHE_SPEC) -- integer::gpu::server_key:: + --features=integer,gpu -p $(TFHE_SPEC) -- integer::gpu::server_key:: .PHONY: test_integer_long_run_gpu # Run the tests of the integer module including experimental on the gpu backend test_integer_long_run_gpu: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),integer,gpu,__long_run_tests -p $(TFHE_SPEC) -- integer::gpu::server_key::radix::tests_long_run --test-threads=6 + --features=integer,gpu,__long_run_tests -p $(TFHE_SPEC) -- integer::gpu::server_key::radix::tests_long_run --test-threads=6 .PHONY: test_integer_compression test_integer_compression: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),integer -p $(TFHE_SPEC) -- integer::ciphertext::compressed_ciphertext_list::tests:: + --features=integer -p $(TFHE_SPEC) -- integer::ciphertext::compressed_ciphertext_list::tests:: RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --doc --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),integer -p $(TFHE_SPEC) -- integer::ciphertext::compress + --features=integer -p $(TFHE_SPEC) -- integer::ciphertext::compress .PHONY: test_integer_compression_gpu test_integer_compression_gpu: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),integer,gpu -p $(TFHE_SPEC) -- integer::gpu::ciphertext::compressed_ciphertext_list::tests:: + --features=integer,gpu -p $(TFHE_SPEC) -- integer::gpu::ciphertext::compressed_ciphertext_list::tests:: RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --doc --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),integer,gpu -p $(TFHE_SPEC) -- integer::gpu::ciphertext::compress + --features=integer,gpu -p $(TFHE_SPEC) -- integer::gpu::ciphertext::compress .PHONY: test_integer_gpu_ci # Run the tests for integer ci on gpu backend test_integer_gpu_ci: install_rs_check_toolchain install_cargo_nextest @@ -662,20 +659,20 @@ test_signed_integer_multi_bit_gpu_ci: install_rs_check_toolchain install_cargo_n .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_SPEC) -- boolean:: + --features=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 RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) tarpaulin --profile $(CARGO_PROFILE) \ --out xml --output-dir coverage/boolean --line --engine llvm --timeout 500 \ $(COVERAGE_EXCLUDED_FILES) \ - --features=$(TARGET_ARCH_FEATURE),boolean,internal-keycache \ + --features=boolean,internal-keycache \ -p $(TFHE_SPEC) -- -Z unstable-options --report-time 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 \ + --features=boolean-c-api,shortint-c-api,high-level-c-api \ -p $(TFHE_SPEC) \ c_api @@ -707,14 +704,14 @@ test_shortint_multi_bit_ci: install_rs_build_toolchain install_cargo_nextest .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_SPEC) -- shortint:: + --features=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 RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) tarpaulin --profile $(CARGO_PROFILE) \ --out xml --output-dir coverage/shortint --line --engine llvm --timeout 500 \ $(COVERAGE_EXCLUDED_FILES) \ - --features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache \ + --features=shortint,internal-keycache \ -p $(TFHE_SPEC) -- -Z unstable-options --report-time shortint:: .PHONY: test_integer_ci # Run the tests for integer ci @@ -774,23 +771,23 @@ test_signed_integer_multi_bit_ci: install_rs_check_toolchain install_cargo_nexte .PHONY: test_integer_long_run # Run the long run tests for integer test_integer_long_run: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,__long_run_tests -p $(TFHE_SPEC) -- integer::server_key::radix_parallel::tests_long_run + --features=integer,internal-keycache,__long_run_tests -p $(TFHE_SPEC) -- integer::server_key::radix_parallel::tests_long_run .PHONY: test_safe_serialization # Run the tests for safe serialization test_safe_serialization: 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 -p $(TFHE_SPEC) -- safe_serialization:: + --features=boolean,shortint,integer,internal-keycache -p $(TFHE_SPEC) -- safe_serialization:: .PHONY: test_zk # Run the tests for the zk module of the TFHE-rs crate test_zk: install_rs_build_toolchain install_cargo_nextest RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),shortint,zk-pok -p $(TFHE_SPEC) -- zk:: + --features=shortint,zk-pok -p $(TFHE_SPEC) -- zk:: .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_SPEC) -- integer:: + --features=integer,internal-keycache -p $(TFHE_SPEC) -- integer:: .PHONY: test_integer_cov # Run the tests of the integer module with code coverage test_integer_cov: install_rs_check_toolchain install_tarpaulin @@ -798,38 +795,38 @@ test_integer_cov: install_rs_check_toolchain install_tarpaulin --out xml --output-dir coverage/integer --line --engine llvm --timeout 500 \ --implicit-test-threads \ --exclude-files $(COVERAGE_EXCLUDED_FILES) \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache \ + --features=integer,internal-keycache \ -p $(TFHE_SPEC) -- -Z unstable-options --report-time 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,zk-pok -p $(TFHE_SPEC) \ + --features=boolean,shortint,integer,internal-keycache,zk-pok -p $(TFHE_SPEC) \ -- high_level_api:: test_high_level_api_gpu: install_rs_build_toolchain install_cargo_nextest RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) nextest run --cargo-profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,gpu -p $(TFHE_SPEC) \ + --features=integer,internal-keycache,gpu -p $(TFHE_SPEC) \ -E "test(/high_level_api::.*gpu.*/)" .PHONY: test_strings # Run the tests for strings ci test_strings: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),shortint,integer,strings -p $(TFHE_SPEC) \ + --features=shortint,integer,strings -p $(TFHE_SPEC) \ -- strings:: .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,pbs-stats,zk-pok \ + --features=boolean,shortint,integer,internal-keycache,pbs-stats,zk-pok \ -p $(TFHE_SPEC) \ -- test_user_docs:: .PHONY: test_user_doc_gpu # Run tests for GPU from the .md documentation test_user_doc_gpu: 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,gpu,zk-pok -p $(TFHE_SPEC) \ + --features=boolean,shortint,integer,internal-keycache,gpu,zk-pok -p $(TFHE_SPEC) \ -- test_user_docs:: @@ -837,14 +834,12 @@ test_user_doc_gpu: install_rs_build_toolchain .PHONY: test_regex_engine # Run tests for regex_engine example test_regex_engine: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --example regex_engine \ - --features=$(TARGET_ARCH_FEATURE),integer + --example regex_engine --features=integer .PHONY: test_sha256_bool # Run tests for sha256_bool example test_sha256_bool: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --example sha256_bool \ - --features=$(TARGET_ARCH_FEATURE),boolean + --example sha256_bool --features=boolean .PHONY: test_examples # Run tests for examples test_examples: test_sha256_bool test_regex_engine @@ -862,7 +857,7 @@ test_kreyvium: install_rs_build_toolchain .PHONY: test_tfhe_csprng # Run tfhe-csprng tests test_tfhe_csprng: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE) -p tfhe-csprng + -p tfhe-csprng .PHONY: test_zk_pok # Run tfhe-zk-pok tests test_zk_pok: install_rs_build_toolchain @@ -880,7 +875,7 @@ test_zk_wasm_x86_compat_ci: check_nvm_installed test_zk_wasm_x86_compat: install_rs_build_toolchain build_node_js_api cd tfhe/tests/zk_wasm_x86_test && npm install RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - -p tfhe --test zk_wasm_x86_test --features=$(TARGET_ARCH_FEATURE),integer,zk-pok + -p tfhe --test zk_wasm_x86_test --features=integer,zk-pok .PHONY: test_versionable # Run tests for tfhe-versionable subcrate test_versionable: install_rs_build_toolchain @@ -893,7 +888,7 @@ test_versionable: install_rs_build_toolchain test_backward_compatibility_ci: install_rs_build_toolchain TFHE_BACKWARD_COMPAT_DATA_DIR="$(BACKWARD_COMPAT_DATA_DIR)" RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ --config "patch.'$(BACKWARD_COMPAT_DATA_URL)'.$(BACKWARD_COMPAT_DATA_PROJECT).path=\"tfhe/$(BACKWARD_COMPAT_DATA_DIR)\"" \ - --features=$(TARGET_ARCH_FEATURE),shortint,integer,zk-pok -p $(TFHE_SPEC) test_backward_compatibility -- --nocapture + --features=shortint,integer,zk-pok -p $(TFHE_SPEC) test_backward_compatibility -- --nocapture .PHONY: test_backward_compatibility # Same as test_backward_compatibility_ci but tries to clone the data repo first if needed test_backward_compatibility: tfhe/$(BACKWARD_COMPAT_DATA_DIR) test_backward_compatibility_ci @@ -908,7 +903,7 @@ doc: install_rs_check_toolchain DOCS_RS=1 \ RUSTDOCFLAGS="--html-in-header katex-header.html" \ cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" doc \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,strings,gpu,internal-keycache,experimental,zk-pok --no-deps -p $(TFHE_SPEC) + --features=boolean,shortint,integer,strings,gpu,internal-keycache,experimental,zk-pok --no-deps -p $(TFHE_SPEC) .PHONY: docs # Build rust doc alias for doc docs: doc @@ -919,7 +914,7 @@ lint_doc: install_rs_check_toolchain DOCS_RS=1 \ RUSTDOCFLAGS="--html-in-header katex-header.html -Dwarnings" \ cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" doc \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,strings,gpu,internal-keycache,experimental,zk-pok -p $(TFHE_SPEC) --no-deps + --features=boolean,shortint,integer,strings,gpu,internal-keycache,experimental,zk-pok -p $(TFHE_SPEC) --no-deps .PHONY: lint_docs # Build rust doc with linting enabled alias for lint_doc lint_docs: lint_doc @@ -948,7 +943,7 @@ check_md_links: install_mlc .PHONY: check_compile_tests # Build tests in debug without running them check_compile_tests: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --no-run \ - --features=$(TARGET_ARCH_FEATURE),experimental,boolean,shortint,integer,internal-keycache \ + --features=experimental,boolean,shortint,integer,internal-keycache \ -p $(TFHE_SPEC) @if [[ "$(OS)" == "Linux" || "$(OS)" == "Darwin" ]]; then \ @@ -959,7 +954,7 @@ check_compile_tests: install_rs_build_toolchain .PHONY: check_compile_tests_benches_gpu # Build tests in debug without running them check_compile_tests_benches_gpu: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --no-run \ - --features=$(TARGET_ARCH_FEATURE),experimental,boolean,shortint,integer,internal-keycache,gpu \ + --features=experimental,boolean,shortint,integer,internal-keycache,gpu \ -p $(TFHE_SPEC) mkdir -p "$(TFHECUDA_BUILD)" && \ cd "$(TFHECUDA_BUILD)" && \ @@ -1038,42 +1033,42 @@ dieharder_csprng: install_dieharder build_tfhe_csprng .PHONY: print_doc_bench_parameters # Print parameters used in doc benchmarks print_doc_bench_parameters: RUSTFLAGS="" cargo run --example print_doc_bench_parameters \ - --features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache -p tfhe + --features=shortint,internal-keycache -p tfhe .PHONY: bench_integer # Run benchmarks for unsigned integer bench_integer: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) __TFHE_RS_FAST_BENCH=$(FAST_BENCH) __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench integer-bench \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- + --features=integer,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- .PHONY: bench_signed_integer # Run benchmarks for signed integer bench_signed_integer: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) __TFHE_RS_FAST_BENCH=$(FAST_BENCH) __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench integer-signed-bench \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- + --features=integer,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- .PHONY: bench_integer_gpu # Run benchmarks for integer on GPU backend bench_integer_gpu: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) __TFHE_RS_FAST_BENCH=$(FAST_BENCH) __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench integer-bench \ - --features=$(TARGET_ARCH_FEATURE),integer,gpu,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- + --features=integer,gpu,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- .PHONY: bench_integer_compression # Run benchmarks for unsigned integer compression bench_integer_compression: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench glwe_packing_compression-integer-bench \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- + --features=integer,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- .PHONY: bench_integer_compression_gpu bench_integer_compression_gpu: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench glwe_packing_compression-integer-bench \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,gpu -p $(TFHE_SPEC) -- + --features=integer,internal-keycache,gpu -p $(TFHE_SPEC) -- .PHONY: bench_integer_multi_bit # Run benchmarks for unsigned integer using multi-bit parameters bench_integer_multi_bit: install_rs_check_toolchain @@ -1081,7 +1076,7 @@ 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,nightly-avx512 -p $(TFHE_SPEC) -- + --features=integer,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- .PHONY: bench_signed_integer_multi_bit # Run benchmarks for signed integer using multi-bit parameters bench_signed_integer_multi_bit: install_rs_check_toolchain @@ -1089,7 +1084,7 @@ bench_signed_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-signed-bench \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- + --features=integer,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- .PHONY: bench_integer_multi_bit_gpu # Run benchmarks for integer on GPU backend using multi-bit parameters bench_integer_multi_bit_gpu: install_rs_check_toolchain @@ -1097,7 +1092,7 @@ bench_integer_multi_bit_gpu: install_rs_check_toolchain __TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) __TFHE_RS_FAST_BENCH=$(FAST_BENCH) __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench integer-bench \ - --features=$(TARGET_ARCH_FEATURE),integer,gpu,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- + --features=integer,gpu,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- .PHONY: bench_unsigned_integer_multi_bit_gpu # Run benchmarks for unsigned integer on GPU backend using multi-bit parameters bench_unsigned_integer_multi_bit_gpu: install_rs_check_toolchain @@ -1105,14 +1100,14 @@ bench_unsigned_integer_multi_bit_gpu: install_rs_check_toolchain __TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) __TFHE_RS_FAST_BENCH=$(FAST_BENCH) __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench integer-bench \ - --features=$(TARGET_ARCH_FEATURE),integer,gpu,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- ::unsigned + --features=integer,gpu,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) -- ::unsigned .PHONY: bench_integer_zk # Run benchmarks for integer encryption with ZK proofs bench_integer_zk: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=$(BENCH_TYPE) \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench zk-pke-bench \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,zk-pok,nightly-avx512 \ + --features=integer,internal-keycache,zk-pok,nightly-avx512 \ -p $(TFHE_SPEC) -- .PHONY: bench_shortint # Run benchmarks for shortint @@ -1120,14 +1115,14 @@ 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,nightly-avx512 -p $(TFHE_SPEC) + --features=shortint,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) .PHONY: bench_shortint_oprf # Run benchmarks for shortint bench_shortint_oprf: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" \ cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench oprf-shortint-bench \ - --features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) + --features=shortint,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) .PHONY: bench_shortint_multi_bit # Run benchmarks for shortint using multi-bit parameters bench_shortint_multi_bit: install_rs_check_toolchain @@ -1135,43 +1130,43 @@ 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,nightly-avx512 -p $(TFHE_SPEC) -- + --features=shortint,internal-keycache,nightly-avx512 -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,nightly-avx512 -p $(TFHE_SPEC) + --features=boolean,internal-keycache,nightly-avx512 -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,nightly-avx512 -p $(TFHE_SPEC) + --features=boolean,shortint,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) .PHONY: bench_pbs128 # Run benchmarks for PBS using FFT 128 bits bench_pbs128: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench pbs128-bench \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) + --features=boolean,shortint,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) .PHONY: bench_pbs_gpu # Run benchmarks for PBS on GPU backend bench_pbs_gpu: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_FAST_BENCH=$(FAST_BENCH) cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench pbs-bench \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,gpu,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) + --features=boolean,shortint,gpu,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) .PHONY: bench_ks # Run benchmarks for keyswitch bench_ks: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench ks-bench \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) + --features=boolean,shortint,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) .PHONY: bench_ks_gpu # Run benchmarks for PBS on GPU backend bench_ks_gpu: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench ks-bench \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,gpu,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) + --features=boolean,shortint,gpu,internal-keycache,nightly-avx512 -p $(TFHE_SPEC) bench_web_js_api_parallel_chrome: browser_path = "$(WEB_RUNNER_DIR)/chrome/chrome-linux64/chrome" bench_web_js_api_parallel_chrome: driver_path = "$(WEB_RUNNER_DIR)/chrome/chromedriver-linux64/chromedriver" @@ -1207,13 +1202,13 @@ bench_web_js_api_parallel_firefox_ci: setup_venv bench_hlapi_erc20: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench hlapi-erc20 \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,pbs-stats,nightly-avx512 -p $(TFHE_SPEC) -- + --features=integer,internal-keycache,pbs-stats,nightly-avx512 -p $(TFHE_SPEC) -- .PHONY: bench_hlapi_erc20_gpu # Run benchmarks for ECR20 operations on GPU bench_hlapi_erc20_gpu: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --bench hlapi-erc20 \ - --features=$(TARGET_ARCH_FEATURE),integer,gpu,internal-keycache,pbs-stats,nightly-avx512 -p $(TFHE_SPEC) -- + --features=integer,gpu,internal-keycache,pbs-stats,nightly-avx512 -p $(TFHE_SPEC) -- .PHONY: bench_tfhe_zk_pok # Run benchmarks for the tfhe_zk_pok crate bench_tfhe_zk_pok: install_rs_check_toolchain @@ -1228,32 +1223,32 @@ bench_tfhe_zk_pok: install_rs_check_toolchain gen_key_cache: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS) --cfg tarpaulin" cargo $(CARGO_RS_BUILD_TOOLCHAIN) run --profile $(CARGO_PROFILE) \ --example generates_test_keys \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,experimental,internal-keycache -p $(TFHE_SPEC) \ + --features=boolean,shortint,experimental,internal-keycache -p $(TFHE_SPEC) \ -- $(MULTI_BIT_ONLY) $(COVERAGE_ONLY) .PHONY: gen_key_cache_core_crypto # Run function to generate keys and cache them for core_crypto tests gen_key_cache_core_crypto: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --tests --profile $(CARGO_PROFILE) \ - --features=$(TARGET_ARCH_FEATURE),experimental,internal-keycache -p $(TFHE_SPEC) -- --nocapture \ + --features=experimental,internal-keycache -p $(TFHE_SPEC) -- --nocapture \ core_crypto::keycache::generate_keys .PHONY: measure_hlapi_compact_pk_ct_sizes # Measure sizes of public keys and ciphertext for high-level API measure_hlapi_compact_pk_ct_sizes: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) run --profile $(CARGO_PROFILE) \ --example hlapi_compact_pk_ct_sizes \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache + --features=integer,internal-keycache .PHONY: measure_shortint_key_sizes # Measure sizes of bootstrapping and key switching keys for shortint measure_shortint_key_sizes: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) run --profile $(CARGO_PROFILE) \ --example shortint_key_sizes \ - --features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache + --features=shortint,internal-keycache .PHONY: measure_boolean_key_sizes # Measure sizes of bootstrapping and key switching keys for boolean measure_boolean_key_sizes: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) run --profile $(CARGO_PROFILE) \ --example boolean_key_sizes \ - --features=$(TARGET_ARCH_FEATURE),boolean,internal-keycache + --features=boolean,internal-keycache .PHONY: parse_integer_benches # Run python parser to output a csv containing integer benches data parse_integer_benches: @@ -1265,14 +1260,13 @@ parse_integer_benches: parse_wasm_benchmarks: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) run --profile $(CARGO_PROFILE) \ --example wasm_benchmarks_parser \ - --features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache \ + --features=shortint,internal-keycache \ -- wasm_benchmark_results.json .PHONY: write_params_to_file # Gather all crypto parameters into a file with a Sage readable format. write_params_to_file: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) run --profile $(CARGO_PROFILE) \ - --example write_params_to_file \ - --features=$(TARGET_ARCH_FEATURE),boolean,shortint,internal-keycache + --example write_params_to_file --features=boolean,shortint,internal-keycache .PHONY: clone_backward_compat_data # Clone the data repo needed for backward compatibility tests clone_backward_compat_data: @@ -1287,22 +1281,20 @@ tfhe/$(BACKWARD_COMPAT_DATA_DIR): clone_backward_compat_data .PHONY: regex_engine # Run regex_engine example regex_engine: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) run --profile $(CARGO_PROFILE) \ - --example regex_engine \ - --features=$(TARGET_ARCH_FEATURE),integer \ + --example regex_engine --features=integer \ -- $(REGEX_STRING) $(REGEX_PATTERN) .PHONY: dark_market # Run dark market example dark_market: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) run --profile $(CARGO_PROFILE) \ --example dark_market \ - --features=$(TARGET_ARCH_FEATURE),integer,internal-keycache \ + --features=integer,internal-keycache \ -- fhe-modified fhe-parallel plain fhe .PHONY: sha256_bool # Run sha256_bool example sha256_bool: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) run --profile $(CARGO_PROFILE) \ - --example sha256_bool \ - --features=$(TARGET_ARCH_FEATURE),boolean + --example sha256_bool --features=boolean .PHONY: pcc # pcc stands for pre commit checks (except GPU) pcc: no_tfhe_typo no_dbg_log check_fmt check_typos lint_doc check_md_docs_are_tested check_intra_md_links \ diff --git a/README.md b/README.md index a10f6702cd..88d4c10765 100644 --- a/README.md +++ b/README.md @@ -70,22 +70,8 @@ production-ready library for all the advanced features of TFHE. ### Cargo.toml configuration To use the latest version of `TFHE-rs` in your project, you first need to add it as a dependency in your `Cargo.toml`: -+ For x86_64-based machines running Unix-like OSes: - -```toml -tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64-unix"] } -``` - -+ For Apple Silicon or aarch64-based machines running Unix-like OSes: - -```toml -tfhe = { version = "*", features = ["boolean", "shortint", "integer", "aarch64-unix"] } -``` - -+ For x86_64-based machines with the [`rdseed instruction`](https://en.wikipedia.org/wiki/RDRAND) running Windows: - ```toml -tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64"] } +tfhe = { version = "*", features = ["boolean", "shortint", "integer"] } ``` > [!Note] diff --git a/apps/trivium/Cargo.toml b/apps/trivium/Cargo.toml index 38aa519b85..d30ce6e298 100644 --- a/apps/trivium/Cargo.toml +++ b/apps/trivium/Cargo.toml @@ -7,14 +7,7 @@ edition = "2021" [dependencies] rayon = { workspace = true } - -[target.'cfg(target_arch = "x86_64")'.dependencies.tfhe] -path = "../../tfhe" -features = [ "boolean", "shortint", "integer", "x86_64" ] - -[target.'cfg(target_arch = "aarch64")'.dependencies.tfhe] -path = "../../tfhe" -features = [ "boolean", "shortint", "integer", "aarch64-unix" ] +tfhe = { path = "../../tfhe", features = [ "boolean", "shortint", "integer" ] } [dev-dependencies] criterion = { version = "0.5.1", features = [ "html_reports" ]} diff --git a/scripts/get_arch_feature.sh b/scripts/get_arch_feature.sh deleted file mode 100755 index 0a4c03a246..0000000000 --- a/scripts/get_arch_feature.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -set -e - -ARCH_FEATURE=x86_64 - -IS_AARCH64="$( (uname -a | grep -c "arm64\|aarch64") || true)" - -if [[ "${IS_AARCH64}" != "0" ]]; then - ARCH_FEATURE=aarch64 -fi - -UNAME="$(uname)" - -if [[ "${UNAME}" == "Linux" || "${UNAME}" == "Darwin" ]]; then - ARCH_FEATURE="${ARCH_FEATURE}-unix" -fi - -echo "${ARCH_FEATURE}" diff --git a/scripts/integer-tests.sh b/scripts/integer-tests.sh index f7b58e219d..e745ded804 100755 --- a/scripts/integer-tests.sh +++ b/scripts/integer-tests.sh @@ -104,7 +104,6 @@ if [[ "${backend}" == "gpu" ]]; then fi CURR_DIR="$(dirname "$0")" -ARCH_FEATURE="$("${CURR_DIR}/get_arch_feature.sh")" # TODO autodetect/have a finer CPU count depending on memory num_cpu_threads="$("${CURR_DIR}"/cpu_count.sh)" @@ -155,7 +154,7 @@ cargo "${RUST_TOOLCHAIN}" nextest run \ --cargo-profile "${cargo_profile}" \ --package "${tfhe_package}" \ --profile ci \ - --features="${ARCH_FEATURE}",integer,internal-keycache,zk-pok,experimental,"${avx512_feature}","${gpu_feature}" \ + --features=integer,internal-keycache,zk-pok,experimental,"${avx512_feature}","${gpu_feature}" \ --test-threads "${test_threads}" \ -E "$filter_expression" @@ -163,7 +162,7 @@ if [[ -z ${multi_bit_argument} ]]; then cargo "${RUST_TOOLCHAIN}" test \ --profile "${cargo_profile}" \ --package "${tfhe_package}" \ - --features="${ARCH_FEATURE}",integer,internal-keycache,experimental,"${avx512_feature}","${gpu_feature}" \ + --features=integer,internal-keycache,experimental,"${avx512_feature}","${gpu_feature}" \ --doc \ -- --test-threads="${doctest_threads}" integer::"${gpu_feature}" fi diff --git a/scripts/shortint-tests.sh b/scripts/shortint-tests.sh index c7b0e1b90a..eb88c8f7c5 100755 --- a/scripts/shortint-tests.sh +++ b/scripts/shortint-tests.sh @@ -65,7 +65,6 @@ if [[ "${FAST_TESTS}" == TRUE ]]; then fi CURR_DIR="$(dirname "$0")" -ARCH_FEATURE="$("${CURR_DIR}/get_arch_feature.sh")" n_threads_small="$("${CURR_DIR}"/cpu_count.sh)" n_threads_big="${n_threads_small}" @@ -94,7 +93,7 @@ if [[ "${BIG_TESTS_INSTANCE}" != TRUE ]]; then --cargo-profile "${cargo_profile}" \ --package "${tfhe_package}" \ --profile ci \ - --features="${ARCH_FEATURE}",shortint,internal-keycache,zk-pok,experimental \ + --features=shortint,internal-keycache,zk-pok,experimental \ --test-threads "${n_threads_small}" \ -E "${filter_expression_small_params}" @@ -111,7 +110,7 @@ and not test(~smart_add_and_mul)""" --cargo-profile "${cargo_profile}" \ --package "${tfhe_package}" \ --profile ci \ - --features="${ARCH_FEATURE}",shortint,internal-keycache,zk-pok,experimental \ + --features=shortint,internal-keycache,zk-pok,experimental \ --test-threads "${n_threads_big}" \ --no-tests=warn \ -E "${filter_expression_big_params}" @@ -120,7 +119,7 @@ and not test(~smart_add_and_mul)""" cargo "${RUST_TOOLCHAIN}" test \ --profile "${cargo_profile}" \ --package "${tfhe_package}" \ - --features="${ARCH_FEATURE}",shortint,internal-keycache,zk-pok,experimental \ + --features=shortint,internal-keycache,zk-pok,experimental \ --doc \ -- shortint:: fi @@ -134,7 +133,7 @@ else --cargo-profile "${cargo_profile}" \ --package "${tfhe_package}" \ --profile ci \ - --features="${ARCH_FEATURE}",shortint,internal-keycache,experimental \ + --features=shortint,internal-keycache,experimental \ --test-threads "${n_threads_big}" \ -E "${filter_expression}" @@ -142,7 +141,7 @@ else cargo "${RUST_TOOLCHAIN}" test \ --profile "${cargo_profile}" \ --package "${tfhe_package}" \ - --features="${ARCH_FEATURE}",shortint,internal-keycache,experimental \ + --features=shortint,internal-keycache,experimental \ --doc \ -- --test-threads="${n_threads_big}" shortint:: fi diff --git a/tfhe-csprng/Cargo.toml b/tfhe-csprng/Cargo.toml index 7f0fec4388..57fe920fb6 100644 --- a/tfhe-csprng/Cargo.toml +++ b/tfhe-csprng/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tfhe-csprng" -version = "0.4.1" +version = "0.5.0" edition = "2021" license = "BSD-3-Clause-Clear" description = "Cryptographically Secure PRNG used in the TFHE-rs library." @@ -25,29 +25,13 @@ clap = "=4.4.4" [features] parallel = ["rayon"] -seeder_x86_64_rdseed = [] -seeder_unix = [] -generator_x86_64_aesni = [] -generator_fallback = [] -generator_aarch64_aes = [] - -x86_64 = [ - "parallel", - "seeder_x86_64_rdseed", - "generator_x86_64_aesni", - "generator_fallback", -] -x86_64-unix = ["x86_64", "seeder_unix"] -aarch64 = ["parallel", "generator_aarch64_aes", "generator_fallback"] -aarch64-unix = ["aarch64", "seeder_unix"] +software-prng = [] [[bench]] name = "benchmark" path = "benches/benchmark.rs" harness = false -required-features = ["seeder_x86_64_rdseed", "generator_x86_64_aesni"] [[example]] name = "generate" path = "examples/generate.rs" -required-features = ["seeder_unix", "generator_fallback"] diff --git a/tfhe-csprng/README.md b/tfhe-csprng/README.md index 458fc89a75..5bdd02f701 100644 --- a/tfhe-csprng/README.md +++ b/tfhe-csprng/README.md @@ -8,13 +8,13 @@ The implementation is based on the AES blockcipher used in CTR mode, as describe Two implementations are available, an accelerated one on x86_64 CPUs with the `aes` feature and the `sse2` feature, and a pure software one that can be used on other platforms. -The crate also makes two seeders available, one needing the x86_64 feature `rdseed` and another one based on the Unix random device `/dev/random` the latter requires the user to provide a secret. +The crate also makes two seeders available, one needing the x86_64 instruction `rdseed` and another one based on the Unix random device `/dev/random` the latter requires the user to provide a secret. ## Running the benchmarks To execute the benchmarks on an x86_64 platform: ```shell -RUSTFLAGS="-Ctarget-cpu=native" cargo bench --features=seeder_x86_64_rdseed,generator_x86_64_aesni +RUSTFLAGS="-Ctarget-cpu=native" cargo bench ``` ## License diff --git a/tfhe-csprng/benches/benchmark.rs b/tfhe-csprng/benches/benchmark.rs index 86b212006e..5945e20ecc 100644 --- a/tfhe-csprng/benches/benchmark.rs +++ b/tfhe-csprng/benches/benchmark.rs @@ -1,15 +1,53 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use tfhe_csprng::generators::{ - AesniRandomGenerator, BytesPerChild, ChildrenCount, RandomGenerator, + BytesPerChild, ChildrenCount, DefaultRandomGenerator, RandomGenerator, }; -use tfhe_csprng::seeders::{RdseedSeeder, Seeder}; +#[cfg(target_os = "macos")] +use tfhe_csprng::seeders::AppleSecureEnclaveSeeder as ActivatedSeeder; +#[cfg(all( + not(target_os = "macos"), + target_arch = "x86_64", + target_feature = "rdseed" +))] +use tfhe_csprng::seeders::RdseedSeeder as ActivatedSeeder; +#[cfg(all( + not(target_os = "macos"), + not(all(target_arch = "x86_64", target_feature = "rdseed")), + target_family = "unix" +))] +use tfhe_csprng::seeders::UnixSeeder as ActivatedSeeder; + +use tfhe_csprng::seeders::Seeder; // The number of bytes to generate during one benchmark iteration. const N_GEN: usize = 1_000_000; +fn new_seeder() -> ActivatedSeeder { + #[cfg(target_os = "macos")] + { + ActivatedSeeder + } + #[cfg(all( + not(target_os = "macos"), + target_arch = "x86_64", + target_feature = "rdseed" + ))] + { + ActivatedSeeder::new() + } + #[cfg(all( + not(target_os = "macos"), + not(all(target_arch = "x86_64", target_feature = "rdseed")), + target_family = "unix" + ))] + { + ActivatedSeeder::new(0) + } +} + fn parent_generate(c: &mut Criterion) { - let mut seeder = RdseedSeeder; - let mut generator = AesniRandomGenerator::new(seeder.seed()); + let mut seeder = new_seeder(); + let mut generator = DefaultRandomGenerator::new(seeder.seed()); c.bench_function("parent_generate", |b| { b.iter(|| { (0..N_GEN).for_each(|_| { @@ -20,8 +58,8 @@ fn parent_generate(c: &mut Criterion) { } fn child_generate(c: &mut Criterion) { - let mut seeder = RdseedSeeder; - let mut generator = AesniRandomGenerator::new(seeder.seed()); + let mut seeder = new_seeder(); + let mut generator = DefaultRandomGenerator::new(seeder.seed()); let mut generator = generator .try_fork(ChildrenCount(1), BytesPerChild(N_GEN * 10_000)) .unwrap() @@ -37,8 +75,8 @@ fn child_generate(c: &mut Criterion) { } fn fork(c: &mut Criterion) { - let mut seeder = RdseedSeeder; - let mut generator = AesniRandomGenerator::new(seeder.seed()); + let mut seeder = new_seeder(); + let mut generator = DefaultRandomGenerator::new(seeder.seed()); c.bench_function("fork", |b| { b.iter(|| { black_box( diff --git a/tfhe-csprng/build.rs b/tfhe-csprng/build.rs deleted file mode 100644 index 5a3939533e..0000000000 --- a/tfhe-csprng/build.rs +++ /dev/null @@ -1,115 +0,0 @@ -// To have clear error messages during compilation about why some piece of code may not be available -// we decided to check the features compatibility with the target configuration in this script. - -use std::collections::HashMap; -use std::env; - -// See https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch for various -// compilation configuration - -// Can be easily extended if needed -pub struct FeatureRequirement { - pub feature_name: &'static str, - // target_arch requirement - pub feature_req_target_arch: Option<&'static str>, - // target_family requirement - pub feature_req_target_family: Option<&'static str>, -} - -// We implement a version of default that is const which is not possible through the Default trait -impl FeatureRequirement { - // As we cannot use cfg!(feature = "feature_name") with something else than a literal, we need - // a reference to the HashMap we populate with the enabled features - fn is_activated(&self, build_activated_features: &HashMap<&'static str, bool>) -> bool { - *build_activated_features.get(self.feature_name).unwrap() - } - - // panics if the requirements are not met - fn check_requirements(&self) { - let target_arch = get_target_arch_cfg(); - if let Some(feature_req_target_arch) = self.feature_req_target_arch { - if feature_req_target_arch != target_arch { - panic!( - "Feature `{}` requires target_arch `{}`, current cfg: `{}`", - self.feature_name, feature_req_target_arch, target_arch - ) - } - } - - let target_families = get_target_family_cfgs(); - if let Some(feature_req_target_family) = self.feature_req_target_family { - if target_families - .split(',') - .all(|family| family != feature_req_target_family) - { - panic!( - "Feature `{}` requires target_family `{}`, current cfgs: `{}`", - self.feature_name, feature_req_target_family, target_families - ) - } - } - } -} - -// const vecs are not yet a thing so use a fixed size array (update the array size when adding -// requirements) -static FEATURE_REQUIREMENTS: [FeatureRequirement; 4] = [ - FeatureRequirement { - feature_name: "seeder_x86_64_rdseed", - feature_req_target_arch: Some("x86_64"), - feature_req_target_family: None, - }, - FeatureRequirement { - feature_name: "generator_x86_64_aesni", - feature_req_target_arch: Some("x86_64"), - feature_req_target_family: None, - }, - FeatureRequirement { - feature_name: "seeder_unix", - feature_req_target_arch: None, - feature_req_target_family: Some("unix"), - }, - FeatureRequirement { - feature_name: "generator_aarch64_aes", - feature_req_target_arch: Some("aarch64"), - feature_req_target_family: None, - }, -]; - -// For a "feature_name" feature_cfg!("feature_name") expands to -// ("feature_name", cfg!(feature = "feature_name")) -macro_rules! feature_cfg { - ($feat_name:literal) => { - ($feat_name, cfg!(feature = $feat_name)) - }; -} - -// Static HashMap would require an additional crate (phf or lazy static e.g.), so we just write a -// function that returns the HashMap we are interested in -fn get_feature_enabled_status() -> HashMap<&'static str, bool> { - HashMap::from([ - feature_cfg!("seeder_x86_64_rdseed"), - feature_cfg!("generator_x86_64_aesni"), - feature_cfg!("seeder_unix"), - feature_cfg!("generator_aarch64_aes"), - ]) -} - -// See https://stackoverflow.com/a/43435335/18088947 for the inspiration of this code -fn get_target_arch_cfg() -> String { - env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH is not set") -} - -fn get_target_family_cfgs() -> String { - env::var("CARGO_CFG_TARGET_FAMILY").expect("CARGO_CFG_TARGET_FAMILY is not set") -} - -fn main() { - let feature_enabled_status = get_feature_enabled_status(); - - // This will panic if some requirements for a feature are not met - FEATURE_REQUIREMENTS - .iter() - .filter(|&req| FeatureRequirement::is_activated(req, &feature_enabled_status)) - .for_each(FeatureRequirement::check_requirements); -} diff --git a/tfhe-csprng/examples/generate.rs b/tfhe-csprng/examples/generate.rs index 2e51195420..baba7d0c30 100644 --- a/tfhe-csprng/examples/generate.rs +++ b/tfhe-csprng/examples/generate.rs @@ -2,35 +2,29 @@ //! the program stdout. It can also generate a fixed number of bytes by passing a value along the //! optional argument `--bytes_total`. For testing purpose. use clap::{value_parser, Arg, Command}; -#[cfg(feature = "generator_x86_64_aesni")] -use tfhe_csprng::generators::AesniRandomGenerator as ActivatedRandomGenerator; -#[cfg(feature = "generator_aarch64_aes")] -use tfhe_csprng::generators::NeonAesRandomGenerator as ActivatedRandomGenerator; -use tfhe_csprng::generators::RandomGenerator; -#[cfg(all( - not(feature = "generator_x86_64_aesni"), - not(feature = "generator_aarch64_aes"), - feature = "generator_fallback" -))] -use tfhe_csprng::generators::SoftwareRandomGenerator as ActivatedRandomGenerator; +use tfhe_csprng::generators::{DefaultRandomGenerator, RandomGenerator}; use std::io::prelude::*; use std::io::{stdout, StdoutLock}; #[cfg(target_os = "macos")] use tfhe_csprng::seeders::AppleSecureEnclaveSeeder as ActivatedSeeder; -#[cfg(all(not(target_os = "macos"), feature = "seeder_x86_64_rdseed"))] +#[cfg(all( + not(target_os = "macos"), + target_arch = "x86_64", + target_feature = "rdseed" +))] use tfhe_csprng::seeders::RdseedSeeder as ActivatedSeeder; use tfhe_csprng::seeders::Seeder; #[cfg(all( not(target_os = "macos"), - not(feature = "seeder_x86_64_rdseed"), - feature = "seeder_unix" + not(all(target_arch = "x86_64", target_feature = "rdseed")), + target_family = "unix" ))] use tfhe_csprng::seeders::UnixSeeder as ActivatedSeeder; fn write_bytes( buffer: &mut [u8], - generator: &mut ActivatedRandomGenerator, + generator: &mut DefaultRandomGenerator, stdout: &mut StdoutLock<'_>, ) -> std::io::Result<()> { buffer.iter_mut().zip(generator).for_each(|(b, g)| *b = g); @@ -39,7 +33,7 @@ fn write_bytes( fn infinite_bytes_generation( buffer: &mut [u8], - generator: &mut ActivatedRandomGenerator, + generator: &mut DefaultRandomGenerator, stdout: &mut StdoutLock<'_>, ) { while write_bytes(buffer, generator, stdout).is_ok() {} @@ -48,7 +42,7 @@ fn infinite_bytes_generation( fn bytes_generation( bytes_total: usize, buffer: &mut [u8], - generator: &mut ActivatedRandomGenerator, + generator: &mut DefaultRandomGenerator, stdout: &mut StdoutLock<'_>, ) { let quotient = bytes_total / buffer.len(); @@ -61,6 +55,29 @@ fn bytes_generation( write_bytes(&mut buffer[0..remaining], generator, stdout).unwrap() } +fn new_seeder() -> ActivatedSeeder { + #[cfg(target_os = "macos")] + { + ActivatedSeeder + } + #[cfg(all( + not(target_os = "macos"), + target_arch = "x86_64", + target_feature = "rdseed" + ))] + { + ActivatedSeeder::new() + } + #[cfg(all( + not(target_os = "macos"), + not(all(target_arch = "x86_64", target_feature = "rdseed")), + target_family = "unix" + ))] + { + ActivatedSeeder::new(0) + } +} + pub fn main() { let matches = Command::new( "Generate a stream of random numbers, specify no flags for infinite generation", @@ -74,25 +91,11 @@ pub fn main() { ) .get_matches(); - // Ugly hack to be able to use UnixSeeder - #[cfg(all( - not(target_os = "macos"), - not(feature = "seeder_x86_64_rdseed"), - feature = "seeder_unix" - ))] - let new_seeder = || ActivatedSeeder::new(0); - #[cfg(not(all( - not(target_os = "macos"), - not(feature = "seeder_x86_64_rdseed"), - feature = "seeder_unix" - )))] - let new_seeder = || ActivatedSeeder; - let mut seeder = new_seeder(); let seed = seeder.seed(); // Don't print on std out eprintln!("seed={seed:?}"); - let mut generator = ActivatedRandomGenerator::new(seed); + let mut generator = DefaultRandomGenerator::new(seed); let stdout = stdout(); let mut buffer = [0u8; 16]; diff --git a/tfhe-csprng/src/generators/aes_ctr/mod.rs b/tfhe-csprng/src/generators/aes_ctr/mod.rs index 04da32c1f4..fb20825d9e 100644 --- a/tfhe-csprng/src/generators/aes_ctr/mod.rs +++ b/tfhe-csprng/src/generators/aes_ctr/mod.rs @@ -206,7 +206,6 @@ pub use index::*; /// A module containing structures to manage table indices and buffer pointers together properly. mod states; -pub use states::*; /// A module containing an abstraction for aes block ciphers. mod block_cipher; diff --git a/tfhe-csprng/src/generators/aes_ctr/parallel.rs b/tfhe-csprng/src/generators/aes_ctr/parallel.rs index 4becf99c78..073f2747f8 100644 --- a/tfhe-csprng/src/generators/aes_ctr/parallel.rs +++ b/tfhe-csprng/src/generators/aes_ctr/parallel.rs @@ -1,6 +1,5 @@ -use crate::generators::aes_ctr::{ - AesBlockCipher, AesCtrGenerator, ChildrenClosure, State, TableIndex, -}; +use crate::generators::aes_ctr::states::State; +use crate::generators::aes_ctr::{AesBlockCipher, AesCtrGenerator, ChildrenClosure, TableIndex}; use crate::generators::{BytesPerChild, ChildrenCount, ForkError}; /// A type alias for the parallel children iterator type. diff --git a/tfhe-csprng/src/generators/default.rs b/tfhe-csprng/src/generators/default.rs new file mode 100644 index 0000000000..1e3e8f27bf --- /dev/null +++ b/tfhe-csprng/src/generators/default.rs @@ -0,0 +1,19 @@ +#[cfg(all(target_arch = "x86_64", not(feature = "software-prng")))] +use super::AesniRandomGenerator; +#[cfg(all(target_arch = "aarch64", not(feature = "software-prng")))] +use super::NeonAesRandomGenerator; +#[cfg(any( + feature = "software-prng", + not(any(target_arch = "x86_64", target_arch = "aarch64")) +))] +use super::SoftwareRandomGenerator; + +#[cfg(all(target_arch = "x86_64", not(feature = "software-prng")))] +pub type DefaultRandomGenerator = AesniRandomGenerator; +#[cfg(all(target_arch = "aarch64", not(feature = "software-prng")))] +pub type DefaultRandomGenerator = NeonAesRandomGenerator; +#[cfg(any( + feature = "software-prng", + not(any(target_arch = "x86_64", target_arch = "aarch64")) +))] +pub type DefaultRandomGenerator = SoftwareRandomGenerator; diff --git a/tfhe-csprng/src/generators/implem/aarch64/block_cipher.rs b/tfhe-csprng/src/generators/implem/aarch64/block_cipher.rs index 3ccb139aa7..77734eaa0e 100644 --- a/tfhe-csprng/src/generators/implem/aarch64/block_cipher.rs +++ b/tfhe-csprng/src/generators/implem/aarch64/block_cipher.rs @@ -25,7 +25,8 @@ impl AesBlockCipher for ArmAesBlockCipher { if !(aes_detected && neon_detected) { panic!( "The ArmAesBlockCipher requires both aes and neon aarch64 CPU features.\n\ - aes feature available: {}\nneon feature available: {}\n.", + aes feature available: {}\nneon feature available: {}\n\ + Please consider enabling the SoftwareRandomGenerator with the `software-prng` feature", aes_detected, neon_detected ) } diff --git a/tfhe-csprng/src/generators/implem/aesni/block_cipher.rs b/tfhe-csprng/src/generators/implem/aesni/block_cipher.rs index c65489b5cb..f5bf56eed0 100644 --- a/tfhe-csprng/src/generators/implem/aesni/block_cipher.rs +++ b/tfhe-csprng/src/generators/implem/aesni/block_cipher.rs @@ -20,7 +20,8 @@ impl AesBlockCipher for AesniBlockCipher { if !(aes_detected && sse2_detected) { panic!( "The AesniBlockCipher requires both aes and sse2 x86 CPU features.\n\ - aes feature available: {}\nsse2 feature available: {}\n.", + aes feature available: {}\nsse2 feature available: {}\n\ + Please consider enabling the SoftwareRandomGenerator with the `software-prng` feature", aes_detected, sse2_detected ) } diff --git a/tfhe-csprng/src/generators/implem/mod.rs b/tfhe-csprng/src/generators/implem/mod.rs index 5ce7cd10f6..5ae976bb15 100644 --- a/tfhe-csprng/src/generators/implem/mod.rs +++ b/tfhe-csprng/src/generators/implem/mod.rs @@ -1,14 +1,12 @@ -#[cfg(feature = "generator_x86_64_aesni")] +#[cfg(target_arch = "x86_64")] mod aesni; -#[cfg(feature = "generator_x86_64_aesni")] +#[cfg(target_arch = "x86_64")] pub use aesni::*; -#[cfg(feature = "generator_aarch64_aes")] +#[cfg(target_arch = "aarch64")] mod aarch64; -#[cfg(feature = "generator_aarch64_aes")] +#[cfg(target_arch = "aarch64")] pub use aarch64::*; -#[cfg(feature = "generator_fallback")] mod soft; -#[cfg(feature = "generator_fallback")] pub use soft::*; diff --git a/tfhe-csprng/src/generators/mod.rs b/tfhe-csprng/src/generators/mod.rs index 1f72e0659e..a80ca08197 100644 --- a/tfhe-csprng/src/generators/mod.rs +++ b/tfhe-csprng/src/generators/mod.rs @@ -123,6 +123,10 @@ mod aes_ctr; mod implem; pub use implem::*; +pub mod default; +/// Convenience alias for the most efficient CSPRNG implementation available. +pub use default::DefaultRandomGenerator; + #[cfg(test)] #[allow(unused)] // to please clippy when tests are not activated pub mod generator_generic_test { diff --git a/tfhe-csprng/src/seeders/implem/mod.rs b/tfhe-csprng/src/seeders/implem/mod.rs index 2d11d99591..45b184d18e 100644 --- a/tfhe-csprng/src/seeders/implem/mod.rs +++ b/tfhe-csprng/src/seeders/implem/mod.rs @@ -3,12 +3,12 @@ mod apple_secure_enclave_seeder; #[cfg(target_os = "macos")] pub use apple_secure_enclave_seeder::AppleSecureEnclaveSeeder; -#[cfg(feature = "seeder_x86_64_rdseed")] +#[cfg(target_arch = "x86_64")] mod rdseed; -#[cfg(feature = "seeder_x86_64_rdseed")] +#[cfg(target_arch = "x86_64")] pub use rdseed::RdseedSeeder; -#[cfg(feature = "seeder_unix")] +#[cfg(target_family = "unix")] mod unix; -#[cfg(feature = "seeder_unix")] +#[cfg(target_family = "unix")] pub use unix::UnixSeeder; diff --git a/tfhe-csprng/src/seeders/implem/rdseed.rs b/tfhe-csprng/src/seeders/implem/rdseed.rs index c6c7a9b12e..1058d9581f 100644 --- a/tfhe-csprng/src/seeders/implem/rdseed.rs +++ b/tfhe-csprng/src/seeders/implem/rdseed.rs @@ -4,7 +4,23 @@ use crate::seeders::{Seed, Seeder}; /// /// The `rdseed` instruction allows to deliver seeds from a hardware source of entropy see /// . -pub struct RdseedSeeder; +pub struct RdseedSeeder(()); + +impl RdseedSeeder { + pub fn new() -> Self { + if Self::is_available() { + Self(()) + } else { + panic!("Tried to use RdSeedSeeder but rdseed instruction is not enabled on the current machine"); + } + } +} + +impl Default for RdseedSeeder { + fn default() -> Self { + Self::new() + } +} impl Seeder for RdseedSeeder { fn seed(&mut self) -> Seed { @@ -46,6 +62,6 @@ mod test { #[test] fn check_bounded_sequence_difference() { - check_seeder_fixed_sequences_different(|_| RdseedSeeder); + check_seeder_fixed_sequences_different(|_| RdseedSeeder::new()); } } diff --git a/tfhe/Cargo.toml b/tfhe/Cargo.toml index 6302772bc6..fcf8cc3885 100644 --- a/tfhe/Cargo.toml +++ b/tfhe/Cargo.toml @@ -53,10 +53,7 @@ strum = { version = "0.26", features = ["derive"] } cbindgen = { version = "0.26.0", optional = true } [dependencies] -tfhe-csprng = { version = "0.4.1", path = "../tfhe-csprng", features = [ - "generator_fallback", - "parallel", -] } +tfhe-csprng = { version = "0.5.0", path = "../tfhe-csprng", features = ["parallel"] } serde = { workspace = true, features = ["default", "derive"] } rayon = { workspace = true } bincode = "1.3.3" @@ -107,7 +104,7 @@ experimental-force_fft_algo_dif4 = [] # End experimental section __c_api = ["dep:cbindgen"] -# For the semver trick to skip the build.rs +# Can be used in some situations to reduce build time with GPU __force_skip_cbindgen = [] boolean-c-api = ["boolean", "__c_api"] shortint-c-api = ["shortint", "__c_api"] @@ -129,30 +126,11 @@ parallel-wasm-api = ["dep:wasm-bindgen-rayon"] nightly-avx512 = ["tfhe-fft/nightly", "tfhe-ntt/nightly", "pulp/nightly"] -# Enable the x86_64 specific accelerated implementation of the random generator for the default -# backend -generator_x86_64_aesni = ["tfhe-csprng/generator_x86_64_aesni"] - -# Enable the aarch64 specific accelerated implementation of the random generator for the default -# backend -generator_aarch64_aes = ["tfhe-csprng/generator_aarch64_aes"] - # Private features __profiling = [] __long_run_tests = [] -seeder_unix = ["tfhe-csprng/seeder_unix"] -seeder_x86_64_rdseed = ["tfhe-csprng/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"] - -aarch64 = ["generator_aarch64_aes"] -aarch64-unix = ["aarch64", "seeder_unix"] +software-prng = ["tfhe-csprng/software-prng"] # Cover several profiles as we cannot have a wildcard it seems [package.metadata.wasm-pack.profile.dev.wasm-bindgen] @@ -163,7 +141,7 @@ split-linked-modules = true [package.metadata.docs.rs] # TODO: manage builds for docs.rs based on their documentation https://docs.rs/about -features = ["x86_64-unix", "boolean", "shortint", "integer", "gpu", "zk-pok"] +features = ["boolean", "shortint", "integer", "gpu", "zk-pok", "software-prng"] rustdoc-args = ["--html-in-header", "katex-header.html"] ########### diff --git a/tfhe/benches/core_crypto/dev_bench.rs b/tfhe/benches/core_crypto/dev_bench.rs index 2177b90b30..d5296f4ff8 100644 --- a/tfhe/benches/core_crypto/dev_bench.rs +++ b/tfhe/benches/core_crypto/dev_bench.rs @@ -87,9 +87,8 @@ fn multi_bit_pbs + CastFrom + Syn let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); // Create the LweSecretKey let input_lwe_secret_key = @@ -180,9 +179,8 @@ fn pbs>(c: &mut Criterion) { let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); // Create the LweSecretKey let input_lwe_secret_key = @@ -270,9 +268,8 @@ fn mem_optimized_pbs>(c: &mut Criterion) let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); // Create the LweSecretKey let input_lwe_secret_key = diff --git a/tfhe/benches/core_crypto/ks_bench.rs b/tfhe/benches/core_crypto/ks_bench.rs index 738dba74b5..e874da9275 100644 --- a/tfhe/benches/core_crypto/ks_bench.rs +++ b/tfhe/benches/core_crypto/ks_bench.rs @@ -130,9 +130,8 @@ fn keyswitch + Serialize>( let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for (name, params) in parameters.iter() { let lwe_dimension = params.lwe_dimension.unwrap(); @@ -216,9 +215,8 @@ fn packing_keyswitch( let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for (name, params) in parameters.iter() { let lwe_dimension = params.lwe_dimension.unwrap(); @@ -325,9 +323,9 @@ mod cuda { let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + SecretRandomGenerator::::new(seeder.seed()); let gpu_index = 0; let streams = CudaStreams::new_single_gpu(GpuIndex(gpu_index)); @@ -428,9 +426,9 @@ mod cuda { let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + SecretRandomGenerator::::new(seeder.seed()); let gpu_index = 0; let streams = CudaStreams::new_single_gpu(GpuIndex(gpu_index)); diff --git a/tfhe/benches/core_crypto/pbs128_bench.rs b/tfhe/benches/core_crypto/pbs128_bench.rs index 96599d4521..fd54dadcbe 100644 --- a/tfhe/benches/core_crypto/pbs128_bench.rs +++ b/tfhe/benches/core_crypto/pbs128_bench.rs @@ -34,11 +34,10 @@ fn pbs_128(c: &mut Criterion) { let mut boxed_seeder = new_seeder(); let seeder = boxed_seeder.as_mut(); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); let input_lwe_secret_key = LweSecretKey::generate_new_binary(lwe_dimension, &mut secret_generator); diff --git a/tfhe/benches/core_crypto/pbs_bench.rs b/tfhe/benches/core_crypto/pbs_bench.rs index 4165a33df7..badf7abe31 100644 --- a/tfhe/benches/core_crypto/pbs_bench.rs +++ b/tfhe/benches/core_crypto/pbs_bench.rs @@ -139,9 +139,8 @@ fn mem_optimized_pbs + Serialize>( let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for (name, params) in parameters.iter() { // Create the LweSecretKey @@ -248,9 +247,8 @@ fn mem_optimized_batched_pbs + Serialize let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for (name, params) in parameters.iter() { // Create the LweSecretKey @@ -371,9 +369,8 @@ fn multi_bit_pbs< let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for (name, params, grouping_factor) in parameters.iter() { // Create the LweSecretKey @@ -465,9 +462,8 @@ fn multi_bit_deterministic_pbs< let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for (name, params, grouping_factor) in parameters.iter() { // Create the LweSecretKey @@ -554,9 +550,8 @@ fn mem_optimized_pbs_ntt(c: &mut Criterion) { let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); let custom_ciphertext_modulus = tfhe::core_crypto::prelude::CiphertextModulus::new((1 << 64) - (1 << 32) + 1); @@ -709,9 +704,8 @@ fn pbs_throughput + Sync + Send + Serial let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for (name, params) in parameters.iter() { let input_lwe_secret_key = allocate_and_generate_new_binary_lwe_secret_key( @@ -895,9 +889,9 @@ mod cuda { let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + SecretRandomGenerator::::new(seeder.seed()); let gpu_index = 0; let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index)); @@ -1016,9 +1010,9 @@ mod cuda { let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + SecretRandomGenerator::::new(seeder.seed()); let gpu_index = 0; let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index)); @@ -1138,9 +1132,9 @@ mod cuda { let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + SecretRandomGenerator::::new(seeder.seed()); let gpu_index = 0; let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index)); @@ -1278,9 +1272,9 @@ mod cuda { let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + SecretRandomGenerator::::new(seeder.seed()); let gpu_index = 0; let stream = CudaStreams::new_single_gpu(GpuIndex(gpu_index)); diff --git a/tfhe/benches/keygen/bench.rs b/tfhe/benches/keygen/bench.rs index a6e00938cf..bc22c229c8 100644 --- a/tfhe/benches/keygen/bench.rs +++ b/tfhe/benches/keygen/bench.rs @@ -2,7 +2,7 @@ use criterion::*; use tfhe::core_crypto::commons::generators::DeterministicSeeder; use tfhe::core_crypto::prelude::{ allocate_and_generate_new_binary_glwe_secret_key, - par_allocate_and_generate_new_lwe_bootstrap_key, ActivatedRandomGenerator, CiphertextModulus, + par_allocate_and_generate_new_lwe_bootstrap_key, CiphertextModulus, DefaultRandomGenerator, EncryptionRandomGenerator, SecretRandomGenerator, }; use tfhe::core_crypto::seeders::new_seeder; @@ -13,10 +13,10 @@ fn criterion_bench(c: &mut Criterion) { let parameters = PARAM_MESSAGE_2_CARRY_2_KS_PBS; let mut seeder = new_seeder(); let mut deterministic_seeder = - DeterministicSeeder::::new(seeder.seed()); + DeterministicSeeder::::new(seeder.seed()); let mut secret_generator = - SecretRandomGenerator::::new(deterministic_seeder.seed()); - let mut encryption_generator = EncryptionRandomGenerator::::new( + SecretRandomGenerator::::new(deterministic_seeder.seed()); + let mut encryption_generator = EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); diff --git a/tfhe/docs/fundamentals/serialization.md b/tfhe/docs/fundamentals/serialization.md index 58d63286c5..2d70db33de 100644 --- a/tfhe/docs/fundamentals/serialization.md +++ b/tfhe/docs/fundamentals/serialization.md @@ -158,7 +158,7 @@ In the following example, we use [bincode](https://crates.io/crates/bincode) for [dependencies] # ... -tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] } +tfhe = { version = "0.10.0", features = ["integer"] } bincode = "1.3.3" ``` diff --git a/tfhe/docs/getting_started/installation.md b/tfhe/docs/getting_started/installation.md index 15e2f3bff4..e040cadc81 100644 --- a/tfhe/docs/getting_started/installation.md +++ b/tfhe/docs/getting_started/installation.md @@ -6,22 +6,8 @@ This document provides instructions to set up **TFHE-rs** in your project. First, add **TFHE-rs** as a dependency in your `Cargo.toml`. -**For `x86_64` machine running a Unix-like OS:** - -```toml -tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "x86_64-unix"] } -``` - -**For `ARM` machine running a Unix-like OS:** - -```toml -tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "aarch64-unix"] } -``` - -**For `x86_64` machines with the** [**`rdseed instruction`**](https://en.wikipedia.org/wiki/RDRAND) **running Windows:** - ```toml -tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64"] } +tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer"] } ``` {% hint style="info" %} @@ -36,8 +22,18 @@ tfhe = { version = "*", features = ["boolean", "shortint", "integer", "x86_64"] **TFHE-rs** currently supports the following platforms: -| OS | x86 | aarch64 | -| ------- | ---------------------------------- | ---------------- | -| Linux | `x86_64-unix` | `aarch64-unix`\* | -| macOS | `x86_64-unix` | `aarch64-unix`\* | -| Windows | `x86_64` with `RDSEED` instruction | Unsupported | +| OS | x86_64 | aarch64 | +|---------|-------------------------------------|-------------| +| Linux | Supported | Supported\* | +| macOS | Supported | Supported\* | +| Windows | Supported with `RDSEED` instruction | Unsupported | + +By default, **TFHE-rs** makes the assumption that hardware AES features are enabled on the target CPU. The required CPU features are: +- x86_64: sse2, aesni +- aarch64: aes, neon + +To add support for older CPU, import **TFHE-rs** with the `software-prng` feature in your `Cargo.toml`: + +```toml +tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "software-prng"] } +``` diff --git a/tfhe/docs/getting_started/quick_start.md b/tfhe/docs/getting_started/quick_start.md index d13c7c5364..96fe444fdc 100644 --- a/tfhe/docs/getting_started/quick_start.md +++ b/tfhe/docs/getting_started/quick_start.md @@ -56,10 +56,10 @@ edition = "2021" [dependencies] ``` -For x86 Unix systems, add the following configuration to include **TFHE-rs**: +Then add the following configuration to include **TFHE-rs**: ```toml -tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] } +tfhe = { version = "0.10.0", features = ["integer"] } ``` Your updated `Cargo.toml` file should look like this: @@ -71,7 +71,7 @@ version = "0.1.0" edition = "2021" [dependencies] -tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] } +tfhe = { version = "0.10.0", features = ["integer"] } ``` If you are on a different platform please refer to the [installation documentation](installation.md) for configuration options of other supported platforms. diff --git a/tfhe/docs/guides/array.md b/tfhe/docs/guides/array.md index 8dd3945557..01758646f3 100644 --- a/tfhe/docs/guides/array.md +++ b/tfhe/docs/guides/array.md @@ -19,7 +19,7 @@ The following example shows a complete workflow of working with encrypted arrays # Cargo.toml [dependencies] -tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] } +tfhe = { version = "0.10.0", features = ["integer"] } ``` ```rust diff --git a/tfhe/docs/guides/c_api.md b/tfhe/docs/guides/c_api.md index f21b6cf062..304438f716 100644 --- a/tfhe/docs/guides/c_api.md +++ b/tfhe/docs/guides/c_api.md @@ -4,16 +4,10 @@ This document describes the C bindings to the **TFHE-rs** high-level primitives ## Setting up TFHE-rs C API for C programming. -You can build **TFHE-rs** C API on a Unix x86\_64 machine using the following command: +You can build **TFHE-rs** C API using the following command: ```shell -RUSTFLAGS="-C target-cpu=native" cargo +nightly build --release --features=x86_64-unix,high-level-c-api -p tfhe && make symlink_c_libs_without_fingerprint -``` - -For a Unix aarch64 machine, use the following command: - -```shell -RUSTFLAGS="-C target-cpu=native" cargo +nightly build --release --features=aarch64-unix,high-level-c-api -p tfhe && make symlink_c_libs_without_fingerprint +RUSTFLAGS="-C target-cpu=native" cargo +nightly build --release --features=high-level-c-api -p tfhe ``` Locate files in the right path: diff --git a/tfhe/docs/guides/data_versioning.md b/tfhe/docs/guides/data_versioning.md index c73b0ccdae..bb8804b364 100644 --- a/tfhe/docs/guides/data_versioning.md +++ b/tfhe/docs/guides/data_versioning.md @@ -16,7 +16,7 @@ You can load serialized data with the `unversionize` function, even in newer ver [dependencies] # ... -tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] } +tfhe = { version = "0.10.0", features = ["integer"] } tfhe-versionable = "0.2.0" bincode = "1.3.3" ``` diff --git a/tfhe/docs/guides/run_on_gpu.md b/tfhe/docs/guides/run_on_gpu.md index 0269032b82..5fd8656de2 100644 --- a/tfhe/docs/guides/run_on_gpu.md +++ b/tfhe/docs/guides/run_on_gpu.md @@ -17,16 +17,9 @@ This guide explains how to update your existing program to leverage GPU accelera To use the **TFHE-rs** GPU backend in your project, add the following dependency in your `Cargo.toml`. -If you are using an `x86` machine: ```toml -tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "x86_64-unix", "gpu"] } -``` - -If you are using an `ARM` machine: - -```toml -tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "aarch64-unix", "gpu"] } +tfhe = { version = "0.10.0", features = ["boolean", "shortint", "integer", "gpu"] } ``` {% hint style="success" %} @@ -37,11 +30,11 @@ For optimal performance when using **TFHE-rs**, run your code in release mode wi **TFHE-rs** GPU backend is supported on Linux (x86, aarch64). -| OS | x86 | aarch64 | -| ------- | ------------- | ---------------- | -| Linux | `x86_64-unix` | `aarch64-unix`\* | -| macOS | Unsupported | Unsupported\* | -| Windows | Unsupported | Unsupported | +| OS | x86 | aarch64 | +|---------|-------------|---------------| +| Linux | Supported | Supported\* | +| macOS | Unsupported | Unsupported\* | +| Windows | Unsupported | Unsupported | ## A first example diff --git a/tfhe/docs/references/core-crypto-api/presentation.md b/tfhe/docs/references/core-crypto-api/presentation.md index b0afbd329a..1bc5c16142 100644 --- a/tfhe/docs/references/core-crypto-api/presentation.md +++ b/tfhe/docs/references/core-crypto-api/presentation.md @@ -25,9 +25,9 @@ let ciphertext_modulus = CiphertextModulus::new_native(); let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + SecretRandomGenerator::::new(seeder.seed()); // Create the LweSecretKey let lwe_secret_key = diff --git a/tfhe/docs/references/core-crypto-api/tutorial.md b/tfhe/docs/references/core-crypto-api/tutorial.md index d7688ec65b..796d6c0950 100644 --- a/tfhe/docs/references/core-crypto-api/tutorial.md +++ b/tfhe/docs/references/core-crypto-api/tutorial.md @@ -9,29 +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.10.0", 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. - -For Apple Silicon, the `aarch64-unix` or `aarch64` feature should be enabled. `aarch64` is not supported on Windows as it's currently missing an entropy source required to seed the [CSPRNGs](https://en.wikipedia.org/wiki/Cryptographically\_secure\_pseudorandom\_number\_generator) used in `TFHE-rs`. - -In short: For `x86_64`-based machines running Unix-like OSes: - -```toml -tfhe = { version = "0.10.0", features = ["x86_64-unix"] } -``` - -For Apple Silicon or aarch64-based machines running Unix-like OSes: - -```toml -tfhe = { version = "0.10.0", features = ["aarch64-unix"] } -``` - -For `x86_64`-based machines with the [`rdseed instruction`](https://en.wikipedia.org/wiki/RDRAND) running Windows: - -```toml -tfhe = { version = "0.10.0", features = ["x86_64"] } +tfhe = { version = "0.10.0" } ``` ### Commented code to double a 2-bit message in a leveled fashion and using a PBS with the `core_crypto` module. @@ -64,12 +42,12 @@ pub fn main() { // Create a generator which uses a CSPRNG to generate secret keys let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + SecretRandomGenerator::::new(seeder.seed()); // Create a generator which uses two CSPRNGs to generate public masks and secret encryption // noise let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); println!("Generating keys..."); diff --git a/tfhe/docs/tutorials/ascii_fhe_string.md b/tfhe/docs/tutorials/ascii_fhe_string.md index 460bd739be..9f29b7a703 100644 --- a/tfhe/docs/tutorials/ascii_fhe_string.md +++ b/tfhe/docs/tutorials/ascii_fhe_string.md @@ -25,7 +25,7 @@ To use the `FheUint8` type, enable the `integer` feature: [dependencies] # Default configuration for x86 Unix machines: -tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] } +tfhe = { version = "0.10.0", features = ["integer"] } ``` Refer to the [installation guide](../getting\_started/installation.md) for other configurations. diff --git a/tfhe/docs/tutorials/parity_bit.md b/tfhe/docs/tutorials/parity_bit.md index fdf4ffec33..7e17056ee4 100644 --- a/tfhe/docs/tutorials/parity_bit.md +++ b/tfhe/docs/tutorials/parity_bit.md @@ -17,12 +17,9 @@ This function returns a Boolean (`true` or `false`) so that the total count of ` ```toml # Cargo.toml -# Default configuration for x86 Unix machines: -tfhe = { version = "0.10.0", features = ["integer", "x86_64-unix"] } +tfhe = { version = "0.10.0", features = ["integer"] } ``` -Refer to the [installation](../getting\_started/installation.md) for other configurations. - First, define the verification function. The function initializes the parity bit to `false`, then applies the `XOR` operation across all bits, adding negation based on the requested mode. diff --git a/tfhe/src/boolean/engine/bootstrapping.rs b/tfhe/src/boolean/engine/bootstrapping.rs index b9a63388a3..10b2316ed8 100644 --- a/tfhe/src/boolean/engine/bootstrapping.rs +++ b/tfhe/src/boolean/engine/bootstrapping.rs @@ -6,7 +6,7 @@ use crate::boolean::{ClientKey, PLAINTEXT_TRUE}; use crate::core_crypto::algorithms::*; use crate::core_crypto::commons::computation_buffers::ComputationBuffers; use crate::core_crypto::commons::generators::{DeterministicSeeder, EncryptionRandomGenerator}; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, Seeder}; +use crate::core_crypto::commons::math::random::{DefaultRandomGenerator, Seeder}; use crate::core_crypto::commons::parameters::{CiphertextModulus, PBSOrder}; use crate::core_crypto::entities::*; use crate::core_crypto::fft_impl::fft64::math::fft::Fft; @@ -214,7 +214,7 @@ impl CompressedServerKey { compressed_key_switching_key.output_key_lwe_dimension(), compressed_key_switching_key.ciphertext_modulus(), ); - par_decompress_seeded_lwe_keyswitch_key::<_, _, _, ActivatedRandomGenerator>( + par_decompress_seeded_lwe_keyswitch_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_key_switching_key, compressed_key_switching_key, ); @@ -230,7 +230,7 @@ impl CompressedServerKey { compressed_bootstrapping_key.input_lwe_dimension(), compressed_bootstrapping_key.ciphertext_modulus(), ); - par_decompress_seeded_lwe_bootstrap_key::<_, _, _, ActivatedRandomGenerator>( + par_decompress_seeded_lwe_bootstrap_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_bootstrapping_key, compressed_bootstrapping_key, ); @@ -331,9 +331,9 @@ pub(crate) struct Bootstrapper { /// The [`EncryptionRandomGenerator`] contains two CSPRNGs, one publicly seeded used to /// generate mask coefficients and one privately seeded used to generate errors during /// encryption. - pub(crate) encryption_generator: EncryptionRandomGenerator, + pub(crate) encryption_generator: EncryptionRandomGenerator, pub(crate) computation_buffers: ComputationBuffers, - pub(crate) seeder: DeterministicSeeder, + pub(crate) seeder: DeterministicSeeder, } impl Bootstrapper { diff --git a/tfhe/src/boolean/engine/mod.rs b/tfhe/src/boolean/engine/mod.rs index e120892107..aa3696e375 100644 --- a/tfhe/src/boolean/engine/mod.rs +++ b/tfhe/src/boolean/engine/mod.rs @@ -11,7 +11,7 @@ use crate::core_crypto::algorithms::*; use crate::core_crypto::commons::generators::{ DeterministicSeeder, EncryptionRandomGenerator, SecretRandomGenerator, }; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, Seeder}; +use crate::core_crypto::commons::math::random::{DefaultRandomGenerator, Seeder}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::entities::*; use crate::core_crypto::seeders::new_seeder; @@ -56,14 +56,14 @@ thread_local! { pub struct BooleanEngine { /// A structure containing a single CSPRNG to generate secret key coefficients. - secret_generator: SecretRandomGenerator, + secret_generator: SecretRandomGenerator, /// A structure containing two CSPRNGs to generate material for encryption like public masks /// and secret errors. /// /// The [`EncryptionRandomGenerator`] contains two CSPRNGs, one publicly seeded used to /// generate mask coefficients and one privately seeded used to generate errors during /// encryption. - encryption_generator: EncryptionRandomGenerator, + encryption_generator: EncryptionRandomGenerator, bootstrapper: Bootstrapper, } @@ -366,14 +366,14 @@ impl BooleanEngine { /// use tfhe::boolean::engine::BooleanEngine; /// use tfhe::core_crypto::commons::generators::DeterministicSeeder; /// use tfhe::core_crypto::commons::math::random::Seed; - /// use tfhe::core_crypto::prelude::ActivatedRandomGenerator; + /// use tfhe::core_crypto::prelude::DefaultRandomGenerator; /// /// // WARNING: Using a deterministic seed is not recommended /// // as it renders the random generation insecure /// /// let deterministic_seed = Seed(0); /// - /// let mut seeder = DeterministicSeeder::::new(deterministic_seed); + /// let mut seeder = DeterministicSeeder::::new(deterministic_seed); /// let boolean_engine = BooleanEngine::new_from_seeder(&mut seeder); /// BooleanEngine::replace_thread_local(boolean_engine); /// @@ -394,7 +394,7 @@ impl BooleanEngine { pub fn new_from_seeder(root_seeder: &mut dyn Seeder) -> Self { let mut deterministic_seeder = - DeterministicSeeder::::new(root_seeder.seed()); + DeterministicSeeder::::new(root_seeder.seed()); // Note that the operands are evaluated from left to right for Rust Struct expressions // See: https://doc.rust-lang.org/stable/reference/expressions.html?highlight=left#evaluation-order-of-operands diff --git a/tfhe/src/boolean/engine/tests.rs b/tfhe/src/boolean/engine/tests.rs index e675d4396d..e4d0a6441c 100644 --- a/tfhe/src/boolean/engine/tests.rs +++ b/tfhe/src/boolean/engine/tests.rs @@ -3,7 +3,7 @@ fn test_replacing_thread_local_engine() { use crate::boolean::engine::BooleanEngine; use crate::core_crypto::commons::generators::DeterministicSeeder; use crate::core_crypto::commons::math::random::Seed; - use crate::core_crypto::prelude::ActivatedRandomGenerator; + use crate::core_crypto::prelude::DefaultRandomGenerator; let deterministic_seed = Seed(0); @@ -11,7 +11,7 @@ fn test_replacing_thread_local_engine() { // then generate a client key, and then encrypt // a boolean value and serialize it to compare // it with other ciphertext - let mut seeder = DeterministicSeeder::::new(deterministic_seed); + let mut seeder = DeterministicSeeder::::new(deterministic_seed); let boolean_engine = BooleanEngine::new_from_seeder(&mut seeder); BooleanEngine::replace_thread_local(boolean_engine); @@ -41,7 +41,7 @@ fn test_replacing_thread_local_engine() { // So we expect the encrypted value to be the same // compared with the one from the main thread let third_thread_data = std::thread::spawn(move || { - let mut seeder = DeterministicSeeder::::new(deterministic_seed); + let mut seeder = DeterministicSeeder::::new(deterministic_seed); let boolean_engine = BooleanEngine::new_from_seeder(&mut seeder); BooleanEngine::replace_thread_local(boolean_engine); let (cks, _) = crate::boolean::gen_keys(); diff --git a/tfhe/src/c_api/core_crypto/mod.rs b/tfhe/src/c_api/core_crypto/mod.rs index 8568fd88ea..fa5dc3b9f9 100644 --- a/tfhe/src/c_api/core_crypto/mod.rs +++ b/tfhe/src/c_api/core_crypto/mod.rs @@ -135,8 +135,7 @@ pub unsafe extern "C" fn core_crypto_lwe_secret_key( let seed_high_bytes: u128 = seed_high_bytes.into(); let seed = (seed_high_bytes << 64) | seed_low_bytes; - let mut secret_generator = - SecretRandomGenerator::::new(Seed(seed)); + let mut secret_generator = SecretRandomGenerator::::new(Seed(seed)); // Create the LweSecretKey let output_lwe_sk_slice = std::slice::from_raw_parts_mut(output_lwe_sk_ptr, lwe_sk_dim); @@ -170,8 +169,8 @@ pub unsafe extern "C" fn core_crypto_lwe_encrypt( let seed = (seed_high_bytes << 64) | seed_low_bytes; let seed = Seed(seed); - let mut deterministic_seeder = DeterministicSeeder::::new(seed); - let mut encryption_generator = EncryptionRandomGenerator::::new( + let mut deterministic_seeder = DeterministicSeeder::::new(seed); + let mut encryption_generator = EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); @@ -219,8 +218,8 @@ pub unsafe extern "C" fn core_crypto_ggsw_encrypt( let seed = (seed_high_bytes << 64) | seed_low_bytes; let seed = Seed(seed); - let mut deterministic_seeder = DeterministicSeeder::::new(seed); - let mut encryption_generator = EncryptionRandomGenerator::::new( + let mut deterministic_seeder = DeterministicSeeder::::new(seed); + let mut encryption_generator = EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); @@ -379,9 +378,9 @@ pub unsafe extern "C" fn core_crypto_par_generate_lwe_bootstrapping_key( let seed = (seed_high_bytes << 64) | seed_low_bytes; let mut deterministic_seeder = - DeterministicSeeder::::new(Seed(seed)); + DeterministicSeeder::::new(Seed(seed)); let mut encryption_random_generator = - EncryptionRandomGenerator::::new( + EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); @@ -463,9 +462,9 @@ pub unsafe extern "C" fn core_crypto_par_generate_lwe_multi_bit_bootstrapping_ke let seed = (seed_high_bytes << 64) | seed_low_bytes; let mut deterministic_seeder = - DeterministicSeeder::::new(Seed(seed)); + DeterministicSeeder::::new(Seed(seed)); let mut encryption_random_generator = - EncryptionRandomGenerator::::new( + EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); @@ -542,9 +541,9 @@ pub unsafe extern "C" fn core_crypto_par_generate_lwe_keyswitch_key( let seed = (seed_high_bytes << 64) | seed_low_bytes; let mut deterministic_seeder = - DeterministicSeeder::::new(Seed(seed)); + DeterministicSeeder::::new(Seed(seed)); let mut encryption_random_generator = - EncryptionRandomGenerator::::new( + EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); @@ -618,9 +617,9 @@ pub unsafe extern "C" fn core_crypto_par_generate_lwe_private_functional_keyswit let seed = (seed_high_bytes << 64) | seed_low_bytes; let mut deterministic_seeder = - DeterministicSeeder::::new(Seed(seed)); + DeterministicSeeder::::new(Seed(seed)); let mut encryption_random_generator = - EncryptionRandomGenerator::::new( + EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); diff --git a/tfhe/src/core_crypto/algorithms/ggsw_encryption.rs b/tfhe/src/core_crypto/algorithms/ggsw_encryption.rs index a2d188bf3d..015c605d44 100644 --- a/tfhe/src/core_crypto/algorithms/ggsw_encryption.rs +++ b/tfhe/src/core_crypto/algorithms/ggsw_encryption.rs @@ -9,7 +9,7 @@ use crate::core_crypto::commons::generators::EncryptionRandomGenerator; use crate::core_crypto::commons::math::decomposition::{ DecompositionLevel, DecompositionTerm, DecompositionTermNonNative, SignedDecomposer, }; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, Distribution, Uniform}; +use crate::core_crypto::commons::math::random::{DefaultRandomGenerator, Distribution, Uniform}; use crate::core_crypto::commons::parameters::{DecompositionBaseLog, PlaintextCount}; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -66,9 +66,8 @@ pub fn ggsw_encryption_multiplicative_factor( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -200,9 +199,8 @@ pub fn encrypt_constant_ggsw_ciphertext::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -465,8 +463,7 @@ pub fn encrypt_constant_seeded_ggsw_ciphertext_with_existing_generator< /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -538,7 +535,7 @@ pub fn encrypt_constant_seeded_ggsw_ciphertext< glwe_secret_key.glwe_dimension() ); - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); @@ -649,8 +646,7 @@ pub fn par_encrypt_constant_seeded_ggsw_ciphertext_with_existing_generator< /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -717,7 +713,7 @@ pub fn par_encrypt_constant_seeded_ggsw_ciphertext< glwe_secret_key.glwe_dimension() ); - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); @@ -825,9 +821,8 @@ fn encrypt_constant_seeded_ggsw_level_matrix_row< /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( diff --git a/tfhe/src/core_crypto/algorithms/glwe_encryption.rs b/tfhe/src/core_crypto/algorithms/glwe_encryption.rs index 5e5aeba858..08fd0d0a88 100644 --- a/tfhe/src/core_crypto/algorithms/glwe_encryption.rs +++ b/tfhe/src/core_crypto/algorithms/glwe_encryption.rs @@ -7,7 +7,7 @@ use crate::core_crypto::algorithms::slice_algorithms::{ }; use crate::core_crypto::commons::ciphertext_modulus::CiphertextModulusKind; use crate::core_crypto::commons::generators::EncryptionRandomGenerator; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, Distribution, Uniform}; +use crate::core_crypto::commons::math::random::{DefaultRandomGenerator, Distribution, Uniform}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -184,9 +184,8 @@ pub fn fill_glwe_mask_and_body_for_encryption_assign_non_native_mod< /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -522,9 +521,8 @@ pub fn fill_glwe_mask_and_body_for_encryption_other_mod< /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -644,9 +642,8 @@ pub fn encrypt_glwe_ciphertext::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -972,8 +969,7 @@ pub fn decrypt_glwe_ciphertext_list( /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the plaintext /// let msg = 3u64; @@ -1067,8 +1063,7 @@ pub fn trivially_encrypt_glwe_ciphertext( /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the plaintext /// let msg = 3u64; @@ -1217,8 +1212,7 @@ pub fn encrypt_seeded_glwe_ciphertext_with_existing_generator< /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -1295,7 +1289,7 @@ pub fn encrypt_seeded_glwe_ciphertext< // Maybe Sized allows to pass Box. NoiseSeeder: Seeder + ?Sized, { - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output_glwe_ciphertext.compression_seed().seed, noise_seeder, ); @@ -1404,8 +1398,7 @@ pub fn encrypt_seeded_glwe_ciphertext_list_with_existing_generator< /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -1486,7 +1479,7 @@ pub fn encrypt_seeded_glwe_ciphertext_list< // Maybe Sized allows to pass Box. NoiseSeeder: Seeder + ?Sized, { - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); diff --git a/tfhe/src/core_crypto/algorithms/glwe_linear_algebra.rs b/tfhe/src/core_crypto/algorithms/glwe_linear_algebra.rs index 3f222a8823..187aa63d70 100644 --- a/tfhe/src/core_crypto/algorithms/glwe_linear_algebra.rs +++ b/tfhe/src/core_crypto/algorithms/glwe_linear_algebra.rs @@ -26,9 +26,8 @@ use crate::core_crypto::entities::*; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -119,9 +118,8 @@ pub fn glwe_ciphertext_add_assign( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -223,9 +221,8 @@ pub fn glwe_ciphertext_add( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -315,9 +312,8 @@ pub fn glwe_ciphertext_plaintext_list_add_assign( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -407,9 +403,8 @@ pub fn glwe_ciphertext_plaintext_list_sub_assign( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -499,9 +494,8 @@ pub fn glwe_ciphertext_plaintext_add_assign( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -590,9 +584,8 @@ pub fn glwe_ciphertext_plaintext_sub_assign( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -671,9 +664,8 @@ where /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -755,9 +747,8 @@ pub fn glwe_ciphertext_cleartext_mul_assign( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -851,9 +842,8 @@ pub fn glwe_ciphertext_cleartext_mul( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -944,9 +934,8 @@ pub fn glwe_ciphertext_sub_assign( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( diff --git a/tfhe/src/core_crypto/algorithms/glwe_sample_extraction.rs b/tfhe/src/core_crypto/algorithms/glwe_sample_extraction.rs index 216d456575..669a56cd21 100644 --- a/tfhe/src/core_crypto/algorithms/glwe_sample_extraction.rs +++ b/tfhe/src/core_crypto/algorithms/glwe_sample_extraction.rs @@ -33,9 +33,8 @@ use rayon::prelude::*; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -192,9 +191,8 @@ pub fn extract_lwe_sample_from_glwe_ciphertext( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -299,9 +297,8 @@ pub fn par_extract_lwe_sample_from_glwe_ciphertext::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( diff --git a/tfhe/src/core_crypto/algorithms/glwe_secret_key_generation.rs b/tfhe/src/core_crypto/algorithms/glwe_secret_key_generation.rs index bcca0813fd..27a7a075ad 100644 --- a/tfhe/src/core_crypto/algorithms/glwe_secret_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/glwe_secret_key_generation.rs @@ -45,8 +45,7 @@ where /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// let mut glwe_secret_key = /// GlweSecretKey::new_empty_key(0u64, glwe_size.to_glwe_dimension(), polynomial_size); diff --git a/tfhe/src/core_crypto/algorithms/lwe_bootstrap_key_generation.rs b/tfhe/src/core_crypto/algorithms/lwe_bootstrap_key_generation.rs index d4358a6609..22577009e6 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_bootstrap_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_bootstrap_key_generation.rs @@ -4,7 +4,7 @@ use crate::core_crypto::algorithms::*; use crate::core_crypto::commons::generators::EncryptionRandomGenerator; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, Distribution, Uniform}; +use crate::core_crypto::commons::math::random::{DefaultRandomGenerator, Distribution, Uniform}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -35,9 +35,8 @@ use rayon::prelude::*; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -208,9 +207,8 @@ where /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -403,7 +401,7 @@ pub fn generate_seeded_lwe_bootstrap_key< output.polynomial_size() ); - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); @@ -526,7 +524,7 @@ pub fn par_generate_seeded_lwe_bootstrap_key< output.polynomial_size() ); - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); diff --git a/tfhe/src/core_crypto/algorithms/lwe_compact_public_key_generation.rs b/tfhe/src/core_crypto/algorithms/lwe_compact_public_key_generation.rs index 1cd911f075..6059227952 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_compact_public_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_compact_public_key_generation.rs @@ -7,7 +7,7 @@ use crate::core_crypto::commons::generators::EncryptionRandomGenerator; use crate::core_crypto::commons::math::random::{Distribution, Uniform}; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; -use crate::core_crypto::prelude::ActivatedRandomGenerator; +use crate::core_crypto::prelude::DefaultRandomGenerator; use slice_algorithms::*; /// Fill an [`LWE compact public key`](`LweCompactPublicKey`) with an actual public key constructed @@ -124,7 +124,7 @@ pub fn generate_seeded_lwe_compact_public_key< output.lwe_dimension() ); - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); diff --git a/tfhe/src/core_crypto/algorithms/lwe_encryption.rs b/tfhe/src/core_crypto/algorithms/lwe_encryption.rs index 0e82160348..bf2bb1215e 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_encryption.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_encryption.rs @@ -8,8 +8,7 @@ use crate::core_crypto::commons::generators::{EncryptionRandomGenerator, SecretR #[cfg(feature = "zk-pok")] use crate::core_crypto::commons::math::random::BoundedDistribution; use crate::core_crypto::commons::math::random::{ - ActivatedRandomGenerator, Distribution, RandomGenerable, RandomGenerator, Uniform, - UniformBinary, + DefaultRandomGenerator, Distribution, RandomGenerable, RandomGenerator, Uniform, UniformBinary, }; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; @@ -202,9 +201,8 @@ pub fn fill_lwe_mask_and_body_for_encryption_other_mod< /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -294,9 +292,8 @@ pub fn encrypt_lwe_ciphertext::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -382,8 +379,7 @@ where /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the plaintext /// let msg = 3u64; @@ -456,8 +452,7 @@ pub fn trivially_encrypt_lwe_ciphertext( /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the plaintext /// let msg = 3u64; @@ -636,9 +631,8 @@ where /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -747,9 +741,8 @@ pub fn encrypt_lwe_ciphertext_list::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -901,9 +894,8 @@ pub fn decrypt_lwe_ciphertext_list( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -1018,8 +1010,7 @@ pub fn encrypt_lwe_ciphertext_with_public_key( /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -1117,8 +1108,7 @@ pub fn encrypt_lwe_ciphertext_with_seeded_public_key::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -1234,7 +1224,7 @@ pub fn encrypt_lwe_ciphertext_iterator_with_seeded_public_key::new(lwe_public_key.compression_seed().seed); + RandomGenerator::::new(lwe_public_key.compression_seed().seed); // Add the public encryption of zeros to get the zero encryption for public_encryption_of_zero_body in lwe_public_key.iter() { @@ -1345,8 +1335,7 @@ pub fn encrypt_seeded_lwe_ciphertext_list_with_existing_generator< /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -1420,7 +1409,7 @@ pub fn encrypt_seeded_lwe_ciphertext_list< // Maybe Sized allows to pass Box. NoiseSeeder: Seeder + ?Sized, { - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); @@ -1514,8 +1503,7 @@ pub fn par_encrypt_seeded_lwe_ciphertext_list_with_existing_generator< /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -1589,7 +1577,7 @@ pub fn par_encrypt_seeded_lwe_ciphertext_list< // Maybe Sized allows to pass Box. NoiseSeeder: Seeder + ?Sized, { - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); @@ -1658,8 +1646,7 @@ pub fn encrypt_seeded_lwe_ciphertext_with_existing_generator< /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -1714,7 +1701,7 @@ pub fn encrypt_seeded_lwe_ciphertext. NoiseSeeder: Seeder + ?Sized, { - let mut encryption_generator = EncryptionRandomGenerator::::new( + let mut encryption_generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); @@ -1750,8 +1737,7 @@ pub fn encrypt_seeded_lwe_ciphertext::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -2039,9 +2025,8 @@ where /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -2156,10 +2141,9 @@ pub fn encrypt_lwe_ciphertext_with_compact_public_key< /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); -/// let mut random_generator = RandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); +/// let mut random_generator = RandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -2502,9 +2486,8 @@ where /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -2645,10 +2628,9 @@ pub fn encrypt_lwe_compact_ciphertext_list_with_compact_public_key< /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); -/// let mut random_generator = RandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); +/// let mut random_generator = RandomGenerator::::new(seeder.seed()); /// /// let crs = CompactPkeCrs::new( /// lwe_dimension, @@ -3032,9 +3014,8 @@ where /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -3179,10 +3160,9 @@ pub fn par_encrypt_lwe_compact_ciphertext_list_with_compact_public_key< /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); -/// let mut random_generator = RandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); +/// let mut random_generator = RandomGenerator::::new(seeder.seed()); /// /// let crs = CompactPkeCrs::new( /// lwe_dimension, @@ -3501,13 +3481,13 @@ mod test { let par_lwe_ct_list = { let mut deterministic_seeder = - DeterministicSeeder::::new(seed); + DeterministicSeeder::::new(seed); let mut secret_random_generator = - SecretRandomGenerator::::new( + SecretRandomGenerator::::new( deterministic_seeder.seed(), ); let mut encryption_random_generator = - EncryptionRandomGenerator::::new( + EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); @@ -3568,13 +3548,13 @@ mod test { let ser_lwe_ct_list = { let mut deterministic_seeder = - DeterministicSeeder::::new(seed); + DeterministicSeeder::::new(seed); let mut secret_random_generator = - SecretRandomGenerator::::new( + SecretRandomGenerator::::new( deterministic_seeder.seed(), ); let mut encryption_random_generator = - EncryptionRandomGenerator::::new( + EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); diff --git a/tfhe/src/core_crypto/algorithms/lwe_keyswitch.rs b/tfhe/src/core_crypto/algorithms/lwe_keyswitch.rs index e16c29ebb7..4346f11b63 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_keyswitch.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_keyswitch.rs @@ -44,9 +44,8 @@ use rayon::prelude::*; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -476,9 +475,8 @@ pub fn keyswitch_lwe_ciphertext_with_scalar_change< /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -584,9 +582,8 @@ pub fn par_keyswitch_lwe_ciphertext( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = diff --git a/tfhe/src/core_crypto/algorithms/lwe_keyswitch_key_generation.rs b/tfhe/src/core_crypto/algorithms/lwe_keyswitch_key_generation.rs index ffbc3b123a..402c838de6 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_keyswitch_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_keyswitch_key_generation.rs @@ -7,7 +7,7 @@ use crate::core_crypto::commons::generators::EncryptionRandomGenerator; use crate::core_crypto::commons::math::decomposition::{ DecompositionLevel, DecompositionTerm, DecompositionTermNonNative, }; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, Distribution, Uniform}; +use crate::core_crypto::commons::math::random::{DefaultRandomGenerator, Distribution, Uniform}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -33,9 +33,8 @@ use crate::core_crypto::entities::*; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -326,8 +325,7 @@ where /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -403,7 +401,7 @@ pub fn generate_seeded_lwe_keyswitch_key< let mut decomposition_plaintexts_buffer = PlaintextListOwned::new(Scalar::ZERO, PlaintextCount(decomp_level_count.0)); - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( lwe_keyswitch_key.compression_seed().seed, noise_seeder, ); diff --git a/tfhe/src/core_crypto/algorithms/lwe_linear_algebra.rs b/tfhe/src/core_crypto/algorithms/lwe_linear_algebra.rs index 9643ee91d9..ebaa123102 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_linear_algebra.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_linear_algebra.rs @@ -26,9 +26,8 @@ use crate::core_crypto::entities::*; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -148,9 +147,8 @@ pub fn lwe_ciphertext_add_assign_other_mod( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -238,9 +236,8 @@ pub fn lwe_ciphertext_add( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -347,9 +344,8 @@ pub fn lwe_ciphertext_plaintext_add_assign_other_mod( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -455,9 +451,8 @@ pub fn lwe_ciphertext_plaintext_sub_assign_other_mod( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -520,9 +515,8 @@ where /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -588,9 +582,8 @@ pub fn lwe_ciphertext_cleartext_mul_assign( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -668,9 +661,8 @@ pub fn lwe_ciphertext_cleartext_mul( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = @@ -747,9 +739,8 @@ pub fn lwe_ciphertext_sub_assign( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let lwe_secret_key = diff --git a/tfhe/src/core_crypto/algorithms/lwe_multi_bit_bootstrap_key_generation.rs b/tfhe/src/core_crypto/algorithms/lwe_multi_bit_bootstrap_key_generation.rs index e5220ec19b..f19ed79f1e 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_multi_bit_bootstrap_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_multi_bit_bootstrap_key_generation.rs @@ -3,7 +3,7 @@ use crate::core_crypto::algorithms::*; use crate::core_crypto::commons::generators::EncryptionRandomGenerator; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, Distribution, Uniform}; +use crate::core_crypto::commons::math::random::{DefaultRandomGenerator, Distribution, Uniform}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -29,9 +29,8 @@ use rayon::prelude::*; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -233,9 +232,8 @@ where /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -517,7 +515,7 @@ pub fn generate_seeded_lwe_multi_bit_bootstrap_key< output.polynomial_size() ); - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); @@ -690,7 +688,7 @@ pub fn par_generate_seeded_lwe_multi_bit_bootstrap_key< output.polynomial_size() ); - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( output.compression_seed().seed, noise_seeder, ); diff --git a/tfhe/src/core_crypto/algorithms/lwe_multi_bit_programmable_bootstrapping.rs b/tfhe/src/core_crypto/algorithms/lwe_multi_bit_programmable_bootstrapping.rs index ea98a62310..34e6754df0 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_multi_bit_programmable_bootstrapping.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_multi_bit_programmable_bootstrapping.rs @@ -174,13 +174,12 @@ pub fn prepare_multi_bit_ggsw_mem_optimized::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create a generator which uses two CSPRNGs to generate public masks and secret encryption /// // noise /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); /// /// println!("Generating keys..."); /// @@ -852,13 +851,12 @@ pub fn multi_bit_deterministic_blind_rotate_assign( /// let seeder = boxed_seeder.as_mut(); /// /// // Create a generator which uses a CSPRNG to generate secret keys -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create a generator which uses two CSPRNGs to generate public masks and secret encryption /// // noise /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); /// /// println!("Generating keys..."); /// diff --git a/tfhe/src/core_crypto/algorithms/lwe_packing_keyswitch.rs b/tfhe/src/core_crypto/algorithms/lwe_packing_keyswitch.rs index 01987f5086..2eaf4e4b4b 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_packing_keyswitch.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_packing_keyswitch.rs @@ -34,9 +34,8 @@ use rayon::prelude::*; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -212,9 +211,8 @@ pub fn keyswitch_lwe_ciphertext_into_glwe_ciphertext::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -405,9 +403,8 @@ pub fn keyswitch_lwe_ciphertext_list_and_pack_in_glwe_ciphertext< /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -540,9 +537,8 @@ pub fn par_keyswitch_lwe_ciphertext_list_and_pack_in_glwe_ciphertext< /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = diff --git a/tfhe/src/core_crypto/algorithms/lwe_packing_keyswitch_key_generation.rs b/tfhe/src/core_crypto/algorithms/lwe_packing_keyswitch_key_generation.rs index 2f09fe942c..287fc9f89f 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_packing_keyswitch_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_packing_keyswitch_key_generation.rs @@ -7,7 +7,7 @@ use crate::core_crypto::algorithms::{ }; use crate::core_crypto::commons::generators::EncryptionRandomGenerator; use crate::core_crypto::commons::math::decomposition::{DecompositionLevel, DecompositionTerm}; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, Distribution, Uniform}; +use crate::core_crypto::commons::math::random::{DefaultRandomGenerator, Distribution, Uniform}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::{ @@ -38,9 +38,8 @@ use crate::core_crypto::entities::{ /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -228,8 +227,7 @@ where /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the LweSecretKey /// let input_lwe_secret_key = @@ -317,7 +315,7 @@ pub fn generate_seeded_lwe_packing_keyswitch_key< PlaintextCount(decomp_level_count.0 * polynomial_size.0), ); - let mut generator = EncryptionRandomGenerator::::new( + let mut generator = EncryptionRandomGenerator::::new( lwe_packing_keyswitch_key.compression_seed().seed, noise_seeder, ); diff --git a/tfhe/src/core_crypto/algorithms/lwe_private_functional_packing_keyswitch_key_generation.rs b/tfhe/src/core_crypto/algorithms/lwe_private_functional_packing_keyswitch_key_generation.rs index b8e480dd96..930770393d 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_private_functional_packing_keyswitch_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_private_functional_packing_keyswitch_key_generation.rs @@ -283,7 +283,7 @@ mod test { // Create the PRNG let mut seeder = new_seeder(); let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + SecretRandomGenerator::::new(seeder.seed()); let glwe_sk: GlweSecretKeyOwned = allocate_and_generate_new_binary_glwe_secret_key( glwe_dimension, @@ -293,12 +293,11 @@ mod test { let lwe_big_sk = glwe_sk.clone().into_lwe_secret_key(); let mut seeder = - DeterministicSeeder::::new(common_encryption_seed); - let mut encryption_generator = - EncryptionRandomGenerator::::new( - seeder.seed(), - &mut seeder, - ); + DeterministicSeeder::::new(common_encryption_seed); + let mut encryption_generator = EncryptionRandomGenerator::::new( + seeder.seed(), + &mut seeder, + ); let par_cbs_pfpksk = par_allocate_and_generate_new_circuit_bootstrap_lwe_pfpksk_list( &lwe_big_sk, @@ -311,12 +310,11 @@ mod test { ); let mut seeder = - DeterministicSeeder::::new(common_encryption_seed); - let mut encryption_generator = - EncryptionRandomGenerator::::new( - seeder.seed(), - &mut seeder, - ); + DeterministicSeeder::::new(common_encryption_seed); + let mut encryption_generator = EncryptionRandomGenerator::::new( + seeder.seed(), + &mut seeder, + ); let ser_cbs_pfpksk = allocate_and_generate_new_circuit_bootstrap_lwe_pfpksk_list( &lwe_big_sk, diff --git a/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/fft128.rs b/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/fft128.rs index f95fad5c4a..702dc7ffc7 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/fft128.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/fft128.rs @@ -49,13 +49,12 @@ use dyn_stack::{PodStack, SizeOverflow, StackReq}; /// let seeder = boxed_seeder.as_mut(); /// /// // Create a generator which uses a CSPRNG to generate secret keys -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create a generator which uses two CSPRNGs to generate public masks and secret encryption /// // noise /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); /// /// println!("Generating keys..."); /// diff --git a/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/fft64.rs b/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/fft64.rs index 9a79650ec2..311e059388 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/fft64.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/fft64.rs @@ -55,13 +55,12 @@ use tfhe_fft::c64; /// let seeder = boxed_seeder.as_mut(); /// /// // Create a generator which uses a CSPRNG to generate secret keys -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create a generator which uses two CSPRNGs to generate public masks and secret encryption /// // noise /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); /// /// println!("Generating keys..."); /// @@ -343,9 +342,8 @@ pub fn add_external_product_assign::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -579,9 +577,8 @@ pub fn cmux_assign( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key( @@ -824,13 +821,12 @@ pub fn cmux_assign_mem_optimized_requirement( /// let seeder = boxed_seeder.as_mut(); /// /// // Create a generator which uses a CSPRNG to generate secret keys -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create a generator which uses two CSPRNGs to generate public masks and secret encryption /// // noise /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); /// /// println!("Generating keys..."); /// diff --git a/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/ntt64.rs b/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/ntt64.rs index 83dbc1d3ff..76364e1d5f 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/ntt64.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping/ntt64.rs @@ -56,13 +56,12 @@ use dyn_stack::{PodStack, SizeOverflow, StackReq}; /// let seeder = boxed_seeder.as_mut(); /// /// // Create a generator which uses a CSPRNG to generate secret keys -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create a generator which uses two CSPRNGs to generate public masks and secret encryption /// // noise /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); /// /// println!("Generating keys..."); /// @@ -312,13 +311,12 @@ pub fn blind_rotate_ntt64_assign_mem_optimized( /// let seeder = boxed_seeder.as_mut(); /// /// // Create a generator which uses a CSPRNG to generate secret keys -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create a generator which uses two CSPRNGs to generate public masks and secret encryption /// // noise /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); /// /// println!("Generating keys..."); /// diff --git a/tfhe/src/core_crypto/algorithms/lwe_secret_key_generation.rs b/tfhe/src/core_crypto/algorithms/lwe_secret_key_generation.rs index 62df2b658a..39306d86f7 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_secret_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_secret_key_generation.rs @@ -41,8 +41,7 @@ where /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// let mut lwe_secret_key = LweSecretKey::new_empty_key(0u64, lwe_dimension); /// diff --git a/tfhe/src/core_crypto/algorithms/lwe_wopbs.rs b/tfhe/src/core_crypto/algorithms/lwe_wopbs.rs index 513baa2b74..902d1adb3e 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_wopbs.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_wopbs.rs @@ -437,9 +437,8 @@ pub fn extract_bits_from_lwe_ciphertext_mem_optimized_requirement( /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// let glwe_sk = allocate_and_generate_new_binary_glwe_secret_key( /// glwe_dimension, diff --git a/tfhe/src/core_crypto/algorithms/test/ggsw_encryption.rs b/tfhe/src/core_crypto/algorithms/test/ggsw_encryption.rs index c7fa0910be..31ec363b98 100644 --- a/tfhe/src/core_crypto/algorithms/test/ggsw_encryption.rs +++ b/tfhe/src/core_crypto/algorithms/test/ggsw_encryption.rs @@ -28,8 +28,7 @@ fn test_parallel_and_seeded_ggsw_encryption_equivalence( let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let main_seed = seeder.seed(); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for _ in 0..NB_TESTS { // Create the GlweSecretKey @@ -55,9 +54,9 @@ fn test_parallel_and_seeded_ggsw_encryption_equivalence( ); let mut deterministic_seeder = - DeterministicSeeder::::new(main_seed); + DeterministicSeeder::::new(main_seed); - let mut encryption_generator = EncryptionRandomGenerator::::new( + let mut encryption_generator = EncryptionRandomGenerator::::new( compression_seed.seed, &mut deterministic_seeder, ); @@ -80,9 +79,9 @@ fn test_parallel_and_seeded_ggsw_encryption_equivalence( ); let mut deterministic_seeder = - DeterministicSeeder::::new(main_seed); + DeterministicSeeder::::new(main_seed); - let mut encryption_generator = EncryptionRandomGenerator::::new( + let mut encryption_generator = EncryptionRandomGenerator::::new( compression_seed.seed, &mut deterministic_seeder, ); @@ -109,7 +108,7 @@ fn test_parallel_and_seeded_ggsw_encryption_equivalence( ); let mut deterministic_seeder = - DeterministicSeeder::::new(main_seed); + DeterministicSeeder::::new(main_seed); encrypt_constant_seeded_ggsw_ciphertext( &glwe_secret_key, @@ -130,7 +129,7 @@ fn test_parallel_and_seeded_ggsw_encryption_equivalence( ); let mut deterministic_seeder = - DeterministicSeeder::::new(main_seed); + DeterministicSeeder::::new(main_seed); par_encrypt_constant_seeded_ggsw_ciphertext( &glwe_secret_key, diff --git a/tfhe/src/core_crypto/algorithms/test/lwe_bootstrap_key_generation.rs b/tfhe/src/core_crypto/algorithms/test/lwe_bootstrap_key_generation.rs index dcf31e34b8..ea4b04fe91 100644 --- a/tfhe/src/core_crypto/algorithms/test/lwe_bootstrap_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/test/lwe_bootstrap_key_generation.rs @@ -2,7 +2,7 @@ use crate::core_crypto::algorithms::*; use crate::core_crypto::commons::dispersion::StandardDev; use crate::core_crypto::commons::generators::{DeterministicSeeder, EncryptionRandomGenerator}; use crate::core_crypto::commons::math::random::{ - ActivatedRandomGenerator, DynamicDistribution, Seed, + DefaultRandomGenerator, DynamicDistribution, Seed, }; use crate::core_crypto::commons::math::torus::UnsignedTorus; use crate::core_crypto::commons::parameters::{ @@ -59,9 +59,9 @@ fn test_parallel_and_seeded_bsk_gen_equivalence( ciphertext_modulus, ); - let mut encryption_generator = EncryptionRandomGenerator::::new( + let mut encryption_generator = EncryptionRandomGenerator::::new( mask_seed, - &mut DeterministicSeeder::::new(deterministic_seeder_seed), + &mut DeterministicSeeder::::new(deterministic_seeder_seed), ); par_generate_lwe_bootstrap_key( @@ -82,9 +82,9 @@ fn test_parallel_and_seeded_bsk_gen_equivalence( ciphertext_modulus, ); - let mut encryption_generator = EncryptionRandomGenerator::::new( + let mut encryption_generator = EncryptionRandomGenerator::::new( mask_seed, - &mut DeterministicSeeder::::new(deterministic_seeder_seed), + &mut DeterministicSeeder::::new(deterministic_seeder_seed), ); generate_lwe_bootstrap_key( @@ -113,7 +113,7 @@ fn test_parallel_and_seeded_bsk_gen_equivalence( &glwe_sk, &mut sequential_seeded_bsk, noise_distribution, - &mut DeterministicSeeder::::new(deterministic_seeder_seed), + &mut DeterministicSeeder::::new(deterministic_seeder_seed), ); let mut parallel_seeded_bsk = SeededLweBootstrapKey::new( @@ -132,7 +132,7 @@ fn test_parallel_and_seeded_bsk_gen_equivalence( &glwe_sk, &mut parallel_seeded_bsk, noise_distribution, - &mut DeterministicSeeder::::new(deterministic_seeder_seed), + &mut DeterministicSeeder::::new(deterministic_seeder_seed), ); assert_eq!(sequential_seeded_bsk, parallel_seeded_bsk); diff --git a/tfhe/src/core_crypto/algorithms/test/lwe_compact_public_key_generation.rs b/tfhe/src/core_crypto/algorithms/test/lwe_compact_public_key_generation.rs index 2571f97a35..d3e60833a5 100644 --- a/tfhe/src/core_crypto/algorithms/test/lwe_compact_public_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/test/lwe_compact_public_key_generation.rs @@ -21,8 +21,7 @@ fn test_seeded_lwe_cpk_gen_equivalence( let seeder = seeder.as_mut(); let mask_seed = seeder.seed(); let deterministic_seeder_seed = seeder.seed(); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for _ in 0..NB_TESTS { // Create the LweSecretKey @@ -32,8 +31,8 @@ fn test_seeded_lwe_cpk_gen_equivalence( let mut cpk = LweCompactPublicKey::new(Scalar::ZERO, lwe_dimension, ciphertext_modulus); let mut deterministic_seeder = - DeterministicSeeder::::new(deterministic_seeder_seed); - let mut encryption_generator = EncryptionRandomGenerator::::new( + DeterministicSeeder::::new(deterministic_seeder_seed); + let mut encryption_generator = EncryptionRandomGenerator::::new( mask_seed, &mut deterministic_seeder, ); @@ -58,7 +57,7 @@ fn test_seeded_lwe_cpk_gen_equivalence( ); let mut deterministic_seeder = - DeterministicSeeder::::new(deterministic_seeder_seed); + DeterministicSeeder::::new(deterministic_seeder_seed); generate_seeded_lwe_compact_public_key( &input_lwe_secret_key, diff --git a/tfhe/src/core_crypto/algorithms/test/lwe_encryption.rs b/tfhe/src/core_crypto/algorithms/test/lwe_encryption.rs index 6b5f09adb9..09e06ca2c1 100644 --- a/tfhe/src/core_crypto/algorithms/test/lwe_encryption.rs +++ b/tfhe/src/core_crypto/algorithms/test/lwe_encryption.rs @@ -27,8 +27,7 @@ fn parallel_and_seeded_lwe_list_encryption_equivalence::new(seeder.seed()); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for _ in 0..NB_TESTS { // Create the LweSecretKey @@ -48,8 +47,8 @@ fn parallel_and_seeded_lwe_list_encryption_equivalence::new(main_seed); - let mut encryption_generator = EncryptionRandomGenerator::::new( + DeterministicSeeder::::new(main_seed); + let mut encryption_generator = EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); @@ -69,8 +68,8 @@ fn parallel_and_seeded_lwe_list_encryption_equivalence::new(main_seed); - let mut encryption_generator = EncryptionRandomGenerator::::new( + DeterministicSeeder::::new(main_seed); + let mut encryption_generator = EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); @@ -85,7 +84,7 @@ fn parallel_and_seeded_lwe_list_encryption_equivalence::new(main_seed); + DeterministicSeeder::::new(main_seed); // Create a new LweCiphertextList let mut par_seeded_lwe_list = SeededLweCiphertextList::new( Scalar::ZERO, @@ -104,7 +103,7 @@ fn parallel_and_seeded_lwe_list_encryption_equivalence::new(main_seed); + DeterministicSeeder::::new(main_seed); let mut ser_seeded_lwe_list = SeededLweCiphertextList::new( Scalar::ZERO, @@ -871,9 +870,8 @@ fn test_u128_encryption() { let mut seeder = new_seeder(); let seeder = seeder.as_mut(); let mut encryption_generator = - EncryptionRandomGenerator::::new(seeder.seed(), seeder); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + EncryptionRandomGenerator::::new(seeder.seed(), seeder); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); const MSG_BITS: u32 = 4; @@ -1016,7 +1014,7 @@ fn lwe_compact_public_encrypt_prove_verify_decrypt_custom_mod( let metadata = [b'c', b'o', b'r', b'e']; let mut rsc = TestResources::new(); - let mut random_generator = RandomGenerator::::new(rsc.seeder.seed()); + let mut random_generator = RandomGenerator::::new(rsc.seeder.seed()); let msg_modulus = Scalar::ONE.shl(message_modulus_log.0); let mut msg = msg_modulus; @@ -1146,14 +1144,13 @@ fn test_par_compact_lwe_list_public_key_encryption_and_proof() { .collect::>(); let par_lwe_ct_list = { - let mut deterministic_seeder = - DeterministicSeeder::::new(seed); + let mut deterministic_seeder = DeterministicSeeder::::new(seed); let mut random_generator = - RandomGenerator::::new(deterministic_seeder.seed()); + RandomGenerator::::new(deterministic_seeder.seed()); let mut secret_random_generator = - SecretRandomGenerator::::new(deterministic_seeder.seed()); + SecretRandomGenerator::::new(deterministic_seeder.seed()); let mut encryption_random_generator = - EncryptionRandomGenerator::::new( + EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); @@ -1238,14 +1235,13 @@ fn test_par_compact_lwe_list_public_key_encryption_and_proof() { }; let ser_lwe_ct_list = { - let mut deterministic_seeder = - DeterministicSeeder::::new(seed); + let mut deterministic_seeder = DeterministicSeeder::::new(seed); let mut random_generator = - RandomGenerator::::new(deterministic_seeder.seed()); + RandomGenerator::::new(deterministic_seeder.seed()); let mut secret_random_generator = - SecretRandomGenerator::::new(deterministic_seeder.seed()); + SecretRandomGenerator::::new(deterministic_seeder.seed()); let mut encryption_random_generator = - EncryptionRandomGenerator::::new( + EncryptionRandomGenerator::::new( deterministic_seeder.seed(), &mut deterministic_seeder, ); diff --git a/tfhe/src/core_crypto/algorithms/test/lwe_keyswitch_key_generation.rs b/tfhe/src/core_crypto/algorithms/test/lwe_keyswitch_key_generation.rs index 4ae42e142e..cb8803b8a7 100644 --- a/tfhe/src/core_crypto/algorithms/test/lwe_keyswitch_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/test/lwe_keyswitch_key_generation.rs @@ -24,8 +24,7 @@ fn test_seeded_lwe_ksk_gen_equivalence( let seeder = seeder.as_mut(); let mask_seed = seeder.seed(); let deterministic_seeder_seed = seeder.seed(); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for _ in 0..NB_TESTS { // Create the LweSecretKey @@ -48,8 +47,8 @@ fn test_seeded_lwe_ksk_gen_equivalence( ); let mut deterministic_seeder = - DeterministicSeeder::::new(deterministic_seeder_seed); - let mut encryption_generator = EncryptionRandomGenerator::::new( + DeterministicSeeder::::new(deterministic_seeder_seed); + let mut encryption_generator = EncryptionRandomGenerator::::new( mask_seed, &mut deterministic_seeder, ); @@ -78,7 +77,7 @@ fn test_seeded_lwe_ksk_gen_equivalence( ); let mut deterministic_seeder = - DeterministicSeeder::::new(deterministic_seeder_seed); + DeterministicSeeder::::new(deterministic_seeder_seed); generate_seeded_lwe_keyswitch_key( &input_lwe_secret_key, diff --git a/tfhe/src/core_crypto/algorithms/test/lwe_multi_bit_bootstrap_key_generation.rs b/tfhe/src/core_crypto/algorithms/test/lwe_multi_bit_bootstrap_key_generation.rs index 85d052a4c9..1ed8c99fb6 100644 --- a/tfhe/src/core_crypto/algorithms/test/lwe_multi_bit_bootstrap_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/test/lwe_multi_bit_bootstrap_key_generation.rs @@ -2,7 +2,7 @@ use crate::core_crypto::algorithms::*; use crate::core_crypto::commons::dispersion::StandardDev; use crate::core_crypto::commons::generators::{DeterministicSeeder, EncryptionRandomGenerator}; use crate::core_crypto::commons::math::random::{ - ActivatedRandomGenerator, DynamicDistribution, Seed, + DefaultRandomGenerator, DynamicDistribution, Seed, }; use crate::core_crypto::commons::math::torus::UnsignedTorus; use crate::core_crypto::commons::parameters::{ @@ -70,9 +70,9 @@ fn test_parallel_and_seeded_multi_bit_bsk_gen_equivalence< ciphertext_modulus, ); - let mut encryption_generator = EncryptionRandomGenerator::::new( + let mut encryption_generator = EncryptionRandomGenerator::::new( mask_seed, - &mut DeterministicSeeder::::new(deterministic_seeder_seed), + &mut DeterministicSeeder::::new(deterministic_seeder_seed), ); par_generate_lwe_multi_bit_bootstrap_key( @@ -94,9 +94,9 @@ fn test_parallel_and_seeded_multi_bit_bsk_gen_equivalence< ciphertext_modulus, ); - let mut encryption_generator = EncryptionRandomGenerator::::new( + let mut encryption_generator = EncryptionRandomGenerator::::new( mask_seed, - &mut DeterministicSeeder::::new(deterministic_seeder_seed), + &mut DeterministicSeeder::::new(deterministic_seeder_seed), ); generate_lwe_multi_bit_bootstrap_key( @@ -126,7 +126,7 @@ fn test_parallel_and_seeded_multi_bit_bsk_gen_equivalence< &glwe_sk, &mut sequential_seeded_multi_bit_bsk, noise_distribution, - &mut DeterministicSeeder::::new(deterministic_seeder_seed), + &mut DeterministicSeeder::::new(deterministic_seeder_seed), ); let mut parallel_seeded_multi_bit_bsk = SeededLweMultiBitBootstrapKey::new( @@ -146,7 +146,7 @@ fn test_parallel_and_seeded_multi_bit_bsk_gen_equivalence< &glwe_sk, &mut parallel_seeded_multi_bit_bsk, noise_distribution, - &mut DeterministicSeeder::::new(deterministic_seeder_seed), + &mut DeterministicSeeder::::new(deterministic_seeder_seed), ); assert_eq!( diff --git a/tfhe/src/core_crypto/algorithms/test/lwe_packing_keyswitch_key_generation.rs b/tfhe/src/core_crypto/algorithms/test/lwe_packing_keyswitch_key_generation.rs index edc62ae884..5a21c79e50 100644 --- a/tfhe/src/core_crypto/algorithms/test/lwe_packing_keyswitch_key_generation.rs +++ b/tfhe/src/core_crypto/algorithms/test/lwe_packing_keyswitch_key_generation.rs @@ -26,8 +26,7 @@ fn test_seeded_lwe_pksk_gen_equivalence( let seeder = seeder.as_mut(); let mask_seed = seeder.seed(); let deterministic_seeder_seed = seeder.seed(); - let mut secret_generator = - SecretRandomGenerator::::new(seeder.seed()); + let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); for _ in 0..NB_TESTS { // Create the LweSecretKey @@ -52,8 +51,8 @@ fn test_seeded_lwe_pksk_gen_equivalence( ); let mut deterministic_seeder = - DeterministicSeeder::::new(deterministic_seeder_seed); - let mut encryption_generator = EncryptionRandomGenerator::::new( + DeterministicSeeder::::new(deterministic_seeder_seed); + let mut encryption_generator = EncryptionRandomGenerator::::new( mask_seed, &mut deterministic_seeder, ); @@ -83,7 +82,7 @@ fn test_seeded_lwe_pksk_gen_equivalence( ); let mut deterministic_seeder = - DeterministicSeeder::::new(deterministic_seeder_seed); + DeterministicSeeder::::new(deterministic_seeder_seed); generate_seeded_lwe_packing_keyswitch_key( &input_lwe_secret_key, diff --git a/tfhe/src/core_crypto/algorithms/test/mod.rs b/tfhe/src/core_crypto/algorithms/test/mod.rs index a7edb1db89..947e8c0ad8 100644 --- a/tfhe/src/core_crypto/algorithms/test/mod.rs +++ b/tfhe/src/core_crypto/algorithms/test/mod.rs @@ -28,8 +28,8 @@ mod noise_distribution; pub struct TestResources { pub seeder: Box, - pub encryption_random_generator: EncryptionRandomGenerator, - pub secret_random_generator: SecretRandomGenerator, + pub encryption_random_generator: EncryptionRandomGenerator, + pub secret_random_generator: SecretRandomGenerator, } impl TestResources { diff --git a/tfhe/src/core_crypto/commons/math/random/activated_random_generator.rs b/tfhe/src/core_crypto/commons/math/random/activated_random_generator.rs index 8aa7d19f79..62c987a58a 100644 --- a/tfhe/src/core_crypto/commons/math/random/activated_random_generator.rs +++ b/tfhe/src/core_crypto/commons/math/random/activated_random_generator.rs @@ -1,19 +1,19 @@ -#[cfg(feature = "generator_x86_64_aesni")] +#[cfg(all(target_arch = "x86_64", not(feature = "software-prng")))] use tfhe_csprng::generators::AesniRandomGenerator; -#[cfg(feature = "generator_aarch64_aes")] +#[cfg(all(target_arch = "aarch64", not(feature = "software-prng")))] use tfhe_csprng::generators::NeonAesRandomGenerator; -#[cfg(all( - not(feature = "generator_x86_64_aesni"), - not(feature = "generator_aarch64_aes") +#[cfg(any( + feature = "software-prng", + not(any(target_arch = "x86_64", target_arch = "aarch64")) ))] use tfhe_csprng::generators::SoftwareRandomGenerator; -#[cfg(feature = "generator_x86_64_aesni")] +#[cfg(all(target_arch = "x86_64", not(feature = "software-prng")))] pub type ActivatedRandomGenerator = AesniRandomGenerator; -#[cfg(feature = "generator_aarch64_aes")] +#[cfg(all(target_arch = "aarch64", not(feature = "software-prng")))] pub type ActivatedRandomGenerator = NeonAesRandomGenerator; -#[cfg(all( - not(feature = "generator_x86_64_aesni"), - not(feature = "generator_aarch64_aes") +#[cfg(any( + feature = "software-prng", + not(any(target_arch = "x86_64", target_arch = "aarch64")) ))] pub type ActivatedRandomGenerator = SoftwareRandomGenerator; diff --git a/tfhe/src/core_crypto/commons/math/random/mod.rs b/tfhe/src/core_crypto/commons/math/random/mod.rs index 4999a26554..b3ed2477c9 100644 --- a/tfhe/src/core_crypto/commons/math/random/mod.rs +++ b/tfhe/src/core_crypto/commons/math/random/mod.rs @@ -19,11 +19,10 @@ use crate::core_crypto::commons::numeric::{FloatingPoint, UnsignedInteger}; use std::ops::Bound; use crate::core_crypto::prelude::{CastInto, Numeric}; -/// Convenience alias for the most efficient CSPRNG implementation available. -pub use activated_random_generator::ActivatedRandomGenerator; pub use gaussian::*; pub use generator::*; pub use t_uniform::*; +pub use tfhe_csprng::generators::DefaultRandomGenerator; use tfhe_versionable::Versionize; pub use uniform::*; pub use uniform_binary::*; @@ -32,7 +31,6 @@ pub use uniform_ternary::*; #[cfg(test)] mod tests; -mod activated_random_generator; mod gaussian; mod generator; mod t_uniform; diff --git a/tfhe/src/core_crypto/commons/mod.rs b/tfhe/src/core_crypto/commons/mod.rs index 8ceb64d110..0bc0b664c9 100644 --- a/tfhe/src/core_crypto/commons/mod.rs +++ b/tfhe/src/core_crypto/commons/mod.rs @@ -36,7 +36,7 @@ pub mod test_tools { EncryptionRandomGenerator, SecretRandomGenerator, }; use crate::core_crypto::commons::math::random::{ - ActivatedRandomGenerator, RandomGenerable, RandomGenerator, Uniform, + DefaultRandomGenerator, RandomGenerable, RandomGenerator, Uniform, }; use crate::core_crypto::commons::parameters::{ CiphertextCount, DecompositionBaseLog, DecompositionLevelCount, GlweDimension, @@ -53,16 +53,15 @@ pub mod test_tools { ) } - pub fn new_random_generator() -> RandomGenerator { + pub fn new_random_generator() -> RandomGenerator { RandomGenerator::new(random_seed()) } - pub fn new_secret_random_generator() -> SecretRandomGenerator { + pub fn new_secret_random_generator() -> SecretRandomGenerator { SecretRandomGenerator::new(random_seed()) } - pub fn new_encryption_random_generator() -> EncryptionRandomGenerator - { + pub fn new_encryption_random_generator() -> EncryptionRandomGenerator { EncryptionRandomGenerator::new(random_seed(), &mut UnsafeRandSeeder) } diff --git a/tfhe/src/core_crypto/entities/compressed_modulus_switched_glwe_ciphertext.rs b/tfhe/src/core_crypto/entities/compressed_modulus_switched_glwe_ciphertext.rs index a2dd144139..0915079f8a 100644 --- a/tfhe/src/core_crypto/entities/compressed_modulus_switched_glwe_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/compressed_modulus_switched_glwe_ciphertext.rs @@ -25,7 +25,7 @@ use crate::core_crypto::prelude::*; /// Gaussian::from_dispersion_parameter(StandardDev(0.00000000000000029403601535432533), 0.0); /// let ciphertext_modulus = CiphertextModulus::new_native(); /// -/// let mut secret_generator = SecretRandomGenerator::::new(Seed(0)); +/// let mut secret_generator = SecretRandomGenerator::::new(Seed(0)); /// /// let glwe_secret_key = allocate_and_generate_new_binary_glwe_secret_key::( /// glwe_size.to_glwe_dimension(), @@ -37,7 +37,7 @@ use crate::core_crypto::prelude::*; /// let seeder = seeder.as_mut(); /// /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); /// /// let inputs = [1 << 57, 1 << 58]; /// diff --git a/tfhe/src/core_crypto/entities/compressed_modulus_switched_lwe_ciphertext.rs b/tfhe/src/core_crypto/entities/compressed_modulus_switched_lwe_ciphertext.rs index f056754d67..31ad542f41 100644 --- a/tfhe/src/core_crypto/entities/compressed_modulus_switched_lwe_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/compressed_modulus_switched_lwe_ciphertext.rs @@ -20,7 +20,7 @@ use crate::core_crypto::prelude::*; /// /// let log_modulus = 12; /// -/// let mut secret_generator = SecretRandomGenerator::::new(Seed(0)); +/// let mut secret_generator = SecretRandomGenerator::::new(Seed(0)); /// /// // Create the LweSecretKey /// let lwe_secret_key = allocate_and_generate_new_binary_lwe_secret_key::( @@ -33,7 +33,7 @@ use crate::core_crypto::prelude::*; /// let seeder = seeder.as_mut(); /// /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); /// /// // Unsecure parameters, do not use them /// let lwe = allocate_and_encrypt_new_lwe_ciphertext( diff --git a/tfhe/src/core_crypto/entities/compressed_modulus_switched_multi_bit_lwe_ciphertext.rs b/tfhe/src/core_crypto/entities/compressed_modulus_switched_multi_bit_lwe_ciphertext.rs index 9414be7615..438d5524eb 100644 --- a/tfhe/src/core_crypto/entities/compressed_modulus_switched_multi_bit_lwe_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/compressed_modulus_switched_multi_bit_lwe_ciphertext.rs @@ -35,13 +35,12 @@ use tfhe_versionable::Versionize; /// let seeder = boxed_seeder.as_mut(); /// /// // Create a generator which uses a CSPRNG to generate secret keys -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create a generator which uses two CSPRNGs to generate public masks and secret encryption /// // noise /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); /// /// // Generate an LweSecretKey with binary coefficients /// let small_lwe_sk = diff --git a/tfhe/src/core_crypto/entities/glwe_secret_key.rs b/tfhe/src/core_crypto/entities/glwe_secret_key.rs index 76c54f505f..bb02f230d8 100644 --- a/tfhe/src/core_crypto/entities/glwe_secret_key.rs +++ b/tfhe/src/core_crypto/entities/glwe_secret_key.rs @@ -206,8 +206,7 @@ where /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); - /// let mut secret_generator = - /// SecretRandomGenerator::::new(seeder.seed()); + /// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// let glwe_secret_key: GlweSecretKeyOwned = GlweSecretKey::generate_new_binary( /// glwe_size.to_glwe_dimension(), diff --git a/tfhe/src/core_crypto/entities/lwe_secret_key.rs b/tfhe/src/core_crypto/entities/lwe_secret_key.rs index f5f6394ad9..ad67866108 100644 --- a/tfhe/src/core_crypto/entities/lwe_secret_key.rs +++ b/tfhe/src/core_crypto/entities/lwe_secret_key.rs @@ -154,8 +154,7 @@ where /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); - /// let mut secret_generator = - /// SecretRandomGenerator::::new(seeder.seed()); + /// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// let lwe_secret_key: LweSecretKeyOwned = /// LweSecretKey::generate_new_binary(lwe_dimension, &mut secret_generator); diff --git a/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext.rs b/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext.rs index 8b0572a657..ba33106c82 100644 --- a/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext.rs @@ -8,7 +8,7 @@ use crate::core_crypto::commons::generators::{ EncryptionRandomGeneratorForkConfig, MaskRandomGeneratorForkConfig, }; use crate::core_crypto::commons::math::random::{ - ActivatedRandomGenerator, CompressionSeed, Distribution, RandomGenerable, + CompressionSeed, DefaultRandomGenerator, Distribution, RandomGenerable, }; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; @@ -280,7 +280,7 @@ impl> SeededGgswCipherte self.decomposition_level_count(), self.ciphertext_modulus(), ); - decompress_seeded_ggsw_ciphertext::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_ggsw_ciphertext::<_, _, _, DefaultRandomGenerator>( &mut decompressed_ct, &self, ); @@ -301,7 +301,7 @@ impl> SeededGgswCipherte self.decomposition_level_count(), self.ciphertext_modulus(), ); - par_decompress_seeded_ggsw_ciphertext::<_, _, _, ActivatedRandomGenerator>( + par_decompress_seeded_ggsw_ciphertext::<_, _, _, DefaultRandomGenerator>( &mut decompressed_ct, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext_list.rs b/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext_list.rs index 7a74f4bb1c..d111c45168 100644 --- a/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext_list.rs +++ b/tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext_list.rs @@ -7,7 +7,7 @@ use crate::core_crypto::commons::generators::{ EncryptionRandomGeneratorForkConfig, MaskRandomGeneratorForkConfig, }; use crate::core_crypto::commons::math::random::{ - ActivatedRandomGenerator, CompressionSeed, Distribution, RandomGenerable, + CompressionSeed, DefaultRandomGenerator, Distribution, RandomGenerable, }; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; @@ -243,7 +243,7 @@ impl> SeededGgswCipherte self.ggsw_ciphertext_count(), self.ciphertext_modulus(), ); - decompress_seeded_ggsw_ciphertext_list::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_ggsw_ciphertext_list::<_, _, _, DefaultRandomGenerator>( &mut decompressed_list, &self, ); @@ -265,7 +265,7 @@ impl> SeededGgswCipherte self.ggsw_ciphertext_count(), self.ciphertext_modulus(), ); - par_decompress_seeded_ggsw_ciphertext_list::<_, _, _, ActivatedRandomGenerator>( + par_decompress_seeded_ggsw_ciphertext_list::<_, _, _, DefaultRandomGenerator>( &mut decompressed_list, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_glwe_ciphertext.rs b/tfhe/src/core_crypto/entities/seeded_glwe_ciphertext.rs index be16920e6a..f2a1d3d1c7 100644 --- a/tfhe/src/core_crypto/entities/seeded_glwe_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/seeded_glwe_ciphertext.rs @@ -6,7 +6,7 @@ use tfhe_versionable::Versionize; use crate::conformance::ParameterSetConformant; use crate::core_crypto::algorithms::*; use crate::core_crypto::backward_compatibility::entities::seeded_glwe_ciphertext::SeededGlweCiphertextVersions; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, CompressionSeed}; +use crate::core_crypto::commons::math::random::{CompressionSeed, DefaultRandomGenerator}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -201,7 +201,7 @@ impl> SeededGlweCipherte self.polynomial_size(), self.ciphertext_modulus(), ); - decompress_seeded_glwe_ciphertext::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_glwe_ciphertext::<_, _, _, DefaultRandomGenerator>( &mut decompressed_ct, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_glwe_ciphertext_list.rs b/tfhe/src/core_crypto/entities/seeded_glwe_ciphertext_list.rs index b925b57000..7ce0c9ff74 100644 --- a/tfhe/src/core_crypto/entities/seeded_glwe_ciphertext_list.rs +++ b/tfhe/src/core_crypto/entities/seeded_glwe_ciphertext_list.rs @@ -4,7 +4,7 @@ use tfhe_versionable::Versionize; use crate::core_crypto::algorithms::*; use crate::core_crypto::backward_compatibility::entities::seeded_glwe_ciphertext_list::SeededGlweCiphertextListVersions; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, CompressionSeed}; +use crate::core_crypto::commons::math::random::{CompressionSeed, DefaultRandomGenerator}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -188,7 +188,7 @@ impl> SeededGlweCipherte self.glwe_ciphertext_count(), self.ciphertext_modulus(), ); - decompress_seeded_glwe_ciphertext_list::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_glwe_ciphertext_list::<_, _, _, DefaultRandomGenerator>( &mut decompressed_list, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_bootstrap_key.rs b/tfhe/src/core_crypto/entities/seeded_lwe_bootstrap_key.rs index d80cfc9399..34d171b72e 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_bootstrap_key.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_bootstrap_key.rs @@ -5,7 +5,7 @@ use tfhe_versionable::Versionize; use crate::conformance::ParameterSetConformant; use crate::core_crypto::algorithms::*; use crate::core_crypto::backward_compatibility::entities::seeded_lwe_bootstrap_key::SeededLweBootstrapKeyVersions; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, CompressionSeed}; +use crate::core_crypto::commons::math::random::{CompressionSeed, DefaultRandomGenerator}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -217,7 +217,7 @@ impl> SeededLweBootstrap self.input_lwe_dimension(), self.ciphertext_modulus(), ); - decompress_seeded_lwe_bootstrap_key::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_lwe_bootstrap_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_bsk, &self, ); @@ -239,7 +239,7 @@ impl> SeededLweBootstrap self.input_lwe_dimension(), self.ciphertext_modulus(), ); - par_decompress_seeded_lwe_bootstrap_key::<_, _, _, ActivatedRandomGenerator>( + par_decompress_seeded_lwe_bootstrap_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_bsk, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext.rs b/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext.rs index 031d2e7f0a..0743a3e001 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext.rs @@ -5,7 +5,7 @@ use tfhe_versionable::Versionize; use crate::conformance::ParameterSetConformant; use crate::core_crypto::algorithms::*; use crate::core_crypto::backward_compatibility::entities::seeded_lwe_ciphertext::SeededLweCiphertextVersions; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, CompressionSeed}; +use crate::core_crypto::commons::math::random::{CompressionSeed, DefaultRandomGenerator}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -173,7 +173,7 @@ impl SeededLweCiphertext { { let mut decompressed_ct = LweCiphertext::new(Scalar::ZERO, self.lwe_size(), self.ciphertext_modulus()); - decompress_seeded_lwe_ciphertext::<_, _, ActivatedRandomGenerator>( + decompress_seeded_lwe_ciphertext::<_, _, DefaultRandomGenerator>( &mut decompressed_ct, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext_list.rs b/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext_list.rs index 4b474b32d4..877bdb2933 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext_list.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_ciphertext_list.rs @@ -8,7 +8,7 @@ use crate::core_crypto::commons::generators::{ EncryptionRandomGeneratorForkConfig, MaskRandomGeneratorForkConfig, }; use crate::core_crypto::commons::math::random::{ - ActivatedRandomGenerator, CompressionSeed, Distribution, RandomGenerable, + CompressionSeed, DefaultRandomGenerator, Distribution, RandomGenerable, }; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; @@ -164,7 +164,7 @@ impl> SeededLweCiphertex self.lwe_ciphertext_count(), self.ciphertext_modulus(), ); - decompress_seeded_lwe_ciphertext_list::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_lwe_ciphertext_list::<_, _, _, DefaultRandomGenerator>( &mut decompressed_list, &self, ); @@ -183,7 +183,7 @@ impl> SeededLweCiphertex self.lwe_ciphertext_count(), self.ciphertext_modulus(), ); - par_decompress_seeded_lwe_ciphertext_list::<_, _, _, ActivatedRandomGenerator>( + par_decompress_seeded_lwe_ciphertext_list::<_, _, _, DefaultRandomGenerator>( &mut decompressed_list, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_compact_public_key.rs b/tfhe/src/core_crypto/entities/seeded_lwe_compact_public_key.rs index a70c6f9e56..f2a317982b 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_compact_public_key.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_compact_public_key.rs @@ -5,7 +5,7 @@ use tfhe_versionable::Versionize; use crate::conformance::ParameterSetConformant; use crate::core_crypto::algorithms::decompress_seeded_lwe_compact_public_key; use crate::core_crypto::backward_compatibility::entities::seeded_lwe_compact_public_key::SeededLweCompactPublicKeyVersions; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, CompressionSeed}; +use crate::core_crypto::commons::math::random::{CompressionSeed, DefaultRandomGenerator}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -179,7 +179,7 @@ impl> SeededLweCompactPu self.lwe_dimension(), self.ciphertext_modulus(), ); - decompress_seeded_lwe_compact_public_key::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_lwe_compact_public_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_cpk, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key.rs b/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key.rs index cea9d5aa40..5487096f44 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key.rs @@ -3,7 +3,7 @@ use crate::conformance::ParameterSetConformant; use crate::core_crypto::algorithms::*; use crate::core_crypto::backward_compatibility::entities::seeded_lwe_keyswitch_key::SeededLweKeyswitchKeyVersions; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, CompressionSeed}; +use crate::core_crypto::commons::math::random::{CompressionSeed, DefaultRandomGenerator}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -251,7 +251,7 @@ impl> SeededLweKeyswitch self.output_key_lwe_dimension(), self.ciphertext_modulus(), ); - decompress_seeded_lwe_keyswitch_key::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_lwe_keyswitch_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_ksk, &self, ); @@ -272,7 +272,7 @@ impl> SeededLweKeyswitch self.output_key_lwe_dimension(), self.ciphertext_modulus(), ); - par_decompress_seeded_lwe_keyswitch_key::<_, _, _, ActivatedRandomGenerator>( + par_decompress_seeded_lwe_keyswitch_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_ksk, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_multi_bit_bootstrap_key.rs b/tfhe/src/core_crypto/entities/seeded_lwe_multi_bit_bootstrap_key.rs index 530c34c19d..35633597e7 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_multi_bit_bootstrap_key.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_multi_bit_bootstrap_key.rs @@ -7,7 +7,7 @@ use crate::core_crypto::commons::generators::{ EncryptionRandomGeneratorForkConfig, MaskRandomGeneratorForkConfig, }; use crate::core_crypto::commons::math::random::{ - ActivatedRandomGenerator, CompressionSeed, Distribution, RandomGenerable, + CompressionSeed, DefaultRandomGenerator, Distribution, RandomGenerable, }; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; @@ -272,7 +272,7 @@ impl> SeededLweMultiBitB self.grouping_factor(), self.ciphertext_modulus(), ); - decompress_seeded_lwe_multi_bit_bootstrap_key::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_lwe_multi_bit_bootstrap_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_bsk, &self, ); @@ -297,7 +297,7 @@ impl> SeededLweMultiBitB self.grouping_factor(), self.ciphertext_modulus(), ); - par_decompress_seeded_lwe_multi_bit_bootstrap_key::<_, _, _, ActivatedRandomGenerator>( + par_decompress_seeded_lwe_multi_bit_bootstrap_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_bsk, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_packing_keyswitch_key.rs b/tfhe/src/core_crypto/entities/seeded_lwe_packing_keyswitch_key.rs index 31daf5997b..09d667c54c 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_packing_keyswitch_key.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_packing_keyswitch_key.rs @@ -3,7 +3,7 @@ use crate::conformance::ParameterSetConformant; use crate::core_crypto::algorithms::*; use crate::core_crypto::backward_compatibility::entities::seeded_lwe_packing_keyswitch_key::SeededLwePackingKeyswitchKeyVersions; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, CompressionSeed}; +use crate::core_crypto::commons::math::random::{CompressionSeed, DefaultRandomGenerator}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -296,7 +296,7 @@ impl> SeededLwePackingKe self.output_key_polynomial_size(), self.ciphertext_modulus(), ); - decompress_seeded_lwe_packing_keyswitch_key::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_lwe_packing_keyswitch_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_pksk, &self, ); diff --git a/tfhe/src/core_crypto/entities/seeded_lwe_public_key.rs b/tfhe/src/core_crypto/entities/seeded_lwe_public_key.rs index 210a5eea4b..38d05ca176 100644 --- a/tfhe/src/core_crypto/entities/seeded_lwe_public_key.rs +++ b/tfhe/src/core_crypto/entities/seeded_lwe_public_key.rs @@ -4,7 +4,7 @@ use tfhe_versionable::Versionize; use crate::core_crypto::algorithms::*; use crate::core_crypto::backward_compatibility::entities::seeded_lwe_public_key::SeededLwePublicKeyVersions; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, CompressionSeed}; +use crate::core_crypto::commons::math::random::{CompressionSeed, DefaultRandomGenerator}; use crate::core_crypto::commons::parameters::*; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; @@ -186,7 +186,7 @@ impl> SeededLwePublicKey self.zero_encryption_count(), self.ciphertext_modulus(), ); - decompress_seeded_lwe_public_key::<_, _, _, ActivatedRandomGenerator>( + decompress_seeded_lwe_public_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_public_key, &self, ); @@ -207,7 +207,7 @@ impl> SeededLwePublicKey self.zero_encryption_count(), self.ciphertext_modulus(), ); - par_decompress_seeded_lwe_public_key::<_, _, _, ActivatedRandomGenerator>( + par_decompress_seeded_lwe_public_key::<_, _, _, DefaultRandomGenerator>( &mut decompressed_public_key, &self, ); diff --git a/tfhe/src/core_crypto/experimental/algorithms/glwe_fast_keyswitch.rs b/tfhe/src/core_crypto/experimental/algorithms/glwe_fast_keyswitch.rs index 49d3006676..df018198b9 100644 --- a/tfhe/src/core_crypto/experimental/algorithms/glwe_fast_keyswitch.rs +++ b/tfhe/src/core_crypto/experimental/algorithms/glwe_fast_keyswitch.rs @@ -52,9 +52,8 @@ use tfhe_fft::c64; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key_out = allocate_and_generate_new_binary_glwe_secret_key( diff --git a/tfhe/src/core_crypto/experimental/algorithms/glwe_partial_sample_extraction.rs b/tfhe/src/core_crypto/experimental/algorithms/glwe_partial_sample_extraction.rs index 0a8196bea1..24d6bc217c 100644 --- a/tfhe/src/core_crypto/experimental/algorithms/glwe_partial_sample_extraction.rs +++ b/tfhe/src/core_crypto/experimental/algorithms/glwe_partial_sample_extraction.rs @@ -35,9 +35,8 @@ use crate::core_crypto::entities::*; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_partial_binary_glwe_secret_key( @@ -187,9 +186,8 @@ pub fn partial_extract_lwe_sample_from_glwe_ciphertext::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the GlweSecretKey /// let glwe_secret_key = allocate_and_generate_new_partial_binary_glwe_secret_key( diff --git a/tfhe/src/core_crypto/experimental/algorithms/lwe_shrinking_keyswitch.rs b/tfhe/src/core_crypto/experimental/algorithms/lwe_shrinking_keyswitch.rs index a91657f3de..4cbf81e502 100644 --- a/tfhe/src/core_crypto/experimental/algorithms/lwe_shrinking_keyswitch.rs +++ b/tfhe/src/core_crypto/experimental/algorithms/lwe_shrinking_keyswitch.rs @@ -30,9 +30,8 @@ use crate::core_crypto::experimental::entities::LweShrinkingKeyswitchKey; /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); /// let mut encryption_generator = -/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// EncryptionRandomGenerator::::new(seeder.seed(), seeder); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// // Create the large LweSecretKey /// let large_lwe_secret_key = diff --git a/tfhe/src/core_crypto/experimental/algorithms/partial_glwe_secret_key_generation.rs b/tfhe/src/core_crypto/experimental/algorithms/partial_glwe_secret_key_generation.rs index ece47c78aa..37e47705bb 100644 --- a/tfhe/src/core_crypto/experimental/algorithms/partial_glwe_secret_key_generation.rs +++ b/tfhe/src/core_crypto/experimental/algorithms/partial_glwe_secret_key_generation.rs @@ -51,8 +51,7 @@ pub fn generate_partial_binary_glwe_secret_key( /// // Create the PRNG /// let mut seeder = new_seeder(); /// let seeder = seeder.as_mut(); -/// let mut secret_generator = -/// SecretRandomGenerator::::new(seeder.seed()); +/// let mut secret_generator = SecretRandomGenerator::::new(seeder.seed()); /// /// let mut glwe_secret_key: GlweSecretKeyOwned = /// allocate_and_generate_new_partial_binary_glwe_secret_key( diff --git a/tfhe/src/core_crypto/prelude.rs b/tfhe/src/core_crypto/prelude.rs index cc973bb597..e82d700225 100644 --- a/tfhe/src/core_crypto/prelude.rs +++ b/tfhe/src/core_crypto/prelude.rs @@ -10,7 +10,7 @@ pub use super::commons::computation_buffers::ComputationBuffers; pub use super::commons::dispersion::*; pub use super::commons::generators::{EncryptionRandomGenerator, SecretRandomGenerator}; pub use super::commons::math::decomposition::SignedDecomposer; -pub use super::commons::math::random::{ActivatedRandomGenerator, Gaussian, TUniform}; +pub use super::commons::math::random::{DefaultRandomGenerator, Gaussian, TUniform}; pub use super::commons::parameters::*; pub use super::commons::traits::*; pub use super::entities::*; diff --git a/tfhe/src/core_crypto/seeders.rs b/tfhe/src/core_crypto/seeders.rs index 0fc590b412..f960b20e87 100644 --- a/tfhe/src/core_crypto/seeders.rs +++ b/tfhe/src/core_crypto/seeders.rs @@ -7,9 +7,9 @@ pub use crate::core_crypto::commons::math::random::Seeder; #[cfg(all(target_os = "macos", not(feature = "__wasm_api")))] pub use tfhe_csprng::seeders::AppleSecureEnclaveSeeder; -#[cfg(feature = "seeder_x86_64_rdseed")] +#[cfg(all(target_arch = "x86_64", not(feature = "__wasm_api")))] pub use tfhe_csprng::seeders::RdseedSeeder; -#[cfg(feature = "seeder_unix")] +#[cfg(all(target_family = "unix", not(feature = "__wasm_api")))] pub use tfhe_csprng::seeders::UnixSeeder; #[cfg(feature = "__wasm_api")] @@ -41,16 +41,15 @@ mod wasm_seeder { /// /// # Note /// -/// With the `seeder_x86_64_rdseed` feature enabled on `x86_64` CPUs the rdseed seeder is +/// When the `rdseed` CPU feature is detected on `x86_64` CPUs the rdseed seeder is /// prioritized. /// /// On macOS the next seeder to be prioritized uses Apple's [`Randomization /// Service`](`https://developer.apple.com/documentation/security/randomization_services?language=objc`) /// calling [`SecRandomCopyBytes`](`https://developer.apple.com/documentation/security/1399291-secrandomcopybytes?language=objc`). /// -/// With the `seeder_unix` feature enabled on Unix platforms, `/dev/random` is used as a fallback -/// and the quality of the generated seeds depends on the particular implementation of the platform -/// your code is running on. +/// On Unix platforms, `/dev/random` is used as a fallback and the quality of the generated seeds +/// depends on the particular implementation of the platform your code is running on. /// /// For the wasm32 target the [`getrandom`](`https://docs.rs/getrandom/latest/getrandom/`) /// js random number generator is used as a source of @@ -75,10 +74,10 @@ pub fn new_seeder() -> Box { #[cfg(not(feature = "__wasm_api"))] { - #[cfg(feature = "seeder_x86_64_rdseed")] + #[cfg(target_arch = "x86_64")] { if RdseedSeeder::is_available() { - seeder = Some(Box::new(RdseedSeeder)); + seeder = Some(Box::new(RdseedSeeder::new())); } } @@ -91,23 +90,14 @@ pub fn new_seeder() -> Box { } } - #[cfg(feature = "seeder_unix")] + #[cfg(target_family = "unix")] { if seeder.is_none() && UnixSeeder::is_available() { seeder = Some(Box::new(UnixSeeder::new(0))); } } - #[cfg(not(feature = "__c_api"))] - { - err_msg = "Unable to instantiate a seeder, make sure to enable a seeder feature \ - like seeder_unix for example on unix platforms."; - } - - #[cfg(feature = "__c_api")] - { - err_msg = "No compatible seeder for current machine found."; - } + err_msg = "No compatible seeder for current machine found."; } #[cfg(feature = "__wasm_api")] diff --git a/tfhe/src/high_level_api/keys/inner.rs b/tfhe/src/high_level_api/keys/inner.rs index 55ba86521b..eb9d7a8d85 100644 --- a/tfhe/src/high_level_api/keys/inner.rs +++ b/tfhe/src/high_level_api/keys/inner.rs @@ -1,6 +1,6 @@ use crate::conformance::ParameterSetConformant; use crate::core_crypto::commons::generators::DeterministicSeeder; -use crate::core_crypto::prelude::{ActivatedRandomGenerator, KeyswitchKeyConformanceParams}; +use crate::core_crypto::prelude::{DefaultRandomGenerator, KeyswitchKeyConformanceParams}; use crate::high_level_api::backward_compatibility::keys::*; use crate::integer::compression_keys::{ CompressedCompressionKey, CompressedDecompressionKey, CompressionKey, CompressionPrivateKeys, @@ -99,7 +99,7 @@ impl IntegerClientKey { (config.block_parameters.message_modulus().0) == 2 || config.block_parameters.message_modulus().0 == 4, "This API only supports parameters for which the MessageModulus is 2 or 4 (1 or 2 bits per block)", ); - let mut seeder = DeterministicSeeder::::new(seed); + let mut seeder = DeterministicSeeder::::new(seed); let cks = crate::shortint::engine::ShortintEngine::new_from_seeder(&mut seeder) .new_client_key(config.block_parameters.into()); diff --git a/tfhe/src/integer/oprf.rs b/tfhe/src/integer/oprf.rs index 6c12165c70..1c92229c3b 100644 --- a/tfhe/src/integer/oprf.rs +++ b/tfhe/src/integer/oprf.rs @@ -1,6 +1,6 @@ use super::{RadixCiphertext, ServerKey, SignedRadixCiphertext}; use crate::core_crypto::commons::generators::DeterministicSeeder; -use crate::core_crypto::prelude::ActivatedRandomGenerator; +use crate::core_crypto::prelude::DefaultRandomGenerator; use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator}; pub use tfhe_csprng::seeders::{Seed, Seeder}; @@ -41,7 +41,7 @@ impl ServerKey { assert!(self.message_modulus().0.is_power_of_two()); let message_bits_count = self.message_modulus().0.ilog2() as u64; - let mut deterministic_seeder = DeterministicSeeder::::new(seed); + let mut deterministic_seeder = DeterministicSeeder::::new(seed); let seeds: Vec = (0..num_blocks) .map(|_| deterministic_seeder.seed()) @@ -120,7 +120,7 @@ impl ServerKey { assert!(self.message_modulus().0.is_power_of_two()); let message_bits_count = self.message_modulus().0.ilog2() as u64; - let mut deterministic_seeder = DeterministicSeeder::::new(seed); + let mut deterministic_seeder = DeterministicSeeder::::new(seed); let seeds: Vec = (0..num_blocks) .map(|_| deterministic_seeder.seed()) @@ -187,7 +187,7 @@ impl ServerKey { assert!(self.message_modulus().0.is_power_of_two()); let message_bits_count = self.message_modulus().0.ilog2() as u64; - let mut deterministic_seeder = DeterministicSeeder::::new(seed); + let mut deterministic_seeder = DeterministicSeeder::::new(seed); let seeds: Vec = (0..num_blocks) .map(|_| deterministic_seeder.seed()) @@ -253,7 +253,7 @@ impl ServerKey { assert!(self.message_modulus().0.is_power_of_two()); let message_bits_count = self.message_modulus().0.ilog2() as u64; - let mut deterministic_seeder = DeterministicSeeder::::new(seed); + let mut deterministic_seeder = DeterministicSeeder::::new(seed); let seeds: Vec = (0..num_blocks) .map(|_| deterministic_seeder.seed()) diff --git a/tfhe/src/js_on_wasm_api/boolean.rs b/tfhe/src/js_on_wasm_api/boolean.rs index 3ab3d49d26..2d0939fcf4 100644 --- a/tfhe/src/js_on_wasm_api/boolean.rs +++ b/tfhe/src/js_on_wasm_api/boolean.rs @@ -1,6 +1,6 @@ use crate::core_crypto::commons::generators::DeterministicSeeder; use crate::core_crypto::commons::math::random::Seed; -use crate::core_crypto::prelude::ActivatedRandomGenerator; +use crate::core_crypto::prelude::DefaultRandomGenerator; use std::panic::set_hook; use wasm_bindgen::prelude::*; @@ -152,7 +152,7 @@ impl Boolean { let seed_low_bytes: u128 = seed_low_bytes.into(); let seed: u128 = (seed_high_bytes << 64) | seed_low_bytes; - let mut seeder = DeterministicSeeder::::new(Seed(seed)); + let mut seeder = DeterministicSeeder::::new(Seed(seed)); let key = crate::boolean::engine::BooleanEngine::new_from_seeder(&mut seeder) .create_client_key(parameters.0); BooleanClientKey(key) diff --git a/tfhe/src/js_on_wasm_api/shortint.rs b/tfhe/src/js_on_wasm_api/shortint.rs index 8a50fd827b..093d6cb2e5 100644 --- a/tfhe/src/js_on_wasm_api/shortint.rs +++ b/tfhe/src/js_on_wasm_api/shortint.rs @@ -1,7 +1,7 @@ #![allow(clippy::use_self)] use crate::core_crypto::commons::generators::DeterministicSeeder; use crate::core_crypto::commons::math::random::Seed; -use crate::core_crypto::prelude::ActivatedRandomGenerator; +use crate::core_crypto::prelude::DefaultRandomGenerator; use crate::js_on_wasm_api::js_high_level_api::into_js_error; use crate::shortint::parameters::classic::compact_pk::*; use crate::shortint::parameters::compact_public_key_only::p_fail_2_minus_64::ks_pbs::PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64; @@ -457,7 +457,7 @@ impl Shortint { let seed_low_bytes: u128 = seed_low_bytes.into(); let seed: u128 = (seed_high_bytes << 64) | seed_low_bytes; - let mut seeder = DeterministicSeeder::::new(Seed(seed)); + let mut seeder = DeterministicSeeder::::new(Seed(seed)); ShortintClientKey( crate::shortint::engine::ShortintEngine::new_from_seeder(&mut seeder) .new_client_key(parameters.0.into()), diff --git a/tfhe/src/shortint/engine/mod.rs b/tfhe/src/shortint/engine/mod.rs index 14e245c755..8986d85bc8 100644 --- a/tfhe/src/shortint/engine/mod.rs +++ b/tfhe/src/shortint/engine/mod.rs @@ -11,7 +11,7 @@ use crate::core_crypto::commons::generators::{ }; #[cfg(feature = "zk-pok")] use crate::core_crypto::commons::math::random::RandomGenerator; -use crate::core_crypto::commons::math::random::{ActivatedRandomGenerator, Seeder}; +use crate::core_crypto::commons::math::random::{DefaultRandomGenerator, Seeder}; use crate::core_crypto::entities::*; use crate::core_crypto::prelude::{ContainerMut, GlweSize}; use crate::core_crypto::seeders::new_seeder; @@ -299,19 +299,19 @@ impl std::fmt::Display for EngineError { /// This structs actually implements the logics into its methods. pub struct ShortintEngine { /// A structure containing a single CSPRNG to generate secret key coefficients. - pub(crate) secret_generator: SecretRandomGenerator, + pub(crate) secret_generator: SecretRandomGenerator, /// A structure containing two CSPRNGs to generate material for encryption like public masks /// and secret errors. /// /// The [`EncryptionRandomGenerator`] contains two CSPRNGs, one publicly seeded used to /// generate mask coefficients and one privately seeded used to generate errors during /// encryption. - pub(crate) encryption_generator: EncryptionRandomGenerator, + pub(crate) encryption_generator: EncryptionRandomGenerator, /// A seeder that can be called to generate 128 bits seeds, useful to create new /// [`EncryptionRandomGenerator`] to encrypt seeded types. - pub(crate) seeder: DeterministicSeeder, + pub(crate) seeder: DeterministicSeeder, #[cfg(feature = "zk-pok")] - pub(crate) random_generator: RandomGenerator, + pub(crate) random_generator: RandomGenerator, pub(crate) computation_buffers: ComputationBuffers, ciphertext_buffers: Memory, } @@ -345,7 +345,7 @@ impl ShortintEngine { pub fn new_from_seeder(root_seeder: &mut dyn Seeder) -> Self { let mut deterministic_seeder = - DeterministicSeeder::::new(root_seeder.seed()); + DeterministicSeeder::::new(root_seeder.seed()); // Note that the operands are evaluated from left to right for Rust Struct expressions // See: https://doc.rust-lang.org/stable/reference/expressions.html?highlight=left#evaluation-order-of-operands diff --git a/tfhe/src/shortint/oprf.rs b/tfhe/src/shortint/oprf.rs index 89a14aec26..4665e853de 100644 --- a/tfhe/src/shortint/oprf.rs +++ b/tfhe/src/shortint/oprf.rs @@ -162,7 +162,7 @@ impl ServerKey { pub(crate) mod test { use crate::core_crypto::commons::generators::DeterministicSeeder; use crate::core_crypto::prelude::{ - decrypt_lwe_ciphertext, ActivatedRandomGenerator, GlweSecretKey, LweSecretKey, + decrypt_lwe_ciphertext, DefaultRandomGenerator, GlweSecretKey, LweSecretKey, }; use crate::shortint::engine::ShortintEngine; use crate::shortint::{ClientKey, ServerKey}; @@ -199,8 +199,7 @@ pub(crate) mod test { parameters: parameters.into(), }; - let mut deterministic_seeder = - DeterministicSeeder::::new(Seed(0)); + let mut deterministic_seeder = DeterministicSeeder::::new(Seed(0)); let mut engine = ShortintEngine::new_from_seeder(&mut deterministic_seeder);