A long format (over 37 bits) is sent as a 192-bit frame, a short one as 96.
Extra bits ahead of a preamble decoded as a frame shifted by those bits. If a
preamble pair is the wrong length or not Manchester, try the next pair.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nested and static nested recovery ran lfsr_recovery32 once per nonce and
intersected two ~2^16 candidate lists. The cipher state is linear while the
nonce is fed in, so the states for one nonce are those for the other xored
with a known difference. Checking both keystreams inside a single recovery
leaves about one candidate instead of two large lists.
lfsr_recovery32_dual() does that: it skips the early bit times where the
difference prunes little (start chosen per call from an exact per bit match
probability, falling back to 0 on overflow), scans the first pass 64 states
at a time through a bit packed filter table, extends the tables branch free
in cache sized chunks, and replaces the 512 scattered sort buckets with one
contiguous counting sort.
lfsr_recovery32() is rebuilt on the same machinery, so hf mf sen, mfkey32,
mfkey64 and the nested tools all gain. It stays single threaded because
nested_util.c already calls it from four threads. recover() takes the second
keystream as optional extra state; the plain path is unchanged.
Both return the same key sets as before, verified against the old code under
ASan/UBSan over random and degenerate nonce pairs.
nested per key: ~390 ms -> ~4 ms
lfsr_recovery32 per call: ~270 ms -> ~165 ms
peak RSS, single nonce: 47.6 MB -> 27.6 MB
tools/mfc/protocol links pthread now, as the other two mfc tool dirs do.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
"BWM link baud....... 1500000 bps", "Bootloader BWM link at 921600 baud"
and "PM3 UART serial baudrate: 921600" now read 1.5 Mbps / 921.6 kbps.
sprint_bitrate() next to sprint_bytes() in common/commonutil.c: decimal
units, as line rates go ("9600 bps", "921.6 kbps", "1.5 Mbps").
Built PM5 (OS + bootrom), RDV4 with FLASH, client gcc; clang shows no
warnings on the changed files. Checked on PM5 over USB and WiFi.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"Transfer Speed PM3 -> Client... 1111313 bytes/s" and
"Memory size... 2048 Kb ( 32 pages * 64k )" (Kb is kilobit) now read
"1.06 MB/s" and "2.00 MB ( 32 pages * 64 KB )".
sprint_bytes() in common/commonutil.c formats a byte count in binary
units ("512 bytes", "136.7 KB", "1.07 MB") for the firmware (armsrc
printf.h sprintf) and the client alike.
Built PM5 (OS + bootrom), RDV4 with FLASH, client gcc; clang shows no
new warnings. Checked on PM5: USB 1.04 MB/s, WiFi 137.5 KB/s, 2.00 MB.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Em410xDecode() overloaded *size four ways: the caller's buffer length on
entry, then the preamble repeat period written back by preambleSearch(),
then a format selector, then the decoded length on exit. The value
reaching removeEm410xParity() as the format selector was therefore not
the buffer length, yet that function derived its read length from it and
read blen bits with no bounds check - up to 110 bits from an arbitrary
start index. A demod buffer whose preamble sits near the end is read out
of bounds.
Give each role its own name - buflen, period, fmt - and bound the reads
in removeEm410xParity() on buflen, which is now passed separately. The
*size write on exit is unchanged, so external callers see the same
contract.
The sledge-of-0x05 scan keeps its original window: it is bounded on the
repeat period, not on the buffer, rearranged only to avoid the unsigned
underflow in `x < *size - sizeof(fives)`. Widening it to the whole buffer
would let stray noise select the 80 bit format and silently fail an
otherwise good read.
Verified with a guard-page harness placing a 70 bit array against a
PAGE_NOACCESS boundary with the preamble at index 7: the previous code
faults with 0xC0000005, this returns -6.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A HID SAM driving MIFARE Classic hands over Crypto1 frames as one bit
stream: each byte's 8 data bits LSB first followed by its parity bit.
These convert between that stream and the bytes plus parity array the
PM3 reader and trace code use. Shared so the client can self test them.
Cross checked against a port of Seader's plugin_hf_mfc_transmit for
frames up to 8 bytes (its limit) and for 4 and 18 byte answers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 16/32-bit parity fallbacks folded x but indexed g_odd_byte_parity[256]
with the unmasked value, reading out of bounds. Only reachable with a
compiler that does not define __GNUC__. Found by cppcheck 2.22.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The emitted bit is the running phase, so a shift accepted before the tag answers
toggles curPhase once too often and the rest of the word comes back complemented.
pskFindFirstPhaseShift judged its first measured length, but waveStart starts as
wherever the caller began looking - that length is part of a wave, not a wave,
and any gap beating fc was taken as a shift. Baseline on the first peak instead.
pskRawDemod_ext separately trusted a shift under one bit period in; the clock is
known by then, so look again from a bit period in.
Both are needed - dropping either leaves one of the tags measured inverting on
most reads.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
aggregate_bits sized each run of like waves in bits and then forced a zero to
one. That is right mid-stream, where a run rounding to nothing would drop a bit
the tag did send. On the leading run it is wrong: a single subcarrier wave is
about fchigh samples against a bit period of clk, so it rounds to no bits and
was made into one anyway - a bit the tag never sent, shifting every bit after it
and dragging startIdx back by most of a bit period.
Skip a leading run that rounds to nothing and let the next transition be first.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The samples before the first level change were counted as bits, and where no
edge arrives inside ten clocks the long-run flush fired first and invented ten
of them out of the quiet lead-in. The count sat on a rounding boundary, so one
sample of jitter in that edge added or dropped a leading bit and rotated the
rest of the word - while startIdx, derived from the same count, held i % clk and
could name no sample.
A level change can only fall on a bit boundary, so start there and report it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Simulation now completes the full exchange with a genuine Paxton reader in
password mode, and crypto mode read/write passes Proxmark-to-Proxmark.
Firmware:
- SOF was one bit period short. The lead-in that compensated for the lost
head half bit was removed and nothing replaced it, so readers rejected
every answer with a second START_AUTH. Default is now 6.
- The edge-detect threshold was latched before being measured, so the value
chosen depended on whether the Proxmark was in a field when sim started.
It is now measured on field entry and re-armed when the reader leaves.
- The percentile walk latched on run-scoped variables, so one attempt made
outside a field poisoned every later one.
- Field loss was detected from TIMESTAMP, which is free-running MCU time and
never stalls. Detect it from receive silence instead.
- Frames of a length the protocol does not have no longer reach the state
machine; our own modulation tail was resetting the session and breaking
every write.
- A dropped edge merges two or three reader bit periods into one gap. Those
bits were discarded; they are now recovered by decomposition, which is what
made crypto mode work (AUTH decode 15% -> 100%).
- Threshold selection is limited to 20 and 32 and settles in under 25 ms.
Client:
- lf hitag info printed a hardcoded 0x06 and reported 'Password mode' for
every tag. It now reads page 3, takes -k (4 bytes password, 6 bytes
crypto), and says so when the config cannot be read.
- lf hitag restore: writes a dump back in dependency order - user pages,
then key material, then config last - validates the config byte, and
prints the credential the tag will require afterwards.
- lf hitag crack2 now reports why it failed instead of a bare 'fail'.
- trace list: bit count moved to its own column, relative mode shows a
Frame Delay Time row rather than renaming Start/End, --frame and -r
rejected together.
Using "data load" on very large trace files (e.g. dumps with 700k samples,
such as COTAG dumps) was causing crashes on some platforms due to stack overflow
since VLA temporary buffers were used.
Replace VLAs in computeSignalProperties() and removeSignalOffset() with
heap-allocated buffers instead.
- Implements mfc_algo_vanderbilt_one() and mfc_algo_vanderbilt_all()
- Generates keys using 'Acces' + block ID pattern (416363657300-4163636573FF)
- Supports all 40 sectors for 4K cards
- Eliminates need for 256+ keys in dictionary file
- Keys generated dynamically on-demand