From 3a98c9fcd32cf9b4c6c10705d25df46fe7b57061 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Fri, 1 Mar 2019 19:13:59 +0200 Subject: [PATCH] fix mad2 crc8 check --- client/mifare/mad.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client/mifare/mad.c b/client/mifare/mad.c index 3973116b4..ff6991f22 100644 --- a/client/mifare/mad.c +++ b/client/mifare/mad.c @@ -109,13 +109,19 @@ static const char *GetAIDDescription(uint16_t AID) { int madCRCCheck(uint8_t *sector, bool verbose, int MADver) { if (MADver == 1) { - uint8_t crc = CRC8Mad(§or[16 + 1], 31); + uint8_t crc = CRC8Mad(§or[16 + 1], 15 + 16); if (crc != sector[16]) { if (verbose) PrintAndLogEx(ERR, "Wrong MAD%d CRC. Calculated: 0x%02x, from card: 0x%02x", MADver, crc, sector[16]); return 3; }; } else { + uint8_t crc = CRC8Mad(§or[1], 15 + 16 + 16); + if (crc != sector[0]) { + if (verbose) + PrintAndLogEx(ERR, "Wrong MAD%d CRC. Calculated: 0x%02x, from card: 0x%02x", MADver, crc, sector[16]); + return 3; + }; } return 0; @@ -191,6 +197,9 @@ int MAD2DecodeAndPrint(uint8_t *sector, bool verbose) { if (res) return res; + if (verbose) + PrintAndLogEx(NORMAL, "CRC8-MAD OK."); + uint8_t InfoByte = sector[1] & 0x3f; PrintAndLogEx(NORMAL, "MAD2 Card publisher sector: 0x%02x", InfoByte);