mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
Merge pull request #105 from phantomzone-org/dev_bdd
Update BDD circuits, add tests & fix non-zero scratch related bug
This commit is contained in:
@@ -11,7 +11,7 @@ use crate::layouts::prepared::GLWESecretPreparedToRef;
|
||||
use crate::layouts::{GGSW, GGSWInfos, GGSWToRef, GLWEInfos, GLWEPlaintext, LWEInfos, prepared::GLWESecretPrepared};
|
||||
|
||||
impl<D: DataRef> GGSW<D> {
|
||||
pub fn assert_noise<M, BE: Backend, P, S, F>(&self, module: &M, sk_prepared: &S, pt_want: &P, max_noise: F)
|
||||
pub fn assert_noise<M, BE: Backend, P, S, F>(&self, module: &M, sk_prepared: &S, pt_want: &P, max_noise: &F)
|
||||
where
|
||||
S: GLWESecretPreparedToRef<BE>,
|
||||
P: ScalarZnxToRef,
|
||||
@@ -32,7 +32,7 @@ impl<D: DataRef> GGSW<D> {
|
||||
}
|
||||
|
||||
pub trait GGSWNoise<BE: Backend> {
|
||||
fn ggsw_assert_noise<R, S, P, F>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: F)
|
||||
fn ggsw_assert_noise<R, S, P, F>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: &F)
|
||||
where
|
||||
R: GGSWToRef,
|
||||
S: GLWESecretPreparedToRef<BE>,
|
||||
@@ -57,7 +57,7 @@ where
|
||||
Scratch<BE>: ScratchTakeBasic,
|
||||
ScratchOwned<BE>: ScratchOwnedBorrow<BE> + ScratchOwnedAlloc<BE>,
|
||||
{
|
||||
fn ggsw_assert_noise<R, S, P, F>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: F)
|
||||
fn ggsw_assert_noise<R, S, P, F>(&self, res: &R, sk_prepared: &S, pt_want: &P, max_noise: &F)
|
||||
where
|
||||
R: GGSWToRef,
|
||||
S: GLWESecretPreparedToRef<BE>,
|
||||
|
||||
@@ -168,7 +168,7 @@ where
|
||||
) + 0.5
|
||||
};
|
||||
|
||||
ct_out.assert_noise(module, &sk_prepared, &pt_scalar, max_noise);
|
||||
ct_out.assert_noise(module, &sk_prepared, &pt_scalar, &max_noise);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,7 +308,7 @@ where
|
||||
) + 0.5
|
||||
};
|
||||
|
||||
ct.assert_noise(module, &sk_prepared, &pt_scalar, max_noise);
|
||||
ct.assert_noise(module, &sk_prepared, &pt_scalar, &max_noise);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ where
|
||||
|
||||
let noise_f = |_col_i: usize| -(k as f64) + SIGMA.log2() + 0.5;
|
||||
|
||||
ct.assert_noise(module, &sk_prepared, &pt_scalar, noise_f);
|
||||
ct.assert_noise(module, &sk_prepared, &pt_scalar, &noise_f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ where
|
||||
let mut ct: GGSW<Vec<u8>> = GGSW::alloc_from_infos(&ggsw_infos);
|
||||
ct.decompress(module, &ct_compressed);
|
||||
|
||||
ct.assert_noise(module, &sk_prepared, &pt_scalar, noise_f);
|
||||
ct.assert_noise(module, &sk_prepared, &pt_scalar, &noise_f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ where
|
||||
) + 0.5
|
||||
};
|
||||
|
||||
ggsw_out.assert_noise(module, &sk_prepared, &pt_in, max_noise);
|
||||
ggsw_out.assert_noise(module, &sk_prepared, &pt_in, &max_noise);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,7 +266,7 @@ where
|
||||
) + 0.5
|
||||
};
|
||||
|
||||
ggsw_out.assert_noise(module, &sk_prepared, &pt_in, max_noise);
|
||||
ggsw_out.assert_noise(module, &sk_prepared, &pt_in, &max_noise);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ where
|
||||
) + 0.5
|
||||
};
|
||||
|
||||
ggsw_out.assert_noise(module, &sk_out_prepared, &pt_scalar, max_noise);
|
||||
ggsw_out.assert_noise(module, &sk_out_prepared, &pt_scalar, &max_noise);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -323,7 +323,7 @@ where
|
||||
) + 0.5
|
||||
};
|
||||
|
||||
ggsw_out.assert_noise(module, &sk_out_prepared, &pt_scalar, max_noise);
|
||||
ggsw_out.assert_noise(module, &sk_out_prepared, &pt_scalar, &max_noise);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,9 @@ use poulpy_core::{
|
||||
layouts::{Base2K, GLWE, GLWEInfos, GLWEPlaintextLayout, GLWESecretPreparedToRef, LWEInfos, Rank, TorusPrecision},
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
use poulpy_core::GLWEEncryptSk;
|
||||
use poulpy_core::ScratchTakeCore;
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
#[cfg(test)]
|
||||
#[cfg(test)]
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch, ZnxZero};
|
||||
use poulpy_hal::source::Source;
|
||||
|
||||
use crate::tfhe::bdd_arithmetic::{FromBits, ToBits, UnsignedInteger};
|
||||
@@ -43,16 +40,14 @@ impl<D: DataRef, T: UnsignedInteger> GLWEInfos for FheUintBlocks<D, T> {
|
||||
}
|
||||
|
||||
impl<T: UnsignedInteger> FheUintBlocks<Vec<u8>, T> {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn alloc<A, BE: Backend>(module: &Module<BE>, infos: &A) -> Self
|
||||
pub fn alloc_from_infos<A, BE: Backend>(module: &Module<BE>, infos: &A) -> Self
|
||||
where
|
||||
A: GLWEInfos,
|
||||
{
|
||||
Self::alloc_with(module, infos.base2k(), infos.k(), infos.rank())
|
||||
Self::alloc(module, infos.base2k(), infos.k(), infos.rank())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn alloc_with<BE: Backend>(module: &Module<BE>, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self {
|
||||
pub fn alloc<BE: Backend>(module: &Module<BE>, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self {
|
||||
Self {
|
||||
blocks: (0..T::WORD_SIZE)
|
||||
.map(|_| GLWE::alloc(module.n().into(), base2k, k, rank))
|
||||
@@ -64,9 +59,7 @@ impl<T: UnsignedInteger> FheUintBlocks<Vec<u8>, T> {
|
||||
}
|
||||
|
||||
impl<D: DataMut, T: UnsignedInteger + ToBits> FheUintBlocks<D, T> {
|
||||
#[allow(dead_code)]
|
||||
#[cfg(test)]
|
||||
pub(crate) fn encrypt_sk<S, BE: Backend>(
|
||||
pub fn encrypt_sk<S, BE: Backend>(
|
||||
&mut self,
|
||||
module: &Module<BE>,
|
||||
value: T,
|
||||
@@ -80,6 +73,7 @@ impl<D: DataMut, T: UnsignedInteger + ToBits> FheUintBlocks<D, T> {
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
use poulpy_core::layouts::GLWEPlaintextLayout;
|
||||
use poulpy_hal::layouts::ZnxZero;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
@@ -95,6 +89,7 @@ impl<D: DataMut, T: UnsignedInteger + ToBits> FheUintBlocks<D, T> {
|
||||
};
|
||||
|
||||
let (mut pt, scratch_1) = scratch.take_glwe_plaintext(&pt_infos);
|
||||
pt.data.zero();
|
||||
|
||||
for i in 0..T::WORD_SIZE {
|
||||
pt.encode_coeff_i64(value.bit(i) as i64, TorusPrecision(2), 0);
|
||||
@@ -159,6 +154,7 @@ impl<D: DataRef, T: UnsignedInteger + FromBits + ToBits> FheUintBlocks<D, T> {
|
||||
};
|
||||
|
||||
let (mut pt_want, scratch_1) = scratch.take_glwe_plaintext(&pt_infos);
|
||||
pt_want.data.zero();
|
||||
|
||||
let mut noise: Vec<f64> = vec![0f64; T::WORD_SIZE];
|
||||
|
||||
|
||||
@@ -7,32 +7,30 @@ use crate::tfhe::{
|
||||
circuit_bootstrapping::CirtuitBootstrappingExecute,
|
||||
};
|
||||
use poulpy_core::GGSWNoise;
|
||||
#[cfg(test)]
|
||||
|
||||
use poulpy_core::layouts::{Base2K, Dnum, Dsize, Rank, TorusPrecision};
|
||||
use poulpy_core::layouts::{GGSW, GLWESecretPreparedToRef};
|
||||
use poulpy_core::{
|
||||
LWEFromGLWE, ScratchTakeCore,
|
||||
layouts::{GGSWInfos, GGSWPreparedFactory, GLWEInfos, LWE, LWEInfos},
|
||||
};
|
||||
#[cfg(test)]
|
||||
|
||||
use poulpy_hal::api::ModuleN;
|
||||
use poulpy_hal::layouts::{Backend, Data, DataMut, DataRef, Module, Scratch};
|
||||
|
||||
pub(crate) struct FheUintBlocksPreparedDebug<D: Data, T: UnsignedInteger> {
|
||||
pub struct FheUintBlocksPreparedDebug<D: Data, T: UnsignedInteger> {
|
||||
pub(crate) blocks: Vec<GGSW<D>>,
|
||||
pub(crate) _base: u8,
|
||||
pub(crate) _phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl<T: UnsignedInteger> FheUintBlocksPreparedDebug<Vec<u8>, T> {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn alloc<A, M>(module: &M, infos: &A) -> Self
|
||||
pub fn alloc_from_infos<A, M>(module: &M, infos: &A) -> Self
|
||||
where
|
||||
M: ModuleN,
|
||||
A: GGSWInfos,
|
||||
{
|
||||
Self::alloc_with(
|
||||
Self::alloc(
|
||||
module,
|
||||
infos.base2k(),
|
||||
infos.k(),
|
||||
@@ -42,8 +40,7 @@ impl<T: UnsignedInteger> FheUintBlocksPreparedDebug<Vec<u8>, T> {
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn alloc_with<M>(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self
|
||||
pub fn alloc<M>(module: &M, base2k: Base2K, k: TorusPrecision, dnum: Dnum, dsize: Dsize, rank: Rank) -> Self
|
||||
where
|
||||
M: ModuleN,
|
||||
{
|
||||
@@ -88,7 +85,7 @@ impl<D: DataRef, T: UnsignedInteger> GGSWInfos for FheUintBlocksPreparedDebug<D,
|
||||
}
|
||||
|
||||
impl<D: DataRef, T: UnsignedInteger + ToBits> FheUintBlocksPreparedDebug<D, T> {
|
||||
pub(crate) fn noise<S, M, BE: Backend>(&self, module: &M, sk: &S, want: T)
|
||||
pub fn print_noise<S, M, BE: Backend>(&self, module: &M, sk: &S, want: T)
|
||||
where
|
||||
S: GLWESecretPreparedToRef<BE>,
|
||||
M: GGSWNoise<BE>,
|
||||
@@ -100,6 +97,20 @@ impl<D: DataRef, T: UnsignedInteger + ToBits> FheUintBlocksPreparedDebug<D, T> {
|
||||
ggsw.print_noise(module, sk, &pt_want);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assert_noise<S, M, F, BE: Backend>(&self, module: &M, sk: &S, want: T, max_noise: &F)
|
||||
where
|
||||
S: GLWESecretPreparedToRef<BE>,
|
||||
M: GGSWNoise<BE>,
|
||||
F: Fn(usize) -> f64,
|
||||
{
|
||||
for (i, ggsw) in self.blocks.iter().enumerate() {
|
||||
use poulpy_hal::layouts::{ScalarZnx, ZnxViewMut};
|
||||
let mut pt_want = ScalarZnx::alloc(self.n().into(), 1);
|
||||
pt_want.at_mut(0, 0)[0] = want.bit(i) as i64;
|
||||
ggsw.assert_noise(module, sk, &pt_want, max_noise);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<BRA: BlindRotationAlgo, BE: Backend, T: UnsignedInteger> FheUintBlockDebugPrepare<BRA, T, BE> for Module<BE>
|
||||
|
||||
@@ -3,17 +3,16 @@ use std::marker::PhantomData;
|
||||
use poulpy_core::layouts::{
|
||||
Base2K, Dnum, Dsize, GGSWInfos, GGSWPreparedFactory, GLWEInfos, LWEInfos, Rank, TorusPrecision, prepared::GGSWPrepared,
|
||||
};
|
||||
#[cfg(test)]
|
||||
|
||||
use poulpy_core::{GGSWEncryptSk, ScratchTakeCore, layouts::GLWESecretPreparedToRef};
|
||||
use poulpy_hal::layouts::{Backend, Data, DataRef, Module};
|
||||
#[cfg(test)]
|
||||
|
||||
use poulpy_hal::{
|
||||
api::ModuleN,
|
||||
layouts::{DataMut, Scratch},
|
||||
source::Source,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::tfhe::bdd_arithmetic::ToBits;
|
||||
use crate::tfhe::bdd_arithmetic::UnsignedInteger;
|
||||
|
||||
@@ -83,13 +82,11 @@ impl<T: UnsignedInteger, BE: Backend> FheUintBlocksPrepared<Vec<u8>, T, BE> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl<T: UnsignedInteger + ToBits, BE: Backend> FheUintBlocksPreparedEncryptSk<T, BE> for Module<BE> where
|
||||
Self: Sized + ModuleN + GGSWEncryptSk<BE> + GGSWPreparedFactory<BE>
|
||||
{
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub trait FheUintBlocksPreparedEncryptSk<T: UnsignedInteger + ToBits, BE: Backend>
|
||||
where
|
||||
Self: Sized + ModuleN + GGSWEncryptSk<BE> + GGSWPreparedFactory<BE>,
|
||||
@@ -107,7 +104,7 @@ where
|
||||
S: GLWESecretPreparedToRef<BE> + GLWEInfos,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
use poulpy_hal::api::ScratchTakeBasic;
|
||||
use poulpy_hal::{api::ScratchTakeBasic, layouts::ZnxZero};
|
||||
|
||||
assert!(self.n().is_multiple_of(T::WORD_SIZE));
|
||||
assert_eq!(res.n(), self.n() as u32);
|
||||
@@ -115,10 +112,10 @@ where
|
||||
|
||||
let (mut tmp_ggsw, scratch_1) = scratch.take_ggsw(res);
|
||||
let (mut pt, scratch_2) = scratch_1.take_scalar_znx(self.n(), 1);
|
||||
pt.zero();
|
||||
|
||||
for i in 0..T::WORD_SIZE {
|
||||
use poulpy_hal::layouts::ZnxViewMut;
|
||||
|
||||
pt.at_mut(0, 0)[0] = value.bit(i) as i64;
|
||||
tmp_ggsw.encrypt_sk(self, &pt, sk, source_xa, source_xe, scratch_2);
|
||||
res.blocks[i].prepare(self, &tmp_ggsw, scratch_2);
|
||||
@@ -126,7 +123,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl<D: DataMut, T: UnsignedInteger + ToBits, BE: Backend> FheUintBlocksPrepared<D, T, BE> {
|
||||
pub(crate) fn encrypt_sk<M, S>(
|
||||
&mut self,
|
||||
|
||||
@@ -2,10 +2,9 @@ mod block;
|
||||
mod block_prepared;
|
||||
mod word;
|
||||
|
||||
#[cfg(test)]
|
||||
mod block_debug;
|
||||
#[cfg(test)]
|
||||
pub(crate) use block_debug::*;
|
||||
|
||||
pub use block_debug::*;
|
||||
|
||||
pub use block::*;
|
||||
pub use block_prepared::*;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,201 +1,73 @@
|
||||
use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
|
||||
pub(crate) enum AnyBitCircuit {
|
||||
B0(BitCircuit<3, 2>),
|
||||
B1(BitCircuit<3, 2>),
|
||||
B2(BitCircuit<3, 2>),
|
||||
B3(BitCircuit<3, 2>),
|
||||
B4(BitCircuit<3, 2>),
|
||||
B5(BitCircuit<3, 2>),
|
||||
B6(BitCircuit<3, 2>),
|
||||
B7(BitCircuit<3, 2>),
|
||||
B8(BitCircuit<3, 2>),
|
||||
B9(BitCircuit<3, 2>),
|
||||
B10(BitCircuit<3, 2>),
|
||||
B11(BitCircuit<3, 2>),
|
||||
B12(BitCircuit<3, 2>),
|
||||
B13(BitCircuit<3, 2>),
|
||||
B14(BitCircuit<3, 2>),
|
||||
B15(BitCircuit<3, 2>),
|
||||
B16(BitCircuit<3, 2>),
|
||||
B17(BitCircuit<3, 2>),
|
||||
B18(BitCircuit<3, 2>),
|
||||
B19(BitCircuit<3, 2>),
|
||||
B20(BitCircuit<3, 2>),
|
||||
B21(BitCircuit<3, 2>),
|
||||
B22(BitCircuit<3, 2>),
|
||||
B23(BitCircuit<3, 2>),
|
||||
B24(BitCircuit<3, 2>),
|
||||
B25(BitCircuit<3, 2>),
|
||||
B26(BitCircuit<3, 2>),
|
||||
B27(BitCircuit<3, 2>),
|
||||
B28(BitCircuit<3, 2>),
|
||||
B29(BitCircuit<3, 2>),
|
||||
B30(BitCircuit<3, 2>),
|
||||
B31(BitCircuit<3, 2>),
|
||||
B0(BitCircuit<4>),
|
||||
B1(BitCircuit<4>),
|
||||
B2(BitCircuit<4>),
|
||||
B3(BitCircuit<4>),
|
||||
B4(BitCircuit<4>),
|
||||
B5(BitCircuit<4>),
|
||||
B6(BitCircuit<4>),
|
||||
B7(BitCircuit<4>),
|
||||
B8(BitCircuit<4>),
|
||||
B9(BitCircuit<4>),
|
||||
B10(BitCircuit<4>),
|
||||
B11(BitCircuit<4>),
|
||||
B12(BitCircuit<4>),
|
||||
B13(BitCircuit<4>),
|
||||
B14(BitCircuit<4>),
|
||||
B15(BitCircuit<4>),
|
||||
B16(BitCircuit<4>),
|
||||
B17(BitCircuit<4>),
|
||||
B18(BitCircuit<4>),
|
||||
B19(BitCircuit<4>),
|
||||
B20(BitCircuit<4>),
|
||||
B21(BitCircuit<4>),
|
||||
B22(BitCircuit<4>),
|
||||
B23(BitCircuit<4>),
|
||||
B24(BitCircuit<4>),
|
||||
B25(BitCircuit<4>),
|
||||
B26(BitCircuit<4>),
|
||||
B27(BitCircuit<4>),
|
||||
B28(BitCircuit<4>),
|
||||
B29(BitCircuit<4>),
|
||||
B30(BitCircuit<4>),
|
||||
B31(BitCircuit<4>),
|
||||
}
|
||||
impl BitCircuitInfo for AnyBitCircuit {
|
||||
fn info(&self) -> (&[Node], &[usize], usize) {
|
||||
fn info(&self) -> (&[Node], usize) {
|
||||
match self {
|
||||
AnyBitCircuit::B0(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B1(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B2(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B3(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B4(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B5(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B6(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B7(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B8(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B9(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B10(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B11(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B12(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B13(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B14(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B15(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B16(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B17(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B18(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B19(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B20(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B21(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B22(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B23(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B24(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B25(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B26(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B27(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B28(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B29(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B30(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B31(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B0(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B1(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B2(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B3(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B4(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B5(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B6(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B7(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B8(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B9(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B10(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B11(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B12(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B13(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B14(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B15(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B16(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B17(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B18(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B19(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B20(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B21(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B22(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B23(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B24(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B25(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B26(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B27(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B28(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B29(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B30(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B31(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,170 +79,298 @@ impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 32usize> {
|
||||
fn output_size(&self) -> usize {
|
||||
u32::BITS as usize
|
||||
}
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], usize) {
|
||||
self.0[bit].info()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 32usize> = Circuit([
|
||||
AnyBitCircuit::B0(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(32, 1, 0), Node::new(0, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(32, 1, 0),
|
||||
Node::Cmux(0, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B1(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(33, 1, 0), Node::new(1, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(33, 1, 0),
|
||||
Node::Cmux(1, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B2(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(34, 1, 0), Node::new(2, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(34, 1, 0),
|
||||
Node::Cmux(2, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B3(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(35, 1, 0), Node::new(3, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(35, 1, 0),
|
||||
Node::Cmux(3, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B4(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(36, 1, 0), Node::new(4, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(36, 1, 0),
|
||||
Node::Cmux(4, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B5(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(37, 1, 0), Node::new(5, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(37, 1, 0),
|
||||
Node::Cmux(5, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B6(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(38, 1, 0), Node::new(6, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(38, 1, 0),
|
||||
Node::Cmux(6, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B7(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(39, 1, 0), Node::new(7, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(39, 1, 0),
|
||||
Node::Cmux(7, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B8(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(40, 1, 0), Node::new(8, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(40, 1, 0),
|
||||
Node::Cmux(8, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B9(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(41, 1, 0), Node::new(9, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(41, 1, 0),
|
||||
Node::Cmux(9, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B10(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(42, 1, 0), Node::new(10, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(42, 1, 0),
|
||||
Node::Cmux(10, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B11(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(43, 1, 0), Node::new(11, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(43, 1, 0),
|
||||
Node::Cmux(11, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B12(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(44, 1, 0), Node::new(12, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(44, 1, 0),
|
||||
Node::Cmux(12, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B13(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(45, 1, 0), Node::new(13, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(45, 1, 0),
|
||||
Node::Cmux(13, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B14(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(46, 1, 0), Node::new(14, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(46, 1, 0),
|
||||
Node::Cmux(14, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B15(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(47, 1, 0), Node::new(15, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(47, 1, 0),
|
||||
Node::Cmux(15, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B16(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(48, 1, 0), Node::new(16, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(48, 1, 0),
|
||||
Node::Cmux(16, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B17(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(49, 1, 0), Node::new(17, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(49, 1, 0),
|
||||
Node::Cmux(17, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B18(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(50, 1, 0), Node::new(18, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(50, 1, 0),
|
||||
Node::Cmux(18, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B19(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(51, 1, 0), Node::new(19, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(51, 1, 0),
|
||||
Node::Cmux(19, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B20(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(52, 1, 0), Node::new(20, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(52, 1, 0),
|
||||
Node::Cmux(20, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B21(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(53, 1, 0), Node::new(21, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(53, 1, 0),
|
||||
Node::Cmux(21, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B22(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(54, 1, 0), Node::new(22, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(54, 1, 0),
|
||||
Node::Cmux(22, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B23(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(55, 1, 0), Node::new(23, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(55, 1, 0),
|
||||
Node::Cmux(23, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B24(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(56, 1, 0), Node::new(24, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(56, 1, 0),
|
||||
Node::Cmux(24, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B25(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(57, 1, 0), Node::new(25, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(57, 1, 0),
|
||||
Node::Cmux(25, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B26(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(58, 1, 0), Node::new(26, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(58, 1, 0),
|
||||
Node::Cmux(26, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B27(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(59, 1, 0), Node::new(27, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(59, 1, 0),
|
||||
Node::Cmux(27, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B28(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(60, 1, 0), Node::new(28, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(60, 1, 0),
|
||||
Node::Cmux(28, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B29(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(61, 1, 0), Node::new(29, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(61, 1, 0),
|
||||
Node::Cmux(29, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B30(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(62, 1, 0), Node::new(30, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(62, 1, 0),
|
||||
Node::Cmux(30, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B31(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(63, 1, 0), Node::new(31, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Copy,
|
||||
Node::Cmux(63, 1, 0),
|
||||
Node::Cmux(31, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
]);
|
||||
|
||||
@@ -1,201 +1,73 @@
|
||||
use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
|
||||
pub(crate) enum AnyBitCircuit {
|
||||
B0(BitCircuit<3, 2>),
|
||||
B1(BitCircuit<3, 2>),
|
||||
B2(BitCircuit<3, 2>),
|
||||
B3(BitCircuit<3, 2>),
|
||||
B4(BitCircuit<3, 2>),
|
||||
B5(BitCircuit<3, 2>),
|
||||
B6(BitCircuit<3, 2>),
|
||||
B7(BitCircuit<3, 2>),
|
||||
B8(BitCircuit<3, 2>),
|
||||
B9(BitCircuit<3, 2>),
|
||||
B10(BitCircuit<3, 2>),
|
||||
B11(BitCircuit<3, 2>),
|
||||
B12(BitCircuit<3, 2>),
|
||||
B13(BitCircuit<3, 2>),
|
||||
B14(BitCircuit<3, 2>),
|
||||
B15(BitCircuit<3, 2>),
|
||||
B16(BitCircuit<3, 2>),
|
||||
B17(BitCircuit<3, 2>),
|
||||
B18(BitCircuit<3, 2>),
|
||||
B19(BitCircuit<3, 2>),
|
||||
B20(BitCircuit<3, 2>),
|
||||
B21(BitCircuit<3, 2>),
|
||||
B22(BitCircuit<3, 2>),
|
||||
B23(BitCircuit<3, 2>),
|
||||
B24(BitCircuit<3, 2>),
|
||||
B25(BitCircuit<3, 2>),
|
||||
B26(BitCircuit<3, 2>),
|
||||
B27(BitCircuit<3, 2>),
|
||||
B28(BitCircuit<3, 2>),
|
||||
B29(BitCircuit<3, 2>),
|
||||
B30(BitCircuit<3, 2>),
|
||||
B31(BitCircuit<3, 2>),
|
||||
B0(BitCircuit<4>),
|
||||
B1(BitCircuit<4>),
|
||||
B2(BitCircuit<4>),
|
||||
B3(BitCircuit<4>),
|
||||
B4(BitCircuit<4>),
|
||||
B5(BitCircuit<4>),
|
||||
B6(BitCircuit<4>),
|
||||
B7(BitCircuit<4>),
|
||||
B8(BitCircuit<4>),
|
||||
B9(BitCircuit<4>),
|
||||
B10(BitCircuit<4>),
|
||||
B11(BitCircuit<4>),
|
||||
B12(BitCircuit<4>),
|
||||
B13(BitCircuit<4>),
|
||||
B14(BitCircuit<4>),
|
||||
B15(BitCircuit<4>),
|
||||
B16(BitCircuit<4>),
|
||||
B17(BitCircuit<4>),
|
||||
B18(BitCircuit<4>),
|
||||
B19(BitCircuit<4>),
|
||||
B20(BitCircuit<4>),
|
||||
B21(BitCircuit<4>),
|
||||
B22(BitCircuit<4>),
|
||||
B23(BitCircuit<4>),
|
||||
B24(BitCircuit<4>),
|
||||
B25(BitCircuit<4>),
|
||||
B26(BitCircuit<4>),
|
||||
B27(BitCircuit<4>),
|
||||
B28(BitCircuit<4>),
|
||||
B29(BitCircuit<4>),
|
||||
B30(BitCircuit<4>),
|
||||
B31(BitCircuit<4>),
|
||||
}
|
||||
impl BitCircuitInfo for AnyBitCircuit {
|
||||
fn info(&self) -> (&[Node], &[usize], usize) {
|
||||
fn info(&self) -> (&[Node], usize) {
|
||||
match self {
|
||||
AnyBitCircuit::B0(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B1(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B2(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B3(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B4(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B5(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B6(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B7(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B8(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B9(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B10(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B11(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B12(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B13(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B14(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B15(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B16(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B17(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B18(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B19(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B20(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B21(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B22(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B23(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B24(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B25(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B26(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B27(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B28(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B29(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B30(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B31(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B0(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B1(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B2(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B3(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B4(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B5(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B6(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B7(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B8(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B9(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B10(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B11(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B12(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B13(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B14(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B15(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B16(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B17(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B18(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B19(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B20(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B21(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B22(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B23(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B24(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B25(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B26(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B27(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B28(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B29(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B30(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B31(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,170 +79,298 @@ impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 32usize> {
|
||||
fn output_size(&self) -> usize {
|
||||
u32::BITS as usize
|
||||
}
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], usize) {
|
||||
self.0[bit].info()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 32usize> = Circuit([
|
||||
AnyBitCircuit::B0(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(32, 1, 0), Node::new(0, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(32, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(0, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B1(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(33, 1, 0), Node::new(1, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(33, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(1, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B2(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(34, 1, 0), Node::new(2, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(34, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(2, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B3(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(35, 1, 0), Node::new(3, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(35, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(3, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B4(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(36, 1, 0), Node::new(4, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(36, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(4, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B5(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(37, 1, 0), Node::new(5, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(37, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(5, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B6(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(38, 1, 0), Node::new(6, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(38, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(6, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B7(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(39, 1, 0), Node::new(7, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(39, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(7, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B8(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(40, 1, 0), Node::new(8, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(40, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(8, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B9(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(41, 1, 0), Node::new(9, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(41, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(9, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B10(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(42, 1, 0), Node::new(10, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(42, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(10, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B11(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(43, 1, 0), Node::new(11, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(43, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(11, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B12(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(44, 1, 0), Node::new(12, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(44, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(12, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B13(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(45, 1, 0), Node::new(13, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(45, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(13, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B14(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(46, 1, 0), Node::new(14, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(46, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(14, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B15(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(47, 1, 0), Node::new(15, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(47, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(15, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B16(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(48, 1, 0), Node::new(16, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(48, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(16, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B17(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(49, 1, 0), Node::new(17, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(49, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(17, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B18(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(50, 1, 0), Node::new(18, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(50, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(18, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B19(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(51, 1, 0), Node::new(19, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(51, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(19, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B20(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(52, 1, 0), Node::new(20, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(52, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(20, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B21(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(53, 1, 0), Node::new(21, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(53, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(21, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B22(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(54, 1, 0), Node::new(22, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(54, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(22, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B23(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(55, 1, 0), Node::new(23, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(55, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(23, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B24(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(56, 1, 0), Node::new(24, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(56, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(24, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B25(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(57, 1, 0), Node::new(25, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(57, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(25, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B26(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(58, 1, 0), Node::new(26, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(58, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(26, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B27(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(59, 1, 0), Node::new(27, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(59, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(27, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B28(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(60, 1, 0), Node::new(28, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(60, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(28, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B29(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(61, 1, 0), Node::new(29, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(61, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(29, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B30(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(62, 1, 0), Node::new(30, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(62, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(30, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B31(BitCircuit::new(
|
||||
[Node::new(0, 0, 0), Node::new(63, 1, 0), Node::new(31, 1, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(63, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Cmux(31, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
]);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,11 @@
|
||||
use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
|
||||
pub(crate) enum AnyBitCircuit {
|
||||
B0(BitCircuit<219, 64>),
|
||||
B0(BitCircuit<256>),
|
||||
}
|
||||
impl BitCircuitInfo for AnyBitCircuit {
|
||||
fn info(&self) -> (&[Node], &[usize], usize) {
|
||||
fn info(&self) -> (&[Node], usize) {
|
||||
match self {
|
||||
AnyBitCircuit::B0(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B0(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,237 +17,269 @@ impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 1usize> {
|
||||
fn output_size(&self) -> usize {
|
||||
1
|
||||
}
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], usize) {
|
||||
self.0[bit].info()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 1usize> = Circuit([AnyBitCircuit::B0(BitCircuit::new(
|
||||
[
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(32, 1, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(0, 0, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(33, 1, 2),
|
||||
Node::new(33, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(1, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(34, 1, 2),
|
||||
Node::new(34, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(2, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(35, 2, 0),
|
||||
Node::new(35, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(3, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(36, 1, 2),
|
||||
Node::new(36, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(4, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(37, 1, 2),
|
||||
Node::new(37, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(5, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(38, 2, 0),
|
||||
Node::new(38, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(6, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(39, 2, 0),
|
||||
Node::new(39, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(7, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(40, 1, 2),
|
||||
Node::new(40, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(8, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(41, 1, 2),
|
||||
Node::new(41, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(9, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(42, 2, 0),
|
||||
Node::new(42, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(10, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(43, 2, 0),
|
||||
Node::new(43, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(11, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(44, 1, 2),
|
||||
Node::new(44, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(12, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(45, 1, 2),
|
||||
Node::new(45, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(13, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(46, 2, 0),
|
||||
Node::new(46, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(14, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(47, 1, 2),
|
||||
Node::new(47, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(15, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(48, 2, 0),
|
||||
Node::new(48, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(16, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(49, 1, 2),
|
||||
Node::new(49, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(17, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(50, 2, 0),
|
||||
Node::new(50, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(18, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(51, 2, 0),
|
||||
Node::new(51, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(19, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(52, 1, 2),
|
||||
Node::new(52, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(20, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(53, 2, 0),
|
||||
Node::new(53, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(21, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(54, 1, 2),
|
||||
Node::new(54, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(22, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(55, 1, 2),
|
||||
Node::new(55, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(23, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(56, 2, 0),
|
||||
Node::new(56, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(24, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(57, 1, 2),
|
||||
Node::new(57, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(25, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(58, 2, 0),
|
||||
Node::new(58, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(26, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(59, 2, 0),
|
||||
Node::new(59, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(27, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(60, 2, 0),
|
||||
Node::new(60, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(28, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(61, 1, 2),
|
||||
Node::new(61, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(29, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(62, 1, 2),
|
||||
Node::new(62, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(30, 3, 2),
|
||||
Node::new(63, 2, 1),
|
||||
Node::new(63, 0, 2),
|
||||
Node::new(31, 0, 1),
|
||||
],
|
||||
[
|
||||
0, 3, 6, 10, 13, 17, 20, 24, 27, 31, 34, 38, 41, 45, 48, 52, 55, 59, 62, 66, 69, 73, 76, 80, 83, 87, 90, 94, 97, 101,
|
||||
104, 108, 111, 115, 118, 122, 125, 129, 132, 136, 139, 143, 146, 150, 153, 157, 160, 164, 167, 171, 174, 178, 181, 185,
|
||||
188, 192, 195, 199, 202, 206, 209, 213, 216, 218,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(32, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(0, 0, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(33, 3, 0),
|
||||
Node::Cmux(33, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(1, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(34, 1, 2),
|
||||
Node::Cmux(34, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(2, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(35, 1, 3),
|
||||
Node::Cmux(35, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(3, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(36, 1, 2),
|
||||
Node::Cmux(36, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(4, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(37, 1, 2),
|
||||
Node::Cmux(37, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(5, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(38, 1, 2),
|
||||
Node::Cmux(38, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(6, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(39, 1, 3),
|
||||
Node::Cmux(39, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(7, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(40, 3, 0),
|
||||
Node::Cmux(40, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(8, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(41, 1, 3),
|
||||
Node::Cmux(41, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(9, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(42, 1, 3),
|
||||
Node::Cmux(42, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(10, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(43, 1, 2),
|
||||
Node::Cmux(43, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(11, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(44, 2, 0),
|
||||
Node::Cmux(44, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(12, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(45, 2, 0),
|
||||
Node::Cmux(45, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(13, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(46, 1, 3),
|
||||
Node::Cmux(46, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(14, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(47, 2, 0),
|
||||
Node::Cmux(47, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(15, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(48, 2, 0),
|
||||
Node::Cmux(48, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(16, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(49, 1, 2),
|
||||
Node::Cmux(49, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(17, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(50, 1, 2),
|
||||
Node::Cmux(50, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(18, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(51, 2, 0),
|
||||
Node::Cmux(51, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(19, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(52, 1, 2),
|
||||
Node::Cmux(52, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(20, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(53, 1, 3),
|
||||
Node::Cmux(53, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(21, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(54, 1, 3),
|
||||
Node::Cmux(54, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(22, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(55, 3, 0),
|
||||
Node::Cmux(55, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(23, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(56, 2, 0),
|
||||
Node::Cmux(56, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(24, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(57, 2, 0),
|
||||
Node::Cmux(57, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(25, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(58, 1, 3),
|
||||
Node::Cmux(58, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(26, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(59, 1, 2),
|
||||
Node::Cmux(59, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(27, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(60, 3, 0),
|
||||
Node::Cmux(60, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(28, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(61, 2, 0),
|
||||
Node::Cmux(61, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(29, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(62, 1, 3),
|
||||
Node::Cmux(62, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(30, 3, 2),
|
||||
Node::Cmux(63, 3, 1),
|
||||
Node::None,
|
||||
Node::None,
|
||||
Node::Cmux(63, 0, 3),
|
||||
Node::Cmux(31, 0, 3),
|
||||
Node::None,
|
||||
Node::None,
|
||||
Node::None,
|
||||
],
|
||||
4,
|
||||
))]);
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
|
||||
pub(crate) enum AnyBitCircuit {
|
||||
B0(BitCircuit<219, 64>),
|
||||
B0(BitCircuit<256>),
|
||||
}
|
||||
impl BitCircuitInfo for AnyBitCircuit {
|
||||
fn info(&self) -> (&[Node], &[usize], usize) {
|
||||
fn info(&self) -> (&[Node], usize) {
|
||||
match self {
|
||||
AnyBitCircuit::B0(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B0(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,237 +17,269 @@ impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 1usize> {
|
||||
fn output_size(&self) -> usize {
|
||||
1
|
||||
}
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], usize) {
|
||||
self.0[bit].info()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 1usize> = Circuit([AnyBitCircuit::B0(BitCircuit::new(
|
||||
[
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(32, 1, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(0, 0, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(33, 2, 0),
|
||||
Node::new(33, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(1, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(34, 2, 0),
|
||||
Node::new(34, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(2, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(35, 1, 2),
|
||||
Node::new(35, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(3, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(36, 2, 0),
|
||||
Node::new(36, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(4, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(37, 2, 0),
|
||||
Node::new(37, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(5, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(38, 1, 2),
|
||||
Node::new(38, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(6, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(39, 2, 0),
|
||||
Node::new(39, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(7, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(40, 1, 2),
|
||||
Node::new(40, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(8, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(41, 1, 2),
|
||||
Node::new(41, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(9, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(42, 1, 2),
|
||||
Node::new(42, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(10, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(43, 2, 0),
|
||||
Node::new(43, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(11, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(44, 1, 2),
|
||||
Node::new(44, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(12, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(45, 2, 0),
|
||||
Node::new(45, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(13, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(46, 1, 2),
|
||||
Node::new(46, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(14, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(47, 2, 0),
|
||||
Node::new(47, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(15, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(48, 2, 0),
|
||||
Node::new(48, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(16, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(49, 1, 2),
|
||||
Node::new(49, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(17, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(50, 1, 2),
|
||||
Node::new(50, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(18, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(51, 1, 2),
|
||||
Node::new(51, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(19, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(52, 2, 0),
|
||||
Node::new(52, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(20, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(53, 2, 0),
|
||||
Node::new(53, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(21, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(54, 2, 0),
|
||||
Node::new(54, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(22, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(55, 1, 2),
|
||||
Node::new(55, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(23, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(56, 2, 0),
|
||||
Node::new(56, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(24, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(57, 1, 2),
|
||||
Node::new(57, 2, 0),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(25, 3, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(58, 2, 0),
|
||||
Node::new(58, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(26, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(59, 2, 0),
|
||||
Node::new(59, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(27, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(60, 2, 0),
|
||||
Node::new(60, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(28, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(61, 2, 0),
|
||||
Node::new(61, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(29, 2, 3),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(62, 2, 0),
|
||||
Node::new(62, 1, 2),
|
||||
Node::new(0, 0, 0),
|
||||
Node::new(0, 1, 1),
|
||||
Node::new(30, 2, 3),
|
||||
Node::new(63, 2, 0),
|
||||
Node::new(63, 1, 2),
|
||||
Node::new(31, 0, 1),
|
||||
],
|
||||
[
|
||||
0, 3, 6, 10, 13, 17, 20, 24, 27, 31, 34, 38, 41, 45, 48, 52, 55, 59, 62, 66, 69, 73, 76, 80, 83, 87, 90, 94, 97, 101,
|
||||
104, 108, 111, 115, 118, 122, 125, 129, 132, 136, 139, 143, 146, 150, 153, 157, 160, 164, 167, 171, 174, 178, 181, 185,
|
||||
188, 192, 195, 199, 202, 206, 209, 213, 216, 218,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(32, 1, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(0, 0, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(33, 1, 2),
|
||||
Node::Cmux(33, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(1, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(34, 1, 2),
|
||||
Node::Cmux(34, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(2, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(35, 2, 0),
|
||||
Node::Cmux(35, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(3, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(36, 3, 0),
|
||||
Node::Cmux(36, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(4, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(37, 1, 2),
|
||||
Node::Cmux(37, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(5, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(38, 2, 0),
|
||||
Node::Cmux(38, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(6, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(39, 1, 2),
|
||||
Node::Cmux(39, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(7, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(40, 1, 2),
|
||||
Node::Cmux(40, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(8, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(41, 1, 3),
|
||||
Node::Cmux(41, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(9, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(42, 2, 0),
|
||||
Node::Cmux(42, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(10, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(43, 1, 3),
|
||||
Node::Cmux(43, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(11, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(44, 3, 0),
|
||||
Node::Cmux(44, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(12, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(45, 3, 0),
|
||||
Node::Cmux(45, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(13, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(46, 2, 0),
|
||||
Node::Cmux(46, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(14, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(47, 2, 0),
|
||||
Node::Cmux(47, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(15, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(48, 1, 2),
|
||||
Node::Cmux(48, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(16, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(49, 2, 0),
|
||||
Node::Cmux(49, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(17, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(50, 1, 2),
|
||||
Node::Cmux(50, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(18, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(51, 2, 0),
|
||||
Node::Cmux(51, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(19, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(52, 1, 3),
|
||||
Node::Cmux(52, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(20, 3, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(53, 3, 0),
|
||||
Node::Cmux(53, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(21, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(54, 2, 0),
|
||||
Node::Cmux(54, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(22, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(55, 3, 0),
|
||||
Node::Cmux(55, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(23, 2, 3),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(56, 2, 0),
|
||||
Node::Cmux(56, 1, 2),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(24, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(57, 3, 0),
|
||||
Node::Cmux(57, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(25, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(58, 3, 0),
|
||||
Node::Cmux(58, 1, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::None,
|
||||
Node::Cmux(26, 2, 3),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(59, 1, 3),
|
||||
Node::Cmux(59, 3, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(27, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(60, 1, 2),
|
||||
Node::Cmux(60, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(28, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(61, 1, 2),
|
||||
Node::Cmux(61, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(29, 3, 2),
|
||||
Node::None,
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(62, 1, 2),
|
||||
Node::Cmux(62, 2, 0),
|
||||
Node::Copy,
|
||||
Node::Copy,
|
||||
Node::Cmux(30, 3, 2),
|
||||
Node::None,
|
||||
Node::Cmux(63, 2, 0),
|
||||
Node::Cmux(63, 1, 2),
|
||||
Node::None,
|
||||
Node::None,
|
||||
Node::Cmux(31, 0, 1),
|
||||
Node::None,
|
||||
Node::None,
|
||||
Node::None,
|
||||
],
|
||||
4,
|
||||
))]);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,201 +1,73 @@
|
||||
use crate::tfhe::bdd_arithmetic::{BitCircuit, BitCircuitInfo, Circuit, GetBitCircuitInfo, Node};
|
||||
pub(crate) enum AnyBitCircuit {
|
||||
B0(BitCircuit<3, 2>),
|
||||
B1(BitCircuit<3, 2>),
|
||||
B2(BitCircuit<3, 2>),
|
||||
B3(BitCircuit<3, 2>),
|
||||
B4(BitCircuit<3, 2>),
|
||||
B5(BitCircuit<3, 2>),
|
||||
B6(BitCircuit<3, 2>),
|
||||
B7(BitCircuit<3, 2>),
|
||||
B8(BitCircuit<3, 2>),
|
||||
B9(BitCircuit<3, 2>),
|
||||
B10(BitCircuit<3, 2>),
|
||||
B11(BitCircuit<3, 2>),
|
||||
B12(BitCircuit<3, 2>),
|
||||
B13(BitCircuit<3, 2>),
|
||||
B14(BitCircuit<3, 2>),
|
||||
B15(BitCircuit<3, 2>),
|
||||
B16(BitCircuit<3, 2>),
|
||||
B17(BitCircuit<3, 2>),
|
||||
B18(BitCircuit<3, 2>),
|
||||
B19(BitCircuit<3, 2>),
|
||||
B20(BitCircuit<3, 2>),
|
||||
B21(BitCircuit<3, 2>),
|
||||
B22(BitCircuit<3, 2>),
|
||||
B23(BitCircuit<3, 2>),
|
||||
B24(BitCircuit<3, 2>),
|
||||
B25(BitCircuit<3, 2>),
|
||||
B26(BitCircuit<3, 2>),
|
||||
B27(BitCircuit<3, 2>),
|
||||
B28(BitCircuit<3, 2>),
|
||||
B29(BitCircuit<3, 2>),
|
||||
B30(BitCircuit<3, 2>),
|
||||
B31(BitCircuit<3, 2>),
|
||||
B0(BitCircuit<4>),
|
||||
B1(BitCircuit<4>),
|
||||
B2(BitCircuit<4>),
|
||||
B3(BitCircuit<4>),
|
||||
B4(BitCircuit<4>),
|
||||
B5(BitCircuit<4>),
|
||||
B6(BitCircuit<4>),
|
||||
B7(BitCircuit<4>),
|
||||
B8(BitCircuit<4>),
|
||||
B9(BitCircuit<4>),
|
||||
B10(BitCircuit<4>),
|
||||
B11(BitCircuit<4>),
|
||||
B12(BitCircuit<4>),
|
||||
B13(BitCircuit<4>),
|
||||
B14(BitCircuit<4>),
|
||||
B15(BitCircuit<4>),
|
||||
B16(BitCircuit<4>),
|
||||
B17(BitCircuit<4>),
|
||||
B18(BitCircuit<4>),
|
||||
B19(BitCircuit<4>),
|
||||
B20(BitCircuit<4>),
|
||||
B21(BitCircuit<4>),
|
||||
B22(BitCircuit<4>),
|
||||
B23(BitCircuit<4>),
|
||||
B24(BitCircuit<4>),
|
||||
B25(BitCircuit<4>),
|
||||
B26(BitCircuit<4>),
|
||||
B27(BitCircuit<4>),
|
||||
B28(BitCircuit<4>),
|
||||
B29(BitCircuit<4>),
|
||||
B30(BitCircuit<4>),
|
||||
B31(BitCircuit<4>),
|
||||
}
|
||||
impl BitCircuitInfo for AnyBitCircuit {
|
||||
fn info(&self) -> (&[Node], &[usize], usize) {
|
||||
fn info(&self) -> (&[Node], usize) {
|
||||
match self {
|
||||
AnyBitCircuit::B0(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B1(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B2(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B3(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B4(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B5(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B6(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B7(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B8(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B9(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B10(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B11(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B12(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B13(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B14(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B15(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B16(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B17(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B18(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B19(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B20(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B21(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B22(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B23(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B24(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B25(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B26(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B27(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B28(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B29(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B30(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B31(bit_circuit) => (
|
||||
bit_circuit.nodes.as_ref(),
|
||||
bit_circuit.levels.as_ref(),
|
||||
bit_circuit.max_inter_state,
|
||||
),
|
||||
AnyBitCircuit::B0(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B1(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B2(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B3(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B4(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B5(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B6(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B7(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B8(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B9(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B10(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B11(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B12(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B13(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B14(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B15(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B16(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B17(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B18(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B19(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B20(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B21(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B22(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B23(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B24(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B25(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B26(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B27(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B28(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B29(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B30(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
AnyBitCircuit::B31(bit_circuit) => (bit_circuit.nodes.as_ref(), bit_circuit.max_inter_state),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,258 +79,298 @@ impl GetBitCircuitInfo<u32> for Circuit<AnyBitCircuit, 32usize> {
|
||||
fn output_size(&self) -> usize {
|
||||
u32::BITS as usize
|
||||
}
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize) {
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], usize) {
|
||||
self.0[bit].info()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) static OUTPUT_CIRCUITS: Circuit<AnyBitCircuit, 32usize> = Circuit([
|
||||
AnyBitCircuit::B0(BitCircuit::new(
|
||||
[Node::new(32, 0, 1), Node::new(32, 1, 0), Node::new(0, 0, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(32, 0, 1),
|
||||
Node::Cmux(32, 1, 0),
|
||||
Node::Cmux(0, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B1(BitCircuit::new(
|
||||
[Node::new(33, 0, 1), Node::new(33, 1, 0), Node::new(1, 0, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(33, 0, 1),
|
||||
Node::Cmux(33, 1, 0),
|
||||
Node::Cmux(1, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B2(BitCircuit::new(
|
||||
[Node::new(34, 0, 1), Node::new(34, 1, 0), Node::new(2, 0, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(34, 1, 0),
|
||||
Node::Cmux(34, 0, 1),
|
||||
Node::Cmux(2, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B3(BitCircuit::new(
|
||||
[Node::new(35, 1, 0), Node::new(35, 0, 1), Node::new(3, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(35, 0, 1),
|
||||
Node::Cmux(35, 1, 0),
|
||||
Node::Cmux(3, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B4(BitCircuit::new(
|
||||
[Node::new(36, 1, 0), Node::new(36, 0, 1), Node::new(4, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(36, 0, 1),
|
||||
Node::Cmux(36, 1, 0),
|
||||
Node::Cmux(4, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B5(BitCircuit::new(
|
||||
[Node::new(37, 0, 1), Node::new(37, 1, 0), Node::new(5, 0, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(37, 0, 1),
|
||||
Node::Cmux(37, 1, 0),
|
||||
Node::Cmux(5, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B6(BitCircuit::new(
|
||||
[Node::new(38, 0, 1), Node::new(38, 1, 0), Node::new(6, 0, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(38, 1, 0),
|
||||
Node::Cmux(38, 0, 1),
|
||||
Node::Cmux(6, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B7(BitCircuit::new(
|
||||
[Node::new(39, 0, 1), Node::new(39, 1, 0), Node::new(7, 0, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(39, 1, 0),
|
||||
Node::Cmux(39, 0, 1),
|
||||
Node::Cmux(7, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B8(BitCircuit::new(
|
||||
[Node::new(40, 0, 1), Node::new(40, 1, 0), Node::new(8, 0, 1)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(40, 0, 1),
|
||||
Node::Cmux(40, 1, 0),
|
||||
Node::Cmux(8, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B9(BitCircuit::new(
|
||||
[Node::new(41, 1, 0), Node::new(41, 0, 1), Node::new(9, 1, 0)],
|
||||
[0, 2],
|
||||
[
|
||||
Node::Cmux(41, 1, 0),
|
||||
Node::Cmux(41, 0, 1),
|
||||
Node::Cmux(9, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B10(BitCircuit::new(
|
||||
[
|
||||
Node::new(42, 0, 1),
|
||||
Node::new(42, 1, 0),
|
||||
Node::new(10, 0, 1),
|
||||
Node::Cmux(42, 0, 1),
|
||||
Node::Cmux(42, 1, 0),
|
||||
Node::Cmux(10, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B11(BitCircuit::new(
|
||||
[
|
||||
Node::new(43, 1, 0),
|
||||
Node::new(43, 0, 1),
|
||||
Node::new(11, 1, 0),
|
||||
Node::Cmux(43, 0, 1),
|
||||
Node::Cmux(43, 1, 0),
|
||||
Node::Cmux(11, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B12(BitCircuit::new(
|
||||
[
|
||||
Node::new(44, 0, 1),
|
||||
Node::new(44, 1, 0),
|
||||
Node::new(12, 0, 1),
|
||||
Node::Cmux(44, 0, 1),
|
||||
Node::Cmux(44, 1, 0),
|
||||
Node::Cmux(12, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B13(BitCircuit::new(
|
||||
[
|
||||
Node::new(45, 1, 0),
|
||||
Node::new(45, 0, 1),
|
||||
Node::new(13, 1, 0),
|
||||
Node::Cmux(45, 1, 0),
|
||||
Node::Cmux(45, 0, 1),
|
||||
Node::Cmux(13, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B14(BitCircuit::new(
|
||||
[
|
||||
Node::new(46, 0, 1),
|
||||
Node::new(46, 1, 0),
|
||||
Node::new(14, 0, 1),
|
||||
Node::Cmux(46, 1, 0),
|
||||
Node::Cmux(46, 0, 1),
|
||||
Node::Cmux(14, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B15(BitCircuit::new(
|
||||
[
|
||||
Node::new(47, 1, 0),
|
||||
Node::new(47, 0, 1),
|
||||
Node::new(15, 1, 0),
|
||||
Node::Cmux(47, 1, 0),
|
||||
Node::Cmux(47, 0, 1),
|
||||
Node::Cmux(15, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B16(BitCircuit::new(
|
||||
[
|
||||
Node::new(48, 0, 1),
|
||||
Node::new(48, 1, 0),
|
||||
Node::new(16, 0, 1),
|
||||
Node::Cmux(48, 0, 1),
|
||||
Node::Cmux(48, 1, 0),
|
||||
Node::Cmux(16, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B17(BitCircuit::new(
|
||||
[
|
||||
Node::new(49, 1, 0),
|
||||
Node::new(49, 0, 1),
|
||||
Node::new(17, 1, 0),
|
||||
Node::Cmux(49, 0, 1),
|
||||
Node::Cmux(49, 1, 0),
|
||||
Node::Cmux(17, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B18(BitCircuit::new(
|
||||
[
|
||||
Node::new(50, 1, 0),
|
||||
Node::new(50, 0, 1),
|
||||
Node::new(18, 1, 0),
|
||||
Node::Cmux(50, 0, 1),
|
||||
Node::Cmux(50, 1, 0),
|
||||
Node::Cmux(18, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B19(BitCircuit::new(
|
||||
[
|
||||
Node::new(51, 0, 1),
|
||||
Node::new(51, 1, 0),
|
||||
Node::new(19, 0, 1),
|
||||
Node::Cmux(51, 1, 0),
|
||||
Node::Cmux(51, 0, 1),
|
||||
Node::Cmux(19, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B20(BitCircuit::new(
|
||||
[
|
||||
Node::new(52, 1, 0),
|
||||
Node::new(52, 0, 1),
|
||||
Node::new(20, 1, 0),
|
||||
Node::Cmux(52, 1, 0),
|
||||
Node::Cmux(52, 0, 1),
|
||||
Node::Cmux(20, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B21(BitCircuit::new(
|
||||
[
|
||||
Node::new(53, 1, 0),
|
||||
Node::new(53, 0, 1),
|
||||
Node::new(21, 1, 0),
|
||||
Node::Cmux(53, 0, 1),
|
||||
Node::Cmux(53, 1, 0),
|
||||
Node::Cmux(21, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B22(BitCircuit::new(
|
||||
[
|
||||
Node::new(54, 1, 0),
|
||||
Node::new(54, 0, 1),
|
||||
Node::new(22, 1, 0),
|
||||
Node::Cmux(54, 1, 0),
|
||||
Node::Cmux(54, 0, 1),
|
||||
Node::Cmux(22, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B23(BitCircuit::new(
|
||||
[
|
||||
Node::new(55, 1, 0),
|
||||
Node::new(55, 0, 1),
|
||||
Node::new(23, 1, 0),
|
||||
Node::Cmux(55, 1, 0),
|
||||
Node::Cmux(55, 0, 1),
|
||||
Node::Cmux(23, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B24(BitCircuit::new(
|
||||
[
|
||||
Node::new(56, 1, 0),
|
||||
Node::new(56, 0, 1),
|
||||
Node::new(24, 1, 0),
|
||||
Node::Cmux(56, 0, 1),
|
||||
Node::Cmux(56, 1, 0),
|
||||
Node::Cmux(24, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B25(BitCircuit::new(
|
||||
[
|
||||
Node::new(57, 1, 0),
|
||||
Node::new(57, 0, 1),
|
||||
Node::new(25, 1, 0),
|
||||
Node::Cmux(57, 0, 1),
|
||||
Node::Cmux(57, 1, 0),
|
||||
Node::Cmux(25, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B26(BitCircuit::new(
|
||||
[
|
||||
Node::new(58, 1, 0),
|
||||
Node::new(58, 0, 1),
|
||||
Node::new(26, 1, 0),
|
||||
Node::Cmux(58, 1, 0),
|
||||
Node::Cmux(58, 0, 1),
|
||||
Node::Cmux(26, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B27(BitCircuit::new(
|
||||
[
|
||||
Node::new(59, 1, 0),
|
||||
Node::new(59, 0, 1),
|
||||
Node::new(27, 1, 0),
|
||||
Node::Cmux(59, 0, 1),
|
||||
Node::Cmux(59, 1, 0),
|
||||
Node::Cmux(27, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B28(BitCircuit::new(
|
||||
[
|
||||
Node::new(60, 1, 0),
|
||||
Node::new(60, 0, 1),
|
||||
Node::new(28, 1, 0),
|
||||
Node::Cmux(60, 0, 1),
|
||||
Node::Cmux(60, 1, 0),
|
||||
Node::Cmux(28, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B29(BitCircuit::new(
|
||||
[
|
||||
Node::new(61, 0, 1),
|
||||
Node::new(61, 1, 0),
|
||||
Node::new(29, 0, 1),
|
||||
Node::Cmux(61, 0, 1),
|
||||
Node::Cmux(61, 1, 0),
|
||||
Node::Cmux(29, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B30(BitCircuit::new(
|
||||
[
|
||||
Node::new(62, 1, 0),
|
||||
Node::new(62, 0, 1),
|
||||
Node::new(30, 1, 0),
|
||||
Node::Cmux(62, 0, 1),
|
||||
Node::Cmux(62, 1, 0),
|
||||
Node::Cmux(30, 0, 1),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
AnyBitCircuit::B31(BitCircuit::new(
|
||||
[
|
||||
Node::new(63, 1, 0),
|
||||
Node::new(63, 0, 1),
|
||||
Node::new(31, 1, 0),
|
||||
Node::Cmux(63, 1, 0),
|
||||
Node::Cmux(63, 0, 1),
|
||||
Node::Cmux(31, 1, 0),
|
||||
Node::None,
|
||||
],
|
||||
[0, 2],
|
||||
2,
|
||||
)),
|
||||
]);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use core::panic;
|
||||
|
||||
use itertools::Itertools;
|
||||
use poulpy_core::{
|
||||
GLWEAdd, GLWECopy, GLWEExternalProduct, GLWESub, ScratchTakeCore,
|
||||
@@ -11,18 +13,17 @@ use poulpy_hal::layouts::{Backend, DataMut, DataRef, Module, Scratch, ZnxZero};
|
||||
use crate::tfhe::bdd_arithmetic::UnsignedInteger;
|
||||
|
||||
pub trait BitCircuitInfo {
|
||||
fn info(&self) -> (&[Node], &[usize], usize);
|
||||
fn info(&self) -> (&[Node], usize);
|
||||
}
|
||||
|
||||
pub trait GetBitCircuitInfo<T: UnsignedInteger> {
|
||||
fn input_size(&self) -> usize;
|
||||
fn output_size(&self) -> usize;
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], &[usize], usize);
|
||||
fn get_circuit(&self, bit: usize) -> (&[Node], usize);
|
||||
}
|
||||
|
||||
pub(crate) struct BitCircuit<const N: usize, const K: usize> {
|
||||
pub(crate) struct BitCircuit<const N: usize> {
|
||||
pub(crate) nodes: [Node; N],
|
||||
pub(crate) levels: [usize; K],
|
||||
pub(crate) max_inter_state: usize,
|
||||
}
|
||||
|
||||
@@ -62,7 +63,9 @@ where
|
||||
}
|
||||
|
||||
for (i, out_i) in out.iter_mut().enumerate().take(circuit.output_size()) {
|
||||
let (nodes, levels, max_inter_state) = circuit.get_circuit(i);
|
||||
let (nodes, max_inter_state) = circuit.get_circuit(i);
|
||||
|
||||
assert!(nodes.len().is_multiple_of(max_inter_state));
|
||||
|
||||
let (mut level, scratch_1) = scratch.take_glwe_slice(max_inter_state * 2, out_i);
|
||||
|
||||
@@ -76,39 +79,44 @@ where
|
||||
let mut level_ref = level.iter_mut().collect_vec();
|
||||
let (mut prev_level, mut next_level) = level_ref.split_at_mut(max_inter_state);
|
||||
|
||||
for i in 0..levels.len() - 1 {
|
||||
let start: usize = levels[i];
|
||||
let end: usize = levels[i + 1];
|
||||
|
||||
let nodes_lvl: &[Node] = &nodes[start..end];
|
||||
let (all_but_last, last) = nodes.split_at(nodes.len() - max_inter_state);
|
||||
|
||||
for nodes_lvl in all_but_last.chunks_exact(max_inter_state) {
|
||||
for (j, node) in nodes_lvl.iter().enumerate() {
|
||||
if node.low_index == node.high_index {
|
||||
self.glwe_copy(next_level[j], prev_level[node.low_index]);
|
||||
} else {
|
||||
self.cmux(
|
||||
next_level[j],
|
||||
prev_level[node.high_index],
|
||||
prev_level[node.low_index],
|
||||
&inputs[node.input_index].to_ref(),
|
||||
scratch_1,
|
||||
);
|
||||
match node {
|
||||
Node::Cmux(in_idx, hi_idx, lo_idx) => {
|
||||
self.cmux(
|
||||
next_level[j],
|
||||
prev_level[*hi_idx],
|
||||
prev_level[*lo_idx],
|
||||
&inputs[*in_idx].to_ref(),
|
||||
scratch_1,
|
||||
);
|
||||
}
|
||||
Node::Copy => self.glwe_copy(next_level[j], prev_level[j]), /* Update BDD circuits to order Cmux -> Copy -> None so that mem swap can be used */
|
||||
Node::None => {}
|
||||
}
|
||||
}
|
||||
|
||||
(prev_level, next_level) = (next_level, prev_level);
|
||||
}
|
||||
|
||||
// handle last output
|
||||
// there's always only 1 node at last level
|
||||
let node: &Node = nodes.last().unwrap();
|
||||
self.cmux(
|
||||
out_i,
|
||||
prev_level[node.high_index],
|
||||
prev_level[node.low_index],
|
||||
&inputs[node.input_index].to_ref(),
|
||||
scratch_1,
|
||||
);
|
||||
// Last chunck of max_inter_state Nodes is always structured as
|
||||
// [CMUX, NONE, NONE, ..., NONE]
|
||||
match &last[0] {
|
||||
Node::Cmux(in_idx, hi_idx, lo_idx) => {
|
||||
self.cmux(
|
||||
out_i,
|
||||
prev_level[*hi_idx],
|
||||
prev_level[*lo_idx],
|
||||
&inputs[*in_idx].to_ref(),
|
||||
scratch_1,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
panic!("invalid last node, should be CMUX")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for out_i in out.iter_mut().skip(circuit.output_size()) {
|
||||
@@ -117,40 +125,25 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize, const K: usize> BitCircuit<N, K> {
|
||||
pub(crate) const fn new(nodes: [Node; N], levels: [usize; K], max_inter_state: usize) -> Self {
|
||||
impl<const N: usize> BitCircuit<N> {
|
||||
pub(crate) const fn new(nodes: [Node; N], max_inter_state: usize) -> Self {
|
||||
Self {
|
||||
nodes,
|
||||
levels,
|
||||
max_inter_state,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<const N: usize, const K: usize> BitCircuitInfo for BitCircuit<N, K> {
|
||||
fn info(&self) -> (&[Node], &[usize], usize) {
|
||||
(
|
||||
self.nodes.as_ref(),
|
||||
self.levels.as_ref(),
|
||||
self.max_inter_state,
|
||||
)
|
||||
impl<const N: usize> BitCircuitInfo for BitCircuit<N> {
|
||||
fn info(&self) -> (&[Node], usize) {
|
||||
(self.nodes.as_ref(), self.max_inter_state)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Node {
|
||||
input_index: usize,
|
||||
high_index: usize,
|
||||
low_index: usize,
|
||||
}
|
||||
|
||||
impl Node {
|
||||
pub(crate) const fn new(input_index: usize, high_index: usize, low_index: usize) -> Self {
|
||||
Self {
|
||||
input_index,
|
||||
high_index,
|
||||
low_index,
|
||||
}
|
||||
}
|
||||
pub enum Node {
|
||||
Cmux(usize, usize, usize),
|
||||
Copy,
|
||||
None,
|
||||
}
|
||||
|
||||
pub trait Cmux<BE: Backend> {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#[cfg(test)]
|
||||
use crate::tfhe::bdd_arithmetic::FheUintBlocksPreparedDebug;
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{FheUintBlocks, FheUintBlocksPrepared, UnsignedInteger},
|
||||
@@ -281,8 +280,7 @@ impl<D: DataMut, T: UnsignedInteger, BE: Backend> FheUintBlocksPrepared<D, T, BE
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) trait FheUintBlockDebugPrepare<BRA: BlindRotationAlgo, T: UnsignedInteger, BE: Backend> {
|
||||
pub trait FheUintBlockDebugPrepare<BRA: BlindRotationAlgo, T: UnsignedInteger, BE: Backend> {
|
||||
fn fhe_uint_block_debug_prepare<DM, DR0, DR1>(
|
||||
&self,
|
||||
res: &mut FheUintBlocksPreparedDebug<DM, T>,
|
||||
|
||||
@@ -3,7 +3,6 @@ mod ciphertexts;
|
||||
mod circuits;
|
||||
mod eval;
|
||||
mod key;
|
||||
mod parameters;
|
||||
|
||||
pub use bdd_2w_to_1w::*;
|
||||
pub use ciphertexts::*;
|
||||
@@ -11,11 +10,7 @@ pub(crate) use circuits::*;
|
||||
pub(crate) use eval::*;
|
||||
pub use key::*;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) use parameters::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
pub mod tests;
|
||||
|
||||
pub trait UnsignedInteger: Copy + 'static {
|
||||
const WORD_SIZE: usize;
|
||||
|
||||
64
poulpy-schemes/src/tfhe/bdd_arithmetic/tests/fft64_ref.rs
Normal file
64
poulpy-schemes/src/tfhe/bdd_arithmetic/tests/fft64_ref.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use poulpy_backend::FFT64Ref;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::tests::test_suite::{
|
||||
test_bdd_add, test_bdd_and, test_bdd_or, test_bdd_prepare, test_bdd_sll, test_bdd_slt, test_bdd_sltu, test_bdd_sra,
|
||||
test_bdd_srl, test_bdd_sub, test_bdd_xor,
|
||||
},
|
||||
blind_rotation::CGGI,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_bdd_prepare_fft64_ref() {
|
||||
test_bdd_prepare::<CGGI, FFT64Ref>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bdd_add_fft64_ref() {
|
||||
test_bdd_add::<CGGI, FFT64Ref>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bdd_and_fft64_ref() {
|
||||
test_bdd_and::<CGGI, FFT64Ref>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bdd_or_fft64_ref() {
|
||||
test_bdd_or::<CGGI, FFT64Ref>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bdd_sll_fft64_ref() {
|
||||
test_bdd_sll::<CGGI, FFT64Ref>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bdd_slt_fft64_ref() {
|
||||
test_bdd_slt::<CGGI, FFT64Ref>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bdd_sltu_fft64_ref() {
|
||||
test_bdd_sltu::<CGGI, FFT64Ref>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bdd_sra_fft64_ref() {
|
||||
test_bdd_sra::<CGGI, FFT64Ref>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bdd_srl_fft64_ref() {
|
||||
test_bdd_srl::<CGGI, FFT64Ref>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bdd_sub_fft64_ref() {
|
||||
test_bdd_sub::<CGGI, FFT64Ref>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bdd_xor_fft64_ref() {
|
||||
test_bdd_xor::<CGGI, FFT64Ref>()
|
||||
}
|
||||
4
poulpy-schemes/src/tfhe/bdd_arithmetic/tests/mod.rs
Normal file
4
poulpy-schemes/src/tfhe/bdd_arithmetic/tests/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod test_suite;
|
||||
|
||||
#[cfg(test)]
|
||||
mod fft64_ref;
|
||||
@@ -0,0 +1,93 @@
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
Add, BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory,
|
||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
pub fn test_bdd_add<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ FheUintBlocksPreparedFactory<u32, BE>
|
||||
+ FheUintBlocksPreparedEncryptSk<u32, BE>
|
||||
+ FheUintBlockDebugPrepare<BRA, u32, BE>
|
||||
+ BDDKeyEncryptSk<BRA, BE>
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
|
||||
let ggsw_infos: GGSWLayout = TEST_GGSW_INFOS;
|
||||
|
||||
let n_glwe: usize = glwe_infos.n().into();
|
||||
|
||||
let module: Module<BE> = Module::<BE>::new(n_glwe as u64);
|
||||
let mut source: Source = Source::new([6u8; 32]);
|
||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
let mut source_xe: Source = Source::new([3u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32();
|
||||
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
// d + a
|
||||
res.add(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
assert_eq!(
|
||||
res.decrypt(&module, &sk_glwe_prep, scratch.borrow()),
|
||||
a.wrapping_add(b)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
And, BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory,
|
||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
pub fn test_bdd_and<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ FheUintBlocksPreparedFactory<u32, BE>
|
||||
+ FheUintBlocksPreparedEncryptSk<u32, BE>
|
||||
+ FheUintBlockDebugPrepare<BRA, u32, BE>
|
||||
+ BDDKeyEncryptSk<BRA, BE>
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
|
||||
let ggsw_infos: GGSWLayout = TEST_GGSW_INFOS;
|
||||
|
||||
let n_glwe: usize = glwe_infos.n().into();
|
||||
|
||||
let module: Module<BE> = Module::<BE>::new(n_glwe as u64);
|
||||
let mut source: Source = Source::new([6u8; 32]);
|
||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
let mut source_xe: Source = Source::new([3u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32();
|
||||
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
res.and(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
assert_eq!(res.decrypt(&module, &sk_glwe_prep, scratch.borrow()), a & b);
|
||||
}
|
||||
@@ -1,30 +1,44 @@
|
||||
#[cfg(test)]
|
||||
mod add;
|
||||
mod and;
|
||||
mod or;
|
||||
mod prepare;
|
||||
mod sll;
|
||||
mod slt;
|
||||
mod sltu;
|
||||
mod sra;
|
||||
mod srl;
|
||||
mod sub;
|
||||
mod xor;
|
||||
|
||||
pub use add::*;
|
||||
pub use and::*;
|
||||
pub use or::*;
|
||||
pub use prepare::*;
|
||||
pub use sll::*;
|
||||
pub use slt::*;
|
||||
pub use sltu::*;
|
||||
pub use sra::*;
|
||||
pub use srl::*;
|
||||
pub use sub::*;
|
||||
pub use xor::*;
|
||||
|
||||
use poulpy_core::layouts::{
|
||||
Base2K, Degree, Dnum, Dsize, GGSWLayout, GLWEAutomorphismKeyLayout, GLWELayout, GLWETensorKeyLayout, GLWEToLWEKeyLayout,
|
||||
Rank, TorusPrecision,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::BDDKeyLayout, blind_rotation::BlindRotationKeyLayout, circuit_bootstrapping::CircuitBootstrappingKeyLayout,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_N_GLWE: u32 = 512;
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_N_LWE: u32 = 77;
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_BASE2K: u32 = 13;
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_K_GLWE: u32 = 26;
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_K_GGSW: u32 = 39;
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_BLOCK_SIZE: u32 = 7;
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_RANK: u32 = 2;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) static TEST_GLWE_INFOS: GLWELayout = GLWELayout {
|
||||
n: Degree(TEST_N_GLWE),
|
||||
base2k: Base2K(TEST_BASE2K),
|
||||
@@ -32,7 +46,6 @@ pub(crate) static TEST_GLWE_INFOS: GLWELayout = GLWELayout {
|
||||
rank: Rank(TEST_RANK),
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) static TEST_GGSW_INFOS: GGSWLayout = GGSWLayout {
|
||||
n: Degree(TEST_N_GLWE),
|
||||
base2k: Base2K(TEST_BASE2K),
|
||||
@@ -42,7 +55,6 @@ pub(crate) static TEST_GGSW_INFOS: GGSWLayout = GGSWLayout {
|
||||
dsize: Dsize(1),
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) static TEST_BDD_KEY_LAYOUT: BDDKeyLayout = BDDKeyLayout {
|
||||
cbt: CircuitBootstrappingKeyLayout {
|
||||
layout_brk: BlindRotationKeyLayout {
|
||||
@@ -0,0 +1,89 @@
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Or,
|
||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
pub fn test_bdd_or<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ FheUintBlocksPreparedFactory<u32, BE>
|
||||
+ FheUintBlocksPreparedEncryptSk<u32, BE>
|
||||
+ FheUintBlockDebugPrepare<BRA, u32, BE>
|
||||
+ BDDKeyEncryptSk<BRA, BE>
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
|
||||
let ggsw_infos: GGSWLayout = TEST_GGSW_INFOS;
|
||||
|
||||
let n_glwe: usize = glwe_infos.n().into();
|
||||
|
||||
let module: Module<BE> = Module::<BE>::new(n_glwe as u64);
|
||||
let mut source: Source = Source::new([6u8; 32]);
|
||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
let mut source_xe: Source = Source::new([3u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32();
|
||||
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
res.or(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
assert_eq!(res.decrypt(&module, &sk_glwe_prep, scratch.borrow()), a | b);
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use poulpy_backend::FFT64Ref;
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWENoise, ScratchTakeCore,
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, SIGMA, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, LWESecret, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
@@ -14,20 +11,15 @@ use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
Add, BDDKey, BDDKeyEncryptSk, BDDKeyLayout, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W,
|
||||
FheUintBlockDebugPrepare, FheUintBlocks, FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedDebug,
|
||||
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sub, TEST_BDD_KEY_LAYOUT, TEST_BLOCK_SIZE, TEST_GGSW_INFOS,
|
||||
TEST_GLWE_INFOS, TEST_N_LWE,
|
||||
BDDKey, BDDKeyEncryptSk, BDDKeyLayout, BDDKeyPrepared, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W,
|
||||
FheUintBlockDebugPrepare, FheUintBlocks, FheUintBlocksPrepare, FheUintBlocksPreparedDebug,
|
||||
FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory,
|
||||
tests::test_suite::{TEST_BASE2K, TEST_BDD_KEY_LAYOUT, TEST_BLOCK_SIZE, TEST_GGSW_INFOS, TEST_GLWE_INFOS, TEST_N_LWE},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory, CGGI},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_bdd_2w_to_1w_fft64_ref() {
|
||||
test_bdd_2w_to_1w::<FFT64Ref, CGGI>()
|
||||
}
|
||||
|
||||
fn test_bdd_2w_to_1w<BE: Backend, BRA: BlindRotationAlgo>()
|
||||
pub fn test_bdd_prepare<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
@@ -40,7 +32,8 @@ where
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>,
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
@@ -58,71 +51,26 @@ where
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
// GLWE Secret
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32();
|
||||
|
||||
println!("a: {a}");
|
||||
println!("b: {b}");
|
||||
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut c_enc: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc(&module, &glwe_infos);
|
||||
let mut c_enc_prep_debug: FheUintBlocksPreparedDebug<Vec<u8>, u32> =
|
||||
FheUintBlocksPreparedDebug::<Vec<u8>, u32>::alloc(&module, &ggsw_infos);
|
||||
let mut c_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
let start: Instant = Instant::now();
|
||||
c_enc.sub(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
let duration: std::time::Duration = start.elapsed();
|
||||
println!("add: {} ms", duration.as_millis());
|
||||
|
||||
println!(
|
||||
"have: {}",
|
||||
c_enc.decrypt(&module, &sk_glwe_prep, scratch.borrow())
|
||||
);
|
||||
println!("want: {}", a.wrapping_sub(b));
|
||||
println!(
|
||||
"noise: {:?}",
|
||||
c_enc.noise(&module, &sk_glwe_prep, a.wrapping_sub(b), scratch.borrow())
|
||||
);
|
||||
|
||||
// LWE Secret
|
||||
let n_lwe: u32 = TEST_N_LWE;
|
||||
let block_size: u32 = TEST_BLOCK_SIZE;
|
||||
|
||||
let mut sk_lwe: LWESecret<Vec<u8>> = LWESecret::alloc(n_lwe.into());
|
||||
sk_lwe.fill_binary_block(block_size as usize, &mut source_xs);
|
||||
|
||||
// CBT KEY
|
||||
let bdd_key_infos: BDDKeyLayout = TEST_BDD_KEY_LAYOUT;
|
||||
|
||||
let mut bdd_key: BDDKey<Vec<u8>, BRA> = BDDKey::alloc_from_infos(&bdd_key_infos);
|
||||
|
||||
let now: Instant = Instant::now();
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
scratch.borrow().data.fill(0);
|
||||
bdd_key.encrypt_sk(
|
||||
&module,
|
||||
&sk_lwe,
|
||||
@@ -132,37 +80,38 @@ where
|
||||
scratch.borrow(),
|
||||
);
|
||||
let mut bdd_key_prepared: BDDKeyPrepared<Vec<u8>, BRA, BE> = BDDKeyPrepared::alloc_from_infos(&module, &bdd_key_infos);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
bdd_key_prepared.prepare(&module, &bdd_key, scratch.borrow());
|
||||
println!("BDD-KGEN: {} ms", now.elapsed().as_millis());
|
||||
|
||||
let now: Instant = Instant::now();
|
||||
// GLWE(value)
|
||||
let mut c_enc: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::alloc_from_infos(&module, &glwe_infos);
|
||||
let value: u32 = source.next_u32();
|
||||
c_enc.encrypt_sk(
|
||||
&module,
|
||||
value,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
// GGSW(0)
|
||||
let mut c_enc_prep_debug: FheUintBlocksPreparedDebug<Vec<u8>, u32> =
|
||||
FheUintBlocksPreparedDebug::<Vec<u8>, u32>::alloc_from_infos(&module, &ggsw_infos);
|
||||
|
||||
// GGSW(value)
|
||||
c_enc_prep_debug.prepare(&module, &c_enc, &bdd_key_prepared, scratch.borrow());
|
||||
println!("CBT: {} ms", now.elapsed().as_millis());
|
||||
|
||||
c_enc_prep_debug.noise(&module, &sk_glwe_prep, a.wrapping_sub(b));
|
||||
let max_noise = |col_i: usize| {
|
||||
let mut noise: f64 = -(ggsw_infos.size() as f64 * TEST_BASE2K as f64) + SIGMA.log2() + 1.0;
|
||||
noise += 0.5 * ggsw_infos.log_n() as f64;
|
||||
if col_i != 0 {
|
||||
noise += 0.5 * ggsw_infos.log_n() as f64
|
||||
}
|
||||
noise
|
||||
};
|
||||
|
||||
let now: Instant = Instant::now();
|
||||
c_enc_prep.prepare(&module, &c_enc, &bdd_key_prepared, scratch.borrow());
|
||||
println!("CBT: {} ms", now.elapsed().as_millis());
|
||||
// c_enc_prep_debug.print_noise(&module, &sk_glwe_prep, value);
|
||||
|
||||
let start: Instant = Instant::now();
|
||||
c_enc.add(&module, &c_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
let duration: std::time::Duration = start.elapsed();
|
||||
println!("add: {} ms", duration.as_millis());
|
||||
|
||||
println!(
|
||||
"have: {}",
|
||||
c_enc.decrypt(&module, &sk_glwe_prep, scratch.borrow())
|
||||
);
|
||||
println!("want: {}", b.wrapping_add(a.wrapping_sub(b)));
|
||||
println!(
|
||||
"noise: {:?}",
|
||||
c_enc.noise(
|
||||
&module,
|
||||
&sk_glwe_prep,
|
||||
b.wrapping_add(a.wrapping_sub(b)),
|
||||
scratch.borrow()
|
||||
)
|
||||
);
|
||||
c_enc_prep_debug.assert_noise(&module, &sk_glwe_prep, value, &max_noise);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sll,
|
||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
pub fn test_bdd_sll<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ FheUintBlocksPreparedFactory<u32, BE>
|
||||
+ FheUintBlocksPreparedEncryptSk<u32, BE>
|
||||
+ FheUintBlockDebugPrepare<BRA, u32, BE>
|
||||
+ BDDKeyEncryptSk<BRA, BE>
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
|
||||
let ggsw_infos: GGSWLayout = TEST_GGSW_INFOS;
|
||||
|
||||
let n_glwe: usize = glwe_infos.n().into();
|
||||
|
||||
let module: Module<BE> = Module::<BE>::new(n_glwe as u64);
|
||||
let mut source: Source = Source::new([6u8; 32]);
|
||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
let mut source_xe: Source = Source::new([3u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32() & 15;
|
||||
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
res.sll(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
assert_eq!(
|
||||
res.decrypt(&module, &sk_glwe_prep, scratch.borrow()),
|
||||
a.wrapping_shl(b)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Slt,
|
||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
pub fn test_bdd_slt<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ FheUintBlocksPreparedFactory<u32, BE>
|
||||
+ FheUintBlocksPreparedEncryptSk<u32, BE>
|
||||
+ FheUintBlockDebugPrepare<BRA, u32, BE>
|
||||
+ BDDKeyEncryptSk<BRA, BE>
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
|
||||
let ggsw_infos: GGSWLayout = TEST_GGSW_INFOS;
|
||||
|
||||
let n_glwe: usize = glwe_infos.n().into();
|
||||
|
||||
let module: Module<BE> = Module::<BE>::new(n_glwe as u64);
|
||||
let mut source: Source = Source::new([6u8; 32]);
|
||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
let mut source_xe: Source = Source::new([3u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32();
|
||||
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
// d + a
|
||||
res.slt(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
assert_eq!(
|
||||
res.decrypt(&module, &sk_glwe_prep, scratch.borrow()),
|
||||
((a as i32) < (b as i32)) as u32
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sltu,
|
||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
pub fn test_bdd_sltu<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ FheUintBlocksPreparedFactory<u32, BE>
|
||||
+ FheUintBlocksPreparedEncryptSk<u32, BE>
|
||||
+ FheUintBlockDebugPrepare<BRA, u32, BE>
|
||||
+ BDDKeyEncryptSk<BRA, BE>
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
|
||||
let ggsw_infos: GGSWLayout = TEST_GGSW_INFOS;
|
||||
|
||||
let n_glwe: usize = glwe_infos.n().into();
|
||||
|
||||
let module: Module<BE> = Module::<BE>::new(n_glwe as u64);
|
||||
let mut source: Source = Source::new([6u8; 32]);
|
||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
let mut source_xe: Source = Source::new([3u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32();
|
||||
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
// d + a
|
||||
res.sltu(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
assert_eq!(
|
||||
res.decrypt(&module, &sk_glwe_prep, scratch.borrow()),
|
||||
(a < b) as u32
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sra,
|
||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
pub fn test_bdd_sra<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ FheUintBlocksPreparedFactory<u32, BE>
|
||||
+ FheUintBlocksPreparedEncryptSk<u32, BE>
|
||||
+ FheUintBlockDebugPrepare<BRA, u32, BE>
|
||||
+ BDDKeyEncryptSk<BRA, BE>
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
|
||||
let ggsw_infos: GGSWLayout = TEST_GGSW_INFOS;
|
||||
|
||||
let n_glwe: usize = glwe_infos.n().into();
|
||||
|
||||
let module: Module<BE> = Module::<BE>::new(n_glwe as u64);
|
||||
let mut source: Source = Source::new([6u8; 32]);
|
||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
let mut source_xe: Source = Source::new([3u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32() & 15;
|
||||
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
res.sra(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
assert_eq!(
|
||||
res.decrypt(&module, &sk_glwe_prep, scratch.borrow()),
|
||||
((a as i32) >> b) as u32
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Srl,
|
||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
pub fn test_bdd_srl<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ FheUintBlocksPreparedFactory<u32, BE>
|
||||
+ FheUintBlocksPreparedEncryptSk<u32, BE>
|
||||
+ FheUintBlockDebugPrepare<BRA, u32, BE>
|
||||
+ BDDKeyEncryptSk<BRA, BE>
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
|
||||
let ggsw_infos: GGSWLayout = TEST_GGSW_INFOS;
|
||||
|
||||
let n_glwe: usize = glwe_infos.n().into();
|
||||
|
||||
let module: Module<BE> = Module::<BE>::new(n_glwe as u64);
|
||||
let mut source: Source = Source::new([6u8; 32]);
|
||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
let mut source_xe: Source = Source::new([3u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32() & 15;
|
||||
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
res.srl(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
assert_eq!(
|
||||
res.decrypt(&module, &sk_glwe_prep, scratch.borrow()),
|
||||
a >> b
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Sub,
|
||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
pub fn test_bdd_sub<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ FheUintBlocksPreparedFactory<u32, BE>
|
||||
+ FheUintBlocksPreparedEncryptSk<u32, BE>
|
||||
+ FheUintBlockDebugPrepare<BRA, u32, BE>
|
||||
+ BDDKeyEncryptSk<BRA, BE>
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
|
||||
let ggsw_infos: GGSWLayout = TEST_GGSW_INFOS;
|
||||
|
||||
let n_glwe: usize = glwe_infos.n().into();
|
||||
|
||||
let module: Module<BE> = Module::<BE>::new(n_glwe as u64);
|
||||
let mut source: Source = Source::new([6u8; 32]);
|
||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
let mut source_xe: Source = Source::new([3u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32();
|
||||
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
res.sub(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
assert_eq!(
|
||||
res.decrypt(&module, &sk_glwe_prep, scratch.borrow()),
|
||||
a.wrapping_sub(b)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
use poulpy_core::{
|
||||
GGSWNoise, GLWEDecrypt, GLWEEncryptSk, GLWENoise, ScratchTakeCore,
|
||||
layouts::{GGSWLayout, GLWELayout, GLWESecret, GLWESecretPreparedFactory, LWEInfos, prepared::GLWESecretPrepared},
|
||||
};
|
||||
use poulpy_hal::{
|
||||
api::{ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow},
|
||||
layouts::{Backend, Module, Scratch, ScratchOwned},
|
||||
source::Source,
|
||||
};
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::tfhe::{
|
||||
bdd_arithmetic::{
|
||||
BDDKeyEncryptSk, BDDKeyPreparedFactory, ExecuteBDDCircuit2WTo1W, FheUintBlockDebugPrepare, FheUintBlocks,
|
||||
FheUintBlocksPrepare, FheUintBlocksPrepared, FheUintBlocksPreparedEncryptSk, FheUintBlocksPreparedFactory, Xor,
|
||||
tests::test_suite::{TEST_GGSW_INFOS, TEST_GLWE_INFOS},
|
||||
},
|
||||
blind_rotation::{BlindRotationAlgo, BlindRotationKey, BlindRotationKeyFactory},
|
||||
};
|
||||
|
||||
pub fn test_bdd_xor<BRA: BlindRotationAlgo, BE: Backend>()
|
||||
where
|
||||
Module<BE>: ModuleNew<BE>
|
||||
+ GLWESecretPreparedFactory<BE>
|
||||
+ GLWEDecrypt<BE>
|
||||
+ GLWENoise<BE>
|
||||
+ FheUintBlocksPreparedFactory<u32, BE>
|
||||
+ FheUintBlocksPreparedEncryptSk<u32, BE>
|
||||
+ FheUintBlockDebugPrepare<BRA, u32, BE>
|
||||
+ BDDKeyEncryptSk<BRA, BE>
|
||||
+ BDDKeyPreparedFactory<BRA, BE>
|
||||
+ GGSWNoise<BE>
|
||||
+ FheUintBlocksPrepare<BRA, u32, BE>
|
||||
+ ExecuteBDDCircuit2WTo1W<u32, BE>
|
||||
+ GLWEEncryptSk<BE>,
|
||||
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyFactory<BRA>,
|
||||
ScratchOwned<BE>: ScratchOwnedAlloc<BE> + ScratchOwnedBorrow<BE>,
|
||||
Scratch<BE>: ScratchTakeCore<BE>,
|
||||
{
|
||||
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
|
||||
let ggsw_infos: GGSWLayout = TEST_GGSW_INFOS;
|
||||
|
||||
let n_glwe: usize = glwe_infos.n().into();
|
||||
|
||||
let module: Module<BE> = Module::<BE>::new(n_glwe as u64);
|
||||
let mut source: Source = Source::new([6u8; 32]);
|
||||
let mut source_xs: Source = Source::new([1u8; 32]);
|
||||
let mut source_xa: Source = Source::new([2u8; 32]);
|
||||
let mut source_xe: Source = Source::new([3u8; 32]);
|
||||
|
||||
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
|
||||
|
||||
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
|
||||
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
|
||||
let mut sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = GLWESecretPrepared::alloc_from_infos(&module, &glwe_infos);
|
||||
sk_glwe_prep.prepare(&module, &sk_glwe);
|
||||
|
||||
let mut res: FheUintBlocks<Vec<u8>, u32> = FheUintBlocks::<Vec<u8>, u32>::alloc_from_infos(&module, &glwe_infos);
|
||||
let mut a_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
let mut b_enc_prep: FheUintBlocksPrepared<Vec<u8>, u32, BE> =
|
||||
FheUintBlocksPrepared::<Vec<u8>, u32, BE>::alloc(&module, &ggsw_infos);
|
||||
|
||||
let a: u32 = source.next_u32();
|
||||
let b: u32 = source.next_u32();
|
||||
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
a_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
a,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
source.fill_bytes(&mut scratch.borrow().data);
|
||||
b_enc_prep.encrypt_sk(
|
||||
&module,
|
||||
b,
|
||||
&sk_glwe_prep,
|
||||
&mut source_xa,
|
||||
&mut source_xe,
|
||||
scratch.borrow(),
|
||||
);
|
||||
|
||||
res.xor(&module, &a_enc_prep, &b_enc_prep, scratch.borrow());
|
||||
|
||||
assert_eq!(res.decrypt(&module, &sk_glwe_prep, scratch.borrow()), a ^ b);
|
||||
}
|
||||
Reference in New Issue
Block a user