rs_matter/crypto/backend/
dummy.rs1use rand_core::{CryptoRng, RngCore};
28
29use crate::crypto::{Crypto, CryptoSensitive, CryptoSensitiveRef};
30use crate::error::Error;
31
32#[derive(Copy, Clone, Debug)]
34#[cfg_attr(feature = "defmt", derive(defmt::Format))]
35pub struct DummyCrypto;
36
37impl Crypto for DummyCrypto {
38 type Rand<'a>
39 = DummyCrypto
40 where
41 Self: 'a;
42
43 type WeakRand<'a>
44 = DummyCrypto
45 where
46 Self: 'a;
47
48 type Hash<'a>
49 = DummyCrypto
50 where
51 Self: 'a;
52
53 type Hash1<'a>
54 = DummyCrypto
55 where
56 Self: 'a;
57
58 type Hmac<'a>
59 = DummyCrypto
60 where
61 Self: 'a;
62
63 type Kdf<'a>
64 = DummyCrypto
65 where
66 Self: 'a;
67
68 type PbKdf<'a>
69 = DummyCrypto
70 where
71 Self: 'a;
72
73 type Aead<'a>
74 = DummyCrypto
75 where
76 Self: 'a;
77
78 type PublicKey<'a>
79 = DummyCrypto
80 where
81 Self: 'a;
82
83 type SecretKey<'a>
84 = DummyCrypto
85 where
86 Self: 'a;
87
88 type SigningSecretKey<'a>
89 = DummyCrypto
90 where
91 Self: 'a;
92
93 type EcScalar<'a>
94 = DummyCrypto
95 where
96 Self: 'a;
97
98 type EcPoint<'a>
99 = DummyCrypto
100 where
101 Self: 'a;
102
103 fn rand(&self) -> Result<Self::Rand<'_>, Error> {
104 unimplemented!()
105 }
106
107 fn weak_rand(&self) -> Result<Self::WeakRand<'_>, Error> {
108 unimplemented!()
109 }
110
111 fn hash(&self) -> Result<Self::Hash<'_>, Error> {
112 unimplemented!()
113 }
114
115 fn hash1(&self) -> Result<Self::Hash<'_>, Error> {
116 unimplemented!()
117 }
118
119 fn hmac<const KEY_LEN: usize>(
120 &self,
121 _key: CryptoSensitiveRef<'_, KEY_LEN>,
122 ) -> Result<Self::Hmac<'_>, Error> {
123 unimplemented!()
124 }
125
126 fn kdf(&self) -> Result<Self::Kdf<'_>, Error> {
127 unimplemented!()
128 }
129
130 fn pbkdf(&self) -> Result<Self::PbKdf<'_>, Error> {
131 unimplemented!()
132 }
133
134 fn aead(&self) -> Result<Self::Aead<'_>, Error> {
135 unimplemented!()
136 }
137
138 fn pub_key(
139 &self,
140 _key: crate::crypto::CanonPkcPublicKeyRef<'_>,
141 ) -> Result<Self::PublicKey<'_>, Error> {
142 unimplemented!()
143 }
144
145 fn generate_secret_key(&self) -> Result<Self::SecretKey<'_>, Error> {
146 unimplemented!()
147 }
148
149 fn secret_key(
150 &self,
151 _key: crate::crypto::CanonPkcSecretKeyRef<'_>,
152 ) -> Result<Self::SecretKey<'_>, Error> {
153 unimplemented!()
154 }
155
156 fn singleton_singing_secret_key(&self) -> Result<Self::SigningSecretKey<'_>, Error> {
157 unimplemented!()
158 }
159
160 fn ec_scalar(
161 &self,
162 _scalar: crate::crypto::CanonEcScalarRef<'_>,
163 ) -> Result<Self::EcScalar<'_>, Error> {
164 unimplemented!()
165 }
166
167 fn ec_scalar_mod_p(
168 &self,
169 _uint: crate::crypto::CanonUint320Ref<'_>,
170 ) -> Result<Self::EcScalar<'_>, Error> {
171 unimplemented!()
172 }
173
174 fn generate_ec_scalar(&self) -> Result<Self::EcScalar<'_>, Error> {
175 unimplemented!()
176 }
177
178 fn ec_point(
179 &self,
180 _point: crate::crypto::CanonEcPointRef<'_>,
181 ) -> Result<Self::EcPoint<'_>, Error> {
182 unimplemented!()
183 }
184
185 fn ec_generator_point(&self) -> Result<Self::EcPoint<'_>, Error> {
186 unimplemented!()
187 }
188}
189
190impl<const HASH_LEN: usize> crate::crypto::Digest<HASH_LEN> for DummyCrypto {
191 fn update(&mut self, _data: &[u8]) -> Result<(), Error> {
192 unimplemented!()
193 }
194
195 fn finish_current(&mut self, _out: &mut CryptoSensitive<HASH_LEN>) -> Result<(), Error> {
196 unimplemented!()
197 }
198
199 fn finish(self, _out: &mut CryptoSensitive<HASH_LEN>) -> Result<(), Error> {
200 unimplemented!()
201 }
202}
203
204impl crate::crypto::Kdf for DummyCrypto {
205 fn expand<const IKM_LEN: usize, const KEY_LEN: usize>(
206 self,
207 _salt: &[u8],
208 _ikm: CryptoSensitiveRef<'_, IKM_LEN>,
209 _info: &[u8],
210 _key: &mut CryptoSensitive<KEY_LEN>,
211 ) -> Result<(), Error> {
212 unimplemented!()
213 }
214}
215
216impl crate::crypto::PbKdf for DummyCrypto {
217 fn derive<const PASS_LEN: usize, const KEY_LEN: usize>(
218 self,
219 _password: CryptoSensitiveRef<'_, PASS_LEN>,
220 _iter: usize,
221 _salt: &[u8],
222 _out: &mut CryptoSensitive<KEY_LEN>,
223 ) -> Result<(), Error> {
224 unimplemented!()
225 }
226}
227
228impl<const KEY_LEN: usize, const NONCE_LEN: usize> crate::crypto::Aead<KEY_LEN, NONCE_LEN>
229 for DummyCrypto
230{
231 fn encrypt_in_place<'a>(
232 &mut self,
233 _key: CryptoSensitiveRef<'_, KEY_LEN>,
234 _nonce: CryptoSensitiveRef<'_, NONCE_LEN>,
235 _aad: &[u8],
236 _data: &'a mut [u8],
237 _data_len: usize,
238 ) -> Result<&'a [u8], Error> {
239 unimplemented!()
240 }
241
242 fn decrypt_in_place<'a>(
243 &mut self,
244 _key: CryptoSensitiveRef<'_, KEY_LEN>,
245 _nonce: CryptoSensitiveRef<'_, NONCE_LEN>,
246 _aad: &[u8],
247 _data: &'a mut [u8],
248 ) -> Result<&'a [u8], Error> {
249 unimplemented!()
250 }
251}
252
253impl<const KEY_LEN: usize, const SIGNATURE_LEN: usize>
254 crate::crypto::PublicKey<'_, KEY_LEN, SIGNATURE_LEN> for DummyCrypto
255{
256 fn verify(
257 &self,
258 _msg: &[u8],
259 _signature: CryptoSensitiveRef<SIGNATURE_LEN>,
260 ) -> Result<bool, Error> {
261 unimplemented!()
262 }
263
264 fn write_canon(&self, _key: &mut CryptoSensitive<KEY_LEN>) -> Result<(), Error> {
265 unimplemented!()
266 }
267}
268
269impl<const PUB_KEY_LEN: usize, const SIGNATURE_LEN: usize>
270 crate::crypto::SigningSecretKey<'_, PUB_KEY_LEN, SIGNATURE_LEN> for DummyCrypto
271{
272 type PublicKey<'s>
273 = DummyCrypto
274 where
275 Self: 's;
276
277 fn csr<'s>(&self, _buf: &'s mut [u8]) -> Result<&'s [u8], Error> {
278 unimplemented!()
279 }
280
281 fn pub_key(&self) -> Result<Self::PublicKey<'_>, Error> {
282 unimplemented!()
283 }
284
285 fn sign(
286 &self,
287 _data: &[u8],
288 _signature: &mut CryptoSensitive<SIGNATURE_LEN>,
289 ) -> Result<(), Error> {
290 unimplemented!()
291 }
292}
293
294impl<
295 const KEY_LEN: usize,
296 const PUB_KEY_LEN: usize,
297 const SIGNATURE_LEN: usize,
298 const SHARED_SECRET_LEN: usize,
299 > crate::crypto::SecretKey<'_, KEY_LEN, PUB_KEY_LEN, SIGNATURE_LEN, SHARED_SECRET_LEN>
300 for DummyCrypto
301{
302 fn derive_shared_secret(
303 &self,
304 _peer_pub_key: &Self::PublicKey<'_>,
305 _shared_secret: &mut CryptoSensitive<SHARED_SECRET_LEN>,
306 ) -> Result<(), Error> {
307 unimplemented!()
308 }
309
310 fn write_canon(&self, _key: &mut CryptoSensitive<KEY_LEN>) -> Result<(), Error> {
311 unimplemented!()
312 }
313}
314
315impl<const LEN: usize> crate::crypto::EcScalar<'_, LEN> for DummyCrypto {
316 fn mul(&self, _other: &Self) -> Result<Self, Error> {
317 unimplemented!()
318 }
319
320 fn write_canon(&self, _scalar: &mut CryptoSensitive<LEN>) -> Result<(), Error> {
321 unimplemented!()
322 }
323}
324
325impl<'a, const LEN: usize, const SCALAR_LEN: usize> crate::crypto::EcPoint<'a, LEN, SCALAR_LEN>
326 for DummyCrypto
327{
328 type Scalar<'s> = DummyCrypto;
329
330 fn is_valid_pubkey(&self) -> Result<bool, Error> {
331 unimplemented!()
332 }
333
334 fn neg(&self) -> Result<Self, Error> {
335 unimplemented!()
336 }
337
338 fn mul(&self, _scalar: &Self::Scalar<'a>) -> Result<Self, Error> {
339 unimplemented!()
340 }
341
342 fn add_mul(
343 &self,
344 _s1: &Self::Scalar<'a>,
345 _p2: &Self,
346 _s2: &Self::Scalar<'a>,
347 ) -> Result<Self, Error> {
348 unimplemented!()
349 }
350
351 fn write_canon(&self, _point: &mut CryptoSensitive<LEN>) -> Result<(), Error> {
352 unimplemented!()
353 }
354}
355
356impl RngCore for DummyCrypto {
357 fn next_u32(&mut self) -> u32 {
358 unimplemented!()
359 }
360
361 fn next_u64(&mut self) -> u64 {
362 unimplemented!()
363 }
364
365 fn fill_bytes(&mut self, _dest: &mut [u8]) {
366 unimplemented!()
367 }
368
369 fn try_fill_bytes(&mut self, _dest: &mut [u8]) -> Result<(), rand_core::Error> {
370 unimplemented!()
371 }
372}
373
374impl CryptoRng for DummyCrypto {}