Skip to content

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

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

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

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.
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

1 participant