concrete_core/specification/engines/
lwe_ciphertext_decryption.rs

1use super::engine_error;
2
3use crate::specification::engines::AbstractEngine;
4use crate::specification::entities::{LweCiphertextEntity, LweSecretKeyEntity, PlaintextEntity};
5
6engine_error! {
7    LweCiphertextDecryptionError for LweCiphertextDecryptionEngine @
8}
9
10/// A trait for engines decrypting LWE ciphertexts.
11///
12/// # Semantics
13///
14/// This [pure](super#operation-semantics) operation generates an plaintext containing the
15/// decryption of the `input` LWE ciphertext, under the `key` secret key.
16///
17/// # Formal Definition
18pub trait LweCiphertextDecryptionEngine<SecretKey, Ciphertext, Plaintext>: AbstractEngine
19where
20    SecretKey: LweSecretKeyEntity,
21    Ciphertext: LweCiphertextEntity<KeyDistribution = SecretKey::KeyDistribution>,
22    Plaintext: PlaintextEntity,
23{
24    /// Decrypts an LWE ciphertext.
25    fn decrypt_lwe_ciphertext(
26        &mut self,
27        key: &SecretKey,
28        input: &Ciphertext,
29    ) -> Result<Plaintext, LweCiphertextDecryptionError<Self::EngineError>>;
30
31    /// Unsafely decrypts an LWE ciphertext.
32    ///
33    /// # Safety
34    /// For the _general_ safety concerns regarding this operation, refer to the different variants
35    /// of [`LweCiphertextDecryptionError`]. For safety concerns _specific_ to an
36    /// engine, refer to the implementer safety section.
37    unsafe fn decrypt_lwe_ciphertext_unchecked(
38        &mut self,
39        key: &SecretKey,
40        input: &Ciphertext,
41    ) -> Plaintext;
42}