use super::engine_error;
use crate::prelude::{LweDimension, MonomialIndex};
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::{GlweCiphertextEntity, LweCiphertextEntity};
engine_error! {
LweCiphertextDiscardingExtractionError for LweCiphertextDiscardingExtractionEngine @
SizeMismatch => "The sizes of the output LWE (LWE dimension) and the input GLWE (GLWE \
dimension * poly size) must be compatible.",
MonomialIndexTooLarge => "The monomial index must be smaller than the GLWE polynomial size."
}
impl<EngineError: std::error::Error> LweCiphertextDiscardingExtractionError<EngineError> {
pub fn perform_generic_checks<GlweCiphertext, LweCiphertext>(
output: &LweCiphertext,
input: &GlweCiphertext,
nth: MonomialIndex,
) -> Result<(), Self>
where
GlweCiphertext: GlweCiphertextEntity,
LweCiphertext: LweCiphertextEntity,
{
if output.lwe_dimension()
!= LweDimension(input.polynomial_size().0 * input.glwe_dimension().0)
{
return Err(Self::SizeMismatch);
}
if nth.0 >= input.polynomial_size().0 {
return Err(Self::MonomialIndexTooLarge);
}
Ok(())
}
}
pub trait LweCiphertextDiscardingExtractionEngine<GlweCiphertext, LweCiphertext>:
AbstractEngine
where
GlweCiphertext: GlweCiphertextEntity,
LweCiphertext: LweCiphertextEntity,
{
fn discard_extract_lwe_ciphertext(
&mut self,
output: &mut LweCiphertext,
input: &GlweCiphertext,
nth: MonomialIndex,
) -> Result<(), LweCiphertextDiscardingExtractionError<Self::EngineError>>;
unsafe fn discard_extract_lwe_ciphertext_unchecked(
&mut self,
output: &mut LweCiphertext,
input: &GlweCiphertext,
nth: MonomialIndex,
);
}