'hf mfu cchk' - widen 3-pass chkkey nkeys to a full byte
nkeys was a 6 bit field but the client chunked by what fits in a frame - 123 keys in segment mode. nkeys wrapped to 59 while memcpy copied all 123 and the loop advanced by 123, so 64 of every 123 keys were never tested and never reported. Full key mode was unaffected, it chunks 30. Give nkeys its own byte. MIFAREU3P_CHKKEY_HEADER goes 18 -> 19, costing one byte of payload, and segment mode chunks 123 again Payload layout changed: client and firmware must be updated together. Thanks Claude!
This commit is contained in:
1 parent
25d958e5e6
commit
ed066d84aa
3 files changed
+21
-9
No files matched your search
@@ -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)
|
||||
|
||||
+12
-6
@@ -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;
|
||||
|
||||
+8
-3
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user