Add support for hashing algorithms in TI DTHE V2
T Pratham
maintainerv2 cover Add support for hashing algorithms in TI DTHE V2
DTHEv2 is a new cryptography engine introduced in TI AM62L SoC. The features of DTHEv2 were detailed in [1]. Additional hardware details available in SoC TRM [2]. DTHEv2 includes, among its various sub-components, a hashing engine which is compliant with various IETF and NIST standards, including FIPS 180-3 and FIPS PUB 198.
This patch series adds support for the hashing algorithms SHA224/256/384/512 and MD5 as well as their HMAC counnterparts for the hashing engine of Texas Instruments DTHE V2 crypto driver.
This patch series depends on the following previous series [3]:
[PATCH v8 0/3] Add support for more AES modes in TI DTHEv2
The driver is tested using full kernel crypto selftests (CRYPTO_SELFTESTS_FULL) which all pass successfully [4].
---
[1]: [PATCH v7 0/2] Add support for Texas Instruments DTHEv2 Crypto Engine
[2]: Section 14.6.3 (DMA Control Registers -> DMASS_DTHE)
[3]: [PATCH v8 0/3] Add support for more AES modes in TI DTHEv2
[4]: DTHEv2 kernel self-tests logs
Changelog:
v2:
- Completely revamped the driver to use the new CRYPTO_AHASH_BLOCK_ONLY framework for handling partial blocks and crypto_engine for queueing.
- Added HMAC as well.
Link to previous versions:
v1: https://lore.kernel.org/all/[email protected]/
---
T Pratham (3):
crypto: ti - Add support for SHA224/256/384/512 in DTHEv2 driver
crypto: ti - Add support for MD5 in DTHEv2 Hashing Engine driver
crypto: ti - Add support for HMAC in DTHEv2 Hashing Engine driver
drivers/crypto/ti/Kconfig | 4 + drivers/crypto/ti/Makefile | 2 +- drivers/crypto/ti/dthev2-aes.c | 6 +- drivers/crypto/ti/dthev2-common.c | 37 +- drivers/crypto/ti/dthev2-common.h | 58 +- drivers/crypto/ti/dthev2-hash.c | 922 ++++++++++++++++++++++++++++++ 6 files changed, 1011 insertions(+), 18 deletions(-) create mode 100644 drivers/crypto/ti/dthev2-hash.c
Signature · 1 line
2.34.1
T Pratham
maintainerPATCH v2 1/3 crypto: ti - Add support for SHA224/256/384/512 in DTHEv2 driver
Add support for SHA224, SHA256, SHA384, SHA512 algorithms in the Hashing Engine of the DTHEv2 hardware cryptographic engine.
--- drivers/crypto/ti/Kconfig | 2 + drivers/crypto/ti/Makefile | 2 +- drivers/crypto/ti/dthev2-aes.c | 6 +- drivers/crypto/ti/dthev2-common.c | 37 +- drivers/crypto/ti/dthev2-common.h | 47 ++- drivers/crypto/ti/dthev2-hash.c | 591 ++++++++++++++++++++++++++++++ 6 files changed, 671 insertions(+), 14 deletions(-) create mode 100644 drivers/crypto/ti/dthev2-hash.c
drivers/crypto/ti/Kconfig +2 -0
@@ -10,6 +10,8 @@ config CRYPTO_DEV_TI_DTHEV2 select CRYPTO_XTS select CRYPTO_GCM select CRYPTO_CCM + select CRYPTO_SHA256 + select CRYPTO_SHA512 select SG_SPLIT help This enables support for the TI DTHE V2 hw cryptography engine
drivers/crypto/ti/Makefile +1 -1
@@ -1,3 +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 +dthev2-objs := dthev2-common.o dthev2-aes.o dthev2-hash.o
drivers/crypto/ti/dthev2-aes.c +3 -3
@@ -520,7 +520,7 @@ static int dthe_aes_run(struct crypto_engine *engine, void *areq) }local_bh_disable (); -crypto_finalize_skcipher_request (dev_data->engine, req, ret); +crypto_finalize_skcipher_request (engine, req, ret);local_bh_enable ();return 0 ; }
@@ -564,7 +564,7 @@ static int dthe_aes_crypt(struct skcipher_request *req)return 0 ; } - engine = dev_data->engine; + engine = dev_data->aes_engine;return crypto_transfer_skcipher_request_to_engine (engine, req); }
@@ -1170,7 +1170,7 @@ static int dthe_aead_crypt(struct aead_request *req) (ctx->aes_mode == DTHE_AES_CCM && !is_zero_ctr))return dthe_aead_do_fallback (req); - engine = dev_data->engine; + engine = dev_data->aes_engine;return crypto_transfer_aead_request_to_engine (engine, req); }
drivers/crypto/ti/dthev2-common.c +30 -7
@@ -96,6 +96,9 @@ static int dthe_dma_init(struct dthe_data *dev_data) goto err_dma_sha_tx; } +// Do AES Rx and Tx channel config here because it is invariant of AES mode +// SHA Tx channel config is done before DMA transfer depending on hashing algorithm +memzero_explicit (&cfg,sizeof (cfg)); cfg.src_addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ;
@@ -130,11 +133,17 @@ static int dthe_dma_init(struct dthe_data *dev_data)static int dthe_register_algs (void ) { -return dthe_register_aes_algs (); +int ret =0 ; + + ret |=dthe_register_hash_algs (); + ret |=dthe_register_aes_algs (); + +return ret; }static void dthe_unregister_algs (void ) { +dthe_unregister_hash_algs ();dthe_unregister_aes_algs (); }
@@ -163,15 +172,26 @@ static int dthe_probe(struct platform_device *pdev)if (ret) goto probe_dma_err; - dev_data->engine =crypto_engine_alloc_init (dev,1 ); -if (!dev_data->engine) { + dev_data->aes_engine =crypto_engine_alloc_init (dev,1 ); +if (!dev_data->aes_engine) { ret = -ENOMEM ; goto probe_engine_err; } + dev_data->hash_engine =crypto_engine_alloc_init (dev,1 ); +if (!dev_data->hash_engine) { + ret = -ENOMEM ; + goto probe_hash_engine_err; + } + + ret =crypto_engine_start (dev_data->aes_engine); +if (ret) { +dev_err (dev,"Failed to start crypto engine for AES\n" ); + goto probe_engine_start_err; + } - ret =crypto_engine_start (dev_data->engine); + ret =crypto_engine_start (dev_data->hash_engine);if (ret) { -dev_err (dev,"Failed to start crypto engine\n" ); +dev_err (dev,"Failed to start crypto engine for hash\n" ); goto probe_engine_start_err; }
@@ -184,7 +204,9 @@ static int dthe_probe(struct platform_device *pdev)return 0 ; probe_engine_start_err: -crypto_engine_exit (dev_data->engine); +crypto_engine_exit (dev_data->hash_engine); +probe_hash_engine_err: +crypto_engine_exit (dev_data->aes_engine); probe_engine_err:dma_release_channel (dev_data->dma_aes_rx);dma_release_channel (dev_data->dma_aes_tx);
@@ -207,7 +229,8 @@ static void dthe_remove(struct platform_device *pdev)dthe_unregister_algs (); -crypto_engine_exit (dev_data->engine); +crypto_engine_exit (dev_data->aes_engine); +crypto_engine_exit (dev_data->hash_engine);dma_release_channel (dev_data->dma_aes_rx);dma_release_channel (dev_data->dma_aes_tx);
drivers/crypto/ti/dthev2-common.h +44 -3
93 lines not on this page · raw message
drivers/crypto/ti/dthev2-hash.c new file +591 -0
591 lines not on this page · raw message
Signature · 1 line
2.34.1
T Pratham
maintainerPATCH v2 2/3 crypto: ti - Add support for MD5 in DTHEv2 Hashing Engine driver
In reply to T PrathamAdd support for MD5 algorithm in the hashing engine of DTHEv2 hardware cryptographic engine.
--- drivers/crypto/ti/Kconfig | 1 + drivers/crypto/ti/dthev2-common.h | 1 + drivers/crypto/ti/dthev2-hash.c | 43 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+)
drivers/crypto/ti/Kconfig +1 -0
@@ -12,6 +12,7 @@ config CRYPTO_DEV_TI_DTHEV2 select CRYPTO_CCM select CRYPTO_SHA256 select CRYPTO_SHA512 + select CRYPTO_MD5 select SG_SPLIT help This enables support for the TI DTHE V2 hw cryptography engine
drivers/crypto/ti/dthev2-common.h +1 -0
@@ -17,6 +17,7 @@#include <crypto/internal/aead.h> #include <crypto/internal/hash.h> #include <crypto/internal/skcipher.h> +#include <crypto/md5.h> #include <crypto/sha2.h> #include <linux/delay.h>
drivers/crypto/ti/dthev2-hash.c +43 -0
73 lines not on this page · raw message
Signature · 1 line
2.34.1
T Pratham
maintainerPATCH v2 3/3 crypto: ti - Add support for HMAC in DTHEv2 Hashing Engine driver
In reply to T PrathamAdd support for HMAC-SHA512/384/256/224 and HMAC-MD5 algorithms in the hashing engine of the DTHEv2 hardware cryptographic engine.
--- drivers/crypto/ti/Kconfig | 1 + drivers/crypto/ti/dthev2-common.h | 10 +- drivers/crypto/ti/dthev2-hash.c | 290 +++++++++++++++++++++++++++++- 3 files changed, 296 insertions(+), 5 deletions(-)
drivers/crypto/ti/Kconfig +1 -0
@@ -13,6 +13,7 @@ config CRYPTO_DEV_TI_DTHEV2 select CRYPTO_SHA256 select CRYPTO_SHA512 select CRYPTO_MD5 + select CRYPTO_HMAC select SG_SPLIT help This enables support for the TI DTHE V2 hw cryptography engine
drivers/crypto/ti/dthev2-common.h +6 -4
@@ -31,9 +31,9 @@#define DTHE_DMA_TIMEOUT_MS 2000/* * Size of largest possible key (of all algorithms) to be stored in dthe_tfm_ctx -* This is currently the keysize of XTS-AES-256 which is 512 bits (64 bytes) +* This is currently the keysize of HMAC-SHA512 which is 1024 bits (128 bytes) */ -#define DTHE_MAX_KEYSIZE (AES_MAX_KEY_SIZE * 2) +#define DTHE_MAX_KEYSIZE (SHA512_BLOCK_SIZE)enum dthe_hash_alg_sel {DTHE_HASH_MD5 =0 ,
@@ -93,9 +93,9 @@ 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 +* @keylen: Key length for algorithms that use a key * @authsize: Authentication size for modes with authentication -* @key: AES key +* @key: Buffer storing the key * @aes_mode: AES mode * @hash_mode: Hashing Engine mode * @phash_size: partial hash size of the hash algorithm selected
@@ -135,6 +135,7 @@ struct dthe_aes_req_ctx {* @phash: buffer to store a partial hash from a previous operation * @digestcnt: stores the digest count from a previous operation; currently hardware only provides * a single 32-bit value even for SHA384/512 +* @odigest: buffer to store the outer digest from a previous operation * @phash_available: flag indicating if a partial hash from a previous operation is available * @flags: flags for internal use * @padding: padding buffer for handling unaligned data
@@ -143,6 +144,7 @@ struct dthe_aes_req_ctx {struct dthe_hash_req_ctx {u32 phash[SHA512_DIGEST_SIZE /sizeof (u32)];u64 digestcnt[2 ]; +u32 odigest[SHA512_DIGEST_SIZE /sizeof (u32)];u8 phash_available;u8 flags;u8 padding[SHA512_BLOCK_SIZE ];
drivers/crypto/ti/dthev2-hash.c +289 -1
363 lines not on this page · raw message
Signature · 1 line
2.34.1
T Pratham
maintainerQuoted 10 lines · T Pratham
DTHEv2 is a new cryptography engine introduced in TI AM62L SoC. The features of DTHEv2 were detailed in [1]. Additional hardware details available in SoC TRM [2]. DTHEv2 includes, among its various sub-components, a hashing engine which is compliant with various IETF and NIST standards, including FIPS 180-3 and FIPS PUB 198.
This patch series adds support for the hashing algorithms SHA224/256/384/512 and MD5 as well as their HMAC counnterparts for the hashing engine of Texas Instruments DTHE V2 crypto driver.
Quoted 7 lines
This patch series depends on the following previous series [3]:
[PATCH v8 0/3] Add support for more AES modes in TI DTHEv2The driver is tested using full kernel crypto selftests (
CRYPTO_SELFTESTS_FULL) which all pass successfully [4].Signed-off-by T Pratham <[email protected]>
Sent an updated version with minor modifications:
https://lore.kernel.org/all/[email protected]/
Signature · 2 lines
Regards T Pratham <[email protected]>