added rlwe basic sk encryption

This commit is contained in:
Jean-Philippe Bossuat
2025-05-06 16:43:17 +02:00
parent e35924f44c
commit fe6f99b9ce
3 changed files with 102 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
use base2k::{Backend, FFT64, MatZnxDft, MatZnxDftAlloc, Module, VecZnx, VecZnxAlloc};
use base2k::{Backend, FFT64, MatZnxDft, MatZnxDftAlloc, Module, VecZnx, VecZnxAlloc, VecZnxDft, VecZnxDftAlloc};
pub struct Ciphertext<T> {
data: T,
@@ -48,7 +48,12 @@ impl<T> Plaintext<T> {
}
}
pub(crate) type CipherVecZnx<C> = Ciphertext<VecZnx<C>>;
pub(crate) type CtVecZnx<C> = Ciphertext<VecZnx<C>>;
pub(crate) type CtVecZnxDft<C, B: Backend> = Ciphertext<VecZnxDft<C, B>>;
pub(crate) type CtMatZnxDft<C, B: Backend> = Ciphertext<MatZnxDft<C, B>>;
pub(crate) type PtVecZnx<C> = Plaintext<VecZnx<C>>;
pub(crate) type PtVecZnxDft<C, B: Backend> = Plaintext<VecZnxDft<C, B>>;
pub(crate) type PtMatZnxDft<C, B: Backend> = Plaintext<MatZnxDft<C, B>>;
impl Ciphertext<VecZnx<Vec<u8>>> {
pub fn new<B: Backend>(module: &Module<B>, log_base2k: usize, log_q: usize, cols: usize) -> Self {
@@ -70,6 +75,16 @@ impl Plaintext<VecZnx<Vec<u8>>> {
}
}
impl<B: Backend> Ciphertext<VecZnxDft<Vec<u8>, B>> {
pub fn new(module: &Module<B>, log_base2k: usize, log_q: usize, cols: usize) -> Self {
Self {
data: module.new_vec_znx_dft(cols, derive_size(log_base2k, log_q)),
log_base2k: log_base2k,
log_q: log_q,
}
}
}
impl<B: Backend> Ciphertext<MatZnxDft<Vec<u8>, B>> {
pub fn new(module: &Module<B>, log_base2k: usize, rows: usize, cols_in: usize, cols_out: usize, log_q: usize) -> Self {
Self {