use super::engine_error;
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::{LweCiphertextEntity, LweSecretKeyEntity, PlaintextEntity};
engine_error! {
LweCiphertextDiscardingDecryptionError for LweCiphertextDiscardingDecryptionEngine @
LweDimensionMismatch => "The secret key and ciphertext LWE dimensions must be the same."
}
impl<EngineError: std::error::Error> LweCiphertextDiscardingDecryptionError<EngineError> {
pub fn perform_generic_checks<SecretKey, Ciphertext>(
key: &SecretKey,
input: &Ciphertext,
) -> Result<(), Self>
where
SecretKey: LweSecretKeyEntity,
Ciphertext: LweCiphertextEntity,
{
if key.lwe_dimension() != input.lwe_dimension() {
return Err(Self::LweDimensionMismatch);
}
Ok(())
}
}
pub trait LweCiphertextDiscardingDecryptionEngine<SecretKey, Ciphertext, Plaintext>:
AbstractEngine
where
SecretKey: LweSecretKeyEntity,
Ciphertext: LweCiphertextEntity,
Plaintext: PlaintextEntity,
{
fn discard_decrypt_lwe_ciphertext(
&mut self,
key: &SecretKey,
output: &mut Plaintext,
input: &Ciphertext,
) -> Result<(), LweCiphertextDiscardingDecryptionError<Self::EngineError>>;
unsafe fn discard_decrypt_lwe_ciphertext_unchecked(
&mut self,
key: &SecretKey,
output: &mut Plaintext,
input: &Ciphertext,
);
}