concrete_core/specification/engines/
lwe_ciphertext_vector_discarding_subtraction.rs1use super::engine_error;
2use crate::specification::engines::AbstractEngine;
3use crate::specification::entities::LweCiphertextVectorEntity;
4
5engine_error! {
6 LweCiphertextVectorDiscardingSubtractionError for LweCiphertextVectorDiscardingSubtractionEngine @
7 LweDimensionMismatch => "The input and output LWE dimensions must be the same.",
8 CiphertextCountMismatch => "The input and output ciphertext count must be the same."
9}
10
11impl<EngineError: std::error::Error> LweCiphertextVectorDiscardingSubtractionError<EngineError> {
12 pub fn perform_generic_checks<OutputCiphertextVector, InputCiphertextVector>(
14 output: &OutputCiphertextVector,
15 input_1: &InputCiphertextVector,
16 input_2: &InputCiphertextVector,
17 ) -> Result<(), Self>
18 where
19 InputCiphertextVector: LweCiphertextVectorEntity,
20 OutputCiphertextVector:
21 LweCiphertextVectorEntity<KeyDistribution = InputCiphertextVector::KeyDistribution>,
22 {
23 if output.lwe_dimension() != input_1.lwe_dimension()
24 || output.lwe_dimension() != input_2.lwe_dimension()
25 {
26 return Err(Self::LweDimensionMismatch);
27 }
28 if output.lwe_ciphertext_count() != input_1.lwe_ciphertext_count()
29 || output.lwe_ciphertext_count() != input_2.lwe_ciphertext_count()
30 {
31 return Err(Self::CiphertextCountMismatch);
32 }
33 Ok(())
34 }
35}
36
37pub trait LweCiphertextVectorDiscardingSubtractionEngine<
47 InputCiphertextVector,
48 OutputCiphertextVector,
49>: AbstractEngine where
50 InputCiphertextVector: LweCiphertextVectorEntity,
51 OutputCiphertextVector:
52 LweCiphertextVectorEntity<KeyDistribution = InputCiphertextVector::KeyDistribution>,
53{
54 fn discard_sub_lwe_ciphertext_vector(
56 &mut self,
57 output: &mut OutputCiphertextVector,
58 input_1: &InputCiphertextVector,
59 input_2: &InputCiphertextVector,
60 ) -> Result<(), LweCiphertextVectorDiscardingSubtractionError<Self::EngineError>>;
61
62 unsafe fn discard_sub_lwe_ciphertext_vector_unchecked(
69 &mut self,
70 output: &mut OutputCiphertextVector,
71 input_1: &InputCiphertextVector,
72 input_2: &InputCiphertextVector,
73 );
74}