[PATCH 1/2] Fix counter width checks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <bhoomikak@xxxxxxxxxxxxxxx>
Signed-off-by: Pavitrakumar M <pavitrakumarm@xxxxxxxxxxxxxxx>
Acked-by: Ruud Derwig <Ruud.Derwig@xxxxxxxxxxxx>
---
 drivers/crypto/dwc-spacc/spacc_skcipher.c | 35 ++++++++++++-----------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/drivers/crypto/dwc-spacc/spacc_skcipher.c b/drivers/crypto/dwc-spacc/spacc_skcipher.c
index 488c03ff6c36..d55bcfe8c3c5 100644
--- a/drivers/crypto/dwc-spacc/spacc_skcipher.c
+++ b/drivers/crypto/dwc-spacc/spacc_skcipher.c
@@ -406,40 +406,42 @@ 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)) {
+		/* 64-bit counter width */
+		if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3) & (0x3)) {
 
-			for (i = 12; i < 16; i++) {
-				num_iv <<= 8;
-				num_iv |= ivc1[i];
+			for (i = 8; i < 16; i++) {
+				num_iv64 <<= 8;
+				num_iv64 |= ivc1[i];
 			}
 
-			diff = SPACC_CTR_IV_MAX32 - num_iv;
+			diff64 = SPACC_CTR_IV_MAX64 - num_iv64;
 
-			if (len > diff) {
+			if (len > diff64) {
 				name = salg->calg->cra_name;
 				ret = spacc_skcipher_fallback(name,
 							      req, enc_dec);
 				return ret;
 			}
+		/* 32-bit counter width */
 		} else if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3)
-			  & (0x3)) { /* 64-bit counter width */
+			& (0x2)) {
 
-			for (i = 8; i < 16; i++) {
-				num_iv64 <<= 8;
-				num_iv64 |= ivc1[i];
+			for (i = 12; i < 16; i++) {
+				num_iv <<= 8;
+				num_iv |= ivc1[i];
 			}
 
-			diff64 = SPACC_CTR_IV_MAX64 - num_iv64;
+			diff = SPACC_CTR_IV_MAX32 - num_iv;
 
-			if (len > diff64) {
+			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)) { /* 16-bit counter width */
+			   & (0x1)) {
 
 			for (i = 14; i < 16; i++) {
 				num_iv <<= 8;
@@ -454,8 +456,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;

base-commit: 2d6213bd592b4731b53ece3492f9d1d18e97eb5e
-- 
2.25.1





[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux