Add schemes (#71)

* Move br + cbt to schemes/tfhe

* refactor blind rotation

* refactor circuit bootstrapping

* renamed exec -> prepared
This commit is contained in:
Jean-Philippe Bossuat
2025-08-15 15:06:26 +02:00
committed by GitHub
parent 8d9897b88b
commit c7219c35e9
130 changed files with 2631 additions and 3270 deletions

View File

@@ -1,4 +1,7 @@
use core::layouts::{prepared::{GGSWCiphertextExec, GLWESecretExec}, GGSWCiphertext, GLWECiphertext, GLWESecret, Infos};
use core::layouts::{
GGSWCiphertext, GLWECiphertext, GLWESecret, Infos,
prepared::{GGSWCiphertextPrepared, GLWESecretPrepared, PrepareAlloc},
};
use std::hint::black_box;
use backend::{
@@ -63,7 +66,7 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
sk.fill_ternary_prob(0.5, &mut source_xs);
let sk_dft: GLWESecretExec<Vec<u8>, FFT64> = GLWESecretExec::from(&module, &sk);
let sk_dft: GLWESecretPrepared<Vec<u8>, FFT64> = sk.prepare_alloc(&module, scratch.borrow());
ct_ggsw.encrypt_sk(
&module,
@@ -84,10 +87,10 @@ fn bench_external_product_glwe_fft64(c: &mut Criterion) {
scratch.borrow(),
);
let ggsw_exec: GGSWCiphertextExec<Vec<u8>, FFT64> = GGSWCiphertextExec::from(&module, &ct_ggsw, scratch.borrow());
let ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, FFT64> = ct_ggsw.prepare_alloc(&module, scratch.borrow());
move || {
black_box(ct_glwe_out.external_product(&module, &ct_glwe_in, &ggsw_exec, scratch.borrow()));
black_box(ct_glwe_out.external_product(&module, &ct_glwe_in, &ggsw_prepared, scratch.borrow()));
}
}
@@ -157,7 +160,7 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
let mut sk: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
sk.fill_ternary_prob(0.5, &mut source_xs);
let sk_dft: GLWESecretExec<Vec<u8>, FFT64> = GLWESecretExec::from(&module, &sk);
let sk_dft: GLWESecretPrepared<Vec<u8>, FFT64> = sk.prepare_alloc(&module, scratch.borrow());
ct_ggsw.encrypt_sk(
&module,
@@ -178,11 +181,11 @@ fn bench_external_product_glwe_inplace_fft64(c: &mut Criterion) {
scratch.borrow(),
);
let ggsw_exec: GGSWCiphertextExec<Vec<u8>, FFT64> = GGSWCiphertextExec::from(&module, &ct_ggsw, scratch.borrow());
let ggsw_prepared: GGSWCiphertextPrepared<Vec<u8>, FFT64> = ct_ggsw.prepare_alloc(&module, scratch.borrow());
move || {
let scratch_borrow = scratch.borrow();
black_box(ct_glwe.external_product_inplace(&module, &ggsw_exec, scratch_borrow));
black_box(ct_glwe.external_product_inplace(&module, &ggsw_prepared, scratch_borrow));
}
}

View File

@@ -1,4 +1,7 @@
use core::layouts::{prepared::{GGLWEAutomorphismKeyExec, GGLWESwitchingKeyExec, GLWESecretExec}, GGLWEAutomorphismKey, GGLWESwitchingKey, GLWECiphertext, GLWESecret, Infos};
use core::layouts::{
GGLWEAutomorphismKey, GGLWESwitchingKey, GLWECiphertext, GLWESecret, Infos,
prepared::{GGLWEAutomorphismKeyPrepared, GGLWESwitchingKeyPrepared, GLWESecretPrepared, PrepareAlloc},
};
use std::{hint::black_box, time::Duration};
use backend::{
@@ -66,7 +69,7 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank_in);
sk_in.fill_ternary_prob(0.5, &mut source_xs);
let sk_in_dft: GLWESecretExec<Vec<u8>, FFT64> = GLWESecretExec::from(&module, &sk_in);
let sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64> = sk_in.prepare_alloc(&module, scratch.borrow());
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank_out);
sk_out.fill_ternary_prob(0.5, &mut source_xs);
@@ -90,10 +93,10 @@ fn bench_keyswitch_glwe_fft64(c: &mut Criterion) {
scratch.borrow(),
);
let ksk_exec: GGLWEAutomorphismKeyExec<Vec<u8>, _> = GGLWEAutomorphismKeyExec::from(&module, &ksk, scratch.borrow());
let ksk_prepared: GGLWEAutomorphismKeyPrepared<Vec<u8>, _> = ksk.prepare_alloc(&module, scratch.borrow());
move || {
black_box(ct_out.automorphism(&module, &ct_in, &ksk_exec, scratch.borrow()));
black_box(ct_out.automorphism(&module, &ct_in, &ksk_prepared, scratch.borrow()));
}
}
@@ -161,7 +164,7 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
let mut sk_in: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
sk_in.fill_ternary_prob(0.5, &mut source_xs);
let sk_in_dft: GLWESecretExec<Vec<u8>, FFT64> = GLWESecretExec::from(&module, &sk_in);
let sk_in_dft: GLWESecretPrepared<Vec<u8>, FFT64> = sk_in.prepare_alloc(&module, scratch.borrow());
let mut sk_out: GLWESecret<Vec<u8>> = GLWESecret::alloc(n, rank);
sk_out.fill_ternary_prob(0.5, &mut source_xs);
@@ -185,10 +188,10 @@ fn bench_keyswitch_glwe_inplace_fft64(c: &mut Criterion) {
scratch.borrow(),
);
let ksk_exec: GGLWESwitchingKeyExec<Vec<u8>, FFT64> = GGLWESwitchingKeyExec::from(&module, &ksk, scratch.borrow());
let ksk_prepared: GGLWESwitchingKeyPrepared<Vec<u8>, FFT64> = ksk.prepare_alloc(&module, scratch.borrow());
move || {
black_box(ct.keyswitch_inplace(&module, &ksk_exec, scratch.borrow()));
black_box(ct.keyswitch_inplace(&module, &ksk_prepared, scratch.borrow()));
}
}