octeontx2-pf: macsec: Use AES library instead of ecb(aes) skcipher
PATCH 1/1 octeontx2-pf: macsec: Use AES library instead of ecb(aes) skcipher
cn10k_ecb_aes_encrypt() just encrypts a single block with AES. That is much more easily and efficiently done with the AES library than crypto_skcipher. Use the AES library instead.
--- .../net/ethernet/marvell/octeontx2/Kconfig | 1 + .../marvell/octeontx2/nic/cn10k_macsec.c | 53 +++++-------------- 2 files changed, 13 insertions(+), 41 deletions(-)
drivers/net/ethernet/marvell/octeontx2/Kconfig +1 -0
@@ -31,10 +31,11 @@ config NDC_DIS_DYNAMIC_CACHING config OCTEONTX2_PF tristate "Marvell OcteonTX2 NIC Physical Function driver" select OCTEONTX2_MBOX select NET_DEVLINK select PAGE_POOL + select CRYPTO_LIB_AES if MACSEC depends on (64BIT && COMPILE_TEST) || ARM64 select DIMLIB depends on PCI depends on PTP_1588_CLOCK_OPTIONAL depends on MACSEC || !MACSEC
drivers/net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c +12 -41
78 lines not on this page · raw message
base-commit: fb78a629b4f0eb399b413f6c093a3da177b3a4eb
Signature · 1 line
2.53.0
Subbaraya Sundeep
maintainerHi,
Quoted 4 lines · Eric Biggers
cn10k_ecb_aes_encrypt()just encrypts a single block with AES. That is much more easily and efficiently done with the AES library thancrypto_skcipher. Use the AES library instead.
Thanks for the patch. Give me couple of days, I will test and ack.
Sundeep
Quoted 111 lines
Signed-off-by Eric Biggers <[email protected]>--- .../net/ethernet/marvell/octeontx2/Kconfig | 1 + .../marvell/octeontx2/nic/cn10k_macsec.c | 53 +++++-------------- 2 files changed, 13 insertions(+), 41 deletions(-)drivers/net/ethernet/marvell/octeontx2/Kconfig +1
-0@@ -31,10 +31,11 @@ config NDC_DIS_DYNAMIC_CACHING config OCTEONTX2_PF tristate "Marvell OcteonTX2 NIC Physical Function driver" select OCTEONTX2_MBOX select NET_DEVLINK select PAGE_POOL + select CRYPTO_LIB_AES if MACSEC depends on (64BIT && COMPILE_TEST) || ARM64 select DIMLIB depends on PCI depends on PTP_1588_CLOCK_OPTIONAL depends on MACSEC || !MACSECdrivers/net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c +12
-41@@ -2,11 +2,11 @@/* Marvell MACSEC hardware offload driver * * Copyright (C) 2022 Marvell. */ -#include <crypto/skcipher.h> +#include <crypto/aes.h> #include <linux/rtnetlink.h> #include <linux/bitfield.h> #include "otx2_common.h" #define MCS_TCAM0_MAC_DA_MASK GENMASK_ULL(47, 0)@@ -44,55 +44,26 @@#define MCS_TCI_C 0x04/* changed text */ #define CN10K_MAX_HASH_LEN 16#define CN10K_MAX_SAK_LEN 32 -static int cn10k_ecb_aes_encrypt (struct otx2_nic *pfvf,u8 *sak, -u16 sak_len,u8 *hash) +static int cn10k_ecb_aes_encrypt (struct otx2_nic *pfvf,const u8 *sak, +u16 sak_len,u8 hash[CN10K_MAX_HASH_LEN ]) { -u8 data[CN10K_MAX_HASH_LEN ] = {0 }; -struct skcipher_request *req =NULL ; -struct scatterlist sg_src, sg_dst; -struct crypto_skcipher *tfm; -DECLARE_CRYPTO_WAIT (wait); -int err; - - tfm =crypto_alloc_skcipher ("ecb(aes)" ,0 ,0 ); -if (IS_ERR (tfm)) { -dev_err (pfvf->dev,"failed to allocate transform for ecb-aes\n" ); -return PTR_ERR (tfm); - } - - req =skcipher_request_alloc (tfm,GFP_KERNEL ); -if (!req) { -dev_err (pfvf->dev,"failed to allocate request for skcipher\n" ); - err = -ENOMEM ; - goto free_tfm; - } +static const u8 zeroes[CN10K_MAX_HASH_LEN ]; +struct aes_enckey aes; - err =crypto_skcipher_setkey (tfm, sak, sak_len); -if (err) { -dev_err (pfvf->dev,"failed to set key for skcipher\n" ); - goto free_req; +if (aes_prepareenckey (&aes, sak, sak_len) !=0 ) { +dev_err (pfvf->dev,"invalid AES key length: %d\n" , sak_len); +return -EINVAL ; } -/* build sg list */ -sg_init_one (&sg_src, data,CN10K_MAX_HASH_LEN ); -sg_init_one (&sg_dst, hash,CN10K_MAX_HASH_LEN ); - -skcipher_request_set_callback (req,0 , crypto_req_done, &wait); -skcipher_request_set_crypt (req, &sg_src, &sg_dst, -CN10K_MAX_HASH_LEN ,NULL ); +static_assert (CN10K_MAX_HASH_LEN ==AES_BLOCK_SIZE ); +aes_encrypt (&aes, hash, zeroes); - err =crypto_skcipher_encrypt (req); - err =crypto_wait_req (err, &wait); - -free_req: -skcipher_request_free (req); -free_tfm: -crypto_free_skcipher (tfm); -return err; +memzero_explicit (&aes,sizeof (aes)); +return 0 ; }static struct cn10k_mcs_txsc *cn10k_mcs_get_txsc (struct cn10k_mcs_cfg *cfg,struct macsec_secy *secy) {base-commit:
fb78a629b4f0eb399b413f6c093a3da177b3a4ebSignature · 1 line
2.53.0
Quoted 5 lines · Eric Biggers
cn10k_ecb_aes_encrypt()just encrypts a single block with AES. That is much more easily and efficiently done with the AES library thancrypto_skcipher. Use the AES library instead.Signed-off-by Eric Biggers <[email protected]>
Thanks,
Sundeep
Quoted 110 lines
--- .../net/ethernet/marvell/octeontx2/Kconfig | 1 + .../marvell/octeontx2/nic/cn10k_macsec.c | 53 +++++-------------- 2 files changed, 13 insertions(+), 41 deletions(-)drivers/net/ethernet/marvell/octeontx2/Kconfig +1
-0@@ -31,10 +31,11 @@ config NDC_DIS_DYNAMIC_CACHING config OCTEONTX2_PF tristate "Marvell OcteonTX2 NIC Physical Function driver" select OCTEONTX2_MBOX select NET_DEVLINK select PAGE_POOL + select CRYPTO_LIB_AES if MACSEC depends on (64BIT && COMPILE_TEST) || ARM64 select DIMLIB depends on PCI depends on PTP_1588_CLOCK_OPTIONAL depends on MACSEC || !MACSECdrivers/net/ethernet/marvell/octeontx2/nic/cn10k_macsec.c +12
-41@@ -2,11 +2,11 @@/* Marvell MACSEC hardware offload driver * * Copyright (C) 2022 Marvell. */ -#include <crypto/skcipher.h> +#include <crypto/aes.h> #include <linux/rtnetlink.h> #include <linux/bitfield.h> #include "otx2_common.h" #define MCS_TCAM0_MAC_DA_MASK GENMASK_ULL(47, 0)@@ -44,55 +44,26 @@#define MCS_TCI_C 0x04/* changed text */ #define CN10K_MAX_HASH_LEN 16#define CN10K_MAX_SAK_LEN 32 -static int cn10k_ecb_aes_encrypt (struct otx2_nic *pfvf,u8 *sak, -u16 sak_len,u8 *hash) +static int cn10k_ecb_aes_encrypt (struct otx2_nic *pfvf,const u8 *sak, +u16 sak_len,u8 hash[CN10K_MAX_HASH_LEN ]) { -u8 data[CN10K_MAX_HASH_LEN ] = {0 }; -struct skcipher_request *req =NULL ; -struct scatterlist sg_src, sg_dst; -struct crypto_skcipher *tfm; -DECLARE_CRYPTO_WAIT (wait); -int err; - - tfm =crypto_alloc_skcipher ("ecb(aes)" ,0 ,0 ); -if (IS_ERR (tfm)) { -dev_err (pfvf->dev,"failed to allocate transform for ecb-aes\n" ); -return PTR_ERR (tfm); - } - - req =skcipher_request_alloc (tfm,GFP_KERNEL ); -if (!req) { -dev_err (pfvf->dev,"failed to allocate request for skcipher\n" ); - err = -ENOMEM ; - goto free_tfm; - } +static const u8 zeroes[CN10K_MAX_HASH_LEN ]; +struct aes_enckey aes; - err =crypto_skcipher_setkey (tfm, sak, sak_len); -if (err) { -dev_err (pfvf->dev,"failed to set key for skcipher\n" ); - goto free_req; +if (aes_prepareenckey (&aes, sak, sak_len) !=0 ) { +dev_err (pfvf->dev,"invalid AES key length: %d\n" , sak_len); +return -EINVAL ; } -/* build sg list */ -sg_init_one (&sg_src, data,CN10K_MAX_HASH_LEN ); -sg_init_one (&sg_dst, hash,CN10K_MAX_HASH_LEN ); - -skcipher_request_set_callback (req,0 , crypto_req_done, &wait); -skcipher_request_set_crypt (req, &sg_src, &sg_dst, -CN10K_MAX_HASH_LEN ,NULL ); +static_assert (CN10K_MAX_HASH_LEN ==AES_BLOCK_SIZE ); +aes_encrypt (&aes, hash, zeroes); - err =crypto_skcipher_encrypt (req); - err =crypto_wait_req (err, &wait); - -free_req: -skcipher_request_free (req); -free_tfm: -crypto_free_skcipher (tfm); -return err; +memzero_explicit (&aes,sizeof (aes)); +return 0 ; }static struct cn10k_mcs_txsc *cn10k_mcs_get_txsc (struct cn10k_mcs_cfg *cfg,struct macsec_secy *secy) {base-commit:
fb78a629b4f0eb399b413f6c093a3da177b3a4ebSignature · 1 line
2.53.0
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Sat, 21 Mar 2026 15:52:08 -0700 you wrote:
cn10k_ecb_aes_encrypt()just encrypts a single block with AES. That is much more easily and efficiently done with the AES library thancrypto_skcipher. Use the AES library instead.Signed-off-by Eric Biggers <[email protected]>--- .../net/ethernet/marvell/octeontx2/Kconfig | 1 + .../marvell/octeontx2/nic/cn10k_macsec.c | 53 +++++-------------- 2 files changed, 13 insertions(+), 41 deletions(-)[...]
Here is the summary with links:
- [net-next] octeontx2-pf: macsec: Use AES library instead of ecb(aes) skcipher
https://git.kernel.org/netdev/net-next/c/8f303194b241
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html