crypto: Add Versal TRNG driver
Subsystems (3)
v4 cover crypto: Add Versal TRNG driver
Versal TRNG module consist of array of Ring Oscillators as entropy source and a deterministic CTR_DRBG random bit generator (DRBG). Add driver to registers entropy source to hwrng and CTR_DRBG generator to crypto subsystem. Derivation Function (DF) defined in NIST SP-800-90A for CTR_DRBG is not supported in current TRNG IP. For DF processing, Update drbg module to export CTR_DRBG derivation function in df_sp80090a module.
Testing
Following compile tests done
* CONFIG_CRYPTO_DRBG_CTR = n and CONFIG_CRYPTO_DEV_XILINX_TRNG = n
* CONFIG_CRYPTO_DRBG_CTR = y and CONFIG_CRYPTO_DEV_XILINX_TRNG = n
* CONFIG_CRYPTO_DRBG_CTR = n and CONFIG_CRYPTO_DEV_XILINX_TRNG = m
* CONFIG_CRYPTO_DRBG_CTR = y and CONFIG_CRYPTO_DEV_XILINX_TRNG = m
Changes in v4
- Add df_sp80090a module to export CTR_DRBG DF function
Changes in v3
- Fix yaml warning introduced in v2.
- Squash fix patches
Changes in v2
- Fixed signoff chain
- Added 3 patch to fix Kernel test robot bugs
Harsh Jain (2):
crypto: xilinx: Add TRNG driver for Versal
crypto: drbg: Export CTR DRBG DF functions
Mounika Botcha (1):
dt-bindings: crypto: Add node for True Random Number Generator
.../bindings/crypto/xlnx,versal-trng.yaml | 36 ++ MAINTAINERS | 6 + crypto/Kconfig | 8 +- crypto/Makefile | 2 + crypto/df_sp80090a.c | 243 ++++++++++ crypto/drbg.c | 244 +--------- drivers/crypto/Kconfig | 13 + drivers/crypto/xilinx/Makefile | 1 + drivers/crypto/xilinx/xilinx-trng.c | 434 ++++++++++++++++++ include/crypto/df_sp80090a.h | 27 ++ include/crypto/drbg.h | 18 + 11 files changed, 791 insertions(+), 241 deletions(-) create mode 100644 Documentation/devicetree/bindings/crypto/xlnx,versal-trng.yaml create mode 100644 crypto/df_sp80090a.c create mode 100644 drivers/crypto/xilinx/xilinx-trng.c create mode 100644 include/crypto/df_sp80090a.h
Signature · 1 line
2.34.1
PATCH v4 1/3 dt-bindings: crypto: Add node for True Random Number Generator
From: Mounika Botcha <[email protected]>
Add TRNG node compatible string and reg properities.
--- .../bindings/crypto/xlnx,versal-trng.yaml | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/xlnx,versal-trng.yaml
Documentation/devicetree/bindings/crypto/xlnx,versal-trng.yaml new file +36 -0
@@ -0,0 +1,36 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/crypto/xlnx,versal-trng.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Xilinx Versal True Random Number Generator Hardware Accelerator + +maintainers: + - Harsh Jain <[email protected]> + - Mounika Botcha <[email protected]> + +description: + The Versal True Random Number Generator consists of Ring Oscillators as + entropy source and a deterministic CTR_DRBG random bit generator (DRBG). + +properties: + compatible: + const: xlnx,versal-trng + + reg: + maxItems: 1 + +required: + - reg + +additionalProperties: false + +examples: + - | + rng@f1230000 { + compatible = "xlnx,versal-trng"; + reg = <0xf1230000 0x1000>; + }; +... +
Signature · 1 line
2.34.1
Re: [PATCH v4 1/3] dt-bindings: crypto: Add node for True Random Number Generator
Quoted 5 lines · Harsh Jain
From: Mounika Botcha <[email protected]>
Add TRNG node compatible string and reg properities.
Reviewed-by Krzysztof Kozlowski <[email protected]>
Why did you placed my tag here?
Quoted 2 lines
Signed-off-by Mounika Botcha <[email protected]>Signed-off-by Harsh Jain <[email protected]>
Who received the tag? When was the patch prepared?
Best regards,
Krzysztof
RE: [PATCH v4 1/3] dt-bindings: crypto: Add node for True Random Number Generator
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 17 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Thursday, July 24, 2025 12:52 PM
To: Jain, Harsh (AECG-SSW) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Botcha, Mounika <[email protected]>; Savitala, Sarat Chand <[email protected]>; Dhanawade, Mohan <[email protected]>; Simek, Michal <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Krzysztof Kozlowski <[email protected]>
Subject: Re: [PATCH v4 1/3] dt-bindings: crypto: Add node for True Random Number GeneratorCaution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 8 lines
Quoted 5 lines · Harsh Jain
From: Mounika Botcha <[email protected]>
Add TRNG node compatible string and reg properities.
Reviewed-by Krzysztof Kozlowski <[email protected]>Why did you placed my tag here?
You shared Reviewed-by on v3. It’s the same patch. Isn't I am supposed to add it in subsequent patches if there is not change?
https://lore.kernel.org/linux-crypto/20250617-rational-benign-woodpecker-6ee31a@kuoka/
Quoted 5 lines
Quoted 3 lines
Signed-off-by Mounika Botcha <[email protected]>Signed-off-by Harsh Jain <[email protected]>Who received the tag? When was the patch prepared?
Did I missed something here?
Quoted 3 lines
Best regards,
Krzysztof
Re: [PATCH v4 1/3] dt-bindings: crypto: Add node for True Random Number Generator
Quoted 24 lines · Harsh (AECG-SSW)
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 22 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Thursday, July 24, 2025 12:52 PM
To: Jain, Harsh (AECG-SSW) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Botcha, Mounika <[email protected]>; Savitala, Sarat Chand <[email protected]>; Dhanawade, Mohan <[email protected]>; Simek, Michal <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Krzysztof Kozlowski <[email protected]>
Subject: Re: [PATCH v4 1/3] dt-bindings: crypto: Add node for True Random Number GeneratorCaution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 4 lines · Harsh Jain
From: Mounika Botcha <[email protected]>
Add TRNG node compatible string and reg properities.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Reviewed-by Krzysztof Kozlowski <[email protected]>Why did you placed my tag here?
You shared Reviewed-by on v3. It’s the same patch. Isn't I am supposed to add it in subsequent patches if there is not change?
https://lore.kernel.org/linux-crypto/20250617-rational-benign-woodpecker-6ee31a@kuoka/
And who sent the patch? Who received the tag? Why the tag is above existing SoB chain?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Signed-off-by Mounika Botcha <[email protected]>Signed-off-by Harsh Jain <[email protected]>Who received the tag? When was the patch prepared?
Did I missed something here?
Yes, using standard tools for the job - b4 - or following the process if you do not want to use the tools.
Best regards,
Krzysztof
Jain, Harsh (AECG-SSW)
Reviewed-by Krzysztof KozlowskiRE: [PATCH v4 1/3] dt-bindings: crypto: Add node for True Random Number Generator
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 49 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Thursday, July 24, 2025 1:39 PM
To: Jain, Harsh (AECG-SSW) <[email protected]>; Krzysztof Kozlowski <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; Botcha, Mounika <[email protected]>; Savitala, Sarat Chand <[email protected]>; Dhanawade, Mohan <[email protected]>; Simek, Michal <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 1/3] dt-bindings: crypto: Add node for True Random Number GeneratorCaution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 6 lines · Harsh (AECG-SSW)
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 4 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Thursday, July 24, 2025 12:52 PM
To: Jain, Harsh (AECG-SSW) <[email protected]>;Quoted 1 line
Quoted 1 line
Quoted 4 lines
Quoted 4 lines
Botcha, Mounika <[email protected]>; Savitala, Sarat Chand <[email protected]>; Dhanawade, Mohan <[email protected]>; Simek, Michal <[email protected]>; [email protected]; [email protected]; [email protected];
Quoted 17 lines
Quoted 16 lines
Cc: Krzysztof Kozlowski <[email protected]>
Subject: Re: [PATCH v4 1/3] dt-bindings: crypto: Add node for True Random Number GeneratorCaution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Quoted 5 lines · Harsh Jain
From: Mounika Botcha <[email protected]>
Add TRNG node compatible string and reg properities.
Reviewed-by Krzysztof Kozlowski <[email protected]>Why did you placed my tag here?
Quoted 8 lines
Quoted 1 line
You shared Reviewed-by on v3. It’s the same patch. Isn't I am supposed to add it
in subsequent patches if there is not change?
6ee31a@kuoka/
And who sent the patch? Who received the tag? Why the tag is above existing SoB chain?
You means to say order of tags should be
Quoted 15 lines
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Signed-off-by Mounika Botcha <[email protected]>Signed-off-by Harsh Jain <[email protected]>Who received the tag? When was the patch prepared?
Did I missed something here?
Yes, using standard tools for the job - b4 - or following the process if you do not want to use the tools.
Best regards,
Krzysztof
PATCH v4 2/3 crypto: xilinx: Add TRNG driver for Versal
In reply to Harsh JainAdd True Random Number Generator(TRNG) driver for Versal platform.
--- MAINTAINERS | 6 + drivers/crypto/Kconfig | 12 + drivers/crypto/xilinx/Makefile | 1 + drivers/crypto/xilinx/xilinx-trng.c | 402 ++++++++++++++++++++++++++++ 4 files changed, 421 insertions(+) create mode 100644 drivers/crypto/xilinx/xilinx-trng.c
MAINTAINERS +6 -0
@@ -27176,6 +27176,12 @@ F: Documentation/misc-devices/xilinx_sdfec.rst F: drivers/misc/xilinx_sdfec.c F: include/uapi/misc/xilinx_sdfec.h +XILINX TRNG DRIVER +M: Mounika Botcha <[email protected]> +M: Harsh Jain <[email protected]> +S: Maintained +F: drivers/crypto/xilinx/xilinx-trng.c + XILINX UARTLITE SERIAL DRIVER M: Peter Korsgaard <[email protected]> L: [email protected]
drivers/crypto/Kconfig +12 -0
@@ -725,6 +725,18 @@ config CRYPTO_DEV_TEGRA Select this to enable Tegra Security Engine which accelerates various AES encryption/decryption and HASH algorithms. +config CRYPTO_DEV_XILINX_TRNG + tristate "Support for Xilinx True Random Generator" + depends on ZYNQMP_FIRMWARE || COMPILE_TEST + select CRYPTO_RNG + select HW_RANDOM + help + Xilinx Versal SoC driver provides kernel-side support for True Random Number + Generator and Pseudo random Number in CTR_DRBG mode as defined in NIST SP800-90A. + + To compile this driver as a module, choose M here: the module + will be called xilinx-trng. + config CRYPTO_DEV_ZYNQMP_AES tristate "Support for Xilinx ZynqMP AES hw accelerator" depends on ZYNQMP_FIRMWARE || COMPILE_TEST
drivers/crypto/xilinx/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_CRYPTO_DEV_XILINX_TRNG) += xilinx-trng.o obj-$(CONFIG_CRYPTO_DEV_ZYNQMP_AES) += zynqmp-aes-gcm.o obj-$(CONFIG_CRYPTO_DEV_ZYNQMP_SHA3) += zynqmp-sha.o
drivers/crypto/xilinx/xilinx-trng.c new file +402 -0
402 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v4 3/3 crypto: drbg: Export CTR DRBG DF functions
In reply to Harsh JainExport drbg_ctr_df() derivative function to re-use it in xilinx trng driver. Changes has been tested by enabling CONFIG_CRYPTO_USER_API_RNG_CAVP
--- crypto/Kconfig | 8 +- crypto/Makefile | 2 + crypto/df_sp80090a.c | 243 +++++++++++++++++++++++++++ crypto/drbg.c | 244 +--------------------------- drivers/crypto/Kconfig | 1 + drivers/crypto/xilinx/xilinx-trng.c | 38 ++++- include/crypto/df_sp80090a.h | 27 +++ include/crypto/drbg.h | 18 ++ 8 files changed, 337 insertions(+), 244 deletions(-) create mode 100644 crypto/df_sp80090a.c create mode 100644 include/crypto/df_sp80090a.h
crypto/Kconfig +6 -2
@@ -1191,8 +1191,7 @@ config CRYPTO_DRBG_HASH config CRYPTO_DRBG_CTR bool "CTR_DRBG" - select CRYPTO_AES - select CRYPTO_CTR + select CRYPTO_DF80090A help CTR_DRBG variant as defined in NIST SP800-90A.
@@ -1328,6 +1327,11 @@ config CRYPTO_KDF800108_CTR select CRYPTO_HMAC select CRYPTO_SHA256 +config CRYPTO_DF80090A + tristate + select CRYPTO_AES + select CRYPTO_CTR + endmenu menu "Userspace interface"
crypto/Makefile +2 -0
@@ -214,4 +214,6 @@ obj-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o # obj-$(CONFIG_CRYPTO_KDF800108_CTR) += kdf_sp800108.o +obj-$(CONFIG_CRYPTO_DF80090A) += df_sp80090a.o + obj-$(CONFIG_CRYPTO_KRB5) += krb5/
crypto/df_sp80090a.c new file +243 -0
243 lines not on this page · raw message
crypto/drbg.c +5 -239
284 lines not on this page · raw message
drivers/crypto/Kconfig +1 -0
@@ -728,6 +728,7 @@ config CRYPTO_DEV_TEGRA config CRYPTO_DEV_XILINX_TRNG tristate "Support for Xilinx True Random Generator" depends on ZYNQMP_FIRMWARE || COMPILE_TEST + select CRYPTO_DF80090A select CRYPTO_RNG select HW_RANDOM help
drivers/crypto/xilinx/xilinx-trng.c +35 -3
@@ -7,6 +7,8 @@#include <linux/bitfield.h> #include <linux/clk.h> #include <linux/crypto.h> +#include <crypto/df_sp80090a.h> +#include <crypto/drbg.h> #include <linux/firmware/xlnx-zynqmp.h> #include <linux/hw_random.h> #include <linux/io.h>
@@ -56,6 +58,8 @@struct xilinx_rng {void __iomem *rng_base;struct device *dev; +unsigned char *scratchpadbuf; +struct crypto_cipher *tfm;struct mutex lock;/* Protect access to TRNG device */ struct hwrng trng; };
@@ -179,9 +183,13 @@ static void xtrng_enable_entropy(struct xilinx_rng *rng)static int xtrng_reseed_internal (struct xilinx_rng *rng) {u8 entropy[TRNG_ENTROPY_SEED_LEN_BYTES ]; +struct drbg_string data; +LIST_HEAD (seedlist);u32 val;int ret; +drbg_string_fill (&data, entropy,TRNG_SEED_LEN_BYTES ); +list_add_tail (&data.list, &seedlist);memset (entropy,0 ,sizeof (entropy));xtrng_enable_entropy (rng);
@@ -189,9 +197,14 @@ static int xtrng_reseed_internal(struct xilinx_rng *rng) ret =xtrng_collect_random_data (rng, entropy,TRNG_SEED_LEN_BYTES , true);if (ret !=TRNG_SEED_LEN_BYTES )return -EINVAL ; + ret =crypto_drbg_ctr_df (rng->tfm, rng->scratchpadbuf, +TRNG_SEED_LEN_BYTES , &seedlist,AES_BLOCK_SIZE , +TRNG_SEED_LEN_BYTES ); +if (ret) +return ret;xtrng_write_multiple_registers (rng->rng_base +TRNG_EXT_SEED_OFFSET , - (u32 *)entropy,TRNG_NUM_INIT_REGS ); + (u32 *)rng->scratchpadbuf,TRNG_NUM_INIT_REGS );/* select reseed operation */ iowrite32 (TRNG_CTRL_PRNGXS_MASK , rng->rng_base +TRNG_CTRL_OFFSET );
@@ -321,6 +334,7 @@ static void xtrng_hwrng_unregister(struct hwrng *trng)static int xtrng_probe (struct platform_device *pdev) {struct xilinx_rng *rng; +size_t sb_size;int ret; rng =devm_kzalloc (&pdev->dev,sizeof (*rng),GFP_KERNEL );
@@ -334,11 +348,24 @@ static int xtrng_probe(struct platform_device *pdev)return PTR_ERR (rng->rng_base); } + rng->tfm =crypto_alloc_cipher ("aes" ,0 ,0 ); +if (IS_ERR (rng->tfm)) { +pr_info ("DRBG: could not allocate cipher TFM handle:\n" ); +return PTR_ERR (rng->tfm); + } + + sb_size =crypto_drbg_ctr_df_datalen (TRNG_SEED_LEN_BYTES ,AES_BLOCK_SIZE ); + rng->scratchpadbuf =devm_kzalloc (&pdev->dev, sb_size,GFP_KERNEL ); +if (!rng->scratchpadbuf) { + ret = -ENOMEM ; + goto cipher_cleanup; + } +xtrng_trng_reset (rng->rng_base); ret =xtrng_reseed_internal (rng);if (ret) {dev_err (&pdev->dev,"TRNG Seed fail\n" ); -return ret; + goto cipher_cleanup; } xilinx_rng_dev = rng;
@@ -346,8 +373,9 @@ static int xtrng_probe(struct platform_device *pdev) ret =crypto_register_rng (&xtrng_trng_alg);if (ret) {dev_err (&pdev->dev,"Crypto Random device registration failed: %d\n" , ret); -return ret; + goto cipher_cleanup; } + ret =xtrng_hwrng_register (&rng->trng);if (ret) {dev_err (&pdev->dev,"HWRNG device registration failed: %d\n" , ret);
@@ -360,6 +388,9 @@ static int xtrng_probe(struct platform_device *pdev) crypto_rng_free:crypto_unregister_rng (&xtrng_trng_alg); +cipher_cleanup: +crypto_free_cipher (rng->tfm); +return ret; }
@@ -371,6 +402,7 @@ static void xtrng_remove(struct platform_device *pdev) rng =platform_get_drvdata (pdev);xtrng_hwrng_unregister (&rng->trng);crypto_unregister_rng (&xtrng_trng_alg); +crypto_free_cipher (rng->tfm);xtrng_write_multiple_registers (rng->rng_base +TRNG_EXT_SEED_OFFSET , zero,TRNG_NUM_INIT_REGS ); xtrng_write_multiple_registers(rng->rng_base + TRNG_PER_STRNG_OFFSET, zero,
include/crypto/df_sp80090a.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* +* Copyright Stephan Mueller <[email protected]>, 2014 +*/ + +#ifndef _CRYPTO_DF80090A_H +#define _CRYPTO_DF80090A_H + +#include <crypto/internal/cipher.h> + +static inline int crypto_drbg_ctr_df_datalen (u8 statelen,u8 blocklen) +{ +return statelen +/* df_data */ + blocklen +/* pad */ + blocklen +/* iv */ + statelen + blocklen;/* temp */ +} + +int crypto_drbg_ctr_df (struct crypto_cipher *tfm, +unsigned char *df_data, +size_t bytes_to_return, +struct list_head *seedlist, +u8 blocklen_bytes, +u8 statelen); + +#endif /* _CRYPTO_DF80090A_H */
include/crypto/drbg.h +18 -0
@@ -144,6 +144,24 @@ struct drbg_state {struct drbg_string test_data; }; +/* +* Convert an integer into a byte representation of this integer. +* The byte representation is big-endian +* +* @val value to be converted +* @buf buffer holding the converted integer -- caller must ensure that +* buffer size is at least 32 bit +*/ +static inline void drbg_cpu_to_be32 (__u32 val,unsigned char *buf) +{ +struct s { +__be32 conv; + }; +struct s *conversion = (struct s *) buf; + + conversion->conv =cpu_to_be32 (val); +} +static inline __u8 drbg_statelen (struct drbg_state *drbg) {if (drbg && drbg->core)
Signature · 1 line
2.34.1
Herbert Xu
maintainerRe: [PATCH v4 3/3] crypto: drbg: Export CTR DRBG DF functions
Quoted 7 lines · Harsh Jain
crypto/df_sp80090a.c new file +0
-0
crypto/df_sp80090a.c line 10
Quoted 10 lines
crypto/df_sp80090a.c new file +10
-0@@ -0,0 +1,243 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* NIST SP800-90A DRBG derivation function +* +* Copyright (C) 2014, Stephan Mueller <[email protected]> +*/ + +#include <crypto/df_sp80090a.h> +#include <crypto/drbg.h>
Please include header files directly rather than relying on indirect inclusions that can disappear at any time. You should add these ones at least:
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt