Skip to contentSkip to conversation

Add support for more AES modes in TI DTHEv2

PATCH In review T Pratham 2 participants 4 messages Mar 20 – Mar 27

Subsystems (2)
lore
Share & tools
lore

T Pratham

author maintainer
#0 lore raw

v11 cover Add support for more AES modes in TI DTHEv2

DTHEv2 is a new cryptography engine introduced in TI AM62L SoC. The features of DTHEv2 and details of AES modes supported were detailed in [1]. Additional hardware details available in SoC TRM [2].

This patch series adds support for the following AES modes:
- AES-GCM
- AES-CCM

The driver is tested using full kernel crypto selftests (CRYPTO_SELFTESTS_FULL) which all pass successfully [3].

---
[1]: [PATCH v7 0/2] Add support for Texas Instruments DTHEv2 Crypto Engine

[2]: Section 14.6.3 (DMA Control Registers -> DMASS_DTHE)

[3]: DTHEv2 AES Engine kernel self-tests logs

Change log:
v11:
- Removed AES-CTR patch merged in v10
- Split scatterlists into AAD and crypt scatterlists to be sent in separate DMA transactions. In-place operations now have the modified crypt scatterlist same for src and dst.
- Added correct handling of in-place operations which require scatterlists to be mapped with DMA_BIDIRECTIONAL dma direction.
- Moved DMA callback registration to the last DMA transcriptor based on conditions (cryptlen = 0 or not).
- Minor cleanup and added dev_err messages.
v10:
- Moved dthe_copy_sg() into AES-CTR patch as it is the first user. Thus maintaining bisectability.
- Corrected padding array size in req_ctx to avoid buffer overflow bug.
- Check for error in registration individually for AES and AEAD algos.
- Fixed return value being overridden in AEAD tag calculation/verification.
- Changed memcmp to crypto_memneq to enhance security.
- Moved verifying AEAD keylen to before copying it in ctx to avoid any buffer overflow bug.
v9:
- Removed modifying scatterlist in AES-CTR. Replaced with allocating our own scatterlist for the same purpose to handle padding.
v8:
- Removed scatterlist chaining from AES-CTR, along with accompanying helper functions added in v6. Replaced with sending only complete blocks to hardware and handling the last partial block in software.
v7:
- Moved padding buffer to inside request ctx.
- Removed already merged AES-XTS patch.
- Moved dthe_copy_sg() helper from CTR patch to GCM patch, where it is being used for first time.
v6:
- Removed memory alloc calls on the data path (CTR padding in aes_run), replaced with scatterlist chaining for added a pad buffer. Added two accompanying helpers dthe_chain_pad_sg() and dthe_unchain_padded_sg().
- Replaced GFP_KERNEL to GFP_ATOMIC in AEAD src and dst scatterlist prep functions to avoid deadlock in data path.
- Added fallback to software in AEADs on failure.
v5:
- Simplified AES-XTS fallback allocation, directly using xts(aes) for alg_name
- Changed fallback to sync and allocated on stack
v4:
- Return -EINVAL in AES-XTS when cryptlen = 0
- Added software fallback for AES-XTS when ciphertext stealing is required (cryptlen is not multiple of AES_BLOCK_SIZE)
- Changed DTHE_MAX_KEYSIZE definition to use AES_MAX_KEY_SIZE instead of AES_KEYSIZE_256
- In AES-CTR, also pad dst scatterlist when padding src scatterlist
- Changed polling for TAG ready to use readl_relaxed_poll_timeout()
- Used crypto API functions to access struct members instead of directly accessing them (crypto_aead_tfm and aead_request_flags)
- Allocated padding buffers in AEAD algos on the stack.
- Changed helper functions dthe_aead_prep_* to return ERR_PTR on error
- Changed some error labels in dthe_aead_run to improve clarity
- Moved iv_in[] declaration from middle of the function to the top
- Corrected setting CCM M value in the hardware register
- Added checks for CCM L value input in the algorithm from IV.
- Added more fallback cases for CCM where hardware has limitations
v3:
- Added header files to remove implicit declaration error.
- Corrected assignment of src_nents and dst_nents in dthe_aead_run (Ran the lkp kernel test bot script locally to ensure no more such errors are present)
v2:
- Corrected assignment of variable unpadded_cryptlen in dthe_aead_run.
- Removed some if conditions which are always false, and documented the cases in comments.
- Moved polling of TAG ready register to a separate function and returning -ETIMEDOUT on poll timeout.
- Corrected comments to adhere to kernel coding guidelines.

Link to previous version:

