use base2k::{ Backend, FFT64, Module, ScalarZnx, ScalarZnxAlloc, ScalarZnxDft, ScalarZnxDftAlloc, ScalarZnxDftOps, ScalarZnxDftToMut, ScalarZnxDftToRef, ScalarZnxToMut, ScalarZnxToRef, Scratch, VecZnxDft, VecZnxDftAlloc, VecZnxDftToMut, }; use sampling::source::Source; use crate::elem::derive_size; pub struct SecretKey { pub data: ScalarZnx, } impl SecretKey> { pub fn new(module: &Module) -> Self { Self { data: module.new_scalar(1), } } } impl SecretKey where S: AsMut<[u8]> + AsRef<[u8]>, { pub fn fill_ternary_prob(&mut self, prob: f64, source: &mut Source) { self.data.fill_ternary_prob(0, prob, source); } pub fn fill_ternary_hw(&mut self, hw: usize, source: &mut Source) { self.data.fill_ternary_hw(0, hw, source); } } impl ScalarZnxToMut for SecretKey where ScalarZnx: ScalarZnxToMut, { fn to_mut(&mut self) -> ScalarZnx<&mut [u8]> { self.data.to_mut() } } impl ScalarZnxToRef for SecretKey where ScalarZnx: ScalarZnxToRef, { fn to_ref(&self) -> ScalarZnx<&[u8]> { self.data.to_ref() } } pub struct SecretKeyDft { pub data: ScalarZnxDft, } impl SecretKeyDft, B> { pub fn new(module: &Module) -> Self { Self { data: module.new_scalar_znx_dft(1), } } pub fn dft(&mut self, module: &Module, sk: &SecretKey) where SecretKeyDft, B>: ScalarZnxDftToMut, SecretKey: ScalarZnxToRef, { module.svp_prepare(self, 0, sk, 0) } } impl ScalarZnxDftToMut for SecretKeyDft where ScalarZnxDft: ScalarZnxDftToMut, { fn to_mut(&mut self) -> ScalarZnxDft<&mut [u8], B> { self.data.to_mut() } } impl ScalarZnxDftToRef for SecretKeyDft where ScalarZnxDft: ScalarZnxDftToRef, { fn to_ref(&self) -> ScalarZnxDft<&[u8], B> { self.data.to_ref() } } pub struct PublicKey { pub data: VecZnxDft, } impl PublicKey, B> { pub fn new(module: &Module, log_base2k: usize, log_q: usize) -> Self { Self { data: module.new_vec_znx_dft(2, derive_size(log_base2k, log_q)), } } } impl> PublicKey { pub fn generate(&mut self, module: &Module, sk: &SecretKey>, scratch: &mut Scratch) where ScalarZnxDft: ScalarZnxDftToMut, { } }