Skip to content

Commit

Permalink
aes-gcm internals: Use cpu_features from GCM context.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Feb 16, 2024
1 parent 459a92f commit ec4160c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
21 changes: 3 additions & 18 deletions src/aead/aes_gcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,7 @@ fn aes_gcm_seal(
remainder.copy_from_slice(&output.as_ref()[..remainder.len()]);
}

finish(
aes_key,
auth,
tag_iv,
aad_len,
total_in_out_len,
cpu_features,
)
finish(aes_key, auth, tag_iv, aad_len, total_in_out_len)
}

fn aes_gcm_open(
Expand Down Expand Up @@ -250,14 +243,7 @@ fn aes_gcm_open(
aes_key.encrypt_iv_xor_block(ctr.into(), input, cpu_features)
});

finish(
aes_key,
auth,
tag_iv,
aad_len,
total_in_out_len,
cpu_features,
)
finish(aes_key, auth, tag_iv, aad_len, total_in_out_len)
}

fn finish(
Expand All @@ -266,7 +252,6 @@ fn finish(
tag_iv: aes::Iv,
aad_len: usize,
in_out_len: usize,
cpu_features: cpu::Features,
) -> Tag {
// Authenticate the final block containing the input lengths.
let aad_bits = polyfill::u64_from_usize(aad_len) << 3;
Expand All @@ -276,7 +261,7 @@ fn finish(
));

// Finalize the tag and return it.
gcm_ctx.pre_finish(|pre_tag| {
gcm_ctx.pre_finish(|pre_tag, cpu_features| {
let encrypted_iv = aes_key.encrypt_block(tag_iv.into_block_less_safe(), cpu_features);
let tag = pre_tag ^ encrypted_iv;
Tag(*tag.as_ref())
Expand Down
6 changes: 3 additions & 3 deletions src/aead/gcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Key {

pub struct Context {
inner: ContextInner,
cpu_features: cpu::Features,
pub(super) cpu_features: cpu::Features,
}

impl Context {
Expand Down Expand Up @@ -232,9 +232,9 @@ impl Context {

pub(super) fn pre_finish<F>(self, f: F) -> super::Tag
where
F: FnOnce(Block) -> super::Tag,
F: FnOnce(Block, cpu::Features) -> super::Tag,
{
f(self.inner.Xi.0)
f(self.inner.Xi.0, self.cpu_features)
}

#[cfg(target_arch = "x86_64")]
Expand Down

0 comments on commit ec4160c

Please sign in to comment.