Compare commits

..

2 Commits

Author SHA1 Message Date
Nicolas Sarlin
ea3b1a7f76 chore(shortint): use default aliases for test params if possible
That way we are sure that prod params are always tested
2026-04-20 18:03:38 +02:00
Nicolas Sarlin
a18e5f3834 chore(shortint): use TEST_ params as much as possible in tests 2026-04-20 18:03:38 +02:00
167 changed files with 1338 additions and 3842 deletions

View File

@@ -4,6 +4,9 @@ ignore = [
"RUSTSEC-2024-0436",
# Ignoring unmaintained 'bincode' crate. Getting rid of it would be too complex on the short term.
"RUSTSEC-2025-0141",
# Ignoring unsoundness in 'rand' with custom logger. Rand update is currently blocked by
# arkworks and we do not use custom loggers.
"RUSTSEC-2026-0097",
]
[output]

View File

@@ -54,7 +54,7 @@ jobs:
- name: Retrieve data from cache
id: retrieve-data-cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
with:
path: |
utils/tfhe-backward-compat-data/**/*.cbor
@@ -89,7 +89,7 @@ jobs:
- name: Store data in cache
if: steps.retrieve-data-cache.outputs.cache-hit != 'true'
continue-on-error: true
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
with:
path: |
utils/tfhe-backward-compat-data/**/*.cbor

View File

@@ -69,7 +69,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
dependencies:
@@ -200,7 +200,7 @@ jobs:
- name: Node cache restoration
id: node-cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
with:
path: |
~/.nvm
@@ -213,7 +213,7 @@ jobs:
make install_node
- name: Node cache save
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
if: steps.node-cache.outputs.cache-hit != 'true'
with:
path: |

View File

@@ -56,7 +56,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
integer:

View File

@@ -57,7 +57,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
integer:

View File

@@ -78,7 +78,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
dependencies:

View File

@@ -45,7 +45,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
wasm:
@@ -92,7 +92,7 @@ jobs:
- name: Node cache restoration
id: node-cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
with:
path: |
~/.nvm
@@ -105,7 +105,7 @@ jobs:
make install_node
- name: Node cache save
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
if: steps.node-cache.outputs.cache-hit != 'true'
with:
path: |

View File

@@ -34,7 +34,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
backward:
@@ -79,11 +79,19 @@ jobs:
exit 1
fi
- name: Post/refresh backward-compat report
- name: Find existing comment
if: steps.report.outputs.has_report == 'true'
uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0
id: find-comment
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4.0.0
with:
header: backward-compat-snapshot
hide_and_recreate: true
hide_classify: OUTDATED
path: report.md
issue-number: ${{ github.event.pull_request.number }}
body-includes: '**Backward-compat snapshot:'
- name: Comment on PR
if: steps.report.outputs.has_report == 'true'
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: report.md
edit-mode: replace

View File

@@ -223,7 +223,7 @@ jobs:
results_type: ${{ inputs.additional_results_type }}
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_${{ matrix.command }}_${{ matrix.op_flavor }}_${{ matrix.bench_type }}_${{ matrix.params_type }}
path: ${{ env.RESULTS_FILENAME }}

View File

@@ -99,7 +99,7 @@ jobs:
--append-results
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_ct_key_sizes
path: ${{ env.RESULTS_FILENAME }}

View File

@@ -89,7 +89,7 @@ jobs:
REF_NAME: ${{ github.ref_name }}
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_integer_multi_bit_gpu_default
path: ${{ env.RESULTS_FILENAME }}
@@ -173,7 +173,7 @@ jobs:
REF_NAME: ${{ github.ref_name }}
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_core_crypto
path: ${{ env.RESULTS_FILENAME }}

View File

@@ -270,7 +270,7 @@ jobs:
filenames: ${{ inputs.additional_file_to_parse }}
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_${{ matrix.command }}_${{ matrix.op_flavor }}_${{ inputs.profile }}_${{ matrix.bench_type }}_${{ matrix.params_type }}
path: ${{ env.RESULTS_FILENAME }}

View File

@@ -204,7 +204,7 @@ jobs:
uses: foundry-rs/foundry-toolchain@8789b3e21e6c11b2697f5eb56eddae542f746c10
- name: Cache cargo
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: |
~/.cargo/registry
@@ -232,7 +232,7 @@ jobs:
working-directory: fhevm/coprocessor/fhevm-engine/tfhe-worker
- name: Use Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: 20.x
@@ -271,7 +271,7 @@ jobs:
- name: Upload profile artifact
env:
REPORT_NAME: ${{ steps.nsys_profile_name.outputs.profile }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ env.REPORT_NAME }}
path: fhevm/coprocessor/fhevm-engine/tfhe-worker/${{ env.REPORT_NAME }}
@@ -302,7 +302,7 @@ jobs:
working-directory: fhevm/
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${COMMIT_SHA}_${BENCHMARKS}_${{ needs.parse-inputs.outputs.profile }}
path: fhevm/$${{ env.RESULTS_FILENAME }}

View File

@@ -185,7 +185,7 @@ jobs:
BENCH_TYPE: ${{ matrix.bench_type }}
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_${{ matrix.bench_type }}_${{ matrix.command }}_benchmarks
path: ${{ env.RESULTS_FILENAME }}

View File

@@ -280,7 +280,7 @@ jobs:
BENCH_TYPE: ${{ env.__TFHE_RS_BENCH_TYPE }}
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_regression_${{ env.RESULTS_FILE_SHA }} # RESULT_FILE_SHA is needed to avoid collision between matrix.command runs
path: ${{ env.RESULTS_FILENAME }}

View File

@@ -99,7 +99,7 @@ jobs:
REF_NAME: ${{ github.ref_name }}
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_fft
path: ${{ env.RESULTS_FILENAME }}

View File

@@ -99,7 +99,7 @@ jobs:
REF_NAME: ${{ github.ref_name }}
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_ntt
path: ${{ env.RESULTS_FILENAME }}

View File

@@ -46,7 +46,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
wasm_bench:

View File

@@ -124,7 +124,7 @@ jobs:
- name: Node cache restoration
id: node-cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
with:
path: |
~/.nvm
@@ -137,7 +137,7 @@ jobs:
make install_node
- name: Node cache save
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
if: steps.node-cache.outputs.cache-hit != 'true'
with:
path: |
@@ -180,7 +180,7 @@ jobs:
REF_NAME: ${{ github.ref_name }}
- name: Upload parsed results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_wasm_${{ matrix.browser }}
path: ${{ env.RESULTS_FILENAME }}

View File

@@ -138,7 +138,7 @@ jobs:
- name: Node cache restoration
if: inputs.run-pcc-cpu-batch == 'pcc_batch_2'
id: node-cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
with:
path: |
~/.nvm
@@ -151,7 +151,7 @@ jobs:
make install_node
- name: Node cache save
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
if: inputs.run-pcc-cpu-batch == 'pcc_batch_2' && steps.node-cache.outputs.cache-hit != 'true'
with:
path: |

View File

@@ -40,7 +40,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
fft:

View File

@@ -42,7 +42,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
ntt:

View File

@@ -43,7 +43,7 @@ jobs:
echo "version=$(make zizmor_version)" >> "${GITHUB_OUTPUT}"
- name: Check workflows security
uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2
with:
advanced-security: 'false' # Print results directly in logs
persona: pedantic

View File

@@ -44,7 +44,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
tfhe:

View File

@@ -46,7 +46,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
csprng:

View File

@@ -87,7 +87,7 @@ jobs:
- name: Upload tables
if: inputs.backend_comparison == false
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_${{ inputs.backend }}_${{ inputs.layer }}_subset_${{inputs.bench_subset}}_${{ inputs.pbs_kind }}_${{ inputs.bench_type }}_tables
# This will upload all the file generated
@@ -111,7 +111,7 @@ jobs:
- name: Upload comparison tables
if: inputs.backend_comparison == true
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ github.sha }}_backends_comparison_tables
# This will upload all the file generated

View File

@@ -49,7 +49,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -47,7 +47,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -48,7 +48,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -49,7 +49,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -45,7 +45,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -48,7 +48,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -48,7 +48,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -48,7 +48,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -49,7 +49,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -49,7 +49,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -48,7 +48,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -49,7 +49,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -49,7 +49,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -47,7 +47,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
gpu:

View File

@@ -41,7 +41,7 @@ jobs:
- name: Check for file changes
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files_yaml: |
hpu:

View File

@@ -62,7 +62,7 @@ jobs:
PACKAGE: ${{ inputs.package-name }}
run: |
cargo package -p "${PACKAGE}"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: crate-${{ inputs.package-name }}
path: target/package/*.crate

View File

@@ -128,7 +128,7 @@ jobs:
run: |
cargo package -p "${PACKAGE}"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: crate-${{ inputs.package-name }}
path: target/package/*.crate
@@ -196,13 +196,6 @@ jobs:
env:
GCC_VERSION: ${{ matrix.gcc }}
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: "false"
token: ${{ secrets.REPO_CHECKOUT_TOKEN }}
- name: Download artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
@@ -217,12 +210,12 @@ jobs:
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
PACKAGE: ${{ inputs.package-name }}
DRY_RUN: ${{ inputs.dry-run && '--dry-run' || '' }}
DRY-RUN: ${{ inputs.dry-run && '--dry-run' || '' }}
run: |
# DRY_RUN expansion cannot be double quoted when variable contains empty string otherwise cargo publish
# would fail. This is safe since DRY_RUN is handled in the env section above.
# dry-run expansion cannot be double quoted when variable contains empty string otherwise cargo publish
# would fail. This is safe since dry-run is handled in the env section above.
# shellcheck disable=SC2086
cargo publish -p "${PACKAGE}" ${DRY_RUN}
cargo publish -p "${PACKAGE}" ${DRY-RUN}
- name: Generate hash
id: published_hash
@@ -262,7 +255,7 @@ jobs:
- name: Slack Notification
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661 # v2.3.3
uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661
env:
SLACK_COLOR: ${{ job.status }}
SLACK_MESSAGE: "Instance teardown (${{ inputs.package-name }} release) finished with status: ${{ job.status }}. (${{ env.ACTION_RUN_URL }})"

View File

@@ -89,7 +89,7 @@ jobs:
make build_web_js_api_parallel
- name: Authenticate on NPM
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'

View File

@@ -53,7 +53,7 @@ jobs:
- name: Restore Sagemath image from cache
id: docker-cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
with:
path: /tmp/sagemath_image
key: sagemath-image-${{ env.SAGEMATH_VERSION }}-${{ github.sha }}
@@ -76,7 +76,7 @@ jobs:
- name: Store Sagemath image in cache
if: steps.docker-cache.outputs.cache-hit != 'true'
continue-on-error: true
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae #v5.0.5
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7 #v5.0.4
with:
path: /tmp/sagemath_image
key: sagemath-image-${{ env.SAGEMATH_VERSION }}-${{ github.sha }}

View File

@@ -360,7 +360,7 @@ check_fmt_toml: install_taplo
.PHONY: check_typos # Check for typos in codebase
check_typos: install_typos_checker
@git ls-files ":!*.png" ":!*.cbor" ":!*.bcode" ":!*.ico" ":!*/twiddles.cu" ":!*.hpu" | typos --file-list - && echo "No typos found"
@git ls-files ":!*.png" ":!*.cbor" ":!*.bcode" ":!*.ico" ":!*/twiddles.cu" | typos --file-list - && echo "No typos found"
.PHONY: clippy_gpu # Run clippy lints on tfhe with "gpu" enabled
clippy_gpu: install_rs_check_toolchain

View File

