use poulpy_hal::{ api::{VecZnxDftBytesOf, VecZnxNormalizeTmpBytes}, layouts::{Backend, DataMut, DataRef, Module, Scratch}, source::Source, }; use crate::{ encryption::{SIGMA, glwe_ct::GLWEEncryptSkInternal}, layouts::{ GLWE, GLWEInfos, GLWEPlaintext, GLWEPlaintextToRef, LWEInfos, compressed::{GLWECompressed, GLWECompressedToMut}, prepared::{GLWESecretPrepared, GLWESecretPreparedToRef}, }, }; impl GLWECompressed> { pub fn encrypt_sk_scratch_space(module: &Module, infos: &A) -> usize where A: GLWEInfos, Module: VecZnxNormalizeTmpBytes + VecZnxDftBytesOf, { GLWE::encrypt_sk_scratch_space(module, infos) } } pub trait GLWECompressedEncryptSk { fn glwe_compressed_encrypt_sk( &self, res: &mut R, pt: &P, sk: &S, seed_xa: [u8; 32], source_xe: &mut Source, scratch: &mut Scratch, ) where R: GLWECompressedToMut, P: GLWEPlaintextToRef, S: GLWESecretPreparedToRef; } impl GLWECompressedEncryptSk for Module where Module: GLWEEncryptSkInternal, { fn glwe_compressed_encrypt_sk( &self, res: &mut R, pt: &P, sk: &S, seed_xa: [u8; 32], source_xe: &mut Source, scratch: &mut Scratch, ) where R: GLWECompressedToMut, P: GLWEPlaintextToRef, S: GLWESecretPreparedToRef, { let res: &mut GLWECompressed<&mut [u8]> = &mut res.to_mut(); let mut source_xa: Source = Source::new(seed_xa); let cols: usize = (res.rank() + 1).into(); self.glwe_encrypt_sk_internal( res.base2k().into(), res.k().into(), &mut res.data, cols, true, Some((pt, 0)), sk, &mut source_xa, source_xe, SIGMA, scratch, ); res.seed = seed_xa; } } impl GLWECompressed { #[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, scratch: &mut Scratch, ) where Module: GLWECompressedEncryptSk, { module.glwe_compressed_encrypt_sk(self, pt, sk, seed_xa, source_xe, scratch); } }