From 58bf99100a6dfcc53ba4ab547f1394bb6873b2ac Mon Sep 17 00:00:00 2001 From: Pavitrakumar M Date: Fri, 16 Aug 2024 17:33:32 +0530 Subject: [PATCH] crypto: spacc - Fix counter width checks This patch fixes counter width checks according to the version extension3 register. The counter widths can be 8, 16, 32 and 64 bits as per the extension3 register. Signed-off-by: Bhoomika K Signed-off-by: Pavitrakumar M Acked-by: Ruud Derwig Signed-off-by: Herbert Xu --- drivers/crypto/dwc-spacc/spacc_skcipher.c | 45 ++++++++++++----------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/drivers/crypto/dwc-spacc/spacc_skcipher.c b/drivers/crypto/dwc-spacc/spacc_skcipher.c index 8c698b75dd92..1ef7c665188f 100644 --- a/drivers/crypto/dwc-spacc/spacc_skcipher.c +++ b/drivers/crypto/dwc-spacc/spacc_skcipher.c @@ -408,24 +408,8 @@ static int spacc_cipher_process(struct skcipher_request *req, int enc_dec) for (i = 0; i < 16; i++) ivc1[i] = req->iv[i]; - /* 32-bit counter width */ - if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3) & (0x2)) { - - for (i = 12; i < 16; i++) { - num_iv <<= 8; - num_iv |= ivc1[i]; - } - - diff = SPACC_CTR_IV_MAX32 - num_iv; - - if (len > diff) { - name = salg->calg->cra_name; - ret = spacc_skcipher_fallback(name, - req, enc_dec); - return ret; - } - } else if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3) - & (0x3)) { /* 64-bit counter width */ + /* 64-bit counter width */ + if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3) & (0x3)) { for (i = 8; i < 16; i++) { num_iv64 <<= 8; @@ -440,8 +424,26 @@ static int spacc_cipher_process(struct skcipher_request *req, int enc_dec) req, enc_dec); return ret; } + /* 32-bit counter width */ } else if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3) - & (0x1)) { /* 16-bit counter width */ + & (0x2)) { + + for (i = 12; i < 16; i++) { + num_iv <<= 8; + num_iv |= ivc1[i]; + } + + diff = SPACC_CTR_IV_MAX32 - num_iv; + + if (len > diff) { + name = salg->calg->cra_name; + ret = spacc_skcipher_fallback(name, + req, enc_dec); + return ret; + } + /* 16-bit counter width */ + } else if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3) + & (0x1)) { for (i = 14; i < 16; i++) { num_iv <<= 8; @@ -456,8 +458,9 @@ static int spacc_cipher_process(struct skcipher_request *req, int enc_dec) req, enc_dec); return ret; } - } else if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3) - & (0x0)) { /* 8-bit counter width */ + /* 8-bit counter width */ + } else if ((readl(device_h->regmap + SPACC_REG_VERSION_EXT_3) + & 0x7) == 0) { for (i = 15; i < 16; i++) { num_iv <<= 8;