Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1691073 > unrolled thread

[PATCH v1] crypto: caam - set hwrng quality level

Started byOleksij Rempel <o.rempel@pengutronix.de>
First post2017-07-19 09:50 +0200
Last post2017-07-20 15:10 +0200
Articles 6 — 4 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v1] crypto: caam - set hwrng quality level Oleksij Rempel <o.rempel@pengutronix.de> - 2017-07-19 09:50 +0200
    Re: [PATCH v1] crypto: caam - set hwrng quality level Horia Geantă <horia.geanta@nxp.com> - 2017-07-19 15:00 +0200
      Re: [PATCH v1] crypto: caam - set hwrng quality level Oleksij Rempel <ore@pengutronix.de> - 2017-07-19 18:40 +0200
        Re: [PATCH v1] crypto: caam - set hwrng quality level Horia Geantă <horia.geanta@nxp.com> - 2017-07-19 19:00 +0200
          Re: [PATCH v1] crypto: caam - set hwrng quality level Oleksij Rempel <ore@pengutronix.de> - 2017-07-19 20:20 +0200
            Re: [PATCH v1] crypto: caam - set hwrng quality level Harald Freudenberger <freude@linux.vnet.ibm.com> - 2017-07-20 15:10 +0200

#1691073 — [PATCH v1] crypto: caam - set hwrng quality level

FromOleksij Rempel <o.rempel@pengutronix.de>
Date2017-07-19 09:50 +0200
Subject[PATCH v1] crypto: caam - set hwrng quality level
Message-ID<u4RU6-5ro-19@gated-at.bofh.it>
According documentation, it is NIST certified TRNG.
So, set high quality to let the HWRNG framework automatically use it.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/crypto/caam/caamrng.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
index 41398da3edf4..684c0bc88dfd 100644
--- a/drivers/crypto/caam/caamrng.c
+++ b/drivers/crypto/caam/caamrng.c
@@ -292,10 +292,16 @@ static int caam_init_rng(struct caam_rng_ctx *ctx, struct device *jrdev)
 	return 0;
 }
 
+/*
+ * hwrng register struct
+ * The trng is suppost to have 100% entropy, and thus
+ * we register with a very high quality value.
+ */
 static struct hwrng caam_rng = {
 	.name		= "rng-caam",
 	.cleanup	= caam_cleanup,
 	.read		= caam_read,
+	.quality	= 999,
 };
 
 static void __exit caam_rng_exit(void)
-- 
2.11.0

[toc] | [next] | [standalone]


#1691664

FromHoria Geantă <horia.geanta@nxp.com>
Date2017-07-19 15:00 +0200
Message-ID<u4WK7-fH-43@gated-at.bofh.it>
In reply to#1691073
On 7/19/2017 10:45 AM, Oleksij Rempel wrote:
> According documentation, it is NIST certified TRNG.
> So, set high quality to let the HWRNG framework automatically use it.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/crypto/caam/caamrng.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
> index 41398da3edf4..684c0bc88dfd 100644
> --- a/drivers/crypto/caam/caamrng.c
> +++ b/drivers/crypto/caam/caamrng.c
> @@ -292,10 +292,16 @@ static int caam_init_rng(struct caam_rng_ctx *ctx, struct device *jrdev)
>  	return 0;
>  }
>  
> +/*
> + * hwrng register struct
> + * The trng is suppost to have 100% entropy, and thus
> + * we register with a very high quality value.
> + */
>  static struct hwrng caam_rng = {
>  	.name		= "rng-caam",
>  	.cleanup	= caam_cleanup,
>  	.read		= caam_read,
> +	.quality	= 999,

Why not 1024, i.e. where is 999 coming from?

Thanks,
Horia

[toc] | [prev] | [next] | [standalone]


#1692020

FromOleksij Rempel <ore@pengutronix.de>
Date2017-07-19 18:40 +0200
Message-ID<u50b1-2KR-27@gated-at.bofh.it>
In reply to#1691664
On Wed, Jul 19, 2017 at 12:49:47PM +0000, Horia Geantă wrote:
> On 7/19/2017 10:45 AM, Oleksij Rempel wrote:
> > According documentation, it is NIST certified TRNG.
> > So, set high quality to let the HWRNG framework automatically use it.
> > 
> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > ---
> >  drivers/crypto/caam/caamrng.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
> > index 41398da3edf4..684c0bc88dfd 100644
> > --- a/drivers/crypto/caam/caamrng.c
> > +++ b/drivers/crypto/caam/caamrng.c
> > @@ -292,10 +292,16 @@ static int caam_init_rng(struct caam_rng_ctx *ctx, struct device *jrdev)
> >  	return 0;
> >  }
> >  
> > +/*
> > + * hwrng register struct
> > + * The trng is suppost to have 100% entropy, and thus
> > + * we register with a very high quality value.
> > + */
> >  static struct hwrng caam_rng = {
> >  	.name		= "rng-caam",
> >  	.cleanup	= caam_cleanup,
> >  	.read		= caam_read,
> > +	.quality	= 999,
> 
> Why not 1024, i.e. where is 999 coming from?

It comes from s390-trng.c driver.
Should I use 1024 instead?

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[toc] | [prev] | [next] | [standalone]


#1692032

FromHoria Geantă <horia.geanta@nxp.com>
Date2017-07-19 19:00 +0200
Message-ID<u50un-2TW-35@gated-at.bofh.it>
In reply to#1692020
On 7/19/2017 7:32 PM, Oleksij Rempel wrote:
> On Wed, Jul 19, 2017 at 12:49:47PM +0000, Horia Geantă wrote:
>> On 7/19/2017 10:45 AM, Oleksij Rempel wrote:
>>> According documentation, it is NIST certified TRNG.
>>> So, set high quality to let the HWRNG framework automatically use it.
>>>
>>> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
>>> ---
>>>  drivers/crypto/caam/caamrng.c | 6 ++++++
>>>  1 file changed, 6 insertions(+)
>>>
>>> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
>>> index 41398da3edf4..684c0bc88dfd 100644
>>> --- a/drivers/crypto/caam/caamrng.c
>>> +++ b/drivers/crypto/caam/caamrng.c
>>> @@ -292,10 +292,16 @@ static int caam_init_rng(struct caam_rng_ctx *ctx, struct device *jrdev)
>>>  	return 0;
>>>  }
>>>  
>>> +/*
>>> + * hwrng register struct
>>> + * The trng is suppost to have 100% entropy, and thus
>>> + * we register with a very high quality value.
>>> + */
>>>  static struct hwrng caam_rng = {
>>>  	.name		= "rng-caam",
>>>  	.cleanup	= caam_cleanup,
>>>  	.read		= caam_read,
>>> +	.quality	= 999,
>>
>> Why not 1024, i.e. where is 999 coming from?
> 
> It comes from s390-trng.c driver.
> Should I use 1024 instead?
> 
AFAICT the range for quality is from 0 to 1024 (no entropy -> perfect
entropy).

1024 should be used since I'd expect a HW TRNG to provide perfect
entropy unless otherwise stated.

[Cc-ing Harald and Martin for awareness wrt. s390/trng.]

Thanks,
Horia

[toc] | [prev] | [next] | [standalone]


#1692084

FromOleksij Rempel <ore@pengutronix.de>
Date2017-07-19 20:20 +0200
Message-ID<u51JM-3Ue-27@gated-at.bofh.it>
In reply to#1692032
On Wed, Jul 19, 2017 at 04:53:21PM +0000, Horia Geantă wrote:
> On 7/19/2017 7:32 PM, Oleksij Rempel wrote:
> > On Wed, Jul 19, 2017 at 12:49:47PM +0000, Horia Geantă wrote:
> >> On 7/19/2017 10:45 AM, Oleksij Rempel wrote:
> >>> According documentation, it is NIST certified TRNG.
> >>> So, set high quality to let the HWRNG framework automatically use it.
> >>>
> >>> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> >>> ---
> >>>  drivers/crypto/caam/caamrng.c | 6 ++++++
> >>>  1 file changed, 6 insertions(+)
> >>>
> >>> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
> >>> index 41398da3edf4..684c0bc88dfd 100644
> >>> --- a/drivers/crypto/caam/caamrng.c
> >>> +++ b/drivers/crypto/caam/caamrng.c
> >>> @@ -292,10 +292,16 @@ static int caam_init_rng(struct caam_rng_ctx *ctx, struct device *jrdev)
> >>>  	return 0;
> >>>  }
> >>>  
> >>> +/*
> >>> + * hwrng register struct
> >>> + * The trng is suppost to have 100% entropy, and thus
> >>> + * we register with a very high quality value.
> >>> + */
> >>>  static struct hwrng caam_rng = {
> >>>  	.name		= "rng-caam",
> >>>  	.cleanup	= caam_cleanup,
> >>>  	.read		= caam_read,
> >>> +	.quality	= 999,
> >>
> >> Why not 1024, i.e. where is 999 coming from?
> > 
> > It comes from s390-trng.c driver.
> > Should I use 1024 instead?
> > 
> AFAICT the range for quality is from 0 to 1024 (no entropy -> perfect
> entropy).
> 
> 1024 should be used since I'd expect a HW TRNG to provide perfect
> entropy unless otherwise stated.

I assume 1024 can be given only on verified HW with accessible verilog
files and compared with resulting chip :)
May be this would be a good example https://www.sifive.com/

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[toc] | [prev] | [next] | [standalone]


