diff options
Diffstat (limited to 'widelfsr.c')
-rw-r--r-- | widelfsr.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/widelfsr.c b/widelfsr.c new file mode 100644 index 0000000..088ec7e --- /dev/null +++ b/widelfsr.c @@ -0,0 +1,30 @@ +#include <linux/kernel.h> + +enum poolinfo { + POOL_WORDS = 128, + POOL_WORDMASK = POOL_WORDS - 1, + POOL_BITS = POOL_WORDS * sizeof(u32) * 8, +}; + +static u32 input_pool_data[POOL_WORDS]; + +static struct { + u16 add_ptr; +} input_pool = { 0 }; + +void mix_widelfsr(const void *in, int nbytes) +{ + unsigned long i = input_pool.add_ptr; + const u8 *src = in; + + /* Mix one byte at a time to simplify size handling and churn faster. */ + while (nbytes--) { + input_pool_data[(i+0)&127] = rol32(input_pool_data[(i+0)&127], 4) ^ + (input_pool_data[(i+126)&127] << 7) ^ + rol32(input_pool_data[(i+127)&127],12) ^ + rol32(input_pool_data[(i+127)&127],21) ^ + *src++; + i = (i+1)&127; + } + input_pool.add_ptr = i; +} |