Skip to content

Commit b2c618c

Browse files
George Spelvingregkh
authored andcommitted
random: Fix fast_mix() function
commit 19acc77 upstream. There was a bad typo in commit 43759d4 ("random: use an improved fast_mix() function") and I didn't notice because it "looked right", so I saw what I expected to see when I reviewed it. Only months later did I look and notice it's not the Threefish-inspired mix function that I had designed and optimized. Mea Culpa. Each input bit still has a chance to affect each output bit, and the fast pool is spilled *long* before it fills, so it's not a total disaster, but it's definitely not the intended great improvement. I'm still working on finding better rotation constants. These are good enough, but since it's unrolled twice, it's possible to get better mixing for free by using eight different constants rather than repeating the same four. Signed-off-by: George Spelvin <linux@horizon.com> Cc: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8b602c5 commit b2c618c

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎drivers/char/random.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,19 +569,19 @@ static void fast_mix(struct fast_pool *f)
569569
__u32 c = f->pool[2], d = f->pool[3];
570570

571571
a += b; c += d;
572-
b = rol32(a, 6); d = rol32(c, 27);
572+
b = rol32(b, 6); d = rol32(d, 27);
573573
d ^= a; b ^= c;
574574

575575
a += b; c += d;
576-
b = rol32(a, 16); d = rol32(c, 14);
576+
b = rol32(b, 16); d = rol32(d, 14);
577577
d ^= a; b ^= c;
578578

579579
a += b; c += d;
580-
b = rol32(a, 6); d = rol32(c, 27);
580+
b = rol32(b, 6); d = rol32(d, 27);
581581
d ^= a; b ^= c;
582582

583583
a += b; c += d;
584-
b = rol32(a, 16); d = rol32(c, 14);
584+
b = rol32(b, 16); d = rol32(d, 14);
585585
d ^= a; b ^= c;
586586

587587
f->pool[0] = a; f->pool[1] = b;

0 commit comments

Comments
 (0)