linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwrng: document the quality field
@ 2018-09-25 16:35 Michael S. Tsirkin
  2018-10-05  2:27 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Michael S. Tsirkin @ 2018-09-25 16:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: Matt Mackall, Herbert Xu, Arnd Bergmann, Greg Kroah-Hartman,
	matthias.bgg, Liam.Merwick, Jim.Quigley, linux-crypto,
	Cornelia Huck, dgilbert

quality field is currently documented as being 'per mill'.  In fact the
math involved is:

                add_hwgenerator_randomness((void *)rng_fillbuf, rc,
                                           rc * current_quality * 8 >> 10);

thus the actual definition is "bits of entropy per 1024 bits of input".

The current documentation seems to have confused multiple people
in the past, let's fix the documentation to match code.

An alternative is to change core to match driver expectations, replacing
	rc * current_quality * 8 >> 10
with
	rc * current_quality / 1000
but that has performance costs, so probably isn't a good option.

Fixes: 0f734e6e768 ("hwrng: add per-device entropy derating")
Reported-by: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---


 drivers/char/hw_random/core.c | 4 ++--
 include/linux/hw_random.h     | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index aaf9e5afaad4..95be7228f327 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -44,10 +44,10 @@ static unsigned short default_quality; /* = 0; default to "off" */
 
 module_param(current_quality, ushort, 0644);
 MODULE_PARM_DESC(current_quality,
-		 "current hwrng entropy estimation per mill");
+		 "current hwrng entropy estimation per 1024 bits of input");
 module_param(default_quality, ushort, 0644);
 MODULE_PARM_DESC(default_quality,
-		 "default entropy content of hwrng per mill");
+		 "default entropy content of hwrng per 1024 bits of input");
 
 static void drop_current_rng(void);
 static int hwrng_init(struct hwrng *rng);
diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h
index bee0827766a3..c0b93e0ff0c0 100644
--- a/include/linux/hw_random.h
+++ b/include/linux/hw_random.h
@@ -33,7 +33,8 @@
  *			and max is a multiple of 4 and >= 32 bytes.
  * @priv:		Private data, for use by the RNG driver.
  * @quality:		Estimation of true entropy in RNG's bitstream
- *			(per mill).
+ *			(in bits of entropy per 1024 bits of input;
+ *			valid values: 1 to 1024, or 0 for unknown).
  */
 struct hwrng {
 	const char *name;
-- 
MST

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hwrng: document the quality field
  2018-09-25 16:35 [PATCH] hwrng: document the quality field Michael S. Tsirkin
@ 2018-10-05  2:27 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2018-10-05  2:27 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-kernel, Matt Mackall, Arnd Bergmann, Greg Kroah-Hartman,
	matthias.bgg, Liam.Merwick, Jim.Quigley, linux-crypto,
	Cornelia Huck, dgilbert

On Tue, Sep 25, 2018 at 12:35:18PM -0400, Michael S. Tsirkin wrote:
> quality field is currently documented as being 'per mill'.  In fact the
> math involved is:
> 
>                 add_hwgenerator_randomness((void *)rng_fillbuf, rc,
>                                            rc * current_quality * 8 >> 10);
> 
> thus the actual definition is "bits of entropy per 1024 bits of input".
> 
> The current documentation seems to have confused multiple people
> in the past, let's fix the documentation to match code.
> 
> An alternative is to change core to match driver expectations, replacing
> 	rc * current_quality * 8 >> 10
> with
> 	rc * current_quality / 1000
> but that has performance costs, so probably isn't a good option.
> 
> Fixes: 0f734e6e768 ("hwrng: add per-device entropy derating")
> Reported-by: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> 
> 
>  drivers/char/hw_random/core.c | 4 ++--
>  include/linux/hw_random.h     | 3 ++-
>  2 files changed, 4 insertions(+), 3 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-05  2:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-25 16:35 [PATCH] hwrng: document the quality field Michael S. Tsirkin
2018-10-05  2:27 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).