From ba984c2537d4c7641bcf726b647ab60535aa7257 Mon Sep 17 00:00:00 2001 From: J-B Orfila Date: Fri, 2 Dec 2022 15:34:23 +0100 Subject: [PATCH] feat(core): blind rotate binding --- .../lwe_programmable_bootstrapping.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping.rs b/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping.rs index bf07f57c4..54182eb12 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_programmable_bootstrapping.rs @@ -3,11 +3,40 @@ use crate::core_crypto::commons::numeric::CastInto; use crate::core_crypto::commons::traits::*; use crate::core_crypto::entities::*; use crate::core_crypto::fft_impl::crypto::bootstrap::{bootstrap_scratch, FourierLweBootstrapKey}; +use crate::core_crypto::fft_impl::crypto::ggsw::cmux_scratch; use crate::core_crypto::fft_impl::math::fft::FftView; use crate::core_crypto::specification::parameters::*; +use aligned_vec::CACHELINE_ALIGN; use concrete_fft::c64; use dyn_stack::{DynStack, SizeOverflow, StackReq}; +pub fn blind_rotate( + input: &LweCiphertext, + lut: &mut GlweCiphertext, + bsk: &FourierLweBootstrapKey, + fft: FftView<'_>, + stack: DynStack<'_>, +) where + // CastInto required for PBS modulus switch which returns a usize + Scalar: UnsignedTorus + CastInto, + InputCont: Container, + OutputCont: ContainerMut, + KeyCont: Container, +{ + bsk.as_view() + .blind_rotate(lut.as_mut_view(), input.as_ref(), fft, stack); +} + +/// Returns the required memory for [`blind_rotate`]. +pub fn blind_rotate_scratch( + glwe_size: GlweSize, + polynomial_size: PolynomialSize, + fft: FftView<'_>, +) -> Result { + StackReq::try_new_aligned::(glwe_size.0 * polynomial_size.0, CACHELINE_ALIGN)? + .try_and(cmux_scratch::(glwe_size, polynomial_size, fft)?) +} + pub fn programmable_bootstrap_lwe_ciphertext( input: &LweCiphertext, output: &mut LweCiphertext,