diff --git a/CHANGELOG.md b/CHANGELOG.md index 51c108698..5feb24eb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Fixed `hf mfu cchk` - now 3-pass key check all keys sent to device (@iceman1001) - Changed iso15693 on device side to share one response buffer across the reader helpers (@iceman1001) - Changed version data on device side to not be inlined, freeing 1.5kB of stack in the main loop (@iceman1001) - Changed `lf pcf7931` - now use bigbuf_calloc and much smaller array (@iceman1001) diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 43d1c7c94..aa36402ad 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -4422,8 +4422,6 @@ static int mfu_3pass_load_keys(uint8_t **pkeyBlock, uint32_t *pkeycnt, const cha return PM3_SUCCESS; } -#define MIFAREU3P_CHKKEY_HEADER (3 + MIFAREU3P_KEY_SIZE) - static int mfu_3pass_check_keys(uint8_t key_index, uint8_t firstChunk, uint8_t lastChunk, uint32_t nkeys, int segment, uint8_t *ref_key, bool xor_ref_key, uint8_t *keyBlock, bool verbose, bool quiet, uint32_t *auths, uint32_t *ms, bool check_answer, bool use_fastread0) { @@ -4784,8 +4782,12 @@ static int CmdHF14AMfUCAuthChk(const char *Cmd) { return PM3_ESOFT; } - uint32_t chunksize = (keycnt > (PM3_CMD_DATA_SIZE - MIFAREU3P_CHKKEY_HEADER) / keysize) ? - ((PM3_CMD_DATA_SIZE - MIFAREU3P_CHKKEY_HEADER) / keysize) : keycnt; + // cap by what fits in one frame, then by what the nkeys field can announce + uint32_t max_chunk = (PM3_CMD_DATA_SIZE - MIFAREU3P_CHKKEY_HEADER) / keysize; + if (max_chunk > MIFAREU3P_CHKKEY_MAX_KEYS) { + max_chunk = MIFAREU3P_CHKKEY_MAX_KEYS; + } + uint32_t chunksize = (keycnt > max_chunk) ? max_chunk : keycnt; bool firstChunk = true, lastChunk = false; int i = 0; @@ -4999,8 +5001,12 @@ static int CmdHF14AMfUAESAuthChk(const char *Cmd) { return PM3_ESOFT; } - uint32_t chunksize = (keycnt > (PM3_CMD_DATA_SIZE - MIFAREU3P_CHKKEY_HEADER) / keysize) ? - ((PM3_CMD_DATA_SIZE - MIFAREU3P_CHKKEY_HEADER) / keysize) : keycnt; + // cap by what fits in one frame, then by what the nkeys field can announce + uint32_t max_chunk = (PM3_CMD_DATA_SIZE - MIFAREU3P_CHKKEY_HEADER) / keysize; + if (max_chunk > MIFAREU3P_CHKKEY_MAX_KEYS) { + max_chunk = MIFAREU3P_CHKKEY_MAX_KEYS; + } + uint32_t chunksize = (keycnt > max_chunk) ? max_chunk : keycnt; bool firstChunk = true, lastChunk = false; int i = 0; diff --git a/include/pm3_cmd.h b/include/pm3_cmd.h index 84484394c..6925a30b9 100644 --- a/include/pm3_cmd.h +++ b/include/pm3_cmd.h @@ -597,8 +597,11 @@ typedef struct { enum { MIFAREU3P_KEY_SIZE = 16, - MIFAREU3P_CHKKEY_HEADER = 2 + MIFAREU3P_KEY_SIZE + // 2 bitfield bytes + a whole byte for nkeys + the reference key + MIFAREU3P_CHKKEY_HEADER = 3 + MIFAREU3P_KEY_SIZE, + MIFAREU3P_CHKKEY_MAX_KEYS = 255 }; + typedef struct { uint8_t key_index : 2; uint8_t firstchunk : 1; @@ -607,8 +610,10 @@ typedef struct { uint8_t segment : 3; uint8_t check_answer : 1; uint8_t use_fastread0 : 1; - // max nkeys: (PM3_CMD_DATA_SIZE - MIFAREU3P_CHKKEY_HEADER) / MIFAREU3P_KEY_SIZE < 32 - uint8_t nkeys : 6; + // a whole byte: a 6 bit field could not announce the 123 keys that already + // fit in one frame in segment mode. Callers still clamp to + // MIFAREU3P_CHKKEY_MAX_KEYS, which binds again above ~1040 byte frames. + uint8_t nkeys; uint8_t ref_key[MIFAREU3P_KEY_SIZE]; uint8_t data[PM3_CMD_DATA_SIZE - MIFAREU3P_CHKKEY_HEADER]; } PACKED mful_3passchk_t;