Skip to content

Refactor hash verification to use hmac.Equal#742

Open
udf2457 wants to merge 1 commit into
theupdateframework:masterfrom
udf2457:verifyHashes
Open

Refactor hash verification to use hmac.Equal#742
udf2457 wants to merge 1 commit into
theupdateframework:masterfrom
udf2457:verifyHashes

Conversation

@udf2457

@udf2457 udf2457 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Replace hex.Encode comparison with hmac.Equal, benefits:

  1. Constant-time comparison
  2. Removes un-necessary double hex encoding

Replace `hex.Encode` comparison with `Hashes.Equal`, benefits:

1. Constant-time comparison
2. Removes un-necessary double hex encoding

Signed-off-by: udf2457 <udf2457@users.noreply.github.com>
@udf2457
udf2457 requested a review from a team as a code owner June 19, 2026 09:48
Copilot AI review requested due to automatic review settings June 19, 2026 09:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors hash verification in metadata to compare raw digest bytes using a constant-time comparison instead of comparing hex-encoded strings, reducing unnecessary allocations and improving side-channel resistance during verification.

Changes:

  • Replace hex.EncodeToString(...)-based digest comparison with hmac.Equal(...) in verifyHashes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread metadata/metadata.go
}
hasher.Write(data)
if hex.EncodeToString(v) != hex.EncodeToString(hasher.Sum(nil)) {
if !hmac.Equal(v, hasher.Sum(nil)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants