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