concrete_core/specification/engines/
lwe_ciphertext_conversion.rs

1use super::engine_error;
2use crate::specification::engines::AbstractEngine;
3use crate::specification::entities::LweCiphertextEntity;
4
5engine_error! {
6    LweCiphertextConversionError for LweCiphertextConversionEngine @
7}
8
9/// A trait for engines converting LWE ciphertexts.
10///
11/// # Semantics
12///
13/// This [pure](super#operation-semantics) operation generates a LWE ciphertext containing the
14/// conversion of the `input` LWE ciphertext to a type with a different representation (for instance
15/// from cpu to gpu memory).
16///
17/// # Formal Definition
18pub trait LweCiphertextConversionEngine<Input, Output>: AbstractEngine
19where
20    Input: LweCiphertextEntity,
21    Output: LweCiphertextEntity<KeyDistribution = Input::KeyDistribution>,
22{
23    /// Converts a LWE ciphertext.
24    fn convert_lwe_ciphertext(
25        &mut self,
26        input: &Input,
27    ) -> Result<Output, LweCiphertextConversionError<Self::EngineError>>;
28
29    /// Unsafely converts a LWE ciphertext.
30    ///
31    /// # Safety
32    /// For the _general_ safety concerns regarding this operation, refer to the different variants
33    /// of [`LweCiphertextConversionError`]. For safety concerns _specific_ to an engine, refer to
34    /// the implementer safety section.
35    unsafe fn convert_lwe_ciphertext_unchecked(&mut self, input: &Input) -> Output;
36}