concrete_core/specification/engines/
glwe_ciphertext_encryption.rs1use super::engine_error;
2use crate::specification::engines::AbstractEngine;
3use crate::specification::entities::{
4 GlweCiphertextEntity, GlweSecretKeyEntity, PlaintextVectorEntity,
5};
6use concrete_commons::dispersion::Variance;
7
8engine_error! {
9 GlweCiphertextEncryptionError for GlweCiphertextEncryptionEngine @
10 PlaintextCountMismatch => "The plaintext count of the input vector and the key polynomial size \
11 must be the same."
12}
13
14impl<EngineError: std::error::Error> GlweCiphertextEncryptionError<EngineError> {
15 pub fn perform_generic_checks<SecretKey, PlaintextVector>(
17 key: &SecretKey,
18 input: &PlaintextVector,
19 ) -> Result<(), Self>
20 where
21 SecretKey: GlweSecretKeyEntity,
22 PlaintextVector: PlaintextVectorEntity,
23 {
24 if key.polynomial_size().0 != input.plaintext_count().0 {
25 return Err(Self::PlaintextCountMismatch);
26 }
27 Ok(())
28 }
29}
30
31pub trait GlweCiphertextEncryptionEngine<SecretKey, PlaintextVector, Ciphertext>:
40 AbstractEngine
41where
42 SecretKey: GlweSecretKeyEntity,
43 PlaintextVector: PlaintextVectorEntity,
44 Ciphertext: GlweCiphertextEntity<KeyDistribution = SecretKey::KeyDistribution>,
45{
46 fn encrypt_glwe_ciphertext(
48 &mut self,
49 key: &SecretKey,
50 input: &PlaintextVector,
51 noise: Variance,
52 ) -> Result<Ciphertext, GlweCiphertextEncryptionError<Self::EngineError>>;
53
54 unsafe fn encrypt_glwe_ciphertext_unchecked(
61 &mut self,
62 key: &SecretKey,
63 input: &PlaintextVector,
64 noise: Variance,
65 ) -> Ciphertext;
66}