110110//! buffer.extend_from_slice(b"plaintext message");
111111//!
112112//! // Encrypt `buffer` in-place, replacing the plaintext contents with ciphertext
113- //! let tag = cipher.encrypt_inout_detached(nonce, b"", &mut buffer).expect("encryption failure!");
113+ //! let tag = cipher.encrypt_inout_detached(nonce, b"", buffer.as_mut_slice().into() ).expect("encryption failure!");
114114//!
115115//! // The tag has only 8 bytes, compared to the usual 16 bytes
116116//! assert_eq!(tag.len(), 8);
119119//! assert_ne!(&buffer, b"plaintext message");
120120//!
121121//! // Decrypt `buffer` in-place, replacing its ciphertext context with the original plaintext
122- //! cipher.decrypt_inout_detached(nonce, b"", &mut buffer, &tag).expect("decryption failure!");
122+ //! cipher.decrypt_inout_detached(nonce, b"", buffer.as_mut_slice().into() , &tag).expect("decryption failure!");
123123//! assert_eq!(&buffer, b"plaintext message");
124124//! # }
125125//! ```
126126
127127pub use aead:: { self , AeadCore , AeadInOut , Error , Key , KeyInit , KeySizeUser } ;
128128pub use cipher;
129129
130- use aead:: { PostfixTagged , inout:: InOutBuf } ;
130+ use aead:: { inout:: InOutBuf , PostfixTagged } ;
131131use cipher:: {
132- BlockCipherEncrypt , BlockSizeUser , InnerIvInit , StreamCipherCore , array:: Array , consts:: U16 ,
133- crypto_common :: OutputSizeUser , typenum :: Unsigned ,
132+ array:: Array , consts:: U16 , crypto_common :: OutputSizeUser , typenum :: Unsigned ,
133+ BlockCipherEncrypt , BlockSizeUser , InnerIvInit , StreamCipherCore ,
134134} ;
135- use cmac:: { Cmac , Mac , digest:: Output } ;
135+ use cmac:: { digest:: Output , Cmac , Mac } ;
136136use core:: marker:: PhantomData ;
137137
138138mod traits;
@@ -228,7 +228,7 @@ where
228228 & self ,
229229 nonce : & Nonce < Self :: NonceSize > ,
230230 associated_data : & [ u8 ] ,
231- buffer : InOutBuf < ' _ , ' _ , u8 > ,
231+ mut buffer : InOutBuf < ' _ , ' _ , u8 > ,
232232 ) -> Result < Tag < M > , Error > {
233233 if buffer. len ( ) as u64 > P_MAX || associated_data. len ( ) as u64 > A_MAX {
234234 return Err ( Error ) ;
@@ -247,10 +247,10 @@ where
247247
248248 // 3. enc ← CTR(M) using n as iv
249249 Ctr128BE :: < Cipher > :: inner_iv_init ( Cipher :: new ( & self . key ) , & n)
250- . apply_keystream_partial ( buffer. into ( ) ) ;
250+ . apply_keystream_partial ( buffer. reborrow ( ) ) ;
251251
252252 // 4. c ← OMAC(2 || enc)
253- let c = Self :: cmac_with_iv ( & self . key , 2 , buffer) ;
253+ let c = Self :: cmac_with_iv ( & self . key , 2 , buffer. get_out ( ) ) ;
254254
255255 // 5. tag ← n ^ h ^ c
256256 // (^ means xor)
@@ -285,7 +285,7 @@ where
285285 let h = Self :: cmac_with_iv ( & self . key , 1 , associated_data) ;
286286
287287 // 4. c ← OMAC(2 || enc)
288- let c = Self :: cmac_with_iv ( & self . key , 2 , buffer) ;
288+ let c = Self :: cmac_with_iv ( & self . key , 2 , buffer. get_in ( ) ) ;
289289
290290 // 5. tag ← n ^ h ^ c
291291 // (^ means xor)
@@ -305,7 +305,7 @@ where
305305 if expected_tag. ct_eq ( tag) . into ( ) {
306306 // Decrypt
307307 Ctr128BE :: < Cipher > :: inner_iv_init ( Cipher :: new ( & self . key ) , & n)
308- . apply_keystream_partial ( buffer. into ( ) ) ;
308+ . apply_keystream_partial ( buffer) ;
309309
310310 Ok ( ( ) )
311311 } else {
0 commit comments