use crate::edwards::PointTable;
use crate::input::{PUBLIC_KEY_LEN, VerifyInput};
use crate::verifier::{VerificationPolicy, Verifier};
use crate::wide::avx512ifma;
pub(crate) mod private {
pub trait Sealed {}
}
#[derive(Clone, Debug)]
pub struct CachedPublicKey {
pub(crate) encoded: [u8; PUBLIC_KEY_LEN],
pub(crate) table: PointTable,
}
impl CachedPublicKey {
pub fn from_encoded(encoded: [u8; PUBLIC_KEY_LEN]) -> Option<Self> {
avx512ifma::decode_public_key_table(&encoded).map(|table| Self { encoded, table })
}
}
pub trait KeyCache: private::Sealed {
#[doc(hidden)]
type Queues<P: VerificationPolicy>: core::fmt::Debug + Default;
fn get(&self, encoded: &[u8; PUBLIC_KEY_LEN]) -> Option<&CachedPublicKey>;
fn insert(&mut self, _key: CachedPublicKey) {}
#[doc(hidden)]
fn dispatch_verify_batch<P: VerificationPolicy>(
verifier: &mut Verifier<P, Self>,
inputs: &[VerifyInput<'_>],
out: &mut [bool],
) where
Self: Sized;
}
#[doc(hidden)]
#[derive(Debug, Default)]
pub struct NoQueues;
#[derive(Clone, Copy, Debug, Default)]
pub struct NullKeyCache;
impl NullKeyCache {
pub fn new() -> Self {
Self
}
}
impl private::Sealed for NullKeyCache {}
impl KeyCache for NullKeyCache {
type Queues<P: VerificationPolicy> = NoQueues;
#[inline]
fn get(&self, _encoded: &[u8; PUBLIC_KEY_LEN]) -> Option<&CachedPublicKey> {
None
}
#[inline]
fn dispatch_verify_batch<P: VerificationPolicy>(
verifier: &mut Verifier<P, Self>,
inputs: &[VerifyInput<'_>],
out: &mut [bool],
) {
P::dispatch_uncached_verify_batch(verifier, inputs, out);
}
}