Linux-Crypto Archive on lore.kernel.org
 help / color / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: Christian Eggers <ceggers@arri.de>
Cc: Fabio Estevam <festevam@gmail.com>,
	Martin Kaiser <martin@kaiser.cx>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	linux-kernel@vger.kernel.org, NXP Linux Team <linux-imx@nxp.com>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Matt Mackall <mpm@selenic.com>, Shawn Guo <shawnguo@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH] hwrng: imx-rngc - setup default RNG quality
Date: Tue, 28 Jul 2020 09:48:17 +0200
Message-ID: <20200728074817.hlevn7ex2hckdbvi@pengutronix.de> (raw)
In-Reply-To: <20200727124552.4336-1-ceggers@arri.de>

Hi Christian,

On 20-07-27 14:45, Christian Eggers wrote:
> When hw_random device's quality is non-zero, it will automatically fill
> the kernel's entropy pool at boot.  For this purpose, one conservative
> quality value is being picked up as the default value.

IMHO your value is not conservative enough and the commit message should
explain why we should use 900. Unfortunately I had not enough time to
send my patch addressing this. However please check my commit message
why 900 is not good:

8<------------------------------------------------------------------------
From 9f047eee5e4ce8353c9b764a47e7f584b2013347 Mon Sep 17 00:00:00 2001
From: Marco Felsch <m.felsch@pengutronix.de>
Date: Thu, 7 May 2020 12:01:28 +0200
Subject: [PATCH] hwrng: imx-rngc - add quality to use it as kernel entropy
 pool

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. Befor 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 (4byte) 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);

  reply index

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 10:57 [PATCH] Support for RNGB on i.MX6 ULL Christian Eggers
2020-07-27 10:57 ` [PATCH 1/3] ARM: dts: imx6ull: Add rngb node Christian Eggers
2020-07-27 11:36   ` Fabio Estevam
2020-07-27 12:45     ` [PATCH] hwrng: imx-rngc - setup default RNG quality Christian Eggers
2020-07-28  7:48       ` Marco Felsch [this message]
2020-07-28  8:47         ` Christian Eggers
2020-07-27 10:57 ` [PATCH 2/3] hwrng: imx-rngc - make clock optional Christian Eggers
2020-07-27 10:57 ` [PATCH 3/3] hwrng: imx-rngc - setup default RNG quality Christian Eggers

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=20200728074817.hlevn7ex2hckdbvi@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=arnd@arndb.de \
    --cc=ceggers@arri.de \
    --cc=festevam@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin@kaiser.cx \
    --cc=mpm@selenic.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    /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

Linux-Crypto Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-crypto/0 linux-crypto/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-crypto linux-crypto/ https://lore.kernel.org/linux-crypto \
		linux-crypto@vger.kernel.org
	public-inbox-index linux-crypto

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-crypto


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git