Skip to content

Commit 58bf991

Browse files
Pavitrakumar Mherbertx
authored andcommitted
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 <[email protected]> Signed-off-by: Pavitrakumar M <[email protected]> Acked-by: Ruud Derwig <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 694a6f5 commit 58bf991

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

drivers/crypto/dwc-spacc/spacc_skcipher.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -408,40 +408,42 @@ static int spacc_cipher_process(struct skcipher_request *req, int enc_dec)
408408
for (i = 0; i < 16; i++)
409409
ivc1[i] = req->iv[i];
410410

411-
/* 32-bit counter width */
412-
if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3) & (0x2)) {
411+
/* 64-bit counter width */
412+
if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3) & (0x3)) {
413413

414-
for (i = 12; i < 16; i++) {
415-
num_iv <<= 8;
416-
num_iv |= ivc1[i];
414+
for (i = 8; i < 16; i++) {
415+
num_iv64 <<= 8;
416+
num_iv64 |= ivc1[i];
417417
}
418418

419-
diff = SPACC_CTR_IV_MAX32 - num_iv;
419+
diff64 = SPACC_CTR_IV_MAX64 - num_iv64;
420420

421-
if (len > diff) {
421+
if (len > diff64) {
422422
name = salg->calg->cra_name;
423423
ret = spacc_skcipher_fallback(name,
424424
req, enc_dec);
425425
return ret;
426426
}
427+
/* 32-bit counter width */
427428
} else if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3)
428-
& (0x3)) { /* 64-bit counter width */
429+
& (0x2)) {
429430

430-
for (i = 8; i < 16; i++) {
431-
num_iv64 <<= 8;
432-
num_iv64 |= ivc1[i];
431+
for (i = 12; i < 16; i++) {
432+
num_iv <<= 8;
433+
num_iv |= ivc1[i];
433434
}
434435

435-
diff64 = SPACC_CTR_IV_MAX64 - num_iv64;
436+
diff = SPACC_CTR_IV_MAX32 - num_iv;
436437

437-
if (len > diff64) {
438+
if (len > diff) {
438439
name = salg->calg->cra_name;
439440
ret = spacc_skcipher_fallback(name,
440441
req, enc_dec);
441442
return ret;
442443
}
444+
/* 16-bit counter width */
443445
} else if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3)
444-
& (0x1)) { /* 16-bit counter width */
446+
& (0x1)) {
445447

446448
for (i = 14; i < 16; i++) {
447449
num_iv <<= 8;
@@ -456,8 +458,9 @@ static int spacc_cipher_process(struct skcipher_request *req, int enc_dec)
456458
req, enc_dec);
457459
return ret;
458460
}
459-
} else if (readl(device_h->regmap + SPACC_REG_VERSION_EXT_3)
460-
& (0x0)) { /* 8-bit counter width */
461+
/* 8-bit counter width */
462+
} else if ((readl(device_h->regmap + SPACC_REG_VERSION_EXT_3)
463+
& 0x7) == 0) {
461464

462465
for (i = 15; i < 16; i++) {
463466
num_iv <<= 8;

0 commit comments

Comments
 (0)