aboutsummaryrefslogtreecommitdiffstats
path: root/widelfsr.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-01-16 13:42:15 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2022-01-24 16:59:37 +0100
commitadcaee95cce63db00e0d338b4cc4c8d13ef121c4 (patch)
tree41e115318bc5f2afdbd23388dfb2b6c6ce62f06e /widelfsr.c
downloadkbench9000-jd/mix-pool-bytes-comparison.tar.xz
kbench9000-jd/mix-pool-bytes-comparison.zip
Initial scaffoldingjd/mix-pool-bytes-comparison
Diffstat (limited to 'widelfsr.c')
-rw-r--r--widelfsr.c30
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;
+}