All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: martin@kaiser.cx, prasannatsmkumar@gmail.com, linux-imx@nxp.com,
	festevam@gmail.com, herbert@gondor.apana.org.au, mpm@selenic.com,
	Anson.Huang@nxp.com, horia.geanta@nxp.com, arnd@arndb.de,
	ceggers@arri.de
Cc: linux-crypto@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de
Subject: [PATCH] hwrng: imx-rngc - add quality to use it as kernel entropy pool
Date: Mon, 31 Aug 2020 16:00:42 +0200	[thread overview]
Message-ID: <20200831140042.2049-1-m.felsch@pengutronix.de> (raw)

The RM describes the RNGB as follow:
8<----------------------------------------------------------------
The RNGB uses the True Random Number Generator (TRNG) and a
Pseudo-Random Number Generator (PRNG) to achieve a true randomness and
cryptographic strength.
8<----------------------------------------------------------------

The RNGB has 3 operation modes: self-test, seed-generation and the final
'random number generation' mode. Before we can retrieve random numbers
from the RNGB we need to generate the seed pool:
8<----------------------------------------------------------------
During the seed generation, the RNGB adds the entropy generated in the
TRNG to the 256-bit XKEY register. The PRNG algorithm executes 20.000
entropy samples from the TRNG to create an initial seed for the random
number generation.
8<----------------------------------------------------------------

The RNGB can generate 2^20 words (1 word == 4 byte) of 'random' data
after the seed pool was initialized. The pool needs to be reseeded if
more words are required. The reseeding is done automatically since
commit 3acd9ea9331c ("hwrng: imx-rngc - use automatic seeding").

We can't retrieve the TRNG values directly so we need a other way to get
the quality level. We know that the PRNG uses 20.000 entropy samples
from the TRNG to generate 2^20 words (1MiB) and the quality level is
defined as (in bits of entropy per 1024 bits of input). So the quality
level can be calculated by:

   20.000 * 1024
   ------------- = ~ 19.5
        2^20

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/char/hw_random/imx-rngc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
index 9c47e431ce90..61c844baf26e 100644
--- a/drivers/char/hw_random/imx-rngc.c
+++ b/drivers/char/hw_random/imx-rngc.c
@@ -285,6 +285,7 @@ static int imx_rngc_probe(struct platform_device *pdev)
 	rngc->rng.init = imx_rngc_init;
 	rngc->rng.read = imx_rngc_read;
 	rngc->rng.cleanup = imx_rngc_cleanup;
+	rngc->rng.quality = 19;
 
 	rngc->dev = &pdev->dev;
 	platform_set_drvdata(pdev, rngc);
-- 
2.20.1


WARNING: multiple messages have this Message-ID (diff)
From: Marco Felsch <m.felsch@pengutronix.de>
To: martin@kaiser.cx, prasannatsmkumar@gmail.com, linux-imx@nxp.com,
	festevam@gmail.com, herbert@gondor.apana.org.au, mpm@selenic.com,
	Anson.Huang@nxp.com, horia.geanta@nxp.com, arnd@arndb.de,
	ceggers@arri.de
Cc: kernel@pengutronix.de, linux-crypto@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH] hwrng: imx-rngc - add quality to use it as kernel entropy pool
Date: Mon, 31 Aug 2020 16:00:42 +0200	[thread overview]
Message-ID: <20200831140042.2049-1-m.felsch@pengutronix.de> (raw)

The RM describes the RNGB as follow:
8<----------------------------------------------------------------
The RNGB uses the True Random Number Generator (TRNG) and a
Pseudo-Random Number Generator (PRNG) to achieve a true randomness and
cryptographic strength.
8<----------------------------------------------------------------

The RNGB has 3 operation modes: self-test, seed-generation and the final
'random number generation' mode. Before we can retrieve random numbers
from the RNGB we need to generate the seed pool:
8<----------------------------------------------------------------
During the seed generation, the RNGB adds the entropy generated in the
TRNG to the 256-bit XKEY register. The PRNG algorithm executes 20.000
entropy samples from the TRNG to create an initial seed for the random
number generation.
8<----------------------------------------------------------------

The RNGB can generate 2^20 words (1 word == 4 byte) of 'random' data
after the seed pool was initialized. The pool needs to be reseeded if
more words are required. The reseeding is done automatically since
commit 3acd9ea9331c ("hwrng: imx-rngc - use automatic seeding").

We can't retrieve the TRNG values directly so we need a other way to get
the quality level. We know that the PRNG uses 20.000 entropy samples
from the TRNG to generate 2^20 words (1MiB) and the quality level is
defined as (in bits of entropy per 1024 bits of input). So the quality
level can be calculated by:

   20.000 * 1024
   ------------- = ~ 19.5
        2^20

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/char/hw_random/imx-rngc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
index 9c47e431ce90..61c844baf26e 100644
--- a/drivers/char/hw_random/imx-rngc.c
+++ b/drivers/char/hw_random/imx-rngc.c
@@ -285,6 +285,7 @@ static int imx_rngc_probe(struct platform_device *pdev)
 	rngc->rng.init = imx_rngc_init;
 	rngc->rng.read = imx_rngc_read;
 	rngc->rng.cleanup = imx_rngc_cleanup;
+	rngc->rng.quality = 19;
 
 	rngc->dev = &pdev->dev;
 	platform_set_drvdata(pdev, rngc);
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2020-08-31 14:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31 14:00 Marco Felsch [this message]
2020-08-31 14:00 ` [PATCH] hwrng: imx-rngc - add quality to use it as kernel entropy pool Marco Felsch
2020-09-11  6:57 ` Herbert Xu
2020-09-11  6:57   ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200831140042.2049-1-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=Anson.Huang@nxp.com \
    --cc=arnd@arndb.de \
    --cc=ceggers@arri.de \
    --cc=festevam@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=martin@kaiser.cx \
    --cc=mpm@selenic.com \
    --cc=prasannatsmkumar@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.