v10: https://lore.kernel.org/all/[email protected]/
v9: https://lore.kernel.org/all/[email protected]/
v8: https://lore.kernel.org/all/[email protected]/
v7: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
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):
crypto: ti - Add support for AES-GCM in DTHEv2 driver
crypto: ti - Add support for AES-CCM in DTHEv2 driver

 drivers/crypto/ti/Kconfig         |   3 +
 drivers/crypto/ti/dthev2-aes.c    | 726 +++++++++++++++++++++++++++++-
 drivers/crypto/ti/dthev2-common.h |  12 +-
 3 files changed, 738 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v11 1/2 crypto: ti - Add support for AES-GCM in DTHEv2 driver

AES-GCM is an AEAD algorithm supporting both encryption and authentication of data. This patch introduces support for AES-GCM as the first AEAD algorithm supported by the DTHEv2 driver.

---
 drivers/crypto/ti/Kconfig         |   2 +
 drivers/crypto/ti/dthev2-aes.c    | 618 +++++++++++++++++++++++++++++-
 drivers/crypto/ti/dthev2-common.h |  11 +-
 3 files changed, 628 insertions(+), 3 deletions(-)
drivers/crypto/ti/Kconfig +2 -0
index 6027e12de279d..221e483737439 100644
@@ -8,6 +8,8 @@ config CRYPTO_DEV_TI_DTHEV2
 	select CRYPTO_CBC
 	select CRYPTO_CTR
 	select CRYPTO_XTS
+	select CRYPTO_GCM
+	select SG_SPLIT
 	help
 	  This enables support for the TI DTHE V2 hw cryptography engine
 	  which can be found on TI K3 SOCs. Selecting this enables use
drivers/crypto/ti/dthev2-aes.c +617 -1

671 lines not on this page · raw message

drivers/crypto/ti/dthev2-common.h +9 -2
index 5239ee93c9442..8514f0df8ac3d 100644
@@ -38,6 +38,7 @@ enum dthe_aes_mode {
 	DTHE_AES_CBC,
 	DTHE_AES_CTR,
 	DTHE_AES_XTS,
+	DTHE_AES_GCM,
 };
 
 /* Driver specific struct definitions */
@@ -78,16 +79,22 @@ struct dthe_list {
  * struct dthe_tfm_ctx - Transform ctx struct containing ctx for all sub-components of DTHE V2
  * @dev_data: Device data struct pointer
  * @keylen: AES key length
+ * @authsize: Authentication size for modes with authentication
  * @key: AES key
  * @aes_mode: AES mode
+ * @aead_fb: Fallback crypto aead handle
  * @skcipher_fb: Fallback crypto skcipher handle for AES-XTS mode
  */
 struct dthe_tfm_ctx {
 	struct dthe_data *dev_data;
 	unsigned int keylen;
+	unsigned int authsize;
 	u32 key[DTHE_MAX_KEYSIZE / sizeof(u32)];
 	enum dthe_aes_mode aes_mode;
-	struct crypto_sync_skcipher *skcipher_fb;
+	union {
+		struct crypto_sync_aead *aead_fb;
+		struct crypto_sync_skcipher *skcipher_fb;
+	};
 };
 
 /**
@@ -98,7 +105,7 @@ struct dthe_tfm_ctx {
  */
 struct dthe_aes_req_ctx {
 	int enc;
-	u8 padding[AES_BLOCK_SIZE];
+	u8 padding[2 * AES_BLOCK_SIZE];
 	struct completion aes_compl;
 };
 
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v11 2/2 crypto: ti - Add support for AES-CCM in DTHEv2 driver

In reply to T Pratham

AES-CCM is an AEAD algorithm supporting both encryption and authentication of data. This patch introduces support for AES-CCM AEAD algorithm in the DTHEv2 driver.

---
 drivers/crypto/ti/Kconfig         |   1 +
 drivers/crypto/ti/dthev2-aes.c    | 140 ++++++++++++++++++++++++++----
 drivers/crypto/ti/dthev2-common.h |   1 +
 3 files changed, 126 insertions(+), 16 deletions(-)
drivers/crypto/ti/Kconfig +1 -0
index 221e483737439..1a3a571ac8cef 100644
@@ -9,6 +9,7 @@ config CRYPTO_DEV_TI_DTHEV2
 	select CRYPTO_CTR
 	select CRYPTO_XTS
 	select CRYPTO_GCM
+	select CRYPTO_CCM
 	select SG_SPLIT
 	help
 	  This enables support for the TI DTHE V2 hw cryptography engine
drivers/crypto/ti/dthev2-aes.c +124 -16

217 lines not on this page · raw message

drivers/crypto/ti/dthev2-common.h +1 -0
index 8514f0df8ac3d..d4a3b9c18bbc1 100644
@@ -39,6 +39,7 @@ enum dthe_aes_mode {
 	DTHE_AES_CTR,
 	DTHE_AES_XTS,
 	DTHE_AES_GCM,
+	DTHE_AES_CCM,
 };
 
 /* Driver specific struct definitions */
Signature · 1 line
2.34.1
maintainer
#3 lore raw
In reply to T Pratham
Quoted 111 lines · T Pratham

DTHEv2 is a new cryptography engine introduced in TI AM62L SoC. The features of DTHEv2 and details of AES modes supported were detailed in [1]. Additional hardware details available in SoC TRM [2].

This patch series adds support for the following AES modes:
- AES-GCM
- AES-CCM

The driver is tested using full kernel crypto selftests (CRYPTO_SELFTESTS_FULL) which all pass successfully [3].

---
[1]: [PATCH v7 0/2] Add support for Texas Instruments DTHEv2 Crypto Engine

[2]: Section 14.6.3 (DMA Control Registers -> DMASS_DTHE)

[3]: DTHEv2 AES Engine kernel self-tests logs

Change log:
v11:
- Removed AES-CTR patch merged in v10
- Split scatterlists into AAD and crypt scatterlists to be sent in separate DMA transactions. In-place operations now have the modified crypt scatterlist same for src and dst.
- Added correct handling of in-place operations which require scatterlists to be mapped with DMA_BIDIRECTIONAL dma direction.
- Moved DMA callback registration to the last DMA transcriptor based on conditions (cryptlen = 0 or not).
- Minor cleanup and added dev_err messages.
v10:
- Moved dthe_copy_sg() into AES-CTR patch as it is the first user. Thus maintaining bisectability.
- Corrected padding array size in req_ctx to avoid buffer overflow bug.
- Check for error in registration individually for AES and AEAD algos.
- Fixed return value being overridden in AEAD tag calculation/verification.
- Changed memcmp to crypto_memneq to enhance security.
- Moved verifying AEAD keylen to before copying it in ctx to avoid any buffer overflow bug.
v9:
- Removed modifying scatterlist in AES-CTR. Replaced with allocating our own scatterlist for the same purpose to handle padding.
v8:
- Removed scatterlist chaining from AES-CTR, along with accompanying helper functions added in v6. Replaced with sending only complete blocks to hardware and handling the last partial block in software.
v7:
- Moved padding buffer to inside request ctx.
- Removed already merged AES-XTS patch.
- Moved dthe_copy_sg() helper from CTR patch to GCM patch, where it is being used for first time.
v6:
- Removed memory alloc calls on the data path (CTR padding in aes_run), replaced with scatterlist chaining for added a pad buffer. Added two accompanying helpers dthe_chain_pad_sg() and dthe_unchain_padded_sg().
- Replaced GFP_KERNEL to GFP_ATOMIC in AEAD src and dst scatterlist prep functions to avoid deadlock in data path.
- Added fallback to software in AEADs on failure.
v5:
- Simplified AES-XTS fallback allocation, directly using xts(aes) for alg_name
- Changed fallback to sync and allocated on stack
v4:
- Return -EINVAL in AES-XTS when cryptlen = 0
- Added software fallback for AES-XTS when ciphertext stealing is required (cryptlen is not multiple of AES_BLOCK_SIZE)
- Changed DTHE_MAX_KEYSIZE definition to use AES_MAX_KEY_SIZE instead of AES_KEYSIZE_256
- In AES-CTR, also pad dst scatterlist when padding src scatterlist
- Changed polling for TAG ready to use readl_relaxed_poll_timeout()
- Used crypto API functions to access struct members instead of directly accessing them (crypto_aead_tfm and aead_request_flags)
- Allocated padding buffers in AEAD algos on the stack.
- Changed helper functions dthe_aead_prep_* to return ERR_PTR on error
- Changed some error labels in dthe_aead_run to improve clarity
- Moved iv_in[] declaration from middle of the function to the top
- Corrected setting CCM M value in the hardware register
- Added checks for CCM L value input in the algorithm from IV.
- Added more fallback cases for CCM where hardware has limitations
v3:
- Added header files to remove implicit declaration error.
- Corrected assignment of src_nents and dst_nents in dthe_aead_run (Ran the lkp kernel test bot script locally to ensure no more such errors are present)
v2:
- Corrected assignment of variable unpadded_cryptlen in dthe_aead_run.
- Removed some if conditions which are always false, and documented the cases in comments.
- Moved polling of TAG ready register to a separate function and returning -ETIMEDOUT on poll timeout.
- Corrected comments to adhere to kernel coding guidelines.

Link to previous version:

v10: https://lore.kernel.org/all/[email protected]/
v9: https://lore.kernel.org/all/[email protected]/
v8: https://lore.kernel.org/all/[email protected]/
v7: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/
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]/
---

Quoted 11 lines

T Pratham (2):
crypto: ti - Add support for AES-GCM in DTHEv2 driver
crypto: ti - Add support for AES-CCM in DTHEv2 driver

 drivers/crypto/ti/Kconfig         |   3 +
 drivers/crypto/ti/dthev2-aes.c    | 726 +++++++++++++++++++++++++++++-
 drivers/crypto/ti/dthev2-common.h |  12 +-
 3 files changed, 738 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1

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