mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
Fixed gadget product & added noise estimations
This commit is contained in:
@@ -1,70 +1,77 @@
|
||||
use crate::elem::{Elem, ElemVecZnx, VecZnxCommon};
|
||||
use crate::elem::{Elem, ElemCommon};
|
||||
use crate::parameters::Parameters;
|
||||
use crate::plaintext::Plaintext;
|
||||
use base2k::{Infos, Module, VecZnx, VmpPMat};
|
||||
|
||||
pub struct Ciphertext<T>(pub Elem<T>);
|
||||
|
||||
impl Parameters {
|
||||
pub fn new_ciphertext(&self, log_q: usize) -> Ciphertext<VecZnx> {
|
||||
Ciphertext::new(self.module(), self.log_base2k(), log_q, 2)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ElemCommon<T> for Ciphertext<T>
|
||||
where
|
||||
T: Infos,
|
||||
{
|
||||
fn n(&self) -> usize {
|
||||
self.elem().n()
|
||||
}
|
||||
|
||||
fn log_n(&self) -> usize {
|
||||
self.elem().log_n()
|
||||
}
|
||||
|
||||
fn log_q(&self) -> usize {
|
||||
self.elem().log_q()
|
||||
}
|
||||
|
||||
fn elem(&self) -> &Elem<T> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
fn elem_mut(&mut self) -> &mut Elem<T> {
|
||||
&mut self.0
|
||||
}
|
||||
|
||||
fn size(&self) -> usize {
|
||||
self.elem().size()
|
||||
}
|
||||
|
||||
fn rows(&self) -> usize {
|
||||
self.elem().rows()
|
||||
}
|
||||
|
||||
fn cols(&self) -> usize {
|
||||
self.elem().cols()
|
||||
}
|
||||
|
||||
fn at(&self, i: usize) -> &T {
|
||||
self.elem().at(i)
|
||||
}
|
||||
|
||||
fn at_mut(&mut self, i: usize) -> &mut T {
|
||||
self.elem_mut().at_mut(i)
|
||||
}
|
||||
|
||||
fn log_base2k(&self) -> usize {
|
||||
self.elem().log_base2k()
|
||||
}
|
||||
|
||||
fn log_scale(&self) -> usize {
|
||||
self.elem().log_scale()
|
||||
}
|
||||
}
|
||||
|
||||
impl Ciphertext<VecZnx> {
|
||||
pub fn new(module: &Module, log_base2k: usize, log_q: usize, rows: usize) -> Self {
|
||||
Self(Elem::<VecZnx>::new(module, log_base2k, log_q, rows))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Ciphertext<T>
|
||||
where
|
||||
T: VecZnxCommon<Owned = T>,
|
||||
{
|
||||
pub fn zero(&mut self) {
|
||||
self.0.zero()
|
||||
}
|
||||
|
||||
pub fn as_plaintext(&self) -> Plaintext<T> {
|
||||
unsafe { Plaintext::<T>(std::ptr::read(&self.0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Ciphertext<T>
|
||||
where
|
||||
T: Infos,
|
||||
{
|
||||
pub fn n(&self) -> usize {
|
||||
self.0.n()
|
||||
}
|
||||
|
||||
pub fn log_q(&self) -> usize {
|
||||
self.0.log_q
|
||||
}
|
||||
|
||||
pub fn rows(&self) -> usize {
|
||||
self.0.rows()
|
||||
}
|
||||
|
||||
pub fn cols(&self) -> usize {
|
||||
self.0.cols()
|
||||
}
|
||||
|
||||
pub fn at(&self, i: usize) -> &T {
|
||||
self.0.at(i)
|
||||
}
|
||||
|
||||
pub fn at_mut(&mut self, i: usize) -> &mut T {
|
||||
self.0.at_mut(i)
|
||||
}
|
||||
|
||||
pub fn log_base2k(&self) -> usize {
|
||||
self.0.log_base2k
|
||||
}
|
||||
|
||||
pub fn log_scale(&self) -> usize {
|
||||
self.0.log_scale
|
||||
}
|
||||
}
|
||||
|
||||
impl Parameters {
|
||||
pub fn new_ciphertext(&self, log_q: usize) -> Ciphertext<VecZnx> {
|
||||
Ciphertext::new(self.module(), self.log_base2k(), log_q, 2)
|
||||
}
|
||||
pub fn new_rlwe_ciphertext(module: &Module, log_base2k: usize, log_q: usize) -> Ciphertext<VecZnx> {
|
||||
let rows: usize = 2;
|
||||
Ciphertext::<VecZnx>::new(module, log_base2k, log_q, rows)
|
||||
}
|
||||
|
||||
pub fn new_gadget_ciphertext(
|
||||
@@ -74,7 +81,7 @@ pub fn new_gadget_ciphertext(
|
||||
log_q: usize,
|
||||
) -> Ciphertext<VmpPMat> {
|
||||
let cols: usize = (log_q + log_base2k - 1) / log_base2k;
|
||||
let mut elem: Elem<VmpPMat> = Elem::<VmpPMat>::new(module, log_base2k, 1, rows, 2 * cols);
|
||||
let mut elem: Elem<VmpPMat> = Elem::<VmpPMat>::new(module, log_base2k, 2, rows, cols);
|
||||
elem.log_q = log_q;
|
||||
Ciphertext(elem)
|
||||
}
|
||||
@@ -86,7 +93,7 @@ pub fn new_rgsw_ciphertext(
|
||||
log_q: usize,
|
||||
) -> Ciphertext<VmpPMat> {
|
||||
let cols: usize = (log_q + log_base2k - 1) / log_base2k;
|
||||
let mut elem: Elem<VmpPMat> = Elem::<VmpPMat>::new(module, log_base2k, 2, rows, 2 * cols);
|
||||
let mut elem: Elem<VmpPMat> = Elem::<VmpPMat>::new(module, log_base2k, 4, rows, cols);
|
||||
elem.log_q = log_q;
|
||||
Ciphertext(elem)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user