1use crate::edwards::PointTable;
2use crate::input::{PUBLIC_KEY_LEN, VerifyInput};
3use crate::verifier::{VerificationPolicy, Verifier};
4use crate::wide::avx512ifma;
5
6pub(crate) mod private {
7 pub trait Sealed {}
9}
10
11#[derive(Clone, Debug)]
16pub struct CachedPublicKey {
17 pub(crate) encoded: [u8; PUBLIC_KEY_LEN],
18 pub(crate) table: PointTable,
19}
20
21impl CachedPublicKey {
22 pub fn from_encoded(encoded: [u8; PUBLIC_KEY_LEN]) -> Option<Self> {
24 avx512ifma::decode_public_key_table(&encoded).map(|table| Self { encoded, table })
25 }
26}
27
28pub trait KeyCache: private::Sealed {
34 #[doc(hidden)]
36 type Queues<P: VerificationPolicy>: core::fmt::Debug + Default;
37
38 fn get(&self, encoded: &[u8; PUBLIC_KEY_LEN]) -> Option<&CachedPublicKey>;
41
42 fn insert(&mut self, _key: CachedPublicKey) {}
45
46 #[doc(hidden)]
48 fn dispatch_verify_batch<P: VerificationPolicy>(
49 verifier: &mut Verifier<P, Self>,
50 inputs: &[VerifyInput<'_>],
51 out: &mut [bool],
52 ) where
53 Self: Sized;
54}
55
56#[doc(hidden)]
58#[derive(Debug, Default)]
59pub struct NoQueues;
60
61#[derive(Clone, Copy, Debug, Default)]
63pub struct NullKeyCache;
64
65impl NullKeyCache {
66 pub fn new() -> Self {
68 Self
69 }
70}
71
72impl private::Sealed for NullKeyCache {}
73
74impl KeyCache for NullKeyCache {
75 type Queues<P: VerificationPolicy> = NoQueues;
76
77 #[inline]
78 fn get(&self, _encoded: &[u8; PUBLIC_KEY_LEN]) -> Option<&CachedPublicKey> {
79 None
80 }
81
82 #[inline]
83 fn dispatch_verify_batch<P: VerificationPolicy>(
84 verifier: &mut Verifier<P, Self>,
85 inputs: &[VerifyInput<'_>],
86 out: &mut [bool],
87 ) {
88 P::dispatch_uncached_verify_batch(verifier, inputs, out);
89 }
90}