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