use super::engine_error;
use crate::prelude::{DecompositionBaseLog, DecompositionLevelCount, Variance};
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::{
GlweSecretKeyEntity, LweBootstrapKeyEntity, LweSecretKeyEntity,
};
engine_error! {
LweBootstrapKeyGenerationError for LweBootstrapKeyGenerationEngine @
NullDecompositionBaseLog => "The key decomposition base log must be greater than zero.",
NullDecompositionLevelCount => "The key decomposition level count must be greater than zero.",
DecompositionTooLarge => "The decomposition precision (base log * level count) must not exceed \
the precision of the ciphertext."
}
impl<EngineError: std::error::Error> LweBootstrapKeyGenerationError<EngineError> {
pub fn perform_generic_checks(
decomposition_base_log: DecompositionBaseLog,
decomposition_level_count: DecompositionLevelCount,
ciphertext_modulus_log: usize,
) -> Result<(), Self> {
if decomposition_base_log.0 == 0 {
return Err(Self::NullDecompositionBaseLog);
}
if decomposition_level_count.0 == 0 {
return Err(Self::NullDecompositionLevelCount);
}
if decomposition_base_log.0 * decomposition_level_count.0 > ciphertext_modulus_log {
return Err(Self::DecompositionTooLarge);
}
Ok(())
}
}
pub trait LweBootstrapKeyGenerationEngine<LweSecretKey, GlweSecretKey, BootstrapKey>:
AbstractEngine
where
BootstrapKey: LweBootstrapKeyEntity,
LweSecretKey: LweSecretKeyEntity,
GlweSecretKey: GlweSecretKeyEntity,
{
fn generate_new_lwe_bootstrap_key(
&mut self,
input_key: &LweSecretKey,
output_key: &GlweSecretKey,
decomposition_base_log: DecompositionBaseLog,
decomposition_level_count: DecompositionLevelCount,
noise: Variance,
) -> Result<BootstrapKey, LweBootstrapKeyGenerationError<Self::EngineError>>;
unsafe fn generate_new_lwe_bootstrap_key_unchecked(
&mut self,
input_key: &LweSecretKey,
output_key: &GlweSecretKey,
decomposition_base_log: DecompositionBaseLog,
decomposition_level_count: DecompositionLevelCount,
noise: Variance,
) -> BootstrapKey;
}