From a4291f676f1d711c998170a61c525d7e8ee0f645 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sun, 8 Feb 2026 22:56:33 +0100 Subject: [PATCH] ulaes cmac: fix 14a raw --- armsrc/cmac_calc.c | 2 +- armsrc/mifarecmd.c | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/armsrc/cmac_calc.c b/armsrc/cmac_calc.c index 1a3eb7290..57df15806 100644 --- a/armsrc/cmac_calc.c +++ b/armsrc/cmac_calc.c @@ -165,7 +165,7 @@ void append_cmac(uint8_t *d, size_t n) { cmd_mac[1] = (g_secure_session.counter >> 8) & 0xFF; memcpy(cmd_mac + 2, d, n); - print_result("cmd mac", cmd_mac, (2 + n)); + // print_result("cmd mac", cmd_mac, (2 + n)); ulaes_cmac(g_secure_session.sessionkey, sizeof(g_secure_session.sessionkey), cmd_mac, (2 + n), mac); // append CMAC to end of the command we are trying to send diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index d2da56917..03b9e89b4 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -287,7 +287,7 @@ static int MifareUFastRead0(void) { // 1 = failed auth // 0 = correct -static uint8_t chkKey3Pass(uint8_t keyno, uint8_t *keybytes, uint32_t *auths, bool check_answer) { +static uint8_t chkKey3Pass(uint8_t keyno, uint8_t *keybytes, uint32_t *auths, bool use_schann, bool check_answer) { uint8_t i = 0, res = 2; bool selected = false; @@ -301,7 +301,6 @@ static uint8_t chkKey3Pass(uint8_t keyno, uint8_t *keybytes, uint32_t *auths, bo if (keyno == MIFAREULC_KEY_INDEX) { res = mifare_ultra_3des_auth(keybytes, check_answer) == 1 ? 0 : 1; // 0 = correct, 1 = failed auth } else { - bool use_schann = false; res = mifare_ultra_aes_auth(keyno, keybytes, use_schann, check_answer) == 1 ? 0 : 1; // 0 = correct, 1 = failed auth } (*auths)++; @@ -335,7 +334,7 @@ void MifareU3PassAuth(mful_3passauth_t *packet) { for (uint16_t r = 0; r < 1 + packet->retries; r++) { WDT_HIT(); - if (chkKey3Pass(packet->keyno, packet->key, &auths, packet->check_answer) == 0) { + if (chkKey3Pass(packet->keyno, packet->key, &auths, packet->use_schann, packet->check_answer) == 0) { res = PM3_SUCCESS; goto out; } @@ -417,7 +416,7 @@ void MifareU3PassChkKeys(mful_3passchk_t *packet) { memcpy(fullkeybytes + (packet->segment * keysize), packet->data + (i * keysize), keysize); } } - if (chkKey3Pass(packet->key_index, fullkeybytes, &auths, packet->check_answer) == 0) { + if (chkKey3Pass(packet->key_index, fullkeybytes, &auths, false, packet->check_answer) == 0) { foundkeys++; memcpy(rpayload.key, fullkeybytes, MIFAREU3P_KEY_SIZE); res = PM3_SUCCESS; @@ -448,8 +447,6 @@ void MifareUReadBlock(mful_readblock_t *packet) { bool usePwd = (packet->keytype == 2); // UL_EV1/NTAG bool useAESKey = (packet->keytype == 3); // UL_AES - init_secure_session(); - LEDsoff(); LED_A_ON(); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); @@ -512,8 +509,6 @@ void MifareUReadBlock(mful_readblock_t *packet) { // datain = KEY bytes void MifareUReadCard(mful_readblock_t *packet) { - init_secure_session(); - LEDsoff(); LED_A_ON(); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); @@ -720,8 +715,6 @@ static void MifareUWriteBlockEx(mful_writeblock_t *packet, bool reply) { memcpy(blockdata, packet->data, sizeof(blockdata)); - init_secure_session(); - LEDsoff(); LED_A_ON(); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); @@ -799,7 +792,7 @@ void MifareUWriteBlockCompat(mful_writeblock_t *packet) { uint8_t blockdata[16] = {0x00}; memcpy(blockdata, packet->data, 16); - // UL-AES doesn't not support copmpability writes + // UL-AES doesn't not support compatibility writes if (useAESKey) { reply_ng(CMD_HF_MIFAREU_WRITEBL_COMPAT, PM3_EINVARG, NULL, 0); return ;