This commit is contained in:
Pro7ech
2025-10-14 18:46:25 +02:00
parent 0533cdff8a
commit 72dca47cbe
153 changed files with 3099 additions and 1956 deletions

View File

@@ -1,6 +1,6 @@
use std::marker::PhantomData;
use poulpy_core::layouts::{Base2K, GLWECiphertext, GLWEInfos, GLWEPlaintextLayout, LWEInfos, Rank, TorusPrecision};
use poulpy_core::layouts::{Base2K, GLWE, GLWEInfos, GLWEPlaintextLayout, LWEInfos, Rank, TorusPrecision};
use poulpy_core::{TakeGLWEPt, layouts::prepared::GLWESecretPrepared};
use poulpy_hal::api::VecZnxBigAllocBytes;
@@ -24,7 +24,7 @@ use crate::tfhe::bdd_arithmetic::{FromBits, ToBits, UnsignedInteger};
/// An FHE ciphertext encrypting the bits of an [UnsignedInteger].
pub struct FheUintBlocks<D: Data, T: UnsignedInteger> {
pub(crate) blocks: Vec<GLWECiphertext<D>>,
pub(crate) blocks: Vec<GLWE<D>>,
pub(crate) _base: u8,
pub(crate) _phantom: PhantomData<T>,
}
@@ -62,7 +62,7 @@ impl<T: UnsignedInteger> FheUintBlocks<Vec<u8>, T> {
pub(crate) fn alloc_with<BE: Backend>(module: &Module<BE>, base2k: Base2K, k: TorusPrecision, rank: Rank) -> Self {
Self {
blocks: (0..T::WORD_SIZE)
.map(|_| GLWECiphertext::alloc_with(module.n().into(), base2k, k, rank))
.map(|_| GLWE::alloc(module.n().into(), base2k, k, rank))
.collect(),
_base: 1,
_phantom: PhantomData,

View File

@@ -60,7 +60,7 @@ impl<T: UnsignedInteger> FheUintBlocksPrepDebug<Vec<u8>, T> {
) -> Self {
Self {
blocks: (0..T::WORD_SIZE)
.map(|_| GGSW::alloc_with(module.n().into(), base2k, k, rank, dnum, dsize))
.map(|_| GGSW::alloc(module.n().into(), base2k, k, rank, dnum, dsize))
.collect(),
_base: 1,
_phantom: PhantomData,

View File

@@ -2,7 +2,7 @@ use itertools::Itertools;
use poulpy_core::{
GLWEOperations, TakeGLWECtSlice, TakeGLWEPt, glwe_packing,
layouts::{
GLWECiphertext, GLWEInfos, GLWEPlaintextLayout, LWEInfos, TorusPrecision,
GLWE, GLWEInfos, GLWEPlaintextLayout, LWEInfos, TorusPrecision,
prepared::{AutomorphismKeyPrepared, GLWESecretPrepared},
},
};
@@ -24,14 +24,14 @@ use std::{collections::HashMap, marker::PhantomData};
use crate::tfhe::bdd_arithmetic::{FromBits, ToBits, UnsignedInteger};
/// A FHE ciphertext encrypting a [UnsignedInteger].
pub struct FheUintWord<D: Data, T: UnsignedInteger>(pub(crate) GLWECiphertext<D>, pub(crate) PhantomData<T>);
pub struct FheUintWord<D: Data, T: UnsignedInteger>(pub(crate) GLWE<D>, pub(crate) PhantomData<T>);
impl<D: DataMut, T: UnsignedInteger> FheUintWord<D, T> {
#[allow(dead_code)]
fn post_process<ATK, BE: Backend>(
&mut self,
module: &Module<BE>,
mut tmp_res: Vec<GLWECiphertext<&mut [u8]>>,
mut tmp_res: Vec<GLWE<&mut [u8]>>,
auto_keys: &HashMap<i64, AutomorphismKeyPrepared<ATK, BE>>,
scratch: &mut Scratch<BE>,
) where
@@ -67,7 +67,7 @@ impl<D: DataMut, T: UnsignedInteger> FheUintWord<D, T> {
// Repacks the GLWE ciphertexts bits
let gap: usize = module.n() / T::WORD_SIZE;
let log_gap: usize = (usize::BITS - (gap - 1).leading_zeros()) as usize;
let mut cts: HashMap<usize, &mut GLWECiphertext<&mut [u8]>> = HashMap::new();
let mut cts: HashMap<usize, &mut GLWE<&mut [u8]>> = HashMap::new();
for (i, ct) in tmp_res.iter_mut().enumerate().take(T::WORD_SIZE) {
cts.insert(i * gap, ct);
}

View File

@@ -2,7 +2,7 @@ use itertools::Itertools;
use poulpy_core::{
GLWEExternalProductInplace, GLWEOperations, TakeGLWECtSlice,
layouts::{
GLWECiphertext, GLWECiphertextToMut, LWEInfos,
GLWE, GLWEToMut, LWEInfos,
prepared::{GGSWCiphertextPreparedToRef, GGSWPrepared},
},
};
@@ -38,7 +38,7 @@ where
fn execute<O>(
&self,
module: &Module<BE>,
out: &mut [GLWECiphertext<O>],
out: &mut [GLWE<O>],
inputs: &[&dyn GGSWCiphertextPreparedToRef<BE>],
scratch: &mut Scratch<BE>,
) where
@@ -54,7 +54,7 @@ where
fn execute<O>(
&self,
module: &Module<BE>,
out: &mut [GLWECiphertext<O>],
out: &mut [GLWE<O>],
inputs: &[&dyn GGSWCiphertextPreparedToRef<BE>],
scratch: &mut Scratch<BE>,
) where
@@ -159,14 +159,8 @@ impl Node {
}
pub trait Cmux<BE: Backend> {
fn cmux<O, T, F, S>(
&self,
out: &mut GLWECiphertext<O>,
t: &GLWECiphertext<T>,
f: &GLWECiphertext<F>,
s: &GGSWPrepared<S, BE>,
scratch: &mut Scratch<BE>,
) where
fn cmux<O, T, F, S>(&self, out: &mut GLWE<O>, t: &GLWE<T>, f: &GLWE<F>, s: &GGSWPrepared<S, BE>, scratch: &mut Scratch<BE>)
where
O: DataMut,
T: DataRef,
F: DataRef,
@@ -177,14 +171,8 @@ impl<BE: Backend> Cmux<BE> for Module<BE>
where
Module<BE>: GLWEExternalProductInplace<BE> + VecZnxSub + VecZnxCopy + VecZnxNegateInplace + VecZnxAddInplace,
{
fn cmux<O, T, F, S>(
&self,
out: &mut GLWECiphertext<O>,
t: &GLWECiphertext<T>,
f: &GLWECiphertext<F>,
s: &GGSWPrepared<S, BE>,
scratch: &mut Scratch<BE>,
) where
fn cmux<O, T, F, S>(&self, out: &mut GLWE<O>, t: &GLWE<T>, f: &GLWE<F>, s: &GGSWPrepared<S, BE>, scratch: &mut Scratch<BE>)
where
O: DataMut,
T: DataRef,
F: DataRef,

View File

@@ -11,7 +11,7 @@ use crate::tfhe::{
use poulpy_core::{
TakeGGSW, TakeGLWECt,
layouts::{
GLWESecret, GLWEToLWEKeyLayout, GLWEToLWESwitchingKey, LWECiphertext, LWESecret,
GLWESecret, GLWEToLWEKeyLayout, GLWEToLWESwitchingKey, LWE, LWESecret,
prepared::{GLWEToLWESwitchingKeyPrepared, Prepare, PrepareAlloc},
},
};
@@ -182,7 +182,7 @@ where
{
assert_eq!(out.blocks.len(), bits.blocks.len());
}
let mut lwe: LWECiphertext<Vec<u8>> = LWECiphertext::alloc(&bits.blocks[0]); //TODO: add TakeLWE
let mut lwe: LWE<Vec<u8>> = LWE::alloc(&bits.blocks[0]); //TODO: add TakeLWE
let (mut tmp_ggsw, scratch_1) = scratch.take_ggsw(out);
for (dst, src) in out.blocks.iter_mut().zip(bits.blocks.iter()) {
lwe.from_glwe(module, src, &self.ks, scratch_1);
@@ -231,7 +231,7 @@ where
{
assert_eq!(out.blocks.len(), bits.blocks.len());
}
let mut lwe: LWECiphertext<Vec<u8>> = LWECiphertext::alloc(&bits.blocks[0]); //TODO: add TakeLWE
let mut lwe: LWE<Vec<u8>> = LWE::alloc(&bits.blocks[0]); //TODO: add TakeLWE
for (dst, src) in out.blocks.iter_mut().zip(bits.blocks.iter()) {
lwe.from_glwe(module, src, &self.ks, scratch);
self.cbt

View File

@@ -1,6 +1,6 @@
#[cfg(test)]
use poulpy_core::layouts::{
AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GGSWCiphertextLayout, GLWECiphertextLayout, GLWEToLWEKeyLayout, Rank,
AutomorphismKeyLayout, Base2K, Degree, Dnum, Dsize, GGSWCiphertextLayout, GLWELayout, GLWEToLWEKeyLayout, Rank,
TensorKeyLayout, TorusPrecision,
};
@@ -25,7 +25,7 @@ pub(crate) const TEST_BLOCK_SIZE: u32 = 7;
pub(crate) const TEST_RANK: u32 = 2;
#[cfg(test)]
pub(crate) static TEST_GLWE_INFOS: GLWECiphertextLayout = GLWECiphertextLayout {
pub(crate) static TEST_GLWE_INFOS: GLWELayout = GLWELayout {
n: Degree(TEST_N_GLWE),
base2k: Base2K(TEST_BASE2K),
k: TorusPrecision(TEST_K_GLWE),

View File

@@ -4,7 +4,7 @@ use poulpy_backend::FFT64Ref;
use poulpy_core::{
TakeGGSW, TakeGLWEPt,
layouts::{
GGSWCiphertextLayout, GLWECiphertextLayout, GLWESecret, LWEInfos, LWESecret,
GGSWCiphertextLayout, GLWELayout, GLWESecret, LWEInfos, LWESecret,
prepared::{GLWESecretPrepared, PrepareAlloc},
},
};
@@ -107,7 +107,7 @@ where
BlindRotationKeyPrepared<Vec<u8>, BRA, BE>: BlincRotationExecute<BE>,
BlindRotationKey<Vec<u8>, BRA>: BlindRotationKeyAlloc + BlindRotationKeyEncryptSk<BE>,
{
let glwe_infos: GLWECiphertextLayout = TEST_GLWE_INFOS;
let glwe_infos: GLWELayout = TEST_GLWE_INFOS;
let ggsw_infos: GGSWCiphertextLayout = TEST_GGSW_INFOS;
let n_glwe: usize = glwe_infos.n().into();
@@ -120,7 +120,7 @@ where
let mut scratch: ScratchOwned<BE> = ScratchOwned::alloc(1 << 22);
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc(&glwe_infos);
let mut sk_glwe: GLWESecret<Vec<u8>> = GLWESecret::alloc_from_infos(&glwe_infos);
sk_glwe.fill_ternary_prob(0.5, &mut source_xs);
let sk_glwe_prep: GLWESecretPrepared<Vec<u8>, BE> = sk_glwe.prepare_alloc(&module, scratch.borrow());