@@ -22,8 +22,13 @@ pub use crypto2::aeadcipher::{Aes128Gcm, Aes256Gcm, Chacha20Poly1305};
22
22
) ,
23
23
feature = "ring"
24
24
) ) ]
25
- pub use super :: ring:: { Aes128Gcm , Aes256Gcm , Chacha20Poly1305 } ;
26
- use super :: CipherKind ;
25
+ pub use crate :: v1:: ring:: { Aes128Gcm , Aes256Gcm , Chacha20Poly1305 } ;
26
+ use crate :: v1:: CipherKind ;
27
+
28
+ #[ cfg( feature = "v1-aead-extra" ) ]
29
+ mod sodium;
30
+ #[ cfg( feature = "v1-aead-extra" ) ]
31
+ pub use self :: sodium:: XChacha20Poly1305 ;
27
32
28
33
trait AeadCipherExt {
29
34
fn ac_kind ( & self ) -> CipherKind ;
@@ -74,6 +79,7 @@ macro_rules! impl_aead_cipher {
74
79
} ;
75
80
}
76
81
82
+ #[ cfg( feature = "v1-aead-extra" ) ]
77
83
macro_rules! impl_siv_cmac_cipher {
78
84
( $name: tt, $kind: tt) => {
79
85
impl AeadCipherExt for $name {
@@ -119,34 +125,54 @@ macro_rules! impl_siv_cmac_cipher {
119
125
} ;
120
126
}
121
127
128
+ #[ cfg( feature = "v1-aead-extra" ) ]
122
129
impl_aead_cipher ! ( Aes128Ccm , AES_128_CCM ) ;
130
+ #[ cfg( feature = "v1-aead-extra" ) ]
123
131
impl_aead_cipher ! ( Aes256Ccm , AES_256_CCM ) ;
132
+
124
133
impl_aead_cipher ! ( Aes128Gcm , AES_128_GCM ) ;
125
134
impl_aead_cipher ! ( Aes256Gcm , AES_256_GCM ) ;
126
135
136
+ #[ cfg( feature = "v1-aead-extra" ) ]
127
137
impl_aead_cipher ! ( Aes128GcmSiv , AES_128_GCM_SIV ) ;
138
+ #[ cfg( feature = "v1-aead-extra" ) ]
128
139
impl_aead_cipher ! ( Aes256GcmSiv , AES_256_GCM_SIV ) ;
129
140
141
+ #[ cfg( feature = "v1-aead-extra" ) ]
130
142
impl_aead_cipher ! ( Aes128OcbTag128 , AES_128_OCB_TAGLEN128 ) ;
143
+ #[ cfg( feature = "v1-aead-extra" ) ]
131
144
impl_aead_cipher ! ( Aes192OcbTag128 , AES_192_OCB_TAGLEN128 ) ;
145
+ #[ cfg( feature = "v1-aead-extra" ) ]
132
146
impl_aead_cipher ! ( Aes256OcbTag128 , AES_256_OCB_TAGLEN128 ) ;
133
147
134
148
impl_aead_cipher ! ( Chacha20Poly1305 , CHACHA20_POLY1305 ) ;
135
149
150
+ #[ cfg( feature = "v1-aead-extra" ) ]
136
151
impl_siv_cmac_cipher ! ( AesSivCmac256 , AES_SIV_CMAC_256 ) ;
152
+ #[ cfg( feature = "v1-aead-extra" ) ]
137
153
impl_siv_cmac_cipher ! ( AesSivCmac384 , AES_SIV_CMAC_384 ) ;
154
+ #[ cfg( feature = "v1-aead-extra" ) ]
138
155
impl_siv_cmac_cipher ! ( AesSivCmac512 , AES_SIV_CMAC_512 ) ;
139
156
157
+ #[ cfg( feature = "v1-aead-extra" ) ]
158
+ impl_aead_cipher ! ( XChacha20Poly1305 , XCHACHA20_POLY1305 ) ;
159
+
140
160
macro_rules! aead_cipher_variant {
141
- ( $( $name: ident @ $kind: ident, ) +) => {
161
+ ( $( $( # [ cfg ( $i_meta : meta ) ] ) ? $ name: ident @ $kind: ident, ) +) => {
142
162
enum AeadCipherInner {
143
- $( $name( $name) , ) +
163
+ $(
164
+ $( #[ cfg( $i_meta) ] ) ?
165
+ $name( $name) ,
166
+ ) +
144
167
}
145
168
146
169
impl AeadCipherInner {
147
170
fn new( kind: CipherKind , key: & [ u8 ] ) -> Self {
148
171
match kind {
149
- $( CipherKind :: $kind => AeadCipherInner :: $name( $name:: new( key) ) , ) +
172
+ $(
173
+ $( #[ cfg( $i_meta) ] ) ?
174
+ CipherKind :: $kind => AeadCipherInner :: $name( $name:: new( key) ) ,
175
+ ) +
150
176
_ => unreachable!( "unrecognized AEAD cipher kind {:?}" , kind) ,
151
177
}
152
178
}
@@ -155,72 +181,98 @@ macro_rules! aead_cipher_variant {
155
181
impl AeadCipherExt for AeadCipherInner {
156
182
fn ac_kind( & self ) -> CipherKind {
157
183
match * self {
158
- $( AeadCipherInner :: $name( ref c) => c. ac_kind( ) , ) +
184
+ $(
185
+ $( #[ cfg( $i_meta) ] ) ?
186
+ AeadCipherInner :: $name( ref c) => c. ac_kind( ) ,
187
+ ) +
159
188
}
160
189
}
161
190
162
191
fn ac_key_len( & self ) -> usize {
163
192
match * self {
164
- $( AeadCipherInner :: $name( ref c) => c. ac_key_len( ) , ) +
193
+ $(
194
+ $( #[ cfg( $i_meta) ] ) ?
195
+ AeadCipherInner :: $name( ref c) => c. ac_key_len( ) ,
196
+ ) +
165
197
}
166
198
}
167
199
fn ac_block_len( & self ) -> usize {
168
200
match * self {
169
- $( AeadCipherInner :: $name( ref c) => c. ac_block_len( ) , ) +
201
+ $(
202
+ $( #[ cfg( $i_meta) ] ) ?
203
+ AeadCipherInner :: $name( ref c) => c. ac_block_len( ) ,
204
+ ) +
170
205
}
171
206
}
172
207
173
208
fn ac_tag_len( & self ) -> usize {
174
209
match * self {
175
- $( AeadCipherInner :: $name( ref c) => c. ac_tag_len( ) , ) +
210
+ $(
211
+ $( #[ cfg( $i_meta) ] ) ?
212
+ AeadCipherInner :: $name( ref c) => c. ac_tag_len( ) ,
213
+ ) +
176
214
}
177
215
}
178
216
179
217
fn ac_n_min( & self ) -> usize {
180
218
match * self {
181
- $( AeadCipherInner :: $name( ref c) => c. ac_n_min( ) , ) +
219
+ $(
220
+ $( #[ cfg( $i_meta) ] ) ?
221
+ AeadCipherInner :: $name( ref c) => c. ac_n_min( ) ,
222
+ ) +
182
223
}
183
224
}
184
225
fn ac_n_max( & self ) -> usize {
185
226
match * self {
186
- $( AeadCipherInner :: $name( ref c) => c. ac_n_max( ) , ) +
227
+ $(
228
+ $( #[ cfg( $i_meta) ] ) ?
229
+ AeadCipherInner :: $name( ref c) => c. ac_n_max( ) ,
230
+ ) +
187
231
}
188
232
}
189
233
190
234
fn ac_encrypt_slice( & self , nonce: & [ u8 ] , plaintext_in_ciphertext_out: & mut [ u8 ] ) {
191
235
match * self {
192
- $( AeadCipherInner :: $name( ref c) => c. ac_encrypt_slice( nonce, plaintext_in_ciphertext_out) , ) +
236
+ $(
237
+ $( #[ cfg( $i_meta) ] ) ?
238
+ AeadCipherInner :: $name( ref c) => c. ac_encrypt_slice( nonce, plaintext_in_ciphertext_out) ,
239
+ ) +
193
240
}
194
241
}
195
242
196
243
fn ac_decrypt_slice( & self , nonce: & [ u8 ] , plaintext_in_ciphertext_out: & mut [ u8 ] ) -> bool {
197
244
match * self {
198
- $( AeadCipherInner :: $name( ref c) => c. ac_decrypt_slice( nonce, plaintext_in_ciphertext_out) , ) +
245
+ $(
246
+ $( #[ cfg( $i_meta) ] ) ?
247
+ AeadCipherInner :: $name( ref c) => c. ac_decrypt_slice( nonce, plaintext_in_ciphertext_out) ,
248
+ ) +
199
249
}
200
250
}
201
251
}
202
252
} ;
203
253
}
204
254
205
255
aead_cipher_variant ! {
206
- Aes128Ccm @ AES_128_CCM ,
207
- Aes256Ccm @ AES_256_CCM ,
256
+ # [ cfg ( feature = "v1-aead-extra" ) ] Aes128Ccm @ AES_128_CCM ,
257
+ # [ cfg ( feature = "v1-aead-extra" ) ] Aes256Ccm @ AES_256_CCM ,
208
258
209
- Aes128OcbTag128 @ AES_128_OCB_TAGLEN128 ,
210
- Aes192OcbTag128 @ AES_192_OCB_TAGLEN128 ,
211
- Aes256OcbTag128 @ AES_256_OCB_TAGLEN128 ,
259
+ # [ cfg ( feature = "v1-aead-extra" ) ] Aes128OcbTag128 @ AES_128_OCB_TAGLEN128 ,
260
+ # [ cfg ( feature = "v1-aead-extra" ) ] Aes192OcbTag128 @ AES_192_OCB_TAGLEN128 ,
261
+ # [ cfg ( feature = "v1-aead-extra" ) ] Aes256OcbTag128 @ AES_256_OCB_TAGLEN128 ,
212
262
213
263
Aes128Gcm @ AES_128_GCM ,
214
264
Aes256Gcm @ AES_256_GCM ,
215
265
216
- AesSivCmac256 @ AES_SIV_CMAC_256 ,
217
- AesSivCmac384 @ AES_SIV_CMAC_384 ,
218
- AesSivCmac512 @ AES_SIV_CMAC_512 ,
266
+ # [ cfg ( feature = "v1-aead-extra" ) ] AesSivCmac256 @ AES_SIV_CMAC_256 ,
267
+ # [ cfg ( feature = "v1-aead-extra" ) ] AesSivCmac384 @ AES_SIV_CMAC_384 ,
268
+ # [ cfg ( feature = "v1-aead-extra" ) ] AesSivCmac512 @ AES_SIV_CMAC_512 ,
219
269
220
- Aes128GcmSiv @ AES_128_GCM_SIV ,
221
- Aes256GcmSiv @ AES_256_GCM_SIV ,
270
+ # [ cfg ( feature = "v1-aead-extra" ) ] Aes128GcmSiv @ AES_128_GCM_SIV ,
271
+ # [ cfg ( feature = "v1-aead-extra" ) ] Aes256GcmSiv @ AES_256_GCM_SIV ,
222
272
223
273
Chacha20Poly1305 @ CHACHA20_POLY1305 ,
274
+
275
+ #[ cfg( feature = "v1-aead-extra" ) ] XChacha20Poly1305 @ XCHACHA20_POLY1305 ,
224
276
}
225
277
226
278
pub struct AeadCipher {
0 commit comments