mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
wip rlwe + some bug fixes in base2k
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
use crate::elem::Elem;
|
||||
use crate::parameters::Parameters;
|
||||
use crate::plaintext::Plaintext;
|
||||
use base2k::VecZnx;
|
||||
use base2k::{Module, VecZnx, VmpPMat, VmpPMatOps};
|
||||
|
||||
pub struct Ciphertext(pub Elem);
|
||||
|
||||
/*
|
||||
impl Parameters {
|
||||
pub fn new_ciphertext(&self, degree: usize, log_base2k: usize, log_q: usize) -> Ciphertext {
|
||||
Ciphertext(self.new_elem(degree, log_base2k, log_q))
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
impl Ciphertext {
|
||||
pub fn new(n: usize, log_base2k: usize, log_q: usize, degree: usize) -> Self {
|
||||
Self(Elem::new(n, log_base2k, log_q, degree))
|
||||
pub fn new(
|
||||
module: &Module,
|
||||
log_base2k: usize,
|
||||
log_q: usize,
|
||||
degree: usize,
|
||||
log_scale: usize,
|
||||
) -> Self {
|
||||
Self(Elem::new(module, log_base2k, log_q, degree, log_scale))
|
||||
}
|
||||
|
||||
pub fn n(&self) -> usize {
|
||||
@@ -45,7 +44,75 @@ impl Ciphertext {
|
||||
self.0.log_base2k()
|
||||
}
|
||||
|
||||
pub fn log_scale(&self) -> usize {
|
||||
self.0.log_scale
|
||||
}
|
||||
|
||||
pub fn as_plaintext(&self) -> Plaintext {
|
||||
unsafe { Plaintext(std::ptr::read(&self.0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Parameters {
|
||||
pub fn new_ciphertext(&self, log_q: usize) -> Ciphertext {
|
||||
Ciphertext::new(self.module(), self.log_base2k(), log_q, self.log_scale(), 1)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GadgetCiphertext {
|
||||
pub value: Vec<VmpPMat>,
|
||||
pub log_base2k: usize,
|
||||
pub log_q: usize,
|
||||
pub log_scale: usize,
|
||||
}
|
||||
|
||||
impl GadgetCiphertext {
|
||||
pub fn new(
|
||||
module: &Module,
|
||||
log_base2k: usize,
|
||||
rows: usize,
|
||||
log_q: usize,
|
||||
log_scale: usize,
|
||||
) -> Self {
|
||||
let cols: usize = (log_q + log_base2k - 1) / log_base2k;
|
||||
let mut value: Vec<VmpPMat> = Vec::new();
|
||||
(0..rows).for_each(|_| value.push(module.new_vmp_pmat(rows, cols)));
|
||||
Self {
|
||||
value,
|
||||
log_base2k,
|
||||
log_q,
|
||||
log_scale,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn n(&self) -> usize {
|
||||
self.value[0].n
|
||||
}
|
||||
|
||||
pub fn rows(&self) -> usize {
|
||||
self.value[0].rows
|
||||
}
|
||||
|
||||
pub fn cols(&self) -> usize {
|
||||
self.value[0].cols
|
||||
}
|
||||
|
||||
pub fn degree(&self) -> usize {
|
||||
self.value.len() - 1
|
||||
}
|
||||
|
||||
pub fn log_q(&self) -> usize {
|
||||
self.log_q
|
||||
}
|
||||
|
||||
pub fn log_base2k(&self) -> usize {
|
||||
self.log_base2k
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RGSWCiphertext {
|
||||
pub value: [GadgetCiphertext; 2],
|
||||
pub log_base2k: usize,
|
||||
pub log_q: usize,
|
||||
pub log_p: usize,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user