Xilinx TRNG fix and simplification
Subsystems (5)
cover Xilinx TRNG fix and simplification
This series fixes and greatly simplifies the Xilinx TRNG driver by:
- Removing the gratuitous crypto_rng interface, leaving just hwrng which is the one that actually matters.
- Replacing the really complicated AES based entropy extraction algorithm with a much simpler one.
Note that this mirrors similar changes in other drivers.
Eric Biggers (4):
crypto: xilinx-trng - Remove crypto_rng interface
crypto: xilinx-trng - Fix return value of xtrng_hwrng_trng_read()
crypto: xilinx-trng - Replace crypto_drbg_ctr_df() with HMAC-SHA512
hwrng: xilinx - Move xilinx-rng into drivers/char/hw_random/
MAINTAINERS | 2 +-
arch/arm64/configs/defconfig | 2 +-
crypto/Kconfig | 5 -
crypto/Makefile | 2 -
crypto/df_sp80090a.c | 222 ------------------
drivers/char/hw_random/Kconfig | 11 +
drivers/char/hw_random/Makefile | 1 +
.../xilinx => char/hw_random}/xilinx-trng.c | 134 ++---------
drivers/crypto/Kconfig | 13 -
drivers/crypto/xilinx/Makefile | 1 -
include/crypto/df_sp80090a.h | 53 -----
11 files changed, 37 insertions(+), 409 deletions(-)
delete mode 100644 crypto/df_sp80090a.c
rename drivers/{crypto/xilinx => char/hw_random}/xilinx-trng.c (75%)
delete mode 100644 include/crypto/df_sp80090a.hbase-commit: 5624ea54f3ba5c83d2e5503411a31a8be0278c1e
prerequisite-patch-id: 07e982b663ac3f8312ca524f6b91b5b38661df5e
prerequisite-patch-id: 72064361a8f36e015ab0b7e1fa4d364b40d90506
prerequisite-patch-id: 8978b8e0db7f47935e5f6f0aff14a97f55d3073c
prerequisite-patch-id: 6aa0e3e93a008279d71e535a3d0cf48643f55e19
Signature · 1 line
2.54.0
PATCH 1/4 crypto: xilinx-trng - Remove crypto_rng interface
Implementing the crypto_rng interface has no purpose, as it isn't used in practice. It's being removed from other drivers too. Just remove it. This leaves hwrng, which is actually used.
Tagging with 'Cc stable' due to the bugs that this removes:
- xtrng_trng_generate() sometimes returned success even when it didn't fill in all the bytes.
- It was possible for xtrng_trng_generate() and xtrng_hwrng_trng_read() to run concurrently and interfere with each other, as the locking code in xtrng_hwrng_trng_read() was broken.
--- drivers/crypto/Kconfig | 1 - drivers/crypto/xilinx/xilinx-trng.c | 85 ++--------------------------- 2 files changed, 4 insertions(+), 82 deletions(-)
drivers/crypto/Kconfig +0 -1
@@ -708,11 +708,10 @@ 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 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.
drivers/crypto/xilinx/xilinx-trng.c +4 -81
183 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH 2/4 crypto: xilinx-trng - Fix return value of xtrng_hwrng_trng_read()
In reply to Eric BiggersImplementations of hwrng::read are expected to return the number of bytes generated. Update xtrng_hwrng_trng_read() to match that.
--- drivers/crypto/xilinx/xilinx-trng.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/crypto/xilinx/xilinx-trng.c +6 -3
@@ -237,22 +237,25 @@ static int xtrng_random_bytes_generate(struct xilinx_rng *rng, u8 *rand_buf_ptr,static int xtrng_hwrng_trng_read (struct hwrng *hwrng,void *data,size_t max,bool wait) {u8 buf[TRNG_SEC_STRENGTH_BYTES ];struct xilinx_rng *rng; -int ret = -EINVAL , i =0 ; +int ret =0 , i =0 ; rng = container_of(hwrng, struct xilinx_rng, trng);while (i < max) { ret =xtrng_random_bytes_generate (rng, buf,TRNG_SEC_STRENGTH_BYTES , wait); -if (ret <0 ) +if (ret <0 ) { +if (i ==0 ) +return ret;break ; + }memcpy (data + i, buf,min_t (int, ret, (max - i))); i +=min_t (int, ret, (max - i)); } -return ret; +return i; }static int xtrng_hwrng_register (struct hwrng *trng) {int ret;
Signature · 1 line
2.54.0
PATCH 3/4 crypto: xilinx-trng - Replace crypto_drbg_ctr_df() with HMAC-SHA512
In reply to Eric BiggersThis code is just trying to condition 48 bytes of random data. This can be done easily using HKDF-SHA512-Extract, saving 300 lines of code.
This commit also fixes forward security (in this particular case) by clearing the entropy from memory after it's used.
--- crypto/Kconfig | 5 - crypto/Makefile | 2 - crypto/df_sp80090a.c | 222 ---------------------------- drivers/crypto/Kconfig | 2 +- drivers/crypto/xilinx/xilinx-trng.c | 44 ++---- include/crypto/df_sp80090a.h | 53 ------- 6 files changed, 16 insertions(+), 312 deletions(-) delete mode 100644 crypto/df_sp80090a.c delete mode 100644 include/crypto/df_sp80090a.h
crypto/Kconfig +0 -5
@@ -1244,15 +1244,10 @@ endif # if CRYPTO_JITTERENTROPY config CRYPTO_KDF800108_CTR tristate select CRYPTO_HMAC select CRYPTO_SHA256 -config CRYPTO_DF80090A - tristate - select CRYPTO_AES - select CRYPTO_CTR - endmenu menu "Userspace interface (deprecated)" config CRYPTO_USER_API tristate
crypto/Makefile +0 -2
@@ -206,8 +206,6 @@ obj-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o # # Key derivation function # obj-$(CONFIG_CRYPTO_KDF800108_CTR) += kdf_sp800108.o -obj-$(CONFIG_CRYPTO_DF80090A) += df_sp80090a.o - obj-$(CONFIG_CRYPTO_KRB5) += krb5/
crypto/df_sp80090a.c deleted +0 -222
222 lines not on this page · raw message
drivers/crypto/Kconfig +1 -1
@@ -707,11 +707,11 @@ config CRYPTO_DEV_TEGRA 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_DF80090A + select CRYPTO_LIB_SHA512 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.
drivers/crypto/xilinx/xilinx-trng.c +15 -29
124 lines not on this page · raw message
include/crypto/df_sp80090a.h deleted +0 -53
53 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH 4/4 hwrng: xilinx - Move xilinx-rng into drivers/char/hw_random/
In reply to Eric BiggersSince this file just implements a hwrng driver, move it into drivers/char/hw_random/. Rename the kconfig option accordingly as well.
---
MAINTAINERS | 2 +-
arch/arm64/configs/defconfig | 2 +-
drivers/char/hw_random/Kconfig | 11 +++++++++++
drivers/char/hw_random/Makefile | 1 +
.../{crypto/xilinx => char/hw_random}/xilinx-trng.c | 0
drivers/crypto/Kconfig | 12 ------------
drivers/crypto/xilinx/Makefile | 1 -
7 files changed, 14 insertions(+), 15 deletions(-)
rename drivers/{crypto/xilinx => char/hw_random}/xilinx-trng.c (100%)MAINTAINERS +1 -1
@@ -29218,11 +29218,11 @@ 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 +F: drivers/char/hw_random/xilinx-trng.c XILINX UARTLITE SERIAL DRIVER M: Peter Korsgaard <[email protected]> L: [email protected] S: Maintained
arch/arm64/configs/defconfig +1 -1
@@ -549,10 +549,11 @@ CONFIG_IPMI_HANDLER=m CONFIG_IPMI_DEVICE_INTERFACE=m CONFIG_IPMI_SI=m CONFIG_HW_RANDOM=y CONFIG_HW_RANDOM_VIRTIO=y CONFIG_HW_RANDOM_QCOM=m +CONFIG_HW_RANDOM_XILINX=m CONFIG_TCG_TPM=y CONFIG_TCG_TIS=m CONFIG_TCG_TIS_SPI=m CONFIG_TCG_TIS_SPI_CR50=y CONFIG_TCG_TIS_I2C_CR50=m
@@ -1953,11 +1954,10 @@ CONFIG_CRYPTO_AES_ARM64_CE_CCM=y CONFIG_CRYPTO_DEV_SUN8I_CE=m CONFIG_CRYPTO_DEV_FSL_CAAM=m CONFIG_CRYPTO_DEV_FSL_DPAA2_CAAM=m CONFIG_CRYPTO_DEV_QCE=m CONFIG_CRYPTO_DEV_TEGRA=m -CONFIG_CRYPTO_DEV_XILINX_TRNG=m CONFIG_CRYPTO_DEV_ZYNQMP_AES=m CONFIG_CRYPTO_DEV_ZYNQMP_SHA3=m CONFIG_CRYPTO_DEV_CCREE=m CONFIG_CRYPTO_DEV_HISI_SEC2=m CONFIG_CRYPTO_DEV_HISI_ZIP=m
drivers/char/hw_random/Kconfig +11 -0
@@ -624,10 +624,21 @@ config HW_RANDOM_QCOM Generator hardware found on some Qualcomm SoCs. To compile this driver as a module, choose M here. The module will be called qcom-rng. If unsure, say N. +config HW_RANDOM_XILINX + tristate "Support for Xilinx True Random Generator" + depends on ZYNQMP_FIRMWARE || COMPILE_TEST + select CRYPTO_LIB_SHA512 + 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. + endif # HW_RANDOM config UML_RANDOM depends on UML select HW_RANDOM
drivers/char/hw_random/Makefile +1 -0
@@ -51,5 +51,6 @@ obj-$(CONFIG_HW_RANDOM_ARM_SMCCC_TRNG) += arm_smccc_trng.o obj-$(CONFIG_HW_RANDOM_CN10K) += cn10k-rng.o obj-$(CONFIG_HW_RANDOM_POLARFIRE_SOC) += mpfs-rng.o obj-$(CONFIG_HW_RANDOM_ROCKCHIP) += rockchip-rng.o obj-$(CONFIG_HW_RANDOM_JH7110) += jh7110-trng.o obj-$(CONFIG_HW_RANDOM_QCOM) += qcom-rng.o +obj-$(CONFIG_HW_RANDOM_XILINX) += xilinx-trng.o
drivers/char/hw_random/xilinx-trng.c renamed from drivers/crypto/xilinx/xilinx-trng.c +0 -0
drivers/crypto/Kconfig +0 -12
@@ -704,22 +704,10 @@ config CRYPTO_DEV_TEGRA help 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_LIB_SHA512 - 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 select CRYPTO_AES select CRYPTO_ENGINE
drivers/crypto/xilinx/Makefile +0 -1
@@ -1,4 +1,3 @@ # 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
Signature · 1 line
2.54.0
AMD General
Quoted 52 lines
-----Original Message-----
From: Eric Biggers <[email protected]>
Sent: Monday, June 1, 2026 12:48 AM
To: [email protected]; Herbert Xu <[email protected]>
Cc: [email protected]; Botcha, Mounika <[email protected]>; Jain, Harsh (AECG-SSW) <[email protected]>; Olivia Mackall <[email protected]>; Simek, Michal <[email protected]>; linux-arm- [email protected]; Eric Biggers <[email protected]>
Subject: [PATCH 0/4] Xilinx TRNG fix and simplificationThis series fixes and greatly simplifies the Xilinx TRNG driver by:
- Removing the gratuitous
crypto_rnginterface, leaving just hwrng which is the one that actually matters.- Replacing the really complicated AES based entropy extraction algorithm with a much simpler one.
Note that this mirrors similar changes in other drivers.
Eric Biggers (4):
crypto: xilinx-trng - Removecrypto_rnginterface
crypto: xilinx-trng - Fix return value ofxtrng_hwrng_trng_read()
crypto: xilinx-trng - Replacecrypto_drbg_ctr_df()with HMAC-SHA512
hwrng: xilinx - Move xilinx-rng intodrivers/char/hw_random/MAINTAINERS | 2 +- arch/arm64/configs/defconfig | 2 +- crypto/Kconfig | 5 - crypto/Makefile | 2 - crypto/df_sp80090a.c | 222 ------------------ drivers/char/hw_random/Kconfig | 11 + drivers/char/hw_random/Makefile | 1 + .../xilinx => char/hw_random}/xilinx-trng.c | 134 ++--------- drivers/crypto/Kconfig | 13 - drivers/crypto/xilinx/Makefile | 1 - include/crypto/df_sp80090a.h | 53 ----- 11 files changed, 37 insertions(+), 409 deletions(-) delete mode 100644 crypto/df_sp80090a.c rename drivers/{crypto/xilinx => char/hw_random}/xilinx-trng.c (75%) delete mode 100644 include/crypto/df_sp80090a.hbase-commit:
5624ea54f3ba5c83d2e5503411a31a8be0278c1e
prerequisite-patch-id:07e982b663ac3f8312ca524f6b91b5b38661df5e
prerequisite-patch-id:72064361a8f36e015ab0b7e1fa4d364b40d90506
prerequisite-patch-id:8978b8e0db7f47935e5f6f0aff14a97f55d3073c
prerequisite-patch-id:6aa0e3e93a008279d71e535a3d0cf48643f55e19--
2.54.0
Herbert Xu
maintainerQuoted 33 lines · Eric Biggers
This series fixes and greatly simplifies the Xilinx TRNG driver by:
- Removing the gratuitous
crypto_rnginterface, leaving just hwrng which is the one that actually matters.- Replacing the really complicated AES based entropy extraction algorithm with a much simpler one.
Note that this mirrors similar changes in other drivers.
Eric Biggers (4):
crypto: xilinx-trng - Removecrypto_rnginterface
crypto: xilinx-trng - Fix return value ofxtrng_hwrng_trng_read()
crypto: xilinx-trng - Replacecrypto_drbg_ctr_df()with HMAC-SHA512
hwrng: xilinx - Move xilinx-rng intodrivers/char/hw_random/MAINTAINERS | 2 +- arch/arm64/configs/defconfig | 2 +- crypto/Kconfig | 5 - crypto/Makefile | 2 - crypto/df_sp80090a.c | 222 ------------------ drivers/char/hw_random/Kconfig | 11 + drivers/char/hw_random/Makefile | 1 + .../xilinx => char/hw_random}/xilinx-trng.c | 134 ++--------- drivers/crypto/Kconfig | 13 - drivers/crypto/xilinx/Makefile | 1 - include/crypto/df_sp80090a.h | 53 ----- 11 files changed, 37 insertions(+), 409 deletions(-) delete mode 100644 crypto/df_sp80090a.c rename drivers/{crypto/xilinx => char/hw_random}/xilinx-trng.c (75%) delete mode 100644 include/crypto/df_sp80090a.h
Quoted 7 lines
base-commit:
5624ea54f3ba5c83d2e5503411a31a8be0278c1e
prerequisite-patch-id:07e982b663ac3f8312ca524f6b91b5b38661df5e
prerequisite-patch-id:72064361a8f36e015ab0b7e1fa4d364b40d90506
prerequisite-patch-id:8978b8e0db7f47935e5f6f0aff14a97f55d3073c
prerequisite-patch-id:6aa0e3e93a008279d71e535a3d0cf48643f55e19Signature · 1 line
2.54.0
All 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
Quoted 42 lines · Herbert Xu
Quoted 33 lines · Eric Biggers
This series fixes and greatly simplifies the Xilinx TRNG driver by:
- Removing the gratuitous
crypto_rnginterface, leaving just hwrng which is the one that actually matters.- Replacing the really complicated AES based entropy extraction algorithm with a much simpler one.
Note that this mirrors similar changes in other drivers.
Eric Biggers (4):
crypto: xilinx-trng - Removecrypto_rnginterface
crypto: xilinx-trng - Fix return value ofxtrng_hwrng_trng_read()
crypto: xilinx-trng - Replacecrypto_drbg_ctr_df()with HMAC-SHA512
hwrng: xilinx - Move xilinx-rng intodrivers/char/hw_random/MAINTAINERS | 2 +- arch/arm64/configs/defconfig | 2 +- crypto/Kconfig | 5 - crypto/Makefile | 2 - crypto/df_sp80090a.c | 222 ------------------ drivers/char/hw_random/Kconfig | 11 + drivers/char/hw_random/Makefile | 1 + .../xilinx => char/hw_random}/xilinx-trng.c | 134 ++--------- drivers/crypto/Kconfig | 13 - drivers/crypto/xilinx/Makefile | 1 - include/crypto/df_sp80090a.h | 53 ----- 11 files changed, 37 insertions(+), 409 deletions(-) delete mode 100644 crypto/df_sp80090a.c rename drivers/{crypto/xilinx => char/hw_random}/xilinx-trng.c (75%) delete mode 100644 include/crypto/df_sp80090a.hQuoted 7 lines
base-commit:
5624ea54f3ba5c83d2e5503411a31a8be0278c1e
prerequisite-patch-id:07e982b663ac3f8312ca524f6b91b5b38661df5e
prerequisite-patch-id:72064361a8f36e015ab0b7e1fa4d364b40d90506
prerequisite-patch-id:8978b8e0db7f47935e5f6f0aff14a97f55d3073c
prerequisite-patch-id:6aa0e3e93a008279d71e535a3d0cf48643f55e19Signature · 1 line
2.54.0
Quoted 1 line
All applied. Thanks.
Can you re-add the following to "hwrng: xilinx - Move xilinx-rng into drivers/char/hw_random/"? It seems you applied this before the qcom-rng series, then dropped the drivers/char/hw_random/Makefile change rather than resolve it.
drivers/char/hw_random/Makefile +1 -0
@@ -51,5 +51,6 @@ obj-$(CONFIG_HW_RANDOM_XIPHERA) += xiphera-trng.o obj-$(CONFIG_HW_RANDOM_ARM_SMCCC_TRNG) += arm_smccc_trng.o obj-$(CONFIG_HW_RANDOM_CN10K) += cn10k-rng.o obj-$(CONFIG_HW_RANDOM_POLARFIRE_SOC) += mpfs-rng.o obj-$(CONFIG_HW_RANDOM_ROCKCHIP) += rockchip-rng.o obj-$(CONFIG_HW_RANDOM_JH7110) += jh7110-trng.o +obj-$(CONFIG_HW_RANDOM_XILINX) += xilinx-trng.o
Herbert Xu
maintainerQuoted 11 lines · Eric Biggers
Can you re-add the following to "hwrng: xilinx - Move xilinx-rng into
drivers/char/hw_random/"? It seems you applied this before the qcom-rng series, then dropped thedrivers/char/hw_random/Makefilechange rather than resolve it.drivers/char/hw_random/Makefile +0
-0
drivers/char/hw_random/Makefile obj-$(CONFIG_HW_RANDOM_XIPHERA) += xiphera-trng.o · line 56
Quoted 6 lines
drivers/char/hw_random/Makefile +1
-0@@ -51,5 +51,6 @@ obj-$(CONFIG_HW_RANDOM_XIPHERA) += xiphera-trng.o obj-$(CONFIG_HW_RANDOM_ARM_SMCCC_TRNG) += arm_smccc_trng.o obj-$(CONFIG_HW_RANDOM_CN10K) += cn10k-rng.o obj-$(CONFIG_HW_RANDOM_POLARFIRE_SOC) += mpfs-rng.o obj-$(CONFIG_HW_RANDOM_ROCKCHIP) += rockchip-rng.o obj-$(CONFIG_HW_RANDOM_JH7110) += jh7110-trng.o +obj-$(CONFIG_HW_RANDOM_XILINX) += xilinx-trng.o
Thanks for checking. It should be fixed now.
Cheers,
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