concrete_core/specification/engines/
glwe_ciphertext_discarding_decryption.rs1use super::engine_error;
2use crate::specification::engines::AbstractEngine;
3use crate::specification::entities::{
4 GlweCiphertextEntity, GlweSecretKeyEntity, PlaintextVectorEntity,
5};
6
7engine_error! {
8 GlweCiphertextDiscardingDecryptionError for GlweCiphertextDiscardingDecryptionEngine @
9 GlweDimensionMismatch => "The GLWE dimension of the key and ciphertext must be the same.",
10 PolynomialSizeMismatch => "The polynomial size of the key and ciphertext must be the same.",
11 PlaintextCountMismatch => "The size of the output plaintext vector and the input ciphertext \
12 polynomial size must be the same."
13}
14
15impl<EngineError: std::error::Error> GlweCiphertextDiscardingDecryptionError<EngineError> {
16 pub fn perform_generic_checks<SecretKey, Ciphertext, PlaintextVector>(
18 key: &SecretKey,
19 output: &PlaintextVector,
20 input: &Ciphertext,
21 ) -> Result<(), Self>
22 where
23 SecretKey: GlweSecretKeyEntity,
24 Ciphertext: GlweCiphertextEntity,
25 PlaintextVector: PlaintextVectorEntity,
26 {
27 if key.polynomial_size() != input.polynomial_size() {
28 return Err(Self::PolynomialSizeMismatch);
29 }
30 if key.glwe_dimension() != input.glwe_dimension() {
31 return Err(Self::GlweDimensionMismatch);
32 }
33 if input.polynomial_size().0 != output.plaintext_count().0 {
34 return Err(Self::PlaintextCountMismatch);
35 }
36 Ok(())
37 }
38}
39
40pub trait GlweCiphertextDiscardingDecryptionEngine<SecretKey, Ciphertext, PlaintextVector>:
51 AbstractEngine
52where
53 SecretKey: GlweSecretKeyEntity,
54 Ciphertext: GlweCiphertextEntity,
55 PlaintextVector: PlaintextVectorEntity,
56{
57 fn discard_decrypt_glwe_ciphertext(
59 &mut self,
60 key: &SecretKey,
61 output: &mut PlaintextVector,
62 input: &Ciphertext,
63 ) -> Result<(), GlweCiphertextDiscardingDecryptionError<Self::EngineError>>;
64
65 unsafe fn discard_decrypt_glwe_ciphertext_unchecked(
72 &mut self,
73 key: &SecretKey,
74 output: &mut PlaintextVector,
75 input: &Ciphertext,
76 );
77}