mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
more refactoring
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use base2k::{BACKEND, Module, Sampling, SvpPPolOps, VecZnx, VecZnxDft, VecZnxDftOps, VecZnxOps, VmpPMat, alloc_aligned_u8};
|
||||
use base2k::{BACKEND, Module, Sampling, ScalarZnxDftOps, VecZnx, VecZnxDft, VecZnxDftOps, VecZnxOps, MatZnxDft, alloc_aligned_u8};
|
||||
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||
use rlwe::{
|
||||
ciphertext::{Ciphertext, new_gadget_ciphertext},
|
||||
@@ -16,7 +16,7 @@ fn bench_gadget_product_inplace(c: &mut Criterion) {
|
||||
res_dft_0: &'a mut VecZnxDft,
|
||||
res_dft_1: &'a mut VecZnxDft,
|
||||
a: &'a VecZnx,
|
||||
b: &'a Ciphertext<VmpPMat>,
|
||||
b: &'a Ciphertext<MatZnxDft>,
|
||||
b_cols: usize,
|
||||
tmp_bytes: &'a mut [u8],
|
||||
) -> Box<dyn FnMut() + 'a> {
|
||||
@@ -69,13 +69,13 @@ fn bench_gadget_product_inplace(c: &mut Criterion) {
|
||||
let mut source_xe: Source = Source::new([4; 32]);
|
||||
let mut source_xa: Source = Source::new([5; 32]);
|
||||
|
||||
let mut sk0_svp_ppol: base2k::SvpPPol = params.module().new_svp_ppol();
|
||||
let mut sk0_svp_ppol: base2k::ScalarZnxDft = params.module().new_svp_ppol();
|
||||
params.module().svp_prepare(&mut sk0_svp_ppol, &sk0.0);
|
||||
|
||||
let mut sk1_svp_ppol: base2k::SvpPPol = params.module().new_svp_ppol();
|
||||
let mut sk1_svp_ppol: base2k::ScalarZnxDft = params.module().new_svp_ppol();
|
||||
params.module().svp_prepare(&mut sk1_svp_ppol, &sk1.0);
|
||||
|
||||
let mut gadget_ct: Ciphertext<VmpPMat> = new_gadget_ciphertext(
|
||||
let mut gadget_ct: Ciphertext<MatZnxDft> = new_gadget_ciphertext(
|
||||
params.module(),
|
||||
params.log_base2k(),
|
||||
params.cols_q(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use base2k::{Encoding, SvpPPolOps, VecZnx, alloc_aligned};
|
||||
use base2k::{Encoding, ScalarZnxDftOps, VecZnx, alloc_aligned};
|
||||
use rlwe::{
|
||||
ciphertext::Ciphertext,
|
||||
elem::ElemCommon,
|
||||
@@ -51,7 +51,7 @@ fn main() {
|
||||
let mut source_xe: Source = Source::new([1; 32]);
|
||||
let mut source_xa: Source = Source::new([2; 32]);
|
||||
|
||||
let mut sk_svp_ppol: base2k::SvpPPol = params.module().new_svp_ppol();
|
||||
let mut sk_svp_ppol: base2k::ScalarZnxDft = params.module().new_svp_ppol();
|
||||
params.module().svp_prepare(&mut sk_svp_ppol, &sk.0);
|
||||
|
||||
params.encrypt_rlwe_sk(
|
||||
|
||||
@@ -7,15 +7,15 @@ use crate::{
|
||||
parameters::Parameters,
|
||||
};
|
||||
use base2k::{
|
||||
Module, Scalar, ScalarOps, SvpPPol, SvpPPolOps, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, VecZnxOps, VmpPMat,
|
||||
VmpPMatOps, assert_alignement,
|
||||
Module, Scalar, ScalarOps, ScalarZnxDft, ScalarZnxDftOps, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, VecZnxOps, MatZnxDft,
|
||||
MatZnxDftOps, assert_alignement,
|
||||
};
|
||||
use sampling::source::Source;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Stores DFT([-A*AUTO(s, -p) + 2^{-K*i}*s + E, A]) where AUTO(X, p): X^{i} -> X^{i*p}
|
||||
pub struct AutomorphismKey {
|
||||
pub value: Ciphertext<VmpPMat>,
|
||||
pub value: Ciphertext<MatZnxDft>,
|
||||
pub p: i64,
|
||||
}
|
||||
|
||||
@@ -106,12 +106,12 @@ impl AutomorphismKey {
|
||||
let (sk_out_bytes, tmp_bytes) = tmp_bytes.split_at_mut(module.bytes_of_svp_ppol());
|
||||
|
||||
let sk_auto: Scalar = module.new_scalar_from_bytes_borrow(sk_auto_bytes);
|
||||
let mut sk_out: SvpPPol = module.new_svp_ppol_from_bytes_borrow(sk_out_bytes);
|
||||
let mut sk_out: ScalarZnxDft = module.new_svp_ppol_from_bytes_borrow(sk_out_bytes);
|
||||
|
||||
let mut keys: Vec<AutomorphismKey> = Vec::new();
|
||||
|
||||
p.iter().for_each(|pi| {
|
||||
let mut value: Ciphertext<VmpPMat> = new_gadget_ciphertext(module, log_base2k, rows, log_q);
|
||||
let mut value: Ciphertext<MatZnxDft> = new_gadget_ciphertext(module, log_base2k, rows, log_q);
|
||||
|
||||
let p_inv: i64 = module.galois_element_inv(*pi);
|
||||
|
||||
@@ -223,7 +223,7 @@ mod test {
|
||||
parameters::{Parameters, ParametersLiteral},
|
||||
plaintext::Plaintext,
|
||||
};
|
||||
use base2k::{BACKEND, Encoding, Module, SvpPPol, SvpPPolOps, VecZnx, VecZnxOps, alloc_aligned};
|
||||
use base2k::{BACKEND, Encoding, Module, ScalarZnxDft, ScalarZnxDftOps, VecZnx, VecZnxOps, alloc_aligned};
|
||||
use sampling::source::{Source, new_seed};
|
||||
|
||||
#[test]
|
||||
@@ -267,7 +267,7 @@ mod test {
|
||||
|
||||
let mut sk: SecretKey = SecretKey::new(module);
|
||||
sk.fill_ternary_hw(params.xs(), &mut source_xs);
|
||||
let mut sk_svp_ppol: SvpPPol = module.new_svp_ppol();
|
||||
let mut sk_svp_ppol: ScalarZnxDft = module.new_svp_ppol();
|
||||
module.svp_prepare(&mut sk_svp_ppol, &sk.0);
|
||||
|
||||
let p: i64 = -5;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::elem::{Elem, ElemCommon};
|
||||
use crate::parameters::Parameters;
|
||||
use base2k::{Infos, Layout, Module, VecZnx, VmpPMat};
|
||||
use base2k::{ZnxInfos, Layout, Module, VecZnx, MatZnxDft};
|
||||
|
||||
pub struct Ciphertext<T>(pub Elem<T>);
|
||||
|
||||
@@ -12,7 +12,7 @@ impl Parameters {
|
||||
|
||||
impl<T> ElemCommon<T> for Ciphertext<T>
|
||||
where
|
||||
T: Infos,
|
||||
T: ZnxInfos,
|
||||
{
|
||||
fn n(&self) -> usize {
|
||||
self.elem().n()
|
||||
@@ -78,16 +78,16 @@ pub fn new_rlwe_ciphertext(module: &Module, log_base2k: usize, log_q: usize) ->
|
||||
Ciphertext::<VecZnx>::new(module, log_base2k, log_q, rows)
|
||||
}
|
||||
|
||||
pub fn new_gadget_ciphertext(module: &Module, log_base2k: usize, rows: usize, log_q: usize) -> Ciphertext<VmpPMat> {
|
||||
pub fn new_gadget_ciphertext(module: &Module, log_base2k: usize, rows: usize, log_q: usize) -> Ciphertext<MatZnxDft> {
|
||||
let cols: usize = (log_q + log_base2k - 1) / log_base2k;
|
||||
let mut elem: Elem<VmpPMat> = Elem::<VmpPMat>::new(module, log_base2k, 2, rows, cols);
|
||||
let mut elem: Elem<MatZnxDft> = Elem::<MatZnxDft>::new(module, log_base2k, 2, rows, cols);
|
||||
elem.log_q = log_q;
|
||||
Ciphertext(elem)
|
||||
}
|
||||
|
||||
pub fn new_rgsw_ciphertext(module: &Module, log_base2k: usize, rows: usize, log_q: usize) -> Ciphertext<VmpPMat> {
|
||||
pub fn new_rgsw_ciphertext(module: &Module, log_base2k: usize, rows: usize, log_q: usize) -> Ciphertext<MatZnxDft> {
|
||||
let cols: usize = (log_q + log_base2k - 1) / log_base2k;
|
||||
let mut elem: Elem<VmpPMat> = Elem::<VmpPMat>::new(module, log_base2k, 4, rows, cols);
|
||||
let mut elem: Elem<MatZnxDft> = Elem::<MatZnxDft>::new(module, log_base2k, 4, rows, cols);
|
||||
elem.log_q = log_q;
|
||||
Ciphertext(elem)
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@ use crate::{
|
||||
parameters::Parameters,
|
||||
plaintext::Plaintext,
|
||||
};
|
||||
use base2k::{Module, SvpPPol, SvpPPolOps, VecZnx, VecZnxBigOps, VecZnxDft, VecZnxDftOps};
|
||||
use base2k::{Module, ScalarZnxDft, ScalarZnxDftOps, VecZnx, VecZnxBigOps, VecZnxDft, VecZnxDftOps};
|
||||
use std::cmp::min;
|
||||
|
||||
pub struct Decryptor {
|
||||
sk: SvpPPol,
|
||||
sk: ScalarZnxDft,
|
||||
}
|
||||
|
||||
impl Decryptor {
|
||||
pub fn new(params: &Parameters, sk: &SecretKey) -> Self {
|
||||
let mut sk_svp_ppol: SvpPPol = params.module().new_svp_ppol();
|
||||
let mut sk_svp_ppol: ScalarZnxDft = params.module().new_svp_ppol();
|
||||
sk.prepare(params.module(), &mut sk_svp_ppol);
|
||||
Self { sk: sk_svp_ppol }
|
||||
}
|
||||
@@ -32,12 +32,12 @@ impl Parameters {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn decrypt_rlwe(&self, res: &mut Plaintext, ct: &Ciphertext<VecZnx>, sk: &SvpPPol, tmp_bytes: &mut [u8]) {
|
||||
pub fn decrypt_rlwe(&self, res: &mut Plaintext, ct: &Ciphertext<VecZnx>, sk: &ScalarZnxDft, tmp_bytes: &mut [u8]) {
|
||||
decrypt_rlwe(self.module(), &mut res.0, &ct.0, sk, tmp_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decrypt_rlwe(module: &Module, res: &mut Elem<VecZnx>, a: &Elem<VecZnx>, sk: &SvpPPol, tmp_bytes: &mut [u8]) {
|
||||
pub fn decrypt_rlwe(module: &Module, res: &mut Elem<VecZnx>, a: &Elem<VecZnx>, sk: &ScalarZnxDft, tmp_bytes: &mut [u8]) {
|
||||
let cols: usize = a.cols();
|
||||
|
||||
assert!(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use base2k::{Infos, Layout, Module, VecZnx, VecZnxOps, VmpPMat, VmpPMatOps};
|
||||
use base2k::{ZnxInfos, Layout, Module, VecZnx, VecZnxOps, MatZnxDft, MatZnxDftOps};
|
||||
|
||||
pub struct Elem<T> {
|
||||
pub value: Vec<T>,
|
||||
@@ -81,7 +81,7 @@ pub trait ElemCommon<T> {
|
||||
fn at_mut(&mut self, i: usize) -> &mut T;
|
||||
}
|
||||
|
||||
impl<T: Infos> ElemCommon<T> for Elem<T> {
|
||||
impl<T: ZnxInfos> ElemCommon<T> for Elem<T> {
|
||||
fn n(&self) -> usize {
|
||||
self.value[0].n()
|
||||
}
|
||||
@@ -152,11 +152,11 @@ impl Elem<VecZnx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Elem<VmpPMat> {
|
||||
impl Elem<MatZnxDft> {
|
||||
pub fn new(module: &Module, log_base2k: usize, size: usize, rows: usize, cols: usize) -> Self {
|
||||
assert!(rows > 0);
|
||||
assert!(cols > 0);
|
||||
let mut value: Vec<VmpPMat> = Vec::new();
|
||||
let mut value: Vec<MatZnxDft> = Vec::new();
|
||||
(0..size).for_each(|_| value.push(module.new_vmp_pmat(1, rows, cols)));
|
||||
Self {
|
||||
value: value,
|
||||
|
||||
@@ -5,8 +5,8 @@ use crate::parameters::Parameters;
|
||||
use crate::plaintext::Plaintext;
|
||||
use base2k::sampling::Sampling;
|
||||
use base2k::{
|
||||
Infos, Module, Scalar, SvpPPol, SvpPPolOps, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, VecZnxOps, VmpPMat,
|
||||
VmpPMatOps,
|
||||
ZnxInfos, Module, Scalar, ScalarZnxDft, ScalarZnxDftOps, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, VecZnxOps, MatZnxDft,
|
||||
MatZnxDftOps,
|
||||
};
|
||||
|
||||
use sampling::source::{Source, new_seed};
|
||||
@@ -19,7 +19,7 @@ impl Parameters {
|
||||
&self,
|
||||
ct: &mut Ciphertext<VecZnx>,
|
||||
pt: Option<&Plaintext>,
|
||||
sk: &SvpPPol,
|
||||
sk: &ScalarZnxDft,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
tmp_bytes: &mut [u8],
|
||||
@@ -38,7 +38,7 @@ impl Parameters {
|
||||
}
|
||||
|
||||
pub struct EncryptorSk {
|
||||
sk: SvpPPol,
|
||||
sk: ScalarZnxDft,
|
||||
source_xa: Source,
|
||||
source_xe: Source,
|
||||
initialized: bool,
|
||||
@@ -47,7 +47,7 @@ pub struct EncryptorSk {
|
||||
|
||||
impl EncryptorSk {
|
||||
pub fn new(params: &Parameters, sk: Option<&SecretKey>) -> Self {
|
||||
let mut sk_svp_ppol: SvpPPol = params.module().new_svp_ppol();
|
||||
let mut sk_svp_ppol: ScalarZnxDft = params.module().new_svp_ppol();
|
||||
let mut initialized: bool = false;
|
||||
if let Some(sk) = sk {
|
||||
sk.prepare(params.module(), &mut sk_svp_ppol);
|
||||
@@ -114,7 +114,7 @@ pub fn encrypt_rlwe_sk(
|
||||
module: &Module,
|
||||
ct: &mut Elem<VecZnx>,
|
||||
pt: Option<&VecZnx>,
|
||||
sk: &SvpPPol,
|
||||
sk: &ScalarZnxDft,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
@@ -127,7 +127,7 @@ fn encrypt_rlwe_sk_core<const PT_POS: u8>(
|
||||
module: &Module,
|
||||
ct: &mut Elem<VecZnx>,
|
||||
pt: Option<&VecZnx>,
|
||||
sk: &SvpPPol,
|
||||
sk: &ScalarZnxDft,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
@@ -217,9 +217,9 @@ pub fn encrypt_grlwe_sk_tmp_bytes(module: &Module, log_base2k: usize, rows: usiz
|
||||
|
||||
pub fn encrypt_grlwe_sk(
|
||||
module: &Module,
|
||||
ct: &mut Ciphertext<VmpPMat>,
|
||||
ct: &mut Ciphertext<MatZnxDft>,
|
||||
m: &Scalar,
|
||||
sk: &SvpPPol,
|
||||
sk: &ScalarZnxDft,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
@@ -258,9 +258,9 @@ pub fn encrypt_rgsw_sk_tmp_bytes(module: &Module, log_base2k: usize, rows: usize
|
||||
|
||||
pub fn encrypt_rgsw_sk(
|
||||
module: &Module,
|
||||
ct: &mut Ciphertext<VmpPMat>,
|
||||
ct: &mut Ciphertext<MatZnxDft>,
|
||||
m: &Scalar,
|
||||
sk: &SvpPPol,
|
||||
sk: &ScalarZnxDft,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
@@ -302,10 +302,10 @@ pub fn encrypt_rgsw_sk(
|
||||
fn encrypt_grlwe_sk_core<const PT_POS: u8>(
|
||||
module: &Module,
|
||||
log_base2k: usize,
|
||||
mut ct: [&mut VmpPMat; 2],
|
||||
mut ct: [&mut MatZnxDft; 2],
|
||||
log_q: usize,
|
||||
m: &Scalar,
|
||||
sk: &SvpPPol,
|
||||
sk: &ScalarZnxDft,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{ciphertext::Ciphertext, elem::ElemCommon, parameters::Parameters};
|
||||
use base2k::{Module, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, VmpPMat, VmpPMatOps};
|
||||
use base2k::{Module, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, MatZnxDft, MatZnxDftOps};
|
||||
use std::cmp::min;
|
||||
|
||||
pub fn gadget_product_core_tmp_bytes(
|
||||
@@ -34,7 +34,7 @@ pub fn gadget_product_core(
|
||||
res_dft_0: &mut VecZnxDft,
|
||||
res_dft_1: &mut VecZnxDft,
|
||||
a: &VecZnx,
|
||||
b: &Ciphertext<VmpPMat>,
|
||||
b: &Ciphertext<MatZnxDft>,
|
||||
b_cols: usize,
|
||||
tmp_bytes: &mut [u8],
|
||||
) {
|
||||
@@ -61,7 +61,7 @@ pub fn gadget_product_big(
|
||||
module: &Module,
|
||||
c: &mut Ciphertext<VecZnxBig>,
|
||||
a: &Ciphertext<VecZnx>,
|
||||
b: &Ciphertext<VmpPMat>,
|
||||
b: &Ciphertext<MatZnxDft>,
|
||||
tmp_bytes: &mut [u8],
|
||||
) {
|
||||
let cols: usize = min(c.cols(), a.cols());
|
||||
@@ -94,7 +94,7 @@ pub fn gadget_product(
|
||||
module: &Module,
|
||||
c: &mut Ciphertext<VecZnx>,
|
||||
a: &Ciphertext<VecZnx>,
|
||||
b: &Ciphertext<VmpPMat>,
|
||||
b: &Ciphertext<MatZnxDft>,
|
||||
tmp_bytes: &mut [u8],
|
||||
) {
|
||||
let cols: usize = min(c.cols(), a.cols());
|
||||
@@ -130,7 +130,7 @@ mod test {
|
||||
plaintext::Plaintext,
|
||||
};
|
||||
use base2k::{
|
||||
BACKEND, Infos, Sampling, SvpPPolOps, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, VecZnxOps, VmpPMat,
|
||||
BACKEND, ZnxInfos, Sampling, ScalarZnxDftOps, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, VecZnxOps, MatZnxDft,
|
||||
alloc_aligned_u8,
|
||||
};
|
||||
use sampling::source::{Source, new_seed};
|
||||
@@ -175,16 +175,16 @@ mod test {
|
||||
// Two secret keys
|
||||
let mut sk0: SecretKey = SecretKey::new(params.module());
|
||||
sk0.fill_ternary_hw(params.xs(), &mut source_xs);
|
||||
let mut sk0_svp_ppol: base2k::SvpPPol = params.module().new_svp_ppol();
|
||||
let mut sk0_svp_ppol: base2k::ScalarZnxDft = params.module().new_svp_ppol();
|
||||
params.module().svp_prepare(&mut sk0_svp_ppol, &sk0.0);
|
||||
|
||||
let mut sk1: SecretKey = SecretKey::new(params.module());
|
||||
sk1.fill_ternary_hw(params.xs(), &mut source_xs);
|
||||
let mut sk1_svp_ppol: base2k::SvpPPol = params.module().new_svp_ppol();
|
||||
let mut sk1_svp_ppol: base2k::ScalarZnxDft = params.module().new_svp_ppol();
|
||||
params.module().svp_prepare(&mut sk1_svp_ppol, &sk1.0);
|
||||
|
||||
// The gadget ciphertext
|
||||
let mut gadget_ct: Ciphertext<VmpPMat> = new_gadget_ciphertext(
|
||||
let mut gadget_ct: Ciphertext<MatZnxDft> = new_gadget_ciphertext(
|
||||
params.module(),
|
||||
log_base2k,
|
||||
params.cols_qp(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::encryptor::{encrypt_grlwe_sk, encrypt_grlwe_sk_tmp_bytes};
|
||||
use crate::keys::{PublicKey, SecretKey, SwitchingKey};
|
||||
use crate::parameters::Parameters;
|
||||
use base2k::{Module, SvpPPol};
|
||||
use base2k::{Module, ScalarZnxDft};
|
||||
use sampling::source::Source;
|
||||
|
||||
pub struct KeyGenerator {}
|
||||
@@ -16,7 +16,7 @@ impl KeyGenerator {
|
||||
pub fn gen_public_key_thread_safe(
|
||||
&self,
|
||||
params: &Parameters,
|
||||
sk_ppol: &SvpPPol,
|
||||
sk_ppol: &ScalarZnxDft,
|
||||
source: &mut Source,
|
||||
tmp_bytes: &mut [u8],
|
||||
) -> PublicKey {
|
||||
@@ -43,7 +43,7 @@ pub fn gen_switching_key(
|
||||
module: &Module,
|
||||
swk: &mut SwitchingKey,
|
||||
sk_in: &SecretKey,
|
||||
sk_out: &SvpPPol,
|
||||
sk_out: &ScalarZnxDft,
|
||||
source_xa: &mut Source,
|
||||
source_xe: &mut Source,
|
||||
sigma: f64,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::ciphertext::Ciphertext;
|
||||
use crate::elem::ElemCommon;
|
||||
use base2k::{Module, VecZnx, VecZnxBigOps, VecZnxDftOps, VmpPMat, VmpPMatOps, assert_alignement};
|
||||
use base2k::{Module, VecZnx, VecZnxBigOps, VecZnxDftOps, MatZnxDft, MatZnxDftOps, assert_alignement};
|
||||
use std::cmp::min;
|
||||
|
||||
pub fn key_switch_tmp_bytes(module: &Module, log_base2k: usize, res_logq: usize, in_logq: usize, gct_logq: usize) -> usize {
|
||||
@@ -16,7 +16,7 @@ pub fn key_switch_rlwe(
|
||||
module: &Module,
|
||||
c: &mut Ciphertext<VecZnx>,
|
||||
a: &Ciphertext<VecZnx>,
|
||||
b: &Ciphertext<VmpPMat>,
|
||||
b: &Ciphertext<MatZnxDft>,
|
||||
b_cols: usize,
|
||||
tmp_bytes: &mut [u8],
|
||||
) {
|
||||
@@ -26,7 +26,7 @@ pub fn key_switch_rlwe(
|
||||
pub fn key_switch_rlwe_inplace(
|
||||
module: &Module,
|
||||
a: &mut Ciphertext<VecZnx>,
|
||||
b: &Ciphertext<VmpPMat>,
|
||||
b: &Ciphertext<MatZnxDft>,
|
||||
b_cols: usize,
|
||||
tmp_bytes: &mut [u8],
|
||||
) {
|
||||
@@ -37,7 +37,7 @@ fn key_switch_rlwe_core(
|
||||
module: &Module,
|
||||
c: *mut Ciphertext<VecZnx>,
|
||||
a: *const Ciphertext<VecZnx>,
|
||||
b: &Ciphertext<VmpPMat>,
|
||||
b: &Ciphertext<MatZnxDft>,
|
||||
b_cols: usize,
|
||||
tmp_bytes: &mut [u8],
|
||||
) {
|
||||
@@ -74,6 +74,6 @@ fn key_switch_rlwe_core(
|
||||
module.vec_znx_big_normalize(c.log_base2k(), c.at_mut(1), &mut res_big, tmp_bytes);
|
||||
}
|
||||
|
||||
pub fn key_switch_grlwe(module: &Module, c: &mut Ciphertext<VecZnx>, a: &Ciphertext<VecZnx>, b: &Ciphertext<VmpPMat>) {}
|
||||
pub fn key_switch_grlwe(module: &Module, c: &mut Ciphertext<VecZnx>, a: &Ciphertext<VecZnx>, b: &Ciphertext<MatZnxDft>) {}
|
||||
|
||||
pub fn key_switch_rgsw(module: &Module, c: &mut Ciphertext<VecZnx>, a: &Ciphertext<VecZnx>, b: &Ciphertext<VmpPMat>) {}
|
||||
pub fn key_switch_rgsw(module: &Module, c: &mut Ciphertext<VecZnx>, a: &Ciphertext<VecZnx>, b: &Ciphertext<MatZnxDft>) {}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::ciphertext::{Ciphertext, new_gadget_ciphertext};
|
||||
use crate::elem::{Elem, ElemCommon};
|
||||
use crate::encryptor::{encrypt_rlwe_sk, encrypt_rlwe_sk_tmp_bytes};
|
||||
use base2k::{Module, Scalar, SvpPPol, SvpPPolOps, VecZnx, VmpPMat};
|
||||
use base2k::{Module, Scalar, ScalarZnxDft, ScalarZnxDftOps, VecZnx, MatZnxDft};
|
||||
use sampling::source::Source;
|
||||
|
||||
pub struct SecretKey(pub Scalar);
|
||||
@@ -19,7 +19,7 @@ impl SecretKey {
|
||||
self.0.fill_ternary_hw(hw, source);
|
||||
}
|
||||
|
||||
pub fn prepare(&self, module: &Module, sk_ppol: &mut SvpPPol) {
|
||||
pub fn prepare(&self, module: &Module, sk_ppol: &mut ScalarZnxDft) {
|
||||
module.svp_prepare(sk_ppol, &self.0)
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ impl PublicKey {
|
||||
pub fn gen_thread_safe(
|
||||
&mut self,
|
||||
module: &Module,
|
||||
sk: &SvpPPol,
|
||||
sk: &ScalarZnxDft,
|
||||
xe: f64,
|
||||
xa_source: &mut Source,
|
||||
xe_source: &mut Source,
|
||||
@@ -57,7 +57,7 @@ impl PublicKey {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SwitchingKey(pub Ciphertext<VmpPMat>);
|
||||
pub struct SwitchingKey(pub Ciphertext<MatZnxDft>);
|
||||
|
||||
impl SwitchingKey {
|
||||
pub fn new(module: &Module, log_base2k: usize, rows: usize, log_q: usize) -> SwitchingKey {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{ciphertext::Ciphertext, elem::ElemCommon, parameters::Parameters};
|
||||
use base2k::{Module, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, VmpPMat, VmpPMatOps, assert_alignement};
|
||||
use base2k::{Module, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, MatZnxDft, MatZnxDftOps, assert_alignement};
|
||||
use std::cmp::min;
|
||||
|
||||
impl Parameters {
|
||||
@@ -26,7 +26,7 @@ pub fn rgsw_product(
|
||||
module: &Module,
|
||||
c: &mut Ciphertext<VecZnx>,
|
||||
a: &Ciphertext<VecZnx>,
|
||||
b: &Ciphertext<VmpPMat>,
|
||||
b: &Ciphertext<MatZnxDft>,
|
||||
b_cols: usize,
|
||||
tmp_bytes: &mut [u8],
|
||||
) {
|
||||
@@ -69,7 +69,7 @@ pub fn rgsw_product(
|
||||
pub fn rgsw_product_inplace(
|
||||
module: &Module,
|
||||
a: &mut Ciphertext<VecZnx>,
|
||||
b: &Ciphertext<VmpPMat>,
|
||||
b: &Ciphertext<MatZnxDft>,
|
||||
b_cols: usize,
|
||||
tmp_bytes: &mut [u8],
|
||||
) {
|
||||
@@ -120,7 +120,7 @@ mod test {
|
||||
plaintext::Plaintext,
|
||||
rgsw_product::rgsw_product_inplace,
|
||||
};
|
||||
use base2k::{BACKEND, Encoding, Module, Scalar, SvpPPol, SvpPPolOps, VecZnx, VecZnxOps, VmpPMat, alloc_aligned};
|
||||
use base2k::{BACKEND, Encoding, Module, Scalar, ScalarZnxDft, ScalarZnxDftOps, VecZnx, VecZnxOps, MatZnxDft, alloc_aligned};
|
||||
use sampling::source::{Source, new_seed};
|
||||
|
||||
#[test]
|
||||
@@ -164,10 +164,10 @@ mod test {
|
||||
|
||||
let mut sk: SecretKey = SecretKey::new(module);
|
||||
sk.fill_ternary_hw(params.xs(), &mut source_xs);
|
||||
let mut sk_svp_ppol: SvpPPol = module.new_svp_ppol();
|
||||
let mut sk_svp_ppol: ScalarZnxDft = module.new_svp_ppol();
|
||||
module.svp_prepare(&mut sk_svp_ppol, &sk.0);
|
||||
|
||||
let mut ct_rgsw: Ciphertext<VmpPMat> = new_rgsw_ciphertext(module, log_base2k, gct_rows, log_qp);
|
||||
let mut ct_rgsw: Ciphertext<MatZnxDft> = new_rgsw_ciphertext(module, log_base2k, gct_rows, log_qp);
|
||||
|
||||
let k: i64 = 3;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{automorphism::AutomorphismKey, ciphertext::Ciphertext, elem::ElemCommon, parameters::Parameters};
|
||||
use base2k::{Module, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, VmpPMatOps, assert_alignement};
|
||||
use base2k::{Module, VecZnx, VecZnxBig, VecZnxBigOps, VecZnxDft, VecZnxDftOps, MatZnxDftOps, assert_alignement};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn trace_galois_elements(module: &Module) -> Vec<i64> {
|
||||
@@ -115,7 +115,7 @@ mod test {
|
||||
parameters::{DEFAULT_SIGMA, Parameters, ParametersLiteral},
|
||||
plaintext::Plaintext,
|
||||
};
|
||||
use base2k::{BACKEND, Encoding, Module, SvpPPol, SvpPPolOps, VecZnx, alloc_aligned};
|
||||
use base2k::{BACKEND, Encoding, Module, ScalarZnxDft, ScalarZnxDftOps, VecZnx, alloc_aligned};
|
||||
use sampling::source::{Source, new_seed};
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -160,7 +160,7 @@ mod test {
|
||||
|
||||
let mut sk: SecretKey = SecretKey::new(module);
|
||||
sk.fill_ternary_hw(params.xs(), &mut source_xs);
|
||||
let mut sk_svp_ppol: SvpPPol = module.new_svp_ppol();
|
||||
let mut sk_svp_ppol: ScalarZnxDft = module.new_svp_ppol();
|
||||
module.svp_prepare(&mut sk_svp_ppol, &sk.0);
|
||||
|
||||
let gal_els: Vec<i64> = trace_galois_elements(module);
|
||||
|
||||
Reference in New Issue
Block a user