@@ -1,14 +1,5 @@
use std::path::PathBuf;
fn get_linux_distribution_name() -> Option<String> {
let content = std::fs::read_to_string("/etc/os-release").ok()?;
for line in content.lines() {
if let Some(value) = line.strip_prefix("NAME=") {
return Some(value.trim_matches('"').to_string());
}
}
None
}
use std::process::Command;
fn main() {
if let Ok(val) = std::env::var("DOCS_RS") {
@@ -37,7 +28,9 @@ fn main() {
println!("cargo::rerun-if-changed=src");
if std::env::consts::OS == "linux" {
if get_linux_distribution_name().as_deref() != Some("Ubuntu") {
let output = Command::new("./get_os_name.sh").output().unwrap();
let distribution = String::from_utf8(output.stdout).unwrap();
if distribution != "Ubuntu\n" {
println!(
"cargo:warning=This Linux distribution is not officially supported. \
Only Ubuntu is supported by tfhe-cuda-backend at this time. Build may fail\n"

View File

@@ -721,7 +721,7 @@ void cuda_integer_grouped_oprf_custom_range_64_async(
uint32_t num_blocks_intermediate, const void *seeded_lwe_input,
const uint64_t *decomposed_scalar, const uint64_t *has_at_least_one_set,
uint32_t num_scalars, uint32_t shift, int8_t *mem, void *const *bsks,
void *const *compute_bsks, void *const *ksks);
void *const *ksks);
void cleanup_cuda_integer_grouped_oprf_custom_range_64(CudaStreamsFFI streams,
int8_t **mem_ptr_void);

View File

@@ -72,13 +72,13 @@ void cuda_integer_grouped_oprf_custom_range_64_async(
uint32_t num_blocks_intermediate, const void *seeded_lwe_input,
const uint64_t *decomposed_scalar, const uint64_t *has_at_least_one_set,
uint32_t num_scalars, uint32_t shift, int8_t *mem, void *const *bsks,
void *const *compute_bsks, void *const *ksks) {
void *const *ksks) {
host_integer_grouped_oprf_custom_range<uint64_t>(
CudaStreams(streams), radix_lwe_out, num_blocks_intermediate,
(const uint64_t *)seeded_lwe_input, decomposed_scalar,
has_at_least_one_set, num_scalars, shift,
(int_grouped_oprf_custom_range_memory<uint64_t> *)mem, bsks, compute_bsks,
(int_grouped_oprf_custom_range_memory<uint64_t> *)mem, bsks,
(uint64_t *const *)ksks);
}

View File

@@ -114,7 +114,7 @@ void host_integer_grouped_oprf_custom_range(
const Torus *decomposed_scalar, const Torus *has_at_least_one_set,
uint32_t num_scalars, uint32_t shift,
int_grouped_oprf_custom_range_memory<Torus> *mem_ptr, void *const *bsks,
void *const *compute_bsks, Torus *const *ksks) {
Torus *const *ksks) {
CudaRadixCiphertextFFI *computation_buffer = mem_ptr->tmp_oprf_output;
set_zero_radix_ciphertext_slice_async<Torus>(
@@ -127,12 +127,12 @@ void host_integer_grouped_oprf_custom_range(
host_integer_scalar_mul_radix<Torus>(
streams, computation_buffer, decomposed_scalar, has_at_least_one_set,
mem_ptr->scalar_mul_buffer, compute_bsks, ksks,
mem_ptr->params.message_modulus, num_scalars);
mem_ptr->scalar_mul_buffer, bsks, ksks, mem_ptr->params.message_modulus,
num_scalars);
host_logical_scalar_shift_inplace<Torus>(
streams, computation_buffer, shift, mem_ptr->logical_scalar_shift_buffer,
compute_bsks, ksks, num_blocks_intermediate);
host_logical_scalar_shift_inplace<Torus>(streams, computation_buffer, shift,
mem_ptr->logical_scalar_shift_buffer,
bsks, ksks, num_blocks_intermediate);
uint32_t num_blocks_output = radix_lwe_out->num_radix_blocks;
uint32_t blocks_to_copy =

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
cat /etc/os-release | grep "\<NAME\>" | sed "s/NAME=\"//g" | sed "s/\"//g"

View File

@@ -1647,7 +1647,6 @@ unsafe extern "C" {
shift: u32,
mem: *mut i8,
bsks: *const *mut ffi::c_void,
compute_bsks: *const *mut ffi::c_void,
ksks: *const *mut ffi::c_void,
);
}

View File

@@ -156,7 +156,7 @@ impl HpuVarWrapped {
{
let mut inner = var.inner.lock().unwrap();
for (slot, ct) in std::iter::zip(inner.bundle.iter_mut(), ct) {
for (slot, ct) in std::iter::zip(inner.bundle.iter_mut(), ct.into_iter()) {
#[cfg(feature = "io-dump")]
let params = ct.params().clone();
for (id, cut) in ct.into_container().iter().enumerate() {

View File

@@ -1,14 +1,5 @@
use std::path::PathBuf;
fn get_linux_distribution_name() -> Option<String> {
let content = std::fs::read_to_string("/etc/os-release").ok()?;
for line in content.lines() {
if let Some(value) = line.strip_prefix("NAME=") {
return Some(value.trim_matches('"').to_string());
}
}
None
}
use std::process::Command;
fn main() {
// Handle docs.rs builds (no CUDA available)
@@ -38,10 +29,16 @@ fn main() {
println!("cargo:rustc-link-arg=-Wl,--allow-multiple-definition");
println!("cargo:rustc-link-arg=-Wl,--no-as-needed");
// Check Linux distribution (reuse script from tfhe-cuda-backend)
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")
.expect("CARGO_MANIFEST_DIR must be set by cargo during build");
if get_linux_distribution_name().as_deref() != Some("Ubuntu") {
let script_path = PathBuf::from(&manifest_dir).join("../tfhe-cuda-backend/get_os_name.sh");
let output = Command::new(&script_path)
.output()
.expect("Failed to run get_os_name.sh — is tfhe-cuda-backend present?");
let distribution =
String::from_utf8(output.stdout).expect("get_os_name.sh output must be valid UTF-8");
if distribution != "Ubuntu\n" {
println!(
"cargo:warning=This Linux distribution is not officially supported. \
Only Ubuntu is supported by zk-cuda-backend at this time. Build may fail\n"

View File

@@ -71,6 +71,11 @@ set(CMAKE_CUDA_FLAGS_DEBUG "-g -O0 -G")
# Additional CUDA flags (aligned with tfhe-cuda-backend)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -Wall -Xcompiler -Wextra --use_fast_math --expt-relaxed-constexpr")
# =============================================================================
# Path to tfhe-cuda-backend for device utilities
# =============================================================================
set(TFHE_CUDA_BACKEND_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../tfhe-cuda-backend/cuda)
# Core source files (without device utilities) Device utilities come from tfhe-cuda-backend.
set(FP_CORE_SOURCES src/primitives/fp.cu src/primitives/fp2.cu src/curve.cu src/msm/pippenger/msm_pippenger.cu
src/msm/msm.cu)
@@ -107,7 +112,7 @@ endif()
target_link_libraries(zk_cuda_backend PUBLIC cudart)
# Include both local headers and tfhe-cuda-backend headers (for device.h)
target_include_directories(zk_cuda_backend PUBLIC include ../src/include)
target_include_directories(zk_cuda_backend PUBLIC include ../src/include ${TFHE_CUDA_BACKEND_DIR}/include)
# =============================================================================
# Tests and Benchmarks (optional, controlled by ZK_CUDA_BACKEND_BUILD_TESTS/BENCHMARKS)
@@ -130,3 +135,4 @@ message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")
message(STATUS "C++ standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "CUDA standard: ${CMAKE_CUDA_STANDARD}")
message(STATUS "tfhe-cuda-backend path: ${TFHE_CUDA_BACKEND_DIR}")

View File

@@ -1,35 +0,0 @@
#pragma once
#include <cstddef>
#include <cstdio>
#include "device.h"
// Variadic checked multiplication of size_t values.
// Folds left-to-right using __builtin_mul_overflow, returning true on overflow.
// On overflow the value written to *out is unspecified.
template <typename... Args>
inline bool checked_mul(size_t *out, size_t first, Args... rest) {
size_t result = first;
for (size_t value : {static_cast<size_t>(rest)...}) {
if (__builtin_mul_overflow(result, value, &result))
return true;
}
*out = result;
return false;
}
// Variadic safe multiplication: computes the product and panics on overflow.
template <typename... Args> inline size_t safe_mul(size_t first, Args... rest) {
size_t result;
bool overflow = checked_mul(&result, first, rest...);
PANIC_IF_FALSE(!overflow, "multiplication overflow wraps size_t");
return result;
}
// Variadic safe multiplication with an appended sizeof(T) factor.
// Computes (args... * sizeof(T)) with overflow checking.
template <typename T, typename... Args>
inline size_t safe_mul_sizeof(Args... args) {
return safe_mul(args..., sizeof(T));
}

View File

@@ -1,145 +0,0 @@
#ifndef DEVICE_H
#define DEVICE_H
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cuda_runtime.h>
extern "C" {
#define check_cuda_error(ans) \
{ cuda_error((ans), __FILE__, __LINE__); }
inline void cuda_error(cudaError_t code, const char *file, int line) {
if (code != cudaSuccess) {
std::fprintf(stderr, "Cuda error: %s %s %d\n", cudaGetErrorString(code),
file, line);
std::abort();
}
}
// The PANIC macro should be used to validate user-inputs to GPU functions
// it will execute in all targets, including production settings
// e.g., cudaMemCopy to the device should check that the destination pointer is
// a device pointer
#define PANIC(format, ...) \
{ \
std::fprintf(stderr, "%s::%d::%s: panic.\n" format "\n", __FILE__, \
__LINE__, __func__, ##__VA_ARGS__); \
std::abort(); \
}
// This is a generic assertion checking macro with user defined printf-style
// message
#define PANIC_IF_FALSE(cond, format, ...) \
do { \
if (!(cond)) { \
PANIC(format "\n\n %s\n", ##__VA_ARGS__, #cond); \
} \
} while (0)
#ifndef GPU_ASSERTS_DISABLE
// The GPU assert should be used to validate assumptions in algorithms,
// for example, checking that two user-provided quantities have a certain
// relationship or that the size of the buffer provided to a function is
// sufficient when it is filled with some algorithm that depends on
// user-provided inputs e.g., OPRF corrections buffer should not have a size
// higher than the number of blocks in the datatype that is generated
#define GPU_ASSERT(cond, format, ...) \
PANIC_IF_FALSE(cond, format, ##__VA_ARGS__)
#else
#define GPU_ASSERT(cond) \
do { \
} while (0)
#endif
uint32_t cuda_get_device();
void cuda_set_device(uint32_t gpu_index);
cudaEvent_t cuda_create_event(uint32_t gpu_index);
void cuda_event_record(cudaEvent_t event, cudaStream_t stream,
uint32_t gpu_index);
void cuda_stream_wait_event(cudaStream_t stream, cudaEvent_t event,
uint32_t gpu_index);
void cuda_event_destroy(cudaEvent_t event, uint32_t gpu_index);
cudaStream_t cuda_create_stream(uint32_t gpu_index);
void cuda_destroy_stream(cudaStream_t stream, uint32_t gpu_index);
void cuda_synchronize_stream(cudaStream_t stream, uint32_t gpu_index);
uint32_t cuda_is_available();
void *cuda_malloc(uint64_t size, uint32_t gpu_index);
void *cuda_malloc_with_size_tracking_async(uint64_t size, cudaStream_t stream,
uint32_t gpu_index,
uint64_t &size_tracker,
bool allocate_gpu_memory);
void *cuda_malloc_async(uint64_t size, cudaStream_t stream, uint32_t gpu_index);
bool cuda_check_valid_malloc(uint64_t size, uint32_t gpu_index);
uint64_t cuda_device_total_memory(uint32_t gpu_index);
void cuda_memcpy_with_size_tracking_async_to_gpu(void *dest, const void *src,
uint64_t size,
cudaStream_t stream,
uint32_t gpu_index,
bool gpu_memory_allocated);
void cuda_memcpy_async_to_gpu(void *dest, const void *src, uint64_t size,
cudaStream_t stream, uint32_t gpu_index);
void cuda_memcpy_with_size_tracking_async_gpu_to_gpu(
void *dest, void const *src, uint64_t size, cudaStream_t stream,
uint32_t gpu_index, bool gpu_memory_allocated);
void cuda_memcpy_async_gpu_to_gpu(void *dest, void const *src, uint64_t size,
cudaStream_t stream, uint32_t gpu_index);
void cuda_memcpy_gpu_to_gpu(void *dest, void const *src, uint64_t size,
uint32_t gpu_index);
void cuda_memcpy_async_to_cpu(void *dest, const void *src, uint64_t size,
cudaStream_t stream, uint32_t gpu_index);
void cuda_memset_with_size_tracking_async(void *dest, uint64_t val,
uint64_t size, cudaStream_t stream,
uint32_t gpu_index,
bool gpu_memory_allocated);
void cuda_memset_async(void *dest, uint64_t val, uint64_t size,
cudaStream_t stream, uint32_t gpu_index);
int cuda_get_number_of_gpus();
int cuda_get_number_of_sms();
void cuda_synchronize_device(uint32_t gpu_index);
void cuda_drop(void *ptr, uint32_t gpu_index);
void cuda_drop_with_size_tracking_async(void *ptr, cudaStream_t stream,
uint32_t gpu_index,
bool gpu_memory_allocated);
void cuda_drop_async(void *ptr, cudaStream_t stream, uint32_t gpu_index);
}
uint32_t cuda_get_max_shared_memory(uint32_t gpu_index);
uint32_t cuda_get_max_shared_memory_per_block(uint32_t gpu_index);
bool cuda_check_support_cooperative_groups();
bool cuda_check_support_thread_block_clusters();
template <typename Torus>
void cuda_set_value_async(cudaStream_t stream, uint32_t gpu_index,
Torus *d_array, Torus value, Torus n);
#endif

View File

@@ -1,16 +0,0 @@
#ifndef HELPER_PROFILE
#define HELPER_PROFILE
#ifdef USE_NVTOOLS
#include <nvtx3/nvToolsExt.h>
#endif
void cuda_nvtx_label_with_color(const char *name);
void cuda_nvtx_pop();
#define PUSH_RANGE(name) \
{ cuda_nvtx_label_with_color(name); }
#define POP_RANGE() \
{ cuda_nvtx_pop(); }
#endif

View File

@@ -1,43 +0,0 @@
#include "helper_profile.cuh"
#include <stdint.h>
uint32_t adler32(const unsigned char *data) {
const uint32_t MOD_ADLER = 65521;
uint32_t a = 1, b = 0;
size_t index;
for (index = 0; data[index] != 0; ++index) {
a = (a + data[index] * 2) % MOD_ADLER;
b = (b + a) % MOD_ADLER;
}
return (b << 16) | a;
}
void cuda_nvtx_label_with_color(const char *name) {
#ifdef USE_NVTOOLS
int color_id = adler32((const unsigned char *)name);
int r, g, b;
r = color_id & 0x000000ff;
g = (color_id & 0x000ff000) >> 12;
b = (color_id & 0x0ff00000) >> 20;
if (r < 64 & g < 64 & b < 64) {
r = r * 3;
g = g * 3 + 64;
b = b * 4;
}
color_id = 0xff000000 | (r << 16) | (g << 8) | (b);
nvtxEventAttributes_t eventAttrib = {0};
eventAttrib.version = NVTX_VERSION;
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
eventAttrib.colorType = NVTX_COLOR_ARGB;
eventAttrib.color = color_id;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
#endif
}
void cuda_nvtx_pop() {
#ifdef USE_NVTOOLS
nvtxRangePop();
#endif
}

View File

@@ -11,7 +11,7 @@
#include <stddef.h>
#include <cstring>
#include "helper_profile.cuh"
#include "../../tfhe-cuda-backend/cuda/src/utils/helper_profile.cuh"
// C++ helper functions (not exported, used internally)
// These can call template functions since they have C++ linkage

View File

@@ -1 +1 @@
nightly-2026-04-22
nightly-2026-01-14

View File

@@ -25,7 +25,7 @@ use tfhe::{
CompressedKVStore, CompressedPublicKey, CompressedServerKey,
CompressedSquashedNoiseCiphertextList, CompressedSquashedNoiseCiphertextListBuilder, FheBool,
FheInt8, FheUint32, FheUint64, FheUint8, ReRandomizationContext, ReRandomizationMode,
ReRandomizationSupport, Seed, ServerKey, SquashedNoiseFheBool, SquashedNoiseFheInt,
ReRandomizationSupport, ServerKey, SquashedNoiseFheBool, SquashedNoiseFheInt,
SquashedNoiseFheUint,
};
use tfhe_backward_compat_data::load::{
@@ -748,22 +748,6 @@ fn test_hl_key_features(
}
}
// OPRF: check that oblivious pseudo-random generation works with the dedicated key.
// The decrypted values only need to be within range; the seed is deterministic but we
// don't compare to specific bit values (those are validated in the unit tests).
if server_key.supports_oprf() {
let seed = Seed(42u128);
let rand_bool = FheBool::generate_oblivious_pseudo_random(seed);
let _: bool = rand_bool.decrypt(client_key);
let rand_uint = FheUint8::generate_oblivious_pseudo_random(seed);
let _: u8 = rand_uint.decrypt(client_key);
let rand_int = FheInt8::generate_oblivious_pseudo_random(seed);
let _: i8 = rand_int.decrypt(client_key);
}
Ok(())
}

View File

@@ -8,7 +8,6 @@ use rayon::prelude::*;
#[cfg(any(feature = "gpu", feature = "hpu"))]
use std::cmp::max;
use tfhe::integer::keycache::KEY_CACHE;
use tfhe::integer::oprf::{OprfPrivateKey, OprfServerKey};
use tfhe::integer::IntegerKeyKind;
use tfhe::keycache::NamedParam;
#[cfg(any(feature = "gpu", feature = "hpu"))]
@@ -36,42 +35,32 @@ pub fn unsigned_oprf(c: &mut Criterion) {
format!("{bench_name}_bounded::{param_name}::{bit_size}_bits");
bench_group.bench_function(&bench_id_oprf, |b| {
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
let oprf_pk = OprfPrivateKey::new(&cks);
let oprf_sk = OprfServerKey::new(&oprf_pk, &cks).unwrap();
let (_, sk) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
b.iter(|| {
_ = black_box(
oprf_sk.par_generate_oblivious_pseudo_random_unsigned_integer(
Seed(0),
num_block as u64,
&sks,
),
);
_ = black_box(sk.par_generate_oblivious_pseudo_random_unsigned_integer(
Seed(0),
num_block as u64,
));
})
});
bench_group.bench_function(&bench_id_oprf_bounded, |b| {
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
let oprf_pk = OprfPrivateKey::new(&cks);
let oprf_sk = OprfServerKey::new(&oprf_pk, &cks).unwrap();
let (_, sk) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
b.iter(|| {
_ = black_box(
oprf_sk.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
sk.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
Seed(0),
bit_size as u64,
num_block as u64,
&sks,
),
);
})
});
}
BenchmarkType::Throughput => {
let (cks, sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
let oprf_pk = OprfPrivateKey::new(&cks);
let oprf_sk = OprfServerKey::new(&oprf_pk, &cks).unwrap();
let (_, sk) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
bench_id_oprf = format!("{bench_name}::throughput::{param_name}::{bit_size}_bits");
bench_id_oprf_bounded =
@@ -82,11 +71,10 @@ pub fn unsigned_oprf(c: &mut Criterion) {
{
// Execute the operation once to know its cost.
reset_pbs_count();
oprf_sk.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
sk.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
Seed(0),
bit_size as u64,
num_block as u64,
&sks,
);
let pbs_count = max(get_pbs_count(), 1);
throughput_num_threads(num_block, pbs_count)
@@ -97,13 +85,11 @@ pub fn unsigned_oprf(c: &mut Criterion) {
let setup = |_batch_size: usize| ();
let run = |_: &mut (), batch_size: usize| {
(0..batch_size).into_par_iter().for_each(|_| {
oprf_sk
.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
Seed(0),
bit_size as u64,
num_block as u64,
&sks,
);
sk.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
Seed(0),
bit_size as u64,
num_block as u64,
);
});
};
find_optimal_batch(run, setup) as u64
@@ -114,10 +100,9 @@ pub fn unsigned_oprf(c: &mut Criterion) {
bench_group.bench_function(&bench_id_oprf, |b| {
b.iter(|| {
(0..elements).into_par_iter().for_each(|_| {
oprf_sk.par_generate_oblivious_pseudo_random_unsigned_integer(
sk.par_generate_oblivious_pseudo_random_unsigned_integer(
Seed(0),
num_block as u64,
&sks,
);
})
})
@@ -126,11 +111,10 @@ pub fn unsigned_oprf(c: &mut Criterion) {
bench_group.bench_function(&bench_id_oprf_bounded, |b| {
b.iter(|| {
(0..elements).into_par_iter().for_each(|_| {
oprf_sk.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
sk.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
Seed(0),
bit_size as u64,
num_block as u64,
&sks,
);
})
})
@@ -164,8 +148,6 @@ pub mod cuda {
use criterion::black_box;
use tfhe::core_crypto::gpu::{get_number_of_gpus, CudaStreams};
use tfhe::integer::gpu::server_key::CudaServerKey;
use tfhe::integer::gpu::CudaOprfServerKey;
use tfhe::integer::oprf::{CompressedOprfServerKey, OprfPrivateKey};
use tfhe::GpuIndex;
use tfhe_csprng::seeders::Seed;
@@ -195,18 +177,12 @@ pub mod cuda {
let (cks, _cpu_sks) =
KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
let gpu_sks = CudaServerKey::new(&cks, &streams);
let oprf_pk = OprfPrivateKey::new(&cks);
let compressed_oprf_sk =
CompressedOprfServerKey::new(&oprf_pk, &cks).unwrap();
let cuda_oprf_sk =
CudaOprfServerKey::decompress_from_cpu(&compressed_oprf_sk, &streams);
b.iter(|| {
_ = black_box(
cuda_oprf_sk.par_generate_oblivious_pseudo_random_unsigned_integer(
gpu_sks.par_generate_oblivious_pseudo_random_unsigned_integer(
Seed(0),
num_block as u64,
&gpu_sks,
&streams,
),
);
@@ -217,20 +193,14 @@ pub mod cuda {
let (cks, _cpu_sks) =
KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
let gpu_sks = CudaServerKey::new(&cks, &streams);
let oprf_pk = OprfPrivateKey::new(&cks);
let compressed_oprf_sk =
CompressedOprfServerKey::new(&oprf_pk, &cks).unwrap();
let cuda_oprf_sk =
CudaOprfServerKey::decompress_from_cpu(&compressed_oprf_sk, &streams);
b.iter(|| {
_ = black_box(
cuda_oprf_sk
gpu_sks
.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
Seed(0),
bit_size as u64,
num_block as u64,
&gpu_sks,
&streams,
),
);
@@ -240,25 +210,13 @@ pub mod cuda {
BenchmarkType::Throughput => {
let (cks, cpu_sks) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
let gpu_sks_vec = cuda_local_keys(&cks);
let cpu_oprf_pk = OprfPrivateKey::new(&cks);
let cpu_oprf_sk = OprfServerKey::new(&cpu_oprf_pk, &cks).unwrap();
let compressed_oprf_sk =
CompressedOprfServerKey::new(&cpu_oprf_pk, &cks).unwrap();
// One CudaOprfServerKey per GPU, matching `gpu_sks_vec`.
let cuda_oprf_sks_vec: Vec<CudaOprfServerKey> = (0..get_number_of_gpus())
.map(|gpu_index| {
let stream = CudaStreams::new_single_gpu(GpuIndex::new(gpu_index));
CudaOprfServerKey::decompress_from_cpu(&compressed_oprf_sk, &stream)
})
.collect();
// Execute the operation once to know its cost.
reset_pbs_count();
cpu_oprf_sk.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
cpu_sks.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
Seed(0),
bit_size as u64,
num_block as u64,
&cpu_sks,
);
let pbs_count = max(get_pbs_count(), 1); // Operation might not perform any PBS, so we take 1 as default
@@ -274,11 +232,10 @@ pub mod cuda {
(0..elements).into_par_iter().for_each(|i| {
let gpu_index: u32 = i as u32 % get_number_of_gpus();
let stream = CudaStreams::new_single_gpu(GpuIndex::new(gpu_index));
cuda_oprf_sks_vec[gpu_index as usize]
gpu_sks_vec[gpu_index as usize]
.par_generate_oblivious_pseudo_random_unsigned_integer(
Seed(0),
num_block as u64,
&gpu_sks_vec[gpu_index as usize],
&stream,
);
})
@@ -290,12 +247,11 @@ pub mod cuda {
(0..elements).into_par_iter().for_each(|i| {
let gpu_index: u32 = i as u32 % get_number_of_gpus();
let stream = CudaStreams::new_single_gpu(GpuIndex::new(gpu_index));
cuda_oprf_sks_vec[gpu_index as usize]
gpu_sks_vec[gpu_index as usize]
.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
Seed(0),
bit_size as u64,
num_block as u64,
&gpu_sks_vec[gpu_index as usize],
&stream,
);
})

View File

@@ -2,7 +2,6 @@ use benchmark::params_aliases::*;
use criterion::{black_box, criterion_group, Criterion};
use tfhe::keycache::NamedParam;
use tfhe::shortint::keycache::KEY_CACHE;
use tfhe::shortint::oprf::{OprfPrivateKey, OprfServerKey};
use tfhe_csprng::seeders::Seed;
fn oprf(c: &mut Criterion) {
@@ -13,15 +12,11 @@ fn oprf(c: &mut Criterion) {
let param = BENCH_PARAM_MESSAGE_2_CARRY_2_KS_PBS;
let keys = KEY_CACHE.get_from_param(param);
let cks = keys.client_key();
let sks = keys.server_key();
let oprf_pk = OprfPrivateKey::new(cks);
let oprf_sk = OprfServerKey::new(&oprf_pk, cks).unwrap();
bench_group.bench_function(format!("2-bits-oprf::{}", param.name()), |b| {
b.iter(|| {
_ = black_box(oprf_sk.generate_oblivious_pseudo_random(Seed(0), 2, sks));
_ = black_box(sks.generate_oblivious_pseudo_random(Seed(0), 2));
})
});
}

View File

@@ -168,7 +168,7 @@ mod generic_tests {
fn test_xof_seed_getters() {
let seed_bytes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
let bits = u128::from_le_bytes(seed_bytes);
let dsep = *b"tfheksps";
let dsep = [b't', b'f', b'h', b'e', b'k', b's', b'p', b's'];
let seed = XofSeed::new_u128(bits, dsep);
let s = u128::from_le_bytes(seed.seed().try_into().unwrap());

View File

@@ -64,7 +64,7 @@ tfhe-fft = { version = "0.10.1", path = "../tfhe-fft", features = [
"serde",
"fft128",
] }
tfhe-ntt = { version = "0.7.1", path = "../tfhe-ntt" }
tfhe-ntt = { version = "0.7.0", path = "../tfhe-ntt" }
pulp = { workspace = true, features = ["default"] }
tfhe-cuda-backend = { version = "0.14.0", path = "../backends/tfhe-cuda-backend", optional = true }
aligned-vec = { workspace = true, features = ["default", "serde"] }

View File

@@ -75,11 +75,11 @@
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="594.0" y="420.0">121 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="678.0" y="420.0">165 ms</text>
<text dominant-baseline="middle" text-anchor="start" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="6" y="460.0">Leading / Trailing zeros/ones</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="342.0" y="460.0">67.2 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="426.0" y="460.0">70.6 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="510.0" y="460.0">89.8 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="594.0" y="460.0">92.6 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="678.0" y="460.0">113 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="342.0" y="460.0">88.4 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="426.0" y="460.0">148 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="510.0" y="460.0">169 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="594.0" y="460.0">222 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="678.0" y="460.0">275 ms</text>
<text dominant-baseline="middle" text-anchor="start" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="6" y="500.0">Log2</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="342.0" y="500.0">110 ms</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="426.0" y="500.0">163 ms</text>

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -75,11 +75,11 @@
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="594.0" y="420.0">32.5 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="678.0" y="420.0">14.0 ops/s</text>
<text dominant-baseline="middle" text-anchor="start" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="6" y="460.0">Leading / Trailing zeros/ones</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="342.0" y="460.0">824 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="426.0" y="460.0">487 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="510.0" y="460.0">222 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="594.0" y="460.0">119 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="678.0" y="460.0">57.8 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="342.0" y="460.0">625 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="426.0" y="460.0">247 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="510.0" y="460.0">108 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="594.0" y="460.0">44.1 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="678.0" y="460.0">19.0 ops/s</text>
<text dominant-baseline="middle" text-anchor="start" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="6" y="500.0">Log2</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="342.0" y="500.0">542 ops/s</text>
<text dominant-baseline="middle" text-anchor="middle" font-family="Arial" font-size="14" font-weight="normal" fill="black" x="426.0" y="500.0">220 ops/s</text>

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -85,7 +85,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let public_key = tfhe::CompactPublicKey::try_new(&client_key).unwrap();
// This can be left empty, but if provided allows to tie the proof to arbitrary data
let metadata = b"TFHE-rs";
let metadata = [b'T', b'F', b'H', b'E', b'-', b'r', b's'];
let clear_a = random::<u64>();
let clear_b = random::<u64>();
@@ -93,7 +93,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let proven_compact_list = tfhe::ProvenCompactCiphertextList::builder(&public_key)
.push(clear_a)
.push(clear_b)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Verify)?;
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Verify)?;
// Server side
let result = {
@@ -101,7 +101,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// Verify the proofs and expand the ciphertexts
let expander =
proven_compact_list.verify_and_expand(&crs, &public_key, metadata)?;
proven_compact_list.verify_and_expand(&crs, &public_key, &metadata)?;
let a: tfhe::FheUint64 = expander.get(0)?.unwrap();
let b: tfhe::FheUint64 = expander.get(1)?.unwrap();

View File

@@ -120,7 +120,7 @@ pub fn main() {
let rerand_domain_separator = *b"TFHE_Rrd";
let crs = CompactPkeCrs::from_config(config, 2048).unwrap();
let metadata = b"rerand";
let metadata = [b'r', b'e', b'r', b'a', b'n', b'd'];
set_server_key(sks);
@@ -132,7 +132,7 @@ pub fn main() {
.push(clear_a)
.push(clear_b)
.push(false)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
// Simulate a 256 bits nonce
@@ -151,7 +151,7 @@ pub fn main() {
// Verify, re_randomize and expand
let expander = compact_list
.verify_re_randomize_and_expand(&crs, &cpk, metadata, seed_gen.next_seed().unwrap())
.verify_re_randomize_and_expand(&crs, &cpk, &metadata, seed_gen.next_seed().unwrap())
.unwrap();
let a: FheUint64 = expander.get(0).unwrap().unwrap();

View File

@@ -46,7 +46,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let server_key = tfhe::ServerKey::new(&client_key);
let public_key = tfhe::CompactPublicKey::try_new(&client_key).unwrap();
// This can be left empty, but if provided allows to tie the proof to arbitrary data
let metadata = b"TFHE-rs";
let metadata = [b'T', b'F', b'H', b'E', b'-', b'r', b's'];
let clear_a = rng.gen::<u64>();
let clear_b = rng.gen::<u64>();
@@ -54,7 +54,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let proven_compact_list = tfhe::ProvenCompactCiphertextList::builder(&public_key)
.push(clear_a)
.push(clear_b)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Verify)?;
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Verify)?;
// Server side
let result = {
@@ -62,7 +62,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// Verify the ciphertexts
let expander =
proven_compact_list.verify_and_expand(&crs, &public_key, metadata)?;
proven_compact_list.verify_and_expand(&crs, &public_key, &metadata)?;
let a: tfhe::FheUint64 = expander.get(0)?.unwrap();
let b: tfhe::FheUint64 = expander.get(1)?.unwrap();
@@ -118,7 +118,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let server_key = tfhe::ServerKey::new(&client_key);
let public_key = tfhe::CompactPublicKey::try_new(&client_key).unwrap();
// This can be left empty, but if provided allows to tie the proof to arbitrary data
let metadata = b"TFHE-rs";
let metadata = [b'T', b'F', b'H', b'E', b'-', b'r', b's'];
let clear_a = rng.gen::<u64>();
let clear_b = rng.gen::<u64>();
@@ -126,7 +126,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let proven_compact_list = tfhe::ProvenCompactCiphertextList::builder(&public_key)
.push(clear_a)
.push(clear_b)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Verify)?;
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Verify)?;
// Server side
let result = {
@@ -134,7 +134,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
// Verify the ciphertexts
let expander =
proven_compact_list.verify_and_expand(&crs, &public_key, metadata)?;
proven_compact_list.verify_and_expand(&crs, &public_key, &metadata)?;
let a: tfhe::FheUint64 = expander.get(0)?.unwrap();
let b: tfhe::FheUint64 = expander.get(1)?.unwrap();

View File

@@ -252,7 +252,9 @@ where
))
}
const NON_ESCAPABLE_SYMBOLS: [u8; 14] = *b"&;:,`~-_!@#%'\"";
const NON_ESCAPABLE_SYMBOLS: [u8; 14] = [
b'&', b';', b':', b',', b'`', b'~', b'-', b'_', b'!', b'@', b'#', b'%', b'\'', b'\"',
];
fn atom<Input>() -> impl Parser<Input, Output = RegExpr>
where

View File

@@ -1251,7 +1251,7 @@ pub fn encrypt_lwe_ciphertext_iterator_with_seeded_public_key<Scalar, KeyCont, O
}
}
for (output_ct, plaintext) in output.iter_mut().zip(encoded) {
for (output_ct, plaintext) in output.iter_mut().zip(encoded.into_iter()) {
lwe_ciphertext_plaintext_add_assign(output_ct, plaintext);
}
}
@@ -2123,7 +2123,7 @@ pub fn encrypt_lwe_ciphertext_with_compact_public_key<
///
/// // We can add custom metadata that will be required for verification, allowing to tie the proof
/// // to some arbitrary data.
/// let metadata = b"TFHE-rs";
/// let metadata = [b'T', b'F', b'H', b'E', b'-', b'r', b's'];
///
/// // Create the PRNG
/// let mut seeder = new_seeder();
@@ -2170,14 +2170,14 @@ pub fn encrypt_lwe_ciphertext_with_compact_public_key<
/// glwe_noise_distribution,
/// encryption_generator.noise_generator_mut(),
/// &crs,
/// metadata,
/// &metadata,
/// ZkComputeLoad::Proof,
/// )
/// .unwrap();
///
/// // verify the ciphertext list with the proof
/// assert!(
/// verify_lwe_ciphertext(&lwe, &lwe_compact_public_key, &proof, &crs, metadata).is_valid()
/// verify_lwe_ciphertext(&lwe, &lwe_compact_public_key, &proof, &crs, &metadata).is_valid()
/// );
///
/// let decrypted_plaintext = decrypt_lwe_ciphertext(&lwe_secret_key, &lwe);
@@ -2572,7 +2572,7 @@ pub fn encrypt_lwe_compact_ciphertext_list_with_compact_public_key<
///
/// // We can add custom metadata that will be required for verification, allowing to tie the proof
/// // to some arbitrary data.
/// let metadata = b"TFHE-rs";
/// let metadata = [b'T', b'F', b'H', b'E', b'-', b'r', b's'];
///
/// // Create the PRNG
/// let mut seeder = new_seeder();
@@ -2623,7 +2623,7 @@ pub fn encrypt_lwe_compact_ciphertext_list_with_compact_public_key<
/// glwe_noise_distribution,
/// encryption_generator.noise_generator_mut(),
/// &crs,
/// metadata,
/// &metadata,
/// ZkComputeLoad::Proof,
/// )
/// .unwrap();
@@ -2634,7 +2634,7 @@ pub fn encrypt_lwe_compact_ciphertext_list_with_compact_public_key<
/// &lwe_compact_public_key,
/// &proof,
/// &crs,
/// metadata,
/// &metadata,
/// )
/// .is_valid());
///
@@ -3045,7 +3045,7 @@ pub fn par_encrypt_lwe_compact_ciphertext_list_with_compact_public_key<
///
/// // We can add custom metadata that will be required for verification, allowing to tie the proof
/// // to some arbitrary data.
/// let metadata = b"TFHE-rs";
/// let metadata = [b'T', b'F', b'H', b'E', b'-', b'r', b's'];
///
/// // Create the PRNG
/// let mut seeder = new_seeder();
@@ -3096,7 +3096,7 @@ pub fn par_encrypt_lwe_compact_ciphertext_list_with_compact_public_key<
/// glwe_noise_distribution,
/// encryption_generator.noise_generator_mut(),
/// &crs,
/// metadata,
/// &metadata,
/// ZkComputeLoad::Proof,
/// )
/// .unwrap();
@@ -3107,7 +3107,7 @@ pub fn par_encrypt_lwe_compact_ciphertext_list_with_compact_public_key<
/// &lwe_compact_public_key,
/// &proof,
/// &crs,
/// metadata,
/// &metadata,
/// )
/// .is_valid());
///

View File

@@ -1010,7 +1010,7 @@ fn lwe_compact_public_encrypt_prove_verify_decrypt_custom_mod<Scalar>(
let message_modulus_log = params.message_modulus_log;
let encoding_with_padding = get_encoding_with_padding(ciphertext_modulus);
let metadata = b"core";
let metadata = [b'c', b'o', b'r', b'e'];
let mut rsc = TestResources::new();
let mut random_generator = RandomGenerator::<DefaultRandomGenerator>::new(rsc.seeder.seed());
@@ -1073,7 +1073,7 @@ fn lwe_compact_public_encrypt_prove_verify_decrypt_custom_mod<Scalar>(
glwe_noise_distribution,
rsc.encryption_random_generator.noise_generator_mut(),
crs,
metadata,
&metadata,
ZkComputeLoad::Proof,
)
.unwrap();
@@ -1090,13 +1090,13 @@ fn lwe_compact_public_encrypt_prove_verify_decrypt_custom_mod<Scalar>(
assert_eq!(msg, decoded);
// Verify the proof
assert!(verify_lwe_ciphertext(&ct, &pk, &proof, crs, metadata).is_valid());
assert!(verify_lwe_ciphertext(&ct, &pk, &proof, crs, &metadata).is_valid());
// verify proof with invalid ciphertext
let index = random_generator.gen::<usize>() % ct.as_ref().len();
let value_to_add = random_generator.gen::<Scalar>();
ct.as_mut()[index] = ct.as_mut()[index].wrapping_add(value_to_add);
assert!(verify_lwe_ciphertext(&ct, &pk, &proof, crs, metadata).is_invalid());
assert!(verify_lwe_ciphertext(&ct, &pk, &proof, crs, &metadata).is_invalid());
}
// In coverage, we break after one while loop iteration, changing message values does
@@ -1122,7 +1122,7 @@ fn test_par_compact_lwe_list_public_key_encryption_and_proof() {
let glwe_noise_distribution = TUniform::new(9);
let ciphertext_modulus = CiphertextModulus::new_native();
let metadata = b"core";
let metadata = [b'c', b'o', b'r', b'e'];
let delta_log = 59;
let delta = 1u64 << delta_log;
@@ -1195,7 +1195,7 @@ fn test_par_compact_lwe_list_public_key_encryption_and_proof() {
glwe_noise_distribution,
encryption_random_generator.noise_generator_mut(),
&crs,
metadata,
&metadata,
ZkComputeLoad::Proof,
)
.unwrap();
@@ -1205,7 +1205,7 @@ fn test_par_compact_lwe_list_public_key_encryption_and_proof() {
&compact_lwe_pk,
&proof,
&crs,
metadata
&metadata
)
.is_valid());
@@ -1236,7 +1236,7 @@ fn test_par_compact_lwe_list_public_key_encryption_and_proof() {
&compact_lwe_pk,
&proof,
&crs,
metadata
&metadata
)
.is_invalid());
@@ -1284,7 +1284,7 @@ fn test_par_compact_lwe_list_public_key_encryption_and_proof() {
glwe_noise_distribution,
encryption_random_generator.noise_generator_mut(),
&crs,
metadata,
&metadata,
ZkComputeLoad::Proof,
)
.unwrap();
@@ -1294,7 +1294,7 @@ fn test_par_compact_lwe_list_public_key_encryption_and_proof() {
&compact_lwe_pk,
&proof,
&crs,
metadata
&metadata
)
.is_valid());
@@ -1325,7 +1325,7 @@ fn test_par_compact_lwe_list_public_key_encryption_and_proof() {
&compact_lwe_pk,
&proof,
&crs,
metadata
&metadata
)
.is_invalid());

View File

@@ -538,5 +538,4 @@ macro_rules! create_parameterized_test_with_non_native_parameters {
};
}
pub(crate) use create_parameterized_test;
pub(crate) use create_parameterized_test_with_non_native_parameters;
pub(crate) use {create_parameterized_test, create_parameterized_test_with_non_native_parameters};

View File

@@ -19,7 +19,7 @@ pub fn pbs_variance_132_bits_security_gaussian(
lwe_dimension.0 as f64,
glwe_dimension.0 as f64,
polynomial_size.0 as f64,
var_min.0,
var_min.0 as f64,
decomposition_level_count.0 as f64,
decomposition_base_log.0 as f64,
ciphertext_modulus,
@@ -45,7 +45,7 @@ pub fn pbs_variance_132_bits_security_tuniform(
lwe_dimension.0 as f64,
glwe_dimension.0 as f64,
polynomial_size.0 as f64,
var_min.0,
var_min.0 as f64,
decomposition_level_count.0 as f64,
decomposition_base_log.0 as f64,
ciphertext_modulus,

View File

@@ -53,7 +53,7 @@ macro_rules! implement_gaussian {
for a in uniform_rand_bytes_v.iter_mut() {
*a = generator.generate_next();
}
let size = <$T as crate::core_crypto::commons::numeric::Numeric>::BITS as i32;
let size = <$T>::BITS as i32;
let mut u: $T = <$S>::from_le_bytes(uniform_rand_bytes_u).cast_into();
u *= <$T>::TWO.powi(-size + 1);
let mut v: $T = <$S>::from_le_bytes(uniform_rand_bytes_v).cast_into();

View File

@@ -102,7 +102,7 @@ macro_rules! implement {
self.floor()
}
fn to_bit_string(&self) -> String {
if <Self as Numeric>::BITS == 32 {
if Self::BITS == 32 {
let mut bit_string = format!("{:032b}", self.to_bits());
bit_string.insert(1, ' ');
bit_string.insert(10, ' ');

View File

@@ -99,6 +99,7 @@ macro_rules! create_gpu_multi_bit_ks32_parameterized_test{
}
use crate::core_crypto::gpu::algorithms::test::params::MultiBitTestKS32Params;
use crate::core_crypto::gpu::lwe_packing_keyswitch_key::CudaLwePackingKeyswitchKey;
use create_gpu_multi_bit_ks32_parameterized_test;
use create_gpu_multi_bit_parameterized_test;
use create_gpu_parameterized_test;
use {
create_gpu_multi_bit_ks32_parameterized_test, create_gpu_multi_bit_parameterized_test,
create_gpu_parameterized_test,
};

View File

@@ -10,10 +10,8 @@ use crate::integer::compression_keys::{
use crate::integer::noise_squashing::{
CompressedNoiseSquashingKey, NoiseSquashingKey, NoiseSquashingPrivateKey,
};
use crate::shortint::parameters::list_compression::CompressionParameters;
use crate::shortint::parameters::{
CompactPublicKeyEncryptionParameters, EncryptionKeyChoice, NoiseSquashingCompressionParameters,
NoiseSquashingParameters, ReRandomizationParameters, ShortintKeySwitchingParameters,
EncryptionKeyChoice, ReRandomizationParameters, ShortintKeySwitchingParameters,
};
use crate::Tag;
use std::convert::Infallible;
@@ -77,9 +75,8 @@ impl Upgrade<PublicKey> for PublicKeyV0 {
type Error = Infallible;
fn upgrade(self) -> Result<PublicKey, Self::Error> {
let Self { key } = self;
Ok(PublicKey {
key,
key: self.key,
tag: Tag::default(),
})
}
@@ -100,9 +97,8 @@ impl Upgrade<CompactPublicKey> for CompactPublicKeyV0 {
type Error = Infallible;
fn upgrade(self) -> Result<CompactPublicKey, Self::Error> {
let Self { key } = self;
Ok(CompactPublicKey {
key,
key: self.key,
tag: Tag::default(),
})
}
@@ -123,9 +119,8 @@ impl Upgrade<CompressedPublicKey> for CompressedPublicKeyV0 {
type Error = Infallible;
fn upgrade(self) -> Result<CompressedPublicKey, Self::Error> {
let Self { key } = self;
Ok(CompressedPublicKey {
key,
key: self.key,
tag: Tag::default(),
})
}
@@ -146,9 +141,8 @@ impl Upgrade<CompressedCompactPublicKey> for CompressedCompactPublicKeyV0 {
type Error = Infallible;
fn upgrade(self) -> Result<CompressedCompactPublicKey, Self::Error> {
let Self { key } = self;
Ok(CompressedCompactPublicKey {
key,
key: self.key,
tag: Tag::default(),
})
}
@@ -160,48 +154,10 @@ pub enum CompressedCompactPublicKeyVersions {
V1(CompressedCompactPublicKey),
}
#[derive(Version)]
pub(crate) struct IntegerConfigV0 {
pub(crate) block_parameters: crate::shortint::atomic_pattern::AtomicPatternParameters,
pub(crate) dedicated_compact_public_key_parameters: Option<(
CompactPublicKeyEncryptionParameters,
ShortintKeySwitchingParameters,
)>,
pub(crate) compression_parameters: Option<CompressionParameters>,
pub(crate) noise_squashing_parameters: Option<NoiseSquashingParameters>,
pub(crate) noise_squashing_compression_parameters: Option<NoiseSquashingCompressionParameters>,
pub(crate) cpk_re_randomization_params: Option<ReRandomizationParameters>,
}
impl Upgrade<IntegerConfig> for IntegerConfigV0 {
type Error = Infallible;
fn upgrade(self) -> Result<IntegerConfig, Self::Error> {
let Self {
block_parameters,
dedicated_compact_public_key_parameters,
compression_parameters,
noise_squashing_parameters,
noise_squashing_compression_parameters,
cpk_re_randomization_params,
} = self;
Ok(IntegerConfig {
block_parameters,
dedicated_compact_public_key_parameters,
compression_parameters,
noise_squashing_parameters,
noise_squashing_compression_parameters,
cpk_re_randomization_params,
dedicated_oprf_key: false,
})
}
}
#[derive(VersionsDispatch)]
#[allow(unused)]
pub(crate) enum IntegerConfigVersions {
V0(IntegerConfigV0),
V1(IntegerConfig),
V0(IntegerConfig),
}
impl Deprecable for IntegerClientKey {
@@ -220,15 +176,11 @@ impl Upgrade<IntegerClientKeyV3> for IntegerClientKeyV2 {
type Error = Infallible;
fn upgrade(self) -> Result<IntegerClientKeyV3, Self::Error> {
let Self {
key,
dedicated_compact_private_key,
compression_key,
} = self;
Ok(IntegerClientKeyV3 {
key,
dedicated_compact_private_key,
compression_key: compression_key
key: self.key,
dedicated_compact_private_key: self.dedicated_compact_private_key,
compression_key: self
.compression_key
.map(|key| crate::integer::compression_keys::CompressionPrivateKeys { key }),
})
}
@@ -334,10 +286,10 @@ pub(crate) struct IntegerClientKeyV6 {
pub(crate) cpk_re_randomization_ksk_params: Option<ShortintKeySwitchingParameters>,
}
impl Upgrade<IntegerClientKeyV7> for IntegerClientKeyV6 {
impl Upgrade<IntegerClientKey> for IntegerClientKeyV6 {
type Error = crate::Error;
fn upgrade(self) -> Result<IntegerClientKeyV7, Self::Error> {
fn upgrade(self) -> Result<IntegerClientKey, Self::Error> {
let Self {
key,
dedicated_compact_private_key,
@@ -376,39 +328,6 @@ impl Upgrade<IntegerClientKeyV7> for IntegerClientKeyV6 {
}
};
Ok(IntegerClientKeyV7 {
key,
dedicated_compact_private_key,
compression_key,
noise_squashing_private_key,
noise_squashing_compression_private_key,
cpk_re_randomization_params,
})
}
}
#[derive(Version)]
pub(crate) struct IntegerClientKeyV7 {
pub(crate) key: crate::integer::ClientKey,
pub(crate) dedicated_compact_private_key: Option<CompactPrivateKey>,
pub(crate) compression_key: Option<CompressionPrivateKeys>,
pub(crate) noise_squashing_private_key: Option<NoiseSquashingPrivateKey>,
pub(crate) noise_squashing_compression_private_key: Option<NoiseSquashingCompressionPrivateKey>,
pub(crate) cpk_re_randomization_params: Option<ReRandomizationParameters>,
}
impl Upgrade<IntegerClientKey> for IntegerClientKeyV7 {
type Error = Infallible;
fn upgrade(self) -> Result<IntegerClientKey, Self::Error> {
let Self {
key,
dedicated_compact_private_key,
compression_key,
noise_squashing_private_key,
noise_squashing_compression_private_key,
cpk_re_randomization_params,
} = self;
Ok(IntegerClientKey {
key,
dedicated_compact_private_key,
@@ -416,7 +335,6 @@ impl Upgrade<IntegerClientKey> for IntegerClientKeyV7 {
noise_squashing_private_key,
noise_squashing_compression_private_key,
cpk_re_randomization_params,
dedicated_oprf_private_key: None,
})
}
}
@@ -431,8 +349,7 @@ pub(crate) enum IntegerClientKeyVersions {
V4(IntegerClientKeyV4),
V5(IntegerClientKeyV5),
V6(IntegerClientKeyV6),
V7(IntegerClientKeyV7),
V8(IntegerClientKey),
V7(IntegerClientKey),
}
impl Deprecable for IntegerServerKey {
@@ -556,10 +473,10 @@ pub struct IntegerServerKeyV7 {
Option<ReRandomizationKeySwitchingKey>,
}
impl Upgrade<IntegerServerKeyV8> for IntegerServerKeyV7 {
impl Upgrade<IntegerServerKey> for IntegerServerKeyV7 {
type Error = Infallible;
fn upgrade(self) -> Result<IntegerServerKeyV8, Self::Error> {
fn upgrade(self) -> Result<IntegerServerKey, Self::Error> {
let Self {
key,
cpk_key_switching_key_material,
@@ -570,7 +487,7 @@ impl Upgrade<IntegerServerKeyV8> for IntegerServerKeyV7 {
cpk_re_randomization_key_switching_key_material,
} = self;
Ok(IntegerServerKeyV8 {
Ok(IntegerServerKey {
key,
cpk_key_switching_key_material,
compression_key,
@@ -586,44 +503,6 @@ impl Upgrade<IntegerServerKeyV8> for IntegerServerKeyV7 {
}
}
#[derive(Version)]
pub struct IntegerServerKeyV8 {
pub(crate) key: crate::integer::ServerKey,
pub(crate) cpk_key_switching_key_material:
Option<crate::integer::key_switching_key::KeySwitchingKeyMaterial>,
pub(crate) compression_key: Option<CompressionKey>,
pub(crate) decompression_key: Option<DecompressionKey>,
pub(crate) noise_squashing_key: Option<NoiseSquashingKey>,
pub(crate) noise_squashing_compression_key: Option<NoiseSquashingCompressionKey>,
pub(crate) cpk_re_randomization_key: Option<ReRandomizationKey>,
}
impl Upgrade<IntegerServerKey> for IntegerServerKeyV8 {
type Error = Infallible;
fn upgrade(self) -> Result<IntegerServerKey, Self::Error> {
let Self {
key,
cpk_key_switching_key_material,
compression_key,
decompression_key,
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
} = self;
Ok(IntegerServerKey {
key,
cpk_key_switching_key_material,
compression_key,
decompression_key,
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key: None,
})
}
}
#[derive(VersionsDispatch)]
pub enum IntegerServerKeyVersions {
V0(Deprecated<IntegerServerKey>),
@@ -634,8 +513,7 @@ pub enum IntegerServerKeyVersions {
V5(IntegerServerKeyV5),
V6(IntegerServerKeyV6),
V7(IntegerServerKeyV7),
V8(IntegerServerKeyV8),
V9(IntegerServerKey),
V8(IntegerServerKey),
}
impl Deprecable for IntegerCompressedServerKey {
@@ -755,10 +633,10 @@ pub struct IntegerCompressedServerKeyV5 {
Option<CompressedReRandomizationKeySwitchingKey>,
}
impl Upgrade<IntegerCompressedServerKeyV6> for IntegerCompressedServerKeyV5 {
impl Upgrade<IntegerCompressedServerKey> for IntegerCompressedServerKeyV5 {
type Error = Infallible;
fn upgrade(self) -> Result<IntegerCompressedServerKeyV6, Self::Error> {
fn upgrade(self) -> Result<IntegerCompressedServerKey, Self::Error> {
let Self {
key,
cpk_key_switching_key_material,
@@ -769,7 +647,7 @@ impl Upgrade<IntegerCompressedServerKeyV6> for IntegerCompressedServerKeyV5 {
cpk_re_randomization_key_switching_key_material,
} = self;
Ok(IntegerCompressedServerKeyV6 {
Ok(IntegerCompressedServerKey {
key,
cpk_key_switching_key_material,
compression_key,
@@ -785,45 +663,6 @@ impl Upgrade<IntegerCompressedServerKeyV6> for IntegerCompressedServerKeyV5 {
}
}
#[derive(Version)]
pub struct IntegerCompressedServerKeyV6 {
pub(crate) key: crate::integer::CompressedServerKey,
pub(crate) cpk_key_switching_key_material:
Option<crate::integer::key_switching_key::CompressedKeySwitchingKeyMaterial>,
pub(crate) compression_key: Option<CompressedCompressionKey>,
pub(crate) decompression_key: Option<CompressedDecompressionKey>,
pub(crate) noise_squashing_key: Option<CompressedNoiseSquashingKey>,
pub(crate) noise_squashing_compression_key: Option<CompressedNoiseSquashingCompressionKey>,
pub(crate) cpk_re_randomization_key: Option<CompressedReRandomizationKey>,
}
impl Upgrade<IntegerCompressedServerKey> for IntegerCompressedServerKeyV6 {
type Error = Infallible;
fn upgrade(self) -> Result<IntegerCompressedServerKey, Self::Error> {
let Self {
key,
cpk_key_switching_key_material,
compression_key,
decompression_key,
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
} = self;
Ok(IntegerCompressedServerKey {
key,
cpk_key_switching_key_material,
compression_key,
decompression_key,
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key: None,
})
}
}
#[derive(VersionsDispatch)]
pub enum IntegerCompressedServerKeyVersions {
V0(Deprecated<IntegerCompressedServerKey>),
@@ -832,8 +671,7 @@ pub enum IntegerCompressedServerKeyVersions {
V3(IntegerCompressedServerKeyV3),
V4(IntegerCompressedServerKeyV4),
V5(IntegerCompressedServerKeyV5),
V6(IntegerCompressedServerKeyV6),
V7(IntegerCompressedServerKey),
V6(IntegerCompressedServerKey),
}
#[derive(VersionsDispatch)]

View File

@@ -7,7 +7,7 @@ use crate::integer::gpu::ciphertext::boolean_value::CudaBooleanBlock;
#[cfg(feature = "gpu")]
use crate::integer::gpu::ciphertext::CudaUnsignedRadixCiphertext;
use crate::integer::BooleanBlock;
use crate::shortint::OprfSeed;
use tfhe_csprng::seeders::Seed;
impl FheBool {
/// Generates an encrypted boolean
@@ -28,15 +28,12 @@ impl FheBool {
///
/// let dec_result: bool = ct_res.decrypt(&client_key);
/// ```
pub fn generate_oblivious_pseudo_random(seed: impl OprfSeed) -> Self {
pub fn generate_oblivious_pseudo_random(seed: Seed) -> Self {
let (ciphertext, tag) = global_state::with_internal_keys(|key| match key {
InternalServerKey::Cpu(key) => {
let sk = &key.pbs_key().key;
let ct = key
.oprf_key()
.key
.generate_oblivious_pseudo_random(seed, 1, sk);
let ct = sk.generate_oblivious_pseudo_random(seed, 1);
(
InnerBoolean::Cpu(BooleanBlock::new_unchecked(ct)),
key.tag.clone(),
@@ -46,8 +43,9 @@ impl FheBool {
InternalServerKey::Cuda(cuda_key) => {
let streams = &cuda_key.streams;
let d_ct: CudaUnsignedRadixCiphertext = cuda_key
.oprf_key()
.generate_oblivious_pseudo_random(seed, 1, cuda_key.pbs_key(), streams);
.key
.key
.generate_oblivious_pseudo_random(seed, 1, streams);
(
InnerBoolean::Cuda(CudaBooleanBlock::from_cuda_radix_ciphertext(
d_ct.ciphertext,
@@ -68,18 +66,17 @@ impl FheBool {
#[cfg(feature = "gpu")]
mod test {
use crate::prelude::FheDecrypt;
use tfhe_csprng::seeders::Seed;
#[test]
fn test_oprf_boolean() {
let config = crate::ConfigBuilder::default()
.use_dedicated_oprf_key(true)
.build();
let config = crate::ConfigBuilder::default().build();
let client_key = crate::ClientKey::generate(config);
let compressed_server_key = crate::CompressedServerKey::new(&client_key);
let gpu_key = compressed_server_key.decompress_to_gpu();
crate::set_server_key(gpu_key);
let rnd = crate::FheBool::generate_oblivious_pseudo_random(crate::Seed(123));
let rnd = crate::FheBool::generate_oblivious_pseudo_random(Seed(123u128));
let decrypted_result: bool = rnd.decrypt(&client_key);
println!("Random bool: {decrypted_result}");
}

View File

@@ -870,7 +870,7 @@ mod zk {
let crs = CompactPkeCrs::from_config(config.into(), 64).unwrap();
let public_key = crate::CompactPublicKey::try_new(&client_key).unwrap();
let metadata = b"TFHE-rs";
let metadata = [b'T', b'F', b'H', b'E', b'-', b'r', b's'];
let clear_a = rng.gen::<u64>();
let clear_b = rng.gen::<bool>();
@@ -878,7 +878,7 @@ mod zk {
let proven_compact_list = crate::ProvenCompactCiphertextList::builder(&public_key)
.push(clear_a)
.push(clear_b)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
let params =
@@ -1628,7 +1628,7 @@ mod tests {
// Intentionally low so that we test when multiple lists and proofs are needed
let crs = CompactPkeCrs::from_config(config, 32).unwrap();
let metadata = b"hlapi";
let metadata = [b'h', b'l', b'a', b'p', b'i'];
let compact_list = ProvenCompactCiphertextList::builder(&pk)
.push(17u32)
@@ -1636,12 +1636,14 @@ mod tests {
.push(false)
.push_with_num_bits(3u32, 2)
.unwrap()
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
let serialized = bincode::serialize(&compact_list).unwrap();
let compact_list: ProvenCompactCiphertextList = bincode::deserialize(&serialized).unwrap();
let expander = compact_list.verify_and_expand(&crs, &pk, metadata).unwrap();
let expander = compact_list
.verify_and_expand(&crs, &pk, &metadata)
.unwrap();
{
let a: FheUint32 = expander.get(0).unwrap().unwrap();
@@ -1707,7 +1709,7 @@ mod tests {
set_server_key(sks);
let crs = CompactPkeCrs::from_config(config, 32).unwrap();
let metadata = b"seed";
let metadata = [b's', b'e', b'e', b'd'];
let mut rng = thread_rng();
let seed_a: [u8; 16] = rng.gen();
@@ -1719,7 +1721,7 @@ mod tests {
.push(17u32)
.push(-1i64)
.push(false)
.build_with_proof_packed_seeded(&crs, metadata, ZkComputeLoad::Proof, seed)
.build_with_proof_packed_seeded(&crs, &metadata, ZkComputeLoad::Proof, seed)
.unwrap()
};
@@ -1736,7 +1738,7 @@ mod tests {
"different seeds must produce different output"
);
let expander = list_a1.verify_and_expand(&crs, &pk, metadata).unwrap();
let expander = list_a1.verify_and_expand(&crs, &pk, &metadata).unwrap();
let a: FheUint32 = expander.get(0).unwrap().unwrap();
let b: FheInt64 = expander.get(1).unwrap().unwrap();
let c: FheBool = expander.get(2).unwrap().unwrap();
@@ -1767,13 +1769,15 @@ mod tests {
let crs = CompactPkeCrs::from_config(config, 32).unwrap();
let metadata = b"hlapi";
let metadata = [b'h', b'l', b'a', b'p', b'i'];
let compact_list = CompactCiphertextList::builder(&pk)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
let expander = compact_list.verify_and_expand(&crs, &pk, metadata).unwrap();
let expander = compact_list
.verify_and_expand(&crs, &pk, &metadata)
.unwrap();
assert!(expander.get::<FheBool>(0).unwrap().is_none());
}
@@ -1814,7 +1818,7 @@ mod tests {
// Intentionally low so that we test when multiple lists and proofs are needed
let crs = CompactPkeCrs::from_config(config, 32).unwrap();
let metadata = b"hlapi";
let metadata = [b'h', b'l', b'a', b'p', b'i'];
let compact_list = ProvenCompactCiphertextList::builder(&pk)
.push(17u32)
@@ -1822,13 +1826,15 @@ mod tests {
.push(false)
.push_with_num_bits(3u32, 2)
.unwrap()
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
let serialized = bincode::serialize(&compact_list).unwrap();
let compact_list: ProvenCompactCiphertextList =
bincode::deserialize(&serialized).unwrap();
let expander = compact_list.verify_and_expand(&crs, &pk, metadata).unwrap();
let expander = compact_list
.verify_and_expand(&crs, &pk, &metadata)
.unwrap();
{
let a: FheUint32 = expander.get(0).unwrap().unwrap();

View File

@@ -132,11 +132,6 @@ impl ConfigBuilder {
self
}
pub fn use_dedicated_oprf_key(mut self, enabled: bool) -> Self {
self.config.inner.use_dedicated_oprf_key(enabled);
self
}
pub fn use_custom_parameters<P>(mut self, block_parameters: P) -> Self
where
P: Into<crate::shortint::atomic_pattern::AtomicPatternParameters>,
@@ -172,7 +167,6 @@ impl From<MetaParameters> for Config {
.noise_squashing_parameters
.and_then(|ns_p| ns_p.compression_parameters),
cpk_re_randomization_params: meta_params.rerandomization_parameters(),
dedicated_oprf_key: true,
},
}
}

View File

@@ -4,8 +4,8 @@ use crate::high_level_api::keys::InternalServerKey;
use crate::high_level_api::re_randomization::ReRandomizationMetadata;
#[cfg(feature = "gpu")]
use crate::integer::gpu::ciphertext::{CudaSignedRadixCiphertext, CudaUnsignedRadixCiphertext};
use crate::shortint::{MessageModulus, OprfSeed};
use crate::FheInt;
use crate::shortint::MessageModulus;
use crate::{FheInt, Seed};
use std::num::NonZeroU64;
impl<Id: FheUintId> FheUint<Id> {
@@ -27,16 +27,14 @@ impl<Id: FheUintId> FheUint<Id> {
///
/// let dec_result: u16 = ct_res.decrypt(&client_key);
/// ```
pub fn generate_oblivious_pseudo_random(seed: impl OprfSeed) -> Self {
pub fn generate_oblivious_pseudo_random(seed: Seed) -> Self {
global_state::with_internal_keys(|key| match key {
InternalServerKey::Cpu(key) => {
let sk = key.pbs_key();
let ct = key
.oprf_key()
.pbs_key()
.par_generate_oblivious_pseudo_random_unsigned_integer(
seed,
Id::num_blocks(key.message_modulus()) as u64,
sk,
);
Self::new(ct, key.tag.clone(), ReRandomizationMetadata::default())
@@ -45,11 +43,11 @@ impl<Id: FheUintId> FheUint<Id> {
InternalServerKey::Cuda(cuda_key) => {
let streams = &cuda_key.streams;
let d_ct: CudaUnsignedRadixCiphertext = cuda_key
.oprf_key()
.key
.key
.par_generate_oblivious_pseudo_random_unsigned_integer(
seed,
Id::num_blocks(cuda_key.message_modulus()) as u64,
cuda_key.pbs_key(),
streams,
);
@@ -88,11 +86,9 @@ impl<Id: FheUintId> FheUint<Id> {
if let InternalServerKey::Cuda(cuda_key) = key {
let streams = &cuda_key.streams;
cuda_key
.oprf_key()
.get_par_generate_oblivious_pseudo_random_unsigned_integer_size_on_gpu(
cuda_key.pbs_key(),
streams,
)
.key
.key
.get_par_generate_oblivious_pseudo_random_unsigned_integer_size_on_gpu(streams)
} else {
0
}
@@ -119,20 +115,15 @@ impl<Id: FheUintId> FheUint<Id> {
/// let dec_result: u16 = ct_res.decrypt(&client_key);
/// assert!(dec_result < (1 << random_bits_count));
/// ```
pub fn generate_oblivious_pseudo_random_bounded(
seed: impl OprfSeed,
random_bits_count: u64,
) -> Self {
pub fn generate_oblivious_pseudo_random_bounded(seed: Seed, random_bits_count: u64) -> Self {
global_state::with_internal_keys(|key| match key {
InternalServerKey::Cpu(key) => {
let sk = key.pbs_key();
let ct = key
.oprf_key()
.pbs_key()
.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
seed,
random_bits_count,
Id::num_blocks(key.message_modulus()) as u64,
sk,
);
Self::new(ct, key.tag.clone(), ReRandomizationMetadata::default())
@@ -141,12 +132,12 @@ impl<Id: FheUintId> FheUint<Id> {
InternalServerKey::Cuda(cuda_key) => {
let streams = &cuda_key.streams;
let d_ct: CudaUnsignedRadixCiphertext = cuda_key
.oprf_key()
.key
.key
.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
seed,
random_bits_count,
Id::num_blocks(cuda_key.message_modulus()) as u64,
cuda_key.pbs_key(),
streams,
);
Self::new(
@@ -205,7 +196,7 @@ impl<Id: FheUintId> FheUint<Id> {
/// assert!(dec_result < excluded_upper_bound.get() as u16);
/// ```
pub fn generate_oblivious_pseudo_random_custom_range(
seed: impl OprfSeed,
seed: Seed,
range: &RangeForRandom,
max_distance: Option<f64>,
) -> Self {
@@ -235,15 +226,13 @@ impl<Id: FheUintId> FheUint<Id> {
let num_blocks_output = Id::num_blocks(key.message_modulus()) as u64;
let sk = key.pbs_key();
let ct = key
.oprf_key()
.pbs_key()
.par_generate_oblivious_pseudo_random_unsigned_custom_range(
seed,
num_input_random_bits,
excluded_upper_bound,
num_blocks_output,
sk,
);
Self::new(ct, key.tag.clone(), ReRandomizationMetadata::default())
@@ -261,13 +250,12 @@ impl<Id: FheUintId> FheUint<Id> {
let num_blocks_output = Id::num_blocks(cuda_key.message_modulus()) as u64;
let ct = cuda_key
.oprf_key()
.pbs_key()
.par_generate_oblivious_pseudo_random_unsigned_custom_range(
seed,
num_input_random_bits,
excluded_upper_bound.get(),
num_blocks_output,
cuda_key.pbs_key(),
&cuda_key.streams,
);
@@ -304,9 +292,9 @@ impl<Id: FheUintId> FheUint<Id> {
if let InternalServerKey::Cuda(cuda_key) = key {
let streams = &cuda_key.streams;
cuda_key
.oprf_key()
.key
.key
.get_par_generate_oblivious_pseudo_random_unsigned_integer_bounded_size_on_gpu(
cuda_key.pbs_key(),
streams,
)
} else {
@@ -337,16 +325,14 @@ impl<Id: FheIntId> FheInt<Id> {
/// assert!(dec_result < 1 << 7);
/// assert!(dec_result >= -(1 << 7));
/// ```
pub fn generate_oblivious_pseudo_random(seed: impl OprfSeed) -> Self {
pub fn generate_oblivious_pseudo_random(seed: Seed) -> Self {
global_state::with_internal_keys(|key| match key {
InternalServerKey::Cpu(key) => {
let sk = key.pbs_key();
let ct = key
.oprf_key()
.pbs_key()
.par_generate_oblivious_pseudo_random_signed_integer(
seed,
Id::num_blocks(key.message_modulus()) as u64,
sk,
);
Self::new(ct, key.tag.clone(), ReRandomizationMetadata::default())
}
@@ -354,11 +340,11 @@ impl<Id: FheIntId> FheInt<Id> {
InternalServerKey::Cuda(cuda_key) => {
let streams = &cuda_key.streams;
let d_ct: CudaSignedRadixCiphertext = cuda_key
.oprf_key()
.key
.key
.par_generate_oblivious_pseudo_random_signed_integer(
seed,
Id::num_blocks(cuda_key.message_modulus()) as u64,
cuda_key.pbs_key(),
streams,
);
@@ -398,11 +384,9 @@ impl<Id: FheIntId> FheInt<Id> {
if let InternalServerKey::Cuda(cuda_key) = key {
let streams = &cuda_key.streams;
cuda_key
.oprf_key()
.get_par_generate_oblivious_pseudo_random_signed_integer_size_on_gpu(
cuda_key.pbs_key(),
streams,
)
.key
.key
.get_par_generate_oblivious_pseudo_random_signed_integer_size_on_gpu(streams)
} else {
0
}
@@ -430,20 +414,15 @@ impl<Id: FheIntId> FheInt<Id> {
/// assert!(dec_result >= 0);
/// assert!(dec_result < 1 << random_bits_count);
/// ```
pub fn generate_oblivious_pseudo_random_bounded(
seed: impl OprfSeed,
random_bits_count: u64,
) -> Self {
pub fn generate_oblivious_pseudo_random_bounded(seed: Seed, random_bits_count: u64) -> Self {
global_state::with_internal_keys(|key| match key {
InternalServerKey::Cpu(key) => {
let sk = key.pbs_key();
let ct = key
.oprf_key()
.pbs_key()
.par_generate_oblivious_pseudo_random_signed_integer_bounded(
seed,
random_bits_count,
Id::num_blocks(key.message_modulus()) as u64,
sk,
);
Self::new(ct, key.tag.clone(), ReRandomizationMetadata::default())
@@ -452,12 +431,12 @@ impl<Id: FheIntId> FheInt<Id> {
InternalServerKey::Cuda(cuda_key) => {
let streams = &cuda_key.streams;
let d_ct: CudaSignedRadixCiphertext = cuda_key
.oprf_key()
.key
.key
.par_generate_oblivious_pseudo_random_signed_integer_bounded(
seed,
random_bits_count,
Id::num_blocks(cuda_key.message_modulus()) as u64,
cuda_key.pbs_key(),
streams,
);
Self::new(
@@ -495,9 +474,9 @@ impl<Id: FheIntId> FheInt<Id> {
if let InternalServerKey::Cuda(cuda_key) = key {
let streams = &cuda_key.streams;
cuda_key
.oprf_key()
.key
.key
.get_par_generate_oblivious_pseudo_random_unsigned_integer_bounded_size_on_gpu(
cuda_key.pbs_key(),
streams,
)
} else {
@@ -591,7 +570,6 @@ mod test {
};
use crate::prelude::FheDecrypt;
use crate::shortint::oprf::test::test_uniformity;
use crate::shortint::parameters::test_params::TEST_PARAM_MESSAGE_2_CARRY_2_PBS_KS_GAUSSIAN_2M128;
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
use crate::{generate_keys, set_server_key, ConfigBuilder, FheUint8, Seed};
use num_bigint::BigUint;
@@ -729,9 +707,7 @@ mod test {
#[test]
fn test_uniformity_generate_oblivious_pseudo_random_custom_range_cpu() {
let params = PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128;
let config = ConfigBuilder::with_custom_parameters(params)
.use_dedicated_oprf_key(true)
.build();
let config = ConfigBuilder::with_custom_parameters(params).build();
let (cks, sks) = generate_keys(config);
rayon::broadcast(|_| set_server_key(sks.clone()));
let message_modulus = cks.message_modulus();
@@ -762,10 +738,8 @@ mod test {
let real_values: Vec<u64> = (0..sample_count)
.into_par_iter()
.map(|_| {
let seed = Seed(rand::thread_rng().gen::<u128>());
let img = FheUint8::generate_oblivious_pseudo_random_custom_range(
seed,
Seed(rand::thread_rng().gen::<u128>()),
&range,
Some(max_distance),
);
@@ -846,50 +820,6 @@ mod test {
}
}
/// Test that OPRF generation works without a dedicated OPRF key by falling
/// back to the compute server key's bootstrapping key.
#[test]
fn test_oprf_fallback_without_dedicated_key() {
// Explicitly disable OPRF so no dedicated OPRF key is generated.
let config = ConfigBuilder::default()
.use_dedicated_oprf_key(false)
.build();
let (client_key, server_key) = generate_keys(config);
set_server_key(server_key);
let ct = FheUint8::generate_oblivious_pseudo_random(Seed(42));
let result: u16 = ct.decrypt(&client_key);
// 8-bit value must fit in [0, 256)
assert!(result < 256);
let ct_bounded = FheUint8::generate_oblivious_pseudo_random_bounded(Seed(42), 3);
let result_bounded: u16 = ct_bounded.decrypt(&client_key);
assert!(result_bounded < (1 << 3));
}
/// Test OPRF with BootstrapKeyswitch (PBS_KS) parameter order.
///
/// This exercises the keyswitch-after-bootstrap code path in
/// `OprfBootstrappingKey::generate_pseudo_random_bits`.
#[test]
fn test_oprf_with_pbs_ks_params() {
let config = ConfigBuilder::with_custom_parameters(
TEST_PARAM_MESSAGE_2_CARRY_2_PBS_KS_GAUSSIAN_2M128,
)
.use_dedicated_oprf_key(true)
.build();
let (client_key, server_key) = generate_keys(config);
set_server_key(server_key);
let ct = FheUint8::generate_oblivious_pseudo_random(Seed(123));
let result: u16 = ct.decrypt(&client_key);
assert!(result < 256);
let ct_bounded = FheUint8::generate_oblivious_pseudo_random_bounded(Seed(456), 3);
let result_bounded: u16 = ct_bounded.decrypt(&client_key);
assert!(result_bounded < (1 << 3));
}
#[cfg(feature = "gpu")]
mod gpu {
use super::*;
@@ -908,11 +838,13 @@ mod test {
fn test_oprf_gpu() {
for setup_fn in crate::high_level_api::integers::unsigned::tests::gpu::GPU_SETUP_FN {
let _ck = setup_fn();
let img = FheUint64::generate_oblivious_pseudo_random_bounded(Seed(0), 1);
let seed = Seed(0);
let img = FheUint64::generate_oblivious_pseudo_random_bounded(seed, 1);
assert_eq!(img.ciphertext.into_cpu().blocks.len(), 32);
let img = FheInt128::generate_oblivious_pseudo_random_bounded(Seed(0), 1);
let img = FheInt128::generate_oblivious_pseudo_random_bounded(seed, 1);
assert_eq!(img.ciphertext.into_cpu().blocks.len(), 64);
}
@@ -932,9 +864,7 @@ mod test {
#[test]
fn test_uniformity_generate_oblivious_pseudo_random_custom_range_gpu() {
let params = PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let config = ConfigBuilder::with_custom_parameters(params)
.use_dedicated_oprf_key(true)
.build();
let config = ConfigBuilder::with_custom_parameters(params).build();
let cks = ClientKey::generate(config);
let message_modulus = cks.message_modulus();
@@ -991,9 +921,8 @@ mod test {
rand::thread_rng()
},
|rng, _| {
let seed = Seed(rng.gen::<u128>());
let img = FheUint8::generate_oblivious_pseudo_random_custom_range(
seed,
Seed(rng.gen::<u128>()),
&range,
Some(max_distance),
);

View File

@@ -260,7 +260,7 @@ impl SignedRadixCiphertext {
}
#[cfg(feature = "hpu")]
(_, Device::Hpu) => {
panic!("Hpu device do not support signed integer yet")
panic!("Hpu device do not support signed integer yet",)
}
}
}

View File

@@ -33,7 +33,6 @@ pub(crate) fn setup_gpu(params: Option<impl Into<TestParameters>>) -> ClientKey
.map_or_else(ConfigBuilder::default, |p| {
ConfigBuilder::with_custom_parameters(p.into())
})
.use_dedicated_oprf_key(true)
.build();
let client_key = ClientKey::generate(config);

View File

@@ -10,7 +10,6 @@ use crate::high_level_api::SquashedNoiseCiphertextState;
use crate::integer::ciphertext::NoiseSquashingCompressionPrivateKey;
use crate::integer::compression_keys::CompressionPrivateKeys;
use crate::integer::noise_squashing::{NoiseSquashingPrivateKey, NoiseSquashingPrivateKeyView};
use crate::integer::oprf::OprfPrivateKey;
use crate::named::Named;
use crate::prelude::Tagged;
use crate::shortint::parameters::ReRandomizationParameters;
@@ -89,14 +88,12 @@ impl ClientKey {
Option<NoiseSquashingPrivateKey>,
Option<NoiseSquashingCompressionPrivateKey>,
Option<ReRandomizationParameters>,
Option<OprfPrivateKey>,
Tag,
) {
let (cks, cpk, cppk, nsk, nscpk, cpkrndp, oprf) = self.key.into_raw_parts();
(cks, cpk, cppk, nsk, nscpk, cpkrndp, oprf, self.tag)
let (cks, cpk, cppk, nsk, nscpk, cpkrndp) = self.key.into_raw_parts();
(cks, cpk, cppk, nsk, nscpk, cpkrndp, self.tag)
}
#[allow(clippy::too_many_arguments)]
pub fn from_raw_parts(
key: crate::integer::ClientKey,
dedicated_compact_private_key: Option<(
@@ -107,7 +104,6 @@ impl ClientKey {
noise_squashing_key: Option<NoiseSquashingPrivateKey>,
noise_squashing_compression_key: Option<NoiseSquashingCompressionPrivateKey>,
cpk_re_randomization_params: Option<ReRandomizationParameters>,
oprf_private_key: Option<OprfPrivateKey>,
tag: Tag,
) -> Self {
Self {
@@ -118,7 +114,6 @@ impl ClientKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_params,
oprf_private_key,
),
tag,
}

View File

@@ -17,7 +17,6 @@ use crate::high_level_api::keys::inner::CudaReRandomizationKey;
use crate::integer::compression_keys::CompressedDecompressionKey;
use crate::integer::noise_squashing::CompressedNoiseSquashingKey;
use crate::integer::oprf::ExpandedOprfServerKey;
use crate::shortint::atomic_pattern::expanded::{
ExpandedAtomicPatternServerKey, ExpandedKS32AtomicPatternServerKey,
ExpandedStandardAtomicPatternServerKey,
@@ -44,7 +43,6 @@ pub struct IntegerExpandedServerKey {
pub noise_squashing_key: Option<ExpandedNoiseSquashingKey>,
pub noise_squashing_compression_key: Option<NoiseSquashingCompressionKey>,
pub cpk_re_randomization_key: Option<ReRandomizationKey>,
pub oprf_key: Option<ExpandedOprfServerKey>,
}
impl IntegerExpandedServerKey {
@@ -65,7 +63,6 @@ impl IntegerExpandedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
} = self;
let atomic_pattern_key = match compute_key.atomic_pattern {
@@ -141,8 +138,6 @@ impl IntegerExpandedServerKey {
)
});
let oprf_key = oprf_key.map(|oprf_key| oprf_key.to_fourier());
IntegerServerKey {
key,
cpk_key_switching_key_material,
@@ -151,7 +146,6 @@ impl IntegerExpandedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
}
}
}
@@ -181,7 +175,6 @@ impl IntegerExpandedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
} = self;
let key = CudaServerKey::from_expanded_server_key(compute_key, streams)?;
@@ -246,10 +239,6 @@ impl IntegerExpandedServerKey {
}
});
let oprf_key = oprf_key.as_ref().map(|expanded_oprf_key| {
crate::integer::gpu::CudaOprfServerKey::from_expanded_cpu(expanded_oprf_key, streams)
});
Ok(crate::high_level_api::keys::inner::IntegerCudaServerKey {
key,
cpk_key_switching_key_material,
@@ -258,7 +247,6 @@ impl IntegerExpandedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
})
}
}

View File

@@ -21,7 +21,6 @@ use crate::integer::compression_keys::{
use crate::integer::noise_squashing::{
CompressedNoiseSquashingKey, NoiseSquashingKey, NoiseSquashingPrivateKey,
};
use crate::integer::oprf::{CompressedOprfServerKey, OprfPrivateKey, OprfServerKey};
use crate::integer::public_key::CompactPublicKey;
use crate::integer::CompressedCompactPublicKey;
use crate::shortint::atomic_pattern::AtomicPatternParameters;
@@ -49,8 +48,6 @@ pub(crate) struct IntegerConfig {
pub(crate) noise_squashing_parameters: Option<NoiseSquashingParameters>,
pub(crate) noise_squashing_compression_parameters: Option<NoiseSquashingCompressionParameters>,
pub(crate) cpk_re_randomization_params: Option<ReRandomizationParameters>,
// Oprf uses the same parameters as the bootstrap key from the block_parameters
pub(crate) dedicated_oprf_key: bool,
}
impl IntegerConfig {
@@ -64,7 +61,6 @@ impl IntegerConfig {
noise_squashing_parameters: None,
noise_squashing_compression_parameters: None,
cpk_re_randomization_params: None,
dedicated_oprf_key: true,
}
}
@@ -125,11 +121,6 @@ impl IntegerConfig {
self.cpk_re_randomization_params = Some(cpk_re_randomization_params);
}
/// Whether to use a dedicated key for the OPRF (default) or not
pub(crate) fn use_dedicated_oprf_key(&mut self, enabled: bool) {
self.dedicated_oprf_key = enabled;
}
pub(crate) fn public_key_encryption_parameters(
&self,
) -> Result<crate::shortint::parameters::CompactPublicKeyEncryptionParameters, crate::Error>
@@ -158,7 +149,6 @@ impl Default for IntegerConfig {
noise_squashing_parameters: None,
noise_squashing_compression_parameters: None,
cpk_re_randomization_params: None,
dedicated_oprf_key: true,
}
}
}
@@ -181,7 +171,6 @@ pub(crate) struct IntegerClientKey {
// compact private key and the post PBS secret key, it needs additional information on how
// to create the required key switching key.
pub(crate) cpk_re_randomization_params: Option<ReRandomizationParameters>,
pub(crate) dedicated_oprf_private_key: Option<OprfPrivateKey>,
}
impl IntegerClientKey {
@@ -196,13 +185,8 @@ impl IntegerClientKey {
first_index: tfhe_csprng::generators::aes_ctr::TableIndex::SECOND,
};
let mut seeder = DeterministicSeeder::<DefaultRandomGenerator>::new(aes_ctr_params);
let mut engine = crate::shortint::engine::ShortintEngine::new_from_seeder(&mut seeder);
let cks = engine.new_client_key(config.block_parameters);
let previous_engine =
crate::shortint::engine::ShortintEngine::with_thread_local_mut(|local_engine| {
std::mem::replace(local_engine, engine)
});
let cks = crate::shortint::engine::ShortintEngine::new_from_seeder(&mut seeder)
.new_client_key(config.block_parameters);
let key = crate::integer::ClientKey::from(cks);
@@ -224,13 +208,6 @@ impl IntegerClientKey {
let cpk_re_randomization_params = config.cpk_re_randomization_params;
let dedicated_oprf_private_key =
config.dedicated_oprf_key.then(|| OprfPrivateKey::new(&key));
crate::shortint::engine::ShortintEngine::with_thread_local_mut(|local_engine| {
*local_engine = previous_engine;
});
Self {
key,
dedicated_compact_private_key,
@@ -238,7 +215,6 @@ impl IntegerClientKey {
noise_squashing_private_key,
noise_squashing_compression_private_key,
cpk_re_randomization_params,
dedicated_oprf_private_key,
}
}
@@ -253,7 +229,6 @@ impl IntegerClientKey {
Option<NoiseSquashingPrivateKey>,
Option<NoiseSquashingCompressionPrivateKey>,
Option<ReRandomizationParameters>,
Option<OprfPrivateKey>,
) {
let Self {
key,
@@ -262,7 +237,6 @@ impl IntegerClientKey {
noise_squashing_private_key,
noise_squashing_compression_private_key,
cpk_re_randomization_params,
dedicated_oprf_private_key,
} = self;
(
key,
@@ -271,7 +245,6 @@ impl IntegerClientKey {
noise_squashing_private_key,
noise_squashing_compression_private_key,
cpk_re_randomization_params,
dedicated_oprf_private_key,
)
}
@@ -287,7 +260,6 @@ impl IntegerClientKey {
noise_squashing_private_key: Option<NoiseSquashingPrivateKey>,
noise_squashing_compression_private_key: Option<NoiseSquashingCompressionPrivateKey>,
cpk_re_randomization_params: Option<ReRandomizationParameters>,
dedicated_oprf_private_key: Option<OprfPrivateKey>,
) -> Self {
let shortint_cks: &crate::shortint::ClientKey = key.as_ref();
@@ -317,7 +289,6 @@ impl IntegerClientKey {
noise_squashing_private_key,
noise_squashing_compression_private_key,
cpk_re_randomization_params,
dedicated_oprf_private_key,
}
}
@@ -395,9 +366,6 @@ impl From<IntegerConfig> for IntegerClientKey {
let cpk_re_randomization_params = config.cpk_re_randomization_params;
let dedicated_oprf_private_key =
config.dedicated_oprf_key.then(|| OprfPrivateKey::new(&key));
Self {
key,
dedicated_compact_private_key,
@@ -405,7 +373,6 @@ impl From<IntegerConfig> for IntegerClientKey {
noise_squashing_private_key,
noise_squashing_compression_private_key,
cpk_re_randomization_params,
dedicated_oprf_private_key,
}
}
}
@@ -425,7 +392,6 @@ pub struct IntegerServerKey {
pub(crate) noise_squashing_key: Option<NoiseSquashingKey>,
pub(crate) noise_squashing_compression_key: Option<NoiseSquashingCompressionKey>,
pub(crate) cpk_re_randomization_key: Option<ReRandomizationKey>,
pub(crate) oprf_key: Option<OprfServerKey>,
}
impl IntegerServerKey {
@@ -508,13 +474,6 @@ impl IntegerServerKey {
}
});
let oprf_key = client_key
.dedicated_oprf_private_key
.as_ref()
.map(|oprf_pk| OprfServerKey::new(oprf_pk, &client_key.key))
.transpose()
.expect("Failed to create the server key for the oprf");
Self {
key: base_integer_key,
cpk_key_switching_key_material,
@@ -523,7 +482,6 @@ impl IntegerServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
}
}
@@ -608,7 +566,6 @@ pub struct IntegerCudaServerKey {
crate::integer::gpu::list_compression::server_keys::CudaNoiseSquashingCompressionKey,
>,
pub(crate) cpk_re_randomization_key: Option<CudaReRandomizationKey>,
pub(crate) oprf_key: Option<crate::integer::gpu::CudaOprfServerKey>,
}
#[cfg(feature = "gpu")]
@@ -669,7 +626,6 @@ pub struct IntegerCompressedServerKey {
pub(crate) noise_squashing_key: Option<CompressedNoiseSquashingKey>,
pub(crate) noise_squashing_compression_key: Option<CompressedNoiseSquashingCompressionKey>,
pub(crate) cpk_re_randomization_key: Option<CompressedReRandomizationKey>,
pub(crate) oprf_key: Option<CompressedOprfServerKey>,
}
impl IntegerCompressedServerKey {
@@ -757,14 +713,6 @@ impl IntegerCompressedServerKey {
}
});
let oprf_key = client_key
.dedicated_oprf_private_key
.as_ref()
.map(|oprf_private_key| {
CompressedOprfServerKey::new(oprf_private_key, &client_key.key)
.expect("Failed to create the OPRF key")
});
Self {
key,
cpk_key_switching_key_material,
@@ -773,7 +721,6 @@ impl IntegerCompressedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
}
}
@@ -788,7 +735,6 @@ impl IntegerCompressedServerKey {
Option<CompressedNoiseSquashingKey>,
Option<CompressedNoiseSquashingCompressionKey>,
Option<CompressedReRandomizationKey>,
Option<CompressedOprfServerKey>,
) {
let Self {
key,
@@ -798,7 +744,6 @@ impl IntegerCompressedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
} = self;
(
@@ -809,11 +754,9 @@ impl IntegerCompressedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
)
}
#[allow(clippy::too_many_arguments)]
pub fn from_raw_parts(
key: crate::integer::CompressedServerKey,
cpk_key_switching_key_material: Option<
@@ -824,7 +767,6 @@ impl IntegerCompressedServerKey {
noise_squashing_key: Option<CompressedNoiseSquashingKey>,
noise_squashing_compression_key: Option<CompressedNoiseSquashingCompressionKey>,
cpk_re_randomization_key: Option<CompressedReRandomizationKey>,
oprf_key: Option<CompressedOprfServerKey>,
) -> Self {
Self {
key,
@@ -834,7 +776,6 @@ impl IntegerCompressedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
}
}
@@ -862,7 +803,6 @@ impl IntegerCompressedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
} = self;
// Expand the main server key (compute key)
@@ -893,8 +833,6 @@ impl IntegerCompressedServerKey {
let cpk_re_randomization_key = cpk_re_randomization_key.as_ref().map(|k| k.decompress());
let oprf_key = oprf_key.as_ref().map(|k| k.expand());
IntegerExpandedServerKey {
compute_key,
cpk_key_switching_key_material,
@@ -903,7 +841,6 @@ impl IntegerCompressedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
}
}
}
@@ -994,7 +931,6 @@ pub struct IntegerServerKeyConformanceParams {
pub noise_squashing_param: Option<NoiseSquashingParameters>,
pub noise_squashing_compression_param: Option<NoiseSquashingCompressionParameters>,
pub cpk_re_randomization_params: Option<ReRandomizationParameters>,
pub dedicated_oprf_key: bool,
}
impl<C: Into<Config>> From<C> for IntegerServerKeyConformanceParams {
@@ -1007,7 +943,6 @@ impl<C: Into<Config>> From<C> for IntegerServerKeyConformanceParams {
noise_squashing_param: config.inner.noise_squashing_parameters,
noise_squashing_compression_param: config.inner.noise_squashing_compression_parameters,
cpk_re_randomization_params: config.inner.cpk_re_randomization_params,
dedicated_oprf_key: config.inner.dedicated_oprf_key,
}
}
}
@@ -1073,7 +1008,6 @@ impl ParameterSetConformant for IntegerServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
} = self;
let cpk_key_switching_key_material_is_ok = match (
@@ -1194,24 +1128,12 @@ impl ParameterSetConformant for IntegerServerKey {
}
};
let oprf_is_ok = match (parameter_set.dedicated_oprf_key, oprf_key.as_ref()) {
// We have to have a dedicated oprf key
// Make sure it's there and that it's conformant
(true, Some(key)) => key.is_conformant(&parameter_set.sk_param),
(true, None) => false,
// The config says to not use a dedicated oprf key but we have one
// while it works, it is not strictly conformant
(false, Some(_)) => false,
(false, None) => true,
};
key.is_conformant(&parameter_set.sk_param)
&& cpk_key_switching_key_material_is_ok
&& compression_is_ok
&& noise_squashing_key_is_ok
&& noise_squashing_compression_key_is_ok
&& re_randomization_keys_are_ok
&& oprf_is_ok
}
}
@@ -1227,7 +1149,6 @@ impl ParameterSetConformant for IntegerCompressedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
} = self;
let cpk_key_switching_key_material_is_ok = match (
@@ -1350,24 +1271,12 @@ impl ParameterSetConformant for IntegerCompressedServerKey {
}
};
let oprf_is_ok = match (parameter_set.dedicated_oprf_key, oprf_key.as_ref()) {
// We have to have a dedicated oprf key
// Make sure it's there and that it's conformant
(true, Some(key)) => key.is_conformant(&parameter_set.sk_param),
(true, None) => false,
// The config says to not use a dedicated oprf key but we have one
// while it works, it is not strictly conformant
(false, Some(_)) => false,
(false, None) => true,
};
key.is_conformant(&parameter_set.sk_param)
&& cpk_key_switching_key_material_is_ok
&& compression_is_ok
&& noise_squashing_key_is_ok
&& noise_squashing_compression_key_is_ok
&& re_randomization_keys_are_ok
&& oprf_is_ok
}
}

View File

@@ -21,7 +21,6 @@ use crate::integer::compression_keys::{
#[cfg(feature = "gpu")]
use crate::integer::gpu::ciphertext::re_randomization::CudaReRandomizationKey as IntegerCudaReRandomizationKey;
use crate::integer::noise_squashing::{CompressedNoiseSquashingKey, NoiseSquashingKey};
use crate::integer::oprf::{CompressedOprfServerKey, OprfServerKey, OprfServerKeyView};
use crate::integer::parameters::IntegerCompactCiphertextListExpansionMode;
use crate::integer::public_key::compact::CompactPublicKey;
use crate::named::Named;
@@ -86,7 +85,6 @@ impl ServerKey {
Option<NoiseSquashingKey>,
Option<NoiseSquashingCompressionKey>,
Option<ReRandomizationKey>,
Option<OprfServerKey>,
Tag,
) {
let IntegerServerKey {
@@ -97,7 +95,6 @@ impl ServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
} = (*self.key).clone();
(
@@ -108,7 +105,6 @@ impl ServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
self.tag,
)
}
@@ -124,7 +120,6 @@ impl ServerKey {
noise_squashing_key: Option<NoiseSquashingKey>,
noise_squashing_compression_key: Option<NoiseSquashingCompressionKey>,
cpk_re_randomization_key: Option<ReRandomizationKey>,
oprf_key: Option<OprfServerKey>,
tag: Tag,
) -> Self {
Self {
@@ -136,7 +131,6 @@ impl ServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
}),
tag,
}
@@ -146,17 +140,6 @@ impl ServerKey {
self.key.pbs_key()
}
/// Returns an OPRF key reference for pseudo-random generation.
///
/// If a dedicated OPRF key was generated, it is used.
/// Otherwise, falls back to the compute server key's bootstrapping key.
pub(in crate::high_level_api) fn oprf_key(&self) -> OprfServerKeyView<'_> {
self.key.oprf_key.as_ref().map_or_else(
|| self.pbs_key().as_oprf_key_view(),
|dedicated| dedicated.as_view(),
)
}
#[cfg(feature = "strings")]
pub(in crate::high_level_api) fn string_key(&self) -> crate::strings::ServerKeyRef<'_> {
crate::strings::ServerKeyRef::new(self.key.pbs_key())
@@ -286,10 +269,6 @@ impl ServerKey {
self.key.compression_key.is_some()
}
pub fn supports_oprf(&self) -> bool {
true
}
pub(in crate::high_level_api) fn message_modulus(&self) -> MessageModulus {
self.key.message_modulus()
}
@@ -414,11 +393,10 @@ impl CompressedServerKey {
Option<CompressedNoiseSquashingKey>,
Option<CompressedNoiseSquashingCompressionKey>,
Option<CompressedReRandomizationKey>,
Option<CompressedOprfServerKey>,
Tag,
) {
let (a, b, c, d, e, f, g, h) = self.integer_key.into_raw_parts();
(a, b, c, d, e, f, g, h, self.tag)
let (a, b, c, d, e, f, g) = self.integer_key.into_raw_parts();
(a, b, c, d, e, f, g, self.tag)
}
#[allow(clippy::too_many_arguments)]
@@ -432,7 +410,6 @@ impl CompressedServerKey {
noise_squashing_key: Option<CompressedNoiseSquashingKey>,
noise_squashing_compression_key: Option<CompressedNoiseSquashingCompressionKey>,
cpk_re_randomization_key: Option<CompressedReRandomizationKey>,
oprf_key: Option<CompressedOprfServerKey>,
tag: Tag,
) -> Self {
Self {
@@ -444,7 +421,6 @@ impl CompressedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
),
tag,
}
@@ -521,17 +497,6 @@ impl CudaServerKey {
}
}
pub(crate) fn oprf_key(&self) -> crate::integer::gpu::CudaOprfServerKeyView<'_> {
self.key.oprf_key.as_ref().map_or_else(
|| {
crate::integer::gpu::GenericCudaOprfServerKey::from_borrowed_bsk(
&self.key.key.bootstrapping_key,
)
},
|dedicated| dedicated.as_view(),
)
}
pub fn gpu_indexes(&self) -> &[GpuIndex] {
match &self.key.key.key_switching_key {
CudaDynamicKeyswitchingKey::KeySwitch32(ksk_32) => ksk_32.d_vec.gpu_indexes.as_slice(),
@@ -892,7 +857,6 @@ mod test {
noise_squashing_param: None,
noise_squashing_compression_param: None,
cpk_re_randomization_params: None,
dedicated_oprf_key: true,
};
assert!(!sk.is_conformant(&conformance_params));
@@ -923,7 +887,6 @@ mod test {
noise_squashing_param: None,
noise_squashing_compression_param: None,
cpk_re_randomization_params: None,
dedicated_oprf_key: true,
};
assert!(!sk.is_conformant(&conformance_params));
@@ -1061,7 +1024,6 @@ mod test {
noise_squashing_param: None,
noise_squashing_compression_param: None,
cpk_re_randomization_params: None,
dedicated_oprf_key: true,
};
assert!(!sk.is_conformant(&conformance_params));
@@ -1092,34 +1054,9 @@ mod test {
noise_squashing_param: None,
noise_squashing_compression_param: None,
cpk_re_randomization_params: None,
dedicated_oprf_key: true,
};
assert!(!sk.is_conformant(&conformance_params));
}
{
let params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let config = ConfigBuilder::with_custom_parameters(params)
.use_dedicated_oprf_key(false)
.build();
let ck = ClientKey::generate(config);
let sk = CompressedServerKey::new(&ck);
let sk_param = params.into();
let mut conformance_params = IntegerServerKeyConformanceParams {
sk_param,
cpk_param: None,
compression_param: None,
noise_squashing_param: None,
noise_squashing_compression_param: None,
cpk_re_randomization_params: None,
dedicated_oprf_key: true,
};
assert!(!sk.is_conformant(&conformance_params));
conformance_params.dedicated_oprf_key = false;
assert!(sk.is_conformant(&conformance_params));
}
}
}

View File

@@ -50,7 +50,6 @@ macro_rules! export_concrete_array_types {
pub use crate::core_crypto::commons::math::random::{Seed, XofSeed};
pub use crate::high_level_api::integers::oprf::RangeForRandom;
pub use crate::integer::server_key::MatchValues;
pub use crate::shortint::OprfSeed;
use crate::{error, Error, Versionize};
use backward_compatibility::compressed_ciphertext_list::SquashedNoiseCiphertextStateVersions;
pub use config::{Config, ConfigBuilder};
@@ -70,8 +69,8 @@ pub use integers::{
pub use keys::CudaServerKey;
pub use keys::{
generate_keys, ClientKey, CompactPublicKey, CompressedCompactPublicKey, CompressedPublicKey,
CompressedReRandomizationKey, CompressedReRandomizationKeySwitchingKey, CompressedServerKey,
KeySwitchingKey, PublicKey, ReRandomizationKey, ReRandomizationKeySwitchingKey, ServerKey,
CompressedReRandomizationKeySwitchingKey, CompressedServerKey, KeySwitchingKey, PublicKey,
ReRandomizationKeySwitchingKey, ServerKey,
};
use strum::FromRepr;

View File

@@ -347,7 +347,7 @@ mod zk {
// Intentionally low so that we test when multiple lists and proofs are needed
let crs = CompactPkeCrs::from_config(config, 32).unwrap();
let metadata = b"rerand";
let metadata = [b'r', b'e', b'r', b'a', b'n', b'd'];
// Case where we want to re-randomize a CompactCiphertextList containing
// FheUint64, FheInt8, and FheBool
@@ -359,7 +359,7 @@ mod zk {
.push(clear_a)
.push(clear_b)
.push(false)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
// Simulate a 256 bits nonce
@@ -378,7 +378,12 @@ mod zk {
// Verify, re_randomize and expand
let expander = compact_list
.verify_re_randomize_and_expand(&crs, &cpk, metadata, seed_gen.next_seed().unwrap())
.verify_re_randomize_and_expand(
&crs,
&cpk,
&metadata,
seed_gen.next_seed().unwrap(),
)
.unwrap();
let a: FheUint64 = expander.get(0).unwrap().unwrap();
@@ -402,7 +407,7 @@ mod zk {
.push(clear_a)
.push(clear_b)
.push(false)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
let nonce: [u8; 256 / 8] = core::array::from_fn(|_| rand::random());

View File

@@ -126,13 +126,9 @@ fn test_server_key_decompression() -> Result<(), Box<dyn std::error::Error>> {
#[test]
fn test_with_seed() {
use crate::shortint::parameters::test_params::TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128;
use crate::Seed;
// Use the most complete meta-params available so that the seed-determinism check
// covers every optional key in the config
let config =
crate::Config::from(TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128);
let builder = ConfigBuilder::default();
let config = builder.build();
let cks1 = ClientKey::generate_with_seed(config, Seed(125));
let cks2 = ClientKey::generate(config);
@@ -209,7 +205,6 @@ fn test_try_from_single_lwe_encryption_key() {
None,
None,
None,
None,
Tag::default(),
);
let sks = ServerKey::new(&client_key);

View File

@@ -47,7 +47,7 @@ fn test_tag_propagation_zk_pok() {
.build();
let crs = crate::zk::CompactPkeCrs::from_config(config, (2 * 32) + (2 * 64) + 2).unwrap();
let metadata = b"hlapi";
let metadata = [b'h', b'l', b'a', b'p', b'i'];
let mut cks = ClientKey::generate(config);
let tag_value = random();
@@ -70,13 +70,15 @@ fn test_tag_propagation_zk_pok() {
.push(i64::MIN)
.push(false)
.push(true)
.build_with_proof_packed(&crs, metadata, crate::zk::ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, crate::zk::ZkComputeLoad::Proof)
.unwrap();
let list_packed: ProvenCompactCiphertextList = serialize_then_deserialize(&list_packed);
assert_eq!(list_packed.tag(), cks.tag());
let expander = list_packed.verify_and_expand(&crs, &cpk, metadata).unwrap();
let expander = list_packed
.verify_and_expand(&crs, &cpk, &metadata)
.unwrap();
{
let au32: FheUint32 = expander.get(0).unwrap().unwrap();
@@ -155,7 +157,7 @@ fn test_tag_propagation_zk_pok_gpu() {
.build();
let crs = crate::zk::CompactPkeCrs::from_config(config, (2 * 32) + (2 * 64) + 2).unwrap();
let metadata = b"hlapi";
let metadata = [b'h', b'l', b'a', b'p', b'i'];
let mut cks = ClientKey::generate(config);
let tag_value = random();
@@ -180,10 +182,12 @@ fn test_tag_propagation_zk_pok_gpu() {
.push(i64::MIN)
.push(false)
.push(true)
.build_with_proof_packed(&crs, metadata, crate::zk::ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, crate::zk::ZkComputeLoad::Proof)
.unwrap();
let expander = list_packed.verify_and_expand(&crs, &cpk, metadata).unwrap();
let expander = list_packed
.verify_and_expand(&crs, &cpk, &metadata)
.unwrap();
{
let au32: FheUint32 = expander.get(0).unwrap().unwrap();

View File

@@ -828,10 +828,8 @@ mod tests {
// We need the private compression key to be common between GPU and CPU
// for the rest of the test to work. This is the only way to do it
// until a more convenient API is added
let (cks, pk, _, nsk, cnsk, cpkrndp, oprf_key, tag) = ck.into_raw_parts();
let ck = ClientKey::from_raw_parts(
cks, pk, common_cck, nsk, cnsk, cpkrndp, oprf_key, tag,
);
let (cks, pk, _, nsk, cnsk, cpkrndp, tag) = ck.into_raw_parts();
let ck = ClientKey::from_raw_parts(cks, pk, common_cck, nsk, cnsk, cpkrndp, tag);
let sk = CompressedServerKey::new(&ck);
assert_eq!(sk.tag().as_u64(), 0);

View File

@@ -11,7 +11,6 @@ use crate::integer::key_switching_key::{
};
use crate::integer::noise_squashing::{CompressedNoiseSquashingKey, NoiseSquashingPrivateKey};
use crate::integer::oprf::{CompressedOprfServerKey, ExpandedOprfServerKey, OprfPrivateKey};
use crate::shortint::atomic_pattern::compressed::{
CompressedAtomicPatternServerKey, CompressedKS32AtomicPatternServerKey,
CompressedStandardAtomicPatternServerKey,
@@ -155,44 +154,6 @@ impl crate::integer::ClientKey {
}
}
impl OprfPrivateKey {
fn generate_with_pre_seeded_generator<G>(
params: AtomicPatternParameters,
max_norm_hwt: NormalizedHammingWeightBound,
secret_generator: &mut SecretRandomGenerator<G>,
) -> Self
where
G: ByteRandomGenerator,
{
let sk = match params {
shortint::AtomicPatternParameters::Standard(std_params) => {
let mut lwe_secret_key =
LweSecretKey::new_empty_key(0u64, std_params.lwe_dimension());
generate_binary_lwe_secret_key_with_bounded_hamming_weight(
&mut lwe_secret_key,
secret_generator,
max_norm_hwt,
);
crate::shortint::oprf::AtomicPatternOprfPrivateKey::Standard(lwe_secret_key)
}
shortint::AtomicPatternParameters::KeySwitch32(ks32_params) => {
let mut lwe_secret_key =
LweSecretKey::new_empty_key(0u32, ks32_params.lwe_dimension());
generate_binary_lwe_secret_key_with_bounded_hamming_weight(
&mut lwe_secret_key,
secret_generator,
max_norm_hwt,
);
crate::shortint::oprf::AtomicPatternOprfPrivateKey::KeySwitch32(lwe_secret_key)
}
};
Self::from_raw_parts(crate::shortint::oprf::OprfPrivateKey::from_raw_parts(sk))
}
}
impl crate::integer::compression_keys::CompressionPrivateKeys {
pub(super) fn generate_with_pre_seeded_generator<G>(
params: CompressionParameters,
@@ -315,14 +276,6 @@ impl ClientKey {
crate::integer::ciphertext::NoiseSquashingCompressionPrivateKey::generate_with_pre_seeded_generator(params, max_norm_hwt, secret_generator)
});
let dedicated_oprf_private_key = config.inner.dedicated_oprf_key.then(|| {
OprfPrivateKey::generate_with_pre_seeded_generator(
config.inner.block_parameters,
max_norm_hwt,
secret_generator,
)
});
Ok(Self {
key: crate::high_level_api::keys::IntegerClientKey {
key: integer_ck,
@@ -335,7 +288,6 @@ impl ClientKey {
noise_squashing_compression_private_key:
integer_private_noise_squashing_compression_key,
cpk_re_randomization_params: config.inner.cpk_re_randomization_params,
dedicated_oprf_private_key,
},
tag,
})
@@ -510,12 +462,6 @@ impl crate::CompressedServerKey {
.as_ref()
.map(|ns_comp_key| ns_comp_key.decompress_with_pre_seeded_generator(generator));
let oprf_key = self
.integer_key
.oprf_key
.as_ref()
.map(|key| key.decompress_with_pre_seeded_generator(generator));
IntegerExpandedServerKey {
compute_key,
cpk_key_switching_key_material,
@@ -524,7 +470,6 @@ impl crate::CompressedServerKey {
noise_squashing_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
}
}
}
@@ -681,126 +626,6 @@ impl integer::compression_keys::CompressedDecompressionKey {
}
}
impl CompressedOprfServerKey {
pub(super) fn generate_with_pre_seeded_generator<Gen>(
private_oprf_key: &OprfPrivateKey,
client_key: &crate::integer::ClientKey,
generator: &mut EncryptionRandomGenerator<Gen>,
) -> Self
where
Gen: ByteRandomGenerator + ParallelByteRandomGenerator,
{
use crate::shortint::oprf::CompressedOprfBootstrappingKey;
let inner = match (&private_oprf_key.0 .0, &client_key.key.atomic_pattern) {
(
crate::shortint::oprf::AtomicPatternOprfPrivateKey::Standard(oprf_lwe_sk),
AtomicPatternClientKey::Standard(ck),
) => match ck.parameters {
PBSParameters::PBS(pbs_params) => {
let seeded_bsk =
allocate_and_generate_lwe_bootstrapping_key_with_pre_seeded_generator(
oprf_lwe_sk,
&ck.glwe_secret_key,
pbs_params.pbs_base_log,
pbs_params.pbs_level,
pbs_params.glwe_noise_distribution,
pbs_params.ciphertext_modulus,
generator,
);
CompressedOprfBootstrappingKey::Classic { seeded_bsk }
}
PBSParameters::MultiBitPBS(mb_params) => {
let mut seeded_bsk = SeededLweMultiBitBootstrapKeyOwned::new(
0u64,
ck.glwe_secret_key.glwe_dimension().to_glwe_size(),
ck.glwe_secret_key.polynomial_size(),
mb_params.pbs_base_log,
mb_params.pbs_level,
oprf_lwe_sk.lwe_dimension(),
mb_params.grouping_factor,
generator.mask_generator().current_compression_seed(),
mb_params.ciphertext_modulus,
);
par_generate_seeded_lwe_multi_bit_bootstrap_key_with_pre_seeded_generator(
oprf_lwe_sk,
&ck.glwe_secret_key,
&mut seeded_bsk,
mb_params.glwe_noise_distribution,
generator,
);
CompressedOprfBootstrappingKey::MultiBit {
seeded_bsk,
deterministic_execution: true,
}
}
},
(
crate::shortint::oprf::AtomicPatternOprfPrivateKey::KeySwitch32(oprf_lwe_sk),
AtomicPatternClientKey::KeySwitch32(ck),
) => {
let seeded_bsk =
allocate_and_generate_lwe_bootstrapping_key_with_pre_seeded_generator(
oprf_lwe_sk,
&ck.glwe_secret_key,
ck.parameters.pbs_base_log,
ck.parameters.pbs_level,
ck.parameters.glwe_noise_distribution,
ck.parameters.ciphertext_modulus,
generator,
);
CompressedOprfBootstrappingKey::Classic { seeded_bsk }
}
_ => panic!("Mismatched atomic patterns for oprf key and client key"),
};
Self(crate::shortint::oprf::CompressedOprfServerKey { inner })
}
pub(super) fn decompress_with_pre_seeded_generator<Gen>(
&self,
generator: &mut MaskRandomGenerator<Gen>,
) -> ExpandedOprfServerKey
where
Gen: ByteRandomGenerator + ParallelByteRandomGenerator,
{
use crate::shortint::oprf::{CompressedOprfBootstrappingKey, ExpandedOprfBootstrappingKey};
let inner = match &self.0.inner {
CompressedOprfBootstrappingKey::Classic { seeded_bsk } => {
let bsk = decompress_bootstrap_key_with_pre_seeded_generator(seeded_bsk, generator);
ExpandedOprfBootstrappingKey::Classic { bsk }
}
CompressedOprfBootstrappingKey::MultiBit {
seeded_bsk,
deterministic_execution: _,
} => {
let bsk =
par_decompress_seeded_lwe_multi_bit_bootstrap_key_to_new_with_pre_seeded_generator(
seeded_bsk, generator,
);
let thread_count =
crate::shortint::engine::ShortintEngine::get_thread_count_for_multi_bit_pbs(
seeded_bsk.input_lwe_dimension(),
seeded_bsk.glwe_size().to_glwe_dimension(),
seeded_bsk.polynomial_size(),
seeded_bsk.decomposition_base_log(),
seeded_bsk.decomposition_level_count(),
seeded_bsk.grouping_factor(),
);
ExpandedOprfBootstrappingKey::MultiBit {
bsk,
thread_count,
deterministic_execution: true,
}
}
};
ExpandedOprfServerKey::from_raw_parts(crate::shortint::oprf::ExpandedOprfServerKey(inner))
}
}
impl CompressedNoiseSquashingKey {
pub(super) fn generate_with_pre_seeded_generator<Gen>(
private_noise_squashing_key: &integer::noise_squashing::NoiseSquashingPrivateKey,
@@ -1007,7 +832,7 @@ where
Self::MultiBit {
bsk,
thread_count,
deterministic_execution: true,
deterministic_execution: params.deterministic_execution,
}
}
}
@@ -1050,7 +875,7 @@ impl ShortintMultibitCompressedBootstrappingKeyParts {
Self {
core_bsk,
deterministic_execution: true,
deterministic_execution: multibit_params.deterministic_execution,
}
}
}
@@ -1260,7 +1085,7 @@ where
}
Self::MultiBit {
seeded_bsk,
deterministic_execution: _,
deterministic_execution,
} => {
let core_bsk = par_decompress_seeded_lwe_multi_bit_bootstrap_key_to_new_with_pre_seeded_generator(
seeded_bsk,
@@ -1280,7 +1105,7 @@ where
ShortintExpandedBootstrappingKey::MultiBit {
bsk: core_bsk,
thread_count,
deterministic_execution: true,
deterministic_execution: *deterministic_execution,
}
}
}
@@ -1317,7 +1142,7 @@ where
Self::MultiBit {
bsk,
thread_count,
deterministic_execution: _,
deterministic_execution,
} => {
let core_bsk = par_decompress_seeded_lwe_multi_bit_bootstrap_key_to_new_with_pre_seeded_generator(
bsk,
@@ -1327,7 +1152,7 @@ where
ShortintExpandedBootstrappingKey::MultiBit {
bsk: core_bsk,
thread_count: *thread_count,
deterministic_execution: true,
deterministic_execution: *deterministic_execution,
}
}
}

View File

@@ -6,7 +6,6 @@ use crate::backward_compatibility::xof_key_set::{
CompressedXofKeySetVersions, XofSeedStartVersions,
};
use crate::core_crypto::commons::generators::MaskRandomGenerator;
use crate::integer::oprf::CompressedOprfServerKey;
use crate::keys::{
CompressedReRandomizationKey, IntegerServerKeyConformanceParams, ReRandomizationKeyGenInfo,
};
@@ -58,7 +57,6 @@ use crate::high_level_api::keys::expanded::IntegerExpandedServerKey;
// else:
// - Re-Rand Public Key (stored in ServerKey) derived from compute params
// 11) SNS Compression Key
// 12) OPRF Key
/// Holds a [XofSeed] and the byte at which the random generator should start.
/// This maintains backward compatibility with tfhe-rs=1.5.4 (csprng=0.8.1)
@@ -361,14 +359,6 @@ impl CompressedXofKeySet {
},
);
let oprf_key = ck.key.dedicated_oprf_private_key.as_ref().map(|sk| {
CompressedOprfServerKey::generate_with_pre_seeded_generator(
sk,
&ck.key.key,
&mut encryption_rand_gen,
)
});
let compressed_server_key = CompressedServerKey::from_raw_parts(
integer_compressed_server_key,
Some(integer_ksk_material),
@@ -377,7 +367,6 @@ impl CompressedXofKeySet {
noise_squashing_bs_key,
noise_squashing_compression_key,
cpk_re_randomization_key,
oprf_key,
ck.tag.clone(),
);

View File

@@ -5,6 +5,5 @@ pub mod client_key;
pub mod key_switching_key;
pub mod list_compression;
pub mod noise_squashing;
pub mod oprf;
pub mod public_key;
pub mod server_key;

View File

@@ -1,20 +0,0 @@
use tfhe_fft::c64;
use tfhe_versionable::VersionsDispatch;
use crate::core_crypto::prelude::Container;
use crate::integer::oprf::{CompressedOprfServerKey, GenericOprfServerKey, OprfPrivateKey};
#[derive(VersionsDispatch)]
pub enum OprfPrivateKeyVersions {
V0(OprfPrivateKey),
}
#[derive(VersionsDispatch)]
pub enum GenericOprfServerKeyVersions<C: Container<Element = c64>> {
V0(GenericOprfServerKey<C>),
}
#[derive(VersionsDispatch)]
pub enum CompressedOprfServerKeyVersions {
V0(CompressedOprfServerKey),
}

View File

@@ -1403,7 +1403,7 @@ mod zk_pok_tests {
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let metadata = b"integer";
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
let num_blocks = 4usize;
let modulus = pke_params
@@ -1433,11 +1433,11 @@ mod zk_pok_tests {
let proven_ct = if is_packed {
builder
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap()
} else {
builder
.build_with_proof(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap()
};
@@ -1452,7 +1452,7 @@ mod zk_pok_tests {
.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.as_view()),
)
.unwrap();
@@ -1495,7 +1495,7 @@ mod zk_pok_tests {
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let metadata = b"integer";
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
let crs = CompactPkeCrs::from_shortint_params(pke_params, LweCiphertextCount(512)).unwrap();
let cks = ClientKey::new(fhe_params);
@@ -1514,13 +1514,13 @@ mod zk_pok_tests {
let proven_ct = CompactCiphertextList::builder(&pk)
.push_with_num_blocks(1u8, 0)
.push_with_num_blocks(-1i8, 0)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
assert!(proven_ct.is_empty());
assert_eq!(proven_ct.len(), 0);
assert_eq!(
proven_ct.verify(&crs, &pk, metadata),
proven_ct.verify(&crs, &pk, &metadata),
ZkVerificationOutcome::Valid
);
assert!(proven_ct.is_conformant(&conformance_params));
@@ -1528,7 +1528,7 @@ mod zk_pok_tests {
proven_ct.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.as_view()),
),
Ok(vec) if vec.is_empty()
@@ -1538,13 +1538,13 @@ mod zk_pok_tests {
// Test by pushing with nothing
{
let proven_ct = CompactCiphertextList::builder(&pk)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
assert!(proven_ct.is_empty());
assert_eq!(proven_ct.len(), 0);
assert_eq!(
proven_ct.verify(&crs, &pk, metadata),
proven_ct.verify(&crs, &pk, &metadata),
ZkVerificationOutcome::Valid
);
assert!(proven_ct.is_conformant(&conformance_params));
@@ -1552,7 +1552,7 @@ mod zk_pok_tests {
proven_ct.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.as_view()),
),
Ok(vec) if vec.is_empty()
@@ -1564,7 +1564,7 @@ mod zk_pok_tests {
let mut proven_ct = CompactCiphertextList::builder(&pk)
.push(1u8)
.push(-1i8)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
proven_ct.ct_list.proved_lists = Vec::new();
@@ -1577,7 +1577,7 @@ mod zk_pok_tests {
let mut proven_ct = CompactCiphertextList::builder(&pk)
.push(1u8)
.push(-1i8)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
proven_ct.info = Vec::new();
@@ -1647,7 +1647,7 @@ mod zk_pok_tests {
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let metadata = b"integer";
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
let crs = CompactPkeCrs::from_shortint_params(pke_params, LweCiphertextCount(2)).unwrap();
let cks = ClientKey::new(fhe_params);
@@ -1664,7 +1664,7 @@ mod zk_pok_tests {
let mut proven_ct = CompactCiphertextList::builder(&pk)
.push_with_num_blocks(1u8, 4)
.push_with_num_blocks(-1i8, 4)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
assert_eq!(proven_ct.len(), 2);
@@ -1684,14 +1684,14 @@ mod zk_pok_tests {
assert!(!proven_ct.is_conformant(&conformance_params));
assert!(proven_ct.is_empty());
assert_eq!(
proven_ct.verify(&crs, &pk, metadata),
proven_ct.verify(&crs, &pk, &metadata),
ZkVerificationOutcome::Valid
);
assert!(matches!(
proven_ct.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.
as_view()),
),
@@ -1706,14 +1706,14 @@ mod zk_pok_tests {
assert!(!proven_ct.is_empty());
assert!(proven_ct.is_packed());
assert_eq!(
proven_ct.verify(&crs, &pk, metadata),
proven_ct.verify(&crs, &pk, &metadata),
ZkVerificationOutcome::Valid
);
assert!(proven_ct
.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.as_view())
)
.is_err());
@@ -1729,14 +1729,14 @@ mod zk_pok_tests {
assert!(!proven_ct.is_empty());
assert!(proven_ct.is_packed());
assert_eq!(
proven_ct.verify(&crs, &pk, metadata),
proven_ct.verify(&crs, &pk, &metadata),
ZkVerificationOutcome::Valid
);
assert!(proven_ct
.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.as_view())
)
.is_ok());
@@ -1748,14 +1748,14 @@ mod zk_pok_tests {
assert!(!proven_ct.is_empty());
assert!(proven_ct.is_packed());
assert_eq!(
proven_ct.verify(&crs, &pk, metadata),
proven_ct.verify(&crs, &pk, &metadata),
ZkVerificationOutcome::Valid
);
assert!(proven_ct
.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.as_view())
)
.is_err());
@@ -1767,7 +1767,7 @@ mod zk_pok_tests {
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let metadata = b"integer";
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
let crs = CompactPkeCrs::from_shortint_params(pke_params, LweCiphertextCount(2)).unwrap();
let cks = ClientKey::new(fhe_params);
@@ -1784,7 +1784,7 @@ mod zk_pok_tests {
let mut proven_ct = CompactCiphertextList::builder(&pk)
.push_with_num_blocks(1u8, 4)
.push_with_num_blocks(-1i8, 4)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
assert!(proven_ct.is_conformant(&conformance_params));
@@ -1803,7 +1803,7 @@ mod zk_pok_tests {
let expander = proven_ct.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.as_view()),
);
assert!(expander.is_err());
@@ -1817,7 +1817,7 @@ mod zk_pok_tests {
TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128_ZKV1;
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let metadata = b"integer";
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
let num_blocks = 4usize;
let modulus = pke_params
@@ -1839,14 +1839,14 @@ mod zk_pok_tests {
let proven_ct = CompactCiphertextList::builder(&pk)
.extend_with_num_blocks(msgs.iter().copied(), num_blocks)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
let expander = proven_ct
.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.as_view()),
)
.unwrap();
@@ -1879,7 +1879,7 @@ mod zk_pok_tests {
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let metadata = b"integer";
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
let crs_blocks_for_64_bits =
64 / ((pke_params.message_modulus.0 * pke_params.carry_modulus.0).ilog2() as usize);
@@ -1900,14 +1900,14 @@ mod zk_pok_tests {
let proven_ct = CompactCiphertextList::builder(&pk)
.extend_with_num_blocks(msgs.iter().copied(), encryption_num_blocks)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
let expander = proven_ct
.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.as_view()),
)
.unwrap();
@@ -1942,7 +1942,7 @@ mod zk_pok_tests {
let ksk_params = PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let fhe_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let metadata = b"integer";
let metadata = [b'i', b'n', b't', b'e', b'g', b'e', b'r'];
let crs_blocks_for_64_bits =
64 / ((pke_params.message_modulus.0 * pke_params.carry_modulus.0).ilog2() as usize);
@@ -1963,7 +1963,7 @@ mod zk_pok_tests {
let proven_ct = CompactCiphertextList::builder(&pk)
.extend_with_num_blocks(msgs.iter().copied(), encryption_num_blocks)
.build_with_proof_packed(&crs, metadata, ZkComputeLoad::Proof)
.build_with_proof_packed(&crs, &metadata, ZkComputeLoad::Proof)
.unwrap();
let infos_block_count = {
@@ -2023,7 +2023,7 @@ mod zk_pok_tests {
.verify_and_expand(
&crs,
&pk,
metadata,
&metadata,
IntegerCompactCiphertextListExpansionMode::CastAndUnpackIfNecessary(ksk.as_view()),
)
.unwrap();

Some files were not shown because too many files have changed in this diff Show More