use backend::hal::{ api::{ ScratchAvailable, SvpApplyInplace, TakeVecZnx, TakeVecZnxDft, VecZnxAddInplace, VecZnxAddNormal, VecZnxBigNormalize, VecZnxDftAllocBytes, VecZnxDftFromVecZnx, VecZnxDftToVecZnxBigConsume, VecZnxFillUniform, VecZnxNormalize, VecZnxNormalizeInplace, VecZnxNormalizeTmpBytes, VecZnxSub, VecZnxSubABInplace, }, layouts::{Backend, DataMut, DataRef, Module, Scratch}, }; use sampling::source::Source; use crate::{ encryption::glwe_ct::glwe_encrypt_sk_internal, layouts::{GLWECiphertext, GLWEPlaintext, Infos, compressed::GLWECiphertextCompressed, prepared::GLWESecretPrepared}, }; impl GLWECiphertextCompressed> { pub fn encrypt_sk_scratch_space(module: &Module, n: usize, basek: usize, k: usize) -> usize where Module: VecZnxNormalizeTmpBytes + VecZnxDftAllocBytes, { GLWECiphertext::encrypt_sk_scratch_space(module, n, basek, k) } } impl GLWECiphertextCompressed { #[allow(clippy::too_many_arguments)] pub fn encrypt_sk( &mut self, module: &Module, pt: &GLWEPlaintext, sk: &GLWESecretPrepared, seed_xa: [u8; 32], source_xe: &mut Source, sigma: f64, scratch: &mut Scratch, ) where Module: VecZnxDftAllocBytes + VecZnxBigNormalize + VecZnxDftFromVecZnx + SvpApplyInplace + VecZnxDftToVecZnxBigConsume + VecZnxNormalizeTmpBytes + VecZnxFillUniform + VecZnxSubABInplace + VecZnxAddInplace + VecZnxNormalizeInplace + VecZnxAddNormal + VecZnxNormalize + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { self.encrypt_sk_internal( module, Some((pt, 0)), sk, seed_xa, source_xe, sigma, scratch, ); } #[allow(clippy::too_many_arguments)] pub(crate) fn encrypt_sk_internal( &mut self, module: &Module, pt: Option<(&GLWEPlaintext, usize)>, sk: &GLWESecretPrepared, seed_xa: [u8; 32], source_xe: &mut Source, sigma: f64, scratch: &mut Scratch, ) where Module: VecZnxDftAllocBytes + VecZnxBigNormalize + VecZnxDftFromVecZnx + SvpApplyInplace + VecZnxDftToVecZnxBigConsume + VecZnxNormalizeTmpBytes + VecZnxFillUniform + VecZnxSubABInplace + VecZnxAddInplace + VecZnxNormalizeInplace + VecZnxAddNormal + VecZnxNormalize + VecZnxSub, Scratch: TakeVecZnxDft + ScratchAvailable + TakeVecZnx, { let mut source_xa = Source::new(seed_xa); let cols: usize = self.rank() + 1; glwe_encrypt_sk_internal( module, self.basek(), self.k(), &mut self.data, cols, true, pt, sk, &mut source_xa, source_xe, sigma, scratch, ); self.seed = seed_xa; } }