mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-14 17:18:05 -05:00
Compare commits
4 Commits
dt/ci/impr
...
mz/just
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
560c9cb3b2 | ||
|
|
28ea89ac42 | ||
|
|
5b8529e6d8 | ||
|
|
aefe2dd806 |
32
.github/workflows/aws_tfhe_fast_tests.yml
vendored
32
.github/workflows/aws_tfhe_fast_tests.yml
vendored
@@ -51,7 +51,7 @@ jobs:
|
||||
echo "Fork git sha: ${{ inputs.fork_git_sha }}"
|
||||
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: ${{ inputs.fork_repo }}
|
||||
ref: ${{ inputs.fork_git_sha }}
|
||||
@@ -65,54 +65,54 @@ jobs:
|
||||
with:
|
||||
toolchain: stable
|
||||
default: true
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run concrete-csprng tests
|
||||
run: |
|
||||
make test_concrete_csprng
|
||||
just test_concrete_csprng
|
||||
|
||||
- name: Run core tests
|
||||
run: |
|
||||
AVX512_SUPPORT=ON make test_core_crypto
|
||||
AVX512_SUPPORT=ON just test_core_crypto
|
||||
|
||||
- name: Run boolean tests
|
||||
run: |
|
||||
make test_boolean
|
||||
just test_boolean
|
||||
|
||||
- name: Run user docs tests
|
||||
run: |
|
||||
make test_user_doc
|
||||
just test_user_doc
|
||||
|
||||
- name: Run js on wasm API tests
|
||||
run: |
|
||||
make test_nodejs_wasm_api_in_docker
|
||||
just test_nodejs_wasm_api_in_docker
|
||||
|
||||
- name: Gen Keys if required
|
||||
run: |
|
||||
make gen_key_cache
|
||||
just gen_key_cache
|
||||
|
||||
- name: Run shortint tests
|
||||
run: |
|
||||
BIG_TESTS_INSTANCE=TRUE FAST_TESTS=TRUE make test_shortint_ci
|
||||
BIG_TESTS_INSTANCE=TRUE FAST_TESTS=TRUE just test_shortint_ci
|
||||
|
||||
- name: Run integer tests
|
||||
run: |
|
||||
BIG_TESTS_INSTANCE=TRUE FAST_TESTS=TRUE make test_integer_ci
|
||||
BIG_TESTS_INSTANCE=TRUE FAST_TESTS=TRUE just test_integer_ci
|
||||
|
||||
- name: Run shortint multi-bit tests
|
||||
run: |
|
||||
BIG_TESTS_INSTANCE=TRUE FAST_TESTS=TRUE make test_shortint_multi_bit_ci
|
||||
BIG_TESTS_INSTANCE=TRUE FAST_TESTS=TRUE just test_shortint_multi_bit_ci
|
||||
|
||||
- name: Run integer multi-bit tests
|
||||
run: |
|
||||
BIG_TESTS_INSTANCE=TRUE FAST_TESTS=TRUE make test_integer_multi_bit_ci
|
||||
BIG_TESTS_INSTANCE=TRUE FAST_TESTS=TRUE just test_integer_multi_bit_ci
|
||||
|
||||
- name: Run high-level API tests
|
||||
run: |
|
||||
make test_high_level_api
|
||||
|
||||
- name: Run safe deserialization tests
|
||||
run: |
|
||||
make test_safe_deserialization
|
||||
just test_high_level_api
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ always() }}
|
||||
|
||||
30
.github/workflows/aws_tfhe_integer_tests.yml
vendored
30
.github/workflows/aws_tfhe_integer_tests.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: AWS Unsigned Integer Tests on CPU
|
||||
name: AWS Integer Tests on CPU
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@@ -23,13 +23,13 @@ on:
|
||||
description: "Action runner name"
|
||||
type: string
|
||||
request_id:
|
||||
description: "Slab request ID"
|
||||
description: 'Slab request ID'
|
||||
type: string
|
||||
fork_repo:
|
||||
description: "Name of forked repo as user/repo"
|
||||
description: 'Name of forked repo as user/repo'
|
||||
type: string
|
||||
fork_git_sha:
|
||||
description: "Git SHA to checkout from fork"
|
||||
description: 'Git SHA to checkout from fork'
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
@@ -50,7 +50,7 @@ jobs:
|
||||
echo "Fork git sha: ${{ inputs.fork_git_sha }}"
|
||||
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: ${{ inputs.fork_repo }}
|
||||
ref: ${{ inputs.fork_git_sha }}
|
||||
@@ -64,22 +64,18 @@ jobs:
|
||||
with:
|
||||
toolchain: stable
|
||||
default: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Gen Keys if required
|
||||
run: |
|
||||
make GEN_KEY_CACHE_MULTI_BIT_ONLY=TRUE gen_key_cache
|
||||
just gen_key_cache
|
||||
|
||||
- name: Run unsigned integer multi-bit tests
|
||||
- name: Run integer tests
|
||||
run: |
|
||||
AVX512_SUPPORT=ON make test_unsigned_integer_multi_bit_ci
|
||||
|
||||
- name: Gen Keys if required
|
||||
run: |
|
||||
make gen_key_cache
|
||||
|
||||
- name: Run unsigned integer tests
|
||||
run: |
|
||||
AVX512_SUPPORT=ON BIG_TESTS_INSTANCE=TRUE make test_unsigned_integer_ci
|
||||
BIG_TESTS_INSTANCE=TRUE just test_integer_ci
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ always() }}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: AWS Signed Integer Tests on CPU
|
||||
name: AWS Multi Bit Tests on CPU
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@@ -23,13 +23,13 @@ on:
|
||||
description: "Action runner name"
|
||||
type: string
|
||||
request_id:
|
||||
description: "Slab request ID"
|
||||
description: 'Slab request ID'
|
||||
type: string
|
||||
fork_repo:
|
||||
description: "Name of forked repo as user/repo"
|
||||
description: 'Name of forked repo as user/repo'
|
||||
type: string
|
||||
fork_git_sha:
|
||||
description: "Git SHA to checkout from fork"
|
||||
description: 'Git SHA to checkout from fork'
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
@@ -50,7 +50,7 @@ jobs:
|
||||
echo "Fork git sha: ${{ inputs.fork_git_sha }}"
|
||||
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: ${{ inputs.fork_repo }}
|
||||
ref: ${{ inputs.fork_git_sha }}
|
||||
@@ -64,26 +64,22 @@ jobs:
|
||||
with:
|
||||
toolchain: stable
|
||||
default: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Gen Keys if required
|
||||
run: |
|
||||
make GEN_KEY_CACHE_MULTI_BIT_ONLY=TRUE gen_key_cache
|
||||
just GEN_KEY_CACHE_MULTI_BIT_ONLY=TRUE gen_key_cache
|
||||
|
||||
- name: Run shortint multi-bit tests
|
||||
run: |
|
||||
make test_shortint_multi_bit_ci
|
||||
just test_shortint_multi_bit_ci
|
||||
|
||||
- name: Run signed integer multi-bit tests
|
||||
- name: Run integer multi-bit tests
|
||||
run: |
|
||||
AVX512_SUPPORT=ON make test_signed_integer_multi_bit_ci
|
||||
|
||||
- name: Gen Keys if required
|
||||
run: |
|
||||
make gen_key_cache
|
||||
|
||||
- name: Run signed integer tests
|
||||
run: |
|
||||
AVX512_SUPPORT=ON BIG_TESTS_INSTANCE=TRUE make test_signed_integer_ci
|
||||
just test_integer_multi_bit_ci
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ always() }}
|
||||
31
.github/workflows/aws_tfhe_tests.yml
vendored
31
.github/workflows/aws_tfhe_tests.yml
vendored
@@ -50,7 +50,7 @@ jobs:
|
||||
echo "Fork git sha: ${{ inputs.fork_git_sha }}"
|
||||
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: ${{ inputs.fork_repo }}
|
||||
ref: ${{ inputs.fork_git_sha }}
|
||||
@@ -65,47 +65,46 @@ jobs:
|
||||
toolchain: stable
|
||||
default: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run concrete-csprng tests
|
||||
run: |
|
||||
make test_concrete_csprng
|
||||
just test_concrete_csprng
|
||||
|
||||
- name: Run core tests
|
||||
run: |
|
||||
AVX512_SUPPORT=ON make test_core_crypto
|
||||
AVX512_SUPPORT=ON just test_core_crypto
|
||||
|
||||
- name: Run boolean tests
|
||||
run: |
|
||||
make test_boolean
|
||||
just test_boolean
|
||||
|
||||
- name: Run C API tests
|
||||
run: |
|
||||
make test_c_api
|
||||
just test_c_api
|
||||
|
||||
- name: Run user docs tests
|
||||
run: |
|
||||
make test_user_doc
|
||||
just test_user_doc
|
||||
|
||||
- name: Gen Keys if required
|
||||
run: |
|
||||
make gen_key_cache
|
||||
just gen_key_cache
|
||||
|
||||
- name: Run shortint tests
|
||||
run: |
|
||||
BIG_TESTS_INSTANCE=TRUE make test_shortint_ci
|
||||
BIG_TESTS_INSTANCE=TRUE just test_shortint_ci
|
||||
|
||||
- name: Run high-level API tests
|
||||
run: |
|
||||
BIG_TESTS_INSTANCE=TRUE make test_high_level_api
|
||||
BIG_TESTS_INSTANCE=TRUE just test_high_level_api
|
||||
|
||||
- name: Run example tests
|
||||
run: |
|
||||
make test_examples
|
||||
make dark_market
|
||||
|
||||
- name: Run apps tests
|
||||
run: |
|
||||
make test_trivium
|
||||
make test_kreyvium
|
||||
just test_examples
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ always() }}
|
||||
|
||||
14
.github/workflows/aws_tfhe_wasm_tests.yml
vendored
14
.github/workflows/aws_tfhe_wasm_tests.yml
vendored
@@ -50,7 +50,7 @@ jobs:
|
||||
echo "Fork git sha: ${{ inputs.fork_git_sha }}"
|
||||
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: ${{ inputs.fork_repo }}
|
||||
ref: ${{ inputs.fork_git_sha }}
|
||||
@@ -64,15 +64,19 @@ jobs:
|
||||
with:
|
||||
toolchain: stable
|
||||
default: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run js on wasm API tests
|
||||
run: |
|
||||
make test_nodejs_wasm_api_in_docker
|
||||
just test_nodejs_wasm_api_in_docker
|
||||
|
||||
- name: Run parallel wasm tests
|
||||
run: |
|
||||
make install_node
|
||||
make ci_test_web_js_api_parallel
|
||||
just install_node
|
||||
just ci_test_web_js_api_parallel
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ always() }}
|
||||
|
||||
22
.github/workflows/boolean_benchmark.yml
vendored
22
.github/workflows/boolean_benchmark.yml
vendored
@@ -19,14 +19,6 @@ on:
|
||||
request_id:
|
||||
description: "Slab request ID"
|
||||
type: string
|
||||
# This input is not used in this workflow but still mandatory since a calling workflow could
|
||||
# use it. If a triggering command include a user_inputs field, then the triggered workflow
|
||||
# must include this very input, otherwise the workflow won't be called.
|
||||
# See start_full_benchmarks.yml as example.
|
||||
user_inputs:
|
||||
description: "Type of benchmarks to run"
|
||||
type: string
|
||||
default: "weekly_benchmarks"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@@ -51,7 +43,7 @@ jobs:
|
||||
echo "BENCH_DATE=$(date --iso-8601=seconds)" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -65,10 +57,14 @@ jobs:
|
||||
with:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run benchmarks with AVX512
|
||||
run: |
|
||||
make AVX512_SUPPORT=ON bench_boolean
|
||||
just AVX512_SUPPORT=ON bench_boolean
|
||||
|
||||
- name: Parse results
|
||||
run: |
|
||||
@@ -87,7 +83,7 @@ jobs:
|
||||
|
||||
- name: Measure key sizes
|
||||
run: |
|
||||
make measure_boolean_key_sizes
|
||||
just measure_boolean_key_sizes
|
||||
|
||||
- name: Parse key sizes results
|
||||
run: |
|
||||
@@ -102,7 +98,7 @@ jobs:
|
||||
path: ${{ env.RESULTS_FILENAME }}
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
|
||||
33
.github/workflows/cargo_build.yml
vendored
33
.github/workflows/cargo_build.yml
vendored
@@ -21,50 +21,45 @@ jobs:
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
|
||||
- name: Install and run newline linter checks
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
wget https://github.com/fernandrone/linelint/releases/download/0.0.6/linelint-linux-amd64
|
||||
echo "16b70fb7b471d6f95cbdc0b4e5dc2b0ac9e84ba9ecdc488f7bdf13df823aca4b linelint-linux-amd64" > checksum
|
||||
sha256sum -c checksum || exit 1
|
||||
chmod +x linelint-linux-amd64
|
||||
mv linelint-linux-amd64 /usr/local/bin/linelint
|
||||
make check_newline
|
||||
|
||||
cargo install just
|
||||
|
||||
- name: Run pcc checks
|
||||
run: |
|
||||
make pcc
|
||||
just pcc
|
||||
|
||||
- name: Build concrete-csprng
|
||||
run: |
|
||||
make build_concrete_csprng
|
||||
just build_concrete_csprng
|
||||
|
||||
- name: Build Release core
|
||||
run: |
|
||||
make build_core AVX512_SUPPORT=ON
|
||||
make build_core_experimental AVX512_SUPPORT=ON
|
||||
just build_core AVX512_SUPPORT=ON
|
||||
just build_core_experimental AVX512_SUPPORT=ON
|
||||
|
||||
- name: Build Release boolean
|
||||
run: |
|
||||
make build_boolean
|
||||
just build_boolean
|
||||
|
||||
- name: Build Release shortint
|
||||
run: |
|
||||
make build_shortint
|
||||
just build_shortint
|
||||
|
||||
- name: Build Release integer
|
||||
run: |
|
||||
make build_integer
|
||||
just build_integer
|
||||
|
||||
- name: Build Release tfhe full
|
||||
run: |
|
||||
make build_tfhe_full
|
||||
just build_tfhe_full
|
||||
|
||||
- name: Build Release c_api
|
||||
run: |
|
||||
make build_c_api
|
||||
just build_c_api
|
||||
|
||||
# The wasm build check is a bit annoying to set-up here and is done during the tests in
|
||||
# aws_tfhe_tests.yml
|
||||
|
||||
101
.github/workflows/code_coverage.yml
vendored
101
.github/workflows/code_coverage.yml
vendored
@@ -6,110 +6,41 @@ env:
|
||||
RUSTFLAGS: "-C target-cpu=native"
|
||||
|
||||
on:
|
||||
# Allows you to run this workflow manually from the Actions tab as an alternative.
|
||||
workflow_dispatch:
|
||||
# All the inputs are provided by Slab
|
||||
inputs:
|
||||
instance_id:
|
||||
description: "AWS instance ID"
|
||||
type: string
|
||||
instance_image_id:
|
||||
description: "AWS instance AMI ID"
|
||||
type: string
|
||||
instance_type:
|
||||
description: "AWS instance product type"
|
||||
type: string
|
||||
runner_name:
|
||||
description: "Action runner name"
|
||||
type: string
|
||||
request_id:
|
||||
description: 'Slab request ID'
|
||||
type: string
|
||||
fork_repo:
|
||||
description: 'Name of forked repo as user/repo'
|
||||
type: string
|
||||
fork_git_sha:
|
||||
description: 'Git SHA to checkout from fork'
|
||||
type: string
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
code-coverage:
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}_${{ github.ref }}_${{ inputs.instance_image_id }}_${{ inputs.instance_type }}
|
||||
cancel-in-progress: true
|
||||
runs-on: ${{ inputs.runner_name }}
|
||||
timeout-minutes: 1080
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Step used for log purpose.
|
||||
- name: Instance configuration used
|
||||
run: |
|
||||
echo "ID: ${{ inputs.instance_id }}"
|
||||
echo "AMI: ${{ inputs.instance_image_id }}"
|
||||
echo "Type: ${{ inputs.instance_type }}"
|
||||
echo "Request ID: ${{ inputs.request_id }}"
|
||||
echo "Fork repo: ${{ inputs.fork_repo }}"
|
||||
echo "Fork git sha: ${{ inputs.fork_git_sha }}"
|
||||
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
with:
|
||||
repository: ${{ inputs.fork_repo }}
|
||||
ref: ${{ inputs.fork_git_sha }}
|
||||
|
||||
- name: Set up home
|
||||
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
echo "HOME=/home/ubuntu" >> "${GITHUB_ENV}"
|
||||
cargo install just
|
||||
|
||||
- name: Install latest stable
|
||||
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af
|
||||
with:
|
||||
toolchain: stable
|
||||
default: true
|
||||
|
||||
- name: Check for file changes
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@1c938490c880156b746568a518594309cfb3f66b
|
||||
with:
|
||||
files_yaml: |
|
||||
tfhe:
|
||||
- tfhe/src/**
|
||||
concrete_csprng:
|
||||
- concrete-csprng/src/**
|
||||
|
||||
- name: Generate Keys
|
||||
if: steps.changed-files.outputs.tfhe_any_changed == 'true'
|
||||
- name: Gen Keys if required
|
||||
run: |
|
||||
make GEN_KEY_CACHE_COVERAGE_ONLY=TRUE gen_key_cache
|
||||
make gen_key_cache_core_crypto
|
||||
just GEN_KEY_CACHE_COVERAGE_ONLY=TRUE gen_key_cache
|
||||
|
||||
- name: Run coverage for core_crypto
|
||||
if: steps.changed-files.outputs.tfhe_any_changed == 'true'
|
||||
- name: Run shortint coverage
|
||||
run: |
|
||||
make test_core_crypto_cov AVX512_SUPPORT=ON
|
||||
just test_shortint_cov
|
||||
|
||||
- name: Run coverage for boolean
|
||||
if: steps.changed-files.outputs.tfhe_any_changed == 'true'
|
||||
run: |
|
||||
make test_boolean_cov
|
||||
|
||||
- name: Run coverage for shortint
|
||||
if: steps.changed-files.outputs.tfhe_any_changed == 'true'
|
||||
run: |
|
||||
make test_shortint_cov
|
||||
|
||||
- name: Upload tfhe coverage to Codecov
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d
|
||||
if: steps.changed-files.outputs.tfhe_any_changed == 'true'
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
directory: ./coverage/
|
||||
fail_ci_if_error: true
|
||||
files: shortint/cobertura.xml,boolean/cobertura.xml,core_crypto/cobertura.xml,core_crypto_avx512/cobertura.xml
|
||||
files: ./coverage/shortint/cobertura.xml
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ failure() }}
|
||||
continue-on-error: true
|
||||
uses: rtCamp/action-slack-notify@b24d75fe0e728a4bf9fc42ee217caa686d141ee8
|
||||
uses: rtCamp/action-slack-notify@12e36fc18b0689399306c2e0b3e0f2978b7f1ee7
|
||||
env:
|
||||
SLACK_COLOR: ${{ job.status }}
|
||||
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
|
||||
|
||||
10
.github/workflows/csprng_randomness_testing.yml
vendored
10
.github/workflows/csprng_randomness_testing.yml
vendored
@@ -42,7 +42,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
|
||||
with:
|
||||
repository: ${{ inputs.fork_repo }}
|
||||
ref: ${{ inputs.fork_git_sha }}
|
||||
@@ -56,10 +56,14 @@ jobs:
|
||||
with:
|
||||
toolchain: stable
|
||||
default: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Dieharder randomness test suite
|
||||
run: |
|
||||
make dieharder_csprng
|
||||
just dieharder_csprng
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ failure() }}
|
||||
|
||||
14
.github/workflows/integer_benchmark.yml
vendored
14
.github/workflows/integer_benchmark.yml
vendored
@@ -44,7 +44,7 @@ jobs:
|
||||
echo "BENCH_DATE=$(date --iso-8601=seconds)" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -58,14 +58,18 @@ jobs:
|
||||
with:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run benchmarks with AVX512
|
||||
run: |
|
||||
make AVX512_SUPPORT=ON FAST_BENCH=TRUE bench_integer
|
||||
just AVX512_SUPPORT=ON FAST_BENCH=TRUE bench_integer
|
||||
|
||||
- name: Parse benchmarks to csv
|
||||
run: |
|
||||
make PARSE_INTEGER_BENCH_CSV_FILE=${{ env.PARSE_INTEGER_BENCH_CSV_FILE }} \
|
||||
just PARSE_INTEGER_BENCH_CSV_FILE=${{ env.PARSE_INTEGER_BENCH_CSV_FILE }} \
|
||||
parse_integer_benches
|
||||
|
||||
- name: Upload csv results artifact
|
||||
@@ -96,7 +100,7 @@ jobs:
|
||||
path: ${{ env.RESULTS_FILENAME }}
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
|
||||
43
.github/workflows/integer_full_benchmark.yml
vendored
43
.github/workflows/integer_full_benchmark.yml
vendored
@@ -19,10 +19,6 @@ on:
|
||||
request_id:
|
||||
description: "Slab request ID"
|
||||
type: string
|
||||
user_inputs:
|
||||
description: "Type of benchmarks to run"
|
||||
type: string
|
||||
default: "weekly_benchmarks"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@@ -30,33 +26,8 @@ env:
|
||||
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
|
||||
jobs:
|
||||
prepare-matrix:
|
||||
name: Prepare operations matrix
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
op_flavor: ${{ steps.set_op_flavor.outputs.op_flavor }}
|
||||
steps:
|
||||
- name: Weekly benchmarks
|
||||
if: ${{ github.event.inputs.user_inputs == 'weekly_benchmarks' }}
|
||||
run: |
|
||||
echo "OP_FLAVOR=[\"default\", \"default_comp\", \"default_scalar\", \"default_scalar_comp\"]" >> ${GITHUB_ENV}
|
||||
|
||||
- name: Quarterly benchmarks
|
||||
if: ${{ github.event.inputs.user_inputs == 'quarterly_benchmarks' }}
|
||||
run: |
|
||||
echo "OP_FLAVOR=[\"default\", \"default_comp\", \"default_scalar\", \"default_scalar_comp\", \
|
||||
\"smart\", \"smart_comp\", \"smart_scalar\", \"smart_parallelized\", \"smart_parallelized_comp\", \"smart_scalar_parallelized\", \"smart_scalar_parallelized_comp\", \
|
||||
\"unchecked\", \"unchecked_comp\", \"unchecked_scalar\", \"unchecked_scalar_comp\", \
|
||||
\"misc\"]" >> ${GITHUB_ENV}
|
||||
|
||||
- name: Set operation flavor output
|
||||
id: set_op_flavor
|
||||
run: |
|
||||
echo "op_flavor=${{ toJSON(env.OP_FLAVOR) }}" >> ${GITHUB_OUTPUT}
|
||||
|
||||
integer-benchmarks:
|
||||
name: Execute integer benchmarks for all operations flavor
|
||||
needs: prepare-matrix
|
||||
runs-on: ${{ github.event.inputs.runner_name }}
|
||||
if: ${{ !cancelled() }}
|
||||
continue-on-error: true
|
||||
@@ -64,7 +35,7 @@ jobs:
|
||||
max-parallel: 1
|
||||
matrix:
|
||||
command: [ integer, integer_multi_bit]
|
||||
op_flavor: ${{ fromJson(needs.prepare-matrix.outputs.op_flavor) }}
|
||||
op_flavor: [ default, default_comp, default_scalar, default_scalar_comp, smart, smart_comp, smart_scalar, smart_parallelized, smart_parallelized_comp, smart_scalar_parallelized, unchecked, unchecked_comp, unchecked_scalar, unchecked_scalar_comp, misc ]
|
||||
steps:
|
||||
- name: Instance configuration used
|
||||
run: |
|
||||
@@ -74,7 +45,7 @@ jobs:
|
||||
echo "Request ID: ${{ inputs.request_id }}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -96,15 +67,19 @@ jobs:
|
||||
override: true
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
token: ${{ secrets.CONCRETE_ACTIONS_TOKEN }}
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run benchmarks with AVX512
|
||||
run: |
|
||||
make AVX512_SUPPORT=ON BENCH_OP_FLAVOR=${{ matrix.op_flavor }} bench_${{ matrix.command }}
|
||||
just AVX512_SUPPORT=ON BENCH_OP_FLAVOR=${{ matrix.op_flavor }} bench_${{ matrix.command }}
|
||||
|
||||
- name: Parse results
|
||||
run: |
|
||||
|
||||
@@ -44,7 +44,7 @@ jobs:
|
||||
echo "BENCH_DATE=$(date --iso-8601=seconds)" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -59,13 +59,18 @@ jobs:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run multi-bit benchmarks with AVX512
|
||||
run: |
|
||||
make AVX512_SUPPORT=ON FAST_BENCH=TRUE bench_integer_multi_bit
|
||||
just AVX512_SUPPORT=ON FAST_BENCH=TRUE bench_integer_multi_bit
|
||||
|
||||
- name: Parse benchmarks to csv
|
||||
run: |
|
||||
make PARSE_INTEGER_BENCH_CSV_FILE=${{ env.PARSE_INTEGER_BENCH_CSV_FILE }} \
|
||||
just PARSE_INTEGER_BENCH_CSV_FILE=${{ env.PARSE_INTEGER_BENCH_CSV_FILE }} \
|
||||
parse_integer_benches
|
||||
|
||||
- name: Upload csv results artifact
|
||||
@@ -96,7 +101,7 @@ jobs:
|
||||
path: ${{ env.RESULTS_FILENAME }}
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
|
||||
52
.github/workflows/m1_tests.yml
vendored
52
.github/workflows/m1_tests.yml
vendored
@@ -15,6 +15,7 @@ env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RUSTFLAGS: "-C target-cpu=native"
|
||||
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
CARGO_PROFILE: release_lto_off
|
||||
FAST_TESTS: "TRUE"
|
||||
|
||||
concurrency:
|
||||
@@ -27,92 +28,97 @@ jobs:
|
||||
runs-on: ["self-hosted", "m1mac"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
|
||||
- name: Install latest stable
|
||||
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af
|
||||
with:
|
||||
toolchain: stable
|
||||
default: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run pcc checks
|
||||
run: |
|
||||
make pcc
|
||||
just pcc
|
||||
|
||||
- name: Build concrete-csprng
|
||||
run: |
|
||||
make build_concrete_csprng
|
||||
just build_concrete_csprng
|
||||
|
||||
- name: Build Release core
|
||||
run: |
|
||||
make build_core
|
||||
just build_core
|
||||
|
||||
- name: Build Release boolean
|
||||
run: |
|
||||
make build_boolean
|
||||
just build_boolean
|
||||
|
||||
- name: Build Release shortint
|
||||
run: |
|
||||
make build_shortint
|
||||
just build_shortint
|
||||
|
||||
- name: Build Release integer
|
||||
run: |
|
||||
make build_integer
|
||||
just build_integer
|
||||
|
||||
- name: Build Release tfhe full
|
||||
run: |
|
||||
make build_tfhe_full
|
||||
just build_tfhe_full
|
||||
|
||||
- name: Build Release c_api
|
||||
run: |
|
||||
make build_c_api
|
||||
just build_c_api
|
||||
|
||||
- name: Run concrete-csprng tests
|
||||
run: |
|
||||
make test_concrete_csprng
|
||||
just test_concrete_csprng
|
||||
|
||||
- name: Run core tests
|
||||
run: |
|
||||
make test_core_crypto
|
||||
just test_core_crypto
|
||||
|
||||
- name: Run boolean tests
|
||||
run: |
|
||||
make test_boolean
|
||||
just test_boolean
|
||||
|
||||
- name: Run C API tests
|
||||
run: |
|
||||
make test_c_api
|
||||
just test_c_api
|
||||
|
||||
- name: Run user docs tests
|
||||
run: |
|
||||
make test_user_doc
|
||||
just test_user_doc
|
||||
|
||||
# JS tests are more easily launched in docker, we won't test that on M1 as docker is pretty
|
||||
# slow on Apple machines due to the virtualization layer.
|
||||
|
||||
- name: Gen Keys if required
|
||||
run: |
|
||||
make gen_key_cache
|
||||
just gen_key_cache
|
||||
|
||||
- name: Run shortint tests
|
||||
run: |
|
||||
make test_shortint_ci
|
||||
just test_shortint_ci
|
||||
|
||||
- name: Run integer tests
|
||||
run: |
|
||||
make test_integer_ci
|
||||
just test_integer_ci
|
||||
|
||||
- name: Gen Keys if required
|
||||
run: |
|
||||
make GEN_KEY_CACHE_MULTI_BIT_ONLY=TRUE gen_key_cache
|
||||
just GEN_KEY_CACHE_MULTI_BIT_ONLY=TRUE gen_key_cache
|
||||
|
||||
- name: Run shortint multi bit tests
|
||||
run: |
|
||||
make test_shortint_multi_bit_ci
|
||||
just test_shortint_multi_bit_ci
|
||||
|
||||
- name: Run integer multi bit tests
|
||||
run: |
|
||||
make test_integer_multi_bit_ci
|
||||
# # These multi bit integer tests are too slow on M1 with low core count and low RAM
|
||||
# - name: Run integer multi bit tests
|
||||
# run: |
|
||||
# just test_integer_multi_bit_ci
|
||||
|
||||
remove_label:
|
||||
name: Remove m1_test label
|
||||
|
||||
19
.github/workflows/make_release.yml
vendored
19
.github/workflows/make_release.yml
vendored
@@ -30,7 +30,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -42,30 +42,39 @@ jobs:
|
||||
run: |
|
||||
cargo publish -p tfhe --token ${{ env.CRATES_TOKEN }} ${{ env.DRY_RUN }}
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Build web package
|
||||
if: ${{ inputs.push_web_package }}
|
||||
run: |
|
||||
make build_web_js_api
|
||||
just build_web_js_api
|
||||
|
||||
- name: Publish web package
|
||||
if: ${{ inputs.push_web_package }}
|
||||
uses: JS-DevTools/npm-publish@4b07b26a2f6e0a51846e1870223e545bae91c552
|
||||
uses: JS-DevTools/npm-publish@5a85faf05d2ade2d5b6682bfe5359915d5159c6c
|
||||
with:
|
||||
token: ${{ secrets.NPM_TOKEN }}
|
||||
package: tfhe/pkg/package.json
|
||||
dry-run: ${{ inputs.dry_run }}
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Build Node package
|
||||
if: ${{ inputs.push_node_package }}
|
||||
run: |
|
||||
rm -rf tfhe/pkg
|
||||
|
||||
make build_node_js_api
|
||||
just build_node_js_api
|
||||
sed -i 's/"tfhe"/"node-tfhe"/g' tfhe/pkg/package.json
|
||||
|
||||
- name: Publish Node package
|
||||
if: ${{ inputs.push_node_package }}
|
||||
uses: JS-DevTools/npm-publish@4b07b26a2f6e0a51846e1870223e545bae91c552
|
||||
uses: JS-DevTools/npm-publish@5a85faf05d2ade2d5b6682bfe5359915d5159c6c
|
||||
with:
|
||||
token: ${{ secrets.NPM_TOKEN }}
|
||||
package: tfhe/pkg/package.json
|
||||
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
|
||||
11
.github/workflows/parameters_check.yml
vendored
11
.github/workflows/parameters_check.yml
vendored
@@ -17,10 +17,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
|
||||
- name: Checkout lattice-estimator
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: malb/lattice-estimator
|
||||
path: lattice_estimator
|
||||
@@ -30,9 +30,14 @@ jobs:
|
||||
sudo apt update
|
||||
sudo apt install -y sagemath
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Collect parameters
|
||||
run: |
|
||||
CARGO_PROFILE=devo make write_params_to_file
|
||||
just write_params_to_file
|
||||
|
||||
- name: Perform security check
|
||||
run: |
|
||||
|
||||
20
.github/workflows/pbs_benchmark.yml
vendored
20
.github/workflows/pbs_benchmark.yml
vendored
@@ -19,14 +19,6 @@ on:
|
||||
request_id:
|
||||
description: "Slab request ID"
|
||||
type: string
|
||||
# This input is not used in this workflow but still mandatory since a calling workflow could
|
||||
# use it. If a triggering command include a user_inputs field, then the triggered workflow
|
||||
# must include this very input, otherwise the workflow won't be called.
|
||||
# See start_full_benchmarks.yml as example.
|
||||
user_inputs:
|
||||
description: "Type of benchmarks to run"
|
||||
type: string
|
||||
default: "weekly_benchmarks"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@@ -51,7 +43,7 @@ jobs:
|
||||
echo "BENCH_DATE=$(date --iso-8601=seconds)" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -65,10 +57,14 @@ jobs:
|
||||
with:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run benchmarks with AVX512
|
||||
run: |
|
||||
make AVX512_SUPPORT=ON bench_pbs
|
||||
just AVX512_SUPPORT=ON bench_pbs
|
||||
|
||||
- name: Parse results
|
||||
run: |
|
||||
@@ -92,7 +88,7 @@ jobs:
|
||||
path: ${{ env.RESULTS_FILENAME }}
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
|
||||
13
.github/workflows/shortint_benchmark.yml
vendored
13
.github/workflows/shortint_benchmark.yml
vendored
@@ -43,7 +43,7 @@ jobs:
|
||||
echo "BENCH_DATE=$(date --iso-8601=seconds)" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -58,9 +58,14 @@ jobs:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run benchmarks with AVX512
|
||||
run: |
|
||||
make AVX512_SUPPORT=ON bench_shortint
|
||||
just AVX512_SUPPORT=ON bench_shortint
|
||||
|
||||
- name: Parse results
|
||||
run: |
|
||||
@@ -79,7 +84,7 @@ jobs:
|
||||
|
||||
- name: Measure key sizes
|
||||
run: |
|
||||
make measure_shortint_key_sizes
|
||||
just measure_shortint_key_sizes
|
||||
|
||||
- name: Parse key sizes results
|
||||
run: |
|
||||
@@ -94,7 +99,7 @@ jobs:
|
||||
path: ${{ env.RESULTS_FILENAME }}
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
|
||||
22
.github/workflows/shortint_full_benchmark.yml
vendored
22
.github/workflows/shortint_full_benchmark.yml
vendored
@@ -19,14 +19,6 @@ on:
|
||||
request_id:
|
||||
description: "Slab request ID"
|
||||
type: string
|
||||
# This input is not used in this workflow but still mandatory since a calling workflow could
|
||||
# use it. If a triggering command include a user_inputs field, then the triggered workflow
|
||||
# must include this very input, otherwise the workflow won't be called.
|
||||
# See start_full_benchmarks.yml as example.
|
||||
user_inputs:
|
||||
description: "Type of benchmarks to run"
|
||||
type: string
|
||||
default: "weekly_benchmarks"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@@ -51,7 +43,7 @@ jobs:
|
||||
echo "Request ID: ${{ inputs.request_id }}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -73,15 +65,19 @@ jobs:
|
||||
override: true
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
token: ${{ secrets.CONCRETE_ACTIONS_TOKEN }}
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run benchmarks with AVX512
|
||||
run: |
|
||||
make AVX512_SUPPORT=ON BENCH_OP_FLAVOR=${{ matrix.op_flavor }} bench_shortint
|
||||
just AVX512_SUPPORT=ON BENCH_OP_FLAVOR=${{ matrix.op_flavor }} bench_shortint
|
||||
|
||||
- name: Parse results
|
||||
run: |
|
||||
@@ -102,7 +98,7 @@ jobs:
|
||||
- name: Measure key sizes
|
||||
if: matrix.op_flavor == 'default'
|
||||
run: |
|
||||
make measure_shortint_key_sizes
|
||||
just measure_shortint_key_sizes
|
||||
|
||||
- name: Parse key sizes results
|
||||
if: matrix.op_flavor == 'default'
|
||||
|
||||
129
.github/workflows/signed_integer_benchmark.yml
vendored
129
.github/workflows/signed_integer_benchmark.yml
vendored
@@ -1,129 +0,0 @@
|
||||
# Run signed integer benchmarks on an AWS instance and return parsed results to Slab CI bot.
|
||||
name: Signed Integer benchmarks
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
instance_id:
|
||||
description: "Instance ID"
|
||||
type: string
|
||||
instance_image_id:
|
||||
description: "Instance AMI ID"
|
||||
type: string
|
||||
instance_type:
|
||||
description: "Instance product type"
|
||||
type: string
|
||||
runner_name:
|
||||
description: "Action runner name"
|
||||
type: string
|
||||
request_id:
|
||||
description: "Slab request ID"
|
||||
type: string
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RESULTS_FILENAME: parsed_benchmark_results_${{ github.sha }}.json
|
||||
PARSE_INTEGER_BENCH_CSV_FILE: tfhe_rs_integer_benches_${{ github.sha }}.csv
|
||||
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
|
||||
jobs:
|
||||
run-integer-benchmarks:
|
||||
name: Execute signed integer benchmarks in EC2
|
||||
runs-on: ${{ github.event.inputs.runner_name }}
|
||||
if: ${{ !cancelled() }}
|
||||
steps:
|
||||
- name: Instance configuration used
|
||||
run: |
|
||||
echo "IDs: ${{ inputs.instance_id }}"
|
||||
echo "AMI: ${{ inputs.instance_image_id }}"
|
||||
echo "Type: ${{ inputs.instance_type }}"
|
||||
echo "Request ID: ${{ inputs.request_id }}"
|
||||
|
||||
- name: Get benchmark date
|
||||
run: |
|
||||
echo "BENCH_DATE=$(date --iso-8601=seconds)" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up home
|
||||
# "Install rust" step require root user to have a HOME directory which is not set.
|
||||
run: |
|
||||
echo "HOME=/home/ubuntu" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af
|
||||
with:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
|
||||
- name: Run benchmarks with AVX512
|
||||
run: |
|
||||
make AVX512_SUPPORT=ON FAST_BENCH=TRUE bench_signed_integer
|
||||
|
||||
- name: Parse benchmarks to csv
|
||||
run: |
|
||||
make PARSE_INTEGER_BENCH_CSV_FILE=${{ env.PARSE_INTEGER_BENCH_CSV_FILE }} \
|
||||
parse_integer_benches
|
||||
|
||||
- name: Upload csv results artifact
|
||||
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
|
||||
with:
|
||||
name: ${{ github.sha }}_csv_integer
|
||||
path: ${{ env.PARSE_INTEGER_BENCH_CSV_FILE }}
|
||||
|
||||
- name: Parse results
|
||||
run: |
|
||||
COMMIT_DATE="$(git --no-pager show -s --format=%cd --date=iso8601-strict ${{ github.sha }})"
|
||||
COMMIT_HASH="$(git describe --tags --dirty)"
|
||||
python3 ./ci/benchmark_parser.py target/criterion ${{ env.RESULTS_FILENAME }} \
|
||||
--database tfhe_rs \
|
||||
--hardware ${{ inputs.instance_type }} \
|
||||
--project-version "${COMMIT_HASH}" \
|
||||
--branch ${{ github.ref_name }} \
|
||||
--commit-date "${COMMIT_DATE}" \
|
||||
--bench-date "${{ env.BENCH_DATE }}" \
|
||||
--walk-subdirs \
|
||||
--name-suffix avx512 \
|
||||
--throughput
|
||||
|
||||
- name: Upload parsed results artifact
|
||||
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
|
||||
with:
|
||||
name: ${{ github.sha }}_integer
|
||||
path: ${{ env.RESULTS_FILENAME }}
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
token: ${{ secrets.CONCRETE_ACTIONS_TOKEN }}
|
||||
|
||||
- name: Send data to Slab
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Computing HMac on results file"
|
||||
SIGNATURE="$(slab/scripts/hmac_calculator.sh ${{ env.RESULTS_FILENAME }} '${{ secrets.JOB_SECRET }}')"
|
||||
echo "Sending results to Slab..."
|
||||
curl -v -k \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-Slab-Repository: ${{ github.repository }}" \
|
||||
-H "X-Slab-Command: store_data_v2" \
|
||||
-H "X-Hub-Signature-256: sha256=${SIGNATURE}" \
|
||||
-d @${{ env.RESULTS_FILENAME }} \
|
||||
${{ secrets.SLAB_URL }}
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ failure() }}
|
||||
continue-on-error: true
|
||||
uses: rtCamp/action-slack-notify@b24d75fe0e728a4bf9fc42ee217caa686d141ee8
|
||||
env:
|
||||
SLACK_COLOR: ${{ job.status }}
|
||||
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
|
||||
SLACK_ICON: https://pbs.twimg.com/profile_images/1274014582265298945/OjBKP9kn_400x400.png
|
||||
SLACK_MESSAGE: "Signed integer benchmarks failed. (${{ env.ACTION_RUN_URL }})"
|
||||
SLACK_USERNAME: ${{ secrets.BOT_USERNAME }}
|
||||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
||||
133
.github/workflows/signed_integer_full_benchmark.yml
vendored
133
.github/workflows/signed_integer_full_benchmark.yml
vendored
@@ -1,133 +0,0 @@
|
||||
# Run all signed integer benchmarks on an AWS instance and return parsed results to Slab CI bot.
|
||||
name: Signed Integer full benchmarks
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
instance_id:
|
||||
description: "Instance ID"
|
||||
type: string
|
||||
instance_image_id:
|
||||
description: "Instance AMI ID"
|
||||
type: string
|
||||
instance_type:
|
||||
description: "Instance product type"
|
||||
type: string
|
||||
runner_name:
|
||||
description: "Action runner name"
|
||||
type: string
|
||||
request_id:
|
||||
description: "Slab request ID"
|
||||
type: string
|
||||
user_inputs:
|
||||
description: "Type of benchmarks to run"
|
||||
type: string
|
||||
default: "weekly_benchmarks"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RESULTS_FILENAME: parsed_benchmark_results_${{ github.sha }}.json
|
||||
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
|
||||
jobs:
|
||||
integer-benchmarks:
|
||||
name: Execute signed integer benchmarks for all operations flavor
|
||||
runs-on: ${{ github.event.inputs.runner_name }}
|
||||
if: ${{ !cancelled() }}
|
||||
continue-on-error: true
|
||||
strategy:
|
||||
max-parallel: 1
|
||||
matrix:
|
||||
command: [ integer, integer_multi_bit ]
|
||||
op_flavor: [ default, default_comp, default_scalar, default_scalar_comp,
|
||||
unchecked, unchecked_comp, unchecked_scalar, unchecked_scalar_comp ]
|
||||
steps:
|
||||
- name: Instance configuration used
|
||||
run: |
|
||||
echo "IDs: ${{ inputs.instance_id }}"
|
||||
echo "AMI: ${{ inputs.instance_image_id }}"
|
||||
echo "Type: ${{ inputs.instance_type }}"
|
||||
echo "Request ID: ${{ inputs.request_id }}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get benchmark details
|
||||
run: |
|
||||
echo "BENCH_DATE=$(date --iso-8601=seconds)" >> "${GITHUB_ENV}"
|
||||
echo "COMMIT_DATE=$(git --no-pager show -s --format=%cd --date=iso8601-strict ${{ github.sha }})" >> "${GITHUB_ENV}"
|
||||
echo "COMMIT_HASH=$(git describe --tags --dirty)" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Set up home
|
||||
# "Install rust" step require root user to have a HOME directory which is not set.
|
||||
run: |
|
||||
echo "HOME=/home/ubuntu" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af
|
||||
with:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
token: ${{ secrets.CONCRETE_ACTIONS_TOKEN }}
|
||||
|
||||
- name: Run benchmarks with AVX512
|
||||
run: |
|
||||
make AVX512_SUPPORT=ON BENCH_OP_FLAVOR=${{ matrix.op_flavor }} bench_signed_${{ matrix.command }}
|
||||
|
||||
- name: Parse results
|
||||
run: |
|
||||
python3 ./ci/benchmark_parser.py target/criterion ${{ env.RESULTS_FILENAME }} \
|
||||
--database tfhe_rs \
|
||||
--hardware ${{ inputs.instance_type }} \
|
||||
--project-version "${{ env.COMMIT_HASH }}" \
|
||||
--branch ${{ github.ref_name }} \
|
||||
--commit-date "${{ env.COMMIT_DATE }}" \
|
||||
--bench-date "${{ env.BENCH_DATE }}" \
|
||||
--walk-subdirs \
|
||||
--name-suffix avx512 \
|
||||
--throughput
|
||||
|
||||
- name: Upload parsed results artifact
|
||||
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
|
||||
with:
|
||||
name: ${{ github.sha }}_${{ matrix.command }}_${{ matrix.op_flavor }}
|
||||
path: ${{ env.RESULTS_FILENAME }}
|
||||
|
||||
- name: Send data to Slab
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Computing HMac on results file"
|
||||
SIGNATURE="$(slab/scripts/hmac_calculator.sh ${{ env.RESULTS_FILENAME }} '${{ secrets.JOB_SECRET }}')"
|
||||
echo "Sending results to Slab..."
|
||||
curl -v -k \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-Slab-Repository: ${{ github.repository }}" \
|
||||
-H "X-Slab-Command: store_data_v2" \
|
||||
-H "X-Hub-Signature-256: sha256=${SIGNATURE}" \
|
||||
-d @${{ env.RESULTS_FILENAME }} \
|
||||
${{ secrets.SLAB_URL }}
|
||||
|
||||
slack-notification:
|
||||
name: Slack Notification
|
||||
runs-on: ${{ github.event.inputs.runner_name }}
|
||||
if: ${{ failure() }}
|
||||
needs: integer-benchmarks
|
||||
steps:
|
||||
- name: Notify
|
||||
continue-on-error: true
|
||||
uses: rtCamp/action-slack-notify@b24d75fe0e728a4bf9fc42ee217caa686d141ee8
|
||||
env:
|
||||
SLACK_COLOR: ${{ job.status }}
|
||||
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
|
||||
SLACK_ICON: https://pbs.twimg.com/profile_images/1274014582265298945/OjBKP9kn_400x400.png
|
||||
SLACK_MESSAGE: "Signed integer full benchmarks failed. (${{ env.ACTION_RUN_URL }})"
|
||||
SLACK_USERNAME: ${{ secrets.BOT_USERNAME }}
|
||||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
||||
@@ -1,129 +0,0 @@
|
||||
# Run signed integer benchmarks with multi-bit cryptographic parameters on an AWS instance and return parsed results to Slab CI bot.
|
||||
name: Signed Integer Multi-bit benchmarks
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
instance_id:
|
||||
description: "Instance ID"
|
||||
type: string
|
||||
instance_image_id:
|
||||
description: "Instance AMI ID"
|
||||
type: string
|
||||
instance_type:
|
||||
description: "Instance product type"
|
||||
type: string
|
||||
runner_name:
|
||||
description: "Action runner name"
|
||||
type: string
|
||||
request_id:
|
||||
description: "Slab request ID"
|
||||
type: string
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RESULTS_FILENAME: parsed_benchmark_results_${{ github.sha }}.json
|
||||
PARSE_INTEGER_BENCH_CSV_FILE: tfhe_rs_integer_benches_${{ github.sha }}.csv
|
||||
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
|
||||
jobs:
|
||||
run-integer-benchmarks:
|
||||
name: Execute signed integer multi-bit benchmarks in EC2
|
||||
runs-on: ${{ github.event.inputs.runner_name }}
|
||||
if: ${{ !cancelled() }}
|
||||
steps:
|
||||
- name: Instance configuration used
|
||||
run: |
|
||||
echo "IDs: ${{ inputs.instance_id }}"
|
||||
echo "AMI: ${{ inputs.instance_image_id }}"
|
||||
echo "Type: ${{ inputs.instance_type }}"
|
||||
echo "Request ID: ${{ inputs.request_id }}"
|
||||
|
||||
- name: Get benchmark date
|
||||
run: |
|
||||
echo "BENCH_DATE=$(date --iso-8601=seconds)" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up home
|
||||
# "Install rust" step require root user to have a HOME directory which is not set.
|
||||
run: |
|
||||
echo "HOME=/home/ubuntu" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af
|
||||
with:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
|
||||
- name: Run multi-bit benchmarks with AVX512
|
||||
run: |
|
||||
make AVX512_SUPPORT=ON FAST_BENCH=TRUE bench_signed_integer_multi_bit
|
||||
|
||||
- name: Parse benchmarks to csv
|
||||
run: |
|
||||
make PARSE_INTEGER_BENCH_CSV_FILE=${{ env.PARSE_INTEGER_BENCH_CSV_FILE }} \
|
||||
parse_integer_benches
|
||||
|
||||
- name: Upload csv results artifact
|
||||
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
|
||||
with:
|
||||
name: ${{ github.sha }}_csv_integer
|
||||
path: ${{ env.PARSE_INTEGER_BENCH_CSV_FILE }}
|
||||
|
||||
- name: Parse results
|
||||
run: |
|
||||
COMMIT_DATE="$(git --no-pager show -s --format=%cd --date=iso8601-strict ${{ github.sha }})"
|
||||
COMMIT_HASH="$(git describe --tags --dirty)"
|
||||
python3 ./ci/benchmark_parser.py target/criterion ${{ env.RESULTS_FILENAME }} \
|
||||
--database tfhe_rs \
|
||||
--hardware ${{ inputs.instance_type }} \
|
||||
--project-version "${COMMIT_HASH}" \
|
||||
--branch ${{ github.ref_name }} \
|
||||
--commit-date "${COMMIT_DATE}" \
|
||||
--bench-date "${{ env.BENCH_DATE }}" \
|
||||
--walk-subdirs \
|
||||
--name-suffix avx512 \
|
||||
--throughput
|
||||
|
||||
- name: Upload parsed results artifact
|
||||
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
|
||||
with:
|
||||
name: ${{ github.sha }}_integer
|
||||
path: ${{ env.RESULTS_FILENAME }}
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
token: ${{ secrets.CONCRETE_ACTIONS_TOKEN }}
|
||||
|
||||
- name: Send data to Slab
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Computing HMac on results file"
|
||||
SIGNATURE="$(slab/scripts/hmac_calculator.sh ${{ env.RESULTS_FILENAME }} '${{ secrets.JOB_SECRET }}')"
|
||||
echo "Sending results to Slab..."
|
||||
curl -v -k \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-Slab-Repository: ${{ github.repository }}" \
|
||||
-H "X-Slab-Command: store_data_v2" \
|
||||
-H "X-Hub-Signature-256: sha256=${SIGNATURE}" \
|
||||
-d @${{ env.RESULTS_FILENAME }} \
|
||||
${{ secrets.SLAB_URL }}
|
||||
|
||||
- name: Slack Notification
|
||||
if: ${{ failure() }}
|
||||
continue-on-error: true
|
||||
uses: rtCamp/action-slack-notify@b24d75fe0e728a4bf9fc42ee217caa686d141ee8
|
||||
env:
|
||||
SLACK_COLOR: ${{ job.status }}
|
||||
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
|
||||
SLACK_ICON: https://pbs.twimg.com/profile_images/1274014582265298945/OjBKP9kn_400x400.png
|
||||
SLACK_MESSAGE: "Signed integer benchmarks failed. (${{ env.ACTION_RUN_URL }})"
|
||||
SLACK_USERNAME: ${{ secrets.BOT_USERNAME }}
|
||||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
||||
35
.github/workflows/start_benchmarks.yml
vendored
35
.github/workflows/start_benchmarks.yml
vendored
@@ -20,18 +20,10 @@ on:
|
||||
description: "Run integer benches"
|
||||
type: boolean
|
||||
default: true
|
||||
signed_integer_bench:
|
||||
description: "Run signed integer benches"
|
||||
type: boolean
|
||||
default: true
|
||||
integer_multi_bit_bench:
|
||||
description: "Run integer multi bit benches"
|
||||
type: boolean
|
||||
default: true
|
||||
signed_integer_multi_bit_bench:
|
||||
description: "Run signed integer multi bit benches"
|
||||
type: boolean
|
||||
default: true
|
||||
pbs_bench:
|
||||
description: "Run PBS benches"
|
||||
type: boolean
|
||||
@@ -46,20 +38,17 @@ jobs:
|
||||
if: ${{ (github.event_name == 'push' && github.repository == 'zama-ai/tfhe-rs') || github.event_name == 'workflow_dispatch' }}
|
||||
strategy:
|
||||
matrix:
|
||||
command: [ boolean_bench, shortint_bench,
|
||||
integer_bench, integer_multi_bit_bench,
|
||||
signed_integer_bench, signed_integer_multi_bit_bench,
|
||||
pbs_bench, wasm_client_bench ]
|
||||
command: [boolean_bench, shortint_bench, integer_bench, integer_multi_bit_bench, pbs_bench, wasm_client_bench]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check for file changes
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@1c938490c880156b746568a518594309cfb3f66b
|
||||
uses: tj-actions/changed-files@246636f5fa148b5ad8e65ca4c57b18af3123e5f6
|
||||
with:
|
||||
files_yaml: |
|
||||
common_benches:
|
||||
@@ -80,23 +69,13 @@ jobs:
|
||||
integer_bench:
|
||||
- tfhe/src/shortint/**
|
||||
- tfhe/src/integer/**
|
||||
- tfhe/benches/integer/bench.rs
|
||||
- tfhe/benches/integer/**
|
||||
- .github/workflows/integer_benchmark.yml
|
||||
integer_multi_bit_bench:
|
||||
- tfhe/src/shortint/**
|
||||
- tfhe/src/integer/**
|
||||
- tfhe/benches/integer/bench.rs
|
||||
- .github/workflows/integer_multi_bit_benchmark.yml
|
||||
signed_integer_bench:
|
||||
- tfhe/src/shortint/**
|
||||
- tfhe/src/integer/**
|
||||
- tfhe/benches/integer/signed_bench.rs
|
||||
- .github/workflows/signed_integer_benchmark.yml
|
||||
signed_integer_multi_bit_bench:
|
||||
- tfhe/src/shortint/**
|
||||
- tfhe/src/integer/**
|
||||
- tfhe/benches/integer/signed_bench.rs
|
||||
- .github/workflows/signed_integer_multi_bit_benchmark.yml
|
||||
- tfhe/benches/integer/**
|
||||
- .github/workflows/integer_benchmark.yml
|
||||
pbs_bench:
|
||||
- tfhe/src/core_crypto/**
|
||||
- tfhe/benches/core_crypto/**
|
||||
@@ -106,7 +85,7 @@ jobs:
|
||||
- .github/workflows/wasm_client_benchmark.yml
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
|
||||
33
.github/workflows/start_full_benchmarks.yml
vendored
33
.github/workflows/start_full_benchmarks.yml
vendored
@@ -3,57 +3,34 @@ name: Start full suite benchmarks
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# Weekly benchmarks will be triggered each Saturday at 1a.m.
|
||||
# Job will be triggered each Saturday at 1a.m.
|
||||
- cron: '0 1 * * 6'
|
||||
# Quarterly benchmarks will be triggered right before end of quarter, the 25th of the current month at 4a.m.
|
||||
# These benchmarks are far longer to execute hence the reason to run them only four time a year.
|
||||
- cron: '0 4 25 MAR,JUN,SEP,DEC *'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
benchmark_type:
|
||||
description: 'Benchmark type'
|
||||
required: true
|
||||
default: 'weekly'
|
||||
type: choice
|
||||
options:
|
||||
- weekly
|
||||
- quarterly
|
||||
|
||||
jobs:
|
||||
start-benchmarks:
|
||||
if: ${{ (github.event_name == 'schedule' && github.repository == 'zama-ai/tfhe-rs') || github.event_name == 'workflow_dispatch' }}
|
||||
strategy:
|
||||
matrix:
|
||||
command: [ boolean_bench, shortint_full_bench, integer_full_bench,
|
||||
signed_integer_full_bench, pbs_bench, wasm_client_bench ]
|
||||
command: [ boolean_bench, shortint_full_bench, integer_full_bench, pbs_bench, wasm_client_bench ]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout tfhe-rs
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
token: ${{ secrets.CONCRETE_ACTIONS_TOKEN }}
|
||||
|
||||
- name: Set benchmarks type as weekly
|
||||
if: (github.event_name == 'workflow_dispatch' && inputs.benchmark_type == 'weekly') || github.event.schedule == '0 1 * * 6'
|
||||
run: |
|
||||
echo "BENCH_TYPE=weekly_benchmarks" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Set benchmarks type as quarterly
|
||||
if: (github.event_name == 'workflow_dispatch' && inputs.benchmark_type == 'quarterly') || github.event.schedule == '0 4 25 MAR,JUN,SEP,DEC *'
|
||||
run: |
|
||||
echo "BENCH_TYPE=quarterly_benchmarks" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Start AWS job in Slab
|
||||
shell: bash
|
||||
run: |
|
||||
echo -n '{"command": "${{ matrix.command }}", "git_ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "user_inputs": "${{ env.BENCH_TYPE }}"}' > command.json
|
||||
echo -n '{"command": "${{ matrix.command }}", "git_ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}' > command.json
|
||||
SIGNATURE="$(slab/scripts/hmac_calculator.sh command.json '${{ secrets.JOB_SECRET }}')"
|
||||
curl -v -k \
|
||||
--fail-with-body \
|
||||
|
||||
2
.github/workflows/sync_on_push.yml
vendored
2
.github/workflows/sync_on_push.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Save repo
|
||||
|
||||
@@ -31,7 +31,7 @@ jobs:
|
||||
@slab-ci cpu_fast_test
|
||||
|
||||
- name: Add approved label
|
||||
uses: actions-ecosystem/action-add-labels@18f1af5e3544586314bbe15c0273249c770b2daf
|
||||
uses: actions-ecosystem/action-add-labels@bd52874380e3909a1ac983768df6976535ece7f8
|
||||
if: ${{ github.event_name == 'pull_request_review' && github.event.review.state == 'approved' && !contains(fromJSON(env.LABELS), 'approved') }}
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -48,7 +48,7 @@ jobs:
|
||||
Pull Request has been approved :tada:
|
||||
Launching full test suite...
|
||||
@slab-ci cpu_test
|
||||
@slab-ci cpu_unsigned_integer_test
|
||||
@slab-ci cpu_signed_integer_test
|
||||
@slab-ci cpu_integer_test
|
||||
@slab-ci cpu_multi_bit_test
|
||||
@slab-ci cpu_wasm_test
|
||||
@slab-ci csprng_randomness_testing
|
||||
|
||||
26
.github/workflows/wasm_client_benchmark.yml
vendored
26
.github/workflows/wasm_client_benchmark.yml
vendored
@@ -19,14 +19,6 @@ on:
|
||||
request_id:
|
||||
description: "Slab request ID"
|
||||
type: string
|
||||
# This input is not used in this workflow but still mandatory since a calling workflow could
|
||||
# use it. If a triggering command include a user_inputs field, then the triggered workflow
|
||||
# must include this very input, otherwise the workflow won't be called.
|
||||
# See start_full_benchmarks.yml as example.
|
||||
user_inputs:
|
||||
description: "Type of benchmarks to run"
|
||||
type: string
|
||||
default: "weekly_benchmarks"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
@@ -51,7 +43,7 @@ jobs:
|
||||
echo "BENCH_DATE=$(date --iso-8601=seconds)" >> "${GITHUB_ENV}"
|
||||
|
||||
- name: Checkout tfhe-rs repo with tags
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -65,15 +57,19 @@ jobs:
|
||||
with:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
|
||||
|
||||
- name: Install just
|
||||
run: |
|
||||
cargo install just
|
||||
|
||||
- name: Run benchmarks
|
||||
run: |
|
||||
make install_node
|
||||
make ci_bench_web_js_api_parallel
|
||||
just install_node
|
||||
just ci_bench_web_js_api_parallel
|
||||
|
||||
- name: Parse results
|
||||
run: |
|
||||
make parse_wasm_benchmarks
|
||||
just parse_wasm_benchmarks
|
||||
|
||||
COMMIT_DATE="$(git --no-pager show -s --format=%cd --date=iso8601-strict ${{ github.sha }})"
|
||||
COMMIT_HASH="$(git describe --tags --dirty)"
|
||||
@@ -88,7 +84,7 @@ jobs:
|
||||
|
||||
- name: Measure public key and ciphertext sizes in HL Api
|
||||
run: |
|
||||
make measure_hlapi_compact_pk_ct_sizes
|
||||
just measure_hlapi_compact_pk_ct_sizes
|
||||
|
||||
- name: Parse key and ciphertext sizes results
|
||||
run: |
|
||||
@@ -103,7 +99,7 @@ jobs:
|
||||
path: ${{ env.RESULTS_FILENAME }}
|
||||
|
||||
- name: Checkout Slab repo
|
||||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
||||
with:
|
||||
repository: zama-ai/slab
|
||||
path: slab
|
||||
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -3,9 +3,9 @@ target/
|
||||
.vscode/
|
||||
|
||||
# Path we use for internal-keycache during tests
|
||||
/keys/
|
||||
./keys/
|
||||
# In case of symlinked keys
|
||||
/keys
|
||||
./keys
|
||||
|
||||
**/Cargo.lock
|
||||
**/*.bin
|
||||
@@ -18,4 +18,4 @@ target/
|
||||
dieharder_run.log
|
||||
|
||||
# Coverage reports
|
||||
/coverage/
|
||||
./coverage/
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
ignore:
|
||||
- .git
|
||||
- target
|
||||
- tfhe/benchmarks_parameters
|
||||
- tfhe/web_wasm_parallel_tests/node_modules
|
||||
- tfhe/web_wasm_parallel_tests/dist
|
||||
- keys
|
||||
- coverage
|
||||
|
||||
rules:
|
||||
# checks if file ends in a newline character
|
||||
end-of-file:
|
||||
enable: true
|
||||
single-new-line: true
|
||||
722
Makefile
722
Makefile
@@ -1,722 +0,0 @@
|
||||
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)
|
||||
RS_BUILD_TOOLCHAIN:=stable
|
||||
CARGO_RS_BUILD_TOOLCHAIN:=+$(RS_BUILD_TOOLCHAIN)
|
||||
CARGO_PROFILE?=release
|
||||
MIN_RUST_VERSION:=$(shell grep '^rust-version[[:space:]]*=' tfhe/Cargo.toml | cut -d '=' -f 2 | xargs)
|
||||
AVX512_SUPPORT?=OFF
|
||||
WASM_RUSTFLAGS:=
|
||||
BIG_TESTS_INSTANCE?=FALSE
|
||||
GEN_KEY_CACHE_MULTI_BIT_ONLY?=FALSE
|
||||
GEN_KEY_CACHE_COVERAGE_ONLY?=FALSE
|
||||
PARSE_INTEGER_BENCH_CSV_FILE?=tfhe_rs_integer_benches.csv
|
||||
FAST_TESTS?=FALSE
|
||||
FAST_BENCH?=FALSE
|
||||
BENCH_OP_FLAVOR?=DEFAULT
|
||||
NODE_VERSION=20
|
||||
# sed: -n, do not print input stream, -e means a script/expression
|
||||
# 1,/version/ indicates from the first line, to the line matching version at the start of the line
|
||||
# p indicates to print, so we keep only the start of the Cargo.toml until we hit the first version
|
||||
# entry which should be the version of tfhe
|
||||
TFHE_CURRENT_VERSION:=\
|
||||
$(shell sed -n -e '1,/^version/p' tfhe/Cargo.toml | \
|
||||
grep '^version[[:space:]]*=' | cut -d '=' -f 2 | xargs)
|
||||
# Cargo has a hard time distinguishing between our package from the workspace and a package that
|
||||
# could be a dependency, so we build an unambiguous spec here
|
||||
TFHE_SPEC:=tfhe@$(TFHE_CURRENT_VERSION)
|
||||
# This is done to avoid forgetting it, we still precise the RUSTFLAGS in the commands to be able to
|
||||
# copy paste the command in the terminal and change them if required without forgetting the flags
|
||||
export RUSTFLAGS?=-C target-cpu=native
|
||||
|
||||
ifeq ($(AVX512_SUPPORT),ON)
|
||||
AVX512_FEATURE=nightly-avx512
|
||||
else
|
||||
AVX512_FEATURE=
|
||||
endif
|
||||
|
||||
ifeq ($(GEN_KEY_CACHE_MULTI_BIT_ONLY),TRUE)
|
||||
MULTI_BIT_ONLY=--multi-bit-only
|
||||
else
|
||||
MULTI_BIT_ONLY=
|
||||
endif
|
||||
|
||||
ifeq ($(GEN_KEY_CACHE_COVERAGE_ONLY),TRUE)
|
||||
COVERAGE_ONLY=--coverage-only
|
||||
else
|
||||
COVERAGE_ONLY=
|
||||
endif
|
||||
|
||||
# Variables used only for regex_engine example
|
||||
REGEX_STRING?=''
|
||||
REGEX_PATTERN?=''
|
||||
|
||||
# Exclude these files from coverage reports
|
||||
define COVERAGE_EXCLUDED_FILES
|
||||
--exclude-files apps/trivium/src/trivium/* \
|
||||
--exclude-files apps/trivium/src/kreyvium/* \
|
||||
--exclude-files apps/trivium/src/static_deque/* \
|
||||
--exclude-files apps/trivium/src/trans_ciphering/* \
|
||||
--exclude-files tasks/src/* \
|
||||
--exclude-files tfhe/benches/boolean/* \
|
||||
--exclude-files tfhe/benches/core_crypto/* \
|
||||
--exclude-files tfhe/benches/shortint/* \
|
||||
--exclude-files tfhe/benches/integer/* \
|
||||
--exclude-files tfhe/benches/* \
|
||||
--exclude-files tfhe/examples/regex_engine/* \
|
||||
--exclude-files tfhe/examples/utilities/*
|
||||
endef
|
||||
|
||||
.PHONY: rs_check_toolchain # Echo the rust toolchain used for checks
|
||||
rs_check_toolchain:
|
||||
@echo $(RS_CHECK_TOOLCHAIN)
|
||||
|
||||
.PHONY: rs_build_toolchain # Echo the rust toolchain used for builds
|
||||
rs_build_toolchain:
|
||||
@echo $(RS_BUILD_TOOLCHAIN)
|
||||
|
||||
.PHONY: install_rs_check_toolchain # Install the toolchain used for checks
|
||||
install_rs_check_toolchain:
|
||||
@rustup toolchain list | grep -q "$(RS_CHECK_TOOLCHAIN)" || \
|
||||
rustup toolchain install --profile default "$(RS_CHECK_TOOLCHAIN)" || \
|
||||
( echo "Unable to install $(RS_CHECK_TOOLCHAIN) toolchain, check your rustup installation. \
|
||||
Rustup can be downloaded at https://rustup.rs/" && exit 1 )
|
||||
|
||||
.PHONY: install_rs_build_toolchain # Install the toolchain used for builds
|
||||
install_rs_build_toolchain:
|
||||
@( rustup toolchain list | grep -q "$(RS_BUILD_TOOLCHAIN)" && \
|
||||
./scripts/check_cargo_min_ver.sh \
|
||||
--rust-toolchain "$(CARGO_RS_BUILD_TOOLCHAIN)" \
|
||||
--min-rust-version "$(MIN_RUST_VERSION)" ) || \
|
||||
rustup toolchain install --profile default "$(RS_BUILD_TOOLCHAIN)" || \
|
||||
( echo "Unable to install $(RS_BUILD_TOOLCHAIN) toolchain, check your rustup installation. \
|
||||
Rustup can be downloaded at https://rustup.rs/" && exit 1 )
|
||||
|
||||
.PHONY: install_cargo_nextest # Install cargo nextest used for shortint tests
|
||||
install_cargo_nextest: install_rs_build_toolchain
|
||||
@cargo nextest --version > /dev/null 2>&1 || \
|
||||
cargo $(CARGO_RS_BUILD_TOOLCHAIN) install cargo-nextest --locked || \
|
||||
( echo "Unable to install cargo nextest, unknown error." && exit 1 )
|
||||
|
||||
.PHONY: install_wasm_pack # Install wasm-pack to build JS packages
|
||||
install_wasm_pack: install_rs_build_toolchain
|
||||
@wasm-pack --version > /dev/null 2>&1 || \
|
||||
cargo $(CARGO_RS_BUILD_TOOLCHAIN) install wasm-pack || \
|
||||
( echo "Unable to install cargo wasm-pack, unknown error." && exit 1 )
|
||||
|
||||
.PHONY: install_node # Install last version of NodeJS via nvm
|
||||
install_node:
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | $(SHELL)
|
||||
source ~/.bashrc
|
||||
$(SHELL) -i -c 'nvm install $(NODE_VERSION)' || \
|
||||
( echo "Unable to install node, unknown error." && exit 1 )
|
||||
|
||||
.PHONY: install_dieharder # Install dieharder for apt distributions or macOS
|
||||
install_dieharder:
|
||||
@dieharder -h > /dev/null 2>&1 || \
|
||||
if [[ "$(OS)" == "Linux" ]]; then \
|
||||
sudo apt update && sudo apt install -y dieharder; \
|
||||
elif [[ "$(OS)" == "Darwin" ]]; then\
|
||||
brew install dieharder; \
|
||||
fi || ( echo "Unable to install dieharder, unknown error." && exit 1 )
|
||||
|
||||
.PHONY: install_tarpaulin # Install tarpaulin to perform code coverage
|
||||
install_tarpaulin: install_rs_build_toolchain
|
||||
@cargo tarpaulin --version > /dev/null 2>&1 || \
|
||||
cargo $(CARGO_RS_BUILD_TOOLCHAIN) install cargo-tarpaulin --locked || \
|
||||
( echo "Unable to install cargo tarpaulin, unknown error." && exit 1 )
|
||||
|
||||
.PHONY: check_linelint_installed # Check if linelint newline linter is installed
|
||||
check_linelint_installed:
|
||||
@printf "\n" | linelint - > /dev/null 2>&1 || \
|
||||
( echo "Unable to locate linelint. Try installing it: https://github.com/fernandrone/linelint/releases" && exit 1 )
|
||||
|
||||
.PHONY: fmt # Format rust code
|
||||
fmt: install_rs_check_toolchain
|
||||
cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" fmt
|
||||
|
||||
.PHONY: check_fmt # Check rust code format
|
||||
check_fmt: install_rs_check_toolchain
|
||||
cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" fmt --check
|
||||
|
||||
.PHONY: fix_newline # Fix newline at end of file issues to be UNIX compliant
|
||||
fix_newline: check_linelint_installed
|
||||
linelint -a .
|
||||
|
||||
.PHONY: check_newline # Check for newline at end of file to be UNIX compliant
|
||||
check_newline: check_linelint_installed
|
||||
linelint .
|
||||
|
||||
.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 \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_boolean # Run clippy lints enabling the boolean features
|
||||
clippy_boolean: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_shortint # Run clippy lints enabling the shortint features
|
||||
clippy_shortint: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_integer # Run clippy lints enabling the integer features
|
||||
clippy_integer: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),integer \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy # Run clippy lints enabling the boolean, shortint, integer
|
||||
clippy: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_c_api # Run clippy lints enabling the boolean, shortint and the C API
|
||||
clippy_c_api: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_js_wasm_api # Run clippy lints enabling the boolean, shortint, integer and the js wasm API
|
||||
clippy_js_wasm_api: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
--features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_tasks # Run clippy lints on helper tasks crate.
|
||||
clippy_tasks:
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
-p tasks -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_trivium # Run clippy lints on Trivium app
|
||||
clippy_trivium: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
|
||||
-p tfhe-trivium -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_all_targets # Run clippy lints on all targets (benches, examples, etc.)
|
||||
clippy_all_targets:
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,safe-deserialization \
|
||||
-p $(TFHE_SPEC) -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_concrete_csprng # Run clippy lints on concrete-csprng
|
||||
clippy_concrete_csprng:
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
|
||||
--features=$(TARGET_ARCH_FEATURE) \
|
||||
-p concrete-csprng -- --no-deps -D warnings
|
||||
|
||||
.PHONY: clippy_all # Run all clippy targets
|
||||
clippy_all: clippy clippy_boolean clippy_shortint clippy_integer clippy_all_targets clippy_c_api \
|
||||
clippy_js_wasm_api clippy_tasks clippy_core clippy_concrete_csprng clippy_trivium
|
||||
|
||||
.PHONY: clippy_fast # Run main clippy targets
|
||||
clippy_fast: clippy clippy_all_targets clippy_c_api clippy_js_wasm_api clippy_tasks clippy_core \
|
||||
clippy_concrete_csprng
|
||||
|
||||
.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)
|
||||
@if [[ "$(AVX512_SUPPORT)" == "ON" ]]; then \
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),$(AVX512_FEATURE) -p $(TFHE_SPEC); \
|
||||
fi
|
||||
|
||||
.PHONY: build_core_experimental # Build core_crypto with experimental features
|
||||
build_core_experimental: install_rs_build_toolchain install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental -p $(TFHE_SPEC)
|
||||
@if [[ "$(AVX512_SUPPORT)" == "ON" ]]; then \
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,$(AVX512_FEATURE) -p $(TFHE_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
|
||||
|
||||
.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
|
||||
|
||||
.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
|
||||
|
||||
.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
|
||||
|
||||
.PHONY: build_c_api # Build the C API for boolean, shortint and integer
|
||||
build_c_api: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api,high-level-c-api,safe-deserialization \
|
||||
-p $(TFHE_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,safe-deserialization,experimental-force_fft_algo_dif4 \
|
||||
-p $(TFHE_SPEC)
|
||||
|
||||
.PHONY: build_web_js_api # Build the js API targeting the web browser
|
||||
build_web_js_api: install_rs_build_toolchain install_wasm_pack
|
||||
cd tfhe && \
|
||||
RUSTFLAGS="$(WASM_RUSTFLAGS)" rustup run "$(RS_BUILD_TOOLCHAIN)" \
|
||||
wasm-pack build --release --target=web \
|
||||
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api
|
||||
|
||||
.PHONY: build_web_js_api_parallel # Build the js API targeting the web browser with parallelism support
|
||||
build_web_js_api_parallel: install_rs_check_toolchain install_wasm_pack
|
||||
cd tfhe && \
|
||||
rustup component add rust-src --toolchain $(RS_CHECK_TOOLCHAIN) && \
|
||||
RUSTFLAGS="$(WASM_RUSTFLAGS) -C target-feature=+atomics,+bulk-memory,+mutable-globals" rustup run $(RS_CHECK_TOOLCHAIN) \
|
||||
wasm-pack build --release --target=web \
|
||||
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,parallel-wasm-api \
|
||||
-Z build-std=panic_abort,std
|
||||
|
||||
.PHONY: build_node_js_api # Build the js API targeting nodejs
|
||||
build_node_js_api: install_rs_build_toolchain install_wasm_pack
|
||||
cd tfhe && \
|
||||
RUSTFLAGS="$(WASM_RUSTFLAGS)" rustup run "$(RS_BUILD_TOOLCHAIN)" \
|
||||
wasm-pack build --release --target=nodejs \
|
||||
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api
|
||||
|
||||
.PHONY: build_concrete_csprng # Build concrete_csprng
|
||||
build_concrete_csprng: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE) -p concrete-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 -p $(TFHE_SPEC) -- core_crypto::
|
||||
@if [[ "$(AVX512_SUPPORT)" == "ON" ]]; then \
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,$(AVX512_FEATURE) -p $(TFHE_SPEC) -- core_crypto::; \
|
||||
fi
|
||||
|
||||
.PHONY: test_core_crypto_cov # Run the tests of the core_crypto module with code coverage
|
||||
test_core_crypto_cov: install_rs_build_toolchain install_rs_check_toolchain install_tarpaulin
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) tarpaulin --profile $(CARGO_PROFILE) \
|
||||
--out xml --ignore-panics --output-dir coverage/core_crypto --line --engine llvm --timeout 500 \
|
||||
--implicit-test-threads $(COVERAGE_EXCLUDED_FILES) \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,internal-keycache,__coverage \
|
||||
-p $(TFHE_SPEC) -- core_crypto::
|
||||
@if [[ "$(AVX512_SUPPORT)" == "ON" ]]; then \
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) tarpaulin --profile $(CARGO_PROFILE) \
|
||||
--out xml --ignore-panics --output-dir coverage/core_crypto_avx512 --line --engine llvm --timeout 500 \
|
||||
--implicit-test-threads $(COVERAGE_EXCLUDED_FILES) \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,internal-keycache,__coverage,$(AVX512_FEATURE) \
|
||||
-p $(TFHE_SPEC) -- core_crypto::; \
|
||||
fi
|
||||
|
||||
.PHONY: test_boolean # Run the tests of the boolean module
|
||||
test_boolean: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean -p $(TFHE_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 --ignore-panics --output-dir coverage/boolean --line --engine llvm --timeout 500 \
|
||||
$(COVERAGE_EXCLUDED_FILES) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,internal-keycache,__coverage \
|
||||
-p $(TFHE_SPEC) -- boolean::
|
||||
|
||||
.PHONY: test_c_api_rs # Run the rust tests for the C API
|
||||
test_c_api_rs: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean-c-api,shortint-c-api,high-level-c-api,safe-deserialization \
|
||||
-p $(TFHE_SPEC) \
|
||||
c_api
|
||||
|
||||
.PHONY: test_c_api_c # Run the C tests for the C API
|
||||
test_c_api_c: build_c_api
|
||||
./scripts/c_api_tests.sh
|
||||
|
||||
.PHONY: test_c_api # Run all the tests for the C API
|
||||
test_c_api: test_c_api_rs test_c_api_c
|
||||
|
||||
.PHONY: test_shortint_ci # Run the tests for shortint ci
|
||||
test_shortint_ci: install_rs_build_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/shortint-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)"
|
||||
|
||||
.PHONY: test_shortint_multi_bit_ci # Run the tests for shortint ci running only multibit tests
|
||||
test_shortint_multi_bit_ci: install_rs_build_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/shortint-tests.sh --rust-toolchain $(CARGO_RS_BUILD_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --multi-bit
|
||||
|
||||
.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::
|
||||
|
||||
.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 --ignore-panics --output-dir coverage/shortint --line --engine llvm --timeout 500 \
|
||||
$(COVERAGE_EXCLUDED_FILES) \
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache,__coverage \
|
||||
-p $(TFHE_SPEC) -- shortint::
|
||||
|
||||
.PHONY: test_integer_ci # Run the tests for integer ci
|
||||
test_integer_ci: install_rs_check_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_CHECK_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --avx512-support "$(AVX512_SUPPORT)"
|
||||
|
||||
.PHONY: test_unsigned_integer_ci # Run the tests for unsigned integer ci
|
||||
test_unsigned_integer_ci: install_rs_check_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_CHECK_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --avx512-support "$(AVX512_SUPPORT)" \
|
||||
--unsigned-only
|
||||
|
||||
.PHONY: test_signed_integer_ci # Run the tests for signed integer ci
|
||||
test_signed_integer_ci: install_rs_check_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_CHECK_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --avx512-support "$(AVX512_SUPPORT)" \
|
||||
--signed-only
|
||||
|
||||
.PHONY: test_integer_multi_bit_ci # Run the tests for integer ci running only multibit tests
|
||||
test_integer_multi_bit_ci: install_rs_check_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_CHECK_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --multi-bit --avx512-support "$(AVX512_SUPPORT)"
|
||||
|
||||
.PHONY: test_unsigned_integer_multi_bit_ci # Run the tests for nsigned integer ci running only multibit tests
|
||||
test_unsigned_integer_multi_bit_ci: install_rs_check_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_CHECK_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --multi-bit --avx512-support "$(AVX512_SUPPORT)" \
|
||||
--unsigned-only
|
||||
|
||||
.PHONY: test_signed_integer_multi_bit_ci # Run the tests for nsigned integer ci running only multibit tests
|
||||
test_signed_integer_multi_bit_ci: install_rs_check_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="$(BIG_TESTS_INSTANCE)" \
|
||||
FAST_TESTS="$(FAST_TESTS)" \
|
||||
./scripts/integer-tests.sh --rust-toolchain $(CARGO_RS_CHECK_TOOLCHAIN) \
|
||||
--cargo-profile "$(CARGO_PROFILE)" --multi-bit --avx512-support "$(AVX512_SUPPORT)" \
|
||||
--signed-only
|
||||
|
||||
.PHONY: test_safe_deserialization # Run the tests for safe deserialization
|
||||
test_safe_deserialization: install_rs_build_toolchain install_cargo_nextest
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache,safe-deserialization -p $(TFHE_SPEC) -- safe_deserialization::
|
||||
|
||||
.PHONY: test_integer # Run all the tests for integer
|
||||
test_integer: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),integer,internal-keycache -p $(TFHE_SPEC) -- integer::
|
||||
|
||||
.PHONY: test_high_level_api # Run all the tests for high_level_api
|
||||
test_high_level_api: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache -p $(TFHE_SPEC) \
|
||||
-- high_level_api::
|
||||
|
||||
.PHONY: test_user_doc # Run tests from the .md documentation
|
||||
test_user_doc: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) --doc \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer,internal-keycache -p $(TFHE_SPEC) \
|
||||
-- test_user_docs::
|
||||
|
||||
.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
|
||||
|
||||
.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
|
||||
|
||||
.PHONY: test_examples # Run tests for examples
|
||||
test_examples: test_sha256_bool test_regex_engine
|
||||
|
||||
.PHONY: test_trivium # Run tests for trivium
|
||||
test_trivium: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
-p tfhe-trivium -- --test-threads=1 trivium::
|
||||
|
||||
.PHONY: test_kreyvium # Run tests for kreyvium
|
||||
test_kreyvium: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
-p tfhe-trivium -- --test-threads=1 kreyvium::
|
||||
|
||||
.PHONY: test_concrete_csprng # Run concrete-csprng tests
|
||||
test_concrete_csprng:
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \
|
||||
--features=$(TARGET_ARCH_FEATURE) -p concrete-csprng
|
||||
|
||||
.PHONY: doc # Build rust doc
|
||||
doc: install_rs_check_toolchain
|
||||
RUSTDOCFLAGS="--html-in-header katex-header.html" \
|
||||
cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" doc \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer --no-deps
|
||||
|
||||
.PHONY: docs # Build rust doc alias for doc
|
||||
docs: doc
|
||||
|
||||
.PHONY: lint_doc # Build rust doc with linting enabled
|
||||
lint_doc: install_rs_check_toolchain
|
||||
RUSTDOCFLAGS="--html-in-header katex-header.html -Dwarnings" \
|
||||
cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" doc \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer --no-deps
|
||||
|
||||
.PHONY: lint_docs # Build rust doc with linting enabled alias for lint_doc
|
||||
lint_docs: lint_doc
|
||||
|
||||
.PHONY: format_doc_latex # Format the documentation latex equations to avoid broken rendering.
|
||||
format_doc_latex:
|
||||
cargo xtask format_latex_doc
|
||||
@"$(MAKE)" --no-print-directory fmt
|
||||
@printf "\n===============================\n\n"
|
||||
@printf "Please manually inspect changes made by format_latex_doc, rustfmt can break equations \
|
||||
if the line length is exceeded\n"
|
||||
@printf "\n===============================\n"
|
||||
|
||||
.PHONY: check_compile_tests # Build tests in debug without running them
|
||||
check_compile_tests:
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --no-run \
|
||||
--features=$(TARGET_ARCH_FEATURE),experimental,boolean,shortint,integer,internal-keycache,safe-deserialization \
|
||||
-p $(TFHE_SPEC)
|
||||
|
||||
@if [[ "$(OS)" == "Linux" || "$(OS)" == "Darwin" ]]; then \
|
||||
"$(MAKE)" build_c_api && \
|
||||
./scripts/c_api_tests.sh --build-only; \
|
||||
fi
|
||||
|
||||
.PHONY: build_nodejs_test_docker # Build a docker image with tools to run nodejs tests for wasm API
|
||||
build_nodejs_test_docker:
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg RUST_TOOLCHAIN="$(RS_BUILD_TOOLCHAIN)" \
|
||||
-f docker/Dockerfile.wasm_tests --build-arg NODE_VERSION=$(NODE_VERSION) -t tfhe-wasm-tests .
|
||||
|
||||
.PHONY: test_nodejs_wasm_api_in_docker # Run tests for the nodejs on wasm API in a docker container
|
||||
test_nodejs_wasm_api_in_docker: build_nodejs_test_docker
|
||||
if [[ -t 1 ]]; then RUN_FLAGS="-it"; else RUN_FLAGS="-i"; fi && \
|
||||
docker run --rm "$${RUN_FLAGS}" \
|
||||
-v "$$(pwd)":/tfhe-wasm-tests/tfhe-rs \
|
||||
-v tfhe-rs-root-target-cache:/root/tfhe-rs-target \
|
||||
-v tfhe-rs-pkg-cache:/tfhe-wasm-tests/tfhe-rs/tfhe/pkg \
|
||||
-v tfhe-rs-root-cargo-registry-cache:/root/.cargo/registry \
|
||||
-v tfhe-rs-root-cache:/root/.cache \
|
||||
tfhe-wasm-tests /bin/bash -i -c 'make test_nodejs_wasm_api'
|
||||
|
||||
.PHONY: test_nodejs_wasm_api # Run tests for the nodejs on wasm API
|
||||
test_nodejs_wasm_api: build_node_js_api
|
||||
cd tfhe && node --test js_on_wasm_tests
|
||||
|
||||
.PHONY: test_web_js_api_parallel # Run tests for the web wasm api
|
||||
test_web_js_api_parallel: build_web_js_api_parallel
|
||||
$(MAKE) -C tfhe/web_wasm_parallel_tests test
|
||||
|
||||
.PHONY: ci_test_web_js_api_parallel # Run tests for the web wasm api
|
||||
ci_test_web_js_api_parallel: build_web_js_api_parallel
|
||||
source ~/.nvm/nvm.sh && \
|
||||
nvm install $(NODE_VERSION) && \
|
||||
nvm use $(NODE_VERSION) && \
|
||||
$(MAKE) -C tfhe/web_wasm_parallel_tests test-ci
|
||||
|
||||
.PHONY: no_tfhe_typo # Check we did not invert the h and f in tfhe
|
||||
no_tfhe_typo:
|
||||
@./scripts/no_tfhe_typo.sh
|
||||
|
||||
.PHONY: no_dbg_log # Check we did not leave dbg macro calls in the rust code
|
||||
no_dbg_log:
|
||||
@./scripts/no_dbg_calls.sh
|
||||
|
||||
.PHONY: dieharder_csprng # Run the dieharder test suite on our CSPRNG implementation
|
||||
dieharder_csprng: install_dieharder build_concrete_csprng
|
||||
./scripts/dieharder_test.sh
|
||||
|
||||
#
|
||||
# Benchmarks
|
||||
#
|
||||
|
||||
.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) \
|
||||
cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench integer-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,$(AVX512_FEATURE) -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
|
||||
RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=MULTI_BIT \
|
||||
__TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) __TFHE_RS_FAST_BENCH=$(FAST_BENCH) \
|
||||
cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench integer-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_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) \
|
||||
cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench integer-signed-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),integer,internal-keycache,$(AVX512_FEATURE) -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
|
||||
RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=MULTI_BIT \
|
||||
__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,$(AVX512_FEATURE) -p $(TFHE_SPEC) --
|
||||
|
||||
.PHONY: bench_shortint # Run benchmarks for shortint
|
||||
bench_shortint: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) \
|
||||
cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench shortint-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_SPEC)
|
||||
|
||||
.PHONY: bench_shortint_multi_bit # Run benchmarks for shortint using multi-bit parameters
|
||||
bench_shortint_multi_bit: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" __TFHE_RS_BENCH_TYPE=MULTI_BIT \
|
||||
__TFHE_RS_BENCH_OP_FLAVOR=$(BENCH_OP_FLAVOR) \
|
||||
cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench shortint-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),shortint,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_SPEC) --
|
||||
|
||||
|
||||
.PHONY: bench_boolean # Run benchmarks for boolean
|
||||
bench_boolean: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench boolean-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_SPEC)
|
||||
|
||||
.PHONY: bench_pbs # Run benchmarks for PBS
|
||||
bench_pbs: install_rs_check_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \
|
||||
--bench pbs-bench \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,internal-keycache,$(AVX512_FEATURE) -p $(TFHE_SPEC)
|
||||
|
||||
.PHONY: bench_web_js_api_parallel # Run benchmarks for the web wasm api
|
||||
bench_web_js_api_parallel: build_web_js_api_parallel
|
||||
$(MAKE) -C tfhe/web_wasm_parallel_tests bench
|
||||
|
||||
.PHONY: ci_bench_web_js_api_parallel # Run benchmarks for the web wasm api
|
||||
ci_bench_web_js_api_parallel: build_web_js_api_parallel
|
||||
source ~/.nvm/nvm.sh && \
|
||||
nvm use node && \
|
||||
$(MAKE) -C tfhe/web_wasm_parallel_tests bench-ci
|
||||
|
||||
#
|
||||
# Utility tools
|
||||
#
|
||||
.PHONY: gen_key_cache # Run the script to generate keys and cache them for shortint tests
|
||||
gen_key_cache: install_rs_build_toolchain
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) run --profile $(CARGO_PROFILE) \
|
||||
--example generates_test_keys \
|
||||
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,internal-keycache -- \
|
||||
$(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 \
|
||||
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
|
||||
|
||||
.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
|
||||
|
||||
.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
|
||||
|
||||
.PHONY: parse_integer_benches # Run python parser to output a csv containing integer benches data
|
||||
parse_integer_benches:
|
||||
python3 ./ci/parse_integer_benches_to_csv.py \
|
||||
--criterion-dir target/criterion \
|
||||
--output-file "$(PARSE_INTEGER_BENCH_CSV_FILE)"
|
||||
|
||||
.PHONY: parse_wasm_benchmarks # Parse benchmarks performed with WASM web client into a CSV file
|
||||
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 \
|
||||
-- web_wasm_parallel_tests/test/benchmark_results
|
||||
|
||||
.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
|
||||
|
||||
#
|
||||
# Real use case examples
|
||||
#
|
||||
|
||||
.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 \
|
||||
-- $(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 \
|
||||
-- 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
|
||||
|
||||
.PHONY: pcc # pcc stands for pre commit checks
|
||||
pcc: no_tfhe_typo no_dbg_log check_fmt lint_doc clippy_all check_compile_tests
|
||||
|
||||
.PHONY: fpcc # pcc stands for pre commit checks, the f stands for fast
|
||||
fpcc: no_tfhe_typo no_dbg_log check_fmt lint_doc clippy_fast check_compile_tests
|
||||
|
||||
.PHONY: conformance # Automatically fix problems that can be fixed
|
||||
conformance: fix_newline fmt
|
||||
|
||||
.PHONY: help # Generate list of targets with descriptions
|
||||
help:
|
||||
@grep '^\.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1\t\2/' | expand -t30 | sort
|
||||
@@ -70,7 +70,9 @@ use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint32, FheUint8};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Basic configuration to use homomorphic integers
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
|
||||
// Key generation
|
||||
let (client_key, server_keys) = generate_keys(config);
|
||||
|
||||
@@ -17,7 +17,7 @@ path = "../../tfhe"
|
||||
features = [ "boolean", "shortint", "integer", "aarch64-unix" ]
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.5.1", features = [ "html_reports" ]}
|
||||
criterion = { version = "0.4", features = [ "html_reports" ]}
|
||||
|
||||
[[bench]]
|
||||
name = "trivium"
|
||||
|
||||
@@ -120,7 +120,7 @@ fn main() {
|
||||
|
||||
# FHE byte Trivium implementation
|
||||
|
||||
The same objects have also been implemented to stream bytes instead of booleans. They can be constructed and used in the same way via the functions `TriviumStreamByte::<u8>::new` and
|
||||
The same objects have also been implemented to stream bytes insead of booleans. They can be constructed and used in the same way via the functions `TriviumStreamByte::<u8>::new` and
|
||||
`TriviumStreamByte::<FheUint8>::new` with the same arguments as before. The `FheUint8` version is significantly slower than the `FheBool` version, because not running
|
||||
with the same cryptographic parameters. Its interest lie in its trans-ciphering capabilities: `TriviumStreamByte<FheUint8>` implements the trait `TransCiphering`,
|
||||
meaning it implements the functions `trans_encrypt_64`. This function takes as input a `FheUint64` and outputs a `FheUint64`, the output being
|
||||
|
||||
@@ -6,7 +6,7 @@ use tfhe_trivium::KreyviumStream;
|
||||
use criterion::Criterion;
|
||||
|
||||
pub fn kreyvium_bool_gen(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled().enable_default_bool().build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB000000000000".to_string();
|
||||
@@ -41,7 +41,7 @@ pub fn kreyvium_bool_gen(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
pub fn kreyvium_bool_warmup(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled().enable_default_bool().build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB000000000000".to_string();
|
||||
|
||||
@@ -6,8 +6,9 @@ use tfhe_trivium::{KreyviumStreamByte, TransCiphering};
|
||||
use criterion::Criterion;
|
||||
|
||||
pub fn kreyvium_byte_gen(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default()
|
||||
.enable_function_evaluation()
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.enable_function_evaluation_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
@@ -35,8 +36,9 @@ pub fn kreyvium_byte_gen(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
pub fn kreyvium_byte_trans(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default()
|
||||
.enable_function_evaluation()
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.enable_function_evaluation_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
@@ -65,8 +67,9 @@ pub fn kreyvium_byte_trans(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
pub fn kreyvium_byte_warmup(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default()
|
||||
.enable_function_evaluation()
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.enable_function_evaluation_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@ use tfhe_trivium::{KreyviumStreamShortint, TransCiphering};
|
||||
use criterion::Criterion;
|
||||
|
||||
pub fn kreyvium_shortint_warmup(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (hl_client_key, hl_server_key) = generate_keys(config);
|
||||
let underlying_ck: tfhe::shortint::ClientKey = (*hl_client_key.as_ref()).clone().into();
|
||||
let underlying_sk: tfhe::shortint::ServerKey = (*hl_server_key.as_ref()).clone().into();
|
||||
@@ -58,7 +60,9 @@ pub fn kreyvium_shortint_warmup(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
pub fn kreyvium_shortint_gen(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (hl_client_key, hl_server_key) = generate_keys(config);
|
||||
let underlying_ck: tfhe::shortint::ClientKey = (*hl_client_key.as_ref()).clone().into();
|
||||
let underlying_sk: tfhe::shortint::ServerKey = (*hl_server_key.as_ref()).clone().into();
|
||||
@@ -103,7 +107,9 @@ pub fn kreyvium_shortint_gen(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
pub fn kreyvium_shortint_trans(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (hl_client_key, hl_server_key) = generate_keys(config);
|
||||
let underlying_ck: tfhe::shortint::ClientKey = (*hl_client_key.as_ref()).clone().into();
|
||||
let underlying_sk: tfhe::shortint::ServerKey = (*hl_server_key.as_ref()).clone().into();
|
||||
|
||||
@@ -6,7 +6,7 @@ use tfhe_trivium::TriviumStream;
|
||||
use criterion::Criterion;
|
||||
|
||||
pub fn trivium_bool_gen(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled().enable_default_bool().build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB".to_string();
|
||||
@@ -41,7 +41,7 @@ pub fn trivium_bool_gen(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
pub fn trivium_bool_warmup(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled().enable_default_bool().build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB".to_string();
|
||||
|
||||
@@ -6,7 +6,9 @@ use tfhe_trivium::{TransCiphering, TriviumStreamByte};
|
||||
use criterion::Criterion;
|
||||
|
||||
pub fn trivium_byte_gen(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB".to_string();
|
||||
@@ -33,7 +35,9 @@ pub fn trivium_byte_gen(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
pub fn trivium_byte_trans(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB".to_string();
|
||||
@@ -61,7 +65,9 @@ pub fn trivium_byte_trans(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
pub fn trivium_byte_warmup(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB".to_string();
|
||||
|
||||
@@ -8,7 +8,9 @@ use tfhe_trivium::{TransCiphering, TriviumStreamShortint};
|
||||
use criterion::Criterion;
|
||||
|
||||
pub fn trivium_shortint_warmup(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (hl_client_key, hl_server_key) = generate_keys(config);
|
||||
let underlying_ck: tfhe::shortint::ClientKey = (*hl_client_key.as_ref()).clone().into();
|
||||
let underlying_sk: tfhe::shortint::ServerKey = (*hl_server_key.as_ref()).clone().into();
|
||||
@@ -58,7 +60,9 @@ pub fn trivium_shortint_warmup(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
pub fn trivium_shortint_gen(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (hl_client_key, hl_server_key) = generate_keys(config);
|
||||
let underlying_ck: tfhe::shortint::ClientKey = (*hl_client_key.as_ref()).clone().into();
|
||||
let underlying_sk: tfhe::shortint::ServerKey = (*hl_server_key.as_ref()).clone().into();
|
||||
@@ -103,7 +107,9 @@ pub fn trivium_shortint_gen(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
pub fn trivium_shortint_trans(c: &mut Criterion) {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (hl_client_key, hl_server_key) = generate_keys(config);
|
||||
let underlying_ck: tfhe::shortint::ClientKey = (*hl_client_key.as_ref()).clone().into();
|
||||
let underlying_sk: tfhe::shortint::ServerKey = (*hl_server_key.as_ref()).clone().into();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! This module implements the Kreyvium stream cipher, using booleans or FheBool
|
||||
//! for the representation of the inner bits.
|
||||
//! for the representaion of the inner bits.
|
||||
|
||||
use crate::static_deque::StaticDeque;
|
||||
|
||||
@@ -35,7 +35,7 @@ pub struct KreyviumStream<T> {
|
||||
}
|
||||
|
||||
impl KreyviumStream<bool> {
|
||||
/// Constructor for `KreyviumStream<bool>`: arguments are the secret key and the input vector.
|
||||
/// Contructor for `KreyviumStream<bool>`: arguments are the secret key and the input vector.
|
||||
/// Outputs a KreyviumStream object already initialized (1152 steps have been run before
|
||||
/// returning)
|
||||
pub fn new(mut key: [bool; 128], mut iv: [bool; 128]) -> KreyviumStream<bool> {
|
||||
@@ -118,7 +118,7 @@ where
|
||||
T: KreyviumBoolInput<T> + std::marker::Send + std::marker::Sync,
|
||||
for<'a> &'a T: KreyviumBoolInput<T>,
|
||||
{
|
||||
/// Internal generic constructor: arguments are already prepared registers, and an optional FHE
|
||||
/// Internal generic contructor: arguments are already prepared registers, and an optional FHE
|
||||
/// server key
|
||||
fn new_from_registers(
|
||||
a_register: [T; 93],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! This module implements the Kreyvium stream cipher, using u8 or FheUint8
|
||||
//! for the representation of the inner bits.
|
||||
//! for the representaion of the inner bits.
|
||||
|
||||
use crate::static_deque::{StaticByteDeque, StaticByteDequeInput};
|
||||
|
||||
@@ -31,7 +31,7 @@ impl KreyviumByteInput<FheUint8> for &FheUint8 {}
|
||||
/// representation of bits (u8 or FheUint8). To be able to compute FHE operations, it also owns
|
||||
/// an Option for a ServerKey.
|
||||
/// Since the original Kreyvium registers' sizes are not a multiple of 8, these registers (which
|
||||
/// store byte-like objects) have a size that is the eighth of the closest multiple of 8 above the
|
||||
/// store byte-like objects) have a size that is the eigth of the closest multiple of 8 above the
|
||||
/// originals' sizes.
|
||||
pub struct KreyviumStreamByte<T> {
|
||||
a_byte: StaticByteDeque<12, T>,
|
||||
@@ -43,7 +43,7 @@ pub struct KreyviumStreamByte<T> {
|
||||
}
|
||||
|
||||
impl KreyviumStreamByte<u8> {
|
||||
/// Constructor for `KreyviumStreamByte<u8>`: arguments are the secret key and the input vector.
|
||||
/// Contructor for `KreyviumStreamByte<u8>`: arguments are the secret key and the input vector.
|
||||
/// Outputs a KreyviumStream object already initialized (1152 steps have been run before
|
||||
/// returning)
|
||||
pub fn new(key_bytes: [u8; 16], iv_bytes: [u8; 16]) -> KreyviumStreamByte<u8> {
|
||||
@@ -146,7 +146,7 @@ where
|
||||
T: KreyviumByteInput<T> + Send,
|
||||
for<'a> &'a T: KreyviumByteInput<T>,
|
||||
{
|
||||
/// Internal generic constructor: arguments are already prepared registers, and an optional FHE
|
||||
/// Internal generic contructor: arguments are already prepared registers, and an optional FHE
|
||||
/// server key
|
||||
fn new_from_registers(
|
||||
a_register: [T; 12],
|
||||
|
||||
@@ -19,7 +19,7 @@ pub struct KreyviumStreamShortint {
|
||||
}
|
||||
|
||||
impl KreyviumStreamShortint {
|
||||
/// Constructor for KreyviumStreamShortint: arguments are the secret key and the input vector,
|
||||
/// Contructor for KreyviumStreamShortint: arguments are the secret key and the input vector,
|
||||
/// and a ServerKey reference. Outputs a KreyviumStream object already initialized (1152
|
||||
/// steps have been run before returning)
|
||||
pub fn new(
|
||||
|
||||
@@ -170,7 +170,7 @@ fn kreyvium_test_4() {
|
||||
|
||||
#[test]
|
||||
fn kreyvium_test_fhe_long() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled().enable_default_bool().build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB000000000000".to_string();
|
||||
@@ -217,7 +217,9 @@ use tfhe::shortint::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn kreyvium_test_shortint_long() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (hl_client_key, hl_server_key) = generate_keys(config);
|
||||
let underlying_ck: tfhe::shortint::ClientKey = (*hl_client_key.as_ref()).clone().into();
|
||||
let underlying_sk: tfhe::shortint::ServerKey = (*hl_server_key.as_ref()).clone().into();
|
||||
@@ -300,8 +302,9 @@ fn kreyvium_test_clear_byte() {
|
||||
|
||||
#[test]
|
||||
fn kreyvium_test_byte_long() {
|
||||
let config = ConfigBuilder::default()
|
||||
.enable_function_evaluation()
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.enable_function_evaluation_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
@@ -339,8 +342,9 @@ fn kreyvium_test_byte_long() {
|
||||
|
||||
#[test]
|
||||
fn kreyvium_test_fhe_byte_transciphering_long() {
|
||||
let config = ConfigBuilder::default()
|
||||
.enable_function_evaluation()
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.enable_function_evaluation_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! This module implements the StaticByteDeque struct: a deque of bytes. The idea
|
||||
//! is that this is a wrapper around StaticDeque, but StaticByteDeque has an additional
|
||||
//! functionality: it can construct the "intermediate" bytes, made of parts of other bytes.
|
||||
//! functionnality: it can construct the "intermediate" bytes, made of parts of other bytes.
|
||||
//! This is pretending to store bits, and allows accessing bits in chunks of 8 consecutive.
|
||||
|
||||
use crate::static_deque::StaticDeque;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use core::ops::{Index, IndexMut};
|
||||
|
||||
/// StaticDeque: a struct implementing a deque whose size is known at compile time.
|
||||
/// It has 2 members: the static array containing the data (never empty), and a cursor
|
||||
/// It has 2 members: the static array conatining the data (never empty), and a cursor
|
||||
/// equal to the index of the oldest element (and the next one to be overwritten).
|
||||
#[derive(Clone)]
|
||||
pub struct StaticDeque<const N: usize, T> {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
use crate::{KreyviumStreamByte, KreyviumStreamShortint, TriviumStreamByte, TriviumStreamShortint};
|
||||
use tfhe::shortint::Ciphertext;
|
||||
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{set_server_key, unset_server_key, FheUint64, FheUint8, ServerKey};
|
||||
|
||||
use rayon::prelude::*;
|
||||
|
||||
@@ -232,7 +232,7 @@ fn trivium_test_clear_byte() {
|
||||
|
||||
#[test]
|
||||
fn trivium_test_fhe_long() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled().enable_default_bool().build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB".to_string();
|
||||
@@ -277,7 +277,9 @@ fn trivium_test_fhe_long() {
|
||||
|
||||
#[test]
|
||||
fn trivium_test_fhe_byte_long() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB".to_string();
|
||||
@@ -314,7 +316,9 @@ fn trivium_test_fhe_byte_long() {
|
||||
|
||||
#[test]
|
||||
fn trivium_test_fhe_byte_transciphering_long() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
let key_string = "0053A6F94C9FF24598EB".to_string();
|
||||
@@ -353,7 +357,9 @@ use tfhe::shortint::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn trivium_test_shortint_long() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (hl_client_key, hl_server_key) = generate_keys(config);
|
||||
let underlying_ck: tfhe::shortint::ClientKey = (*hl_client_key.as_ref()).clone().into();
|
||||
let underlying_sk: tfhe::shortint::ServerKey = (*hl_server_key.as_ref()).clone().into();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! This module implements the Trivium stream cipher, using booleans or FheBool
|
||||
//! for the representation of the inner bits.
|
||||
//! for the representaion of the inner bits.
|
||||
|
||||
use crate::static_deque::StaticDeque;
|
||||
|
||||
@@ -33,7 +33,7 @@ pub struct TriviumStream<T> {
|
||||
}
|
||||
|
||||
impl TriviumStream<bool> {
|
||||
/// Constructor for `TriviumStream<bool>`: arguments are the secret key and the input vector.
|
||||
/// Contructor for `TriviumStream<bool>`: arguments are the secret key and the input vector.
|
||||
/// Outputs a TriviumStream object already initialized (1152 steps have been run before
|
||||
/// returning)
|
||||
pub fn new(key: [bool; 80], iv: [bool; 80]) -> TriviumStream<bool> {
|
||||
@@ -94,7 +94,7 @@ where
|
||||
T: TriviumBoolInput<T> + std::marker::Send + std::marker::Sync,
|
||||
for<'a> &'a T: TriviumBoolInput<T>,
|
||||
{
|
||||
/// Internal generic constructor: arguments are already prepared registers, and an optional FHE
|
||||
/// Internal generic contructor: arguments are already prepared registers, and an optional FHE
|
||||
/// server key
|
||||
fn new_from_registers(
|
||||
a_register: [T; 93],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! This module implements the Trivium stream cipher, using u8 or FheUint8
|
||||
//! for the representation of the inner bits.
|
||||
//! for the representaion of the inner bits.
|
||||
|
||||
use crate::static_deque::{StaticByteDeque, StaticByteDequeInput};
|
||||
|
||||
@@ -31,7 +31,7 @@ impl TriviumByteInput<FheUint8> for &FheUint8 {}
|
||||
/// representation of bits (u8 or FheUint8). To be able to compute FHE operations, it also owns
|
||||
/// an Option for a ServerKey.
|
||||
/// Since the original Trivium registers' sizes are not a multiple of 8, these registers (which
|
||||
/// store byte-like objects) have a size that is the eighth of the closest multiple of 8 above the
|
||||
/// store byte-like objects) have a size that is the eigth of the closest multiple of 8 above the
|
||||
/// originals' sizes.
|
||||
pub struct TriviumStreamByte<T> {
|
||||
a_byte: StaticByteDeque<12, T>,
|
||||
@@ -41,7 +41,7 @@ pub struct TriviumStreamByte<T> {
|
||||
}
|
||||
|
||||
impl TriviumStreamByte<u8> {
|
||||
/// Constructor for `TriviumStreamByte<u8>`: arguments are the secret key and the input vector.
|
||||
/// Contructor for `TriviumStreamByte<u8>`: arguments are the secret key and the input vector.
|
||||
/// Outputs a TriviumStream object already initialized (1152 steps have been run before
|
||||
/// returning)
|
||||
pub fn new(key: [u8; 10], iv: [u8; 10]) -> TriviumStreamByte<u8> {
|
||||
@@ -111,7 +111,7 @@ where
|
||||
T: TriviumByteInput<T> + Send,
|
||||
for<'a> &'a T: TriviumByteInput<T>,
|
||||
{
|
||||
/// Internal generic constructor: arguments are already prepared registers, and an optional FHE
|
||||
/// Internal generic contructor: arguments are already prepared registers, and an optional FHE
|
||||
/// server key
|
||||
fn new_from_registers(
|
||||
a_register: [T; 12],
|
||||
|
||||
@@ -17,9 +17,9 @@ pub struct TriviumStreamShortint {
|
||||
}
|
||||
|
||||
impl TriviumStreamShortint {
|
||||
/// Constructor for TriviumStreamShortint: arguments are the secret key and the input vector,
|
||||
/// and a ServerKey reference. Outputs a TriviumStream object already initialized (1152
|
||||
/// steps have been run before returning)
|
||||
/// Contructor for TriviumStreamShortint: arguments are the secret key and the input vector, and
|
||||
/// a ServerKey reference. Outputs a TriviumStream object already initialized (1152 steps
|
||||
/// have been run before returning)
|
||||
pub fn new(
|
||||
key: [Ciphertext; 80],
|
||||
iv: [u64; 80],
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
{
|
||||
"m6i.metal": 7.168,
|
||||
"hpc7a.96xlarge": 7.7252
|
||||
"m6i.metal": 7.168
|
||||
}
|
||||
|
||||
@@ -36,24 +36,23 @@ def check_security(filename):
|
||||
try:
|
||||
# The lattice estimator is not able to manage such large dimension.
|
||||
# If we have the security for smaller `n` then we have security for larger ones.
|
||||
if param.n > 16384:
|
||||
if param.n == 32768:
|
||||
param = param.updated(n = 16384)
|
||||
|
||||
usvp_level = LWE.primal_usvp(param, red_cost_model = model)
|
||||
dual_level = LWE.dual_hybrid(param, red_cost_model = model)
|
||||
|
||||
estimator_level = log(min(usvp_level["rop"], dual_level["rop"]),2 )
|
||||
security_level = f"security level = {estimator_level} bits"
|
||||
if estimator_level < 127:
|
||||
print("FAIL\t({security_level})")
|
||||
reason = f"attained {security_level} target is 128 bits"
|
||||
print("FAIL")
|
||||
reason = f"attained security level = {estimator_level} bits target is 128 bits"
|
||||
to_update.append((param, reason))
|
||||
continue
|
||||
except Exception as err:
|
||||
print("FAIL")
|
||||
to_update.append((param, f"{repr(err)}"))
|
||||
else:
|
||||
print(f"OK\t({security_level})")
|
||||
print("OK")
|
||||
|
||||
return to_update
|
||||
|
||||
@@ -73,4 +72,4 @@ if __name__ == "__main__":
|
||||
print(f"[{param.tag}] reason: {reason} (param)")
|
||||
sys.exit(int(1)) # Explicit conversion is needed to make this call work
|
||||
else:
|
||||
print("All parameters passed the security check")
|
||||
print("All parameters passed the security check")
|
||||
@@ -20,10 +20,7 @@ def main(args):
|
||||
bench_function_id = bench_data["function_id"]
|
||||
|
||||
split = bench_function_id.split("::")
|
||||
if split.len() == 5: # Signed integers
|
||||
(_, _, function_name, parameter_set, bits) = split
|
||||
else: # Unsigned integers
|
||||
(_, function_name, parameter_set, bits) = split
|
||||
(_, function_name, parameter_set, bits) = split
|
||||
|
||||
if "_scalar_" in bits:
|
||||
(bits, scalar) = bits.split("_bits_scalar_")
|
||||
|
||||
45
ci/slab.toml
45
ci/slab.toml
@@ -1,37 +1,32 @@
|
||||
[profile.cpu-big]
|
||||
region = "eu-west-3"
|
||||
image_id = "ami-051942e4055555752"
|
||||
instance_type = "m6i.32xlarge"
|
||||
|
||||
[profile.cpu-big_fallback]
|
||||
region = "us-east-1"
|
||||
image_id = "ami-04e3bb9aebb6786df"
|
||||
image_id = "ami-0ab73f5bd11708a85"
|
||||
instance_type = "m6i.32xlarge"
|
||||
|
||||
[profile.cpu-small]
|
||||
region = "eu-west-3"
|
||||
image_id = "ami-051942e4055555752"
|
||||
image_id = "ami-0ab73f5bd11708a85"
|
||||
instance_type = "m6i.4xlarge"
|
||||
|
||||
[profile.bench]
|
||||
region = "eu-west-1"
|
||||
image_id = "ami-0e88d98b86aff13de"
|
||||
instance_type = "hpc7a.96xlarge"
|
||||
region = "eu-west-3"
|
||||
image_id = "ami-0ab73f5bd11708a85"
|
||||
instance_type = "m6i.metal"
|
||||
|
||||
[command.cpu_test]
|
||||
workflow = "aws_tfhe_tests.yml"
|
||||
profile = "cpu-big"
|
||||
check_run_name = "CPU AWS Tests"
|
||||
|
||||
[command.cpu_unsigned_integer_test]
|
||||
[command.cpu_integer_test]
|
||||
workflow = "aws_tfhe_integer_tests.yml"
|
||||
profile = "cpu-big"
|
||||
check_run_name = "CPU Unsigned Integer AWS Tests"
|
||||
check_run_name = "CPU Integer AWS Tests"
|
||||
|
||||
[command.cpu_signed_integer_test]
|
||||
workflow = "aws_tfhe_signed_integer_tests.yml"
|
||||
[command.cpu_multi_bit_test]
|
||||
workflow = "aws_tfhe_multi_bit_tests.yml"
|
||||
profile = "cpu-big"
|
||||
check_run_name = "CPU Signed Integer AWS Tests"
|
||||
check_run_name = "CPU AWS Multi Bit Tests"
|
||||
|
||||
[command.cpu_wasm_test]
|
||||
workflow = "aws_tfhe_wasm_tests.yml"
|
||||
@@ -48,11 +43,6 @@ workflow = "integer_full_benchmark.yml"
|
||||
profile = "bench"
|
||||
check_run_name = "Integer CPU AWS Benchmarks Full Suite"
|
||||
|
||||
[command.signed_integer_full_bench]
|
||||
workflow = "signed_integer_full_benchmark.yml"
|
||||
profile = "bench"
|
||||
check_run_name = "Signed Integer CPU AWS Benchmarks Full Suite"
|
||||
|
||||
[command.integer_bench]
|
||||
workflow = "integer_benchmark.yml"
|
||||
profile = "bench"
|
||||
@@ -63,16 +53,6 @@ workflow = "integer_multi_bit_benchmark.yml"
|
||||
profile = "bench"
|
||||
check_run_name = "Integer multi bit CPU AWS Benchmarks"
|
||||
|
||||
[command.signed_integer_bench]
|
||||
workflow = "signed_integer_benchmark.yml"
|
||||
profile = "bench"
|
||||
check_run_name = "Signed integer CPU AWS Benchmarks"
|
||||
|
||||
[command.signed_integer_multi_bit_bench]
|
||||
workflow = "signed_integer_multi_bit_benchmark.yml"
|
||||
profile = "bench"
|
||||
check_run_name = "Signed integer multi bit CPU AWS Benchmarks"
|
||||
|
||||
[command.shortint_full_bench]
|
||||
workflow = "shortint_full_benchmark.yml"
|
||||
profile = "bench"
|
||||
@@ -102,8 +82,3 @@ check_run_name = "WASM Client AWS Benchmarks"
|
||||
workflow = "csprng_randomness_testing.yml"
|
||||
profile = "cpu-small"
|
||||
check_run_name = "CSPRNG randomness testing"
|
||||
|
||||
[command.code_coverage]
|
||||
workflow = "code_coverage.yml"
|
||||
profile = "cpu-small"
|
||||
check_run_name = "Code coverage"
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
coverage:
|
||||
status:
|
||||
# Disable patch checks in GitHub until all tfhe-rs layers have coverage implemented.
|
||||
patch: false
|
||||
@@ -9,7 +9,6 @@ documentation = "https://docs.zama.ai/tfhe-rs"
|
||||
repository = "https://github.com/zama-ai/tfhe-rs"
|
||||
readme = "README.md"
|
||||
keywords = ["fully", "homomorphic", "encryption", "fhe", "cryptography"]
|
||||
rust-version = "1.72"
|
||||
|
||||
[dependencies]
|
||||
aes = "0.8.2"
|
||||
@@ -20,8 +19,8 @@ libc = "0.2.133"
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.8.3"
|
||||
criterion = "0.5.1"
|
||||
clap = "=4.4.4"
|
||||
criterion = "0.3"
|
||||
clap = "=4.2.7"
|
||||
|
||||
[features]
|
||||
parallel = ["rayon"]
|
||||
|
||||
@@ -35,23 +35,17 @@ impl AesBlockCipher for ArmAesBlockCipher {
|
||||
}
|
||||
|
||||
fn generate_batch(&mut self, AesIndex(aes_ctr): AesIndex) -> [u8; BYTES_PER_BATCH] {
|
||||
#[target_feature(enable = "aes,neon")]
|
||||
unsafe fn implementation(
|
||||
this: &ArmAesBlockCipher,
|
||||
AesIndex(aes_ctr): AesIndex,
|
||||
) -> [u8; BYTES_PER_BATCH] {
|
||||
let mut output = [0u8; BYTES_PER_BATCH];
|
||||
// We want 128 bytes of output, the ctr gives 128 bit message (16 bytes)
|
||||
for (i, out) in output.chunks_exact_mut(16).enumerate() {
|
||||
let mut output = [0u8; BYTES_PER_BATCH];
|
||||
// We want 128 bytes of output, the ctr gives 128 bit message (16 bytes)
|
||||
for (i, out) in output.chunks_exact_mut(16).enumerate() {
|
||||
let encrypted = unsafe {
|
||||
// Safe because we prevent the user from creating the Generator
|
||||
// on non-supported hardware
|
||||
let encrypted = encrypt(aes_ctr + (i as u128), &this.round_keys);
|
||||
out.copy_from_slice(&encrypted.to_ne_bytes());
|
||||
}
|
||||
output
|
||||
encrypt(aes_ctr + (i as u128), &self.round_keys)
|
||||
};
|
||||
out.copy_from_slice(&encrypted.to_ne_bytes());
|
||||
}
|
||||
// SAFETY: we checked for aes and neon availability in `Self::new`
|
||||
unsafe { implementation(self, AesIndex(aes_ctr)) }
|
||||
output
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +55,6 @@ impl AesBlockCipher for ArmAesBlockCipher {
|
||||
///
|
||||
/// You must make sure the CPU's arch is`aarch64` and has
|
||||
/// `neon` and `aes` features.
|
||||
#[inline(always)]
|
||||
unsafe fn sub_word(word: u32) -> u32 {
|
||||
let data = vreinterpretq_u8_u32(vdupq_n_u32(word));
|
||||
let zero_key = vdupq_n_u8(0u8);
|
||||
@@ -75,17 +68,14 @@ unsafe fn sub_word(word: u32) -> u32 {
|
||||
vgetq_lane_u32::<0>(vreinterpretq_u32_u8(temp))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn uint8x16_t_to_u128(input: uint8x16_t) -> u128 {
|
||||
unsafe { transmute(input) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn u128_to_uint8x16_t(input: u128) -> uint8x16_t {
|
||||
unsafe { transmute(input) }
|
||||
}
|
||||
|
||||
#[target_feature(enable = "aes,neon")]
|
||||
unsafe fn generate_round_keys(key: AesKey) -> [uint8x16_t; NUM_ROUND_KEYS] {
|
||||
let mut round_keys: [uint8x16_t; NUM_ROUND_KEYS] = std::mem::zeroed();
|
||||
round_keys[0] = u128_to_uint8x16_t(key.0);
|
||||
@@ -119,7 +109,6 @@ unsafe fn generate_round_keys(key: AesKey) -> [uint8x16_t; NUM_ROUND_KEYS] {
|
||||
///
|
||||
/// You must make sure the CPU's arch is`aarch64` and has
|
||||
/// `neon` and `aes` features.
|
||||
#[inline(always)]
|
||||
unsafe fn encrypt(message: u128, keys: &[uint8x16_t; NUM_ROUND_KEYS]) -> u128 {
|
||||
// Notes:
|
||||
// According the [ARM Manual](https://developer.arm.com/documentation/ddi0487/gb/):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::generators::aes_ctr::{AesBlockCipher, AesIndex, AesKey, BYTES_PER_BATCH};
|
||||
use std::arch::x86_64::{
|
||||
__m128i, _mm_aesenc_si128, _mm_aesenclast_si128, _mm_aeskeygenassist_si128, _mm_shuffle_epi32,
|
||||
_mm_slli_si128, _mm_store_si128, _mm_xor_si128,
|
||||
__m128i, _mm_aesenc_si128, _mm_aesenclast_si128, _mm_aeskeygenassist_si128, _mm_load_si128,
|
||||
_mm_shuffle_epi32, _mm_slli_si128, _mm_store_si128, _mm_xor_si128,
|
||||
};
|
||||
use std::mem::transmute;
|
||||
|
||||
@@ -25,36 +25,26 @@ impl AesBlockCipher for AesniBlockCipher {
|
||||
)
|
||||
}
|
||||
|
||||
// SAFETY: we checked for aes and sse2 availability
|
||||
let round_keys = unsafe { generate_round_keys(key) };
|
||||
let round_keys = generate_round_keys(key);
|
||||
AesniBlockCipher { round_keys }
|
||||
}
|
||||
|
||||
fn generate_batch(&mut self, AesIndex(aes_ctr): AesIndex) -> [u8; BYTES_PER_BATCH] {
|
||||
#[target_feature(enable = "sse2,aes")]
|
||||
unsafe fn implementation(
|
||||
this: &AesniBlockCipher,
|
||||
AesIndex(aes_ctr): AesIndex,
|
||||
) -> [u8; BYTES_PER_BATCH] {
|
||||
si128arr_to_u8arr(aes_encrypt_many(
|
||||
u128_to_si128(aes_ctr),
|
||||
u128_to_si128(aes_ctr + 1),
|
||||
u128_to_si128(aes_ctr + 2),
|
||||
u128_to_si128(aes_ctr + 3),
|
||||
u128_to_si128(aes_ctr + 4),
|
||||
u128_to_si128(aes_ctr + 5),
|
||||
u128_to_si128(aes_ctr + 6),
|
||||
u128_to_si128(aes_ctr + 7),
|
||||
&this.round_keys,
|
||||
))
|
||||
}
|
||||
// SAFETY: we checked for aes and sse2 availability in `Self::new`
|
||||
unsafe { implementation(self, AesIndex(aes_ctr)) }
|
||||
si128arr_to_u8arr(aes_encrypt_many(
|
||||
&u128_to_si128(aes_ctr),
|
||||
&u128_to_si128(aes_ctr + 1),
|
||||
&u128_to_si128(aes_ctr + 2),
|
||||
&u128_to_si128(aes_ctr + 3),
|
||||
&u128_to_si128(aes_ctr + 4),
|
||||
&u128_to_si128(aes_ctr + 5),
|
||||
&u128_to_si128(aes_ctr + 6),
|
||||
&u128_to_si128(aes_ctr + 7),
|
||||
&self.round_keys,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[target_feature(enable = "sse2,aes")]
|
||||
unsafe fn generate_round_keys(key: AesKey) -> [__m128i; 11] {
|
||||
fn generate_round_keys(key: AesKey) -> [__m128i; 11] {
|
||||
let key = u128_to_si128(key.0);
|
||||
let mut keys: [__m128i; 11] = [u128_to_si128(0); 11];
|
||||
aes_128_key_expansion(key, &mut keys);
|
||||
@@ -64,19 +54,27 @@ unsafe fn generate_round_keys(key: AesKey) -> [__m128i; 11] {
|
||||
// Uses aes to encrypt many values at once. This allows a substantial speedup (around 30%)
|
||||
// compared to the naive approach.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[inline(always)]
|
||||
fn aes_encrypt_many(
|
||||
message_1: __m128i,
|
||||
message_2: __m128i,
|
||||
message_3: __m128i,
|
||||
message_4: __m128i,
|
||||
message_5: __m128i,
|
||||
message_6: __m128i,
|
||||
message_7: __m128i,
|
||||
message_8: __m128i,
|
||||
message_1: &__m128i,
|
||||
message_2: &__m128i,
|
||||
message_3: &__m128i,
|
||||
message_4: &__m128i,
|
||||
message_5: &__m128i,
|
||||
message_6: &__m128i,
|
||||
message_7: &__m128i,
|
||||
message_8: &__m128i,
|
||||
keys: &[__m128i; 11],
|
||||
) -> [__m128i; 8] {
|
||||
unsafe {
|
||||
let message_1 = _mm_load_si128(message_1 as *const __m128i);
|
||||
let message_2 = _mm_load_si128(message_2 as *const __m128i);
|
||||
let message_3 = _mm_load_si128(message_3 as *const __m128i);
|
||||
let message_4 = _mm_load_si128(message_4 as *const __m128i);
|
||||
let message_5 = _mm_load_si128(message_5 as *const __m128i);
|
||||
let message_6 = _mm_load_si128(message_6 as *const __m128i);
|
||||
let message_7 = _mm_load_si128(message_7 as *const __m128i);
|
||||
let message_8 = _mm_load_si128(message_8 as *const __m128i);
|
||||
|
||||
let mut tmp_1 = _mm_xor_si128(message_1, keys[0]);
|
||||
let mut tmp_2 = _mm_xor_si128(message_2, keys[0]);
|
||||
let mut tmp_3 = _mm_xor_si128(message_3, keys[0]);
|
||||
@@ -127,7 +125,6 @@ fn aes_128_assist(temp1: __m128i, temp2: __m128i) -> __m128i {
|
||||
temp1
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn aes_128_key_expansion(key: __m128i, keys: &mut [__m128i; 11]) {
|
||||
let (mut temp1, mut temp2): (__m128i, __m128i);
|
||||
temp1 = key;
|
||||
@@ -166,7 +163,6 @@ fn aes_128_key_expansion(key: __m128i, keys: &mut [__m128i; 11]) {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn u128_to_si128(input: u128) -> __m128i {
|
||||
unsafe { transmute(input) }
|
||||
}
|
||||
@@ -176,7 +172,6 @@ fn si128_to_u128(input: __m128i) -> u128 {
|
||||
unsafe { transmute(input) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn si128arr_to_u8arr(input: [__m128i; 8]) -> [u8; BYTES_PER_BATCH] {
|
||||
unsafe { transmute(input) }
|
||||
}
|
||||
@@ -222,7 +217,7 @@ mod test {
|
||||
let mut keys: [__m128i; 11] = [u128_to_si128(0); 11];
|
||||
aes_128_key_expansion(key, &mut keys);
|
||||
let ciphertexts = aes_encrypt_many(
|
||||
message, message, message, message, message, message, message, message, &keys,
|
||||
&message, &message, &message, &message, &message, &message, &message, &message, &keys,
|
||||
);
|
||||
for ct in &ciphertexts {
|
||||
assert_eq!(CIPHERTEXT, si128_to_u128(*ct));
|
||||
|
||||
@@ -17,7 +17,7 @@ pub struct BytesPerChild(pub usize);
|
||||
#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq)]
|
||||
pub struct ByteCount(pub u128);
|
||||
|
||||
/// An error occurring during a generator fork.
|
||||
/// An error occuring during a generator fork.
|
||||
#[derive(Debug)]
|
||||
pub enum ForkError {
|
||||
ForkTooLarge,
|
||||
@@ -145,7 +145,7 @@ pub mod generator_generic_test {
|
||||
|
||||
/// Checks that the PRNG roughly generates uniform numbers.
|
||||
///
|
||||
/// To do that, we perform an histogram of the occurrences of each byte value, over a fixed
|
||||
/// To do that, we perform an histogram of the occurences of each byte value, over a fixed
|
||||
/// number of samples and check that the empirical probabilities of the bins are close to
|
||||
/// the theoretical probabilities.
|
||||
pub fn test_roughly_uniform<G: RandomGenerator>() {
|
||||
|
||||
@@ -8,7 +8,7 @@ pub struct RdseedSeeder;
|
||||
|
||||
impl Seeder for RdseedSeeder {
|
||||
fn seed(&mut self) -> Seed {
|
||||
Seed(unsafe { rdseed_random_m128() })
|
||||
Seed(rdseed_random_m128())
|
||||
}
|
||||
|
||||
fn is_available() -> bool {
|
||||
@@ -17,8 +17,7 @@ impl Seeder for RdseedSeeder {
|
||||
}
|
||||
|
||||
// Generates a random 128 bits value from rdseed
|
||||
#[target_feature(enable = "rdseed")]
|
||||
unsafe fn rdseed_random_m128() -> u128 {
|
||||
fn rdseed_random_m128() -> u128 {
|
||||
let mut rand1: u64 = 0;
|
||||
let mut rand2: u64 = 0;
|
||||
let mut output_bytes = [0u8; 16];
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! When initializing a generator, one needs to provide a [`Seed`], which is then used as key to the
|
||||
//! AES blockcipher. As a consequence, the quality of the outputs of the generator is directly
|
||||
//! conditioned by the quality of this seed. This module proposes different mechanisms to deliver
|
||||
//! seeds that can accommodate varying scenarios.
|
||||
//! seeds that can accomodate varying scenarios.
|
||||
|
||||
/// A seed value, used to initialize a generator.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
@@ -15,16 +15,13 @@ pub trait Seeder {
|
||||
fn seed(&mut self) -> Seed;
|
||||
|
||||
/// Check whether the seeder can be used on the current machine. This function may check if some
|
||||
/// required CPU features are available or if some OS features are available for example.
|
||||
/// required CPU features are available or if some OS features are availble for example.
|
||||
fn is_available() -> bool
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
mod implem;
|
||||
// This import statement can be empty if seeder features are disabled, rustc's behavior changed to
|
||||
// warn of empty modules, we know this can happen, so allow it.
|
||||
#[allow(unused_imports)]
|
||||
pub use implem::*;
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -11,7 +11,6 @@ RUN sed -i 's|^deb http://archive.ubuntu.com/ubuntu/|deb http://mirror.ubuntu.ik
|
||||
ENV CARGO_TARGET_DIR=/root/tfhe-rs-target
|
||||
|
||||
ARG RUST_TOOLCHAIN="stable"
|
||||
ARG NODE_VERSION
|
||||
|
||||
WORKDIR /tfhe-wasm-tests
|
||||
|
||||
@@ -35,6 +34,6 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > install-rustup.s
|
||||
chmod +x install-node.sh && \
|
||||
./install-node.sh && \
|
||||
. "$HOME/.nvm/nvm.sh" && \
|
||||
bash -i -c 'nvm install ${NODE_VERSION} && nvm use ${NODE_VERSION}'
|
||||
bash -i -c 'nvm install node && nvm use node'
|
||||
|
||||
WORKDIR /tfhe-wasm-tests/tfhe-rs/
|
||||
|
||||
578
justfile
Normal file
578
justfile
Normal file
@@ -0,0 +1,578 @@
|
||||
|
||||
SHELL := `/usr/bin/env which bash`
|
||||
|
||||
set shell := ["bash", "-c"]
|
||||
|
||||
default:
|
||||
@just --list
|
||||
|
||||
OS := `uname`
|
||||
RS_CHECK_TOOLCHAIN := `cat toolchain.txt | tr -d '\n'`
|
||||
CARGO_RS_CHECK_TOOLCHAIN := "+" + RS_CHECK_TOOLCHAIN
|
||||
TARGET_ARCH_FEATURE:=`./scripts/get_arch_feature.sh`
|
||||
RS_BUILD_TOOLCHAIN := "stable"
|
||||
CARGO_PROFILE := "release"
|
||||
MIN_RUST_VERSION := `grep rust-version tfhe/Cargo.toml | cut -d '=' -f 2 | xargs`
|
||||
AVX512_SUPPORT := "OFF"
|
||||
WASM_RUSTFLAGS := ""
|
||||
BIG_TESTS_INSTANCE := "FALSE"
|
||||
GEN_KEY_CACHE_MULTI_BIT_ONLY := "FALSE"
|
||||
PARSE_INTEGER_BENCH_CSV_FILE := "tfhe_rs_integer_benches.csv"
|
||||
export FAST_TESTS := "FALSE"
|
||||
export __TFHE_RS_FAST_BENCH := "FALSE"
|
||||
export __TFHE_RS_BENCH_OP_FLAVOR := "DEFAULT"
|
||||
# This is done to avoid forgetting it, we still precise the RUSTFLAGS in the commands to be able to
|
||||
# copy paste the command in the terminal and change them if required without forgetting the flags
|
||||
export RUSTFLAGS := "-C target-cpu=native"
|
||||
|
||||
|
||||
CARGO := "cargo +" + RS_CHECK_TOOLCHAIN
|
||||
|
||||
CARGO_BUILD := CARGO + " build --profile " + CARGO_PROFILE + " "
|
||||
CARGO_TEST := CARGO + " test --profile " + CARGO_PROFILE + " "
|
||||
CARGO_RUN := CARGO + " run --profile " + CARGO_PROFILE + " "
|
||||
CARGO_CHECK := CARGO + " check "
|
||||
CARGO_CLIPPY := CARGO + " clippy "
|
||||
CARGO_DOC := CARGO + " doc "
|
||||
CARGO_FMT := CARGO + " fmt "
|
||||
CARGO_BENCH := CARGO + " bench "
|
||||
|
||||
|
||||
|
||||
AVX512_FEATURE := if AVX512_SUPPORT == "ON" {
|
||||
"nightly-avx512"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
FEATURES := "--features=" + TARGET_ARCH_FEATURE + "," + AVX512_FEATURE + ","
|
||||
|
||||
|
||||
|
||||
MULTI_BIT_ONLY := if GEN_KEY_CACHE_MULTI_BIT_ONLY == "TRUE" {
|
||||
"--multi-bit-only"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
# Variables used only for regex_engine example
|
||||
REGEX_STRING := ''
|
||||
REGEX_PATTERN := ''
|
||||
|
||||
rs_check_toolchain:
|
||||
@echo {{RS_CHECK_TOOLCHAIN}}
|
||||
|
||||
|
||||
rs_build_toolchain:
|
||||
@echo {{RS_BUILD_TOOLCHAIN}}
|
||||
|
||||
|
||||
install_rs_check_toolchain:
|
||||
@rustup toolchain list | grep -q "{{RS_CHECK_TOOLCHAIN}}" || \
|
||||
rustup toolchain install --profile default "{{RS_CHECK_TOOLCHAIN}}" || \
|
||||
( echo "Unable to install {{RS_CHECK_TOOLCHAIN}} toolchain, check your rustup installation. \
|
||||
Rustup can be downloaded at https://rustup.rs/" && exit 1 )
|
||||
|
||||
|
||||
install_rs_build_toolchain:
|
||||
@( rustup toolchain list | grep -q "{{RS_BUILD_TOOLCHAIN}}" && \
|
||||
./scripts/check_cargo_min_ver.sh \
|
||||
--rust-toolchain "{{RS_BUILD_TOOLCHAIN}}" \
|
||||
--min-rust-version "{{MIN_RUST_VERSION}}" ) || \
|
||||
rustup toolchain install --profile default "{{RS_BUILD_TOOLCHAIN}}" || \
|
||||
( echo "Unable to install {{RS_BUILD_TOOLCHAIN}} toolchain, check your rustup installation. \
|
||||
Rustup can be downloaded at https://rustup.rs/" && exit 1 )
|
||||
|
||||
|
||||
install_cargo_nextest: install_rs_build_toolchain
|
||||
@cargo nextest --version > /dev/null 2>&1 || \
|
||||
{{CARGO}} install cargo-nextest --locked || \
|
||||
( echo "Unable to install cargo nextest, unknown error." && exit 1 )
|
||||
|
||||
|
||||
install_wasm_pack: install_rs_build_toolchain
|
||||
@wasm-pack --version > /dev/null 2>&1 || \
|
||||
{{CARGO}} install wasm-pack || \
|
||||
( echo "Unable to install cargo wasm-pack, unknown error." && exit 1 )
|
||||
|
||||
|
||||
install_node:
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | {{SHELL}}
|
||||
source ~/.bashrc
|
||||
{{SHELL}} -i -c 'nvm install node' || \
|
||||
( echo "Unable to install node, unknown error." && exit 1 )
|
||||
|
||||
|
||||
install_dieharder:
|
||||
@dieharder -h > /dev/null 2>&1 || \
|
||||
if [[ "{{OS}}" == "Linux" ]]; then \
|
||||
sudo apt update && sudo apt install -y dieharder; \
|
||||
elif [[ "{{OS}}" == "Darwin" ]]; then\
|
||||
brew install dieharder; \
|
||||
fi || ( echo "Unable to install dieharder, unknown error." && exit 1 )
|
||||
|
||||
|
||||
fmt: install_rs_check_toolchain
|
||||
{{CARGO_FMT}}
|
||||
|
||||
check_fmt:
|
||||
{{CARGO_FMT}} --check
|
||||
|
||||
|
||||
clippy_core: install_rs_check_toolchain
|
||||
{{CARGO_CLIPPY}} {{FEATURES}} -p tfhe -- --no-deps -D warnings
|
||||
{{CARGO_CLIPPY}} {{FEATURES}},experimental -p tfhe -- --no-deps -D warnings
|
||||
|
||||
|
||||
clippy_boolean: install_rs_check_toolchain
|
||||
{{CARGO_CLIPPY}} {{FEATURES}},boolean -p tfhe -- --no-deps -D warnings
|
||||
|
||||
clippy_shortint: install_rs_check_toolchain
|
||||
{{CARGO_CLIPPY}} {{FEATURES}},shortint \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
|
||||
|
||||
clippy_integer: install_rs_check_toolchain
|
||||
{{CARGO_CLIPPY}} {{FEATURES}},integer \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
|
||||
clippy: install_rs_check_toolchain
|
||||
{{CARGO_CLIPPY}} --all-targets \
|
||||
{{FEATURES}},boolean,shortint,integer \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
|
||||
|
||||
clippy_c_api: install_rs_check_toolchain
|
||||
{{CARGO_CLIPPY}} {{FEATURES}},boolean-c-api,shortint-c-api \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
|
||||
|
||||
clippy_js_wasm_api: install_rs_check_toolchain
|
||||
{{CARGO_CLIPPY}} --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
|
||||
|
||||
clippy_tasks:
|
||||
{{CARGO_CLIPPY}} \
|
||||
-p tasks -- --no-deps -D warnings
|
||||
|
||||
|
||||
clippy_trivium: install_rs_check_toolchain
|
||||
{{CARGO_CLIPPY}} -p tfhe-trivium \
|
||||
{{FEATURES}},boolean,shortint,integer \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
|
||||
|
||||
clippy_all_targets:
|
||||
{{CARGO_CLIPPY}} --all-targets \
|
||||
{{FEATURES}},boolean,shortint,integer \
|
||||
-p tfhe -- --no-deps -D warnings
|
||||
|
||||
|
||||
clippy_concrete_csprng:
|
||||
{{CARGO_CLIPPY}} --all-targets \
|
||||
{{FEATURES}} \
|
||||
-p concrete-csprng -- --no-deps -D warnings
|
||||
|
||||
|
||||
clippy_all: clippy clippy_boolean clippy_shortint clippy_integer clippy_all_targets clippy_c_api clippy_js_wasm_api clippy_tasks clippy_core clippy_concrete_csprng clippy_trivium
|
||||
|
||||
|
||||
clippy_fast: clippy clippy_all_targets clippy_c_api clippy_js_wasm_api clippy_tasks clippy_core clippy_concrete_csprng
|
||||
|
||||
|
||||
gen_key_cache: install_rs_build_toolchain
|
||||
{{CARGO_RUN}} \
|
||||
--example generates_test_keys \
|
||||
{{FEATURES}},shortint,internal-keycache -p tfhe -- \
|
||||
{{MULTI_BIT_ONLY}}
|
||||
|
||||
|
||||
build_core: install_rs_build_toolchain install_rs_check_toolchain
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}} -p tfhe
|
||||
@if [[ "{{AVX512_SUPPORT}}" == "ON" ]]; then \
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}},{{AVX512_FEATURE}} -p tfhe; \
|
||||
fi
|
||||
|
||||
|
||||
build_core_experimental: install_rs_build_toolchain install_rs_check_toolchain
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}},experimental -p tfhe
|
||||
@if [[ "{{AVX512_SUPPORT}}" == "ON" ]]; then \
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}},experimental,{{AVX512_FEATURE}} -p tfhe; \
|
||||
fi
|
||||
|
||||
|
||||
build_boolean: install_rs_build_toolchain
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}},boolean -p tfhe --all-targets
|
||||
|
||||
|
||||
build_shortint: install_rs_build_toolchain
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}},shortint -p tfhe --all-targets
|
||||
|
||||
|
||||
build_integer: install_rs_build_toolchain
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}},integer -p tfhe --all-targets
|
||||
|
||||
|
||||
build_tfhe_full: install_rs_build_toolchain
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}},boolean,shortint,integer -p tfhe --all-targets
|
||||
|
||||
|
||||
build_c_api: install_rs_check_toolchain
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}},boolean-c-api,shortint-c-api,high-level-c-api, \
|
||||
-p tfhe
|
||||
|
||||
|
||||
build_c_api_experimental_deterministic_fft: install_rs_check_toolchain
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}},boolean-c-api,shortint-c-api,high-level-c-api,experimental-force_fft_algo_dif4 \
|
||||
-p tfhe
|
||||
|
||||
|
||||
build_web_js_api: install_rs_build_toolchain install_wasm_pack
|
||||
cd tfhe && \
|
||||
RUSTFLAGS="{{WASM_RUSTFLAGS}}" rustup run "{{RS_BUILD_TOOLCHAIN}}" \
|
||||
wasm-pack build --release --target=web \
|
||||
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api
|
||||
|
||||
|
||||
build_web_js_api_parallel: install_rs_check_toolchain install_wasm_pack
|
||||
cd tfhe && \
|
||||
rustup component add rust-src --toolchain {{RS_CHECK_TOOLCHAIN}} && \
|
||||
RUSTFLAGS="{{WASM_RUSTFLAGS}} -C target-feature=+atomics,+bulk-memory,+mutable-globals" rustup run {{RS_CHECK_TOOLCHAIN}} \
|
||||
wasm-pack build --release --target=web \
|
||||
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,parallel-wasm-api \
|
||||
-Z build-std=panic_abort,std
|
||||
|
||||
|
||||
build_node_js_api: install_rs_build_toolchain install_wasm_pack
|
||||
cd tfhe && \
|
||||
RUSTFLAGS="{{WASM_RUSTFLAGS}}" rustup run "{{RS_BUILD_TOOLCHAIN}}" \
|
||||
wasm-pack build --release --target=nodejs \
|
||||
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api
|
||||
|
||||
|
||||
build_concrete_csprng: install_rs_build_toolchain
|
||||
{{CARGO_BUILD}} \
|
||||
{{FEATURES}} -p concrete-csprng --all-targets
|
||||
|
||||
|
||||
test_core_crypto: install_rs_build_toolchain install_rs_check_toolchain
|
||||
{{CARGO_TEST}} \
|
||||
{{FEATURES}},experimental -p tfhe -- core_crypto::
|
||||
@if [[ "{{AVX512_SUPPORT}}" == "ON" ]]; then \
|
||||
{{CARGO_TEST}} \
|
||||
{{FEATURES}},experimental,{{AVX512_FEATURE}} -p tfhe -- core_crypto::; \
|
||||
fi
|
||||
|
||||
|
||||
test_boolean: install_rs_build_toolchain
|
||||
{{CARGO_TEST}} \
|
||||
{{FEATURES}},boolean -p tfhe -- boolean::
|
||||
|
||||
|
||||
test_c_api_rs: install_rs_check_toolchain
|
||||
{{CARGO_TEST}} \
|
||||
{{FEATURES}},boolean-c-api,shortint-c-api,high-level-c-api \
|
||||
-p tfhe \
|
||||
c_api
|
||||
|
||||
|
||||
test_c_api_c: build_c_api
|
||||
./scripts/c_api_tests.sh
|
||||
|
||||
|
||||
test_c_api: test_c_api_rs test_c_api_c
|
||||
|
||||
|
||||
test_shortint_ci: install_rs_build_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="{{BIG_TESTS_INSTANCE}}" \
|
||||
./scripts/shortint-tests.sh --rust-toolchain {{RS_BUILD_TOOLCHAIN}} \
|
||||
--cargo-profile "{{CARGO_PROFILE}}"
|
||||
|
||||
|
||||
test_shortint_multi_bit_ci: install_rs_build_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="{{BIG_TESTS_INSTANCE}}" \
|
||||
./scripts/shortint-tests.sh --rust-toolchain {{RS_BUILD_TOOLCHAIN}} \
|
||||
--cargo-profile "{{CARGO_PROFILE}}" --multi-bit
|
||||
|
||||
|
||||
test_shortint: install_rs_build_toolchain
|
||||
{{CARGO_TEST}} \
|
||||
{{FEATURES}},shortint,internal-keycache -p tfhe -- shortint::
|
||||
|
||||
|
||||
test_integer_ci: install_rs_build_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="{{BIG_TESTS_INSTANCE}}" \
|
||||
./scripts/integer-tests.sh --rust-toolchain {{RS_BUILD_TOOLCHAIN}} \
|
||||
--cargo-profile "{{CARGO_PROFILE}}"
|
||||
|
||||
|
||||
test_integer_multi_bit_ci: install_rs_build_toolchain install_cargo_nextest
|
||||
BIG_TESTS_INSTANCE="{{BIG_TESTS_INSTANCE}}" \
|
||||
./scripts/integer-tests.sh --rust-toolchain {{RS_BUILD_TOOLCHAIN}} \
|
||||
--cargo-profile "{{CARGO_PROFILE}}" --multi-bit
|
||||
|
||||
|
||||
test_integer: install_rs_build_toolchain
|
||||
{{CARGO_TEST}} \
|
||||
{{FEATURES}},integer,internal-keycache -p tfhe -- integer::
|
||||
|
||||
|
||||
test_high_level_api: install_rs_build_toolchain
|
||||
{{CARGO_TEST}} \
|
||||
{{FEATURES}},boolean,shortint,integer,internal-keycache -p tfhe \
|
||||
-- high_level_api::
|
||||
|
||||
|
||||
test_user_doc: install_rs_build_toolchain
|
||||
{{CARGO_TEST}} --doc \
|
||||
{{FEATURES}},boolean,shortint,integer,internal-keycache -p tfhe \
|
||||
-- test_user_docs::
|
||||
|
||||
|
||||
test_regex_engine: install_rs_build_toolchain
|
||||
{{CARGO_TEST}} \
|
||||
--example regex_engine \
|
||||
{{FEATURES}},integer
|
||||
|
||||
|
||||
test_sha256_bool: install_rs_build_toolchain
|
||||
{{CARGO_TEST}} \
|
||||
--example sha256_bool \
|
||||
{{FEATURES}},boolean
|
||||
|
||||
|
||||
test_examples: test_sha256_bool test_regex_engine
|
||||
|
||||
|
||||
test_trivium: install_rs_build_toolchain
|
||||
{{CARGO_TEST}} \
|
||||
trivium {{FEATURES}},boolean,shortint,integer \
|
||||
-- --test-threads=1
|
||||
|
||||
|
||||
test_kreyvium: install_rs_build_toolchain
|
||||
{{CARGO_TEST}} \
|
||||
kreyvium {{FEATURES}},boolean,shortint,integer \
|
||||
-- --test-threads=1
|
||||
|
||||
|
||||
test_concrete_csprng:
|
||||
{{CARGO_TEST}} \
|
||||
{{FEATURES}} -p concrete-csprng
|
||||
|
||||
|
||||
doc: install_rs_check_toolchain
|
||||
RUSTDOCFLAGS="--html-in-header katex-header.html" \
|
||||
{{CARGO_DOC}} \
|
||||
{{FEATURES}},boolean,shortint,integer --no-deps
|
||||
|
||||
|
||||
docs: doc
|
||||
|
||||
|
||||
lint_doc: install_rs_check_toolchain
|
||||
RUSTDOCFLAGS="--html-in-header katex-header.html -Dwarnings" \
|
||||
{{CARGO_DOC}} \
|
||||
{{FEATURES}},boolean,shortint,integer --no-deps
|
||||
|
||||
|
||||
lint_docs: lint_doc
|
||||
|
||||
|
||||
format_doc_latex:
|
||||
cargo xtask format_latex_doc
|
||||
@just --no-print-directory fmt
|
||||
@printf "\n===============================\n\n"
|
||||
@printf "Please manually inspect changes made by format_latex_doc, rustfmt can break equations \
|
||||
if the line length is exceeded\n"
|
||||
@printf "\n===============================\n"
|
||||
|
||||
|
||||
check_compile_tests:
|
||||
{{CARGO}} test --no-run \
|
||||
{{FEATURES}},experimental,boolean,shortint,integer,internal-keycache \
|
||||
-p tfhe
|
||||
|
||||
@if [[ "{{OS}}" == "Linux" || "{{OS}}" == "Darwin" ]]; then \
|
||||
just build_c_api; \
|
||||
./scripts/c_api_tests.sh --build-only; \
|
||||
fi
|
||||
|
||||
|
||||
build_nodejs_test_docker:
|
||||
DOCKER_BUILDKIT=1 docker build --build-arg RUST_TOOLCHAIN="{{RS_BUILD_TOOLCHAIN}}" \
|
||||
-f docker/Dockerfile.wasm_tests -t tfhe-wasm-tests .
|
||||
|
||||
|
||||
test_nodejs_wasm_api_in_docker: build_nodejs_test_docker
|
||||
if [[ -t 1 ]]; then RUN_FLAGS="-it"; else RUN_FLAGS="-i"; fi && \
|
||||
docker run --rm "$${RUN_FLAGS}" \
|
||||
-v "$$(pwd)":/tfhe-wasm-tests/tfhe-rs \
|
||||
-v tfhe-rs-root-target-cache:/root/tfhe-rs-target \
|
||||
-v tfhe-rs-pkg-cache:/tfhe-wasm-tests/tfhe-rs/tfhe/pkg \
|
||||
-v tfhe-rs-root-cargo-registry-cache:/root/.cargo/registry \
|
||||
-v tfhe-rs-root-cache:/root/.cache \
|
||||
tfhe-wasm-tests /bin/bash -i -c 'make test_nodejs_wasm_api'
|
||||
|
||||
|
||||
test_nodejs_wasm_api: build_node_js_api
|
||||
cd tfhe && node --test js_on_wasm_tests
|
||||
|
||||
|
||||
test_web_js_api_parallel: build_web_js_api_parallel
|
||||
just -C tfhe/web_wasm_parallel_tests test
|
||||
|
||||
|
||||
ci_test_web_js_api_parallel: build_web_js_api_parallel
|
||||
source ~/.nvm/nvm.sh && \
|
||||
nvm use node && \
|
||||
just -C tfhe/web_wasm_parallel_tests test-ci
|
||||
|
||||
|
||||
no_tfhe_typo:
|
||||
@./scripts/no_tfhe_typo.sh
|
||||
|
||||
|
||||
no_dbg_log:
|
||||
@./scripts/no_dbg_calls.sh
|
||||
|
||||
|
||||
dieharder_csprng: install_dieharder build_concrete_csprng
|
||||
./scripts/dieharder_test.sh
|
||||
|
||||
#
|
||||
# Benchmarks
|
||||
#
|
||||
|
||||
|
||||
bench_integer: install_rs_check_toolchain
|
||||
{{CARGO_BENCH}} \
|
||||
--bench integer-bench \
|
||||
{{FEATURES}},integer,internal-keycache,{{AVX512_FEATURE}} -p tfhe --
|
||||
|
||||
|
||||
bench_integer_multi_bit: install_rs_check_toolchain
|
||||
__TFHE_RS_BENCH_TYPE=MULTI_BIT \
|
||||
{{CARGO_BENCH}} \
|
||||
--bench integer-bench \
|
||||
{{FEATURES}},integer,internal-keycache,{{AVX512_FEATURE}} -p tfhe --
|
||||
|
||||
|
||||
bench_shortint: install_rs_check_toolchain
|
||||
{{CARGO_BENCH}} \
|
||||
--bench shortint-bench \
|
||||
{{FEATURES}},shortint,internal-keycache,{{AVX512_FEATURE}} -p tfhe
|
||||
|
||||
|
||||
bench_shortint_multi_bit: install_rs_check_toolchain
|
||||
__TFHE_RS_BENCH_TYPE=MULTI_BIT \
|
||||
{{CARGO_BENCH}} \
|
||||
--bench shortint-bench \
|
||||
{{FEATURES}},shortint,internal-keycache,{{AVX512_FEATURE}} -p tfhe --
|
||||
|
||||
|
||||
|
||||
bench_boolean: install_rs_check_toolchain
|
||||
{{CARGO_BENCH}} \
|
||||
--bench boolean-bench \
|
||||
{{FEATURES}},boolean,internal-keycache,{{AVX512_FEATURE}} -p tfhe
|
||||
|
||||
|
||||
bench_pbs: install_rs_check_toolchain
|
||||
{{CARGO_BENCH}} \
|
||||
--bench pbs-bench \
|
||||
{{FEATURES}},boolean,shortint,internal-keycache,{{AVX512_FEATURE}} -p tfhe
|
||||
|
||||
|
||||
bench_web_js_api_parallel: build_web_js_api_parallel
|
||||
just -C tfhe/web_wasm_parallel_tests bench
|
||||
|
||||
|
||||
ci_bench_web_js_api_parallel: build_web_js_api_parallel
|
||||
source ~/.nvm/nvm.sh && \
|
||||
nvm use node && \
|
||||
just -C tfhe/web_wasm_parallel_tests bench-ci
|
||||
|
||||
#
|
||||
# Utility tools
|
||||
#
|
||||
|
||||
|
||||
measure_hlapi_compact_pk_ct_sizes: install_rs_check_toolchain
|
||||
{{CARGO_RUN}} \
|
||||
--example hlapi_compact_pk_ct_sizes \
|
||||
{{FEATURES}},integer,internal-keycache
|
||||
|
||||
|
||||
measure_shortint_key_sizes: install_rs_check_toolchain
|
||||
{{CARGO_RUN}} \
|
||||
--example shortint_key_sizes \
|
||||
{{FEATURES}},shortint,internal-keycache
|
||||
|
||||
|
||||
measure_boolean_key_sizes: install_rs_check_toolchain
|
||||
{{CARGO_RUN}} \
|
||||
--example boolean_key_sizes \
|
||||
{{FEATURES}},boolean,internal-keycache
|
||||
|
||||
|
||||
parse_integer_benches:
|
||||
python3 ./ci/parse_integer_benches_to_csv.py \
|
||||
--criterion-dir target/criterion \
|
||||
--output-file "{{PARSE_INTEGER_BENCH_CSV_FILE}}"
|
||||
|
||||
|
||||
parse_wasm_benchmarks: install_rs_check_toolchain
|
||||
{{CARGO_RUN}} \
|
||||
--example wasm_benchmarks_parser \
|
||||
{{FEATURES}},shortint,internal-keycache \
|
||||
-- web_wasm_parallel_tests/test/benchmark_results
|
||||
|
||||
|
||||
write_params_to_file: install_rs_check_toolchain
|
||||
{{CARGO_RUN}} \
|
||||
--example write_params_to_file \
|
||||
{{FEATURES}},boolean,shortint,internal-keycache
|
||||
|
||||
#
|
||||
# Real use case examples
|
||||
#
|
||||
|
||||
|
||||
regex_engine: install_rs_check_toolchain
|
||||
{{CARGO_RUN}} \
|
||||
--example regex_engine \
|
||||
{{FEATURES}},integer \
|
||||
-- {{REGEX_STRING}} {{REGEX_PATTERN}}
|
||||
|
||||
|
||||
dark_market: install_rs_check_toolchain
|
||||
{{CARGO_RUN}} \
|
||||
--example dark_market \
|
||||
{{FEATURES}},integer,internal-keycache \
|
||||
-- fhe-modified fhe-parallel plain fhe
|
||||
|
||||
|
||||
sha256_bool: install_rs_check_toolchain
|
||||
{{CARGO_RUN}} \
|
||||
--example sha256_bool \
|
||||
{{FEATURES}},boolean
|
||||
|
||||
|
||||
pcc: no_tfhe_typo no_dbg_log check_fmt lint_doc clippy_all check_compile_tests
|
||||
|
||||
|
||||
fpcc: no_tfhe_typo no_dbg_log check_fmt lint_doc clippy_fast check_compile_tests
|
||||
|
||||
conformance: fmt
|
||||
@@ -8,21 +8,14 @@ function usage() {
|
||||
echo "--help Print this message"
|
||||
echo "--rust-toolchain The toolchain to run the tests with default: stable"
|
||||
echo "--multi-bit Run multi-bit tests only: default off"
|
||||
echo "--unsigned-only Run only unsigned integer tests, by default both signed and unsigned tests are run"
|
||||
echo "--signed-only Run only signed integer tests, by default both signed and unsigned tests are run"
|
||||
echo "--cargo-profile The cargo profile used to build tests"
|
||||
echo "--avx512-support Set to ON to enable avx512"
|
||||
echo
|
||||
}
|
||||
|
||||
RUST_TOOLCHAIN="+stable"
|
||||
multi_bit=""
|
||||
not_multi_bit="_multi_bit"
|
||||
# Run signed test by default
|
||||
signed=""
|
||||
not_signed=""
|
||||
cargo_profile="release"
|
||||
avx512_feature=""
|
||||
|
||||
while [ -n "$1" ]
|
||||
do
|
||||
@@ -42,28 +35,11 @@ do
|
||||
not_multi_bit=""
|
||||
;;
|
||||
|
||||
"--unsigned-only" )
|
||||
signed=""
|
||||
not_signed="_signed"
|
||||
;;
|
||||
|
||||
"--signed-only" )
|
||||
signed="_signed"
|
||||
not_signed=""
|
||||
;;
|
||||
|
||||
"--cargo-profile" )
|
||||
shift
|
||||
cargo_profile="$1"
|
||||
;;
|
||||
|
||||
"--avx512-support" )
|
||||
shift
|
||||
if [[ "$1" == "ON" ]]; then
|
||||
avx512_feature=nightly-avx512
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown param : $1"
|
||||
exit 1
|
||||
@@ -86,86 +62,104 @@ if [[ $(uname) == "Darwin" ]]; then
|
||||
nproc_bin="sysctl -n hw.logicalcpu"
|
||||
fi
|
||||
|
||||
# TODO autodetect/have a finer CPU count depending on memory
|
||||
num_cpu_threads="$(${nproc_bin})"
|
||||
n_threads="$(${nproc_bin})"
|
||||
|
||||
if uname -a | grep "arm64"; then
|
||||
if [[ $(uname) == "Darwin" ]]; then
|
||||
# Keys are 4.7 gigs at max, CI M1 macs only has 8 gigs of RAM
|
||||
small_instance_n_threads=1
|
||||
n_threads=1
|
||||
fi
|
||||
else
|
||||
# Keys are 4.7 gigs at max, test machine has 32 gigs of RAM
|
||||
small_instance_n_threads=6
|
||||
n_threads=6
|
||||
fi
|
||||
|
||||
if [[ "${BIG_TESTS_INSTANCE}" == TRUE ]]; then
|
||||
test_threads="$((num_cpu_threads * 1 / 2))"
|
||||
doctest_threads="${num_cpu_threads}"
|
||||
else
|
||||
test_threads="${small_instance_n_threads}"
|
||||
doctest_threads="${num_cpu_threads}"
|
||||
fi
|
||||
|
||||
# block pbs are too slow for high params
|
||||
# mul_crt_4_4 is extremely flaky (~80% failure)
|
||||
# test_wopbs_bivariate_crt_wopbs_param_message generate tables that are too big at the moment
|
||||
# test_integer_smart_mul_param_message_4_carry_4_ks_pbs is too slow
|
||||
# so is test_integer_default_add_sequence_multi_thread_param_message_4_carry_4_ks_pbs
|
||||
# we skip smart_div, smart_rem which are already covered by the smar_div_rem test
|
||||
# we similarly skip default_div, default_rem which are covered by default_div_rem
|
||||
full_test_filter_expression="""\
|
||||
if [[ "${BIG_TESTS_INSTANCE}" != TRUE ]]; then
|
||||
if [[ "${FAST_TESTS}" != TRUE ]]; then
|
||||
# block pbs are too slow for high params
|
||||
# mul_crt_4_4 is extremely flaky (~80% failure)
|
||||
# test_wopbs_bivariate_crt_wopbs_param_message generate tables that are too big at the moment
|
||||
# test_integer_smart_mul_param_message_4_carry_4_ks_pbs is too slow
|
||||
# so is test_integer_default_add_sequence_multi_thread_param_message_4_carry_4_ks_pbs
|
||||
filter_expression="""\
|
||||
test(/^integer::.*${multi_bit}/) \
|
||||
${signed:+"and test(/^integer::.*${signed}/)"} \
|
||||
${not_multi_bit:+"and not test(~${not_multi_bit})"} \
|
||||
${not_signed:+"and not test(~${not_signed})"} \
|
||||
and not test(/.*integer_smart_div_param/) \
|
||||
and not test(/.*integer_smart_rem_param/) \
|
||||
and not test(/.*integer_default_div_param/) \
|
||||
and not test(/.*integer_default_rem_param/) \
|
||||
and not test(/.*_block_pbs(_base)?_param_message_[34]_carry_[34]_ks_pbs$/) \
|
||||
and not test(~mul_crt_param_message_4_carry_4_ks_pbs) \
|
||||
and not test(/.*test_wopbs_bivariate_crt_wopbs_param_message_[34]_carry_[34]_ks_pbs$/) \
|
||||
and not test(/.*test_integer_smart_mul_param_message_4_carry_4_ks_pbs$/) \
|
||||
and not test(/.*test_integer_default_add_sequence_multi_thread_param_message_4_carry_4_ks_pbs$/)"""
|
||||
|
||||
# test only fast default operations with only two set of parameters
|
||||
# we skip default_div, default_rem which are covered by default_div_rem
|
||||
fast_test_filter_expression="""\
|
||||
else
|
||||
# test only fast default operations with only two set of parameters
|
||||
filter_expression="""\
|
||||
test(/^integer::.*${multi_bit}/) \
|
||||
${signed:+"and test(/^integer::.*${signed}/)"} \
|
||||
${not_multi_bit:+"and not test(~${not_multi_bit})"} \
|
||||
${not_signed:+"and not test(~${not_signed})"} \
|
||||
and test(/.*_default_.*?_param${multi_bit}_message_[2-3]_carry_[2-3]${multi_bit:+"_group_2"}_ks_pbs/) \
|
||||
and not test(/.*integer_default_div_param/) \
|
||||
and not test(/.*integer_default_rem_param/) \
|
||||
and not test(/.*_param_message_[14]_carry_[14]_ks_pbs$/) \
|
||||
and not test(/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs$/)"""
|
||||
fi
|
||||
|
||||
if [[ "${FAST_TESTS}" == "TRUE" ]]; then
|
||||
echo "Running 'fast' test set'"
|
||||
filter_expression="${fast_test_filter_expression}"
|
||||
else
|
||||
echo "Running 'slow' test set"
|
||||
filter_expression="${full_test_filter_expression}"
|
||||
fi
|
||||
|
||||
cargo "${RUST_TOOLCHAIN}" nextest run \
|
||||
--tests \
|
||||
--cargo-profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--profile ci \
|
||||
--features="${ARCH_FEATURE}",integer,internal-keycache,"${avx512_feature}" \
|
||||
--test-threads "${test_threads}" \
|
||||
-E "$filter_expression"
|
||||
|
||||
if [[ "${multi_bit}" == "" ]]; then
|
||||
cargo "${RUST_TOOLCHAIN}" test \
|
||||
--profile "${cargo_profile}" \
|
||||
cargo "${RUST_TOOLCHAIN}" nextest run \
|
||||
--tests \
|
||||
--cargo-profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--features="${ARCH_FEATURE}",integer,internal-keycache,"${avx512_feature}" \
|
||||
--doc \
|
||||
-- --test-threads="${doctest_threads}" integer::
|
||||
--profile ci \
|
||||
--features="${ARCH_FEATURE}",integer,internal-keycache \
|
||||
--test-threads "${n_threads}" \
|
||||
-E "$filter_expression"
|
||||
|
||||
if [[ "${multi_bit}" == "" ]]; then
|
||||
cargo "${RUST_TOOLCHAIN}" test \
|
||||
--profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--features="${ARCH_FEATURE}",integer,internal-keycache \
|
||||
--doc \
|
||||
-- integer::
|
||||
fi
|
||||
else
|
||||
if [[ "${FAST_TESTS}" != TRUE ]]; then
|
||||
# block pbs are too slow for high params
|
||||
# mul_crt_4_4 is extremely flaky (~80% failure)
|
||||
# test_wopbs_bivariate_crt_wopbs_param_message generate tables that are too big at the moment
|
||||
# test_integer_smart_mul_param_message_4_carry_4_ks_pbs is too slow
|
||||
# so is test_integer_default_add_sequence_multi_thread_param_message_4_carry_4_ks_pbs
|
||||
filter_expression="""\
|
||||
test(/^integer::.*${multi_bit}/) \
|
||||
${not_multi_bit:+"and not test(~${not_multi_bit})"} \
|
||||
and not test(/.*_block_pbs(_base)?_param_message_[34]_carry_[34]_ks_pbs$/) \
|
||||
and not test(~mul_crt_param_message_4_carry_4_ks_pbs) \
|
||||
and not test(/.*test_wopbs_bivariate_crt_wopbs_param_message_[34]_carry_[34]_ks_pbs$/) \
|
||||
and not test(/.*test_integer_smart_mul_param_message_4_carry_4_ks_pbs$/) \
|
||||
and not test(/.*test_integer_default_add_sequence_multi_thread_param_message_4_carry_4_ks_pbs$/)"""
|
||||
else
|
||||
# test only fast default operations with only two set of parameters
|
||||
filter_expression="""\
|
||||
test(/^integer::.*${multi_bit}/) \
|
||||
${not_multi_bit:+"and not test(~${not_multi_bit})"} \
|
||||
and test(/.*_default_.*?_param${multi_bit}_message_[2-3]_carry_[2-3]${multi_bit:+"_group_2"}_ks_pbs/) \
|
||||
and not test(/.*_param_message_[14]_carry_[14]_ks_pbs$/) \
|
||||
and not test(/.*default_add_sequence_multi_thread_param_message_3_carry_3_ks_pbs$/)"""
|
||||
fi
|
||||
|
||||
num_cpu_threads="$(${nproc_bin})"
|
||||
num_threads=$((num_cpu_threads * 1 / 2))
|
||||
cargo "${RUST_TOOLCHAIN}" nextest run \
|
||||
--tests \
|
||||
--cargo-profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--profile ci \
|
||||
--features="${ARCH_FEATURE}",integer,internal-keycache \
|
||||
--test-threads $num_threads \
|
||||
-E "$filter_expression"
|
||||
|
||||
if [[ "${multi_bit}" == "" ]]; then
|
||||
cargo "${RUST_TOOLCHAIN}" test \
|
||||
--profile "${cargo_profile}" \
|
||||
--package tfhe \
|
||||
--features="${ARCH_FEATURE}",integer,internal-keycache \
|
||||
--doc \
|
||||
-- --test-threads="$(${nproc_bin})" integer::
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Test ran in $SECONDS seconds"
|
||||
|
||||
@@ -94,7 +94,6 @@ or test(/^shortint::.*_param${multi_bit}_message_2_carry_3${multi_bit:+"_group_[
|
||||
or test(/^shortint::.*_param${multi_bit}_message_3_carry_1${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
|
||||
or test(/^shortint::.*_param${multi_bit}_message_3_carry_2${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
|
||||
or test(/^shortint::.*_param${multi_bit}_message_3_carry_3${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
|
||||
or test(/^shortint::.*_ci_run_filter/) \
|
||||
)\
|
||||
and not test(~smart_add_and_mul)""" # This test is too slow
|
||||
else
|
||||
@@ -160,7 +159,6 @@ or test(/^shortint::.*_param${multi_bit}_message_3_carry_1${multi_bit:+"_group_[
|
||||
or test(/^shortint::.*_param${multi_bit}_message_3_carry_2${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
|
||||
or test(/^shortint::.*_param${multi_bit}_message_3_carry_3${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
|
||||
or test(/^shortint::.*_param${multi_bit}_message_4_carry_4${multi_bit:+"_group_[0-9]"}(_compact_pk)?_ks_pbs/) \
|
||||
or test(/^shortint::.*_ci_run_filter/) \
|
||||
)\
|
||||
and not test(~smart_add_and_mul)""" # This test is too slow
|
||||
else
|
||||
|
||||
@@ -6,7 +6,7 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = "=4.4.4"
|
||||
clap = "3.1"
|
||||
lazy_static = "1.4"
|
||||
log = "0.4"
|
||||
simplelog = "0.12"
|
||||
|
||||
2
tfhe/.gitignore
vendored
2
tfhe/.gitignore
vendored
@@ -1 +1 @@
|
||||
build/
|
||||
build/
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tfhe"
|
||||
version = "0.5.0"
|
||||
version = "0.4.0"
|
||||
edition = "2021"
|
||||
readme = "../README.md"
|
||||
keywords = ["fully", "homomorphic", "encryption", "fhe", "cryptography"]
|
||||
@@ -17,7 +17,7 @@ exclude = [
|
||||
"/js_on_wasm_tests/",
|
||||
"/web_wasm_parallel_tests/",
|
||||
]
|
||||
rust-version = "1.72"
|
||||
rust-version = "1.67"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -26,30 +26,29 @@ rand = "0.8.5"
|
||||
rand_distr = "0.4.3"
|
||||
paste = "1.0.7"
|
||||
lazy_static = { version = "1.4.0" }
|
||||
criterion = "0.5.1"
|
||||
criterion = "0.4.0"
|
||||
doc-comment = "0.3.3"
|
||||
serde_json = "1.0.94"
|
||||
# clap has to be pinned as its minimum supported rust version
|
||||
# changes often between minor releases, which breaks our CI
|
||||
clap = { version = "=4.4.4", features = ["derive"] }
|
||||
clap = { version = "=4.2.7", features = ["derive"] }
|
||||
# Used in user documentation
|
||||
bincode = "1.3.3"
|
||||
fs2 = { version = "0.4.3" }
|
||||
itertools = "0.11.0"
|
||||
itertools = "0.10.5"
|
||||
num_cpus = "1.15"
|
||||
# For erf and normality test
|
||||
libm = "0.2.6"
|
||||
# Begin regex-engine deps
|
||||
test-case = "3.1.0"
|
||||
combine = "4.6.6"
|
||||
env_logger = "0.10.0"
|
||||
log = "0.4.19"
|
||||
# End regex-engine deps
|
||||
|
||||
[build-dependencies]
|
||||
cbindgen = { version = "0.26.0", optional = true }
|
||||
cbindgen = { version = "0.24.3", optional = true }
|
||||
|
||||
[dependencies]
|
||||
concrete-csprng = { version = "0.4.0", path = "../concrete-csprng", features = [
|
||||
concrete-csprng = { version = "0.4.0", path= "../concrete-csprng", features = [
|
||||
"generator_fallback",
|
||||
"parallel",
|
||||
] }
|
||||
@@ -61,10 +60,11 @@ concrete-fft = { version = "0.3.0", features = ["serde", "fft128"] }
|
||||
pulp = "0.13"
|
||||
aligned-vec = { version = "0.5", features = ["serde"] }
|
||||
dyn-stack = { version = "0.9" }
|
||||
paste = { version = "1.0.7", optional = true }
|
||||
once_cell = "1.13"
|
||||
paste = "1.0.7"
|
||||
fs2 = { version = "0.4.3", optional = true }
|
||||
# While we wait for repeat_n in rust standard library
|
||||
itertools = "0.11.0"
|
||||
itertools = "0.10.5"
|
||||
|
||||
# wasm deps
|
||||
wasm-bindgen = { version = "0.2.86", features = [
|
||||
@@ -73,45 +73,40 @@ wasm-bindgen = { version = "0.2.86", features = [
|
||||
wasm-bindgen-rayon = { version = "1.0", optional = true }
|
||||
js-sys = { version = "0.3", optional = true }
|
||||
console_error_panic_hook = { version = "0.1.7", optional = true }
|
||||
serde-wasm-bindgen = { version = "0.6.0", optional = true }
|
||||
serde-wasm-bindgen = { version = "0.4", optional = true }
|
||||
getrandom = { version = "0.2.8", optional = true }
|
||||
bytemuck = "1.13.1"
|
||||
|
||||
[features]
|
||||
# paste is used by the HL API
|
||||
boolean = ["dep:paste"]
|
||||
shortint = ["dep:paste"]
|
||||
integer = ["shortint", "dep:paste"]
|
||||
internal-keycache = ["dep:lazy_static", "dep:fs2", "dep:bincode", "dep:paste"]
|
||||
safe-deserialization = ["dep:bincode"]
|
||||
boolean = []
|
||||
shortint = []
|
||||
integer = ["shortint"]
|
||||
internal-keycache = ["lazy_static", "fs2", "bincode"]
|
||||
|
||||
# Experimental section
|
||||
experimental = []
|
||||
experimental-force_fft_algo_dif4 = []
|
||||
# End experimental section
|
||||
|
||||
__c_api = ["dep:cbindgen", "dep:bincode", "dep:paste"]
|
||||
# For the semver trick to skip the build.rs
|
||||
__force_skip_cbindgen = []
|
||||
__c_api = ["cbindgen", "bincode"]
|
||||
boolean-c-api = ["boolean", "__c_api"]
|
||||
shortint-c-api = ["shortint", "__c_api"]
|
||||
high-level-c-api = ["boolean-c-api", "shortint-c-api", "integer", "__c_api"]
|
||||
|
||||
__wasm_api = [
|
||||
"dep:wasm-bindgen",
|
||||
"dep:js-sys",
|
||||
"dep:console_error_panic_hook",
|
||||
"dep:serde-wasm-bindgen",
|
||||
"dep:getrandom",
|
||||
"wasm-bindgen",
|
||||
"js-sys",
|
||||
"console_error_panic_hook",
|
||||
"serde-wasm-bindgen",
|
||||
"getrandom",
|
||||
"getrandom/js",
|
||||
"dep:bincode",
|
||||
"safe-deserialization",
|
||||
"bincode",
|
||||
]
|
||||
boolean-client-js-wasm-api = ["boolean", "__wasm_api"]
|
||||
shortint-client-js-wasm-api = ["shortint", "__wasm_api"]
|
||||
integer-client-js-wasm-api = ["integer", "__wasm_api"]
|
||||
high-level-client-js-wasm-api = ["boolean", "shortint", "integer", "__wasm_api"]
|
||||
parallel-wasm-api = ["dep:wasm-bindgen-rayon"]
|
||||
parallel-wasm-api = ["wasm-bindgen-rayon"]
|
||||
|
||||
nightly-avx512 = ["concrete-fft/nightly", "pulp/nightly"]
|
||||
|
||||
@@ -151,12 +146,6 @@ rustdoc-args = ["--html-in-header", "katex-header.html"]
|
||||
# #
|
||||
###########
|
||||
|
||||
[[bench]]
|
||||
name = "ks-bench"
|
||||
path = "benches/core_crypto/ks_bench.rs"
|
||||
harness = false
|
||||
required-features = ["shortint", "internal-keycache"]
|
||||
|
||||
[[bench]]
|
||||
name = "pbs-bench"
|
||||
path = "benches/core_crypto/pbs_bench.rs"
|
||||
@@ -192,12 +181,6 @@ path = "benches/integer/bench.rs"
|
||||
harness = false
|
||||
required-features = ["integer", "internal-keycache"]
|
||||
|
||||
[[bench]]
|
||||
name = "integer-signed-bench"
|
||||
path = "benches/integer/signed_bench.rs"
|
||||
harness = false
|
||||
required-features = ["integer", "internal-keycache"]
|
||||
|
||||
[[bench]]
|
||||
name = "keygen"
|
||||
path = "benches/keygen/bench.rs"
|
||||
@@ -220,7 +203,7 @@ required-features = ["shortint", "internal-keycache"]
|
||||
[[example]]
|
||||
name = "generates_test_keys"
|
||||
path = "examples/utilities/generates_test_keys.rs"
|
||||
required-features = ["boolean", "shortint", "internal-keycache"]
|
||||
required-features = ["shortint", "internal-keycache"]
|
||||
|
||||
[[example]]
|
||||
name = "boolean_key_sizes"
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn write_to_json_boolean<T: Into<CryptoParametersRecord<u32>>>(
|
||||
|
||||
// Put all `bench_function` in one place
|
||||
// so the keygen is only run once per parameters saving time.
|
||||
fn benches(c: &mut Criterion, params: BooleanParameters, parameter_name: &str) {
|
||||
fn benchs(c: &mut Criterion, params: BooleanParameters, parameter_name: &str) {
|
||||
let mut bench_group = c.benchmark_group("gates_benches");
|
||||
|
||||
let cks = ClientKey::new(¶ms);
|
||||
@@ -83,15 +83,15 @@ fn benches(c: &mut Criterion, params: BooleanParameters, parameter_name: &str) {
|
||||
}
|
||||
|
||||
fn bench_default_parameters(c: &mut Criterion) {
|
||||
benches(c, DEFAULT_PARAMETERS, "DEFAULT_PARAMETERS");
|
||||
benchs(c, DEFAULT_PARAMETERS, "DEFAULT_PARAMETERS");
|
||||
}
|
||||
|
||||
fn bench_default_parameters_ks_pbs(c: &mut Criterion) {
|
||||
benches(c, DEFAULT_PARAMETERS_KS_PBS, "DEFAULT_PARAMETERS_KS_PBS");
|
||||
benchs(c, DEFAULT_PARAMETERS_KS_PBS, "DEFAULT_PARAMETERS_KS_PBS");
|
||||
}
|
||||
|
||||
fn bench_low_prob_parameters(c: &mut Criterion) {
|
||||
benches(
|
||||
benchs(
|
||||
c,
|
||||
PARAMETERS_ERROR_PROB_2_POW_MINUS_165,
|
||||
"PARAMETERS_ERROR_PROB_2_POW_MINUS_165",
|
||||
@@ -99,7 +99,7 @@ fn bench_low_prob_parameters(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
fn bench_low_prob_parameters_ks_pbs(c: &mut Criterion) {
|
||||
benches(
|
||||
benchs(
|
||||
c,
|
||||
PARAMETERS_ERROR_PROB_2_POW_MINUS_165_KS_PBS,
|
||||
"PARAMETERS_ERROR_PROB_2_POW_MINUS_165_KS_PBS",
|
||||
@@ -107,5 +107,5 @@ fn bench_low_prob_parameters_ks_pbs(c: &mut Criterion) {
|
||||
}
|
||||
|
||||
fn bench_tfhe_lib_parameters(c: &mut Criterion) {
|
||||
benches(c, TFHE_LIB_PARAMETERS, " TFHE_LIB_PARAMETERS");
|
||||
benchs(c, TFHE_LIB_PARAMETERS, " TFHE_LIB_PARAMETERS");
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ fn multi_bit_pbs<Scalar: UnsignedTorus + CastInto<usize> + CastFrom<usize> + Syn
|
||||
);
|
||||
|
||||
let id = format!("Multi Bit PBS {}", Scalar::BITS);
|
||||
|
||||
#[allow(clippy::unit_arg)]
|
||||
{
|
||||
c.bench_function(&id, |b| {
|
||||
b.iter(|| {
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use tfhe::core_crypto::prelude::*;
|
||||
use tfhe::keycache::NamedParam;
|
||||
use tfhe::shortint::prelude::*;
|
||||
|
||||
fn criterion_bench(criterion: &mut Criterion) {
|
||||
type Scalar = u64;
|
||||
|
||||
let mut bench_group = criterion.benchmark_group("KS");
|
||||
bench_group
|
||||
.sample_size(15)
|
||||
.measurement_time(std::time::Duration::from_secs(60));
|
||||
|
||||
for params in [
|
||||
PARAM_MESSAGE_1_CARRY_1_KS_PBS,
|
||||
PARAM_MESSAGE_2_CARRY_2_KS_PBS,
|
||||
PARAM_MESSAGE_3_CARRY_3_KS_PBS,
|
||||
PARAM_MESSAGE_4_CARRY_4_KS_PBS,
|
||||
]
|
||||
.into_iter()
|
||||
{
|
||||
let lwe_dimension = params.lwe_dimension;
|
||||
let lwe_modular_std_dev = params.lwe_modular_std_dev;
|
||||
let ciphertext_modulus = params.ciphertext_modulus;
|
||||
let encoding_with_padding = if ciphertext_modulus.is_native_modulus() {
|
||||
Scalar::ONE << (Scalar::BITS - 1)
|
||||
} else {
|
||||
Scalar::cast_from(ciphertext_modulus.get_custom_modulus() / 2)
|
||||
};
|
||||
let glwe_dimension = params.glwe_dimension;
|
||||
let polynomial_size = params.polynomial_size;
|
||||
let ks_decomp_base_log = params.ks_base_log;
|
||||
let ks_decomp_level_count = params.ks_level;
|
||||
let msg_modulus: Scalar = params.message_modulus.0.cast_into();
|
||||
let total_modulus: Scalar = (params.message_modulus.0 * params.carry_modulus.0).cast_into();
|
||||
|
||||
let msg = msg_modulus - 1;
|
||||
let delta: Scalar = encoding_with_padding / total_modulus;
|
||||
|
||||
// Create the PRNG
|
||||
let mut seeder = new_seeder();
|
||||
let seeder = seeder.as_mut();
|
||||
let mut encryption_generator =
|
||||
EncryptionRandomGenerator::<ActivatedRandomGenerator>::new(seeder.seed(), seeder);
|
||||
let mut secret_generator =
|
||||
SecretRandomGenerator::<ActivatedRandomGenerator>::new(seeder.seed());
|
||||
|
||||
let lwe_sk =
|
||||
allocate_and_generate_new_binary_lwe_secret_key(lwe_dimension, &mut secret_generator);
|
||||
|
||||
let glwe_sk = allocate_and_generate_new_binary_glwe_secret_key(
|
||||
glwe_dimension,
|
||||
polynomial_size,
|
||||
&mut secret_generator,
|
||||
);
|
||||
let big_lwe_sk = glwe_sk.into_lwe_secret_key();
|
||||
let ksk_big_to_small = allocate_and_generate_new_lwe_keyswitch_key(
|
||||
&big_lwe_sk,
|
||||
&lwe_sk,
|
||||
ks_decomp_base_log,
|
||||
ks_decomp_level_count,
|
||||
lwe_modular_std_dev,
|
||||
ciphertext_modulus,
|
||||
&mut encryption_generator,
|
||||
);
|
||||
|
||||
let plaintext = Plaintext(msg * delta);
|
||||
let ct = allocate_and_encrypt_new_lwe_ciphertext(
|
||||
&big_lwe_sk,
|
||||
plaintext,
|
||||
lwe_modular_std_dev,
|
||||
ciphertext_modulus,
|
||||
&mut encryption_generator,
|
||||
);
|
||||
|
||||
let mut output_ct = LweCiphertext::new(
|
||||
Scalar::ZERO,
|
||||
lwe_sk.lwe_dimension().to_lwe_size(),
|
||||
ciphertext_modulus,
|
||||
);
|
||||
|
||||
bench_group.bench_function(¶ms.name(), |bencher| {
|
||||
bencher.iter(|| {
|
||||
keyswitch_lwe_ciphertext(&ksk_big_to_small, &ct, &mut output_ct);
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_bench);
|
||||
criterion_main!(benches);
|
||||
@@ -12,7 +12,7 @@ use rand::prelude::*;
|
||||
use rand::Rng;
|
||||
use std::vec::IntoIter;
|
||||
use tfhe::integer::keycache::KEY_CACHE;
|
||||
use tfhe::integer::{IntegerKeyKind, RadixCiphertext, ServerKey};
|
||||
use tfhe::integer::{RadixCiphertext, ServerKey};
|
||||
use tfhe::keycache::NamedParam;
|
||||
|
||||
use tfhe::integer::U256;
|
||||
@@ -118,7 +118,7 @@ fn bench_server_key_binary_function_dirty_inputs<F>(
|
||||
|
||||
let bench_id = format!("{bench_name}::{param_name}::{bit_size}_bits");
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param);
|
||||
|
||||
let encrypt_two_values = || {
|
||||
let clear_0 = gen_random_u256(&mut rng);
|
||||
@@ -186,7 +186,7 @@ fn bench_server_key_binary_function_clean_inputs<F>(
|
||||
|
||||
let bench_id = format!("{bench_name}::{param_name}::{bit_size}_bits");
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param);
|
||||
|
||||
let encrypt_two_values = || {
|
||||
let clear_0 = gen_random_u256(&mut rng);
|
||||
@@ -243,7 +243,7 @@ fn bench_server_key_unary_function_dirty_inputs<F>(
|
||||
|
||||
let bench_id = format!("{bench_name}::{param_name}::{bit_size}_bits");
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param);
|
||||
|
||||
let encrypt_one_value = || {
|
||||
let clear_0 = gen_random_u256(&mut rng);
|
||||
@@ -308,7 +308,7 @@ fn bench_server_key_unary_function_clean_inputs<F>(
|
||||
|
||||
let bench_id = format!("{bench_name}::{param_name}::{bit_size}_bits");
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param);
|
||||
|
||||
let encrypt_one_value = || {
|
||||
let clear_0 = gen_random_u256(&mut rng);
|
||||
@@ -362,7 +362,7 @@ fn bench_server_key_binary_scalar_function_dirty_inputs<F, G>(
|
||||
|
||||
let bench_id = format!("{bench_name}::{param_name}::{bit_size}_bits");
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param);
|
||||
|
||||
let encrypt_one_value = || {
|
||||
let clear_0 = gen_random_u256(&mut rng);
|
||||
@@ -435,7 +435,7 @@ fn bench_server_key_binary_scalar_function_clean_inputs<F, G>(
|
||||
|
||||
let bench_id = format!("{bench_name}::{param_name}::{bit_size}_bits_scalar_{bit_size}");
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param);
|
||||
|
||||
let encrypt_one_value = || {
|
||||
let clear_0 = gen_random_u256(&mut rng);
|
||||
@@ -515,7 +515,7 @@ fn if_then_else_parallelized(c: &mut Criterion) {
|
||||
|
||||
let bench_id = format!("{bench_name}::{param_name}::{bit_size}_bits");
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
|
||||
let (cks, sks) = KEY_CACHE.get_from_params(param);
|
||||
|
||||
let encrypt_tree_values = || {
|
||||
let clear_0 = gen_random_u256(&mut rng);
|
||||
@@ -524,7 +524,7 @@ fn if_then_else_parallelized(c: &mut Criterion) {
|
||||
let clear_1 = gen_random_u256(&mut rng);
|
||||
let ct_1 = cks.encrypt_radix(clear_1, num_block);
|
||||
|
||||
let cond = sks.create_trivial_boolean_block(rng.gen_bool(0.5));
|
||||
let cond = sks.create_trivial_radix(rng.gen_bool(0.5) as u64, num_block);
|
||||
|
||||
(cond, ct_0, ct_1)
|
||||
};
|
||||
@@ -650,23 +650,15 @@ define_server_key_bench_fn!(method_name: smart_bitxor, display_name: bitxor);
|
||||
define_server_key_bench_fn!(method_name: smart_add_parallelized, display_name: add);
|
||||
define_server_key_bench_fn!(method_name: smart_sub_parallelized, display_name: sub);
|
||||
define_server_key_bench_fn!(method_name: smart_mul_parallelized, display_name: mul);
|
||||
define_server_key_bench_fn!(method_name: smart_div_parallelized, display_name: div);
|
||||
define_server_key_bench_fn!(method_name: smart_div_rem_parallelized, display_name: div_mod);
|
||||
define_server_key_bench_fn!(method_name: smart_rem_parallelized, display_name: rem);
|
||||
define_server_key_bench_fn!(method_name: smart_bitand_parallelized, display_name: bitand);
|
||||
define_server_key_bench_fn!(method_name: smart_bitxor_parallelized, display_name: bitxor);
|
||||
define_server_key_bench_fn!(method_name: smart_bitor_parallelized, display_name: bitor);
|
||||
define_server_key_bench_fn!(method_name: smart_rotate_right_parallelized, display_name: rotate_right);
|
||||
define_server_key_bench_fn!(method_name: smart_rotate_left_parallelized, display_name: rotate_left);
|
||||
define_server_key_bench_fn!(method_name: smart_right_shift_parallelized, display_name: right_shift);
|
||||
define_server_key_bench_fn!(method_name: smart_left_shift_parallelized, display_name: left_shift);
|
||||
|
||||
define_server_key_bench_default_fn!(method_name: add_parallelized, display_name: add);
|
||||
define_server_key_bench_default_fn!(method_name: sub_parallelized, display_name: sub);
|
||||
define_server_key_bench_default_fn!(method_name: mul_parallelized, display_name: mul);
|
||||
define_server_key_bench_default_fn!(method_name: div_parallelized, display_name: div);
|
||||
define_server_key_bench_default_fn!(method_name: rem_parallelized, display_name: modulo);
|
||||
define_server_key_bench_default_fn!(method_name: div_rem_parallelized, display_name: div_mod);
|
||||
define_server_key_bench_default_fn!(method_name: bitand_parallelized, display_name: bitand);
|
||||
define_server_key_bench_default_fn!(method_name: bitxor_parallelized, display_name: bitxor);
|
||||
define_server_key_bench_default_fn!(method_name: bitor_parallelized, display_name: bitor);
|
||||
@@ -679,11 +671,7 @@ define_server_key_bench_default_fn!(method_name: unchecked_bitand, display_name:
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_bitor, display_name: bitor);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_bitxor, display_name: bitxor);
|
||||
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_add_parallelized, display_name: add);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_mul_parallelized, display_name: mul);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_div_parallelized, display_name: div);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_rem_parallelized, display_name: modulo);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_div_rem_parallelized, display_name: div_mod);
|
||||
define_server_key_bench_default_fn!(
|
||||
method_name: unchecked_bitand_parallelized,
|
||||
display_name: bitand
|
||||
@@ -696,38 +684,6 @@ define_server_key_bench_default_fn!(
|
||||
method_name: unchecked_bitxor_parallelized,
|
||||
display_name: bitxor
|
||||
);
|
||||
define_server_key_bench_default_fn!(
|
||||
method_name: unchecked_rotate_right_parallelized,
|
||||
display_name: rotate_right
|
||||
);
|
||||
define_server_key_bench_default_fn!(
|
||||
method_name: unchecked_rotate_left_parallelized,
|
||||
display_name: rotate_left
|
||||
);
|
||||
define_server_key_bench_default_fn!(
|
||||
method_name: unchecked_right_shift_parallelized,
|
||||
display_name: right_shift
|
||||
);
|
||||
define_server_key_bench_default_fn!(
|
||||
method_name: unchecked_left_shift_parallelized,
|
||||
display_name: left_shift
|
||||
);
|
||||
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_bitand_parallelized,
|
||||
display_name: bitand,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_bitor_parallelized,
|
||||
display_name: bitor,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_bitxor_parallelized,
|
||||
display_name: bitxor,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_add,
|
||||
@@ -760,46 +716,6 @@ define_server_key_bench_scalar_fn!(
|
||||
display_name: mul,
|
||||
rng_func: mul_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_div_parallelized,
|
||||
display_name: div,
|
||||
rng_func: div_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_rem_parallelized,
|
||||
display_name: modulo,
|
||||
rng_func: div_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_div_rem_parallelized,
|
||||
display_name: div_mod,
|
||||
rng_func: div_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_bitand_parallelized,
|
||||
display_name: bitand,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_bitor_parallelized,
|
||||
display_name: bitor,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_bitxor_parallelized,
|
||||
display_name: bitxor,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_rotate_left_parallelized,
|
||||
display_name: rotate_left,
|
||||
rng_func: shift_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_rotate_right_parallelized,
|
||||
display_name: rotate_right,
|
||||
rng_func: shift_scalar
|
||||
);
|
||||
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: scalar_add_parallelized,
|
||||
@@ -826,11 +742,6 @@ define_server_key_bench_scalar_default_fn!(
|
||||
display_name: modulo,
|
||||
rng_func: div_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: scalar_div_rem_parallelized,
|
||||
display_name: div_mod,
|
||||
rng_func: div_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: scalar_left_shift_parallelized,
|
||||
display_name: left_shift,
|
||||
@@ -851,22 +762,6 @@ define_server_key_bench_scalar_default_fn!(
|
||||
display_name: rotate_right,
|
||||
rng_func: shift_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: scalar_bitand_parallelized,
|
||||
display_name: bitand,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: scalar_bitor_parallelized,
|
||||
display_name: bitor,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: scalar_bitxor_parallelized,
|
||||
display_name: bitxor,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: scalar_eq_parallelized,
|
||||
display_name: equal,
|
||||
@@ -908,47 +803,6 @@ define_server_key_bench_scalar_default_fn!(
|
||||
rng_func: default_scalar
|
||||
);
|
||||
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_eq_parallelized,
|
||||
display_name: equal,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_ne_parallelized,
|
||||
display_name: not_equal,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_le_parallelized,
|
||||
display_name: less_or_equal,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_lt_parallelized,
|
||||
display_name: less_than,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_ge_parallelized,
|
||||
display_name: greater_or_equal,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_gt_parallelized,
|
||||
display_name: greater_than,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_max_parallelized,
|
||||
display_name: max,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_fn!(
|
||||
method_name: smart_scalar_min_parallelized,
|
||||
display_name: min,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_add,
|
||||
display_name: add,
|
||||
@@ -964,50 +818,10 @@ define_server_key_bench_scalar_default_fn!(
|
||||
display_name: mul,
|
||||
rng_func: mul_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_div_parallelized,
|
||||
display_name: div,
|
||||
rng_func: div_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_rem_parallelized,
|
||||
display_name: modulo,
|
||||
rng_func: div_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_div_rem_parallelized,
|
||||
display_name: div_mod,
|
||||
rng_func: div_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_rotate_right_parallelized,
|
||||
display_name: rotate_right,
|
||||
rng_func: shift_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_rotate_left_parallelized,
|
||||
display_name: rotate_left,
|
||||
rng_func: shift_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_right_shift_parallelized,
|
||||
display_name: right_shift,
|
||||
rng_func: shift_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_left_shift_parallelized,
|
||||
display_name: left_shift,
|
||||
rng_func: shift_scalar
|
||||
);
|
||||
|
||||
define_server_key_bench_unary_fn!(method_name: smart_neg, display_name: negation);
|
||||
define_server_key_bench_unary_fn!(method_name: smart_neg_parallelized, display_name: negation);
|
||||
define_server_key_bench_unary_fn!(method_name: smart_abs_parallelized, display_name: abs);
|
||||
|
||||
define_server_key_bench_unary_default_fn!(method_name: neg_parallelized, display_name: negation);
|
||||
define_server_key_bench_unary_default_fn!(method_name: abs_parallelized, display_name: abs);
|
||||
|
||||
define_server_key_bench_unary_default_fn!(method_name: unchecked_abs_parallelized, display_name: abs);
|
||||
|
||||
define_server_key_bench_unary_fn!(method_name: full_propagate, display_name: carry_propagation);
|
||||
define_server_key_bench_unary_fn!(
|
||||
@@ -1018,7 +832,6 @@ define_server_key_bench_unary_fn!(
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_max, display_name: max);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_min, display_name: min);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_eq, display_name: equal);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_ne, display_name: not_equal);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_lt, display_name: less_than);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_le, display_name: less_or_equal);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_gt, display_name: greater_than);
|
||||
@@ -1027,7 +840,6 @@ define_server_key_bench_default_fn!(method_name: unchecked_ge, display_name: gre
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_max_parallelized, display_name: max);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_min_parallelized, display_name: min);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_eq_parallelized, display_name: equal);
|
||||
define_server_key_bench_default_fn!(method_name: unchecked_ne_parallelized, display_name: not_equal);
|
||||
define_server_key_bench_default_fn!(
|
||||
method_name: unchecked_lt_parallelized,
|
||||
display_name: less_than
|
||||
@@ -1045,35 +857,9 @@ define_server_key_bench_default_fn!(
|
||||
display_name: greater_or_equal
|
||||
);
|
||||
|
||||
define_server_key_bench_scalar_default_fn!(method_name: unchecked_scalar_max_parallelized, display_name: max,rng_func: default_scalar);
|
||||
define_server_key_bench_scalar_default_fn!(method_name: unchecked_scalar_min_parallelized, display_name: min,rng_func: default_scalar);
|
||||
define_server_key_bench_scalar_default_fn!(method_name: unchecked_scalar_eq_parallelized, display_name: equal,rng_func: default_scalar);
|
||||
define_server_key_bench_scalar_default_fn!(method_name: unchecked_scalar_ne_parallelized, display_name: not_equal,rng_func: default_scalar);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_lt_parallelized,
|
||||
display_name: less_than,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_le_parallelized,
|
||||
display_name: less_or_equal,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_gt_parallelized,
|
||||
display_name: greater_than,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
define_server_key_bench_scalar_default_fn!(
|
||||
method_name: unchecked_scalar_ge_parallelized,
|
||||
display_name: greater_or_equal,
|
||||
rng_func: default_scalar
|
||||
);
|
||||
|
||||
define_server_key_bench_fn!(method_name: smart_max, display_name: max);
|
||||
define_server_key_bench_fn!(method_name: smart_min, display_name: min);
|
||||
define_server_key_bench_fn!(method_name: smart_eq, display_name: equal);
|
||||
define_server_key_bench_fn!(method_name: smart_ne, display_name: not_equal);
|
||||
define_server_key_bench_fn!(method_name: smart_lt, display_name: less_than);
|
||||
define_server_key_bench_fn!(method_name: smart_le, display_name: less_or_equal);
|
||||
define_server_key_bench_fn!(method_name: smart_gt, display_name: greater_than);
|
||||
@@ -1082,7 +868,6 @@ define_server_key_bench_fn!(method_name: smart_ge, display_name: greater_or_equa
|
||||
define_server_key_bench_fn!(method_name: smart_max_parallelized, display_name: max);
|
||||
define_server_key_bench_fn!(method_name: smart_min_parallelized, display_name: min);
|
||||
define_server_key_bench_fn!(method_name: smart_eq_parallelized, display_name: equal);
|
||||
define_server_key_bench_fn!(method_name: smart_ne_parallelized, display_name: not_equal);
|
||||
define_server_key_bench_fn!(method_name: smart_lt_parallelized, display_name: less_than);
|
||||
define_server_key_bench_fn!(
|
||||
method_name: smart_le_parallelized,
|
||||
@@ -1138,7 +923,6 @@ criterion_group!(
|
||||
smart_max,
|
||||
smart_min,
|
||||
smart_eq,
|
||||
smart_ne,
|
||||
smart_lt,
|
||||
smart_le,
|
||||
smart_gt,
|
||||
@@ -1147,21 +931,12 @@ criterion_group!(
|
||||
|
||||
criterion_group!(
|
||||
smart_parallelized_ops,
|
||||
smart_neg_parallelized,
|
||||
smart_abs_parallelized,
|
||||
smart_add_parallelized,
|
||||
smart_sub_parallelized,
|
||||
smart_mul_parallelized,
|
||||
// smart_div_parallelized,
|
||||
// smart_rem_parallelized,
|
||||
smart_div_rem_parallelized, // For ciphertext div == rem == div_rem
|
||||
smart_bitand_parallelized,
|
||||
smart_bitor_parallelized,
|
||||
smart_bitxor_parallelized,
|
||||
smart_rotate_right_parallelized,
|
||||
smart_rotate_left_parallelized,
|
||||
smart_right_shift_parallelized,
|
||||
smart_left_shift_parallelized,
|
||||
);
|
||||
|
||||
criterion_group!(
|
||||
@@ -1169,7 +944,6 @@ criterion_group!(
|
||||
smart_max_parallelized,
|
||||
smart_min_parallelized,
|
||||
smart_eq_parallelized,
|
||||
smart_ne_parallelized,
|
||||
smart_lt_parallelized,
|
||||
smart_le_parallelized,
|
||||
smart_gt_parallelized,
|
||||
@@ -1178,14 +952,12 @@ criterion_group!(
|
||||
|
||||
criterion_group!(
|
||||
default_parallelized_ops,
|
||||
neg_parallelized,
|
||||
abs_parallelized,
|
||||
add_parallelized,
|
||||
sub_parallelized,
|
||||
mul_parallelized,
|
||||
// div_parallelized,
|
||||
// rem_parallelized,
|
||||
div_rem_parallelized,
|
||||
div_parallelized,
|
||||
rem_parallelized,
|
||||
neg_parallelized,
|
||||
bitand_parallelized,
|
||||
bitnot_parallelized,
|
||||
bitor_parallelized,
|
||||
@@ -1221,26 +993,6 @@ criterion_group!(
|
||||
smart_scalar_add_parallelized,
|
||||
smart_scalar_sub_parallelized,
|
||||
smart_scalar_mul_parallelized,
|
||||
smart_scalar_div_parallelized,
|
||||
smart_scalar_rem_parallelized, // For scalar rem == div_rem
|
||||
// smart_scalar_div_rem_parallelized,
|
||||
smart_scalar_bitand_parallelized,
|
||||
smart_scalar_bitor_parallelized,
|
||||
smart_scalar_bitxor_parallelized,
|
||||
smart_scalar_rotate_right_parallelized,
|
||||
smart_scalar_rotate_left_parallelized,
|
||||
);
|
||||
|
||||
criterion_group!(
|
||||
smart_scalar_parallelized_ops_comp,
|
||||
smart_scalar_max_parallelized,
|
||||
smart_scalar_min_parallelized,
|
||||
smart_scalar_eq_parallelized,
|
||||
smart_scalar_ne_parallelized,
|
||||
smart_scalar_lt_parallelized,
|
||||
smart_scalar_le_parallelized,
|
||||
smart_scalar_gt_parallelized,
|
||||
smart_scalar_ge_parallelized,
|
||||
);
|
||||
|
||||
criterion_group!(
|
||||
@@ -1250,14 +1002,10 @@ criterion_group!(
|
||||
scalar_mul_parallelized,
|
||||
scalar_div_parallelized,
|
||||
scalar_rem_parallelized,
|
||||
// scalar_div_rem_parallelized,
|
||||
scalar_left_shift_parallelized,
|
||||
scalar_right_shift_parallelized,
|
||||
scalar_rotate_left_parallelized,
|
||||
scalar_rotate_right_parallelized,
|
||||
scalar_bitand_parallelized,
|
||||
scalar_bitor_parallelized,
|
||||
scalar_bitxor_parallelized,
|
||||
);
|
||||
|
||||
criterion_group!(
|
||||
@@ -1282,40 +1030,11 @@ criterion_group!(
|
||||
unchecked_bitxor,
|
||||
);
|
||||
|
||||
criterion_group!(
|
||||
unchecked_parallelized_ops,
|
||||
unchecked_abs_parallelized,
|
||||
unchecked_add_parallelized,
|
||||
unchecked_mul_parallelized,
|
||||
// unchecked_div_parallelized,
|
||||
// unchecked_rem_parallelized,
|
||||
unchecked_div_rem_parallelized,
|
||||
unchecked_bitand_parallelized,
|
||||
unchecked_bitor_parallelized,
|
||||
unchecked_bitxor_parallelized,
|
||||
unchecked_rotate_right_parallelized,
|
||||
unchecked_rotate_left_parallelized,
|
||||
unchecked_right_shift_parallelized,
|
||||
unchecked_left_shift_parallelized,
|
||||
);
|
||||
|
||||
criterion_group!(
|
||||
unchecked_parallelized_ops_comp,
|
||||
unchecked_eq_parallelized,
|
||||
unchecked_ne_parallelized,
|
||||
unchecked_gt_parallelized,
|
||||
unchecked_ge_parallelized,
|
||||
unchecked_lt_parallelized,
|
||||
unchecked_max_parallelized,
|
||||
unchecked_min_parallelized,
|
||||
);
|
||||
|
||||
criterion_group!(
|
||||
unchecked_ops_comp,
|
||||
unchecked_max,
|
||||
unchecked_min,
|
||||
unchecked_eq,
|
||||
unchecked_ne,
|
||||
unchecked_lt,
|
||||
unchecked_le,
|
||||
unchecked_gt,
|
||||
@@ -1327,28 +1046,20 @@ criterion_group!(
|
||||
unchecked_scalar_add,
|
||||
unchecked_scalar_sub,
|
||||
unchecked_scalar_mul_parallelized,
|
||||
unchecked_scalar_div_parallelized,
|
||||
unchecked_scalar_rem_parallelized,
|
||||
// unchecked_scalar_div_rem_parallelized,
|
||||
unchecked_scalar_bitand_parallelized,
|
||||
unchecked_scalar_bitor_parallelized,
|
||||
unchecked_scalar_bitxor_parallelized,
|
||||
unchecked_scalar_rotate_right_parallelized,
|
||||
unchecked_scalar_rotate_left_parallelized,
|
||||
unchecked_scalar_right_shift_parallelized,
|
||||
unchecked_scalar_left_shift_parallelized,
|
||||
unchecked_bitand_parallelized,
|
||||
unchecked_bitor_parallelized,
|
||||
unchecked_bitxor_parallelized,
|
||||
);
|
||||
|
||||
criterion_group!(
|
||||
unchecked_scalar_ops_comp,
|
||||
unchecked_scalar_max_parallelized,
|
||||
unchecked_scalar_min_parallelized,
|
||||
unchecked_scalar_eq_parallelized,
|
||||
unchecked_scalar_ne_parallelized,
|
||||
unchecked_scalar_lt_parallelized,
|
||||
unchecked_scalar_le_parallelized,
|
||||
unchecked_scalar_gt_parallelized,
|
||||
unchecked_scalar_ge_parallelized,
|
||||
unchecked_max_parallelized,
|
||||
unchecked_min_parallelized,
|
||||
unchecked_eq_parallelized,
|
||||
unchecked_lt_parallelized,
|
||||
unchecked_le_parallelized,
|
||||
unchecked_gt_parallelized,
|
||||
unchecked_ge_parallelized,
|
||||
);
|
||||
|
||||
criterion_group!(misc, full_propagate, full_propagate_parallelized);
|
||||
@@ -1367,9 +1078,7 @@ fn main() {
|
||||
"smart_parallelized" => smart_parallelized_ops(),
|
||||
"smart_parallelized_comp" => smart_parallelized_ops_comp(),
|
||||
"smart_scalar_parallelized" => smart_scalar_parallelized_ops(),
|
||||
"smart_scalar_parallelized_comp" => smart_scalar_parallelized_ops_comp(),
|
||||
"unchecked" => unchecked_ops(),
|
||||
"unchecked_parallelized" => unchecked_parallelized_ops(),
|
||||
"unchecked_comp" => unchecked_ops_comp(),
|
||||
"unchecked_scalar" => unchecked_scalar_ops(),
|
||||
"unchecked_scalar_comp" => unchecked_scalar_ops_comp(),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -393,7 +393,7 @@ fn _bench_wopbs_param_message_8_norm2_5(c: &mut Criterion) {
|
||||
let mut bench_group = c.benchmark_group("programmable_bootstrap");
|
||||
|
||||
let param = WOPBS_PARAM_MESSAGE_4_NORM2_6_KS_PBS;
|
||||
let param_set: ShortintParameterSet = param.into();
|
||||
let param_set: ShortintParameterSet = param.try_into().unwrap();
|
||||
let pbs_params = param_set.pbs_parameters().unwrap();
|
||||
|
||||
let keys = KEY_CACHE_WOPBS.get_from_param((pbs_params, param));
|
||||
@@ -402,14 +402,14 @@ fn _bench_wopbs_param_message_8_norm2_5(c: &mut Criterion) {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let clear = rng.gen::<usize>() % param.message_modulus.0;
|
||||
let ct = cks.encrypt_without_padding(clear as u64);
|
||||
let mut ct = cks.encrypt_without_padding(clear as u64);
|
||||
let vec_lut = wopbs_key.generate_lut_native_crt(&ct, |x| x);
|
||||
|
||||
let id = format!("Shortint WOPBS: {param:?}");
|
||||
|
||||
bench_group.bench_function(&id, |b| {
|
||||
b.iter(|| {
|
||||
let _ = wopbs_key.programmable_bootstrapping_native_crt(&ct, &vec_lut);
|
||||
let _ = wopbs_key.programmable_bootstrapping_native_crt(&mut ct, &vec_lut);
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#[cfg(all(feature = "__c_api", not(feature = "__force_skip_cbindgen")))]
|
||||
#[cfg(feature = "__c_api")]
|
||||
fn gen_c_api() {
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
@@ -32,15 +32,14 @@ fn gen_c_api() {
|
||||
}
|
||||
|
||||
extern crate cbindgen;
|
||||
let crate_dir: PathBuf = env::var("CARGO_MANIFEST_DIR").unwrap().into();
|
||||
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let package_name = env::var("CARGO_PKG_NAME").unwrap();
|
||||
let output_file = target_dir().join(format!("{package_name}.h"));
|
||||
let output_file = target_dir()
|
||||
.join(format!("{package_name}.h"))
|
||||
.display()
|
||||
.to_string();
|
||||
|
||||
let parse_expand_features_vec = vec![
|
||||
// Note that this list may not be complete, but as macro expansion is used mostly/only for
|
||||
// the C API and the HL API, this is fine, if the C API build fails or generates invalid
|
||||
// headers then you likely need to add other features that will be forwarded to Cargo
|
||||
// expand
|
||||
#[cfg(feature = "__c_api")]
|
||||
"__c_api",
|
||||
#[cfg(feature = "boolean-c-api")]
|
||||
@@ -64,8 +63,8 @@ fn gen_c_api() {
|
||||
};
|
||||
|
||||
cbindgen::Builder::new()
|
||||
.with_crate(crate_dir.as_path())
|
||||
.with_config(cbindgen::Config::from_file(crate_dir.join("cbindgen.toml")).unwrap())
|
||||
.with_crate(crate_dir.clone())
|
||||
.with_config(cbindgen::Config::from_root_or_default(crate_dir))
|
||||
.with_parse_expand(&parse_expand_vec)
|
||||
.with_parse_expand_features(&parse_expand_features_vec)
|
||||
.generate()
|
||||
@@ -74,6 +73,6 @@ fn gen_c_api() {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(all(feature = "__c_api", not(feature = "__force_skip_cbindgen")))]
|
||||
#[cfg(feature = "__c_api")]
|
||||
gen_c_api()
|
||||
}
|
||||
|
||||
@@ -37,3 +37,4 @@ foreach (testsourcefile ${TEST_CASES})
|
||||
# Enabled asserts even in release mode
|
||||
add_definitions(-UNDEBUG)
|
||||
endforeach (testsourcefile ${TEST_CASES})
|
||||
|
||||
|
||||
@@ -99,7 +99,8 @@ int main(void) {
|
||||
ConfigBuilder *builder;
|
||||
Config *config;
|
||||
|
||||
config_builder_default(&builder);
|
||||
config_builder_all_disabled(&builder);
|
||||
config_builder_enable_default_integers_small(&builder);
|
||||
config_builder_build(builder, &config);
|
||||
|
||||
ClientKey *client_key = NULL;
|
||||
|
||||
@@ -110,140 +110,13 @@ int uint256_public_key(const ClientKey *client_key, const PublicKey *public_key)
|
||||
return ok;
|
||||
}
|
||||
|
||||
int int256_client_key(const ClientKey *client_key) {
|
||||
int ok;
|
||||
FheInt256 *lhs = NULL;
|
||||
FheInt256 *rhs = NULL;
|
||||
FheInt256 *result = NULL;
|
||||
FheInt64 *cast_result = NULL;
|
||||
// This is +1
|
||||
I256 lhs_clear = {1, 0, 0, 0};
|
||||
// This is -1
|
||||
I256 rhs_clear = {UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX};
|
||||
I256 result_clear = {0};
|
||||
|
||||
ok = fhe_int256_try_encrypt_with_client_key_i256(lhs_clear, client_key, &lhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int256_try_encrypt_with_client_key_i256(rhs_clear, client_key, &rhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int256_add(lhs, rhs, &result);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int256_decrypt(result, client_key, &result_clear);
|
||||
assert(ok == 0);
|
||||
|
||||
// We did 1 + (-1), so we expect 0
|
||||
assert(result_clear.w0 == 0);
|
||||
assert(result_clear.w1 == 0);
|
||||
assert(result_clear.w2 == 0);
|
||||
assert(result_clear.w3 == 0);
|
||||
|
||||
fhe_int256_destroy(result);
|
||||
ok = fhe_int256_sub(lhs, rhs, &result);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int256_decrypt(result, client_key, &result_clear);
|
||||
assert(ok == 0);
|
||||
|
||||
// We did 1 - (-1), so we expect 2
|
||||
assert(result_clear.w0 == 2);
|
||||
assert(result_clear.w1 == 0);
|
||||
assert(result_clear.w2 == 0);
|
||||
assert(result_clear.w3 == 0);
|
||||
|
||||
// try some casting
|
||||
ok = fhe_int256_cast_into_fhe_int64(result, &cast_result);
|
||||
assert(ok == 0);
|
||||
int64_t u64_clear;
|
||||
ok = fhe_int64_decrypt(cast_result, client_key, &u64_clear);
|
||||
assert(ok == 0);
|
||||
assert(u64_clear == 2);
|
||||
|
||||
fhe_int256_destroy(lhs);
|
||||
fhe_int256_destroy(rhs);
|
||||
fhe_int256_destroy(result);
|
||||
fhe_int64_destroy(cast_result);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int int256_encrypt_trivial(const ClientKey *client_key) {
|
||||
int ok;
|
||||
FheInt256 *lhs = NULL;
|
||||
FheInt256 *rhs = NULL;
|
||||
FheInt256 *result = NULL;
|
||||
I256 lhs_clear = {1, 2, 3, 4};
|
||||
I256 rhs_clear = {5, 6, 7, 8};
|
||||
I256 result_clear = {0};
|
||||
|
||||
ok = fhe_int256_try_encrypt_trivial_i256(lhs_clear, &lhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int256_try_encrypt_trivial_i256(rhs_clear, &rhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int256_add(lhs, rhs, &result);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int256_decrypt(result, client_key, &result_clear);
|
||||
assert(ok == 0);
|
||||
|
||||
assert(result_clear.w0 == 6);
|
||||
assert(result_clear.w1 == 8);
|
||||
assert(result_clear.w2 == 10);
|
||||
assert(result_clear.w3 == 12);
|
||||
|
||||
fhe_int256_destroy(lhs);
|
||||
fhe_int256_destroy(rhs);
|
||||
fhe_int256_destroy(result);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
int int256_public_key(const ClientKey *client_key, const PublicKey *public_key) {
|
||||
int ok;
|
||||
FheInt256 *lhs = NULL;
|
||||
FheInt256 *rhs = NULL;
|
||||
FheInt256 *result = NULL;
|
||||
// This is +1
|
||||
I256 lhs_clear = {1, 0, 0, 0};
|
||||
// This is -1
|
||||
I256 rhs_clear = {UINT64_MAX, UINT64_MAX, UINT64_MAX, UINT64_MAX};
|
||||
I256 result_clear = {0};
|
||||
|
||||
ok = fhe_int256_try_encrypt_with_public_key_i256(lhs_clear, public_key, &lhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int256_try_encrypt_with_public_key_i256(rhs_clear, public_key, &rhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int256_sub(lhs, rhs, &result);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int256_decrypt(result, client_key, &result_clear);
|
||||
assert(ok == 0);
|
||||
|
||||
// We did 1 - (-1), so we expect 2
|
||||
assert(result_clear.w0 == 2);
|
||||
assert(result_clear.w1 == 0);
|
||||
assert(result_clear.w2 == 0);
|
||||
assert(result_clear.w3 == 0);
|
||||
|
||||
fhe_int256_destroy(lhs);
|
||||
fhe_int256_destroy(rhs);
|
||||
fhe_int256_destroy(result);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(void) {
|
||||
int ok = 0;
|
||||
ConfigBuilder *builder;
|
||||
Config *config;
|
||||
|
||||
config_builder_default(&builder);
|
||||
config_builder_all_disabled(&builder);
|
||||
config_builder_enable_default_integers_small(&builder);
|
||||
config_builder_build(builder, &config);
|
||||
|
||||
ClientKey *client_key = NULL;
|
||||
@@ -259,10 +132,6 @@ int main(void) {
|
||||
uint256_encrypt_trivial(client_key);
|
||||
uint256_public_key(client_key, public_key);
|
||||
|
||||
int256_client_key(client_key);
|
||||
int256_encrypt_trivial(client_key);
|
||||
int256_public_key(client_key, public_key);
|
||||
|
||||
client_key_destroy(client_key);
|
||||
public_key_destroy(public_key);
|
||||
server_key_destroy(server_key);
|
||||
|
||||
@@ -102,7 +102,8 @@ int main(void) {
|
||||
ConfigBuilder *builder;
|
||||
Config *config;
|
||||
|
||||
config_builder_default(&builder);
|
||||
config_builder_all_disabled(&builder);
|
||||
config_builder_enable_default_bool(&builder);
|
||||
config_builder_build(builder, &config);
|
||||
|
||||
ClientKey *client_key = NULL;
|
||||
|
||||
@@ -78,7 +78,7 @@ int uint256_encrypt_trivial(const ClientKey *client_key) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
int uint256_compact_public_key(const ClientKey *client_key,
|
||||
int uint256_public_key(const ClientKey *client_key,
|
||||
const CompressedCompactPublicKey *compressed_public_key) {
|
||||
int ok;
|
||||
CompactPublicKey *public_key = NULL;
|
||||
@@ -112,7 +112,7 @@ int uint256_compact_public_key(const ClientKey *client_key,
|
||||
lhs = expand_output[0];
|
||||
rhs = expand_output[1];
|
||||
// We can destroy the compact list
|
||||
// The expanded ciphertext are independent from it
|
||||
// The expanded ciphertext are independant from it
|
||||
compact_fhe_uint256_list_destroy(list);
|
||||
|
||||
ok = fhe_uint256_sub(lhs, rhs, &result);
|
||||
@@ -158,88 +158,14 @@ int uint256_compact_public_key(const ClientKey *client_key,
|
||||
return ok;
|
||||
}
|
||||
|
||||
int int32_compact_public_key(const ClientKey *client_key,
|
||||
const CompressedCompactPublicKey *compressed_public_key) {
|
||||
int ok;
|
||||
CompactPublicKey *public_key = NULL;
|
||||
FheInt32 *lhs = NULL;
|
||||
FheInt32 *rhs = NULL;
|
||||
FheInt32 *result = NULL;
|
||||
CompactFheInt32List *list = NULL;
|
||||
|
||||
int32_t result_clear = 0;
|
||||
int32_t clears[2] = {-9482394, 98712234};
|
||||
|
||||
ok = compressed_compact_public_key_decompress(compressed_public_key, &public_key);
|
||||
assert(ok == 0);
|
||||
|
||||
// Compact list example
|
||||
{
|
||||
ok = compact_fhe_int32_list_try_encrypt_with_compact_public_key_i32(&clears[0], 2,
|
||||
public_key, &list);
|
||||
assert(ok == 0);
|
||||
|
||||
size_t len = 0;
|
||||
ok = compact_fhe_int32_list_len(list, &len);
|
||||
assert(ok == 0);
|
||||
assert(len == 2);
|
||||
|
||||
FheInt32 *expand_output[2] = {NULL};
|
||||
ok = compact_fhe_int32_list_expand(list, &expand_output[0], 2);
|
||||
assert(ok == 0);
|
||||
|
||||
// transfer ownership
|
||||
lhs = expand_output[0];
|
||||
rhs = expand_output[1];
|
||||
// We can destroy the compact list
|
||||
// The expanded ciphertext are independent from it
|
||||
compact_fhe_int32_list_destroy(list);
|
||||
|
||||
ok = fhe_int32_sub(lhs, rhs, &result);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int32_decrypt(result, client_key, &result_clear);
|
||||
assert(ok == 0);
|
||||
|
||||
assert(result_clear == clears[0] - clears[1]);
|
||||
|
||||
fhe_int32_destroy(lhs);
|
||||
fhe_int32_destroy(rhs);
|
||||
fhe_int32_destroy(result);
|
||||
}
|
||||
|
||||
{
|
||||
ok = fhe_int32_try_encrypt_with_compact_public_key_i32(clears[0], public_key, &lhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int32_try_encrypt_with_compact_public_key_i32(clears[1], public_key, &rhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int32_add(lhs, rhs, &result);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = fhe_int32_decrypt(result, client_key, &result_clear);
|
||||
assert(ok == 0);
|
||||
|
||||
assert(result_clear == clears[0] + clears[1]);
|
||||
|
||||
fhe_int32_destroy(lhs);
|
||||
fhe_int32_destroy(rhs);
|
||||
fhe_int32_destroy(result);
|
||||
}
|
||||
|
||||
compact_public_key_destroy(public_key);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int ok = 0;
|
||||
{
|
||||
ConfigBuilder *builder;
|
||||
Config *config;
|
||||
|
||||
config_builder_default(&builder);
|
||||
config_builder_use_custom_parameters(&builder,
|
||||
config_builder_all_disabled(&builder);
|
||||
config_builder_enable_custom_integers(&builder,
|
||||
SHORTINT_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS);
|
||||
config_builder_build(builder, &config);
|
||||
|
||||
@@ -254,8 +180,7 @@ int main(void) {
|
||||
|
||||
uint256_client_key(client_key);
|
||||
uint256_encrypt_trivial(client_key);
|
||||
uint256_compact_public_key(client_key, compressed_public_key);
|
||||
int32_compact_public_key(client_key, compressed_public_key);
|
||||
uint256_public_key(client_key, compressed_public_key);
|
||||
|
||||
client_key_destroy(client_key);
|
||||
compressed_compact_public_key_destroy(compressed_public_key);
|
||||
@@ -266,8 +191,8 @@ int main(void) {
|
||||
ConfigBuilder *builder;
|
||||
Config *config;
|
||||
|
||||
config_builder_default(&builder);
|
||||
config_builder_use_custom_parameters(&builder,
|
||||
config_builder_all_disabled(&builder);
|
||||
config_builder_enable_custom_integers(&builder,
|
||||
SHORTINT_PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS);
|
||||
config_builder_build(builder, &config);
|
||||
|
||||
@@ -282,8 +207,7 @@ int main(void) {
|
||||
|
||||
uint256_client_key(client_key);
|
||||
uint256_encrypt_trivial(client_key);
|
||||
uint256_compact_public_key(client_key, compressed_public_key);
|
||||
int32_compact_public_key(client_key, compressed_public_key);
|
||||
uint256_public_key(client_key, compressed_public_key);
|
||||
|
||||
client_key_destroy(client_key);
|
||||
compressed_compact_public_key_destroy(compressed_public_key);
|
||||
|
||||
@@ -64,67 +64,6 @@ int uint8_public_key(const ClientKey *client_key, const PublicKey *public_key) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
int uint8_safe_serialization(const ClientKey *client_key, const ServerKey *server_key) {
|
||||
int ok;
|
||||
CompactFheUint8 *lhs = NULL;
|
||||
CompactFheUint8 *deserialized_lhs = NULL;
|
||||
CompactFheUint8 *result = NULL;
|
||||
Buffer value_buffer = {.pointer = NULL, .length = 0};
|
||||
Buffer cks_buffer = {.pointer = NULL, .length = 0};
|
||||
BufferView deser_view = {.pointer = NULL, .length = 0};
|
||||
ClientKey *deserialized_client_key = NULL;
|
||||
|
||||
const uint64_t max_serialization_size = UINT64_C(1) << UINT64_C(20);
|
||||
|
||||
uint8_t lhs_clear = 123;
|
||||
|
||||
ok = client_key_serialize(client_key, &cks_buffer);
|
||||
assert(ok == 0);
|
||||
|
||||
deser_view.pointer = cks_buffer.pointer;
|
||||
deser_view.length = cks_buffer.length;
|
||||
ok = client_key_deserialize(deser_view, &deserialized_client_key);
|
||||
assert(ok == 0);
|
||||
|
||||
struct CompactPublicKey *public_key;
|
||||
|
||||
ok = compact_public_key_new(deserialized_client_key, &public_key);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = compact_fhe_uint8_try_encrypt_with_compact_public_key_u8(lhs_clear, public_key, &lhs);
|
||||
assert(ok == 0);
|
||||
|
||||
ok = compact_fhe_uint8_safe_serialize(lhs, &value_buffer, max_serialization_size);
|
||||
assert(ok == 0);
|
||||
|
||||
deser_view.pointer = value_buffer.pointer;
|
||||
deser_view.length = value_buffer.length;
|
||||
ok = compact_fhe_uint8_safe_deserialize_conformant(deser_view, max_serialization_size, server_key,
|
||||
&deserialized_lhs);
|
||||
assert(ok == 0);
|
||||
|
||||
FheUint8 *expanded = NULL;
|
||||
|
||||
ok = compact_fhe_uint8_expand(deserialized_lhs, &expanded);
|
||||
assert(ok == 0);
|
||||
|
||||
uint8_t clear;
|
||||
ok = fhe_uint8_decrypt(expanded, deserialized_client_key, &clear);
|
||||
assert(ok == 0);
|
||||
|
||||
assert(clear == lhs_clear);
|
||||
|
||||
if (value_buffer.pointer != NULL) {
|
||||
destroy_buffer(&value_buffer);
|
||||
}
|
||||
compact_fhe_uint8_destroy(lhs);
|
||||
compact_fhe_uint8_destroy(deserialized_lhs);
|
||||
compact_fhe_uint8_destroy(result);
|
||||
fhe_uint8_destroy(expanded);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
int uint8_serialization(const ClientKey *client_key) {
|
||||
int ok;
|
||||
FheUint8 *lhs = NULL;
|
||||
@@ -203,7 +142,9 @@ int main(void) {
|
||||
ConfigBuilder *builder;
|
||||
Config *config;
|
||||
|
||||
ok = config_builder_default(&builder);
|
||||
ok = config_builder_all_disabled(&builder);
|
||||
assert(ok == 0);
|
||||
ok = config_builder_enable_default_integers(&builder);
|
||||
assert(ok == 0);
|
||||
ok = config_builder_build(builder, &config);
|
||||
assert(ok == 0);
|
||||
@@ -218,8 +159,6 @@ int main(void) {
|
||||
assert(ok == 0);
|
||||
ok = uint8_serialization(client_key);
|
||||
assert(ok == 0);
|
||||
ok = uint8_safe_serialization(client_key, server_key);
|
||||
assert(ok == 0);
|
||||
ok = uint8_compressed(client_key);
|
||||
assert(ok == 0);
|
||||
|
||||
@@ -240,7 +179,9 @@ int main(void) {
|
||||
ConfigBuilder *builder;
|
||||
Config *config;
|
||||
|
||||
ok = config_builder_default_with_small_encryption(&builder);
|
||||
ok = config_builder_all_disabled(&builder);
|
||||
assert(ok == 0);
|
||||
ok = config_builder_enable_default_integers_small(&builder);
|
||||
assert(ok == 0);
|
||||
ok = config_builder_build(builder, &config);
|
||||
assert(ok == 0);
|
||||
|
||||
@@ -114,15 +114,14 @@ bitflags = false
|
||||
############## Options for How Your Rust library Should Be Parsed ##############
|
||||
|
||||
[parse]
|
||||
parse_deps = false
|
||||
include = []
|
||||
parse_deps = true
|
||||
include = ["tfhe"]
|
||||
exclude = []
|
||||
clean = false
|
||||
extra_bindings = []
|
||||
|
||||
|
||||
[parse.expand]
|
||||
# Managed by build.rs to programmatically select features when required
|
||||
crates = []
|
||||
all_features = false
|
||||
default_features = true
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
## Getting Started
|
||||
* [Installation](getting_started/installation.md)
|
||||
* [Quick Start](getting_started/quick_start.md)
|
||||
* [Types & Operations](getting_started/operations.md)
|
||||
* [Operations](getting_started/operations.md)
|
||||
* [Benchmarks](getting_started/benchmarks.md)
|
||||
* [Security and Cryptography](getting_started/security_and_cryptography.md)
|
||||
|
||||
## Tutorials
|
||||
* [Homomorphic Parity Bit](tutorials/parity_bit.md)
|
||||
* [Homomorphic Case Changing on Ascii String](tutorials/ascii_fhe_string.md)
|
||||
* [Homomorphic Case Changing on Latin String](tutorials/latin_fhe_string.md)
|
||||
|
||||
## How To
|
||||
* [Configure Rust](how_to/rust_configuration.md)
|
||||
@@ -56,3 +56,4 @@
|
||||
|
||||
## API references
|
||||
* [docs.rs](https://docs.rs/tfhe/)
|
||||
|
||||
|
||||
@@ -102,23 +102,25 @@ for buy_order in buy_orders.iter_mut() {
|
||||
#### The complete algorithm in plain Rust:
|
||||
|
||||
```rust
|
||||
fn fill_orders(orders: &mut [u16], total_volume: u16) {
|
||||
let mut volume_left_to_transact = total_volume;
|
||||
for order in orders {
|
||||
let filled_amount = std::cmp::min(volume_left_to_transact, *order);
|
||||
*order = filled_amount;
|
||||
volume_left_to_transact -= filled_amount;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn volume_match(sell_orders: &mut [u16], buy_orders: &mut [u16]) {
|
||||
fn volume_match_plain(sell_orders: &mut Vec<u16>, buy_orders: &mut Vec<u16>) {
|
||||
let total_sell_volume: u16 = sell_orders.iter().sum();
|
||||
let total_buy_volume: u16 = buy_orders.iter().sum();
|
||||
|
||||
let total_volume = std::cmp::min(total_buy_volume, total_sell_volume);
|
||||
|
||||
fill_orders(sell_orders, total_volume);
|
||||
fill_orders(buy_orders, total_volume);
|
||||
let mut volume_left_to_transact = total_volume;
|
||||
for sell_order in sell_orders.iter_mut() {
|
||||
let filled_amount = std::cmp::min(volume_left_to_transact, *sell_order);
|
||||
*sell_order = filled_amount;
|
||||
volume_left_to_transact -= filled_amount;
|
||||
}
|
||||
|
||||
let mut volume_left_to_transact = total_volume;
|
||||
for buy_order in buy_orders.iter_mut() {
|
||||
let filled_amount = std::cmp::min(volume_left_to_transact, *buy_order);
|
||||
*buy_order = filled_amount;
|
||||
volume_left_to_transact -= filled_amount;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -153,17 +155,15 @@ Now, we can start implementing the algorithm with FHE:
|
||||
1. Calculate the total sell volume and the total buy volume.
|
||||
|
||||
```rust
|
||||
fn vector_sum(server_key: &ServerKey, orders: &mut [RadixCiphertext]) -> RadixCiphertext {
|
||||
let mut total_volume = server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS);
|
||||
for order in orders {
|
||||
server_key.smart_add_assign(&mut total_volume, order);
|
||||
}
|
||||
total_volume
|
||||
let mut total_sell_volume = server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS);
|
||||
for sell_order in sell_orders.iter_mut() {
|
||||
server_key.smart_add_assign(&mut total_sell_volume, sell_order);
|
||||
}
|
||||
|
||||
let mut total_sell_volume = vector_sum(server_key, sell_orders);
|
||||
let mut total_buy_volume = vector_sum(server_key, buy_orders);
|
||||
|
||||
let mut total_buy_volume = server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS);
|
||||
for buy_order in buy_orders.iter_mut() {
|
||||
server_key.smart_add_assign(&mut total_buy_volume, buy_order);
|
||||
}
|
||||
```
|
||||
|
||||
2. Find the total volume that will be transacted by taking the minimum of the total sell volume and the total buy
|
||||
@@ -177,21 +177,17 @@ let total_volume = server_key.smart_min(&mut total_sell_volume, &mut total_buy_v
|
||||
reduce code duplication since the code for filling buy orders and sell orders are the same.
|
||||
|
||||
```rust
|
||||
fn fill_orders(
|
||||
server_key: &ServerKey,
|
||||
orders: &mut [RadixCiphertext],
|
||||
total_volume: RadixCiphertext,
|
||||
) {
|
||||
let mut volume_left_to_transact = total_volume;
|
||||
for order in orders {
|
||||
let mut filled_amount = server_key.smart_min(&mut volume_left_to_transact, order);
|
||||
let fill_orders = |orders: &mut [RadixCiphertext]| {
|
||||
let mut volume_left_to_transact = total_volume.clone();
|
||||
for mut order in orders.iter_mut() {
|
||||
let mut filled_amount = server_key.smart_min(&mut volume_left_to_transact, &mut order);
|
||||
server_key.smart_sub_assign(&mut volume_left_to_transact, &mut filled_amount);
|
||||
*order = filled_amount;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fill_orders(server_key, sell_orders, total_volume.clone());
|
||||
fill_orders(server_key, buy_orders, total_volume);
|
||||
fill_orders(sell_orders);
|
||||
fill_orders(buy_orders);
|
||||
```
|
||||
|
||||
#### The complete algorithm in TFHE-rs:
|
||||
@@ -199,40 +195,36 @@ fill_orders(server_key, buy_orders, total_volume);
|
||||
```rust
|
||||
const NUMBER_OF_BLOCKS: usize = 8;
|
||||
|
||||
fn vector_sum(server_key: &ServerKey, orders: &mut [RadixCiphertext]) -> RadixCiphertext {
|
||||
let mut total_volume = server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS);
|
||||
for order in orders {
|
||||
server_key.smart_add_assign(&mut total_volume, order);
|
||||
}
|
||||
total_volume
|
||||
}
|
||||
|
||||
fn fill_orders(
|
||||
server_key: &ServerKey,
|
||||
orders: &mut [RadixCiphertext],
|
||||
total_volume: RadixCiphertext,
|
||||
) {
|
||||
let mut volume_left_to_transact = total_volume;
|
||||
for order in orders {
|
||||
let mut filled_amount = server_key.smart_min(&mut volume_left_to_transact, order);
|
||||
server_key.smart_sub_assign(&mut volume_left_to_transact, &mut filled_amount);
|
||||
*order = filled_amount;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn volume_match(
|
||||
fn volume_match_fhe(
|
||||
sell_orders: &mut [RadixCiphertext],
|
||||
buy_orders: &mut [RadixCiphertext],
|
||||
server_key: &ServerKey,
|
||||
) {
|
||||
let mut total_sell_volume = vector_sum(server_key, sell_orders);
|
||||
let mut total_buy_volume = vector_sum(server_key, buy_orders);
|
||||
let mut total_sell_volume = server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS);
|
||||
for sell_order in sell_orders.iter_mut() {
|
||||
server_key.smart_add_assign(&mut total_sell_volume, sell_order);
|
||||
}
|
||||
|
||||
let mut total_buy_volume = server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS);
|
||||
for buy_order in buy_orders.iter_mut() {
|
||||
server_key.smart_add_assign(&mut total_buy_volume, buy_order);
|
||||
}
|
||||
|
||||
let total_volume = server_key.smart_min(&mut total_sell_volume, &mut total_buy_volume);
|
||||
|
||||
fill_orders(server_key, sell_orders, total_volume.clone());
|
||||
fill_orders(server_key, buy_orders, total_volume);
|
||||
let fill_orders = |orders: &mut [RadixCiphertext]| {
|
||||
let mut volume_left_to_transact = total_volume.clone();
|
||||
for mut order in orders.iter_mut() {
|
||||
let mut filled_amount = server_key.smart_min(&mut volume_left_to_transact, &mut order);
|
||||
server_key.smart_sub_assign(&mut volume_left_to_transact, &mut filled_amount);
|
||||
*order = filled_amount;
|
||||
}
|
||||
};
|
||||
|
||||
fill_orders(sell_orders);
|
||||
fill_orders(buy_orders);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Optimizing the implementation
|
||||
@@ -243,73 +235,63 @@ pub fn volume_match(
|
||||
|
||||
* We can parallelize vector sum with Rayon and `reduce` operation.
|
||||
```rust
|
||||
fn vector_sum(server_key: &ServerKey, orders: Vec<RadixCiphertext>) -> RadixCiphertext {
|
||||
orders.into_par_iter().reduce(
|
||||
let parallel_vector_sum = |vec: &mut [RadixCiphertext]| {
|
||||
vec.to_vec().into_par_iter().reduce(
|
||||
|| server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS),
|
||||
|mut acc: RadixCiphertext, mut ele: RadixCiphertext| {
|
||||
|mut acc: RadixCiphertext, mut ele: RadixCiphertext| {
|
||||
server_key.smart_add_parallelized(&mut acc, &mut ele)
|
||||
},
|
||||
)
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
* We can run vector summation on `buy_orders` and `sell_orders` in parallel since these operations do not depend on each other.
|
||||
```rust
|
||||
let (mut total_sell_volume, mut total_buy_volume) = rayon::join(
|
||||
|| vector_sum(server_key, sell_orders.to_owned()),
|
||||
|| vector_sum(server_key, buy_orders.to_owned()),
|
||||
);
|
||||
let (mut total_sell_volume, mut total_buy_volume) =
|
||||
rayon::join(|| vector_sum(sell_orders), || vector_sum(buy_orders));
|
||||
```
|
||||
|
||||
* We can match sell and buy orders in parallel since the matching does not depend on each other.
|
||||
```rust
|
||||
rayon::join(
|
||||
|| fill_orders(server_key, sell_orders, total_volume.clone()),
|
||||
|| fill_orders(server_key, buy_orders, total_volume.clone()),
|
||||
);
|
||||
rayon::join(|| fill_orders(sell_orders), || fill_orders(buy_orders));
|
||||
```
|
||||
|
||||
#### Optimized algorithm
|
||||
```rust
|
||||
fn vector_sum(server_key: &ServerKey, orders: Vec<RadixCiphertext>) -> RadixCiphertext {
|
||||
orders.into_par_iter().reduce(
|
||||
|| server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS),
|
||||
|mut acc: RadixCiphertext, mut ele: RadixCiphertext| {
|
||||
server_key.smart_add_parallelized(&mut acc, &mut ele)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn fill_orders(
|
||||
server_key: &ServerKey,
|
||||
orders: &mut [RadixCiphertext],
|
||||
total_volume: RadixCiphertext,
|
||||
) {
|
||||
let mut volume_left_to_transact = total_volume;
|
||||
for order in orders {
|
||||
let mut filled_amount =
|
||||
server_key.smart_min_parallelized(&mut volume_left_to_transact, order);
|
||||
server_key.smart_sub_assign_parallelized(&mut volume_left_to_transact, &mut filled_amount);
|
||||
*order = filled_amount;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn volume_match(
|
||||
fn volume_match_fhe_parallelized(
|
||||
sell_orders: &mut [RadixCiphertext],
|
||||
buy_orders: &mut [RadixCiphertext],
|
||||
server_key: &ServerKey,
|
||||
) {
|
||||
let parallel_vector_sum = |vec: &mut [RadixCiphertext]| {
|
||||
vec.to_vec().into_par_iter().reduce(
|
||||
|| server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS),
|
||||
|mut acc: RadixCiphertext, mut ele: RadixCiphertext| {
|
||||
server_key.smart_add_parallelized(&mut acc, &mut ele)
|
||||
},
|
||||
)
|
||||
};
|
||||
|
||||
let (mut total_sell_volume, mut total_buy_volume) = rayon::join(
|
||||
|| vector_sum(server_key, sell_orders.to_owned()),
|
||||
|| vector_sum(server_key, buy_orders.to_owned()),
|
||||
|| parallel_vector_sum(sell_orders),
|
||||
|| parallel_vector_sum(buy_orders),
|
||||
);
|
||||
|
||||
let total_volume =
|
||||
server_key.smart_min_parallelized(&mut total_sell_volume, &mut total_buy_volume);
|
||||
rayon::join(
|
||||
|| fill_orders(server_key, sell_orders, total_volume.clone()),
|
||||
|| fill_orders(server_key, buy_orders, total_volume.clone()),
|
||||
);
|
||||
|
||||
let fill_orders = |orders: &mut [RadixCiphertext]| {
|
||||
let mut volume_left_to_transact = total_volume.clone();
|
||||
for mut order in orders.iter_mut() {
|
||||
let mut filled_amount =
|
||||
server_key.smart_min_parallelized(&mut volume_left_to_transact, &mut order);
|
||||
server_key
|
||||
.smart_sub_assign_parallelized(&mut volume_left_to_transact, &mut filled_amount);
|
||||
*order = filled_amount;
|
||||
}
|
||||
};
|
||||
|
||||
rayon::join(|| fill_orders(sell_orders), || fill_orders(buy_orders));
|
||||
}
|
||||
```
|
||||
|
||||
@@ -330,19 +312,14 @@ We will call the new list the "prefix sum" of the array.
|
||||
|
||||
The new version for the plain `fill_orders` is as follows:
|
||||
```rust
|
||||
fn fill_orders(total_orders: u16, orders: &mut [u16], prefix_sum_arr: &[u16]) {
|
||||
let fill_orders = |orders: &mut [u64], prefix_sum: &[u64], total_orders: u64|{
|
||||
orders.iter().for_each(|order : &mut u64| {
|
||||
let previous_prefix_sum = if i == 0 { 0 } else { prefix_sum_arr[i - 1] };
|
||||
|
||||
let diff = total_orders as i64 - previous_prefix_sum as i64;
|
||||
|
||||
if (diff < 0) {
|
||||
*order = 0;
|
||||
} else if diff < order {
|
||||
*order = diff as u16;
|
||||
} else {
|
||||
// *order = *order;
|
||||
if (total_orders >= prefix_sum[i]) {
|
||||
continue;
|
||||
} else if total_orders >= prefix_sum.get(i-1).unwrap_or(0) {
|
||||
*order = total_orders - prefix_sum.get(i-1).unwrap_or(0);
|
||||
} else {
|
||||
*order = 0;
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -351,15 +328,11 @@ fn fill_orders(total_orders: u16, orders: &mut [u16], prefix_sum_arr: &[u16]) {
|
||||
To write this new function we need transform the conditional code into a mathematical expression since FHE does not support conditional operations.
|
||||
```rust
|
||||
|
||||
fn fill_orders(total_orders: u16, orders: &mut [u16], prefix_sum_arr: &[u16]) {
|
||||
for (i, order) in orders.iter_mut().enumerate() {
|
||||
let previous_prefix_sum = if i == 0 { 0 } else { prefix_sum_arr[i - 1] };
|
||||
|
||||
*order = (total_orders as i64 - previous_prefix_sum as i64)
|
||||
.max(0)
|
||||
.min(*order as i64) as u16;
|
||||
let fill_orders = |orders: &mut [u64], prefix_sum: &[u64], total_orders: u64| {
|
||||
orders.iter().for_each(|order| : &mut){
|
||||
*order = *order + ((total_orders >= prefix_sum - std::cmp::min(total_orders, prefix_sum.get(i - 1).unwrap_or(&0).clone()) - *order);
|
||||
}
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
New `fill_order` function requires a prefix sum array. We are going to calculate this prefix sum array in parallel
|
||||
@@ -372,129 +345,108 @@ So we modify how the algorithm is implemented, but we don't change the algorithm
|
||||
|
||||
Here is the modified version of the algorithm in TFHE-rs:
|
||||
```rust
|
||||
fn compute_prefix_sum(server_key: &ServerKey, arr: &[RadixCiphertext]) -> Vec<RadixCiphertext> {
|
||||
if arr.is_empty() {
|
||||
return arr.to_vec();
|
||||
}
|
||||
let mut prefix_sum: Vec<RadixCiphertext> = (0..arr.len().next_power_of_two())
|
||||
.into_par_iter()
|
||||
.map(|i| {
|
||||
if i < arr.len() {
|
||||
arr[i].clone()
|
||||
} else {
|
||||
server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS)
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
for d in 0..prefix_sum.len().ilog2() {
|
||||
prefix_sum
|
||||
.par_chunks_exact_mut(2_usize.pow(d + 1))
|
||||
.for_each(move |chunk| {
|
||||
let length = chunk.len();
|
||||
let mut left = chunk.get((length - 1) / 2).unwrap().clone();
|
||||
server_key.smart_add_assign_parallelized(chunk.last_mut().unwrap(), &mut left)
|
||||
});
|
||||
}
|
||||
let last = prefix_sum.last().unwrap().clone();
|
||||
*prefix_sum.last_mut().unwrap() = server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS);
|
||||
for d in (0..prefix_sum.len().ilog2()).rev() {
|
||||
prefix_sum
|
||||
.par_chunks_exact_mut(2_usize.pow(d + 1))
|
||||
.for_each(move |chunk| {
|
||||
let length = chunk.len();
|
||||
let temp = chunk.last().unwrap().clone();
|
||||
let mut mid = chunk.get((length - 1) / 2).unwrap().clone();
|
||||
server_key.smart_add_assign_parallelized(chunk.last_mut().unwrap(), &mut mid);
|
||||
chunk[(length - 1) / 2] = temp;
|
||||
});
|
||||
}
|
||||
prefix_sum.push(last);
|
||||
prefix_sum[1..=arr.len()].to_vec()
|
||||
}
|
||||
|
||||
fn fill_orders(
|
||||
server_key: &ServerKey,
|
||||
total_orders: &RadixCiphertext,
|
||||
orders: &mut [RadixCiphertext],
|
||||
prefix_sum_arr: &[RadixCiphertext],
|
||||
) {
|
||||
orders
|
||||
.into_par_iter()
|
||||
.enumerate()
|
||||
.for_each(move |(i, order)| {
|
||||
// (total_orders - previous_prefix_sum).max(0)
|
||||
let mut diff = if i == 0 {
|
||||
total_orders.clone()
|
||||
} else {
|
||||
let previous_prefix_sum = &prefix_sum_arr[i - 1];
|
||||
|
||||
// total_orders - previous_prefix_sum
|
||||
let mut diff = server_key.smart_sub_parallelized(
|
||||
&mut total_orders.clone(),
|
||||
&mut previous_prefix_sum.clone(),
|
||||
);
|
||||
|
||||
// total_orders > prefix_sum
|
||||
let mut cond = server_key.smart_gt_parallelized(
|
||||
&mut total_orders.clone(),
|
||||
&mut previous_prefix_sum.clone(),
|
||||
);
|
||||
|
||||
// (total_orders - previous_prefix_sum) * (total_orders > previous_prefix_sum)
|
||||
// = (total_orders - previous_prefix_sum).max(0)
|
||||
server_key.smart_mul_parallelized(&mut cond, &mut diff)
|
||||
};
|
||||
|
||||
// (total_orders - previous_prefix_sum).max(0).min(*order);
|
||||
*order = server_key.smart_min_parallelized(&mut diff, order);
|
||||
});
|
||||
}
|
||||
|
||||
/// FHE implementation of the volume matching algorithm.
|
||||
///
|
||||
/// In this function, the implemented algorithm is modified to utilize more concurrency.
|
||||
///
|
||||
/// Matches the given encrypted [sell_orders] with encrypted [buy_orders] using the given
|
||||
/// [server_key]. The amount of the orders that are successfully filled is written over the original
|
||||
/// order count.
|
||||
pub fn volume_match(
|
||||
fn volume_match_fhe_modified(
|
||||
sell_orders: &mut [RadixCiphertext],
|
||||
buy_orders: &mut [RadixCiphertext],
|
||||
server_key: &ServerKey,
|
||||
) {
|
||||
let compute_prefix_sum = |arr: &[RadixCiphertext]| {
|
||||
if arr.is_empty() {
|
||||
return arr.to_vec();
|
||||
}
|
||||
let mut prefix_sum: Vec<RadixCiphertext> = (0..arr.len().next_power_of_two())
|
||||
.into_par_iter()
|
||||
.map(|i| {
|
||||
if i < arr.len() {
|
||||
arr[i].clone()
|
||||
} else {
|
||||
server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS)
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
// Up sweep
|
||||
for d in 0..(prefix_sum.len().ilog2() as u32) {
|
||||
prefix_sum
|
||||
.par_chunks_exact_mut(2_usize.pow(d + 1))
|
||||
.for_each(move |chunk| {
|
||||
let length = chunk.len();
|
||||
let mut left = chunk.get((length - 1) / 2).unwrap().clone();
|
||||
server_key.smart_add_assign_parallelized(chunk.last_mut().unwrap(), &mut left)
|
||||
});
|
||||
}
|
||||
// Down sweep
|
||||
let last = prefix_sum.last().unwrap().clone();
|
||||
*prefix_sum.last_mut().unwrap() = server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS);
|
||||
for d in (0..(prefix_sum.len().ilog2() as u32)).rev() {
|
||||
prefix_sum
|
||||
.par_chunks_exact_mut(2_usize.pow(d + 1))
|
||||
.for_each(move |chunk| {
|
||||
let length = chunk.len();
|
||||
let t = chunk.last().unwrap().clone();
|
||||
let mut left = chunk.get((length - 1) / 2).unwrap().clone();
|
||||
server_key.smart_add_assign_parallelized(chunk.last_mut().unwrap(), &mut left);
|
||||
chunk[(length - 1) / 2] = t;
|
||||
});
|
||||
}
|
||||
prefix_sum.push(last);
|
||||
prefix_sum[1..=arr.len()].to_vec()
|
||||
};
|
||||
|
||||
println!("Creating prefix sum arrays...");
|
||||
let time = Instant::now();
|
||||
let (prefix_sum_sell_orders, prefix_sum_buy_orders) = rayon::join(
|
||||
|| compute_prefix_sum(server_key, sell_orders),
|
||||
|| compute_prefix_sum(server_key, buy_orders),
|
||||
|| compute_prefix_sum(sell_orders),
|
||||
|| compute_prefix_sum(buy_orders),
|
||||
);
|
||||
println!("Created prefix sum arrays in {:?}", time.elapsed());
|
||||
|
||||
let zero = server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS);
|
||||
let fill_orders = |total_orders: &RadixCiphertext,
|
||||
orders: &mut [RadixCiphertext],
|
||||
prefix_sum_arr: &[RadixCiphertext]| {
|
||||
orders
|
||||
.into_par_iter()
|
||||
.enumerate()
|
||||
.for_each(move |(i, order)| {
|
||||
server_key.smart_add_assign_parallelized(
|
||||
order,
|
||||
&mut server_key.smart_mul_parallelized(
|
||||
&mut server_key
|
||||
.smart_ge_parallelized(&mut order.clone(), &mut total_orders.clone()),
|
||||
&mut server_key.smart_sub_parallelized(
|
||||
&mut server_key.smart_sub_parallelized(
|
||||
&mut total_orders.clone(),
|
||||
&mut server_key.smart_min_parallelized(
|
||||
&mut total_orders.clone(),
|
||||
&mut prefix_sum_arr
|
||||
.get(i - 1)
|
||||
.unwrap_or(
|
||||
&server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS),
|
||||
)
|
||||
.clone(),
|
||||
),
|
||||
),
|
||||
&mut order.clone(),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
let total_buy_orders = prefix_sum_buy_orders.last().unwrap_or(&zero);
|
||||
let total_buy_orders = &mut prefix_sum_buy_orders
|
||||
.last()
|
||||
.unwrap_or(&server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS))
|
||||
.clone();
|
||||
|
||||
let total_sell_orders = prefix_sum_sell_orders.last().unwrap_or(&zero);
|
||||
let total_sell_orders = &mut prefix_sum_sell_orders
|
||||
.last()
|
||||
.unwrap_or(&server_key.create_trivial_zero_radix(NUMBER_OF_BLOCKS))
|
||||
.clone();
|
||||
|
||||
println!("Matching orders...");
|
||||
let time = Instant::now();
|
||||
rayon::join(
|
||||
|| {
|
||||
fill_orders(
|
||||
server_key,
|
||||
total_sell_orders,
|
||||
buy_orders,
|
||||
&prefix_sum_buy_orders,
|
||||
)
|
||||
},
|
||||
|| {
|
||||
fill_orders(
|
||||
server_key,
|
||||
total_buy_orders,
|
||||
sell_orders,
|
||||
&prefix_sum_sell_orders,
|
||||
)
|
||||
},
|
||||
|| fill_orders(total_sell_orders, buy_orders, &prefix_sum_buy_orders),
|
||||
|| fill_orders(total_buy_orders, sell_orders, &prefix_sum_sell_orders),
|
||||
);
|
||||
println!("Matched orders in {:?}", time.elapsed());
|
||||
}
|
||||
|
||||
@@ -504,7 +504,7 @@ Pattern | Description
|
||||
`/^abc$/` | Matches with content that equals exactly `abc` (case sensitive)
|
||||
`/^abc$/i` | Matches with content that equals `abc` (case insensitive)
|
||||
`/abc/` | Matches with content that contains somewhere `abc`
|
||||
`/ab?c/` | Matches with content that contains somewhere `abc` or somewhere `ab`
|
||||
`/ab?c/` | Matches with content that contains somewhere `abc` or somwhere `ab`
|
||||
`/^ab*c$/` | For example, matches with: `ac`, `abc`, `abbbbc`
|
||||
`/^[a-c]b\|cd$/` | Matches with: `ab`, `bb`, `cb`, `cd`
|
||||
`/^[a-c]b\|cd$/i` | Matches with: `ab`, `Ab`, `aB`, ..., `cD`, `CD`
|
||||
|
||||
@@ -136,11 +136,7 @@ fn sha256(padded_input: Vec<bool>) -> [bool; 256] {
|
||||
|
||||
The key idea is that we can replace each bit of ```padded_input``` with a Fully Homomorphic Encryption of the same bit value, and operate over the encrypted values using homomorphic operations. To achieve this we need to change the function signatures and deal with the borrowing rules of the Ciphertext type (which represents an encrypted bit) but the structure of the sha256 function remains the same. The part of the code that requires more consideration is the implementation of the sha256 operations, since they will use homomorphic boolean operations internally.
|
||||
|
||||
Homomorphic operations are really expensive, so we have to remove their unnecessary use and maximize parallelization in order to speed up the program. To simplify our code we use the Rayon crate which provides parallel iterators and efficiently manages threads.
|
||||
|
||||
The final code is available at https://github.com/zama-ai/tfhe-rs/tree/main/tfhe/examples/sha256_bool
|
||||
|
||||
Let's now take a look at each sha256 operation!
|
||||
Homomorphic operations are really expensive, so we have to remove their unnecessary use and maximize parallelization in order to speed up the program. To simplify our code we use the Rayon crate which provides parallel iterators and efficiently manages threads. Let's now take a look at each sha256 operation!
|
||||
|
||||
#### Rotate Right and Shift Right
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ Welcome to this tutorial about `TFHE-rs` `core_crypto` module.
|
||||
To use `TFHE-rs`, it first has to be added as a dependency in the `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
tfhe = { version = "0.5.0", features = [ "x86_64-unix" ] }
|
||||
tfhe = { version = "0.4.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.
|
||||
@@ -19,19 +19,19 @@ For Apple Silicon, the `aarch64-unix` or `aarch64` feature should be enabled. `a
|
||||
In short: For `x86_64`-based machines running Unix-like OSes:
|
||||
|
||||
```toml
|
||||
tfhe = { version = "0.5.0", features = ["x86_64-unix"] }
|
||||
tfhe = { version = "0.4.0", features = ["x86_64-unix"] }
|
||||
```
|
||||
|
||||
For Apple Silicon or aarch64-based machines running Unix-like OSes:
|
||||
|
||||
```toml
|
||||
tfhe = { version = "0.5.0", features = ["aarch64-unix"] }
|
||||
tfhe = { version = "0.4.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.5.0", features = ["x86_64"] }
|
||||
tfhe = { version = "0.4.0", features = ["x86_64"] }
|
||||
```
|
||||
|
||||
### Commented code to double a 2-bit message in a leveled fashion and using a PBS with the `core_crypto` module.
|
||||
@@ -249,7 +249,7 @@ pub fn main() {
|
||||
println!("Checking result...");
|
||||
assert_eq!(6, pbs_multiplication_result);
|
||||
println!(
|
||||
"Multiplication via PBS result is correct! Expected 6, got {pbs_multiplication_result}"
|
||||
"Mulitplication via PBS result is correct! Expected 6, got {pbs_multiplication_result}"
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -35,7 +35,7 @@ fn main() {
|
||||
Note that both the `client_key` and `server_key` implement the `Serialize` and `Deserialize` traits. This way you can use any compatible serializer to store/send the data. To store the `server_key` in a binary file, you can use the `bincode` library:
|
||||
|
||||
```rust
|
||||
use std::fs::{File, create_dir_all};
|
||||
use std::fs::File;
|
||||
use std::io::{Write, Read};
|
||||
use tfhe::boolean::prelude::*;
|
||||
|
||||
@@ -49,13 +49,7 @@ fn main() {
|
||||
// We serialize the server key to bytes, and store them in a file:
|
||||
let encoded: Vec<u8> = bincode::serialize(&server_key).unwrap();
|
||||
|
||||
// Create a tmp dir with the current user name to avoid cluttering the /tmp dir
|
||||
let user = std::env::var("USER").unwrap_or_else(|_| "unknown_user".to_string());
|
||||
let tmp_dir_for_user = &format!("/tmp/{user}");
|
||||
|
||||
create_dir_all(tmp_dir_for_user).unwrap();
|
||||
|
||||
let server_key_file = &format!("{tmp_dir_for_user}/tutorial_server_key.bin");
|
||||
let server_key_file = "/tmp/tutorial_server_key.bin";
|
||||
|
||||
// We write the server key to a file:
|
||||
let mut file = File::create(server_key_file)
|
||||
@@ -92,7 +86,7 @@ fn main() {
|
||||
// Don't consider the following line; you should follow the procedure above.
|
||||
let (client_key, _) = gen_keys();
|
||||
|
||||
//---------------------------- CLIENT SIDE
|
||||
//---------------------------- SERVER SIDE
|
||||
|
||||
// We use the client key to encrypt the messages:
|
||||
let ct_1 = client_key.encrypt(true);
|
||||
@@ -110,8 +104,7 @@ fn main() {
|
||||
|
||||
## Encrypting inputs using a public key
|
||||
|
||||
Anyone (the server or a third party) with the public key can also encrypt some (or all) of the inputs.
|
||||
The public key can only be used to encrypt, not to decrypt.
|
||||
Once the server key is available on the **server side**, it is possible to perform some homomorphic computations. The client simply needs to encrypt some data and send it to the server. Again, the `Ciphertext` type implements the `Serialize` and the `Deserialize` traits, so that any serializer and communication tool suiting your use case can be utilized:
|
||||
|
||||
```rust
|
||||
use tfhe::boolean::prelude::*;
|
||||
@@ -121,18 +114,18 @@ fn main() {
|
||||
let (client_key, _) = gen_keys();
|
||||
let public_key = PublicKey::new(&client_key);
|
||||
|
||||
//---------------------------- SERVER or THIRD_PARTY SIDE
|
||||
//---------------------------- SERVER SIDE
|
||||
|
||||
// We use the public key to encrypt the messages:
|
||||
let ct_1 = public_key.encrypt(true);
|
||||
let ct_2 = public_key.encrypt(false);
|
||||
|
||||
// We serialize the ciphertexts (if not on the server already):
|
||||
// We serialize the ciphertexts:
|
||||
let encoded_1: Vec<u8> = bincode::serialize(&ct_1).unwrap();
|
||||
let encoded_2: Vec<u8> = bincode::serialize(&ct_2).unwrap();
|
||||
|
||||
// ...
|
||||
// And we send them to the server to be deserialized (if not on the server already)
|
||||
// And we send them to the server somehow
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
@@ -8,7 +8,7 @@ Here is an example using the `bincode` serialization library, which serializes t
|
||||
binary format:
|
||||
|
||||
```rust
|
||||
use std::fs::{File, create_dir_all};
|
||||
use std::fs::File;
|
||||
use std::io::{Write, Read};
|
||||
use tfhe::boolean::prelude::*;
|
||||
|
||||
@@ -20,14 +20,8 @@ fn main() {
|
||||
let encoded_server_key: Vec<u8> = bincode::serialize(&server_key).unwrap();
|
||||
let encoded_client_key: Vec<u8> = bincode::serialize(&client_key).unwrap();
|
||||
|
||||
// Create a tmp dir with the current user name to avoid cluttering the /tmp dir
|
||||
let user = std::env::var("USER").unwrap_or_else(|_| "unknown_user".to_string());
|
||||
let tmp_dir_for_user = &format!("/tmp/{user}");
|
||||
|
||||
create_dir_all(tmp_dir_for_user).unwrap();
|
||||
|
||||
let server_key_file = &format!("{tmp_dir_for_user}/ser_example_server_key.bin");
|
||||
let client_key_file = &format!("{tmp_dir_for_user}/ser_example_client_key.bin");
|
||||
let server_key_file = "/tmp/ser_example_server_key.bin";
|
||||
let client_key_file = "/tmp/ser_example_client_key.bin";
|
||||
|
||||
// We write the keys to files:
|
||||
let mut file = File::create(server_key_file)
|
||||
|
||||
@@ -17,7 +17,7 @@ This crate implements two ways to represent an integer:
|
||||
|
||||
The first possibility to represent a large integer is to use a Radix-based decomposition on the plaintexts. Let $$B \in \mathbb{N}$$ be a basis such that the size of $$B$$ is smaller than (or equal to) 4 bits. Then, an integer $$m \in \mathbb{N}$$ can be written as $$m = m_0 + m_1*B + m_2*B^2 + ...$$, where each $$m_i$$ is strictly smaller than $$B$$. Each $$m_i$$ is then independently encrypted. In the end, an Integer ciphertext is defined as a set of shortint ciphertexts.
|
||||
|
||||
The definition of an integer requires a basis and a number of blocks. These parameters are chosen at key generation. Below, the keys are dedicated to integers encrypting messages over 8 bits, using a basis over 2 bits (i.e., $$B=2^2$$) and 4 blocks.
|
||||
The definition of an integer requires a basis and a number of blocks. This is done at key generation. Below, the keys are dedicated to unsigned integers encrypting messages over 8 bits, using a basis over 2 bits (i.e., $$B=2^2$$) and 4 blocks.
|
||||
|
||||
```rust
|
||||
use tfhe::integer::gen_keys_radix;
|
||||
@@ -93,10 +93,6 @@ Each operation may come in different 'flavors':
|
||||
|
||||
Not all operations have these 4 flavors, as some of them are implemented in a way that the operation is always possible without ever exceeding the plaintext space capacity.
|
||||
|
||||
{% hint style="info" %}
|
||||
If you don't know which flavor to use, you should use the `default` one.
|
||||
{% endhint %}
|
||||
|
||||
## How to use each operation type
|
||||
|
||||
Let's try to do a circuit evaluation using the different flavors of already introduced operations. For a very small circuit, the `unchecked` flavor may be enough to do the computation correctly. Otherwise, `checked` and `smart` are the best options.
|
||||
@@ -162,17 +158,16 @@ fn main() {
|
||||
let ct_2 = client_key.encrypt(msg2);
|
||||
let ct_3 = client_key.encrypt(msg3);
|
||||
|
||||
server_key.checked_small_scalar_mul_assign(&mut ct_1, scalar).unwrap();
|
||||
|
||||
server_key.checked_sub_assign(&mut ct_1, &ct_2).unwrap();
|
||||
|
||||
let result = server_key.checked_add_assign(&mut ct_1, &ct_3);
|
||||
let result = server_key.checked_small_scalar_mul_assign(&mut ct_1, scalar);
|
||||
assert!(result.is_ok());
|
||||
|
||||
let result = server_key.checked_sub_assign(&mut ct_1, &ct_2);
|
||||
assert!(result.is_err());
|
||||
|
||||
// We use the client key to decrypt the output of the circuit:
|
||||
// Only the scalar multiplication could be done
|
||||
let output: u64 = client_key.decrypt(&ct_1);
|
||||
assert_eq!(output, ((msg1 * scalar) - msg2) % modulus as u64);
|
||||
assert_eq!(output, (msg1 * scalar) % modulus as u64);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -213,14 +208,6 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
{% hint style="warning" %}
|
||||
You must avoid cloning the inputs when calling `smart` operations to preserve performance. For instance, you SHOULD NOT have these kind of patterns in the code:
|
||||
```Rust
|
||||
sks.smart_add(&mut a.clone(), &mut b.clone());
|
||||
```
|
||||
{% endhint %}
|
||||
|
||||
|
||||
The main advantage of the default flavor is to ensure predictable timings, as long as only this kind of operation is used. Only the parallelized version of the operations is provided.
|
||||
|
||||
{% hint style="warning" %}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Tutorial
|
||||
|
||||
`tfhe::integer` is dedicated to integers smaller than 256 bits. The steps to homomorphically evaluate an integer circuit are described here.
|
||||
`tfhe::integer` is dedicated to unsigned integers smaller than 256 bits. The steps to homomorphically evaluate an integer circuit are described here.
|
||||
|
||||
## Key Types
|
||||
|
||||
@@ -25,7 +25,7 @@ To generate the keys, a user needs two parameters:
|
||||
* A set of `shortint` cryptographic parameters.
|
||||
* The number of ciphertexts used to encrypt an integer (we call them "shortint blocks").
|
||||
|
||||
We are now going to build a pair of keys that can encrypt **8-bit** integers (signed or unsigned) by using **4** shortint blocks that store **2** bits of message each.
|
||||
We are now going to build a pair of keys that can encrypt an **8-bit** integer by using **4** shortint blocks that store **2** bits of message each.
|
||||
|
||||
```rust
|
||||
use tfhe::integer::gen_keys_radix;
|
||||
|
||||
@@ -40,7 +40,8 @@ use tfhe::{ConfigBuilder, generate_keys, set_server_key, FheUint8};
|
||||
use tfhe::prelude::*;
|
||||
|
||||
fn main() {
|
||||
let config = ConfigBuilder::default()
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
@@ -140,7 +141,7 @@ use tfhe::integer::gen_keys_radix;
|
||||
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
|
||||
|
||||
fn main() {
|
||||
// We create keys for radix representation to create 16 bits integers
|
||||
// We create keys for radix represention to create 16 bits integers
|
||||
// using 8 blocks of 2 bits
|
||||
let (cks, sks) = gen_keys_radix(PARAM_MESSAGE_2_CARRY_2, 8);
|
||||
|
||||
|
||||
@@ -37,14 +37,8 @@ Each operation may come in different 'flavors':
|
||||
|
||||
Not all operations have these 4 flavors, as some of them are implemented in a way that the operation is always possible without ever exceeding the plaintext space capacity.
|
||||
|
||||
{% hint style="info" %}
|
||||
If you don't know which flavor to use, you should use the `default` one.
|
||||
{% endhint %}
|
||||
|
||||
|
||||
## How to use operation types
|
||||
|
||||
|
||||
Let's try to do a circuit evaluation using the different flavors of operations that we have already introduced. For a very small circuit, the `unchecked` flavour may be enough to do the computation correctly. Otherwise,`checked` and `smart` are the best options.
|
||||
|
||||
Let's do a scalar multiplication, a subtraction, and a multiplication.
|
||||
@@ -374,13 +368,13 @@ fn main() {
|
||||
|
||||
// We use the private client key to encrypt two messages:
|
||||
let ct_1 = client_key.encrypt(msg1);
|
||||
let ct_2 = client_key.encrypt(msg2);
|
||||
let mut ct_2 = client_key.encrypt(msg2);
|
||||
|
||||
// Compute the lookup table for the bivariate functions
|
||||
let acc = server_key.generate_lookup_table_bivariate(|x,y| (x.count_ones()
|
||||
+ y.count_ones()) as u64 % modulus );
|
||||
|
||||
let ct_res = server_key.apply_lookup_table_bivariate(&ct_1, &ct_2, &acc);
|
||||
let ct_res = server_key.smart_apply_lookup_table_bivariate(&ct_1, &mut ct_2, &acc);
|
||||
|
||||
// We use the client key to decrypt the output of the circuit:
|
||||
let output = client_key.decrypt(&ct_res);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Tutorial
|
||||
|
||||
`tfhe::shortint` is dedicated to unsigned integers smaller than 8 bits. The steps to homomorphically evaluate a circuit are described below.
|
||||
`tfhe::shortint` is dedicated to small unsigned integers smaller than 8 bits. The steps to homomorphically evaluate a circuit are described below.
|
||||
|
||||
## Key generation
|
||||
|
||||
|
||||
@@ -1,106 +1,101 @@
|
||||
# Benchmarks
|
||||
|
||||
Due to their nature, homomorphic operations are naturally slower than their cleartext equivalents. Some timings are exposed for basic operations. For completeness, benchmarks for other libraries are also given.
|
||||
Due to their nature, homomorphic operations are naturally slower than their clear equivalent. Some timings are exposed for basic operations. For completeness, benchmarks for other libraries are also given.
|
||||
|
||||
{% hint style="info" %}
|
||||
All benchmarks were launched on an AWS m6i.metal with the following specifications: Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz and 512GB of RAM.
|
||||
{% endhint %}
|
||||
|
||||
## Integer
|
||||
|
||||
This measures the execution time for some operation sets of tfhe-rs::integer (the unsigned version). Note that the timings for `FheInt` (i.e., the signed integers) are similar.
|
||||
|
||||
| Operation \ Size | `FheUint8` | `FheUint16` | `FheUint32` | `FheUint64` | `FheUint128` | `FheUint256` |
|
||||
|--------------------------------------------------------|------------|-------------|-------------|-------------|--------------|--------------|
|
||||
| Negation (`-`) | 70.9 ms | 99.3 ms | 129 ms | 180 ms | 239 ms | 333 ms |
|
||||
| Add / Sub (`+`,`-`) | 70.5 ms | 100 ms | 132 ms | 186 ms | 249 ms | 334 ms |
|
||||
| Mul (`x`) | 144 ms | 216 ms | 333 ms | 832 ms | 2.50 s | 8.85 s |
|
||||
| Equal / Not Equal (`eq`, `ne`) | 36.1 ms | 36.5 ms | 57.4 ms | 64.2 ms | 67.3 ms | 78.1 ms |
|
||||
| Comparisons (`ge`, `gt`, `le`, `lt`) | 52.6 ms | 73.1 ms | 98.8 ms | 124 ms | 165 ms | 201 ms |
|
||||
| Max / Min (`max`,`min`) | 76.2 ms | 102 ms | 135 ms | 171 ms | 212 ms | 301 ms |
|
||||
| Bitwise operations (`&`, `\|`, `^`) | 19.4 ms | 20.3 ms | 21.0 ms | 27.2 ms | 31.6 ms | 40.2 ms |
|
||||
| Div / Rem (`/`, `%`) | 729 ms | 1.93 s | 4.81 s | 12.2 s | 30.7 s | 89.6 s |
|
||||
| Left / Right Shifts (`<<`, `>>`) | 99.4 ms | 129 ms | 180 ms | 243 ms | 372 ms | 762 ms |
|
||||
| Left / Right Rotations (`left_rotate`, `right_rotate`) | 103 ms | 128 ms | 182 ms | 241 ms | 374 ms | 763 ms |
|
||||
|
||||
|
||||
All timings are related to parallelized Radix-based integer operations, where each block is encrypted using the default parameters (i.e., PARAM\_MESSAGE\_2\_CARRY\_2\_KS\_PBS, more information about parameters can be found [here](../fine_grained_api/shortint/parameters.md)).
|
||||
To ensure predictable timings, the operation flavor is the `default` one: the carry is propagated if needed. The operation costs may be reduced by using `unchecked`, `checked`, or `smart`.
|
||||
|
||||
|
||||
## Shortint
|
||||
|
||||
This measures the execution time for some operations using various parameter sets of tfhe-rs::shortint. Except for `unchecked_add`, all timings are related to the `default` operations. This flavor ensures predictable timings for an operation along the entire circuit by clearing the carry space after each operation.
|
||||
|
||||
This uses the Concrete FFT + AVX-512 configuration.
|
||||
|
||||
| Parameter set | PARAM\_MESSAGE\_1\_CARRY\_1 | PARAM\_MESSAGE\_2\_CARRY\_2 | PARAM\_MESSAGE\_3\_CARRY\_3 | PARAM\_MESSAGE\_4\_CARRY\_4 |
|
||||
|------------------------------------|-----------------------------|-----------------------------|-----------------------------|-----------------------------|
|
||||
| unchecked\_add | 348 ns | 413 ns | 2.95 µs | 12.1 µs |
|
||||
| add | 7.59 ms | 17.0 ms | 121 ms | 835 ms |
|
||||
| mul\_lsb | 8.13 ms | 16.8 ms | 121 ms | 827 ms |
|
||||
| keyswitch\_programmable\_bootstrap | 7.28 ms | 16.6 ms | 121 ms | 811 ms |
|
||||
|
||||
|
||||
## Boolean
|
||||
|
||||
This measures the execution time of a single binary Boolean gate.
|
||||
|
||||
### tfhe-rs::boolean.
|
||||
|
||||
| Parameter set | Concrete FFT + AVX-512 |
|
||||
|------------------------------------------------------|------------------------|
|
||||
| DEFAULT\_PARAMETERS\_KS\_PBS | 9.19 ms |
|
||||
| PARAMETERS\_ERROR\_PROB\_2\_POW\_MINUS\_165\_KS\_PBS | 14.1 ms |
|
||||
| TFHE\_LIB\_PARAMETERS | 10.0 ms |
|
||||
|
||||
| Parameter set | Concrete FFT | Concrete FFT + AVX-512 |
|
||||
| --------------------- | ------------ | ---------------------- |
|
||||
| DEFAULT\_PARAMETERS | 8.8ms | 6.8ms |
|
||||
| TFHE\_LIB\_PARAMETERS | 13.6ms | 10.9ms |
|
||||
|
||||
### tfhe-lib.
|
||||
|
||||
Using the same m6i.metal machine as the one for tfhe-rs, the timings are:
|
||||
| Parameter set | fftw | spqlios-fma |
|
||||
| ------------------------------------------------ | ------ | ----------- |
|
||||
| default\_128bit\_gate\_bootstrapping\_parameters | 28.9ms | 15.7ms |
|
||||
|
||||
| Parameter set | spqlios-fma |
|
||||
|--------------------------------------------------|-------------|
|
||||
| default\_128bit\_gate\_bootstrapping\_parameters | 15.4 ms |
|
||||
### OpenFHE.
|
||||
|
||||
### OpenFHE (v1.1.1).
|
||||
|
||||
Following the official instructions from OpenFHE, `clang14` and the following command are used to setup the project:
|
||||
`cmake -DNATIVE_SIZE=32 -DWITH_NATIVEOPT=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DWITH_OPENMP=OFF ..`
|
||||
|
||||
To use the HEXL library, the configuration used is as follows:
|
||||
```bash
|
||||
export CXX=clang++
|
||||
export CC=clang
|
||||
|
||||
scripts/configure.sh
|
||||
Release -> y
|
||||
hexl -> y
|
||||
|
||||
scripts/build-openfhe-development-hexl.sh
|
||||
```
|
||||
|
||||
Using the same m6i.metal machine as the one for tfhe-rs, the timings are:
|
||||
|
||||
| Parameter set | GINX | GINX w/ Intel HEXL |
|
||||
|----------------------------------|---------|--------------------|
|
||||
| FHEW\_BINGATE/STD128\_OR | 40.2 ms | 31.0 ms |
|
||||
| FHEW\_BINGATE/STD128\_LMKCDEY_OR | 38.6 ms | 28.4 ms |
|
||||
| Parameter set | GINX | GINX (Intel HEXL) |
|
||||
| ------------- | ----- | ----------------- |
|
||||
| STD\_128 | 172ms | 78ms |
|
||||
| MEDIUM | 113ms | 50.2ms |
|
||||
|
||||
|
||||
## How to reproduce TFHE-rs benchmarks
|
||||
## Integer
|
||||
This measures the execution time for some operation sets of tfhe-rs::integer.
|
||||
|
||||
TFHE-rs benchmarks can be easily reproduced from [source](https://github.com/zama-ai/tfhe-rs).
|
||||
| Operation \ Size | `FheUint8` | `FheUint16` | `FheUint32` | ` FheUint64` | `FheUint128` | `FheUint256` |
|
||||
|--------------------------------------------------------|------------|-------------|-------------|--------------|--------------|--------------|
|
||||
| Negation (`-`) | 80.4 ms | 106 ms | 132 ms | 193 ms | 257 ms | 348 ms |
|
||||
| Add / Sub (`+`,`-`) | 81.5 ms | 110 ms | 139 ms | 200 ms | 262 ms | 355 ms |
|
||||
| Mul (`x`) | 150 ms | 221 ms | 361 ms | 928 ms | 2.90 s | 10.97 s |
|
||||
| Equal / Not Equal (`eq`, `ne`) | 39.4 ms | 40.2 ms | 61.1 ms | 66.4 ms | 74.5 ms | 85.7 ms |
|
||||
| Comparisons (`ge`, `gt`, `le`, `lt`) | 57.5 ms | 79.6 ms | 105 ms | 136 ms | 174 ms | 219 ms |
|
||||
| Max / Min (`max`,`min`) | 100 ms | 130 ms | 163 ms | 204 ms | 245 ms | 338 ms |
|
||||
| Bitwise operations (`&`, `|`, `^`) | 20.7 ms | 21.1 ms | 22.6 ms | 30.2 ms | 34.1 ms | 42.1 ms |
|
||||
| Div / Rem (`/`, `%`) | 1.37 s | 3.50 s | 9.12 s | 23.9 s | 59.9 s | 149.2 s |
|
||||
| Left / Right Shifts (`<<`, `>>`) | 106 ms | 140 ms | 202 ms | 262 ms | 403 ms | 827 ms |
|
||||
| Left / Right Rotations (`left_rotate`, `right_rotate`) | 105 ms | 140 ms | 199 ms | 263 ms | 403 ms | 829 ms |
|
||||
|
||||
|
||||
|
||||
All timings are related to parallelized Radix-based integer operations, where each block is encrypted using the default parameters (i.e., PARAM\_MESSAGE\_2\_CARRY\_2, more information about parameters can be found [here](../fine_grained_api/shortint/parameters.md)).
|
||||
To ensure predictable timings, the operation flavor is the `default` one: the carry is propagated if needed. The operation costs could be reduced by using `unchecked`, `checked`, or `smart`.
|
||||
|
||||
|
||||
## Shortint
|
||||
This measures the execution time for some operations using various parameter sets of tfhe-rs::shortint.
|
||||
|
||||
This uses the Concrete FFT + AVX-512 configuration.
|
||||
|
||||
| Parameter set | unchecked\_add | unchecked\_mul\_lsb | keyswitch\_programmable\_bootstrap |
|
||||
|-----------------------------|----------------|---------------------|------------------------------------|
|
||||
| PARAM\_MESSAGE\_1\_CARRY\_1 | 338 ns | 8.3 ms | 8.1 ms |
|
||||
| PARAM\_MESSAGE\_2\_CARRY\_2 | 406 ns | 18.4 ms | 18.4 ms |
|
||||
| PARAM\_MESSAGE\_3\_CARRY\_3 | 3.06 µs | 134 ms | 129.4 ms |
|
||||
| PARAM\_MESSAGE\_4\_CARRY\_4 | 11.7 µs | 854 ms | 828.1 ms |
|
||||
|
||||
Next, the timings for the operation flavor `default` are given. This flavor ensures predictable timings of an operation along the entire circuit by clearing the carry space after each operation.
|
||||
|
||||
| Parameter set | add | mul\_lsb | keyswitch\_programmable\_bootstrap |
|
||||
| --------------------------- | -------------- | ------------------- | ---------------------------------- |
|
||||
| PARAM\_MESSAGE\_1\_CARRY\_1 | 7.90 ms | 8.00 ms | 8.10 ms |
|
||||
| PARAM\_MESSAGE\_2\_CARRY\_2 | 18.4 ms | 18.1 ms | 18.4 ms |
|
||||
| PARAM\_MESSAGE\_3\_CARRY\_3 | 131.5 ms | 129.5 ms | 129.4 ms |
|
||||
| PARAM\_MESSAGE\_4\_CARRY\_4 | 852.5 ms | 839.7 ms | 828.1 ms |
|
||||
|
||||
## How to reproduce benchmarks
|
||||
|
||||
TFHE-rs benchmarks can easily be reproduced from the [sources](https://github.com/zama-ai/tfhe-rs).
|
||||
|
||||
```shell
|
||||
#Boolean benchmarks:
|
||||
make AVX512_SUPPORT=ON bench_boolean
|
||||
make bench_boolean
|
||||
|
||||
#Integer benchmarks:
|
||||
make AVX512_SUPPORT=ON bench_integer
|
||||
make bench_integer
|
||||
|
||||
#Shortint benchmarks:
|
||||
make AVX512_SUPPORT=ON bench_shortint
|
||||
make bench_shortint
|
||||
```
|
||||
|
||||
If the host machine does not support AVX512, then turning on `AVX512_SUPPORT` will not provide any speed-up.
|
||||
If the host machine supports AVX-512, then the argument `AVX512_SUPPORT=ON' should be added, e.g.:
|
||||
|
||||
```shell
|
||||
#Integer benchmarks:
|
||||
make AVX512_SUPPORT=ON bench_integer
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,22 +4,12 @@
|
||||
|
||||
## Importing into your project
|
||||
|
||||
To use `TFHE-rs` in your project, you first need to add it as a dependency in your `Cargo.toml`.
|
||||
To use `TFHE-rs` in your project, you first need to add it as a dependency in your `Cargo.toml`:
|
||||
|
||||
If you are using an `x86` machine:
|
||||
```toml
|
||||
tfhe = { version = "0.5.0", features = [ "boolean", "shortint", "integer", "x86_64-unix" ] }
|
||||
tfhe = { version = "0.4.0", features = [ "boolean", "shortint", "integer", "x86_64-unix" ] }
|
||||
```
|
||||
|
||||
If you are using an `ARM` machine:
|
||||
```toml
|
||||
tfhe = { version = "0.5.0", features = [ "boolean", "shortint", "integer", "aarch64-unix" ] }
|
||||
```
|
||||
|
||||
{% hint style="info" %}
|
||||
You need to use a Rust version >= 1.72 to compile TFHE-rs.
|
||||
{% endhint %}
|
||||
|
||||
{% hint style="success" %}
|
||||
When running code that uses `TFHE-rs`, it is highly recommended to run in release mode with cargo's `--release` flag to have the best possible performance
|
||||
{% endhint %}
|
||||
@@ -35,3 +25,7 @@ TFHE-rs is supported on Linux (x86, aarch64), macOS (x86, aarch64) and Windows (
|
||||
| Linux | `x86_64-unix` | `aarch64-unix`\* |
|
||||
| macOS | `x86_64-unix` | `aarch64-unix`\* |
|
||||
| Windows | `x86_64` | Unsupported |
|
||||
|
||||
{% hint style="info" %}
|
||||
Users who have ARM devices can compile TFHE-rs using a stable toolchain with version >= 1.72 (see [Configuration](../how_to/rust_configuration.md) for more details).
|
||||
{% endhint %}
|
||||
|
||||
@@ -1,57 +1,260 @@
|
||||
# Homomorphic Types and Operations
|
||||
# Operations
|
||||
|
||||
## Types
|
||||
`TFHE-rs` includes two main types to represent encrypted data:
|
||||
- `FheUint`: this is the homomorphic equivalent of Rust unsigned integers `u8, u16, ...`
|
||||
- `FheInt`: this is the homomorphic equivalent of Rust (signed) integers `i8, i16, ...`
|
||||
The table below contains an overview of the available operations in `TFHE-rs`. More details, and further examples, are given in the following sections.
|
||||
|
||||
In the same manner as many programming languages, the number of bits used to represent the data must be chosen when declaring a variable. For instance:
|
||||
| name | symbol | FheUint/FheUint | FheUint/Uint | Uint/FheUint |
|
||||
|-----------------------|-------------|--------------------|--------------------------|--------------------------|
|
||||
| Neg | `-` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Add | `+` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Sub | `-` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Mul | `*` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Div | `/` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Rem | `%` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Not | `!` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| BitAnd | `&` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| BitOr | `\|` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| BitXor | `^` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Shr | `>>` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Shl | `<<` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Min | `min` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Max | `max` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Greater than | `gt` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Greater or equal than | `ge` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Lower than | `lt` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Lower or equal than | `le` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Equal | `eq` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Cast (into dest type) | `cast_into` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: |
|
||||
| Cast (from src type) | `cast_from` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: |
|
||||
|
||||
```Rust
|
||||
// let clear_a: u64 = 7;
|
||||
let mut a = FheUint64::try_encrypt(clear_a, &keys)?;
|
||||
## Boolean Operations
|
||||
|
||||
// let clear_b: i8 = 3;
|
||||
let mut b = FheInt8::try_encrypt(clear_b, &keys)?;
|
||||
Native homomorphic Booleans support common Boolean operations.
|
||||
|
||||
// let clear_c: u128 = 2;
|
||||
let mut c = FheUint128::try_encrypt(clear_c, &keys)?;
|
||||
The list of supported operations is:
|
||||
|
||||
| name | symbol | type |
|
||||
| ------------------------------------------------------------- | ------ | ------ |
|
||||
| [BitAnd](https://doc.rust-lang.org/std/ops/trait.BitAnd.html) | `&` | Binary |
|
||||
| [BitOr](https://doc.rust-lang.org/std/ops/trait.BitOr.html) | `\|` | Binary |
|
||||
| [BitXor](https://doc.rust-lang.org/std/ops/trait.BitXor.html) | `^` | Binary |
|
||||
| [Not](https://doc.rust-lang.org/std/ops/trait.Not.html) | `!` | Unary |
|
||||
|
||||
## ShortInt Operations
|
||||
|
||||
Native small homomorphic integer types (e.g., FheUint3 or FheUint4) easily compute various operations. In general, computing over encrypted data is as easy as computing over clear data, since the same operation symbol is used. The addition between two ciphertexts is done using the symbol `+` between two FheUint values. Many operations can be computed between a clear value (i.e. a scalar) and a ciphertext.
|
||||
|
||||
In Rust, operations on native types are modular. For example, computations on `u8` are carried out modulo $$2^{8}$$. A similar idea applies for FheUintX, where operations are done modulo $$2^{X}$$. For FheUint3, operations are done modulo $$8 = 2^{3}$$.
|
||||
|
||||
### Arithmetic operations.
|
||||
|
||||
Small homomorphic integer types support all common arithmetic operations, meaning `+`, `-`, `x`, `/`, `mod`.
|
||||
|
||||
The division operation implements a subtlety: since data is encrypted, it is possible to compute a division by 0. In this case, the division is tweaked so that dividing by 0 returns the max possible value for the message.
|
||||
|
||||
The list of supported operations is:
|
||||
|
||||
| name | symbol | type |
|
||||
| ------------------------------------------------------- | ------ | ------ |
|
||||
| [Add](https://doc.rust-lang.org/std/ops/trait.Add.html) | `+` | Binary |
|
||||
| [Sub](https://doc.rust-lang.org/std/ops/trait.Sub.html) | `-` | Binary |
|
||||
| [Mul](https://doc.rust-lang.org/std/ops/trait.Mul.html) | `*` | Binary |
|
||||
| [Div](https://doc.rust-lang.org/std/ops/trait.Div.html) | `/` | Binary |
|
||||
| [Rem](https://doc.rust-lang.org/std/ops/trait.Rem.html) | `%` | Binary |
|
||||
| [Neg](https://doc.rust-lang.org/std/ops/trait.Neg.html) | `-` | Unary |
|
||||
|
||||
A simple example on how to use these operations:
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint3};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = ConfigBuilder::all_disabled().enable_default_uint3().build();
|
||||
let (keys, server_keys) = generate_keys(config);
|
||||
set_server_key(server_keys);
|
||||
|
||||
let clear_a = 7;
|
||||
let clear_b = 3;
|
||||
let clear_c = 2;
|
||||
|
||||
let mut a = FheUint3::try_encrypt(clear_a, &keys)?;
|
||||
let mut b = FheUint3::try_encrypt(clear_b, &keys)?;
|
||||
let mut c = FheUint3::try_encrypt(clear_c, &keys)?;
|
||||
|
||||
|
||||
a = a * &b; // Clear equivalent computations: 7 * 3 mod 8 = 5
|
||||
b = &b + &c; // Clear equivalent computations: 3 + 2 mod 8 = 5
|
||||
b = b - 5; // Clear equivalent computations: 5 - 5 mod 8 = 0
|
||||
|
||||
let dec_a = a.decrypt(&keys);
|
||||
let dec_b = b.decrypt(&keys);
|
||||
|
||||
// We homomorphically swapped values using bitwise operations
|
||||
assert_eq!(dec_a, (clear_a * clear_b) % 8);
|
||||
assert_eq!(dec_b, ((clear_b + clear_c) - 5) % 8);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
## Operation list
|
||||
The table below contains an overview of the available operations in `TFHE-rs`. The notation `Enc` (for Encypted) either refers to `FheInt` or `FheUint`, for any size between 1 and 256-bits.
|
||||
### Bitwise operations.
|
||||
|
||||
More details, and further examples, are given in the following sections.
|
||||
Small homomorphic integer types support some bitwise operations.
|
||||
|
||||
| name | symbol | `Enc`/`Enc` | `Enc`/ `Int` |
|
||||
|-----------------------|----------------|--------------------|--------------------------|
|
||||
| Neg | `-` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Add | `+` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Sub | `-` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Mul | `*` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Div | `/` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Rem | `%` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Not | `!` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| BitAnd | `&` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| BitOr | `\|` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| BitXor | `^` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Shr | `>>` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Shl | `<<` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Min | `min` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Max | `max` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Greater than | `gt` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Greater or equal than | `ge` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Lower than | `lt` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Lower or equal than | `le` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Equal | `eq` | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Cast (into dest type) | `cast_into` | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
| Cast (from src type) | `cast_from` | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
| Ternary operator | `if_then_else` | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
The list of supported operations is:
|
||||
|
||||
| name | symbol | type |
|
||||
|--------------------------------------------------------------------------------------|----------------|--------|
|
||||
| [Not](https://doc.rust-lang.org/std/ops/trait.Not.html) | `!` | Unary |
|
||||
| [BitAnd](https://doc.rust-lang.org/std/ops/trait.BitAnd.html) | `&` | Binary |
|
||||
| [BitOr](https://doc.rust-lang.org/std/ops/trait.BitOr.html) | `\|` | Binary |
|
||||
| [BitXor](https://doc.rust-lang.org/std/ops/trait.BitXor.html) | `^` | Binary |
|
||||
| [Shr](https://doc.rust-lang.org/std/ops/trait.Shr.html) | `>>` | Binary |
|
||||
| [Shl](https://doc.rust-lang.org/std/ops/trait.Shl.html) | `<<` | Binary |
|
||||
| [Rotate Right](https://doc.rust-lang.org/std/primitive.u32.html#method.rotate_right) | `rotate_right` | Binary |
|
||||
| [Rotate Left](https://doc.rust-lang.org/std/primitive.u32.html#method.rotate_left) | `rotate_left` | Binary |
|
||||
|
||||
A simple example on how to use these operations:
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint3};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = ConfigBuilder::all_disabled().enable_default_uint3().build();
|
||||
let (keys, server_keys) = generate_keys(config);
|
||||
set_server_key(server_keys);
|
||||
|
||||
let clear_a = 7;
|
||||
let clear_b = 3;
|
||||
|
||||
let mut a = FheUint3::try_encrypt(clear_a, &keys)?;
|
||||
let mut b = FheUint3::try_encrypt(clear_b, &keys)?;
|
||||
|
||||
a = a ^ &b;
|
||||
b = b ^ &a;
|
||||
a = a ^ &b;
|
||||
|
||||
let dec_a = a.decrypt(&keys);
|
||||
let dec_b = b.decrypt(&keys);
|
||||
|
||||
// We homomorphically swapped values using bitwise operations
|
||||
assert_eq!(dec_a, clear_b);
|
||||
assert_eq!(dec_b, clear_a);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
### Comparisons.
|
||||
|
||||
Small homomorphic integer types support comparison operations.
|
||||
|
||||
Due to some Rust limitations, it is not possible to overload the comparison symbols because of the inner definition of the operations. Rust expects to have a Boolean as an output, whereas a ciphertext is returned when using homomorphic types.
|
||||
|
||||
You will need to use different methods instead of using symbols for the comparisons. These methods follow the same naming conventions as the two standard Rust traits:
|
||||
|
||||
* [PartialOrd](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html)
|
||||
* [PartialEq](https://doc.rust-lang.org/std/cmp/trait.PartialEq.html)
|
||||
|
||||
The list of supported operations is:
|
||||
|
||||
| name | symbol | type |
|
||||
|-----------------------------------------------------------------------------|--------|--------|
|
||||
| [Equal ](https://doc.rust-lang.org/std/cmp/trait.PartialEq.html) | `eq` | Binary |
|
||||
| [Not Equal ](https://doc.rust-lang.org/std/cmp/trait.PartialEq.html) | `ne` | Binary |
|
||||
| [Greater Than ](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html) | `gt` | Binary |
|
||||
| [Greater or Equal](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html) | `ge` | Binary |
|
||||
| [Lower ](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html) | `lt` | Binary |
|
||||
| [Lower or Equal ](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html) | `le` | Binary |
|
||||
|
||||
|
||||
A simple example on how to use these operations:
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint3};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = ConfigBuilder::all_disabled().enable_default_uint3().build();
|
||||
let (keys, server_keys) = generate_keys(config);
|
||||
set_server_key(server_keys);
|
||||
|
||||
let clear_a = 7;
|
||||
let clear_b = 3;
|
||||
|
||||
let mut a = FheUint3::try_encrypt(clear_a, &keys)?;
|
||||
let mut b = FheUint3::try_encrypt(clear_b, &keys)?;
|
||||
|
||||
assert_eq!(a.gt(&b).decrypt(&keys) != 0, true);
|
||||
assert_eq!(b.le(&a).decrypt(&keys) != 0, true);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
### Univariate function evaluation.
|
||||
|
||||
The shortint type also supports the computation of univariate functions, which make use of TFHE's _programmable bootstrapping_.
|
||||
|
||||
A simple example on how to use these operations:
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint4};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = ConfigBuilder::all_disabled().enable_default_uint4().build();
|
||||
let (keys, server_keys) = generate_keys(config);
|
||||
set_server_key(server_keys);
|
||||
|
||||
let pow_5 = |value: u64| {
|
||||
value.pow(5) % FheUint4::MODULUS as u64
|
||||
};
|
||||
|
||||
let clear_a = 12;
|
||||
let a = FheUint4::try_encrypt(12, &keys)?;
|
||||
|
||||
let c = a.map(pow_5);
|
||||
let decrypted = c.decrypt(&keys);
|
||||
assert_eq!(decrypted, pow_5(clear_a) as u8);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
### Bivariate function evaluations.
|
||||
|
||||
Using the shortint type allows you to evaluate bivariate functions (i.e., functions that take two ciphertexts as input).
|
||||
|
||||
A simple code example:
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint2};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = ConfigBuilder::all_disabled().enable_default_uint2().build();
|
||||
let (keys, server_keys) = generate_keys(config);
|
||||
set_server_key(server_keys);
|
||||
|
||||
let clear_a = 1;
|
||||
let clear_b = 3;
|
||||
let a = FheUint2::try_encrypt(clear_a, &keys)?;
|
||||
let b = FheUint2::try_encrypt(clear_b, &keys)?;
|
||||
|
||||
|
||||
let c = a.bivariate_function(&b, std::cmp::max);
|
||||
let decrypted = c.decrypt(&keys);
|
||||
assert_eq!(decrypted, std::cmp::max(clear_a, clear_b) as u8);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
## Integer
|
||||
|
||||
In `TFHE-rs`, integers are used to encrypt all messages which are larger than 4 bits. All supported operations are listed below.
|
||||
In TFHE-rs, integers are used to encrypt any messages larger than 4 bits. All supported operations are listed below.
|
||||
|
||||
### Arithmetic operations.
|
||||
|
||||
@@ -68,43 +271,40 @@ The list of supported operations is:
|
||||
| [Div](https://doc.rust-lang.org/std/ops/trait.Div.html)* | `/` | Binary |
|
||||
| [Rem](https://doc.rust-lang.org/std/ops/trait.Rem.html)* | `%` | Binary |
|
||||
|
||||
For division by 0, the convention is to return `modulus - 1`. For instance, for `FheUint8`, the modulus is $$2^8=256$$, so a division by 0 will return an encryption of 255.
|
||||
For the remainder operator, the convention is to return the first input without any modification. For instance, if `ct1 = FheUint8(63)` and `ct2 = FheUint8(0)` then `ct1 % ct2` will return `FheUint8(63)`.
|
||||
For the division operator, the convention is to return the modulus - 1. For instance, for FheUint8, the modulus is $$2^8=256$$, so a division by 0 will return an encryption of 255.
|
||||
For the remainder operator, the convention is to return the first input without any modification. For instance, for ct1 = FheUint8(63) and ct2 = FheUint8(0), then ct1 % ct2 will return FheUint8(63).
|
||||
|
||||
A simple example of how to use these operations:
|
||||
|
||||
|
||||
A simple example on how to use these operations:
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheInt8, FheUint8};
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers().build();
|
||||
let (keys, server_keys) = generate_keys(config);
|
||||
set_server_key(server_keys);
|
||||
|
||||
let clear_a = 15_u64;
|
||||
let clear_b = 27_u64;
|
||||
let clear_c = 43_u64;
|
||||
let clear_d = -87_i64;
|
||||
|
||||
let mut a = FheUint8::try_encrypt(clear_a, &keys)?;
|
||||
let mut b = FheUint8::try_encrypt(clear_b, &keys)?;
|
||||
let mut c = FheUint8::try_encrypt(clear_c, &keys)?;
|
||||
let mut d = FheInt8::try_encrypt(clear_d, &keys)?;
|
||||
|
||||
|
||||
a = a * &b; // Clear equivalent computations: 15 * 27 mod 256 = 149
|
||||
b = &b + &c; // Clear equivalent computations: 27 + 43 mod 256 = 70
|
||||
a = a * &b; // Clear equivalent computations: 15 * 27 mod 256 = 149
|
||||
b = &b + &c; // Clear equivalent computations: 27 + 43 mod 256 = 70
|
||||
b = b - 76u8; // Clear equivalent computations: 70 - 76 mod 256 = 250
|
||||
d = d - 13i8; // Clear equivalent computations: -87 - 13 = 100 in [-128, 128[
|
||||
|
||||
let dec_a: u8 = a.decrypt(&keys);
|
||||
let dec_b: u8 = b.decrypt(&keys);
|
||||
let dec_d: i8 = d.decrypt(&keys);
|
||||
|
||||
assert_eq!(dec_a, ((clear_a * clear_b) % 256_u64) as u8);
|
||||
assert_eq!(dec_b, (((clear_b + clear_c).wrapping_sub(76_u64)) % 256_u64) as u8);
|
||||
assert_eq!(dec_d, (clear_d - 13) as i8);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -127,14 +327,14 @@ The list of supported operations is:
|
||||
| [Rotate Right](https://doc.rust-lang.org/std/primitive.u32.html#method.rotate_right) | `rotate_right` | Binary |
|
||||
| [Rotate Left](https://doc.rust-lang.org/std/primitive.u32.html#method.rotate_left) | `rotate_left` | Binary |
|
||||
|
||||
A simple example of how to use these operations:
|
||||
A simple example on how to use these operations:
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers().build();
|
||||
let (keys, server_keys) = generate_keys(config);
|
||||
set_server_key(server_keys);
|
||||
|
||||
@@ -161,14 +361,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
### Comparisons.
|
||||
|
||||
Homomorphic integers support comparison operations.
|
||||
|
||||
Due to some Rust limitations, it is not possible to overload the comparison symbols because of the inner definition of the operations. This is because Rust expects to have a Boolean as an output, whereas a ciphertext is returned when using homomorphic types.
|
||||
|
||||
You will need to use different methods instead of using symbols for the comparisons. These methods follow the same naming conventions as the two standard Rust traits:
|
||||
|
||||
* [PartialOrd](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html)
|
||||
* [PartialEq](https://doc.rust-lang.org/std/cmp/trait.PartialEq.html)
|
||||
Homomorphic integers support comparison operations. Since Rust does not allow the overloading of these operations, a simple function has been associated to each one.
|
||||
|
||||
The list of supported operations is:
|
||||
|
||||
@@ -181,22 +374,22 @@ The list of supported operations is:
|
||||
| [Lower ](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html) | `lt` | Binary |
|
||||
| [Lower or Equal ](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html) | `le` | Binary |
|
||||
|
||||
A simple example of how to use these operations:
|
||||
A simple example on how to use these operations:
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheInt8};
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers().build();
|
||||
let (keys, server_keys) = generate_keys(config);
|
||||
set_server_key(server_keys);
|
||||
|
||||
let clear_a: i8 = -121;
|
||||
let clear_b: i8 = 87;
|
||||
let clear_a:u8 = 164;
|
||||
let clear_b:u8 = 212;
|
||||
|
||||
let mut a = FheInt8::try_encrypt(clear_a, &keys)?;
|
||||
let mut b = FheInt8::try_encrypt(clear_b, &keys)?;
|
||||
let mut a = FheUint8::try_encrypt(clear_a, &keys)?;
|
||||
let mut b = FheUint8::try_encrypt(clear_b, &keys)?;
|
||||
|
||||
let greater = a.gt(&b);
|
||||
let greater_or_equal = a.ge(&b);
|
||||
@@ -204,17 +397,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let lower_or_equal = a.le(&b);
|
||||
let equal = a.eq(&b);
|
||||
|
||||
let dec_gt = greater.decrypt(&keys);
|
||||
let dec_ge = greater_or_equal.decrypt(&keys);
|
||||
let dec_lt = lower.decrypt(&keys);
|
||||
let dec_le = lower_or_equal.decrypt(&keys);
|
||||
let dec_eq = equal.decrypt(&keys);
|
||||
let dec_gt : u8 = greater.decrypt(&keys);
|
||||
let dec_ge : u8 = greater_or_equal.decrypt(&keys);
|
||||
let dec_lt : u8 = lower.decrypt(&keys);
|
||||
let dec_le : u8 = lower_or_equal.decrypt(&keys);
|
||||
let dec_eq : u8 = equal.decrypt(&keys);
|
||||
|
||||
assert_eq!(dec_gt, clear_a > clear_b);
|
||||
assert_eq!(dec_ge, clear_a >= clear_b);
|
||||
assert_eq!(dec_lt, clear_a < clear_b);
|
||||
assert_eq!(dec_le, clear_a <= clear_b);
|
||||
assert_eq!(dec_eq, clear_a == clear_b);
|
||||
// We homomorphically swapped values using bitwise operations
|
||||
assert_eq!(dec_gt, (clear_a > clear_b ) as u8);
|
||||
assert_eq!(dec_ge, (clear_a >= clear_b) as u8);
|
||||
assert_eq!(dec_lt, (clear_a < clear_b ) as u8);
|
||||
assert_eq!(dec_le, (clear_a <= clear_b) as u8);
|
||||
assert_eq!(dec_eq, (clear_a == clear_b) as u8);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -229,14 +423,14 @@ Homomorphic integers support the min/max operations.
|
||||
| Min | `min` | Binary |
|
||||
| Max | `max` | Binary |
|
||||
|
||||
A simple example of how to use these operations:
|
||||
A simple example on how to use these operations:
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint8};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled().enable_default_integers().build();
|
||||
let (keys, server_keys) = generate_keys(config);
|
||||
set_server_key(server_keys);
|
||||
|
||||
@@ -252,6 +446,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let dec_min : u8 = min.decrypt(&keys);
|
||||
let dec_max : u8 = max.decrypt(&keys);
|
||||
|
||||
// We homomorphically swapped values using bitwise operations
|
||||
assert_eq!(dec_min, u8::min(clear_a, clear_b));
|
||||
assert_eq!(dec_max, u8::max(clear_a, clear_b));
|
||||
|
||||
@@ -259,67 +454,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
```
|
||||
|
||||
### Ternary conditional operator.
|
||||
The ternary conditional operator allows computing conditional instructions of the form `if cond { choice_if } else { choice_else }`.
|
||||
|
||||
| name | symbol | type |
|
||||
|------------------|----------------|---------|
|
||||
| Ternary operator | `if_then_else` | Ternary |
|
||||
|
||||
The syntax is `encrypted_condition.if_then_else(encrypted_choice_if, encrypted_choice_else)`. The `encrypted_condition` should be an encryption of 0 or 1 in order to be valid.
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheInt32};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Basic configuration to use homomorphic integers
|
||||
let config = ConfigBuilder::default().build();
|
||||
|
||||
// Key generation
|
||||
let (client_key, server_keys) = generate_keys(config);
|
||||
|
||||
let clear_a = 32i32;
|
||||
let clear_b = -45i32;
|
||||
|
||||
// Encrypting the input data using the (private) client_key
|
||||
// FheInt32: Encrypted equivalent to i32
|
||||
let encrypted_a = FheInt32::try_encrypt(clear_a, &client_key)?;
|
||||
let encrypted_b = FheInt32::try_encrypt(clear_b, &client_key)?;
|
||||
|
||||
// On the server side:
|
||||
set_server_key(server_keys);
|
||||
|
||||
// Clear equivalent computations: 32 > -45
|
||||
let encrypted_comp = &encrypted_a.gt(&encrypted_b);
|
||||
let clear_res = encrypted_comp.decrypt(&client_key);
|
||||
assert_eq!(clear_res, clear_a > clear_b);
|
||||
|
||||
// `encrypted_comp` is a FheBool, thus it encrypts a boolean value.
|
||||
// This acts as a condition on which the
|
||||
// `if_then_else` function can be applied on.
|
||||
// Clear equivalent computations:
|
||||
// if 32 > -45 {result = 32} else {result = -45}
|
||||
let encrypted_res = &encrypted_comp.if_then_else(&encrypted_a, &encrypted_b);
|
||||
|
||||
let clear_res: i32 = encrypted_res.decrypt(&client_key);
|
||||
assert_eq!(clear_res, clear_a);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Casting.
|
||||
|
||||
Casting between integer types is possible via the `cast_from` associated function
|
||||
or the `cast_into` method.
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheInt16, FheUint8, FheUint32, FheUint16};
|
||||
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint8, FheUint32, FheUint16};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
// Casting requires server_key to set
|
||||
@@ -356,30 +503,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
assert_eq!(da, (clear as u32) as u8);
|
||||
}
|
||||
|
||||
{
|
||||
let clear = 12_837i16;
|
||||
let a = FheInt16::encrypt(clear, &client_key);
|
||||
|
||||
// Casting from FheInt16 to FheUint16
|
||||
let a = FheUint16::cast_from(a);
|
||||
let da: u16 = a.decrypt(&client_key);
|
||||
assert_eq!(da, clear as u16);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Boolean Operations
|
||||
|
||||
Native homomorphic Booleans support common Boolean operations.
|
||||
|
||||
The list of supported operations is:
|
||||
|
||||
| name | symbol | type |
|
||||
| ------------------------------------------------------------- | ------ | ------ |
|
||||
| [BitAnd](https://doc.rust-lang.org/std/ops/trait.BitAnd.html) | `&` | Binary |
|
||||
| [BitOr](https://doc.rust-lang.org/std/ops/trait.BitOr.html) | `\|` | Binary |
|
||||
| [BitXor](https://doc.rust-lang.org/std/ops/trait.BitXor.html) | `^` | Binary |
|
||||
| [Not](https://doc.rust-lang.org/std/ops/trait.Not.html) | `!` | Unary |
|
||||
|
||||
@@ -18,7 +18,9 @@ use tfhe::{ConfigBuilder, generate_keys, set_server_key, FheUint8};
|
||||
use tfhe::prelude::*;
|
||||
|
||||
fn main() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
|
||||
// Client-side
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
@@ -44,7 +46,7 @@ fn main() {
|
||||
|
||||
The default configuration for x86 Unix machines:
|
||||
```toml
|
||||
tfhe = { version = "0.5.0", features = ["integer", "x86_64-unix"]}
|
||||
tfhe = { version = "0.4.0", features = ["integer", "x86_64-unix"]}
|
||||
```
|
||||
|
||||
Configuration options for different platforms can be found [here](../getting_started/installation.md). Other rust and homomorphic types features can be found [here](../how_to/rust_configuration.md).
|
||||
@@ -74,8 +76,9 @@ The config is generated by first creating a builder with all types deactivated.
|
||||
use tfhe::{ConfigBuilder, generate_keys};
|
||||
|
||||
fn main() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
}
|
||||
@@ -95,7 +98,9 @@ This function will **move** the server key to an internal state of the crate and
|
||||
use tfhe::{ConfigBuilder, generate_keys, set_server_key};
|
||||
|
||||
fn main() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
|
||||
let (client_key, server_key) = generate_keys(config);
|
||||
|
||||
@@ -134,3 +139,6 @@ let clear_result = clear_a + clear_b;
|
||||
|
||||
assert_eq!(decrypted_result, clear_result);
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ The figure below illustrates this problem in the case of an addition, where an e
|
||||
|
||||
### Programmable BootStrapping (PBS)
|
||||
|
||||
The bootstrapping of TFHE has the particularity of being programmable: this means that any function can be homomorphically computed over an encrypted input, while also reducing the noise. These functions are represented by look-up tables. The computation of a PBS is in general either preceded or followed by a keyswitch, which is an operation used to change the encryption key. The output ciphertext is then encrypted with the same key as the input one. To do this, two (public) evaluation keys are required: a bootstrapping key and a keyswitching key. These operations are quite complex to describe, more information about these operations (or about TFHE in general) can be found here [TFHE Deep Dive](https://www.zama.ai/post/tfhe-deep-dive-part-1).
|
||||
The bootstrapping of TFHE has the particularity of being programmable: this means that any function can be homomorphically computed over an encrypted input, while also reducing the noise. These functions are represented by look-up tables. The computation of a PBS is in general either preceded or followed by a keyswitch, which is an operation used to change the encryption key. The output ciphertext is then encrypted with the same key as the input one. To do this, two (public) evaluation keys are required: a boostrapping key and a keyswitching key. These operations are quite complex to describe, more information about these operations (or about TFHE in general) can be found here [TFHE Deep Dive](https://www.zama.ai/post/tfhe-deep-dive-part-1).
|
||||
|
||||
|
||||
### Carry.
|
||||
|
||||
@@ -3,7 +3,6 @@ TFHE-rs includes features to reduce the size of both keys and ciphertexts, by co
|
||||
|
||||
In the library, entities that can be compressed are prefixed by `Compressed`. For instance, the type of a compressed `FheUint256` is `CompressedFheUint256`.
|
||||
|
||||
In the following example code, we use the `bincode` crate dependency to serialize in a binary format and compare serialized sizes.
|
||||
|
||||
## Compressed ciphertexts
|
||||
This example shows how to compress a ciphertext encypting messages over 16 bits.
|
||||
@@ -13,23 +12,14 @@ use tfhe::prelude::*;
|
||||
use tfhe::{ConfigBuilder, generate_keys, set_server_key, CompressedFheUint16};
|
||||
|
||||
fn main() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (client_key, _) = generate_keys(config);
|
||||
|
||||
let clear = 12_837u16;
|
||||
let compressed = CompressedFheUint16::try_encrypt(clear, &client_key).unwrap();
|
||||
println!(
|
||||
"compressed size : {}",
|
||||
bincode::serialize(&compressed).unwrap().len()
|
||||
);
|
||||
|
||||
let decompressed = compressed.decompress();
|
||||
|
||||
println!(
|
||||
"decompressed size: {}",
|
||||
bincode::serialize(&decompressed).unwrap().len()
|
||||
);
|
||||
|
||||
let clear_decompressed: u16 = decompressed.decrypt(&client_key);
|
||||
assert_eq!(clear_decompressed, clear);
|
||||
}
|
||||
@@ -41,28 +31,17 @@ This example shows how to compress the server keys.
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{
|
||||
generate_keys, set_server_key, ClientKey, CompressedServerKey, ConfigBuilder, FheUint8,
|
||||
};
|
||||
use tfhe::{ConfigBuilder, generate_keys, set_server_key, FheUint8, CompressedServerKey, ClientKey};
|
||||
|
||||
fn main() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
|
||||
let cks = ClientKey::generate(config);
|
||||
let compressed_sks = CompressedServerKey::new(&cks);
|
||||
|
||||
println!(
|
||||
"compressed size : {}",
|
||||
bincode::serialize(&compressed_sks).unwrap().len()
|
||||
);
|
||||
|
||||
let sks = compressed_sks.decompress();
|
||||
|
||||
println!(
|
||||
"decompressed size: {}",
|
||||
bincode::serialize(&sks).unwrap().len()
|
||||
);
|
||||
|
||||
set_server_key(sks);
|
||||
|
||||
let clear_a = 12u8;
|
||||
@@ -72,7 +51,6 @@ fn main() {
|
||||
let decrypted: u8 = c.decrypt(&cks);
|
||||
assert_eq!(decrypted, clear_a.wrapping_add(234));
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -80,7 +58,7 @@ fn main() {
|
||||
This example shows how to compress the classical public keys.
|
||||
|
||||
{% hint style="warning" %}
|
||||
It is not currently recommended to use the CompressedPublicKey to encrypt ciphertexts without first decompressing it. In case the resulting PublicKey is too large to fit in memory the encryption with the CompressedPublicKey will be very slow, this is a known problem and will be addressed in future releases.
|
||||
It is not currently recommended to use the CompressedPublicKey to encrypt ciphertexts without first decompressing it. In case the resulting PublicKey is too large to fit in memory the encryption with the CompressedPublicKey will be very slow, this is a known problem and will be adressed in future releases.
|
||||
{% endhint %}
|
||||
|
||||
```rust
|
||||
@@ -88,17 +66,12 @@ use tfhe::prelude::*;
|
||||
use tfhe::{ConfigBuilder, generate_keys, set_server_key, FheUint8, CompressedPublicKey};
|
||||
|
||||
fn main() {
|
||||
let config = ConfigBuilder::default().build();
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_default_integers()
|
||||
.build();
|
||||
let (client_key, _) = generate_keys(config);
|
||||
|
||||
let compressed_public_key = CompressedPublicKey::new(&client_key);
|
||||
|
||||
println!("compressed size : {}", bincode::serialize(&compressed_public_key).unwrap().len());
|
||||
|
||||
let public_key = compressed_public_key.decompress();
|
||||
|
||||
println!("decompressed size: {}", bincode::serialize(&public_key).unwrap().len());
|
||||
|
||||
let public_key = CompressedPublicKey::new(&client_key);
|
||||
|
||||
let a = FheUint8::try_encrypt(213u8, &public_key).unwrap();
|
||||
let clear: u8 = a.decrypt(&client_key);
|
||||
@@ -113,11 +86,11 @@ This example shows how to use compressed compact public keys.
|
||||
|
||||
```rust
|
||||
use tfhe::prelude::*;
|
||||
use tfhe::{generate_keys, set_server_key, CompressedCompactPublicKey, ConfigBuilder, FheUint8};
|
||||
use tfhe::{ConfigBuilder, generate_keys, set_server_key, FheUint8, CompressedCompactPublicKey};
|
||||
|
||||
fn main() {
|
||||
let config = ConfigBuilder::default()
|
||||
.use_custom_parameters(
|
||||
let config = ConfigBuilder::all_disabled()
|
||||
.enable_custom_integers(
|
||||
tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS,
|
||||
None,
|
||||
)
|
||||
@@ -125,22 +98,10 @@ fn main() {
|
||||
let (client_key, _) = generate_keys(config);
|
||||
|
||||
let public_key_compressed = CompressedCompactPublicKey::new(&client_key);
|
||||
|
||||
println!(
|
||||
"compressed size : {}",
|
||||
bincode::serialize(&public_key_compressed).unwrap().len()
|
||||
);
|
||||
|
||||
let public_key = public_key_compressed.decompress();
|
||||
|
||||
println!(
|
||||
"decompressed size: {}",
|
||||
bincode::serialize(&public_key).unwrap().len()
|
||||
);
|
||||
|
||||
|
||||
let a = FheUint8::try_encrypt(255u8, &public_key).unwrap();
|
||||
let clear: u8 = a.decrypt(&client_key);
|
||||
assert_eq!(clear, 255u8);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user