From 504685d1ae09f61fa88b75f7e53ef60b9c47ef9e Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Wed, 8 Jan 2025 11:52:56 -0800 Subject: [PATCH] aead internals: Rename `SrcIndexError` to `IndexError`. --- src/aead/aes/vp.rs | 6 +++--- src/aead/aes_gcm.rs | 22 ++++++++++------------ src/aead/algorithm.rs | 4 ++-- src/aead/chacha.rs | 4 ++-- src/aead/overlapping/base.rs | 8 ++++---- src/aead/overlapping/mod.rs | 2 +- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/aead/aes/vp.rs b/src/aead/aes/vp.rs index 6e52cafdd..394161207 100644 --- a/src/aead/aes/vp.rs +++ b/src/aead/aes/vp.rs @@ -64,7 +64,7 @@ impl EncryptCtr32 for Key { #[cfg(target_arch = "arm")] impl EncryptCtr32 for Key { fn ctr32_encrypt_within(&self, in_out: Overlapping<'_>, ctr: &mut Counter) { - use super::{super::overlapping::SrcIndexError, bs, BLOCK_LEN}; + use super::{super::overlapping::IndexError, bs, BLOCK_LEN}; let in_out = { let (in_out, src) = in_out.into_slice_src_mut(); @@ -86,7 +86,7 @@ impl EncryptCtr32 for Key { let bsaes_in_out_len = bsaes_blocks * BLOCK_LEN; let bs_in_out = Overlapping::new(&mut in_out[..(src.start + bsaes_in_out_len)], src.clone()) - .unwrap_or_else(|SrcIndexError { .. }| unreachable!()); + .unwrap_or_else(|IndexError { .. }| unreachable!()); // SAFETY: // * self.inner was initialized with `vpaes_set_encrypt_key` above, @@ -96,7 +96,7 @@ impl EncryptCtr32 for Key { } Overlapping::new(&mut in_out[bsaes_in_out_len..], src) - .unwrap_or_else(|SrcIndexError { .. }| unreachable!()) + .unwrap_or_else(|IndexError { .. }| unreachable!()) }; // SAFETY: diff --git a/src/aead/aes_gcm.rs b/src/aead/aes_gcm.rs index c76f3651e..89819a136 100644 --- a/src/aead/aes_gcm.rs +++ b/src/aead/aes_gcm.rs @@ -15,7 +15,7 @@ use super::{ aes::{self, Counter, Overlapping, OverlappingPartialBlock, BLOCK_LEN, ZERO_BLOCK}, gcm, - overlapping::SrcIndexError, + overlapping::IndexError, Aad, Nonce, Tag, }; use crate::{ @@ -286,8 +286,7 @@ pub(super) fn open( src: RangeFrom, ) -> Result { #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] - let in_out = - Overlapping::new(in_out_slice, src.clone()).map_err(error::erase::)?; + let in_out = Overlapping::new(in_out_slice, src.clone()).map_err(error::erase::)?; let mut ctr = Counter::one(nonce); let tag_iv = ctr.increment(); @@ -331,7 +330,7 @@ pub(super) fn open( }); // Authenticate any remaining whole blocks. let in_out = Overlapping::new(in_out_slice, src.clone()).unwrap_or_else( - |SrcIndexError { .. }| { + |IndexError { .. }| { // This can't happen. If it did, then the assembly already // overwrote part of the remaining input. unreachable!() @@ -344,7 +343,7 @@ pub(super) fn open( // Decrypt any remaining whole blocks. let whole = Overlapping::new(&mut in_out_slice[..(src.start + whole_len)], src.clone()) - .map_err(error::erase::)?; + .map_err(error::erase::)?; aes_key.ctr32_encrypt_within(whole, &mut ctr); let in_out_slice = match in_out_slice.get_mut(whole_len..) { @@ -352,7 +351,7 @@ pub(super) fn open( None => unreachable!(), }; let in_out = Overlapping::new(in_out_slice, src) - .unwrap_or_else(|SrcIndexError { .. }| unreachable!()); + .unwrap_or_else(|IndexError { .. }| unreachable!()); let in_out = OverlappingPartialBlock::new(in_out) .unwrap_or_else(|InputTooLongError { .. }| unreachable!()); open_finish(aes_key, auth, in_out, ctr, tag_iv) @@ -399,8 +398,8 @@ pub(super) fn open( } } let remainder = &mut in_out_slice[whole_len..]; - let remainder = Overlapping::new(remainder, src) - .unwrap_or_else(|SrcIndexError { .. }| unreachable!()); + let remainder = + Overlapping::new(remainder, src).unwrap_or_else(|IndexError { .. }| unreachable!()); let remainder = OverlappingPartialBlock::new(remainder) .unwrap_or_else(|InputTooLongError { .. }| unreachable!()); open_finish(aes_key, auth, remainder, ctr, tag_iv) @@ -443,8 +442,7 @@ fn open_strided Result { - let in_out = - Overlapping::new(in_out_slice, src.clone()).map_err(error::erase::)?; + let in_out = Overlapping::new(in_out_slice, src.clone()).map_err(error::erase::)?; let input = in_out.input(); let input_len = input.len(); @@ -475,7 +473,7 @@ fn open_strided)?; + .map_err(error::erase::)?; aes_key.ctr32_encrypt_within(chunk, &mut ctr); output += chunk_len; input += chunk_len; @@ -483,7 +481,7 @@ fn open_strided key, _ => unreachable!(), }; - let in_out = Overlapping::new(in_out, src).map_err(error::erase::)?; + let in_out = Overlapping::new(in_out, src).map_err(error::erase::)?; chacha20_poly1305::open(key, nonce, aad, in_out, cpu_features) .map_err(error::erase::) } diff --git a/src/aead/chacha.rs b/src/aead/chacha.rs index 96ad6f990..f442fac2b 100644 --- a/src/aead/chacha.rs +++ b/src/aead/chacha.rs @@ -179,7 +179,7 @@ const BLOCK_LEN: usize = 64; mod tests { extern crate alloc; - use super::{super::overlapping::SrcIndexError, *}; + use super::{super::overlapping::IndexError, *}; use crate::{error, test}; use alloc::vec; @@ -286,7 +286,7 @@ mod tests { ctr, ); let in_out = Overlapping::new(buf, src) - .map_err(error::erase::) + .map_err(error::erase::) .unwrap(); f(key, ctr, in_out); assert_eq!(&buf[..input.len()], expected) diff --git a/src/aead/overlapping/base.rs b/src/aead/overlapping/base.rs index 51099eeae..fb641306f 100644 --- a/src/aead/overlapping/base.rs +++ b/src/aead/overlapping/base.rs @@ -25,10 +25,10 @@ impl<'o, T> Overlapping<'o, T> { Self { in_out, src: 0.. } } - pub fn new(in_out: &'o mut [T], src: RangeFrom) -> Result { + pub fn new(in_out: &'o mut [T], src: RangeFrom) -> Result { match in_out.get(src.clone()) { Some(_) => Ok(Self { in_out, src }), - None => Err(SrcIndexError::new(src)), + None => Err(IndexError::new(src)), } } @@ -85,9 +85,9 @@ impl Overlapping<'_, T> { } } -pub struct SrcIndexError(#[allow(dead_code)] RangeFrom); +pub struct IndexError(#[allow(dead_code)] RangeFrom); -impl SrcIndexError { +impl IndexError { #[cold] #[inline(never)] fn new(src: RangeFrom) -> Self { diff --git a/src/aead/overlapping/mod.rs b/src/aead/overlapping/mod.rs index 17ce533c6..908b8b92c 100644 --- a/src/aead/overlapping/mod.rs +++ b/src/aead/overlapping/mod.rs @@ -13,7 +13,7 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. pub use self::{ - base::{Overlapping, SrcIndexError}, + base::{IndexError, Overlapping}, partial_block::PartialBlock, };