diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 9255a3a21..9fe55a0ff 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -2028,6 +2028,79 @@ int mfu_get_version_uid(uint8_t *version, uint8_t *uid) { return PM3_SUCCESS; } +// Statistical PRNG check (generic weak-RNG backstop). +// Genuine NXP ULC draws RndB from a hardware TRNG (2^64 space), so it never +// repeats across a realistic batch. The common counterfeits (Giantec +// GT23SC4489, USCUID-UL) use a 16-bit LFSR whose wakeup-timing seed +// concentrates the observed RndB pool to ~2^6.5, so a duplicate appears within +// ~12 authentications. A single collision is therefore proof of a weak PRNG. +// This runs only on the genuine-looking fallthrough below (the known +// counterfeit profiles return earlier), so it is the catch-all for weak-RNG +// clones that match none of those profiles, including future variants. +// Ref: "BREAKMEIFYOUCAN!", eprint.iacr.org/2026/100, Section 11. +#define MFULC_PRNG_SAMPLES 40 +#define MFULC_PRNG_CLEAR 39 // no collision by here => an LFSR pool would have, >99.99% + +static int mfulc_prng_test(uint32_t samples) { + if (samples < 2) { + samples = 2; + } + if (samples > 64) { + samples = 64; + } + + uint8_t rndb[64][8]; + uint32_t got = 0; + + for (uint32_t i = 0; i < samples; i++) { + iso14a_card_select_t card; + if (ul_select(&card) == false) { + continue; + } + uint8_t nonce[11] = {0x00}; + int rl = ulc_requestAuthentication(nonce, sizeof(nonce)); + DropField(); + // response is AF || ek(RndB)[8] || CRC[2]; compare the 8-byte ek(RndB) + if (rl < 9 || nonce[0] != 0xAF) { + continue; + } + memcpy(rndb[got], &nonce[1], 8); + got++; + } + + if (got < 2) { + PrintAndLogEx(INFO, "PRNG......... could not collect nonces (got %u)", got); + return PM3_ESOFT; + } + + uint32_t first_dup = 0; + uint32_t dups = 0; + for (uint32_t i = 0; i < got; i++) { + for (uint32_t j = 0; j < i; j++) { + if (memcmp(rndb[i], rndb[j], 8) == 0) { + if (first_dup == 0) { + first_dup = i + 1; // 1-based draw index + } + dups++; + break; + } + } + } + + if (dups > 0) { + PrintAndLogEx(SUCCESS, "PRNG......... " _RED_("weak") ": repeated RndB (%u dup in %u, first at draw %u)", dups, got, first_dup); + PrintAndLogEx(INFO, " genuine NXP uses a TRNG and never repeats: counterfeit (LFSR) tell"); + return PM3_SUCCESS; + } + + if (got >= MFULC_PRNG_CLEAR) { + PrintAndLogEx(INFO, "PRNG......... no RndB collision in %u nonces, consistent with a genuine TRNG", got); + } else { + PrintAndLogEx(INFO, "PRNG......... no RndB collision in %u nonces (need >= %u for high confidence)", got, (uint32_t)MFULC_PRNG_CLEAR); + } + return PM3_SUCCESS; +} + static int mfulc_fingerprint(void) { iso14a_card_select_t card; PacketResponseNG resp; @@ -2139,6 +2212,9 @@ static int mfulc_fingerprint(void) { } } } + // No known counterfeit profile matched; run the generic weak-PRNG + // backstop before concluding the card is genuine. + mfulc_prng_test(MFULC_PRNG_SAMPLES); PrintAndLogEx(INFO, "likely MF0ICU2"); DropField(); return PM3_SUCCESS;