From 3d81da6d1ad500cd99ecb81f0ade2d73750d9c0f Mon Sep 17 00:00:00 2001 From: merlokk Date: Wed, 1 Nov 2017 16:18:13 +0200 Subject: [PATCH] added validate_prng_nonce from iceman1001 fork --- common/crapto1/crapto1.c | 11 +++++++++++ common/crapto1/crapto1.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/common/crapto1/crapto1.c b/common/crapto1/crapto1.c index 9398a1f3..b77842e9 100644 --- a/common/crapto1/crapto1.c +++ b/common/crapto1/crapto1.c @@ -426,6 +426,17 @@ int nonce_distance(uint32_t from, uint32_t to) return (65535 + dist[to >> 16] - dist[from >> 16]) % 65535; } +/** validate_prng_nonce + * Determine if nonce is deterministic. ie: Suspectable to Darkside attack. + * returns + * true = weak prng + * false = hardend prng + */ +bool validate_prng_nonce(uint32_t nonce) { + // init prng table: + nonce_distance(nonce, nonce); + return ((65535 - dist[nonce >> 16] + dist[nonce & 0xffff]) % 65535) == 16; +} static uint32_t fastfwd[2][8] = { { 0, 0x4BC53, 0xECB1, 0x450E2, 0x25E29, 0x6E27A, 0x2B298, 0x60ECB}, diff --git a/common/crapto1/crapto1.h b/common/crapto1/crapto1.h index 8e79d224..154e4cc8 100644 --- a/common/crapto1/crapto1.h +++ b/common/crapto1/crapto1.h @@ -20,6 +20,7 @@ #ifndef CRAPTO1_INCLUDED #define CRAPTO1_INCLUDED #include +#include #ifdef __cplusplus extern "C" { #endif @@ -48,6 +49,7 @@ uint8_t lfsr_rollback_bit(struct Crypto1State* s, uint32_t in, int fb); uint8_t lfsr_rollback_byte(struct Crypto1State* s, uint32_t in, int fb); uint32_t lfsr_rollback_word(struct Crypto1State* s, uint32_t in, int fb); int nonce_distance(uint32_t from, uint32_t to); +extern bool validate_prng_nonce(uint32_t nonce); #define FOREACH_VALID_NONCE(N, FILTER, FSIZE)\ uint32_t __n = 0,__M = 0, N = 0;\ int __i;\