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
46
47
48
use super::engine_error;
use crate::prelude::{GlweSize, PlaintextVectorEntity};
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::GlweCiphertextEntity;
engine_error! {
GlweCiphertextTrivialEncryptionError for GlweCiphertextTrivialEncryptionEngine @
}
/// A trait for engines trivially encrypting GLWE ciphertext.
///
/// # Semantics
///
/// This [pure](super#operation-semantics) operation generates a GLWE ciphertext containing the
/// trivial encryption of the `input` plaintext vector with the requested `glwe_size`.
///
/// # Formal Definition
///
/// A trivial encryption uses a zero mask and no noise.
/// It is absolutely not secure, as the body contains a direct copy of the plaintext.
/// However, it is useful for some FHE algorithms taking public information as input. For
/// example, a trivial GLWE encryption of a public lookup table is used in the bootstrap.
pub trait GlweCiphertextTrivialEncryptionEngine<PlaintextVector, Ciphertext>:
AbstractEngine
where
PlaintextVector: PlaintextVectorEntity,
Ciphertext: GlweCiphertextEntity,
{
/// Trivially encrypts a plaintext vector into a GLWE ciphertext.
fn trivially_encrypt_glwe_ciphertext(
&mut self,
glwe_size: GlweSize,
input: &PlaintextVector,
) -> Result<Ciphertext, GlweCiphertextTrivialEncryptionError<Self::EngineError>>;
/// Unsafely creates the trivial GLWE encryption of the plaintext vector.
///
/// # Safety
/// For the _general_ safety concerns regarding this operation, refer to the different variants
/// of [`GlweCiphertextTrivialEncryptionError`]. For safety concerns _specific_ to an engine,
/// refer to the implementer safety section.
unsafe fn trivially_encrypt_glwe_ciphertext_unchecked(
&mut self,
glwe_size: GlweSize,
input: &PlaintextVector,
) -> Ciphertext;
}