linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Support for RNGB on i.MX6 ULL
@ 2020-07-27 10:57 Christian Eggers
  2020-07-27 10:57 ` [PATCH 1/3] ARM: dts: imx6ull: Add rngb node Christian Eggers
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christian Eggers @ 2020-07-27 10:57 UTC (permalink / raw)
  To: Rob Herring, Shawn Guo, Sascha Hauer
  Cc: Pengutronix Kernel Team, Fabio Estevam, NXP Linux Team,
	Matt Mackall, Herbert Xu, Arnd Bergmann, Greg Kroah-Hartman,
	Martin Kaiser, PrasannaKumar Muralidharan, Christian Eggers,
	Dong Aisheng, Anson Huang, devicetree, linux-arm-kernel,
	linux-kernel, linux-crypto

This small series adds support for the Random Number Generator on 
the i.MX6 ULL SoC.



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

* [PATCH 1/3] ARM: dts: imx6ull: Add rngb node
  2020-07-27 10:57 [PATCH] Support for RNGB on i.MX6 ULL Christian Eggers
@ 2020-07-27 10:57 ` Christian Eggers
  2020-07-27 11:36   ` Fabio Estevam
  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
  2 siblings, 1 reply; 8+ messages in thread
From: Christian Eggers @ 2020-07-27 10:57 UTC (permalink / raw)
  To: Rob Herring, Shawn Guo, Sascha Hauer
  Cc: Christian Eggers, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Matt Mackall, Herbert Xu, Arnd Bergmann,
	Greg Kroah-Hartman, Martin Kaiser, PrasannaKumar Muralidharan,
	Anson Huang, devicetree, linux-arm-kernel, linux-kernel,
	linux-crypto

The RNGB block on 6ull has no major differences, but it has no
switchable clock.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 arch/arm/boot/dts/imx6ull.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/imx6ull.dtsi b/arch/arm/boot/dts/imx6ull.dtsi
index fcde7f77ae42..3d021b304a83 100644
--- a/arch/arm/boot/dts/imx6ull.dtsi
+++ b/arch/arm/boot/dts/imx6ull.dtsi
@@ -68,6 +68,12 @@ dcp: crypto@2280000 {
 				clock-names = "dcp";
 			};
 
+			rngb: rng@2284000 {
+				compatible = "fsl,imx6ull-dcp", "fsl,imx25-rngb";
+				reg = <0x02284000 0x4000>;
+				interrupts = <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>;
+			};
+
 			iomuxc_snvs: iomuxc-snvs@2290000 {
 				compatible = "fsl,imx6ull-iomuxc-snvs";
 				reg = <0x02290000 0x4000>;
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


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

* [PATCH 2/3] hwrng: imx-rngc - make clock optional
  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 10:57 ` Christian Eggers
  2020-07-27 10:57 ` [PATCH 3/3] hwrng: imx-rngc - setup default RNG quality Christian Eggers
  2 siblings, 0 replies; 8+ messages in thread
From: Christian Eggers @ 2020-07-27 10:57 UTC (permalink / raw)
  To: Rob Herring, Shawn Guo, Sascha Hauer
  Cc: Christian Eggers, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Matt Mackall, Herbert Xu, Arnd Bergmann,
	Greg Kroah-Hartman, Martin Kaiser, PrasannaKumar Muralidharan,
	Anson Huang, devicetree, linux-arm-kernel, linux-kernel,
	linux-crypto

On i.MX6 ULL the RNGB has no switchable clock.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 drivers/char/hw_random/imx-rngc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
index 9c47e431ce90..f9c5ddd0276b 100644
--- a/drivers/char/hw_random/imx-rngc.c
+++ b/drivers/char/hw_random/imx-rngc.c
@@ -245,7 +245,7 @@ static int imx_rngc_probe(struct platform_device *pdev)
 	if (IS_ERR(rngc->base))
 		return PTR_ERR(rngc->base);
 
-	rngc->clk = devm_clk_get(&pdev->dev, NULL);
+	rngc->clk = devm_clk_get_optional(&pdev->dev, NULL);
 	if (IS_ERR(rngc->clk)) {
 		dev_err(&pdev->dev, "Can not get rng_clk\n");
 		return PTR_ERR(rngc->clk);
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


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

* [PATCH 3/3] hwrng: imx-rngc - setup default RNG quality
  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 10:57 ` [PATCH 2/3] hwrng: imx-rngc - make clock optional Christian Eggers
