Skip to contentSkip to conversation

hw_random: introduce Arm CryptoCell TRNG driver

PATCH Superseded Hadar Gat 2 participants 6 messages Mar 22, 2020 – Mar 23, 2020

Subsystems (4)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Hadar Gat

author maintainer
#0 lore raw

v5 cover hw_random: introduce Arm CryptoCell TRNG driver

The Arm CryptoCell is a hardware security engine.
This patch introduces driver for its TRNG (True Random Number Generator) engine.

v5 changes:
1. in arm-cctrng.yaml, fixed error in 'make dt_binding_check'
2. in cctrng.c, clean up cctrng clock handling

v4 changes: update arm-cctrng.yaml to conform with json-schema standard.

v3 change: removed few unneeded "#ifdef CONFIG_PM" from the code.

v2 changes: fixed 'make dt_bnding_check' errors.

Hadar Gat (3):
dt-bindings: add device tree binding for Arm CryptoCell trng engine
hw_random: cctrng: introduce Arm CryptoCell driver
MAINTAINERS: add HG as cctrng maintainer

 .../devicetree/bindings/rng/arm-cctrng.yaml        |  55 ++
 MAINTAINERS                                        |   9 +
 drivers/char/hw_random/Kconfig                     |  12 +
 drivers/char/hw_random/Makefile                    |   1 +
 drivers/char/hw_random/cctrng.c                    | 735 +++++++++++++++++++++
 drivers/char/hw_random/cctrng.h                    |  69 ++
 6 files changed, 881 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rng/arm-cctrng.yaml
 create mode 100644 drivers/char/hw_random/cctrng.c
 create mode 100644 drivers/char/hw_random/cctrng.h
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH v5 1/3 dt-bindings: add device tree binding for Arm CryptoCell trng engine

The Arm CryptoCell is a hardware security engine. This patch adds DT bindings for its TRNG (True Random Number Generator) engine.

---
 .../devicetree/bindings/rng/arm-cctrng.yaml        | 55 ++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rng/arm-cctrng.yaml
Documentation/devicetree/bindings/rng/arm-cctrng.yaml new file +55 -0
new file mode 100644
index 0000000..7f70e4b
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rng/arm-cctrng.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Arm TrustZone CryptoCell TRNG engine
+
+maintainers:
+  - Hadar Gat <[email protected]>
+
+description: |+
+  Arm TrustZone CryptoCell TRNG (True Random Number Generator) engine.
+
+properties:
+  compatible:
+    enum:
+      - arm,cryptocell-713-trng
+      - arm,cryptocell-703-trng
+
+  interrupts:
+    maxItems: 1
+
+  reg:
+    maxItems: 1
+
+  arm,rosc-ratio:
+    description:
+      Arm TrustZone CryptoCell TRNG engine has 4 ring oscillators.
+      Sampling ratio values for these 4 ring oscillators. (from calibration)
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32-array
+      - items:
+          minItems: 4
+          maxItems: 4
+
+  clocks:
+    maxItems: 1
+
+required:
+  - compatible
+  - interrupts
+  - reg
+  - arm,rosc-ratio
+
+additionalProperties: false
+
+examples:
+  - |
+    arm_cctrng: rng@60000000 {
+        compatible = "arm,cryptocell-713-trng";
+        interrupts = <0 29 4>;
+        reg = <0x60000000 0x10000>;
+        arm,rosc-ratio = <5000 1000 500 0>;
+    };
Signature · 1 line
2.7.4
author maintainer
#2 lore raw

PATCH v5 2/3 hw_random: cctrng: introduce Arm CryptoCell driver

In reply to Hadar Gat

Introduce low level Arm CryptoCell TRNG HW support.

---
 drivers/char/hw_random/Kconfig  |  12 +
 drivers/char/hw_random/Makefile |   1 +
 drivers/char/hw_random/cctrng.c | 735 ++++++++++++++++++++++++++++++++++++++++
 drivers/char/hw_random/cctrng.h |  69 ++++
 4 files changed, 817 insertions(+)
 create mode 100644 drivers/char/hw_random/cctrng.c
 create mode 100644 drivers/char/hw_random/cctrng.h
drivers/char/hw_random/Kconfig +12 -0
index 9bc46da..848f26f 100644
@@ -474,6 +474,18 @@ config HW_RANDOM_KEYSTONE
 	help
 	  This option enables Keystone's hardware random generator.
 
+config HW_RANDOM_CCTRNG
+	tristate "Arm CryptoCell True Random Number Generator support"
+	default HW_RANDOM
+	help
+	  This driver provides support for the True Random Number
+	  Generator available in Arm TrustZone CryptoCell.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called cctrng.
+
+	  If unsure, say Y.
+
 endif # HW_RANDOM
 
 config UML_RANDOM
drivers/char/hw_random/Makefile +1 -0
index a7801b4..2c67247 100644
@@ -41,3 +41,4 @@ obj-$(CONFIG_HW_RANDOM_S390) += s390-trng.o
 obj-$(CONFIG_HW_RANDOM_KEYSTONE) += ks-sa-rng.o
 obj-$(CONFIG_HW_RANDOM_OPTEE) += optee-rng.o
 obj-$(CONFIG_HW_RANDOM_NPCM) += npcm-rng.o
