-
Notifications
You must be signed in to change notification settings - Fork 179
finish inout migration #664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,21 +103,21 @@ pub use aead::{self, AeadCore, AeadInOut, Error, Key, KeyInit, KeySizeUser}; | |
| #[cfg(feature = "aes")] | ||
| pub use aes; | ||
|
|
||
| use aead::{inout::InOutBuf, PostfixTagged}; | ||
| use aead::{PostfixTagged, inout::InOutBuf}; | ||
|
|
||
| use cipher::{ | ||
| BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore, | ||
| array::{Array, ArraySize}, | ||
| consts::U16, | ||
| BlockCipherEncrypt, BlockSizeUser, InnerIvInit, StreamCipherCore, | ||
| }; | ||
| use core::marker::PhantomData; | ||
| use ghash::{universal_hash::UniversalHash, GHash}; | ||
| use ghash::{GHash, universal_hash::UniversalHash}; | ||
|
|
||
| #[cfg(feature = "zeroize")] | ||
| use zeroize::Zeroize; | ||
|
|
||
| #[cfg(feature = "aes")] | ||
| use aes::{cipher::consts::U12, Aes128, Aes256}; | ||
| use aes::{Aes128, Aes256, cipher::consts::U12}; | ||
|
|
||
| /// Maximum length of associated data. | ||
| pub const A_MAX: u64 = 1 << 36; | ||
|
|
@@ -270,7 +270,7 @@ where | |
| &self, | ||
| nonce: &Nonce<NonceSize>, | ||
| associated_data: &[u8], | ||
| buffer: InOutBuf<'_, '_, u8>, | ||
| mut buffer: InOutBuf<'_, '_, u8>, | ||
| ) -> Result<Tag<TagSize>, Error> { | ||
| if buffer.len() as u64 > P_MAX || associated_data.len() as u64 > A_MAX { | ||
| return Err(Error); | ||
|
|
@@ -280,9 +280,9 @@ where | |
|
|
||
| // TODO(tarcieri): interleave encryption with GHASH | ||
| // See: <https://github.com/RustCrypto/AEADs/issues/74> | ||
| ctr.apply_keystream_partial(buffer.into()); | ||
| ctr.apply_keystream_partial(buffer.reborrow()); | ||
|
|
||
| let full_tag = self.compute_tag(mask, associated_data, buffer); | ||
| let full_tag = self.compute_tag(mask, associated_data, buffer.get_in()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one probably needs to be
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah there is probably a whole slew of those, I assumed the backing buffer was unique. |
||
| Ok(Tag::try_from(&full_tag[..TagSize::to_usize()]).expect("tag size mismatch")) | ||
| } | ||
|
|
||
|
|
@@ -301,11 +301,11 @@ where | |
|
|
||
| // TODO(tarcieri): interleave encryption with GHASH | ||
| // See: <https://github.com/RustCrypto/AEADs/issues/74> | ||
| let expected_tag = self.compute_tag(mask, associated_data, buffer); | ||
| let expected_tag = self.compute_tag(mask, associated_data, buffer.get_in()); | ||
|
|
||
| use subtle::ConstantTimeEq; | ||
| if expected_tag[..TagSize::to_usize()].ct_eq(tag).into() { | ||
| ctr.apply_keystream_partial(buffer.into()); | ||
| ctr.apply_keystream_partial(buffer); | ||
| Ok(()) | ||
| } else { | ||
| Err(Error) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,7 +213,7 @@ where | |
| // TODO(tarcieri): add offset param to `encrypt_inout_detached` | ||
| buffer.as_mut().copy_within(..pt_len, IV_SIZE); | ||
|
|
||
| let tag = self.encrypt_inout_detached(headers, &mut buffer.as_mut()[IV_SIZE..])?; | ||
| let tag = self.encrypt_inout_detached(headers, (&mut buffer.as_mut()[IV_SIZE..]).into())?; | ||
| buffer.as_mut()[..IV_SIZE].copy_from_slice(tag.as_slice()); | ||
| Ok(()) | ||
| } | ||
|
|
@@ -227,15 +227,15 @@ where | |
| pub fn encrypt_inout_detached<I, T>( | ||
| &mut self, | ||
| headers: I, | ||
| plaintext: InOutBuf<'_, '_, u8>, | ||
| mut plaintext: InOutBuf<'_, '_, u8>, | ||
| ) -> Result<Tag, Error> | ||
| where | ||
| I: IntoIterator<Item = T>, | ||
| T: AsRef<[u8]>, | ||
| { | ||
| // Compute the synthetic IV for this plaintext | ||
| let siv_tag = s2v(&mut self.mac, headers, plaintext)?; | ||
| self.xor_with_keystream(siv_tag, plaintext); | ||
| let siv_tag = s2v(&mut self.mac, headers, plaintext.get_in())?; | ||
| self.xor_with_keystream(siv_tag, plaintext.get_out()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably needs to pass |
||
| Ok(siv_tag) | ||
| } | ||
|
|
||
|
|
@@ -271,7 +271,7 @@ where | |
| } | ||
|
|
||
| let siv_tag = Tag::try_from(&buffer.as_ref()[..IV_SIZE]).expect("tag size mismatch"); | ||
| self.decrypt_inout_detached(headers, &mut buffer.as_mut()[IV_SIZE..], &siv_tag)?; | ||
| self.decrypt_inout_detached(headers, (&mut buffer.as_mut()[IV_SIZE..]).into(), &siv_tag)?; | ||
|
|
||
| let pt_len = buffer.len() - IV_SIZE; | ||
|
|
||
|
|
@@ -290,22 +290,22 @@ where | |
| pub fn decrypt_inout_detached<I, T>( | ||
| &mut self, | ||
| headers: I, | ||
| ciphertext: InOutBuf<'_, '_, u8>, | ||
| mut ciphertext: InOutBuf<'_, '_, u8>, | ||
| siv_tag: &Tag, | ||
| ) -> Result<(), Error> | ||
| where | ||
| I: IntoIterator<Item = T>, | ||
| T: AsRef<[u8]>, | ||
| { | ||
| self.xor_with_keystream(*siv_tag, ciphertext); | ||
| let computed_siv_tag = s2v(&mut self.mac, headers, ciphertext)?; | ||
| self.xor_with_keystream(*siv_tag, ciphertext.get_out()); | ||
| let computed_siv_tag = s2v(&mut self.mac, headers, ciphertext.get_in())?; | ||
|
|
||
| // Note: `CtOutput` provides constant-time equality | ||
| if CtOutput::<M>::new(computed_siv_tag) == CtOutput::new(*siv_tag) { | ||
| Ok(()) | ||
| } else { | ||
| // Re-encrypt the decrypted plaintext to avoid revealing it | ||
| self.xor_with_keystream(*siv_tag, ciphertext); | ||
| self.xor_with_keystream(*siv_tag, ciphertext.get_out()); | ||
| Err(Error) | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one needs to be
get_out, since it's authenticating the decrypted plaintext (since the "SIV" tag is calculated from the plaintext)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, in case it's not the same backing buffer for in and out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes