concrete_core/specification/engines/
glwe_ciphertext_decryption.rs1use super::engine_error;
2use crate::specification::engines::AbstractEngine;
3use crate::specification::entities::{
4 GlweCiphertextEntity, GlweSecretKeyEntity, PlaintextVectorEntity,
5};
6
7engine_error! {
8 GlweCiphertextDecryptionError for GlweCiphertextDecryptionEngine @
9 GlweDimensionMismatch => "The ciphertext and secret key GLWE dimension must be the same.",
10 PolynomialSizeMismatch => "The ciphertext and secret key polynomial size must be the same."
11}
12
13impl<EngineError: std::error::Error> GlweCiphertextDecryptionError<EngineError> {
14 pub fn perform_generic_checks<SecretKey, Ciphertext>(
16 key: &SecretKey,
17 input: &Ciphertext,
18 ) -> Result<(), Self>
19 where
20 SecretKey: GlweSecretKeyEntity,
21 Ciphertext: GlweCiphertextEntity<KeyDistribution = SecretKey::KeyDistribution>,
22 {
23 if input.glwe_dimension() != key.glwe_dimension() {
24 return Err(Self::GlweDimensionMismatch);
25 }
26 if input.polynomial_size() != key.polynomial_size() {
27 return Err(Self::PolynomialSizeMismatch);
28 }
29 Ok(())
30 }
31}
32
33pub trait GlweCiphertextDecryptionEngine<SecretKey, Ciphertext, PlaintextVector>:
42 AbstractEngine
43where
44 SecretKey: GlweSecretKeyEntity,
45 Ciphertext: GlweCiphertextEntity<KeyDistribution = SecretKey::KeyDistribution>,
46 PlaintextVector: PlaintextVectorEntity,
47{
48 fn decrypt_glwe_ciphertext(
50 &mut self,
51 key: &SecretKey,
52 input: &Ciphertext,
53 ) -> Result<PlaintextVector, GlweCiphertextDecryptionError<Self::EngineError>>;
54
55 unsafe fn decrypt_glwe_ciphertext_unchecked(
62 &mut self,
63 key: &SecretKey,
64 input: &Ciphertext,
65 ) -> PlaintextVector;
66}