diff --git a/common/crapto1/crapto1.c b/common/crapto1/crapto1.c index 60ae72dad..4a2e9e791 100644 --- a/common/crapto1/crapto1.c +++ b/common/crapto1/crapto1.c @@ -430,10 +430,13 @@ int nonce_distance(uint32_t from, uint32_t to) { * false = hardend prng */ bool validate_prng_nonce(uint32_t nonce) { - // init prng table: - if (nonce_distance(nonce, nonce) == -1) - return false; - return ((65535 - dist[nonce >> 16] + dist[nonce & 0xffff]) % 65535) == 16; + uint16_t x = nonce >> 16; + x = (x & 0xff) << 8 | x >> 8; + for (uint8_t i = 0; i<16; i++) { + x = x >> 1 | (x ^ x >> 2 ^ x >> 3 ^ x >> 5) << 15; + } + x = (x & 0xff) << 8 | x >> 8; + return x == (nonce & 0xFFFF); } static uint32_t fastfwd[2][8] = {