#1692913

FromHarald Freudenberger <freude@linux.vnet.ibm.com>
Date2017-07-20 15:10 +0200
Message-ID<u5jnl-7Tm-29@gated-at.bofh.it>
In reply to#1692084
On 07/19/2017 08:13 PM, Oleksij Rempel wrote:
> On Wed, Jul 19, 2017 at 04:53:21PM +0000, Horia Geantă wrote:
>> On 7/19/2017 7:32 PM, Oleksij Rempel wrote:
>>> On Wed, Jul 19, 2017 at 12:49:47PM +0000, Horia Geantă wrote:
>>>> On 7/19/2017 10:45 AM, Oleksij Rempel wrote:
>>>>> According documentation, it is NIST certified TRNG.
>>>>> So, set high quality to let the HWRNG framework automatically use it.
>>>>>
>>>>> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
>>>>> ---
>>>>>  drivers/crypto/caam/caamrng.c | 6 ++++++
>>>>>  1 file changed, 6 insertions(+)
>>>>>
>>>>> diff --git a/drivers/crypto/caam/caamrng.c b/drivers/crypto/caam/caamrng.c
>>>>> index 41398da3edf4..684c0bc88dfd 100644
>>>>> --- a/drivers/crypto/caam/caamrng.c
>>>>> +++ b/drivers/crypto/caam/caamrng.c
>>>>> @@ -292,10 +292,16 @@ static int caam_init_rng(struct caam_rng_ctx *ctx, struct device *jrdev)
>>>>>  	return 0;
>>>>>  }
>>>>>  
>>>>> +/*
>>>>> + * hwrng register struct
>>>>> + * The trng is suppost to have 100% entropy, and thus
>>>>> + * we register with a very high quality value.
>>>>> + */
>>>>>  static struct hwrng caam_rng = {
>>>>>  	.name		= "rng-caam",
>>>>>  	.cleanup	= caam_cleanup,
>>>>>  	.read		= caam_read,
>>>>> +	.quality	= 999,
>>>> Why not 1024, i.e. where is 999 coming from?
>>> It comes from s390-trng.c driver.
>>> Should I use 1024 instead?
>>>
>> AFAICT the range for quality is from 0 to 1024 (no entropy -> perfect
>> entropy).
>>
>> 1024 should be used since I'd expect a HW TRNG to provide perfect
>> entropy unless otherwise stated.
> I assume 1024 can be given only on verified HW with accessible verilog
> files and compared with resulting chip :)
> May be this would be a good example https://www.sifive.com/
>
Well, the header file says:
...
/**
 * struct hwrng - Hardware Random Number Generator driver
 * @name:               Unique RNG name.
 * @init:               Initialization callback (can be NULL).
 * @cleanup:            Cleanup callback (can be NULL).
 * @data_present:       Callback to determine if data is available
 *                      on the RNG. If NULL, it is assumed that
 *                      there is always data available.  *OBSOLETE*
 * @data_read:          Read data from the RNG device.
 *                      Returns the number of lower random bytes in "data".
 *                      Must not be NULL.    *OBSOLETE*
 * @read:               New API. drivers can fill up to max bytes of data
 *                      into the buffer. The buffer is aligned for any type
 *                      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).
 */
...
quality = estimation of true entropy per mill.
I understand this as quality=1000 meaning 100% entropy.
However, the core code currently does not really check this value.
When more than one hwrng sources do register, simple the one with
the higher quality value wins :-) The value is not even checked
to be in a given range.

I searched through some device drivers which do register at
the hwrng and it looks like most of the drivers do not even
set this value. My feeling is, you should use 999 when your
hardware provides 'perfect' random. So there is a chance for
an even 'more perfect' hardware coming up later to overrule
your 'perfect' hardware.

regards
Harald Freudenberger

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web