Skip to contentSkip to conversation

crypto: Add Versal TRNG driver

PATCH In review Harsh Jain 2 participants 6 messages Aug 25, 2025 – Sep 6, 2025

Subsystems (3)
lore
Share & tools
lore

Harsh Jain

author
#0 lore raw

v6 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 v5
- Direct include header file in df_sp80090a.c
- Add internal/drbg.h

Changes in v5
- Direct include header file
- Fix review-by tag position

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                          | 247 ++++++++++
 crypto/drbg.c                                 | 244 +---------
 drivers/crypto/Kconfig                        |  13 +
 drivers/crypto/xilinx/Makefile                |   1 +
 drivers/crypto/xilinx/xilinx-trng.c           | 435 ++++++++++++++++++
 include/crypto/df_sp80090a.h                  |  27 ++
 include/crypto/drbg.h                         |  25 +-
 include/crypto/internal/drbg.h                |  54 +++
 12 files changed, 833 insertions(+), 265 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
 create mode 100644 include/crypto/internal/drbg.h
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v6 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
new file mode 100644
index 000000000000..180adb96e5e7
@@ -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
author
#2 lore raw

PATCH v6 2/3 crypto: xilinx: Add TRNG driver for Versal

In reply to Harsh Jain

Add 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 | 405 ++++++++++++++++++++++++++++
 4 files changed, 424 insertions(+)
 create mode 100644 drivers/crypto/xilinx/xilinx-trng.c
MAINTAINERS +6 -0
index fe168477caa4..e8424fcbc255 100644
@@ -27602,6 +27602,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
index 04b4c43b6bae..53eedc0dea4d 100644
@@ -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
index 730feff5b5f2..9b51636ef75e 100644
@@ -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 +405 -0

405 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v6 3/3 crypto: drbg: Export CTR DRBG DF functions

In reply to Harsh Jain

Export 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                | 247 ++++++++++++++++++++++++++++
 crypto/drbg.c                       | 244 +--------------------------
 drivers/crypto/Kconfig              |   1 +
 drivers/crypto/xilinx/xilinx-trng.c |  42 ++++-
 include/crypto/df_sp80090a.h        |  27 +++
 include/crypto/drbg.h               |  25 +--
 include/crypto/internal/drbg.h      |  54 ++++++
 9 files changed, 379 insertions(+), 271 deletions(-)
 create mode 100644 crypto/df_sp80090a.c
 create mode 100644 include/crypto/df_sp80090a.h
 create mode 100644 include/crypto/internal/drbg.h
crypto/Kconfig +6 -2
index 23bd98981ae8..f773c84f056b 100644
@@ -1211,8 +1211,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.
 
@@ -1348,6 +1347,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
index 6c5d59369dac..ba3cab673ee5 100644
@@ -210,4 +210,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 +247 -0

247 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
index 53eedc0dea4d..78557bff0753 100644
@@ -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 +36 -6

114 lines not on this page · raw message

include/crypto/df_sp80090a.h new file +27 -0
new file mode 100644
index 000000000000..182865538662
@@ -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 +1 -24
index af5ad51d3eef..2d42518cbdce 100644
@@ -47,6 +47,7 @@
 #include <linux/module.h>
 #include <linux/crypto.h>
 #include <linux/slab.h>
+#include <crypto/internal/drbg.h>
 #include <crypto/internal/rng.h>
 #include <crypto/rng.h>
 #include <linux/fips.h>
@@ -54,30 +55,6 @@
 #include <linux/list.h>
 #include <linux/workqueue.h>
 
-/*
- * Concatenation Helper and string operation helper
- *
- * SP800-90A requires the concatenation of different data. To avoid copying
- * buffers around or allocate additional memory, the following data structure
- * is used to point to the original memory with its size. In addition, it
- * is used to build a linked list. The linked list defines the concatenation
- * of individual buffers. The order of memory block referenced in that
- * linked list determines the order of concatenation.
- */
-struct drbg_string {
-	const unsigned char *buf;
-	size_t len;
-	struct list_head list;
-};
-
-static inline void drbg_string_fill(struct drbg_string *string,
-				    const unsigned char *buf, size_t len)
-{
-	string->buf = buf;
-	string->len = len;
-	INIT_LIST_HEAD(&string->list);
-}
-
 struct drbg_state;
 typedef uint32_t drbg_flag_t;
 
include/crypto/internal/drbg.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#4 lore raw

Re: [PATCH V6 3/3] crypto: drbg: Export CTR DRBG DF functions

drivers/crypto/xilinx/xilinx-trng.c static int xtrng_probe(struct platform_device *pdev) · line 352

Quoted 2 lines · Harsh Jain
drivers/crypto/xilinx/xilinx-trng.c +1 -0
+	rng->tfm = crypto_alloc_cipher("aes", 0, 0);

Please don't add any new users of crypto_alloc_cipher. This particular case should switch over to lib/crypto/aes.

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
maintainer
#5 lore raw
In reply to Harsh Jain
Quoted 52 lines · Harsh Jain

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 v5
- Direct include header file in df_sp80090a.c
- Add internal/drbg.h

Changes in v5
- Direct include header file
- Fix review-by tag position

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                          | 247 ++++++++++
 crypto/drbg.c                                 | 244 +---------
 drivers/crypto/Kconfig                        |  13 +
 drivers/crypto/xilinx/Makefile                |   1 +
 drivers/crypto/xilinx/xilinx-trng.c           | 435 ++++++++++++++++++
 include/crypto/df_sp80090a.h                  |  27 ++
Quoted 11 lines
 include/crypto/drbg.h                         |  25 +-
 include/crypto/internal/drbg.h                |  54 +++
 12 files changed, 833 insertions(+), 265 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
 create mode 100644 include/crypto/internal/drbg.h
Signature · 1 line
2.34.1

Patches 1-2 applied. 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