Add bdd rotation

This commit is contained in:
Jean-Philippe Bossuat
2025-10-24 18:13:43 +02:00
parent 96d8f4cfc4
commit d989867c91
13 changed files with 177 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "poulpy-core"
version = "0.2.0"
version = "0.3.1"
edition = "2024"
license = "Apache-2.0"
description = "A backend agnostic crate implementing RLWE-based encryption & arithmetic."

View File

@@ -0,0 +1,55 @@
use poulpy_hal::layouts::{Backend, Module, Scratch};
use crate::{
GLWERotate, ScratchTakeCore,
layouts::{GGSW, GGSWInfos, GGSWToMut, GGSWToRef, GLWEInfos},
};
impl<BE: Backend> GGSWRotate<BE> for Module<BE> where Module<BE>: GLWERotate<BE> {}
pub trait GGSWRotate<BE: Backend>
where
Self: GLWERotate<BE>,
{
fn ggsw_rotate_tmp_bytes(&self) -> usize {
self.glwe_rotate_tmp_bytes()
}
fn ggsw_rotate<R, A>(&self, k: i64, res: &mut R, a: &A)
where
R: GGSWToMut,
A: GGSWToRef,
{
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
let a: &GGSW<&[u8]> = &a.to_ref();
assert!(res.dnum() <= a.dnum());
assert_eq!(res.dsize(), a.dsize());
assert_eq!(res.rank(), a.rank());
let rows: usize = res.dnum().into();
let cols: usize = (res.rank() + 1).into();
for row in 0..rows {
for col in 0..cols {
self.glwe_rotate(k, &mut res.at_mut(row, col), &a.at(row, col));
}
}
}
fn ggsw_rotate_inplace<R>(&self, k: i64, res: &mut R, scratch: &mut Scratch<BE>)
where
R: GGSWToMut,
Scratch<BE>: ScratchTakeCore<BE>,
{
let res: &mut GGSW<&mut [u8]> = &mut res.to_mut();
let rows: usize = res.dnum().into();
let cols: usize = (res.rank() + 1).into();
for row in 0..rows {
for col in 0..cols {
self.glwe_rotate_inplace(k, &mut res.at_mut(row, col), scratch);
}
}
}
}

View File

@@ -5,6 +5,7 @@ use poulpy_hal::{
VecZnxSubInplace, VecZnxSubNegateInplace,
},
layouts::{Backend, Module, Scratch, VecZnx, ZnxZero},
reference::vec_znx::vec_znx_rotate_inplace_tmp_bytes,
};
use crate::{
@@ -185,6 +186,10 @@ pub trait GLWERotate<BE: Backend>
where
Self: ModuleN + VecZnxRotate + VecZnxRotateInplace<BE>,
{
fn glwe_rotate_tmp_bytes(&self) -> usize {
vec_znx_rotate_inplace_tmp_bytes(self.n())
}
fn glwe_rotate<R, A>(&self, k: i64, res: &mut R, a: &A)
where
R: GLWEToMut,

View File

@@ -1,3 +1,5 @@
mod ggsw;
mod glwe;
pub use ggsw::*;
pub use glwe::*;