[PATCH v2 19/30] crypto: sa2ul - remove redundant algorithm ID fields
From: Manorit Chawdhry
Date: Wed Nov 04 2026 - 00:54:07 EST
Use the full digest size to select HMAC-SHA1 or HMAC-SHA256 when
preparing ipad and opad. The size is already populated for the SHA and
AEAD paths, so a separate software algorithm ID is unnecessary.
Keep the digest size unchanged during context setup and round only the
hardware egress length, so SHA1 still selects its 20-byte digest after
both encryption and decryption contexts are prepared.
The encryption algorithm ID and command-label algorithm field are unused,
so remove them and their assignments along with the legacy authentication
and encryption ID enums.
Signed-off-by: Manorit Chawdhry <m-chawdhry@xxxxxx>
---
drivers/crypto/sa2ul.c | 32 ++++++--------------------------
drivers/crypto/sa2ul.h | 34 ----------------------------------
2 files changed, 6 insertions(+), 60 deletions(-)
diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index 2c1d51b1cb88..36f1d13dfe91 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -95,14 +95,12 @@ static struct device *sa_k3_dev;
/**
* struct sa_cmdl_cfg - Command label configuration descriptor
- * @aalg: authentication algorithm ID
* @enc_eng_id: Encryption Engine ID supported by the SA hardware
* @auth_eng_id: Authentication Engine ID
* @iv_size: Initialization Vector size
* @enc: True, if this is an encode request
*/
struct sa_cmdl_cfg {
- int aalg;
u8 enc_eng_id;
u8 auth_eng_id;
u8 iv_size;
@@ -117,8 +115,6 @@ struct sa_cmdl_cfg {
* @hash_size: Size of digest
* @iv_idx: iv index in psdata
* @iv_out_size: iv out size
- * @ealg_id: Encryption Algorithm ID
- * @aalg_id: Authentication algorithm ID
* @mci_enc: Mode Control Instruction for Encryption algorithm
* @mci_dec: Mode Control Instruction for Decryption
* @inv_key: Whether the encryption algorithm demands key inversion
@@ -131,8 +127,6 @@ struct algo_data {
u8 hash_size;
u8 iv_idx;
u8 iv_out_size;
- u8 ealg_id;
- u8 aalg_id;
u8 *mci_enc;
u8 *mci_dec;
bool inv_key;
@@ -377,15 +371,15 @@ static void sa_prepare_iopads(struct algo_data *data, const u8 *key,
struct hmac_sha256_key sha256;
} k;
- switch (data->aalg_id) {
- case SA_AALG_ID_HMAC_SHA1:
+ switch (data->hash_size) {
+ case SHA1_DIGEST_SIZE:
hmac_sha1_preparekey(&k.sha1, key, key_sz);
cpu_to_be32_array(ipad, k.sha1.istate.h,
ARRAY_SIZE(k.sha1.istate.h));
cpu_to_be32_array(opad, k.sha1.ostate.h,
ARRAY_SIZE(k.sha1.ostate.h));
break;
- case SA_AALG_ID_HMAC_SHA2_256:
+ case SHA256_DIGEST_SIZE:
hmac_sha256_preparekey(&k.sha256, key, key_sz);
cpu_to_be32_array(ipad, k.sha256.key.istate.h,
ARRAY_SIZE(k.sha256.key.istate.h));
@@ -393,8 +387,8 @@ static void sa_prepare_iopads(struct algo_data *data, const u8 *key,
ARRAY_SIZE(k.sha256.key.ostate.h));
break;
default:
- dev_err(sa_k3_dev, "%s: bad aalg_id=%d\n", __func__,
- data->aalg_id);
+ dev_err(sa_k3_dev, "%s: bad hash_size=%u\n", __func__,
+ data->hash_size);
return;
}
@@ -654,7 +648,6 @@ int sa_init_sc(struct sa_ctx_info *ctx, const struct sa_match_data *match_data,
sc_buf[1] = SA_SCCTL_FE_AUTH_ENC;
if (!ad->hash_size)
return -EINVAL;
- ad->hash_size = roundup(ad->hash_size, 8);
} else if (ad->enc_eng.eng_id && !ad->auth_eng.eng_id) {
enc_sc_offset = SA_CTX_PHP_PE_CTX_SZ;
@@ -690,7 +683,7 @@ int sa_init_sc(struct sa_ctx_info *ctx, const struct sa_match_data *match_data,
sa_swiz_128(sc_buf, SA_CTX_MAX_SZ);
sa_set_swinfo(first_engine, ctx->sc_id, ctx->sc_phys, 1, 0,
- SA_SW_INFO_FLAG_EVICT, ad->hash_size, swinfo);
+ SA_SW_INFO_FLAG_EVICT, roundup(ad->hash_size, 8), swinfo);
sa_dump_sc(sc_buf, ctx->sc_phys);
@@ -875,7 +868,6 @@ static int sa_aes_cbc_setkey(struct crypto_skcipher *tfm, const u8 *key,
ad.mci_enc = mci_cbc_enc_array[key_idx];
ad.mci_dec = mci_cbc_dec_array[key_idx];
ad.inv_key = true;
- ad.ealg_id = SA_EALG_ID_AES_CBC;
ad.iv_idx = 4;
ad.iv_out_size = 16;
@@ -895,7 +887,6 @@ static int sa_aes_ecb_setkey(struct crypto_skcipher *tfm, const u8 *key,
ad.mci_enc = mci_ecb_enc_array[key_idx];
ad.mci_dec = mci_ecb_dec_array[key_idx];
ad.inv_key = true;
- ad.ealg_id = SA_EALG_ID_AES_ECB;
return sa_cipher_setkey(tfm, key, keylen, &ad);
}
@@ -907,7 +898,6 @@ static int sa_3des_cbc_setkey(struct crypto_skcipher *tfm, const u8 *key,
ad.mci_enc = mci_cbc_3des_enc_array;
ad.mci_dec = mci_cbc_3des_dec_array;
- ad.ealg_id = SA_EALG_ID_3DES_CBC;
ad.iv_idx = 6;
ad.iv_out_size = 8;
@@ -1373,7 +1363,6 @@ static int sa_sha_setup(struct sa_tfm_ctx *ctx, struct algo_data *ad)
ad->auth_eng.sc_size = SA_CTX_AUTH_TYPE2_SZ;
memset(&cfg, 0, sizeof(cfg));
- cfg.aalg = ad->aalg_id;
cfg.enc_eng_id = ad->enc_eng.eng_id;
cfg.auth_eng_id = ad->auth_eng.eng_id;
cfg.iv_size = 0;
@@ -1508,7 +1497,6 @@ static int sa_sha1_cra_init(struct crypto_tfm *tfm)
sa_sha_cra_init_alg(tfm, "sha1");
- ad.aalg_id = SA_AALG_ID_SHA1;
ad.hash_size = SHA1_DIGEST_SIZE;
ad.auth_ctrl = SA_AUTH_SW_CTRL_SHA1;
@@ -1524,7 +1512,6 @@ static int sa_sha256_cra_init(struct crypto_tfm *tfm)
sa_sha_cra_init_alg(tfm, "sha256");
- ad.aalg_id = SA_AALG_ID_SHA2_256;
ad.hash_size = SHA256_DIGEST_SIZE;
ad.auth_ctrl = SA_AUTH_SW_CTRL_SHA256;
@@ -1540,7 +1527,6 @@ static int sa_sha512_cra_init(struct crypto_tfm *tfm)
sa_sha_cra_init_alg(tfm, "sha512");
- ad.aalg_id = SA_AALG_ID_SHA2_512;
ad.hash_size = SHA512_DIGEST_SIZE;
ad.auth_ctrl = SA_AUTH_SW_CTRL_SHA512;
@@ -1692,11 +1678,9 @@ static int sa_aead_setkey(struct crypto_aead *authenc,
ad->mci_dec = mci_cbc_dec_no_iv_array[key_idx];
ad->inv_key = true;
ad->keyed_mac = true;
- ad->ealg_id = SA_EALG_ID_AES_CBC;
memset(&cfg, 0, sizeof(cfg));
cfg.enc = true;
- cfg.aalg = ad->aalg_id;
cfg.enc_eng_id = ad->enc_eng.eng_id;
cfg.auth_eng_id = ad->auth_eng.eng_id;
cfg.iv_size = crypto_aead_ivsize(authenc);
@@ -1750,8 +1734,6 @@ static int sa_aead_cbc_sha1_setkey(struct crypto_aead *authenc,
{
struct algo_data ad = { 0 };
- ad.ealg_id = SA_EALG_ID_AES_CBC;
- ad.aalg_id = SA_AALG_ID_HMAC_SHA1;
ad.hash_size = SHA1_DIGEST_SIZE;
ad.auth_ctrl = SA_AUTH_SW_CTRL_SHA1;
@@ -1763,8 +1745,6 @@ static int sa_aead_cbc_sha256_setkey(struct crypto_aead *authenc,
{
struct algo_data ad = { 0 };
- ad.ealg_id = SA_EALG_ID_AES_CBC;
- ad.aalg_id = SA_AALG_ID_HMAC_SHA2_256;
ad.hash_size = SHA256_DIGEST_SIZE;
ad.auth_ctrl = SA_AUTH_SW_CTRL_SHA256;
diff --git a/drivers/crypto/sa2ul.h b/drivers/crypto/sa2ul.h
index ecd8f09faf59..ea86199b6231 100644
--- a/drivers/crypto/sa2ul.h
+++ b/drivers/crypto/sa2ul.h
@@ -277,40 +277,6 @@ struct sa_sha_req_ctx {
struct ahash_request fallback_req;
};
-/* Encryption algorithms */
-enum sa_ealg_id {
- SA_EALG_ID_NONE = 0, /* No encryption */
- SA_EALG_ID_NULL, /* NULL encryption */
- SA_EALG_ID_AES_CTR, /* AES Counter mode */
- SA_EALG_ID_AES_F8, /* AES F8 mode */
- SA_EALG_ID_AES_CBC, /* AES CBC mode */
- SA_EALG_ID_DES_CBC, /* DES CBC mode */
- SA_EALG_ID_3DES_CBC, /* 3DES CBC mode */
- SA_EALG_ID_CCM, /* Counter with CBC-MAC mode */
- SA_EALG_ID_GCM, /* Galois Counter mode */
- SA_EALG_ID_AES_ECB,
- SA_EALG_ID_LAST
-};
-
-/* Authentication algorithms */
-enum sa_aalg_id {
- SA_AALG_ID_NONE = 0, /* No Authentication */
- SA_AALG_ID_NULL = SA_EALG_ID_LAST, /* NULL Authentication */
- SA_AALG_ID_MD5, /* MD5 mode */
- SA_AALG_ID_SHA1, /* SHA1 mode */
- SA_AALG_ID_SHA2_224, /* 224-bit SHA2 mode */
- SA_AALG_ID_SHA2_256, /* 256-bit SHA2 mode */
- SA_AALG_ID_SHA2_512, /* 512-bit SHA2 mode */
- SA_AALG_ID_HMAC_MD5, /* HMAC with MD5 mode */
- SA_AALG_ID_HMAC_SHA1, /* HMAC with SHA1 mode */
- SA_AALG_ID_HMAC_SHA2_224, /* HMAC with 224-bit SHA2 mode */
- SA_AALG_ID_HMAC_SHA2_256, /* HMAC with 256-bit SHA2 mode */
- SA_AALG_ID_GMAC, /* Galois Message Auth. Code mode */
- SA_AALG_ID_CMAC, /* Cipher-based Mes. Auth. Code mode */
- SA_AALG_ID_CBC_MAC, /* Cipher Block Chaining */
- SA_AALG_ID_AES_XCBC /* AES Extended Cipher Block Chaining */
-};
-
/**
* struct sa_eng_info: Security accelerator engine info
* @eng_id: Engine ID
--
2.43.0