Fix MAC calculation

Doing non-first auth would reset counters, breaking MAC calculation and crypto as a whole

Signed-off-by: team-orangeBlue <63470411+team-orangeBlue@users.noreply.github.com>
This commit is contained in:
team-orangeBlue authored and GitHub committed 2026-05-29 13:27:09 +03:00
1 parent 319a4d5bb0
commit ee14761c22
1 file changed
+2 -2
+2 -2
View File
@@ -420,8 +420,6 @@ int MifareAuth4(mf4Session_t *mf4session, const uint8_t *keyn, uint8_t *key, boo
if (mf4session) {
mf4session->Authenticated = true;
mf4session->R_Ctr = 0;
mf4session->W_Ctr = 0;
mf4session->KeyNum = keyn[1] + (keyn[0] << 8);
memmove(mf4session->RndA, RndA, 16);
memmove(mf4session->RndB, RndB, 16);
@@ -429,6 +427,8 @@ int MifareAuth4(mf4Session_t *mf4session, const uint8_t *keyn, uint8_t *key, boo
memmove(mf4session->Kenc, kenc, 16);
memmove(mf4session->Kmac, kmac, 16);
if (!nonfirst) {
mf4session->R_Ctr = 0;
mf4session->W_Ctr = 0;
memmove(mf4session->TI, raw, 4);
memmove(mf4session->PICCap2, &raw[20], 6);
memmove(mf4session->PCDCap2, &raw[26], 6);