ulaes cmac: fix 14a raw

This commit is contained in:
Philippe Teuwen committed 2026-02-08 22:56:33 +01:00
1 parent 54b4459f45
commit a4291f676f
2 files changed
+5 -12

No files matched your search

+1 -1
View File
@@ -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
+4 -11
View File
@@ -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 ;