dcrypt_sign/falcon/
mod.rs

1// File: dcrypt-sign/src/falcon/mod.rs
2
3use dcrypt_api::{Error, Result, Signature as SignatureTrait};
4use rand::{CryptoRng, RngCore};
5use zeroize::Zeroize;
6
7/// Falcon-512 signature scheme
8pub struct Falcon512;
9
10#[derive(Clone, Zeroize)]
11pub struct FalconPublicKey(pub Vec<u8>);
12
13#[derive(Clone, Zeroize)]
14pub struct FalconSecretKey(pub Vec<u8>);
15
16#[derive(Clone)]
17pub struct FalconSignature(pub Vec<u8>);
18
19impl AsRef<[u8]> for FalconPublicKey {
20    fn as_ref(&self) -> &[u8] {
21        &self.0
22    }
23}
24
25impl AsMut<[u8]> for FalconPublicKey {
26    fn as_mut(&mut self) -> &mut [u8] {
27        &mut self.0
28    }
29}
30
31impl AsRef<[u8]> for FalconSecretKey {
32    fn as_ref(&self) -> &[u8] {
33        &self.0
34    }
35}
36
37impl AsMut<[u8]> for FalconSecretKey {
38    fn as_mut(&mut self) -> &mut [u8] {
39        &mut self.0
40    }
41}
42
43impl AsRef<[u8]> for FalconSignature {
44    fn as_ref(&self) -> &[u8] {
45        &self.0
46    }
47}
48
49impl AsMut<[u8]> for FalconSignature {
50    fn as_mut(&mut self) -> &mut [u8] {
51        &mut self.0
52    }
53}
54
55impl SignatureTrait for Falcon512 {
56    type PublicKey = FalconPublicKey;
57    type SecretKey = FalconSecretKey;
58    type SignatureData = FalconSignature;
59    type KeyPair = (Self::PublicKey, Self::SecretKey);
60
61    fn name() -> &'static str {
62        "Falcon-512"
63    }
64
65    fn keypair<R: CryptoRng + RngCore>(_rng: &mut R) -> Result<Self::KeyPair> {
66        Err(Error::NotImplemented {
67            feature: "Falcon-512 key generation",
68        })
69    }
70
71    fn public_key(keypair: &Self::KeyPair) -> Self::PublicKey {
72        keypair.0.clone()
73    }
74
75    fn secret_key(keypair: &Self::KeyPair) -> Self::SecretKey {
76        keypair.1.clone()
77    }
78
79    fn sign(_message: &[u8], _secret_key: &Self::SecretKey) -> Result<Self::SignatureData> {
80        Err(Error::NotImplemented {
81            feature: "Falcon-512 signing",
82        })
83    }
84
85    fn verify(
86        _message: &[u8],
87        _signature: &Self::SignatureData,
88        _public_key: &Self::PublicKey,
89    ) -> Result<()> {
90        Err(Error::NotImplemented {
91            feature: "Falcon-512 verification",
92        })
93    }
94}
95
96/// Falcon-1024 signature scheme
97pub struct Falcon1024;
98
99impl SignatureTrait for Falcon1024 {
100    type PublicKey = FalconPublicKey;
101    type SecretKey = FalconSecretKey;
102    type SignatureData = FalconSignature;
103    type KeyPair = (Self::PublicKey, Self::SecretKey);
104
105    fn name() -> &'static str {
106        "Falcon-1024"
107    }
108
109    fn keypair<R: CryptoRng + RngCore>(_rng: &mut R) -> Result<Self::KeyPair> {
110        Err(Error::NotImplemented {
111            feature: "Falcon-1024 key generation",
112        })
113    }
114
115    fn public_key(keypair: &Self::KeyPair) -> Self::PublicKey {
116        keypair.0.clone()
117    }
118
119    fn secret_key(keypair: &Self::KeyPair) -> Self::SecretKey {
120        keypair.1.clone()
121    }
122
123    fn sign(_message: &[u8], _secret_key: &Self::SecretKey) -> Result<Self::SignatureData> {
124        Err(Error::NotImplemented {
125            feature: "Falcon-1024 signing",
126        })
127    }
128
129    fn verify(
130        _message: &[u8],
131        _signature: &Self::SignatureData,
132        _public_key: &Self::PublicKey,
133    ) -> Result<()> {
134        Err(Error::NotImplemented {
135            feature: "Falcon-1024 verification",
136        })
137    }
138}