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
18///
19/// ## LWE Decryption
20/// ###### inputs:
21/// - $\mathsf{ct} = \left( \vec{a} , b\right) \in \mathsf{LWE}^n\_{\vec{s}}( \mathsf{pt} )\subseteq
22///   \mathbb{Z}\_q^{(n+1)}$: an LWE ciphertext
23/// - $\vec{s}\in\mathbb{Z}\_q^n$: a secret key
24///
25/// ###### outputs:
26/// - $\mathsf{pt}\in\mathbb{Z}\_q$: a plaintext
27///
28/// ###### algorithm:
29/// 1. compute $\mathsf{pt} = b - \left\langle \vec{a} , \vec{s} \right\rangle \in\mathbb{Z}\_q$
30/// 3. output $\mathsf{pt}$
31///
32/// **Remark:** Observe that the decryption is followed by a decoding phase that will contain a
33/// rounding.
34pub trait LweCiphertextDecryptionEngine<SecretKey, Ciphertext, Plaintext>: AbstractEngine
35where
36    SecretKey: LweSecretKeyEntity,
37    Ciphertext: LweCiphertextEntity,
38    Plaintext: PlaintextEntity,
39{
40    /// Decrypts an LWE ciphertext.
41    fn decrypt_lwe_ciphertext(
42        &mut self,
43        key: &SecretKey,
44        input: &Ciphertext,
45    ) -> Result<Plaintext, LweCiphertextDecryptionError<Self::EngineError>>;
46
47    /// Unsafely decrypts an LWE ciphertext.
48    ///
49    /// # Safety
50    /// For the _general_ safety concerns regarding this operation, refer to the different variants
51    /// of [`LweCiphertextDecryptionError`]. For safety concerns _specific_ to an
52    /// engine, refer to the implementer safety section.
53    unsafe fn decrypt_lwe_ciphertext_unchecked(
54        &mut self,
55        key: &SecretKey,
56        input: &Ciphertext,
57    ) -> Plaintext;
58}