From 645a4e9d1d7a3e5a3eb2a80f7db6b1745105b208 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 1 May 2019 14:55:14 +0200 Subject: [PATCH] generalize KEYS_IN_BLOCK usage --- client/cmdhfmf.c | 2 +- client/mifare/mifarehost.c | 8 ++------ client/mifare/mifarehost.h | 3 +++ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 8d48245a5..792dc95f3 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -1932,7 +1932,7 @@ static int CmdHF14AMfChk(const char *Cmd) { uint8_t trgKeyType = 0; - uint16_t max_keys = keycnt > ((PM3_CMD_DATA_SIZE - 4) / 6) ? ((PM3_CMD_DATA_SIZE - 4) / 6) : keycnt; + uint16_t max_keys = keycnt > KEYS_IN_BLOCK ? KEYS_IN_BLOCK : keycnt; // time uint64_t t1 = msclock(); diff --git a/client/mifare/mifarehost.c b/client/mifare/mifarehost.c index 16ecc80cd..f9f80aa5c 100644 --- a/client/mifare/mifarehost.c +++ b/client/mifare/mifarehost.c @@ -90,7 +90,7 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) { *key = UINT64_C(-1); uint8_t keyBlock[PM3_CMD_DATA_SIZE]; - uint32_t max_keys = (PM3_CMD_DATA_SIZE - 4) / 6; + uint32_t max_keys = KEYS_IN_BLOCK; for (uint32_t i = 0; i < keycount; i += max_keys) { uint32_t size = keycount - i > max_keys ? max_keys : keycount - i; @@ -227,10 +227,6 @@ int mfCheckKeys_fast(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChunk, // ref: https://github.com/J-Run/mf_key_brute int mfKeyBrute(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint64_t *resultkey) { -#define KEYS_IN_BLOCK ((PM3_CMD_DATA_SIZE - 4) / 6) -#define KEYBLOCK_SIZE (KEYS_IN_BLOCK * 6) -#define CANDIDATE_SIZE (0xFFFF * 6) - uint64_t key64; uint8_t found = false; uint8_t candidates[CANDIDATE_SIZE] = {0x00}; @@ -386,7 +382,7 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint64_t key64 = -1; // The list may still contain several key candidates. Test each of them with mfCheckKeys - uint32_t max_keys = keycnt > ((PM3_CMD_DATA_SIZE - 4) / 6) ? ((PM3_CMD_DATA_SIZE - 4) / 6) : keycnt; + uint32_t max_keys = keycnt > KEYS_IN_BLOCK ? KEYS_IN_BLOCK : keycnt; uint8_t keyBlock[PM3_CMD_DATA_SIZE] = {0x00}; for (i = 0; i < keycnt; i += max_keys) { diff --git a/client/mifare/mifarehost.h b/client/mifare/mifarehost.h index fd3935d41..90837bcf7 100644 --- a/client/mifare/mifarehost.h +++ b/client/mifare/mifarehost.h @@ -68,6 +68,9 @@ typedef struct { } icesector_t; extern char logHexFileName[FILE_PATH_SIZE]; +#define KEYS_IN_BLOCK ((PM3_CMD_DATA_SIZE - 4) / 6) +#define KEYBLOCK_SIZE (KEYS_IN_BLOCK * 6) +#define CANDIDATE_SIZE (0xFFFF * 6) int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key); int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *resultKey, bool calibrate);