hw_random: introduce Arm CryptoCell TRNG driver
Subsystems (4)
Hadar Gat
maintainerv5 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
Hadar Gat
maintainerPATCH 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
@@ -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
Hadar Gat
maintainerPATCH v5 2/3 hw_random: cctrng: introduce Arm CryptoCell driver
In reply to Hadar GatIntroduce 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
@@ -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
@@ -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
Hadar Gat
maintainerPATCH v5 3/3 MAINTAINERS: add HG as cctrng maintainer
In reply to Hadar GatI work for Arm on maintaining the TrustZone CryptoCell TRNG driver.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -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
Re: [PATCH v5 2/3] hw_random: cctrng: introduce Arm CryptoCell driver
In reply to Hadar GatHello Hadar,
Quoted 29 lines · Hadar Gat
Introduce low level Arm CryptoCell TRNG HW support.
Signed-off-by Hadar Gat <[email protected]>--- 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
Hadar Gat
maintainerRE: [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.
Signed-off-by Hadar Gat <[email protected]>--- 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 mode100644
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.qualityto 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