Add support for Texas Instruments DTHEv2 Crypto Engine
Subsystems (3)
T Pratham
maintainerv6 cover Add support for Texas Instruments DTHEv2 Crypto Engine
Data Transform and Hashing Engine (DTHE) v2 is a new cryptography engine introduced i TI AM62L SoC. DTHEv2 consists of multiple crypto IPs[1] (such as AES Engine, hashing engine, TRNG, etc.) which can be used for offloading cryptographic operations off of the CPU. The primary benefit of DTHEv2 is enhanced side-channel attack resistance, with AES and PKE engine being DPA and EMA resistant. These side-channel resistances are the underlying requirement for various certifications like SESIP, PSA, and IEC62443 (lvl 3+). Thus, DTHEv2 provides critical security benefits for embedded systems that require protection against passive physical attacks.
The AES Engine of DTHEv2 supports multiple AES modes (ECB, CBC, CTR, CFB, f8), several protocols (GCM, CCM, XTS) and authentication modes (CBC-MAC and f9). The hashing engine supports MD5, SHA1, and SHA2 (224, 256, 384, 512) algorithms along with HMAC. This patch series introduces basic driver support for DTHEv2 engine, beginning with suporting AES-ECB and AES-CBC algorithms. Other algorithms are planned to be added gradually in phases after initial suppport is added.
The driver is tested using full kernel crypto selftests (CRYPTO_SELFTESTS) which all pass successfully [2].
---
[1]: Section 14.6.3 (DMA Control Registers -> DMASS_DTHE)
[2]: DTHEv2 AES-ECB and AES-CBC kernel self-tests logs
Change log:
v6:
- Reworded the cover letter and commit messages to name DTHEv2 as a crypto engine instead of crypto accelerator.
- Reworded the cover letter completely to emphasise more on the utility of DTHEv2 as better resistance against physical attacks
- Reworded DTHEv2 description (help text) in KConfig
- Added dma_terminate_sync calls to ensure DMA requests are removed in case when completion times-out.
- Some rearrangement of fields between dthe_tfm_ctx and dthe_aes_req_ctx struct, so that per tfm members are correctly placed in tfm_ctx and per request members are in req_ctx. Subsequently setkey, encrypt and decrypt functions are also changed.
- Removed exit_tfm function which was useless and not required.
- Removed unnecessary zeroing of tfm_ctx object in init_tfm.
- Corrected return value in dthe_aes_run function.
- Reduced cra_priority of DTHEv2 algorithms.
v5:
- Simplified tfm ctx struct
- Set cra_reqsize instead of using crypto_skcipher_set_reqsize()
- Move setting sysconfig and irqenable registers to dthe_aes_run
v4:
- Corrected dt-bindings example indentation
- Simplified dt-bindings example, removing the node surrounding crypto
- Fixed typo in dthev2-common.h header guard
- Removed unused ctx field in dev_data struct
- Moved per-op data into request context
v3:
- Corrected dt-bindings reg length is too long error
- Converted AES driver code to use crypto_engine APIs for using internal crypto queue instead of mutex.
- Removed calls to skcipher_request_complete in paths not returning -EINPROGRESS before.
- Added missing KConfig import, which was accidentally removed in v2.
v2:
- Corrected dt-bindings syntax errors and other review comments in v1.
- Completely changed driver code structure, splitting code into multiple files
Link to previous versions:
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
---
T Pratham (2):
dt-bindings: crypto: Add binding for TI DTHE V2
crypto: ti: Add driver for DTHE V2 AES Engine (ECB, CBC)
.../bindings/crypto/ti,am62l-dthev2.yaml | 50 +++ MAINTAINERS | 7 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/ti/Kconfig | 14 + drivers/crypto/ti/Makefile | 3 + drivers/crypto/ti/dthev2-aes.c | 411 ++++++++++++++++++ drivers/crypto/ti/dthev2-common.c | 220 ++++++++++ drivers/crypto/ti/dthev2-common.h | 101 +++++ 9 files changed, 808 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/ti,am62l-dthev2.yaml create mode 100644 drivers/crypto/ti/Kconfig create mode 100644 drivers/crypto/ti/Makefile create mode 100644 drivers/crypto/ti/dthev2-aes.c create mode 100644 drivers/crypto/ti/dthev2-common.c create mode 100644 drivers/crypto/ti/dthev2-common.h
Signature · 1 line
2.43.0
T Pratham
maintainerPATCH v6 1/2 dt-bindings: crypto: Add binding for TI DTHE V2
Add DT binding for Texas Instruments DTHE V2 cryptography engine.
DTHE V2 is introduced as a part of TI AM62L SoC and can currently be only found in it.
--- .../bindings/crypto/ti,am62l-dthev2.yaml | 50 +++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/ti,am62l-dthev2.yaml
Documentation/devicetree/bindings/crypto/ti,am62l-dthev2.yaml new file +50 -0
@@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/crypto/ti,am62l-dthev2.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: K3 SoC DTHE V2 crypto module + +maintainers: + - T Pratham <[email protected]> + +properties: + compatible: + enum: + - ti,am62l-dthev2 + + reg: + maxItems: 1 + + dmas: + items: + - description: AES Engine RX DMA Channel + - description: AES Engine TX DMA Channel + - description: SHA Engine TX DMA Channel + + dma-names: + items: + - const: rx + - const: tx1 + - const: tx2 + +required: + - compatible + - reg + - dmas + - dma-names + +additionalProperties: false + +examples: + - | + crypto@40800000 { + compatible = "ti,am62l-dthev2"; + reg = <0x40800000 0x10000>; + + dmas = <&main_bcdma 0 0 0x4700 0>, + <&main_bcdma 0 0 0xc701 0>, + <&main_bcdma 0 0 0xc700 0>; + dma-names = "rx", "tx1", "tx2"; + };
MAINTAINERS +6 -0
@@ -25169,6 +25169,12 @@ S: Odd Fixes F: drivers/clk/ti/ F: include/linux/clk/ti.h +TI DATA TRANSFORM AND HASHING ENGINE (DTHE) V2 CRYPTO DRIVER +M: T Pratham <[email protected]> +L: [email protected] +S: Supported +F: Documentation/devicetree/bindings/crypto/ti,am62l-dthev2.yaml + TI DAVINCI MACHINE SUPPORT M: Bartosz Golaszewski <[email protected]> L: [email protected] (moderated for non-subscribers)
Signature · 1 line
2.43.0
Re: [PATCH v6 1/2] dt-bindings: crypto: Add binding for TI DTHE V2
Quoted 7 lines · T Pratham
Add DT binding for Texas Instruments DTHE V2 cryptography engine.
DTHE V2 is introduced as a part of TI AM62L SoC and can currently be only found in it.
Signed-off-by T Pratham <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>
Why are you changing the tags?!?
This is not really acceptable. You must use the tag exactly as given to you. Not alter it anyhow!
Best regards,
Krzysztof
T Pratham
maintainerRe: [PATCH v6 1/2] dt-bindings: crypto: Add binding for TI DTHE V2
Quoted 9 lines · Krzysztof Kozlowski
Quoted 7 lines · T Pratham
Add DT binding for Texas Instruments DTHE V2 cryptography engine.
DTHE V2 is introduced as a part of TI AM62L SoC and can currently be only found in it.
Signed-off-by T Pratham <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>
Quoted 8 lines
Why are you changing the tags?!?
This is not really acceptable. You must use the tag exactly as given to you. Not alter it anyhow!
Best regards,
Krzysztof
Apologies! Genuine error from my side adding the tag in v5. Got carried over to v6 as well. Will correct this in next re-spin.
Regards
T Pratham
T Pratham
maintainerPATCH v6 2/2 crypto: ti: Add driver for DTHE V2 AES Engine (ECB, CBC)
In reply to T PrathamAdd support for ECB and CBC modes in the AES Engine of the DTHE V2 hardware cryptography engine.
--- MAINTAINERS | 1 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/ti/Kconfig | 14 + drivers/crypto/ti/Makefile | 3 + drivers/crypto/ti/dthev2-aes.c | 411 ++++++++++++++++++++++++++++++ drivers/crypto/ti/dthev2-common.c | 220 ++++++++++++++++ drivers/crypto/ti/dthev2-common.h | 101 ++++++++ 8 files changed, 752 insertions(+) create mode 100644 drivers/crypto/ti/Kconfig create mode 100644 drivers/crypto/ti/Makefile create mode 100644 drivers/crypto/ti/dthev2-aes.c create mode 100644 drivers/crypto/ti/dthev2-common.c create mode 100644 drivers/crypto/ti/dthev2-common.h
MAINTAINERS +1 -0
@@ -25174,6 +25174,7 @@ M: T Pratham <[email protected]> L: [email protected] S: Supported F: Documentation/devicetree/bindings/crypto/ti,am62l-dthev2.yaml +F: drivers/crypto/ti/ TI DAVINCI MACHINE SUPPORT M: Bartosz Golaszewski <[email protected]>
drivers/crypto/Kconfig +1 -0
@@ -863,5 +863,6 @@ config CRYPTO_DEV_SA2UL source "drivers/crypto/aspeed/Kconfig" source "drivers/crypto/starfive/Kconfig" source "drivers/crypto/inside-secure/eip93/Kconfig" +source "drivers/crypto/ti/Kconfig" endif # CRYPTO_HW
drivers/crypto/Makefile +1 -0
@@ -48,3 +48,4 @@ obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic/ obj-y += intel/ obj-y += starfive/ obj-y += cavium/ +obj-$(CONFIG_ARCH_K3) += ti/
drivers/crypto/ti/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +config CRYPTO_DEV_TI_DTHEV2 + tristate "Support for TI DTHE V2 cryptography engine" + depends on CRYPTO && CRYPTO_HW && ARCH_K3 + select CRYPTO_ENGINE + select CRYPTO_SKCIPHER + select CRYPTO_ECB + select CRYPTO_CBC + help + This enables support for the TI DTHE V2 hw cryptography engine + which can be found on TI K3 SOCs. Selecting this enables use + of hardware offloading for cryptographic algorithms on + these devices, providing enhanced resistance against side-channel + attacks.
drivers/crypto/ti/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_CRYPTO_DEV_TI_DTHEV2) += dthev2.o +dthev2-objs := dthev2-common.o dthev2-aes.o
drivers/crypto/ti/dthev2-aes.c new file +411 -0
411 lines not on this page · raw message
drivers/crypto/ti/dthev2-common.c new file +220 -0
220 lines not on this page · raw message
drivers/crypto/ti/dthev2-common.h new file +101 -0
101 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v6 2/2] crypto: ti: Add driver for DTHE V2 AES Engine (ECB, CBC)
Hi,
Quoted 20 lines · T Pratham
Add support for ECB and CBC modes in the AES Engine of the DTHE V2 hardware cryptography engine.
Signed-off-by T Pratham <[email protected]>--- MAINTAINERS | 1 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/ti/Kconfig | 14 + drivers/crypto/ti/Makefile | 3 + drivers/crypto/ti/dthev2-aes.c | 411 ++++++++++++++++++++++++++++++ drivers/crypto/ti/dthev2-common.c | 220 ++++++++++++++++ drivers/crypto/ti/dthev2-common.h | 101 ++++++++ 8 files changed, 752 insertions(+) create mode 100644 drivers/crypto/ti/Kconfig create mode 100644 drivers/crypto/ti/Makefile create mode 100644 drivers/crypto/ti/dthev2-aes.c create mode 100644 drivers/crypto/ti/dthev2-common.c create mode 100644 drivers/crypto/ti/dthev2-common.h
[...]
Quoted 39 lines
drivers/crypto/ti/dthev2-common.c new file +39
-0+static int dthe_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct dthe_data *dev_data; +int ret; + + dev_data =devm_kzalloc (dev,sizeof (*dev_data),GFP_KERNEL ); +if (!dev_data) +return -ENOMEM ; + + dev_data->dev = dev; + dev_data->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (dev_data->regs)) +return PTR_ERR (dev_data->regs); + +platform_set_drvdata (pdev, dev_data); + +spin_lock (&dthe_dev_list.lock); +list_add (&dev_data->list, &dthe_dev_list.dev_list); +spin_unlock (&dthe_dev_list.lock); + + ret =dthe_dma_init (dev_data); +if (ret) + goto probe_dma_err; + + dev_data->engine =crypto_engine_alloc_init (dev,1 ); +if (!dev_data->engine) { + ret = -ENOMEM ; + goto probe_engine_err; + } + + ret =crypto_engine_start (dev_data->engine); +if (ret) { +dev_err (dev,"Failed to start crypto engine\n" ); + goto probe_engine_start_err; + } + + ret =dthe_register_algs (); +if (ret) {
drivers/crypto/ti/dthev2-common.c line 170
Quoted 10 lines
drivers/crypto/ti/dthev2-common.c new file +10
-0+dev_err (dev,"Failed to register algs\n" ); + goto probe_reg_err; + } + +return 0 ; + +probe_reg_err: +crypto_engine_stop (dev_data->engine); +probe_engine_start_err: +crypto_engine_exit (dev_data->engine);
crypto_engine_exit() calls crypto_engine_stop() internally, so there is no need to call both functions here. Just use crypto_engine_exit().
/**
* crypto_engine_exit - free the resources of hardware engine when exit
* @engine: the hardware engine need to be freed
*/
void crypto_engine_exit(struct crypto_engine *engine)
{
int ret;
ret = crypto_engine_stop(engine);
if (ret)
return;
kthread_destroy_worker(engine->kworker);
}Quoted 15 lines
drivers/crypto/ti/dthev2-common.c new file +15
-0+probe_engine_err: +dma_release_channel (dev_data->dma_aes_rx); +dma_release_channel (dev_data->dma_aes_tx); +dma_release_channel (dev_data->dma_sha_tx); +probe_dma_err: +spin_lock (&dthe_dev_list.lock); +list_del (&dev_data->list); +spin_unlock (&dthe_dev_list.lock); + +return ret; +} + +static void dthe_remove (struct platform_device *pdev) +{ +struct dthe_data *dev_data =platform_get_drvdata (pdev);
drivers/crypto/ti/dthev2-common.c line 195
Quoted 10 lines
drivers/crypto/ti/dthev2-common.c new file +10
-0+ +spin_lock (&dthe_dev_list.lock); +list_del (&dev_data->list); +spin_unlock (&dthe_dev_list.lock); + +dthe_unregister_algs (); + +crypto_engine_stop (dev_data->engine); +crypto_engine_exit (dev_data->engine); +
Same here.
drivers/crypto/ti/dthev2-common.c line 181
Quoted 4 lines
drivers/crypto/ti/dthev2-common.c new file +4
-0+dma_release_channel (dev_data->dma_aes_rx); +dma_release_channel (dev_data->dma_aes_tx); +dma_release_channel (dev_data->dma_sha_tx); +}
Ovidiu
T Pratham
maintainerRe: [PATCH v6 2/2] crypto: ti: Add driver for DTHE V2 AES Engine (ECB, CBC)
Quoted 26 lines · Ovidiu Panait
Hi,
Quoted 20 lines · T Pratham
Add support for ECB and CBC modes in the AES Engine of the DTHE V2 hardware cryptography engine.
Signed-off-by T Pratham <[email protected]>--- MAINTAINERS | 1 + drivers/crypto/Kconfig | 1 + drivers/crypto/Makefile | 1 + drivers/crypto/ti/Kconfig | 14 + drivers/crypto/ti/Makefile | 3 + drivers/crypto/ti/dthev2-aes.c | 411 ++++++++++++++++++++++++++++++ drivers/crypto/ti/dthev2-common.c | 220 ++++++++++++++++ drivers/crypto/ti/dthev2-common.h | 101 ++++++++ 8 files changed, 752 insertions(+) create mode 100644 drivers/crypto/ti/Kconfig create mode 100644 drivers/crypto/ti/Makefile create mode 100644 drivers/crypto/ti/dthev2-aes.c create mode 100644 drivers/crypto/ti/dthev2-common.c create mode 100644 drivers/crypto/ti/dthev2-common.h[...]
[...]
Quoted 14 lines
drivers/crypto/ti/dthev2-common.c line 170
Quoted 5 lines
drivers/crypto/ti/dthev2-common.c new file +5
-0+ +probe_reg_err: +crypto_engine_stop (dev_data->engine); +probe_engine_start_err: +crypto_engine_exit (dev_data->engine);
crypto_engine_exit()callscrypto_engine_stop()internally, so there is no need to call both functions here. Just usecrypto_engine_exit()./**
*crypto_engine_exit- free the resources of hardware engine when exit
* @engine: the hardware engine need to be freed
*/
voidcrypto_engine_exit(struct crypto_engine *engine)
Quoted 10 lines
{
int ret;
ret = crypto_engine_stop(engine);
if (ret)
return;
kthread_destroy_worker(engine->kworker);
}Thanks for this insight! Will correct this.
[...]
Quoted 2 lines
Ovidiu
Regards
T Pratham