@ 2020-07-27 10:57 ` Christian Eggers
  2 siblings, 0 replies; 8+ messages in thread
From: Christian Eggers @ 2020-07-27 10:57 UTC (permalink / raw)
  To: Rob Herring, Shawn Guo, Sascha Hauer
  Cc: Christian Eggers, Pengutronix Kernel Team, Fabio Estevam,
	NXP Linux Team, Matt Mackall, Herbert Xu, Arnd Bergmann,
	Greg Kroah-Hartman, Martin Kaiser, PrasannaKumar Muralidharan,
	Anson Huang, devicetree, linux-arm-kernel, linux-kernel,
	linux-crypto

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.

Signed-off-by: Christian Eggers <ceggers@arri.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 f9c5ddd0276b..a62ff78bd7ea 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 = 900;
 
 	rngc->dev = &pdev->dev;
 	platform_set_drvdata(pdev, rngc);
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


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

* Re: [PATCH 1/3] ARM: dts: imx6ull: Add rngb node
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Fabio Estevam @ 2020-07-27 11:36 UTC (permalink / raw)
  To: Christian Eggers, Horia Geanta Neag
  Cc: Rob Herring, Shawn Guo, Sascha Hauer, Pengutronix Kernel Team,
	NXP Linux Team, Matt Mackall, Herbert Xu, Arnd Bergmann,
	Greg Kroah-Hartman, Martin Kaiser, PrasannaKumar Muralidharan,
	Anson Huang,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-kernel, open list:HARDWARE RANDOM NUMBER GENERATOR CORE

Hi Christian,

On Mon, Jul 27, 2020 at 8:00 AM Christian Eggers <ceggers@arri.de> wrote:
>
> The RNGB block on 6ull has no major differences, but it has no
> switchable clock.

Horia has already sent a patch series that adds imx6ull rngb support:
https://lkml.org/lkml/2020/7/23/173

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

* [PATCH] hwrng: imx-rngc - setup default RNG quality
  2020-07-27 11:36   ` Fabio Estevam
@ 2020-07-27 12:45     ` Christian Eggers
  2020-07-28  7:48       ` Marco Felsch
  0 siblings, 1 reply; 8+ messages in thread
From: Christian Eggers @ 2020-07-27 12:45 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Matt Mackall, Herbert Xu, Arnd Bergmann, Greg Kroah-Hartman,
	Shawn Guo, Sascha Hauer, Pengutronix Kernel Team, NXP Linux Team,
	Martin Kaiser, linux-crypto, linux-arm-kernel, linux-kernel,
	Christian Eggers

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.

Signed-off-by: Christian Eggers <ceggers@arri.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 f9c5ddd0276b..a62ff78bd7ea 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 = 900;
 
 	rngc->dev = &pdev->dev;
 	platform_set_drvdata(pdev, rngc);
-- 
On Mon, Jul 27, 2020 Fabian Estevam wrote:
> Horia has already sent a patch series that adds imx6ull rngb support:
> https://lkml.org/lkml/2020/7/23/173

That happens when patches are sent upstream one year after writing....

Can you please add the third patch of the series?

regards

Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


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

* Re: [PATCH] hwrng: imx-rngc - setup default RNG quality
  2020-07-27 12:45     ` [PATCH] hwrng: imx-rngc - setup default RNG quality Christian Eggers
@ 2020-07-28  7:48       ` Marco Felsch
  2020-07-28  8:47         ` Christian Eggers
  0 siblings, 1 reply; 8+ messages in thread
From: Marco Felsch @ 2020-07-28  7:48 UTC (permalink / raw)
  To: Christian Eggers
  Cc: Fabio Estevam, Martin Kaiser, Herbert Xu, Arnd Bergmann,
	Greg Kroah-Hartman, Sascha Hauer, linux-kernel, NXP Linux Team,
	Pengutronix Kernel Team, Matt Mackall, Shawn Guo,
	linux-arm-kernel, linux-crypto

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);

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

* Re: [PATCH] hwrng: imx-rngc - setup default RNG quality
  2020-07-28  7:48       ` Marco Felsch
@ 2020-07-28  8:47         ` Christian Eggers
  0 siblings, 0 replies; 8+ messages in thread
From: Christian Eggers @ 2020-07-28  8:47 UTC (permalink / raw)
  To: Marco Felsch
  Cc: Fabio Estevam, Martin Kaiser, Herbert Xu, Arnd Bergmann,
	Greg Kroah-Hartman, Sascha Hauer, linux-kernel, NXP Linux Team,
	Pengutronix Kernel Team, Matt Mackall, Shawn Guo,
	linux-arm-kernel, linux-crypto

Hi Marco,

On Tuesday, 28 July 2020, 09:48:17 CEST, Marco Felsch wrote:
> 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:
ok, you caught me. I found the value of 900 in several other drivers and 
simply took it. Even parts of my commit message were simply copied...

As I have no real idea about determining the right quality, I will leave this 
task for you :-)

Thanks
Christian




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

end of thread, other threads:[~2020-07-28  8:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).