+obj-$(CONFIG_HW_RANDOM_CCTRNG) += cctrng.o
drivers/char/hw_random/cctrng.c new file +735 -0

735 lines not on this page · raw message

drivers/char/hw_random/cctrng.h new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#5 lore raw

PATCH v5 3/3 MAINTAINERS: add HG as cctrng maintainer

In reply to Hadar Gat

I work for Arm on maintaining the TrustZone CryptoCell TRNG driver.

---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
index c312b65..3f27716 100644
@@ -3847,6 +3847,15 @@ S:	Supported
 F:	drivers/crypto/ccree/
 W:	https://developer.arm.com/products/system-ip/trustzone-cryptocell/cryptocell-700-family
 
+CCTRNG ARM TRUSTZONE CRYPTOCELL TRUE RANDOM NUMBER GENERATOR (TRNG) DRIVER
+M:	Hadar Gat <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/char/hw_random/cctrng.c
+F:	drivers/char/hw_random/cctrng.h
+F:	Documentation/devicetree/bindings/rng/arm-cctrng.txt
+W:	https://developer.arm.com/products/system-ip/trustzone-cryptocell/cryptocell-700-family
+
 CEC FRAMEWORK
 M:	Hans Verkuil <[email protected]>
 L:	[email protected]
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v5 2/3] hw_random: cctrng: introduce Arm CryptoCell driver

In reply to Hadar Gat

Hello Hadar,

Quoted 29 lines · Hadar Gat

Introduce low level Arm CryptoCell TRNG HW support.

---
 drivers/char/hw_random/Kconfig  |  12 +
 drivers/char/hw_random/Makefile |   1 +
 drivers/char/hw_random/cctrng.c | 735
++++++++++++++++++++++++++++++++++++++++
 drivers/char/hw_random/cctrng.h |  69 ++++
 4 files changed, 817 insertions(+)
 create mode 100644 drivers/char/hw_random/cctrng.c
 create mode 100644 drivers/char/hw_random/cctrng.h

[...]

drivers/char/hw_random/cctrng.c new file +14 -0
+static int cctrng_probe(struct platform_device *pdev)
+{
+	struct resource *req_mem_cc_regs = NULL;
+	struct cctrng_drvdata *drvdata;
+	struct device *dev = &pdev->dev;
+	int rc = 0;
+	u32 val;
+	int irq;
+
+	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
+	if (!drvdata)
+		return -ENOMEM;
+
+	drvdata->rng.name = devm_kstrdup(dev, dev_name(dev),

GFP_KERNEL);

drivers/char/hw_random/cctrng.c line 507

Quoted 5 lines
drivers/char/hw_random/cctrng.c new file +5 -0
+	if (!drvdata->rng.name)
+		return -ENOMEM;
+
+	drvdata->rng.read = cctrng_read;
+	drvdata->rng.priv = (unsigned long)drvdata;

You are not initializing drvdata->rng.quality to a default value, which results in the TRNG not being used by the kernel by default. If its a perfect TRNG this should be set to 1024, i.e. 1024 bits of entropy per 1024 bits of input.

Regards,
Rouven Czerwinski

author maintainer
#4 lore raw

RE: [PATCH v5 2/3] hw_random: cctrng: introduce Arm CryptoCell driver

Hi Rouven,

Quoted 34 lines

Hello Hadar,

Quoted 30 lines · Hadar Gat

Introduce low level Arm CryptoCell TRNG HW support.

---
 drivers/char/hw_random/Kconfig  |  12 +
 drivers/char/hw_random/Makefile |   1 +
 drivers/char/hw_random/cctrng.c | 735
++++++++++++++++++++++++++++++++++++++++
 drivers/char/hw_random/cctrng.h |  69 ++++
 4 files changed, 817 insertions(+)
 create mode 100644 drivers/char/hw_random/cctrng.c  create mode

100644 drivers/char/hw_random/cctrng.h

[...]

drivers/char/hw_random/cctrng.c new file +13 -0
+static int cctrng_probe(struct platform_device *pdev) {
+	struct resource *req_mem_cc_regs = NULL;
+	struct cctrng_drvdata *drvdata;
+	struct device *dev = &pdev->dev;
+	int rc = 0;
+	u32 val;
+	int irq;
+
+	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
+	if (!drvdata)
+		return -ENOMEM;
+
+	drvdata->rng.name = devm_kstrdup(dev, dev_name(dev),

GFP_KERNEL);

drivers/char/hw_random/cctrng.c new file +2 -0
+	if (!drvdata->rng.name)
+		return -ENOMEM;
Quoted 8 lines

drivers/char/hw_random/cctrng.c line 507

Quoted 3 lines
drivers/char/hw_random/cctrng.c new file +3 -0
+
+	drvdata->rng.read = cctrng_read;
+	drvdata->rng.priv = (unsigned long)drvdata;

You are not initializing drvdata->rng.quality to a default value, which results in the TRNG not being used by the kernel by default. If its a perfect TRNG this should be set to 1024, i.e. 1024 bits of entropy per
1024 bits of input.

Thanks for noticing. I'll fix that.

Quoted 3 lines

Regards,
Rouven Czerwinski

Thanks,
Hadar