From 579bafa1619abd01dfd2528a7dc0b87ded86a25b Mon Sep 17 00:00:00 2001 From: Ryan4n6 <131580830+Ryan4n6@users.noreply.github.com> Date: Tue, 3 Nov 2026 03:04:17 -0500 Subject: [PATCH] feat(hf mfu): add weak-PRNG backstop for Ultralight C fingerprint The existing mfulc_fingerprint() detects known counterfeit families (Lab401 DW, Feiju FJ8010, USCUID-UL v1/v2, Giantec GT23SC4489, Hospitality) by their deterministic command and CRC tells, returning early on a match. This commit adds a generic weak-PRNG catch-all for clones that evade those fixed profiles. mfulc_prng_test() runs on the genuine-looking fallthrough, right before the "likely MF0ICU2" verdict. It collects RndB nonces via repeated 1A00 auth starts and flags a duplicate: - Genuine NXP draws RndB from a hardware TRNG (2^64 space), so it never repeats across a realistic batch. - Giantec/USCUID use a 16-bit LFSR whose wakeup-timing seed concentrates the observed pool to roughly 2^6.5, so a duplicate appears within 12 authentications. A single collision is proof of a weak PRNG. This backstop catches weak-RNG clones, including future variants the profile table does not know. MFULC_PRNG_SAMPLES (40) and MFULC_PRNG_CLEAR (39) are tunable. Tested on genuine NXP MF0ULC (UID 04 1C BE 92 E7 7A 80): 40 unique nonces, no collision, verdict "consistent with a genuine TRNG". Ref: "BREAKMEIFYOUCAN!", eprint.iacr.org/2026/100, Section 11. Co-Authored-By: Claude Opus 4.5 Claude-Session: https://claude.ai/code/session_012e7xUDfDUXJQU7SWV3ULS1 --- client/src/cmdhfmfu.c | 76 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) 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;