Skip to content

Use constant-time comparison for output prefix verification in MAC#73

Closed
JACKURUVI99 wants to merge 1 commit into
tink-crypto:mainfrom
JACKURUVI99:fix/non-constant-time-prefix-comparison
Closed

Use constant-time comparison for output prefix verification in MAC#73
JACKURUVI99 wants to merge 1 commit into
tink-crypto:mainfrom
JACKURUVI99:fix/non-constant-time-prefix-comparison

Conversation

@JACKURUVI99

Copy link
Copy Markdown
Contributor

Summary

Three places in MAC verification use non-constant-time comparisons for the output prefix check, inconsistent with the fix recently applied in ChunkedMacVerificationFromComputation (175df91).

  • ChunkedHmacImpl.createVerification()util.Bytes.equals()Arrays.equals() (non-CT)
  • ChunkedAesCmacImpl.createVerification() — same
  • LegacyFullMac.verifyMac()Arrays.equals() directly (non-CT)

All three are replaced with MessageDigest.isEqual() which is guaranteed constant-time by the JCA spec, consistent with the pattern already used in ChunkedMacVerificationFromComputation.

Files Changed

File Change
ChunkedHmacImpl.java Bytes.equals()MessageDigest.isEqual()
ChunkedAesCmacImpl.java Bytes.equals()MessageDigest.isEqual()
LegacyFullMac.java Arrays.equals()MessageDigest.isEqual()

Fixes #72.

Arrays.equals() and util.Bytes.equals() exit on the first mismatching
byte, leaking timing information in security-sensitive MAC verification
paths. Replace with MessageDigest.isEqual() (constant-time) in:

- ChunkedHmacImpl.createVerification() — output prefix check
- ChunkedAesCmacImpl.createVerification() — output prefix check
- LegacyFullMac.verifyMac() — prefix check before rawMac.verifyMac()

Consistent with the fix already applied in ChunkedMacVerificationFromComputation
(175df91). Fixes tink-crypto#72.
@tholenst

Copy link
Copy Markdown
Contributor

The output prefix is public and does not need constant time verification.

@tholenst tholenst closed this Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChunkedHmacVerification: non-constant-time MAC comparison at line 52 enables timing side-channel attack

2 participants