use crate::prelude::{LwePublicKeyZeroEncryptionCount, Variance};
use crate::specification::engines::AbstractEngine;
use crate::specification::entities::{LwePublicKeyEntity, LweSecretKeyEntity};
engine_error! {
LwePublicKeyGenerationError for LwePublicKeyGenerationEngine @
NullPublicKeyZeroEncryptionCount => "The number of LWE encryptions of zero in the LWE public \
key must be greater than zero."
}
impl<EngineError: std::error::Error> LwePublicKeyGenerationError<EngineError> {
pub fn perform_generic_checks(
lwe_public_key_zero_encryption_count: LwePublicKeyZeroEncryptionCount,
) -> Result<(), Self> {
if lwe_public_key_zero_encryption_count.0 == 0 {
return Err(Self::NullPublicKeyZeroEncryptionCount);
}
Ok(())
}
}
pub trait LwePublicKeyGenerationEngine<SecretKey, PublicKey>: AbstractEngine
where
SecretKey: LweSecretKeyEntity,
PublicKey: LwePublicKeyEntity,
{
fn generate_new_lwe_public_key(
&mut self,
lwe_secret_key: &SecretKey,
noise: Variance,
lwe_public_key_zero_encryption_count: LwePublicKeyZeroEncryptionCount,
) -> Result<PublicKey, LwePublicKeyGenerationError<Self::EngineError>>;
unsafe fn generate_new_lwe_public_key_unchecked(
&mut self,
lwe_secret_key: &SecretKey,
noise: Variance,
lwe_public_key_zero_encryption_count: LwePublicKeyZeroEncryptionCount,
) -> PublicKey;
}