Skip to content

Commit ec4160c

Browse files
committed
aes-gcm internals: Use cpu_features from GCM context.
1 parent 459a92f commit ec4160c

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

src/aead/aes_gcm.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,7 @@ fn aes_gcm_seal(
146146
remainder.copy_from_slice(&output.as_ref()[..remainder.len()]);
147147
}
148148

149-
finish(
150-
aes_key,
151-
auth,
152-
tag_iv,
153-
aad_len,
154-
total_in_out_len,
155-
cpu_features,
156-
)
149+
finish(aes_key, auth, tag_iv, aad_len, total_in_out_len)
157150
}
158151

159152
fn aes_gcm_open(
@@ -250,14 +243,7 @@ fn aes_gcm_open(
250243
aes_key.encrypt_iv_xor_block(ctr.into(), input, cpu_features)
251244
});
252245

253-
finish(
254-
aes_key,
255-
auth,
256-
tag_iv,
257-
aad_len,
258-
total_in_out_len,
259-
cpu_features,
260-
)
246+
finish(aes_key, auth, tag_iv, aad_len, total_in_out_len)
261247
}
262248

263249
fn finish(
@@ -266,7 +252,6 @@ fn finish(
266252
tag_iv: aes::Iv,
267253
aad_len: usize,
268254
in_out_len: usize,
269-
cpu_features: cpu::Features,
270255
) -> Tag {
271256
// Authenticate the final block containing the input lengths.
272257
let aad_bits = polyfill::u64_from_usize(aad_len) << 3;
@@ -276,7 +261,7 @@ fn finish(
276261
));
277262

278263
// Finalize the tag and return it.
279-
gcm_ctx.pre_finish(|pre_tag| {
264+
gcm_ctx.pre_finish(|pre_tag, cpu_features| {
280265
let encrypted_iv = aes_key.encrypt_block(tag_iv.into_block_less_safe(), cpu_features);
281266
let tag = pre_tag ^ encrypted_iv;
282267
Tag(*tag.as_ref())

src/aead/gcm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Key {
8484

8585
pub struct Context {
8686
inner: ContextInner,
87-
cpu_features: cpu::Features,
87+
pub(super) cpu_features: cpu::Features,
8888
}
8989

9090
impl Context {
@@ -232,9 +232,9 @@ impl Context {
232232

233233
pub(super) fn pre_finish<F>(self, f: F) -> super::Tag
234234
where
235-
F: FnOnce(Block) -> super::Tag,
235+
F: FnOnce(Block, cpu::Features) -> super::Tag,
236236
{
237-
f(self.inner.Xi.0)
237+
f(self.inner.Xi.0, self.cpu_features)
238238
}
239239

240240
#[cfg(target_arch = "x86_64")]

0 commit comments

Comments
 (0)