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

@@ -9,13 +9,10 @@ use poulpy_hal::{
use crate::{
TakeGLWECt,
layouts::{
GGLWEInfos, GLWECiphertext, GLWECiphertextLayout, GLWEInfos, LWECiphertext, LWEInfos, Rank,
prepared::GLWEToLWESwitchingKeyPrepared,
},
layouts::{GGLWEInfos, GLWE, GLWEInfos, GLWELayout, LWE, LWEInfos, Rank, prepared::GLWEToLWESwitchingKeyPrepared},
};
impl LWECiphertext<Vec<u8>> {
impl LWE<Vec<u8>> {
pub fn from_glwe_scratch_space<B: Backend, OUT, IN, KEY>(
module: &Module<B>,
lwe_infos: &OUT,
@@ -28,24 +25,24 @@ impl LWECiphertext<Vec<u8>> {
KEY: GGLWEInfos,
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VecZnxNormalizeTmpBytes,
{
let glwe_layout: GLWECiphertextLayout = GLWECiphertextLayout {
let glwe_layout: GLWELayout = GLWELayout {
n: module.n().into(),
base2k: lwe_infos.base2k(),
k: lwe_infos.k(),
rank: Rank(1),
};
GLWECiphertext::alloc_bytes_with(
GLWE::bytes_of(
module.n().into(),
lwe_infos.base2k(),
lwe_infos.k(),
1u32.into(),
) + GLWECiphertext::keyswitch_scratch_space(module, &glwe_layout, glwe_infos, key_infos)
) + GLWE::keyswitch_scratch_space(module, &glwe_layout, glwe_infos, key_infos)
}
}
impl<DLwe: DataMut> LWECiphertext<DLwe> {
pub fn sample_extract<DGlwe: DataRef>(&mut self, a: &GLWECiphertext<DGlwe>) {
impl<DLwe: DataMut> LWE<DLwe> {
pub fn sample_extract<DGlwe: DataRef>(&mut self, a: &GLWE<DGlwe>) {
#[cfg(debug_assertions)]
{
assert!(self.n() <= a.n());
@@ -66,7 +63,7 @@ impl<DLwe: DataMut> LWECiphertext<DLwe> {
pub fn from_glwe<DGlwe, DKs, B: Backend>(
&mut self,
module: &Module<B>,
a: &GLWECiphertext<DGlwe>,
a: &GLWE<DGlwe>,
ks: &GLWEToLWESwitchingKeyPrepared<DKs, B>,
scratch: &mut Scratch<B>,
) where
@@ -92,7 +89,7 @@ impl<DLwe: DataMut> LWECiphertext<DLwe> {
assert!(self.n() <= module.n() as u32);
}
let glwe_layout: GLWECiphertextLayout = GLWECiphertextLayout {
let glwe_layout: GLWELayout = GLWELayout {
n: module.n().into(),
base2k: self.base2k(),
k: self.k(),

View File

@@ -9,13 +9,10 @@ use poulpy_hal::{
use crate::{
TakeGLWECt,
layouts::{
GGLWEInfos, GLWECiphertext, GLWECiphertextLayout, GLWEInfos, LWECiphertext, LWEInfos,
prepared::LWEToGLWESwitchingKeyPrepared,
},
layouts::{GGLWEInfos, GLWE, GLWEInfos, GLWELayout, LWE, LWEInfos, prepared::LWEToGLWESwitchingKeyPrepared},
};
impl GLWECiphertext<Vec<u8>> {
impl GLWE<Vec<u8>> {
pub fn from_lwe_scratch_space<B: Backend, OUT, IN, KEY>(
module: &Module<B>,
glwe_infos: &OUT,
@@ -28,27 +25,27 @@ impl GLWECiphertext<Vec<u8>> {
KEY: GGLWEInfos,
Module<B>: VecZnxDftAllocBytes + VmpApplyDftToDftTmpBytes + VecZnxBigNormalizeTmpBytes + VecZnxNormalizeTmpBytes,
{
let ct: usize = GLWECiphertext::alloc_bytes_with(
let ct: usize = GLWE::bytes_of(
module.n().into(),
key_infos.base2k(),
lwe_infos.k().max(glwe_infos.k()),
1u32.into(),
);
let ks: usize = GLWECiphertext::keyswitch_inplace_scratch_space(module, glwe_infos, key_infos);
let ks: usize = GLWE::keyswitch_inplace_scratch_space(module, glwe_infos, key_infos);
if lwe_infos.base2k() == key_infos.base2k() {
ct + ks
} else {
let a_conv = VecZnx::alloc_bytes(module.n(), 1, lwe_infos.size()) + module.vec_znx_normalize_tmp_bytes();
let a_conv = VecZnx::bytes_of(module.n(), 1, lwe_infos.size()) + module.vec_znx_normalize_tmp_bytes();
ct + a_conv + ks
}
}
}
impl<D: DataMut> GLWECiphertext<D> {
impl<D: DataMut> GLWE<D> {
pub fn from_lwe<DLwe, DKsk, B: Backend>(
&mut self,
module: &Module<B>,
lwe: &LWECiphertext<DLwe>,
lwe: &LWE<DLwe>,
ksk: &LWEToGLWESwitchingKeyPrepared<DKsk, B>,
scratch: &mut Scratch<B>,
) where
@@ -74,7 +71,7 @@ impl<D: DataMut> GLWECiphertext<D> {
assert!(lwe.n() <= module.n() as u32);
}
let (mut glwe, scratch_1) = scratch.take_glwe_ct(&GLWECiphertextLayout {
let (mut glwe, scratch_1) = scratch.take_glwe_ct(&GLWELayout {
n: ksk.n(),
base2k: ksk.base2k(),
k: lwe.k(),