use super::engine_error;
use crate::prelude::Variance;
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::{
GlweCiphertextEntity, GlweSecretKeyEntity, PlaintextVectorEntity,
};
engine_error! {
GlweCiphertextDiscardingEncryptionError for GlweCiphertextDiscardingEncryptionEngine @
GlweDimensionMismatch => "The GLWE dimension of the key and ciphertext must be the same.",
PolynomialSizeMismatch => "The polynomial size of the key and ciphertext must be the same.",
PlaintextCountMismatch => "The size of the input plaintext vector and the output ciphertext \
polynomial size must be the same."
}
impl<EngineError: std::error::Error> GlweCiphertextDiscardingEncryptionError<EngineError> {
pub fn perform_generic_checks<SecretKey, PlaintextVector, Ciphertext>(
key: &SecretKey,
output: &Ciphertext,
input: &PlaintextVector,
) -> Result<(), Self>
where
SecretKey: GlweSecretKeyEntity,
PlaintextVector: PlaintextVectorEntity,
Ciphertext: GlweCiphertextEntity,
{
if key.polynomial_size() != output.polynomial_size() {
return Err(Self::PolynomialSizeMismatch);
}
if key.glwe_dimension() != output.glwe_dimension() {
return Err(Self::GlweDimensionMismatch);
}
if key.polynomial_size().0 != input.plaintext_count().0 {
return Err(Self::PlaintextCountMismatch);
}
Ok(())
}
}
pub trait GlweCiphertextDiscardingEncryptionEngine<SecretKey, PlaintextVector, Ciphertext>:
AbstractEngine
where
SecretKey: GlweSecretKeyEntity,
PlaintextVector: PlaintextVectorEntity,
Ciphertext: GlweCiphertextEntity,
{
fn discard_encrypt_glwe_ciphertext(
&mut self,
key: &SecretKey,
output: &mut Ciphertext,
input: &PlaintextVector,
noise: Variance,
) -> Result<(), GlweCiphertextDiscardingEncryptionError<Self::EngineError>>;
unsafe fn discard_encrypt_glwe_ciphertext_unchecked(
&mut self,
key: &SecretKey,
output: &mut Ciphertext,
input: &PlaintextVector,
noise: Variance,
);
}