Skip to contentSkip to conversation

random: do not sign extend bytes for rotation when mixing

PATCH New Jason A. Donenfeld 1 participant 1 message Dec 25, 2021 Random number driver

lore
Share & tools
lore

Jason A. Donenfeld

author maintainer
#0 lore raw

PATCH 1/1 random: do not sign extend bytes for rotation when mixing

By using char instead of unsigned char, certain platforms will sign extend the byte when w = rol32(*bytes++, input_rotate) is called, meaning that bit 7 is overrepresented when mixing. This isn't a real problem (unless the mixer itself is already broken) since it's still invertible, but it's not quite correct either. Fix this by using an explicit unsigned type.

---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/random.c +1 -1
index 99cce575a79c..82db125aaed7 100644
@@ -546,7 +546,7 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
 	unsigned long i, tap1, tap2, tap3, tap4, tap5;
 	int input_rotate;
 	int wordmask = r->poolinfo->poolwords - 1;
-	const char *bytes = in;
+	const unsigned char *bytes = in;
 	__u32 w;
 
 	tap1 = r->poolinfo->tap1;
Signature · 1 line
2.34.1