Skip to content

Commit

Permalink
aead internals: Rename SrcIndexError to IndexError.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Jan 9, 2025
1 parent fa0c22b commit 504685d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/aead/aes/vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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:
Expand Down
22 changes: 10 additions & 12 deletions src/aead/aes_gcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -286,8 +286,7 @@ pub(super) fn open(
src: RangeFrom<usize>,
) -> Result<Tag, error::Unspecified> {
#[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
let in_out =
Overlapping::new(in_out_slice, src.clone()).map_err(error::erase::<SrcIndexError>)?;
let in_out = Overlapping::new(in_out_slice, src.clone()).map_err(error::erase::<IndexError>)?;

let mut ctr = Counter::one(nonce);
let tag_iv = ctr.increment();
Expand Down Expand Up @@ -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!()
Expand All @@ -344,15 +343,15 @@ 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::<SrcIndexError>)?;
.map_err(error::erase::<IndexError>)?;
aes_key.ctr32_encrypt_within(whole, &mut ctr);

let in_out_slice = match in_out_slice.get_mut(whole_len..) {
Some(partial) => partial,
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -443,8 +442,7 @@ fn open_strided<A: aes::EncryptBlock + aes::EncryptCtr32, G: gcm::UpdateBlocks +
mut ctr: Counter,
tag_iv: aes::Iv,
) -> Result<Tag, error::Unspecified> {
let in_out =
Overlapping::new(in_out_slice, src.clone()).map_err(error::erase::<SrcIndexError>)?;
let in_out = Overlapping::new(in_out_slice, src.clone()).map_err(error::erase::<IndexError>)?;
let input = in_out.input();
let input_len = input.len();

Expand Down Expand Up @@ -475,15 +473,15 @@ fn open_strided<A: aes::EncryptBlock + aes::EncryptCtr32, G: gcm::UpdateBlocks +
&mut in_out_slice[output..][..(chunk_len + in_prefix_len)],
in_prefix_len..,
)
.map_err(error::erase::<SrcIndexError>)?;
.map_err(error::erase::<IndexError>)?;
aes_key.ctr32_encrypt_within(chunk, &mut ctr);
output += chunk_len;
input += chunk_len;
}
}

let in_out = Overlapping::new(&mut in_out_slice[whole_len..], src)
.unwrap_or_else(|SrcIndexError { .. }| unreachable!());
.unwrap_or_else(|IndexError { .. }| unreachable!());
let in_out = OverlappingPartialBlock::new(in_out)
.unwrap_or_else(|InputTooLongError { .. }| unreachable!());

Expand Down
4 changes: 2 additions & 2 deletions src/aead/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use core::ops::RangeFrom;
use super::{
aes, aes_gcm, chacha20_poly1305,
nonce::{Nonce, NONCE_LEN},
overlapping::{Overlapping, SrcIndexError},
overlapping::{IndexError, Overlapping},
Aad, KeyInner, Tag, TAG_LEN,
};

Expand Down Expand Up @@ -265,7 +265,7 @@ fn chacha20_poly1305_open(
KeyInner::ChaCha20Poly1305(key) => key,
_ => unreachable!(),
};
let in_out = Overlapping::new(in_out, src).map_err(error::erase::<SrcIndexError>)?;
let in_out = Overlapping::new(in_out, src).map_err(error::erase::<IndexError>)?;
chacha20_poly1305::open(key, nonce, aad, in_out, cpu_features)
.map_err(error::erase::<InputTooLongError>)
}
4 changes: 2 additions & 2 deletions src/aead/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -286,7 +286,7 @@ mod tests {
ctr,
);
let in_out = Overlapping::new(buf, src)
.map_err(error::erase::<SrcIndexError>)
.map_err(error::erase::<IndexError>)
.unwrap();
f(key, ctr, in_out);
assert_eq!(&buf[..input.len()], expected)
Expand Down
8 changes: 4 additions & 4 deletions src/aead/overlapping/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>) -> Result<Self, SrcIndexError> {
pub fn new(in_out: &'o mut [T], src: RangeFrom<usize>) -> Result<Self, IndexError> {
match in_out.get(src.clone()) {
Some(_) => Ok(Self { in_out, src }),
None => Err(SrcIndexError::new(src)),
None => Err(IndexError::new(src)),
}
}

Expand Down Expand Up @@ -85,9 +85,9 @@ impl<T> Overlapping<'_, T> {
}
}

pub struct SrcIndexError(#[allow(dead_code)] RangeFrom<usize>);
pub struct IndexError(#[allow(dead_code)] RangeFrom<usize>);

impl SrcIndexError {
impl IndexError {
#[cold]
#[inline(never)]
fn new(src: RangeFrom<usize>) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion src/aead/overlapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down

0 comments on commit 504685d

Please sign in to comment.