Fix AES SM MAC compare in unprotect() - #273
Open
bahadirtmzr wants to merge 1 commit into
Open
Conversation
bahadirtmzr
marked this pull request as ready for review
August 18, 2026 15:27
bahadirtmzr
force-pushed
the
security/verified-findings-only
branch
from
August 18, 2026 16:38
ec138fa to
5b8d987
Compare
unprotect() copies CC (the MAC from the chip) instead of CCb when the computed AES-CMAC is longer than 8 bytes, so the integrity check compares the chip MAC with itself. protect() already truncates CCb correctly. Existing 3DES tests never hit this branch because DES MACs are already 8 bytes.
bahadirtmzr
force-pushed
the
security/verified-findings-only
branch
from
August 18, 2026 16:41
5b8d987 to
7d9cb8a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
unprotect()is supposed to compare the first 8 bytes of the computed AES-CMAC with DO'8E.It currently does this:
CCis the MAC from the chip, so that assignment throws away the computed CMAC. AES-CMAC is 16 bytes, so we always take the branch and the compare becomesCC == CC.protect()already truncatesCCb. The existing 3DES tests never hit this because DES MACs are already 8 bytes.After PACE-AES or Chip Authentication AES, a response with one ciphertext byte flipped and the original MAC still unprotects.
testAESUnprotectRejectsModifiedCiphertextcovers that case.testAESUnprotectAcceptsValidMACchecks a correctly MACed AES response still works.The fix is the one assignment: truncate
CCb, notCC.