Support AES-192/256 PACE (fixes reading Portuguese Cartão de Cidadão) - #50
Open
FerroLx wants to merge 1 commit into
Open
Support AES-192/256 PACE (fixes reading Portuguese Cartão de Cidadão)#50FerroLx wants to merge 1 commit into
FerroLx wants to merge 1 commit into
Conversation
Two AES key-length bugs prevented PACE with AES-192/256, which the current Portuguese Cartão de Cidadão (and other modern eMRTDs) negotiate: 1. proto/pace.dart decryptNonce hard-coded the nonce cipher to AESChiperSelector.getChiper(size: KEY_LENGTH.s128), ignoring the negotiated keyLength. With an AES-256 k_pi (32 bytes) this raised "key length must be 128 bits". Use the in-scope `keyLength`. 2. crypto/aes.dart AESChiperSelector.getChiper returned AESCipher128() for the KEY_LENGTH.s192 case (copy-paste error). Return AESCipher192(). Note: this also needs pointycastle's CMac AES-256 IV fix (CMac.init sizing the zero IV to key length instead of block size) for the PACE mutual-auth CMAC and secure-messaging MAC to work end to end.
FerroLx
force-pushed
the
fix/pace-aes192-256
branch
from
July 24, 2026 10:15
65a731a to
06e79b6
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.
Problem
PACE fails on eMRTDs that negotiate AES-192/256 (e.g. the current Portuguese
Cartão de Cidadão), due to two AES key-length bugs.
Fixes
1.
proto/pace.dart—decryptNoncehard-coded the nonce cipher to AES-128:ignoring the negotiated
keyLengthalready in scope. With an AES-256k_pi(32 bytes)this raises "key length must be 128 bits". Fixed to
getChiper(size: keyLength).2.
crypto/aes.dart—AESChiperSelector.getChiperreturnedAESCipher128()for theKEY_LENGTH.s192case (copy-paste error). Fixed toAESCipher192().Dependency
End-to-end AES-256 PACE also requires the pointycastle
CMac.initIV fix(sizes the zero IV to key length instead of cipher block size) for the mutual-auth
CMAC and secure-messaging MAC. See bcgit/pc-dart.
Testing
Verified by successfully reading a real Portuguese Cartão de Cidadão (PACE, AES-256)
over NFC end-to-end (EF.SOD + DG1 + DG2) with both fixes applied.