Skip to content

Support AES-192/256 PACE (fixes reading Portuguese Cartão de Cidadão) - #50

Open
FerroLx wants to merge 1 commit into
ZeroPass:masterfrom
munimen-security:fix/pace-aes192-256
Open

Support AES-192/256 PACE (fixes reading Portuguese Cartão de Cidadão)#50
FerroLx wants to merge 1 commit into
ZeroPass:masterfrom
munimen-security:fix/pace-aes192-256

Conversation

@FerroLx

@FerroLx FerroLx commented Jul 24, 2026

Copy link
Copy Markdown

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.dartdecryptNonce hard-coded the nonce cipher to AES-128:

AESCipher aesCipher128 = AESChiperSelector.getChiper(size: KEY_LENGTH.s128);

ignoring the negotiated keyLength already in scope. With an AES-256 k_pi (32 bytes)
this raises "key length must be 128 bits". Fixed to getChiper(size: keyLength).

2. crypto/aes.dartAESChiperSelector.getChiper returned AESCipher128() for the
KEY_LENGTH.s192 case (copy-paste error). Fixed to AESCipher192().

Dependency

End-to-end AES-256 PACE also requires the pointycastle CMac.init IV 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.

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
FerroLx force-pushed the fix/pace-aes192-256 branch from 65a731a to 06e79b6 Compare July 24, 2026 10:15
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.

1 participant