Skip to content

Commit 67da1c8

Browse files
committed
Make CRC size explicit in some cmd/reply size calculations
1 parent 63392ba commit 67da1c8

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

armsrc/iso14443a.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uin
17641764
} else {
17651765
// first blocks of emu are header
17661766
uint16_t start = (block * 4) + MFU_DUMP_PREFIX_LENGTH;
1767-
uint8_t emdata[MIFARE_BLOCK_SIZE + 2] = {0};
1767+
uint8_t emdata[MIFARE_BLOCK_SIZE + CRC16_SIZE] = {0};
17681768
emlGet(emdata, start, MIFARE_BLOCK_SIZE);
17691769
AddCrc14A(emdata, MIFARE_BLOCK_SIZE);
17701770
EmSendCmd(emdata, sizeof(emdata));
@@ -1783,7 +1783,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uin
17831783
// block1 = 4byte UID.
17841784
p_response = &responses[RESP_INDEX_UIDC1];
17851785
} else { // all other tags (16 byte block tags)
1786-
uint8_t emdata[MIFARE_BLOCK_SIZE + 2] = {0};
1786+
uint8_t emdata[MIFARE_BLOCK_SIZE + CRC16_SIZE] = {0};
17871787
emlGet(emdata, block, MIFARE_BLOCK_SIZE);
17881788
AddCrc14A(emdata, MIFARE_BLOCK_SIZE);
17891789
EmSendCmd(emdata, sizeof(emdata));

armsrc/mifarecmd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,7 +2909,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
29092909
}
29102910

29112911
// read block
2912-
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, sizeof(receivedAnswer), receivedAnswerPar, NULL) != MIFARE_BLOCK_SIZE + 2)) {
2912+
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, blockNo, receivedAnswer, sizeof(receivedAnswer), receivedAnswerPar, NULL) != MIFARE_BLOCK_SIZE + CRC16_SIZE)) {
29132913
if (g_dbglevel >= DBG_ERROR) Dbprintf("read block send command error");
29142914
errormsg = 0;
29152915
break;
@@ -3515,7 +3515,7 @@ void MifareGen3Blk(uint8_t block_len, uint8_t *block) {
35153515

35163516
int retval = PM3_SUCCESS;
35173517
uint8_t block_cmd[5] = { 0x90, 0xf0, 0xcc, 0xcc, 0x10 };
3518-
uint8_t cmdlen = sizeof(block_cmd) + MIFARE_BLOCK_SIZE + 2;
3518+
uint8_t cmdlen = sizeof(block_cmd) + MIFARE_BLOCK_SIZE + CRC16_SIZE;
35193519
uint8_t *cmd = BigBuf_calloc(cmdlen);
35203520

35213521
iso14a_card_select_t *card_info = (iso14a_card_select_t *) BigBuf_calloc(sizeof(iso14a_card_select_t));
@@ -3532,7 +3532,7 @@ void MifareGen3Blk(uint8_t block_len, uint8_t *block) {
35323532

35333533
bool doReselect = false;
35343534
if (block_len < MIFARE_BLOCK_SIZE) {
3535-
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, 0, &cmd[sizeof(block_cmd)], MIFARE_BLOCK_SIZE + 2, NULL, NULL) != MIFARE_BLOCK_SIZE + 2)) {
3535+
if ((mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_READBLOCK, 0, &cmd[sizeof(block_cmd)], MIFARE_BLOCK_SIZE + CRC16_SIZE, NULL, NULL) != MIFARE_BLOCK_SIZE + CRC16_SIZE)) {
35363536
if (g_dbglevel >= DBG_ERROR) Dbprintf("Read manufacturer block failed");
35373537
retval = PM3_ESOFT;
35383538
goto OUT;
@@ -3567,7 +3567,7 @@ void MifareGen3Blk(uint8_t block_len, uint8_t *block) {
35673567
}
35683568
}
35693569

3570-
retval = DoGen3Cmd(cmd, sizeof(block_cmd) + MIFARE_BLOCK_SIZE + 2);
3570+
retval = DoGen3Cmd(cmd, sizeof(block_cmd) + MIFARE_BLOCK_SIZE + CRC16_SIZE);
35713571
}
35723572

35733573
OUT:

armsrc/mifaresim.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *uid, uint16_t
10391039
}
10401040
}
10411041
AddCrc14A(response, MIFARE_BLOCK_SIZE);
1042-
mf_crypto1_encrypt(pcs, response, MIFARE_BLOCK_SIZE + 2, response_par);
1043-
EmSendCmdPar(response, MIFARE_BLOCK_SIZE + 2, response_par);
1042+
mf_crypto1_encrypt(pcs, response, MIFARE_BLOCK_SIZE + CRC16_SIZE, response_par);
1043+
EmSendCmdPar(response, MIFARE_BLOCK_SIZE + CRC16_SIZE, response_par);
10441044
FpgaDisableTracing();
10451045

10461046
if (g_dbglevel >= DBG_EXTENDED) {
@@ -1309,7 +1309,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *uid, uint16_t
13091309
// WRITE BL2
13101310
case MFEMUL_WRITEBL2: {
13111311

1312-
if (receivedCmd_len == MIFARE_BLOCK_SIZE + 2) {
1312+
if (receivedCmd_len == MIFARE_BLOCK_SIZE + CRC16_SIZE) {
13131313

13141314
mf_crypto1_decryptEx(pcs, receivedCmd, receivedCmd_len, receivedCmd_dec);
13151315

common/crc16.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "common.h"
2222

23+
#define CRC16_SIZE 2
2324
#define CRC16_POLY_CCITT 0x1021
2425
#define CRC16_POLY_KERMIT 0x8408
2526
#define CRC16_POLY_LEGIC 0xc6c6 //0x6363

0 commit comments

Comments
 (0)