dcrypt_sign/rainbow/
mod.rs1use dcrypt_api::{Error, Result, Signature as SignatureTrait};
4use rand::{CryptoRng, RngCore};
5use zeroize::Zeroize;
6
7pub struct RainbowI;
9
10#[derive(Clone, Zeroize)]
11pub struct RainbowPublicKey(pub Vec<u8>);
12
13#[derive(Clone, Zeroize)]
14pub struct RainbowSecretKey(pub Vec<u8>);
15
16#[derive(Clone)]
17pub struct RainbowSignature(pub Vec<u8>);
18
19impl AsRef<[u8]> for RainbowPublicKey {
20 fn as_ref(&self) -> &[u8] {
21 &self.0
22 }
23}
24
25impl AsMut<[u8]> for RainbowPublicKey {
26 fn as_mut(&mut self) -> &mut [u8] {
27 &mut self.0
28 }
29}
30
31impl AsRef<[u8]> for RainbowSecretKey {
32 fn as_ref(&self) -> &[u8] {
33 &self.0
34 }
35}
36
37impl AsMut<[u8]> for RainbowSecretKey {
38 fn as_mut(&mut self) -> &mut [u8] {
39 &mut self.0
40 }
41}
42
43impl AsRef<[u8]> for RainbowSignature {
44 fn as_ref(&self) -> &[u8] {
45 &self.0
46 }
47}
48
49impl AsMut<[u8]> for RainbowSignature {
50 fn as_mut(&mut self) -> &mut [u8] {
51 &mut self.0
52 }
53}
54
55impl SignatureTrait for RainbowI {
56 type PublicKey = RainbowPublicKey;
57 type SecretKey = RainbowSecretKey;
58 type SignatureData = RainbowSignature;
59 type KeyPair = (Self::PublicKey, Self::SecretKey);
60
61 fn name() -> &'static str {
62 "Rainbow-I"
63 }
64
65 fn keypair<R: CryptoRng + RngCore>(_rng: &mut R) -> Result<Self::KeyPair> {
66 Err(Error::NotImplemented {
67 feature: "Rainbow-I 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: "Rainbow-I 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: "Rainbow-I verification",
92 })
93 }
94}
95
96pub struct RainbowIII;
98
99impl SignatureTrait for RainbowIII {
100 type PublicKey = RainbowPublicKey;
101 type SecretKey = RainbowSecretKey;
102 type SignatureData = RainbowSignature;
103 type KeyPair = (Self::PublicKey, Self::SecretKey);
104
105 fn name() -> &'static str {
106 "Rainbow-III"
107 }
108
109 fn keypair<R: CryptoRng + RngCore>(_rng: &mut R) -> Result<Self::KeyPair> {
110 Err(Error::NotImplemented {
111 feature: "Rainbow-III 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: "Rainbow-III 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: "Rainbow-III verification",
136 })
137 }
138}
139
140pub struct RainbowV;
142
143impl SignatureTrait for RainbowV {
144 type PublicKey = RainbowPublicKey;
145 type SecretKey = RainbowSecretKey;
146 type SignatureData = RainbowSignature;
147 type KeyPair = (Self::PublicKey, Self::SecretKey);
148
149 fn name() -> &'static str {
150 "Rainbow-V"
151 }
152
153 fn keypair<R: CryptoRng + RngCore>(_rng: &mut R) -> Result<Self::KeyPair> {
154 Err(Error::NotImplemented {
155 feature: "Rainbow-V key generation",
156 })
157 }
158
159 fn public_key(keypair: &Self::KeyPair) -> Self::PublicKey {
160 keypair.0.clone()
161 }
162
163 fn secret_key(keypair: &Self::KeyPair) -> Self::SecretKey {
164 keypair.1.clone()
165 }
166
167 fn sign(_message: &[u8], _secret_key: &Self::SecretKey) -> Result<Self::SignatureData> {
168 Err(Error::NotImplemented {
169 feature: "Rainbow-V signing",
170 })
171 }
172
173 fn verify(
174 _message: &[u8],
175 _signature: &Self::SignatureData,
176 _public_key: &Self::PublicKey,
177 ) -> Result<()> {
178 Err(Error::NotImplemented {
179 feature: "Rainbow-V verification",
180 })
181 }
182}