Skip to content

Commit

Permalink
hmac: Tweak optimization for huge HMAC keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Dec 26, 2024
1 parent fb1b00e commit 9b42883
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ impl Digest {
ctx.try_finish(cpu)
}

#[cold]
#[inline(never)]
pub(crate) fn compute_from_cold(
algorithm: &'static Algorithm,
data: &[u8],
cpu: cpu::Features,
) -> Result<Self, FinishError> {
Self::compute_from(algorithm, data, cpu)
}

/// The algorithm that was used to calculate the digest value.
#[inline(always)]
pub fn algorithm(&self) -> &'static Algorithm {
Expand Down
2 changes: 1 addition & 1 deletion src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl Key {
let key_value = if key_value.len() <= block_len {
key_value
} else {
key_hash = Digest::compute_from(digest_alg, key_value, cpu_features)?;
key_hash = Digest::compute_from_cold(digest_alg, key_value, cpu_features)?;
key_hash.as_ref()
};

Expand Down

0 comments on commit 9b42883

Please sign in to comment.