one_time_signatures_cry4/
lib.rs1use sha2::Digest;
2use std::any::Any;
3
4pub mod lamport;
5pub mod winternitz;
6
7pub use lamport::{LamportPublicKey, LamportSecretKey};
8pub use winternitz::{WinternitzSecretKey, WinternitzPublicKey};
9
10#[derive(Copy, Clone)]
11pub enum OneTimeScheme {
12 Lamport,
13 Winternitz(usize),
14}
15
16pub trait OneTimeSignature: OneTimeSignatureToAny {}
17
18pub trait OneTimeSignatureToAny: 'static {
19 fn as_any(&self) -> &dyn Any;
20}
21
22impl<T: 'static> OneTimeSignatureToAny for T {
23 fn as_any(&self) -> &dyn Any {
24 self
25 }
26}
27
28pub trait OneTimeSecretKey<D> {
29 fn sign(&mut self, m: &[u8]) -> Result<Box<dyn OneTimeSignature>, String>;
30 fn sign_arbitrary(&mut self, m: &[u8]) -> Result<Box<dyn OneTimeSignature>, String>;
31}
32pub trait OneTimePublicKey<D> : OneTimePublicKeyClone<D> {
33 fn verify(&self, m: &[u8], sig: &Box<dyn OneTimeSignature>) -> Result<(), String>;
34 fn verify_arbitrary(&self, m: &[u8], sig: &Box<dyn OneTimeSignature>) -> Result<(), String>;
35 fn to_bytes(&self) -> Vec<u8>;
36}
37
38pub trait OneTimePublicKeyClone<D> {
39 fn clone_box(&self) -> Box<dyn OneTimePublicKey<D>>;
40}
41
42impl<D, T> OneTimePublicKeyClone<D> for T
43where
44 D: Digest,
45 T: 'static + OneTimePublicKey<D> + Clone,
46{
47 fn clone_box(&self) -> Box<dyn OneTimePublicKey<D>> {
48 Box::new(self.clone())
49 }
50}
51
52impl<D: Digest> Clone for Box<dyn OneTimePublicKey<D>> {
53 fn clone(&self) -> Box<dyn OneTimePublicKey<D>> {
54 self.clone_box()
55 }
56}