mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 21:26:41 +01:00
wip
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user