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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use super::engine_error;
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::{
GlweCiphertextEntity, GlweSecretKeyEntity, PlaintextVectorEntity,
};
engine_error! {
GlweCiphertextDecryptionError for GlweCiphertextDecryptionEngine @
GlweDimensionMismatch => "The ciphertext and secret key GLWE dimension must be the same.",
PolynomialSizeMismatch => "The ciphertext and secret key polynomial size must be the same."
}
impl<EngineError: std::error::Error> GlweCiphertextDecryptionError<EngineError> {
pub fn perform_generic_checks<SecretKey, Ciphertext>(
key: &SecretKey,
input: &Ciphertext,
) -> Result<(), Self>
where
SecretKey: GlweSecretKeyEntity,
Ciphertext: GlweCiphertextEntity,
{
if input.glwe_dimension() != key.glwe_dimension() {
return Err(Self::GlweDimensionMismatch);
}
if input.polynomial_size() != key.polynomial_size() {
return Err(Self::PolynomialSizeMismatch);
}
Ok(())
}
}
pub trait GlweCiphertextDecryptionEngine<SecretKey, Ciphertext, PlaintextVector>:
AbstractEngine
where
SecretKey: GlweSecretKeyEntity,
Ciphertext: GlweCiphertextEntity,
PlaintextVector: PlaintextVectorEntity,
{
fn decrypt_glwe_ciphertext(
&mut self,
key: &SecretKey,
input: &Ciphertext,
) -> Result<PlaintextVector, GlweCiphertextDecryptionError<Self::EngineError>>;
unsafe fn decrypt_glwe_ciphertext_unchecked(
&mut self,
key: &SecretKey,
input: &Ciphertext,
) -> PlaintextVector;
}