Coverage Report

Created: 2025-12-31 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/aes-0.8.4/src/autodetect.rs
Line
Count
Source
1
//! Autodetection support for hardware accelerated AES backends with fallback
2
//! to the fixsliced "soft" implementation.
3
4
use crate::soft;
5
use cipher::{
6
    consts::{U16, U24, U32},
7
    AlgorithmName, BlockCipher, BlockClosure, BlockDecrypt, BlockEncrypt, BlockSizeUser, Key,
8
    KeyInit, KeySizeUser,
9
};
10
use core::fmt;
11
use core::mem::ManuallyDrop;
12
13
#[cfg(all(target_arch = "aarch64", aes_armv8))]
14
use crate::armv8 as intrinsics;
15
16
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
17
use crate::ni as intrinsics;
18
19
cpufeatures::new!(aes_intrinsics, "aes");
20
21
macro_rules! define_aes_impl {
22
    (
23
        $name:ident,
24
        $name_enc:ident,
25
        $name_dec:ident,
26
        $module:tt,
27
        $key_size:ty,
28
        $doc:expr $(,)?
29
    ) => {
30
        mod $module {
31
            use super::{intrinsics, soft};
32
            use core::mem::ManuallyDrop;
33
34
            pub(super) union Inner {
35
                pub(super) intrinsics: ManuallyDrop<intrinsics::$name>,
36
                pub(super) soft: ManuallyDrop<soft::$name>,
37
            }
38
39
            pub(super) union InnerEnc {
40
                pub(super) intrinsics: ManuallyDrop<intrinsics::$name_enc>,
41
                pub(super) soft: ManuallyDrop<soft::$name_enc>,
42
            }
43
44
            pub(super) union InnerDec {
45
                pub(super) intrinsics: ManuallyDrop<intrinsics::$name_dec>,
46
                pub(super) soft: ManuallyDrop<soft::$name_dec>,
47
            }
48
        }
49
50
        #[doc=$doc]
51
        #[doc = "block cipher"]
52
        pub struct $name {
53
            inner: $module::Inner,
54
            token: aes_intrinsics::InitToken,
55
        }
56
57
        impl KeySizeUser for $name {
58
            type KeySize = $key_size;
59
        }
60
        impl From<$name_enc> for $name {
61
            #[inline]
62
0
            fn from(enc: $name_enc) -> $name {
63
0
                Self::from(&enc)
64
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256 as core::convert::From<aes::autodetect::Aes256Enc>>::from
Unexecuted instantiation: <aes::autodetect::Aes128 as core::convert::From<aes::autodetect::Aes128Enc>>::from
Unexecuted instantiation: <aes::autodetect::Aes192 as core::convert::From<aes::autodetect::Aes192Enc>>::from
65
        }
66
67
        impl From<&$name_enc> for $name {
68
0
            fn from(enc: &$name_enc) -> $name {
69
                use core::ops::Deref;
70
0
                let inner = if enc.token.get() {
71
0
                    $module::Inner {
72
0
                        intrinsics: ManuallyDrop::new(unsafe {
73
0
                            enc.inner.intrinsics.deref().into()
74
0
                        }),
75
0
                    }
76
                } else {
77
0
                    $module::Inner {
78
0
                        soft: ManuallyDrop::new(unsafe { enc.inner.soft.deref().into() }),
79
0
                    }
80
                };
81
82
0
                Self {
83
0
                    inner,
84
0
                    token: enc.token,
85
0
                }
86
0
            }
Unexecuted instantiation: <aes::autodetect::Aes128 as core::convert::From<&aes::autodetect::Aes128Enc>>::from
Unexecuted instantiation: <aes::autodetect::Aes256 as core::convert::From<&aes::autodetect::Aes256Enc>>::from
Unexecuted instantiation: <aes::autodetect::Aes192 as core::convert::From<&aes::autodetect::Aes192Enc>>::from
87
        }
88
89
        impl KeyInit for $name {
90
            #[inline]
91
2.23k
            fn new(key: &Key<Self>) -> Self {
92
2.23k
                let (token, aesni_present) = aes_intrinsics::init_get();
93
94
2.23k
                let inner = if aesni_present {
95
2.23k
                    $module::Inner {
96
2.23k
                        intrinsics: ManuallyDrop::new(intrinsics::$name::new(key)),
97
2.23k
                    }
98
                } else {
99
0
                    $module::Inner {
100
0
                        soft: ManuallyDrop::new(soft::$name::new(key)),
101
0
                    }
102
                };
103
104
2.23k
                Self { inner, token }
105
2.23k
            }
<aes::autodetect::Aes256 as crypto_common::KeyInit>::new
Line
Count
Source
91
2.23k
            fn new(key: &Key<Self>) -> Self {
92
2.23k
                let (token, aesni_present) = aes_intrinsics::init_get();
93
94
2.23k
                let inner = if aesni_present {
95
2.23k
                    $module::Inner {
96
2.23k
                        intrinsics: ManuallyDrop::new(intrinsics::$name::new(key)),
97
2.23k
                    }
98
                } else {
99
0
                    $module::Inner {
100
0
                        soft: ManuallyDrop::new(soft::$name::new(key)),
101
0
                    }
102
                };
103
104
2.23k
                Self { inner, token }
105
2.23k
            }
Unexecuted instantiation: <aes::autodetect::Aes256 as crypto_common::KeyInit>::new
Unexecuted instantiation: <aes::autodetect::Aes128 as crypto_common::KeyInit>::new
Unexecuted instantiation: <aes::autodetect::Aes192 as crypto_common::KeyInit>::new
106
        }
107
108
        impl Clone for $name {
109
0
            fn clone(&self) -> Self {
110
0
                let inner = if self.token.get() {
111
0
                    $module::Inner {
112
0
                        intrinsics: unsafe { self.inner.intrinsics.clone() },
113
0
                    }
114
                } else {
115
0
                    $module::Inner {
116
0
                        soft: unsafe { self.inner.soft.clone() },
117
0
                    }
118
                };
119
120
0
                Self {
121
0
                    inner,
122
0
                    token: self.token,
123
0
                }
124
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256 as core::clone::Clone>::clone
Unexecuted instantiation: <aes::autodetect::Aes128 as core::clone::Clone>::clone
Unexecuted instantiation: <aes::autodetect::Aes192 as core::clone::Clone>::clone
125
        }
126
127
        impl BlockSizeUser for $name {
128
            type BlockSize = U16;
129
        }
130
131
        impl BlockCipher for $name {}
132
133
        impl BlockEncrypt for $name {
134
26.7k
            fn encrypt_with_backend(&self, f: impl BlockClosure<BlockSize = U16>) {
135
                unsafe {
136
26.7k
                    if self.token.get() {
137
                        #[target_feature(enable = "aes")]
138
26.7k
                        unsafe fn inner(
139
26.7k
                            state: &intrinsics::$name,
140
26.7k
                            f: impl BlockClosure<BlockSize = U16>,
141
26.7k
                        ) {
142
26.7k
                            f.call(&mut state.get_enc_backend());
143
26.7k
                        }
<aes::autodetect::Aes256 as cipher::block::BlockEncrypt>::encrypt_with_backend::inner::<cbc::encrypt::Closure<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, cipher::block::BlockCtx<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>>>>
Line
Count
Source
138
26.7k
                        unsafe fn inner(
139
26.7k
                            state: &intrinsics::$name,
140
26.7k
                            f: impl BlockClosure<BlockSize = U16>,
141
26.7k
                        ) {
142
26.7k
                            f.call(&mut state.get_enc_backend());
143
26.7k
                        }
Unexecuted instantiation: <aes::autodetect::Aes256 as cipher::block::BlockEncrypt>::encrypt_with_backend::inner::<_>
Unexecuted instantiation: <aes::autodetect::Aes128 as cipher::block::BlockEncrypt>::encrypt_with_backend::inner::<_>
Unexecuted instantiation: <aes::autodetect::Aes192 as cipher::block::BlockEncrypt>::encrypt_with_backend::inner::<_>
144
26.7k
                        inner(&self.inner.intrinsics, f);
145
0
                    } else {
146
0
                        f.call(&mut self.inner.soft.get_enc_backend());
147
0
                    }
148
                }
149
26.7k
            }
<aes::autodetect::Aes256 as cipher::block::BlockEncrypt>::encrypt_with_backend::<cbc::encrypt::Closure<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, cipher::block::BlockCtx<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>>>>
Line
Count
Source
134
26.7k
            fn encrypt_with_backend(&self, f: impl BlockClosure<BlockSize = U16>) {
135
                unsafe {
136
26.7k
                    if self.token.get() {
137
                        #[target_feature(enable = "aes")]
138
                        unsafe fn inner(
139
                            state: &intrinsics::$name,
140
                            f: impl BlockClosure<BlockSize = U16>,
141
                        ) {
142
                            f.call(&mut state.get_enc_backend());
143
                        }
144
26.7k
                        inner(&self.inner.intrinsics, f);
145
0
                    } else {
146
0
                        f.call(&mut self.inner.soft.get_enc_backend());
147
0
                    }
148
                }
149
26.7k
            }
Unexecuted instantiation: <aes::autodetect::Aes256 as cipher::block::BlockEncrypt>::encrypt_with_backend::<_>
Unexecuted instantiation: <aes::autodetect::Aes128 as cipher::block::BlockEncrypt>::encrypt_with_backend::<_>
Unexecuted instantiation: <aes::autodetect::Aes192 as cipher::block::BlockEncrypt>::encrypt_with_backend::<_>
150
        }
151
152
        impl BlockDecrypt for $name {
153
0
            fn decrypt_with_backend(&self, f: impl BlockClosure<BlockSize = U16>) {
154
                unsafe {
155
0
                    if self.token.get() {
156
                        #[target_feature(enable = "aes")]
157
0
                        unsafe fn inner(
158
0
                            state: &intrinsics::$name,
159
0
                            f: impl BlockClosure<BlockSize = U16>,
160
0
                        ) {
161
0
                            f.call(&mut state.get_dec_backend());
162
0
                        }
Unexecuted instantiation: <aes::autodetect::Aes256 as cipher::block::BlockDecrypt>::decrypt_with_backend::inner::<cbc::decrypt::Closure<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, cipher::block::BlockCtx<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>>>>
Unexecuted instantiation: <aes::autodetect::Aes256 as cipher::block::BlockDecrypt>::decrypt_with_backend::inner::<_>
Unexecuted instantiation: <aes::autodetect::Aes128 as cipher::block::BlockDecrypt>::decrypt_with_backend::inner::<_>
Unexecuted instantiation: <aes::autodetect::Aes192 as cipher::block::BlockDecrypt>::decrypt_with_backend::inner::<_>
163
0
                        inner(&self.inner.intrinsics, f);
164
0
                    } else {
165
0
                        f.call(&mut self.inner.soft.get_dec_backend());
166
0
                    }
167
                }
168
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256 as cipher::block::BlockDecrypt>::decrypt_with_backend::<cbc::decrypt::Closure<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, cipher::block::BlockCtx<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>, typenum::bit::B0>>>>
Unexecuted instantiation: <aes::autodetect::Aes256 as cipher::block::BlockDecrypt>::decrypt_with_backend::<_>
Unexecuted instantiation: <aes::autodetect::Aes128 as cipher::block::BlockDecrypt>::decrypt_with_backend::<_>
Unexecuted instantiation: <aes::autodetect::Aes192 as cipher::block::BlockDecrypt>::decrypt_with_backend::<_>
169
        }
170
171
        impl fmt::Debug for $name {
172
0
            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
173
0
                f.write_str(concat!(stringify!($name), " { .. }"))
174
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256 as core::fmt::Debug>::fmt
Unexecuted instantiation: <aes::autodetect::Aes128 as core::fmt::Debug>::fmt
Unexecuted instantiation: <aes::autodetect::Aes192 as core::fmt::Debug>::fmt
175
        }
176
177
        impl AlgorithmName for $name {
178
0
            fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
179
0
                f.write_str(stringify!($name))
180
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256 as crypto_common::AlgorithmName>::write_alg_name
Unexecuted instantiation: <aes::autodetect::Aes128 as crypto_common::AlgorithmName>::write_alg_name
Unexecuted instantiation: <aes::autodetect::Aes192 as crypto_common::AlgorithmName>::write_alg_name
181
        }
182
183
        impl Drop for $name {
184
            #[inline]
185
2.23k
            fn drop(&mut self) {
186
2.23k
                if self.token.get() {
187
2.23k
                    unsafe { ManuallyDrop::drop(&mut self.inner.intrinsics) };
188
2.23k
                } else {
189
0
                    unsafe { ManuallyDrop::drop(&mut self.inner.soft) };
190
0
                };
191
2.23k
            }
<aes::autodetect::Aes256 as core::ops::drop::Drop>::drop
Line
Count
Source
185
2.23k
            fn drop(&mut self) {
186
2.23k
                if self.token.get() {
187
2.23k
                    unsafe { ManuallyDrop::drop(&mut self.inner.intrinsics) };
188
2.23k
                } else {
189
0
                    unsafe { ManuallyDrop::drop(&mut self.inner.soft) };
190
0
                };
191
2.23k
            }
Unexecuted instantiation: <aes::autodetect::Aes256 as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aes::autodetect::Aes128 as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aes::autodetect::Aes192 as core::ops::drop::Drop>::drop
192
        }
193
194
        #[cfg(feature = "zeroize")]
195
        impl zeroize::ZeroizeOnDrop for $name {}
196
197
        #[doc=$doc]
198
        #[doc = "block cipher (encrypt-only)"]
199
        pub struct $name_enc {
200
            inner: $module::InnerEnc,
201
            token: aes_intrinsics::InitToken,
202
        }
203
204
        impl KeySizeUser for $name_enc {
205
            type KeySize = $key_size;
206
        }
207
208
        impl KeyInit for $name_enc {
209
            #[inline]
210
0
            fn new(key: &Key<Self>) -> Self {
211
0
                let (token, aesni_present) = aes_intrinsics::init_get();
212
213
0
                let inner = if aesni_present {
214
0
                    $module::InnerEnc {
215
0
                        intrinsics: ManuallyDrop::new(intrinsics::$name_enc::new(key)),
216
0
                    }
217
                } else {
218
0
                    $module::InnerEnc {
219
0
                        soft: ManuallyDrop::new(soft::$name_enc::new(key)),
220
0
                    }
221
                };
222
223
0
                Self { inner, token }
224
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Enc as crypto_common::KeyInit>::new
Unexecuted instantiation: <aes::autodetect::Aes192Enc as crypto_common::KeyInit>::new
Unexecuted instantiation: <aes::autodetect::Aes128Enc as crypto_common::KeyInit>::new
225
        }
226
227
        impl Clone for $name_enc {
228
0
            fn clone(&self) -> Self {
229
0
                let inner = if self.token.get() {
230
0
                    $module::InnerEnc {
231
0
                        intrinsics: unsafe { self.inner.intrinsics.clone() },
232
0
                    }
233
                } else {
234
0
                    $module::InnerEnc {
235
0
                        soft: unsafe { self.inner.soft.clone() },
236
0
                    }
237
                };
238
239
0
                Self {
240
0
                    inner,
241
0
                    token: self.token,
242
0
                }
243
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Enc as core::clone::Clone>::clone
Unexecuted instantiation: <aes::autodetect::Aes192Enc as core::clone::Clone>::clone
Unexecuted instantiation: <aes::autodetect::Aes128Enc as core::clone::Clone>::clone
244
        }
245
246
        impl BlockSizeUser for $name_enc {
247
            type BlockSize = U16;
248
        }
249
250
        impl BlockCipher for $name_enc {}
251
252
        impl BlockEncrypt for $name_enc {
253
0
            fn encrypt_with_backend(&self, f: impl BlockClosure<BlockSize = U16>) {
254
                unsafe {
255
0
                    if self.token.get() {
256
                        #[target_feature(enable = "aes")]
257
0
                        unsafe fn inner(
258
0
                            state: &intrinsics::$name_enc,
259
0
                            f: impl BlockClosure<BlockSize = U16>,
260
0
                        ) {
261
0
                            f.call(&mut state.get_enc_backend());
262
0
                        }
Unexecuted instantiation: <aes::autodetect::Aes256Enc as cipher::block::BlockEncrypt>::encrypt_with_backend::inner::<_>
Unexecuted instantiation: <aes::autodetect::Aes192Enc as cipher::block::BlockEncrypt>::encrypt_with_backend::inner::<_>
Unexecuted instantiation: <aes::autodetect::Aes128Enc as cipher::block::BlockEncrypt>::encrypt_with_backend::inner::<_>
263
0
                        inner(&self.inner.intrinsics, f);
264
0
                    } else {
265
0
                        f.call(&mut self.inner.soft.get_enc_backend());
266
0
                    }
267
                }
268
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Enc as cipher::block::BlockEncrypt>::encrypt_with_backend::<_>
Unexecuted instantiation: <aes::autodetect::Aes192Enc as cipher::block::BlockEncrypt>::encrypt_with_backend::<_>
Unexecuted instantiation: <aes::autodetect::Aes128Enc as cipher::block::BlockEncrypt>::encrypt_with_backend::<_>
269
        }
270
271
        impl fmt::Debug for $name_enc {
272
0
            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
273
0
                f.write_str(concat!(stringify!($name_enc), " { .. }"))
274
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Enc as core::fmt::Debug>::fmt
Unexecuted instantiation: <aes::autodetect::Aes192Enc as core::fmt::Debug>::fmt
Unexecuted instantiation: <aes::autodetect::Aes128Enc as core::fmt::Debug>::fmt
275
        }
276
277
        impl AlgorithmName for $name_enc {
278
0
            fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
279
0
                f.write_str(stringify!($name_enc))
280
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Enc as crypto_common::AlgorithmName>::write_alg_name
Unexecuted instantiation: <aes::autodetect::Aes192Enc as crypto_common::AlgorithmName>::write_alg_name
Unexecuted instantiation: <aes::autodetect::Aes128Enc as crypto_common::AlgorithmName>::write_alg_name
281
        }
282
283
        impl Drop for $name_enc {
284
            #[inline]
285
0
            fn drop(&mut self) {
286
0
                if self.token.get() {
287
0
                    unsafe { ManuallyDrop::drop(&mut self.inner.intrinsics) };
288
0
                } else {
289
0
                    unsafe { ManuallyDrop::drop(&mut self.inner.soft) };
290
0
                };
291
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Enc as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aes::autodetect::Aes192Enc as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aes::autodetect::Aes128Enc as core::ops::drop::Drop>::drop
292
        }
293
294
        #[cfg(feature = "zeroize")]
295
        impl zeroize::ZeroizeOnDrop for $name_enc {}
296
297
        #[doc=$doc]
298
        #[doc = "block cipher (decrypt-only)"]
299
        pub struct $name_dec {
300
            inner: $module::InnerDec,
301
            token: aes_intrinsics::InitToken,
302
        }
303
304
        impl KeySizeUser for $name_dec {
305
            type KeySize = $key_size;
306
        }
307
308
        impl From<$name_enc> for $name_dec {
309
            #[inline]
310
0
            fn from(enc: $name_enc) -> $name_dec {
311
0
                Self::from(&enc)
312
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Dec as core::convert::From<aes::autodetect::Aes256Enc>>::from
Unexecuted instantiation: <aes::autodetect::Aes192Dec as core::convert::From<aes::autodetect::Aes192Enc>>::from
Unexecuted instantiation: <aes::autodetect::Aes128Dec as core::convert::From<aes::autodetect::Aes128Enc>>::from
313
        }
314
315
        impl From<&$name_enc> for $name_dec {
316
0
            fn from(enc: &$name_enc) -> $name_dec {
317
                use core::ops::Deref;
318
0
                let inner = if enc.token.get() {
319
0
                    $module::InnerDec {
320
0
                        intrinsics: ManuallyDrop::new(unsafe {
321
0
                            enc.inner.intrinsics.deref().into()
322
0
                        }),
323
0
                    }
324
                } else {
325
0
                    $module::InnerDec {
326
0
                        soft: ManuallyDrop::new(unsafe { enc.inner.soft.deref().into() }),
327
0
                    }
328
                };
329
330
0
                Self {
331
0
                    inner,
332
0
                    token: enc.token,
333
0
                }
334
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Dec as core::convert::From<&aes::autodetect::Aes256Enc>>::from
Unexecuted instantiation: <aes::autodetect::Aes192Dec as core::convert::From<&aes::autodetect::Aes192Enc>>::from
Unexecuted instantiation: <aes::autodetect::Aes128Dec as core::convert::From<&aes::autodetect::Aes128Enc>>::from
335
        }
336
337
        impl KeyInit for $name_dec {
338
            #[inline]
339
0
            fn new(key: &Key<Self>) -> Self {
340
0
                let (token, aesni_present) = aes_intrinsics::init_get();
341
342
0
                let inner = if aesni_present {
343
0
                    $module::InnerDec {
344
0
                        intrinsics: ManuallyDrop::new(intrinsics::$name_dec::new(key)),
345
0
                    }
346
                } else {
347
0
                    $module::InnerDec {
348
0
                        soft: ManuallyDrop::new(soft::$name_dec::new(key)),
349
0
                    }
350
                };
351
352
0
                Self { inner, token }
353
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Dec as crypto_common::KeyInit>::new
Unexecuted instantiation: <aes::autodetect::Aes192Dec as crypto_common::KeyInit>::new
Unexecuted instantiation: <aes::autodetect::Aes128Dec as crypto_common::KeyInit>::new
354
        }
355
356
        impl Clone for $name_dec {
357
0
            fn clone(&self) -> Self {
358
0
                let inner = if self.token.get() {
359
0
                    $module::InnerDec {
360
0
                        intrinsics: unsafe { self.inner.intrinsics.clone() },
361
0
                    }
362
                } else {
363
0
                    $module::InnerDec {
364
0
                        soft: unsafe { self.inner.soft.clone() },
365
0
                    }
366
                };
367
368
0
                Self {
369
0
                    inner,
370
0
                    token: self.token,
371
0
                }
372
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Dec as core::clone::Clone>::clone
Unexecuted instantiation: <aes::autodetect::Aes192Dec as core::clone::Clone>::clone
Unexecuted instantiation: <aes::autodetect::Aes128Dec as core::clone::Clone>::clone
373
        }
374
375
        impl BlockSizeUser for $name_dec {
376
            type BlockSize = U16;
377
        }
378
379
        impl BlockCipher for $name_dec {}
380
381
        impl BlockDecrypt for $name_dec {
382
0
            fn decrypt_with_backend(&self, f: impl BlockClosure<BlockSize = U16>) {
383
                unsafe {
384
0
                    if self.token.get() {
385
                        #[target_feature(enable = "aes")]
386
0
                        unsafe fn inner(
387
0
                            state: &intrinsics::$name_dec,
388
0
                            f: impl BlockClosure<BlockSize = U16>,
389
0
                        ) {
390
0
                            f.call(&mut state.get_dec_backend());
391
0
                        }
Unexecuted instantiation: <aes::autodetect::Aes256Dec as cipher::block::BlockDecrypt>::decrypt_with_backend::inner::<_>
Unexecuted instantiation: <aes::autodetect::Aes192Dec as cipher::block::BlockDecrypt>::decrypt_with_backend::inner::<_>
Unexecuted instantiation: <aes::autodetect::Aes128Dec as cipher::block::BlockDecrypt>::decrypt_with_backend::inner::<_>
392
0
                        inner(&self.inner.intrinsics, f);
393
0
                    } else {
394
0
                        f.call(&mut self.inner.soft.get_dec_backend());
395
0
                    }
396
                }
397
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Dec as cipher::block::BlockDecrypt>::decrypt_with_backend::<_>
Unexecuted instantiation: <aes::autodetect::Aes192Dec as cipher::block::BlockDecrypt>::decrypt_with_backend::<_>
Unexecuted instantiation: <aes::autodetect::Aes128Dec as cipher::block::BlockDecrypt>::decrypt_with_backend::<_>
398
        }
399
400
        impl fmt::Debug for $name_dec {
401
0
            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
402
0
                f.write_str(concat!(stringify!($name_dec), " { .. }"))
403
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Dec as core::fmt::Debug>::fmt
Unexecuted instantiation: <aes::autodetect::Aes192Dec as core::fmt::Debug>::fmt
Unexecuted instantiation: <aes::autodetect::Aes128Dec as core::fmt::Debug>::fmt
404
        }
405
406
        impl AlgorithmName for $name_dec {
407
0
            fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
408
0
                f.write_str(stringify!($name_dec))
409
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Dec as crypto_common::AlgorithmName>::write_alg_name
Unexecuted instantiation: <aes::autodetect::Aes192Dec as crypto_common::AlgorithmName>::write_alg_name
Unexecuted instantiation: <aes::autodetect::Aes128Dec as crypto_common::AlgorithmName>::write_alg_name
410
        }
411
412
        impl Drop for $name_dec {
413
            #[inline]
414
0
            fn drop(&mut self) {
415
0
                if self.token.get() {
416
0
                    unsafe { ManuallyDrop::drop(&mut self.inner.intrinsics) };
417
0
                } else {
418
0
                    unsafe { ManuallyDrop::drop(&mut self.inner.soft) };
419
0
                };
420
0
            }
Unexecuted instantiation: <aes::autodetect::Aes256Dec as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aes::autodetect::Aes192Dec as core::ops::drop::Drop>::drop
Unexecuted instantiation: <aes::autodetect::Aes128Dec as core::ops::drop::Drop>::drop
421
        }
422
423
        #[cfg(feature = "zeroize")]
424
        impl zeroize::ZeroizeOnDrop for $name_dec {}
425
    };
426
}
427
428
define_aes_impl!(Aes128, Aes128Enc, Aes128Dec, aes128, U16, "AES-128");
429
define_aes_impl!(Aes192, Aes192Enc, Aes192Dec, aes192, U24, "AES-192");
430
define_aes_impl!(Aes256, Aes256Enc, Aes256Dec, aes256, U32, "AES-256");