Faster validate_prng_nonce

This commit is contained in:
Philippe Teuwen 2024-07-29 11:54:53 +02:00
commit bd3e8db852

View file

@ -430,10 +430,13 @@ int nonce_distance(uint32_t from, uint32_t to) {
* false = hardend prng * false = hardend prng
*/ */
bool validate_prng_nonce(uint32_t nonce) { bool validate_prng_nonce(uint32_t nonce) {
// init prng table: uint16_t x = nonce >> 16;
if (nonce_distance(nonce, nonce) == -1) x = (x & 0xff) << 8 | x >> 8;
return false; for (uint8_t i = 0; i<16; i++) {
return ((65535 - dist[nonce >> 16] + dist[nonce & 0xffff]) % 65535) == 16; 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] = { static uint32_t fastfwd[2][8] = {