hf mf hardnested: fix the nonce reply length, 9 bytes per pair not 4 per nonce
Thanks @TheArchitect0880 for pointing it out and suggested a first fix. MifareAcquireEncryptedNonces packs two 4 byte encrypted nonces plus one byte holding both their encrypted parity nibbles into every entry, but the reply declared num_nonces * 4 bytes. The client walks that buffer 9 bytes at a time, so on RDV4 it read 612 bytes out of a 544 byte payload and handed roughly 15 of every 136 nonces to add_nonce() from stale packet buffer content. Those fake nonces went into the .bin nonce file too. Count pairs instead of bytes. num_nonces now reports whole pairs only, so a button abort or a static nonce bailout part way through a pair drops the dangling nonce rather than shipping a half built entry whose parity nibble was never filled in. MFC_NONCE_PAIR_SIZE and MFC_MAX_NONCE_PAIRS document the layout next to mf_nonces_resp_t so the 9 vs 4 confusion cannot come back, and the client now refuses a reply too short for the nonce count it carries. Both acquisition functions collect straight into the reply buffer rather than a second PM3_CMD_DATA_SIZE stack array, which halves the stack used per call. MifareAcquireNonces also returned isOK = 2 on button press, which is not a PM3_* status; that is PM3_EOPABORTED now. Co-Authored-By: Claude Opus 5 (1M context)
This commit is contained in:
1 parent
5ca15e4587
commit
6341f40b4c
4 files changed
+53
-24
No files matched your search
@@ -541,6 +541,14 @@ typedef struct {
|
||||
// most 4 byte nonces that fit alongside the reply header in one frame
|
||||
#define MFC_MAX_NONCES ((PM3_CMD_DATA_SIZE - sizeof(mf_nonces_resp_t)) / 4)
|
||||
|
||||
// ACQ_ENCRYPTED_NONCES does not store bare nonces. It stores pairs: two 4 byte
|
||||
// encrypted nonces followed by one byte holding both their encrypted parity
|
||||
// nibbles, high nibble first. num_nonces in the reply counts nonces, so the
|
||||
// payload is always (num_nonces / 2) * MFC_NONCE_PAIR_SIZE bytes and
|
||||
// num_nonces is always even.
|
||||
#define MFC_NONCE_PAIR_SIZE 9
|
||||
#define MFC_MAX_NONCE_PAIRS ((PM3_CMD_DATA_SIZE - sizeof(mf_nonces_resp_t)) / MFC_NONCE_PAIR_SIZE)
|
||||
|
||||
// CMD_HF_MIFARE_CHKKEYS_FAST payload.
|
||||
// Replaces three bit-packed oldargs:
|
||||
// arg0 = sectorcnt | firstchunk<<8 | lastchunk<<12 | singlesector_params<<16
|
||||
|
||||
Reference in new issue
Block a user