use super::engine_error;
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::{
GlweCiphertextEntity, GlweSecretKeyEntity, PlaintextVectorEntity,
};
engine_error! {
GlweCiphertextDiscardingDecryptionError for GlweCiphertextDiscardingDecryptionEngine @
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 output plaintext vector and the input ciphertext \
polynomial size must be the same."
}
impl<EngineError: std::error::Error> GlweCiphertextDiscardingDecryptionError<EngineError> {
pub fn perform_generic_checks<SecretKey, Ciphertext, PlaintextVector>(
key: &SecretKey,
output: &PlaintextVector,
input: &Ciphertext,
) -> Result<(), Self>
where
SecretKey: GlweSecretKeyEntity,
Ciphertext: GlweCiphertextEntity,
PlaintextVector: PlaintextVectorEntity,
{
if key.polynomial_size() != input.polynomial_size() {
return Err(Self::PolynomialSizeMismatch);
}
if key.glwe_dimension() != input.glwe_dimension() {
return Err(Self::GlweDimensionMismatch);
}
if input.polynomial_size().0 != output.plaintext_count().0 {
return Err(Self::PlaintextCountMismatch);
}
Ok(())
}
}
pub trait GlweCiphertextDiscardingDecryptionEngine<SecretKey, Ciphertext, PlaintextVector>:
AbstractEngine
where
SecretKey: GlweSecretKeyEntity,
Ciphertext: GlweCiphertextEntity,
PlaintextVector: PlaintextVectorEntity,
{
fn discard_decrypt_glwe_ciphertext(
&mut self,
key: &SecretKey,
output: &mut PlaintextVector,
input: &Ciphertext,
) -> Result<(), GlweCiphertextDiscardingDecryptionError<Self::EngineError>>;
unsafe fn discard_decrypt_glwe_ciphertext_unchecked(
&mut self,
key: &SecretKey,
output: &mut PlaintextVector,
input: &Ciphertext,
);
}