concrete_core/specification/engines/
lwe_ciphertext_encryption.rs

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