diff mbox

hwrng: core - allow perfect entropy from hardware devices

Message ID 1426663020-10646-1-git-send-email-keithp@keithp.com (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show

Commit Message

Keith Packard March 18, 2015, 7:17 a.m. UTC
Hardware random number quality is measured from 0 (no entropy) to 1024
(perfect entropy). Allow hardware devices to assert the full range by
truncating the device-provided value at 1024 instead of 1023.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 drivers/char/hw_random/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Herbert Xu March 18, 2015, 10:02 a.m. UTC | #1
On Wed, Mar 18, 2015 at 12:17:00AM -0700, Keith Packard wrote:
> Hardware random number quality is measured from 0 (no entropy) to 1024
> (perfect entropy). Allow hardware devices to assert the full range by
> truncating the device-provided value at 1024 instead of 1023.
> 
> Signed-off-by: Keith Packard <keithp@keithp.com>

Patch applied.  Thanks Keith!
diff mbox

Patch

diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 1500cfd..b726683 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -98,7 +98,8 @@  static inline int hwrng_init(struct hwrng *rng)
 	add_early_randomness(rng);
 
 	current_quality = rng->quality ? : default_quality;
-	current_quality &= 1023;
+	if (current_quality > 1024)
+		current_quality = 1024;
 
 	if (current_quality == 0 && hwrng_fill)
 		kthread_stop(hwrng_fill);