mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-10 15:18:33 -05:00
feat(core): add conversion functions for GgswCiphertext
This commit is contained in:
70
tfhe/src/core_crypto/algorithms/ggsw_conversion.rs
Normal file
70
tfhe/src/core_crypto/algorithms/ggsw_conversion.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
//! Module containing primitives pertaining to the conversion of
|
||||
//! [`standard GGSW ciphertexts`](`GgswCiphertext`) to various representations/numerical domains
|
||||
//! like the Fourier domain.
|
||||
|
||||
use crate::core_crypto::commons::computation_buffers::ComputationBuffers;
|
||||
use crate::core_crypto::commons::traits::*;
|
||||
use crate::core_crypto::entities::*;
|
||||
use crate::core_crypto::fft_impl::crypto::ggsw::{
|
||||
fill_with_forward_fourier_scratch, FourierGgswCiphertext,
|
||||
};
|
||||
use crate::core_crypto::fft_impl::math::fft::{Fft, FftView};
|
||||
use concrete_fft::c64;
|
||||
use dyn_stack::{DynStack, SizeOverflow, StackReq};
|
||||
|
||||
/// Convert a [`GGSW ciphertext`](`GgswCiphertext`) with standard coefficients to the Fourier
|
||||
/// domain.
|
||||
///
|
||||
/// If you want to manage the computation memory manually you can use
|
||||
/// [`convert_standard_ggsw_ciphertext_to_fourier_mem_optimized`].
|
||||
pub fn convert_standard_ggsw_ciphertext_to_fourier<Scalar, InputCont, OutputCont>(
|
||||
input_ggsw: &GgswCiphertext<InputCont>,
|
||||
output_ggsw: &mut FourierGgswCiphertext<OutputCont>,
|
||||
) where
|
||||
Scalar: UnsignedTorus,
|
||||
InputCont: Container<Element = Scalar>,
|
||||
OutputCont: ContainerMut<Element = c64>,
|
||||
{
|
||||
let fft = Fft::new(output_ggsw.polynomial_size());
|
||||
let fft = fft.as_view();
|
||||
|
||||
let mut buffers = ComputationBuffers::new();
|
||||
buffers.resize(
|
||||
convert_standard_ggsw_ciphertext_to_fourier_mem_optimized_requirement(fft)
|
||||
.unwrap()
|
||||
.unaligned_bytes_required(),
|
||||
);
|
||||
|
||||
convert_standard_ggsw_ciphertext_to_fourier_mem_optimized(
|
||||
input_ggsw,
|
||||
output_ggsw,
|
||||
fft,
|
||||
buffers.stack(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Memory optimized version of [`convert_standard_ggsw_ciphertext_to_fourier`].
|
||||
///
|
||||
/// See [`cmux_assign_mem_optimized`](`crate::core_crypto::algorithms::cmux_assign_mem_optimized`)
|
||||
/// for usage.
|
||||
pub fn convert_standard_ggsw_ciphertext_to_fourier_mem_optimized<Scalar, InputCont, OutputCont>(
|
||||
input_ggsw: &GgswCiphertext<InputCont>,
|
||||
output_ggsw: &mut FourierGgswCiphertext<OutputCont>,
|
||||
fft: FftView<'_>,
|
||||
stack: DynStack<'_>,
|
||||
) where
|
||||
Scalar: UnsignedTorus,
|
||||
InputCont: Container<Element = Scalar>,
|
||||
OutputCont: ContainerMut<Element = c64>,
|
||||
{
|
||||
output_ggsw
|
||||
.as_mut_view()
|
||||
.fill_with_forward_fourier(input_ggsw.as_view(), fft, stack);
|
||||
}
|
||||
|
||||
/// Return the required memory for [`convert_standard_ggsw_ciphertext_to_fourier_mem_optimized`].
|
||||
pub fn convert_standard_ggsw_ciphertext_to_fourier_mem_optimized_requirement(
|
||||
fft: FftView<'_>,
|
||||
) -> Result<StackReq, SizeOverflow> {
|
||||
fill_with_forward_fourier_scratch(fft)
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
//! operating on [`slices of scalars`](`slice_algorithms`) and on
|
||||
//! [`polynomials`](`polynomial_algorithms`).
|
||||
|
||||
pub mod ggsw_conversion;
|
||||
pub mod ggsw_encryption;
|
||||
pub mod glwe_encryption;
|
||||
pub mod glwe_sample_extraction;
|
||||
@@ -33,6 +34,7 @@ pub mod slice_algorithms;
|
||||
|
||||
// No pub use for slice and polynomial algorithms which would not interest higher level users
|
||||
// They can still be used via `use crate::core_crypto::algorithms::slice_algorithms::*;`
|
||||
pub use ggsw_conversion::*;
|
||||
pub use ggsw_encryption::*;
|
||||
pub use glwe_encryption::*;
|
||||
pub use glwe_sample_extraction::*;
|
||||
|
||||
Reference in New Issue
Block a user