Skip to content

Commit c65d123

Browse files
ambarusherbertx
authored andcommitted
crypto: atmel-{aes,tdes} - Do not save IV for ECB mode
ECB mode does not use IV. Signed-off-by: Tudor Ambarus <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 75eca7a commit c65d123

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

drivers/crypto/atmel-aes.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ static void atmel_aes_set_iv_as_last_ciphertext_block(struct atmel_aes_dev *dd)
515515

516516
static inline int atmel_aes_complete(struct atmel_aes_dev *dd, int err)
517517
{
518+
struct skcipher_request *req = skcipher_request_cast(dd->areq);
519+
struct atmel_aes_reqctx *rctx = skcipher_request_ctx(req);
520+
518521
#if IS_ENABLED(CONFIG_CRYPTO_DEV_ATMEL_AUTHENC)
519522
if (dd->ctx->is_aead)
520523
atmel_aes_authenc_complete(dd, err);
@@ -523,7 +526,8 @@ static inline int atmel_aes_complete(struct atmel_aes_dev *dd, int err)
523526
clk_disable(dd->iclk);
524527
dd->flags &= ~AES_FLAGS_BUSY;
525528

526-
if (!dd->ctx->is_aead)
529+
if (!dd->ctx->is_aead &&
530+
(rctx->mode & AES_FLAGS_OPMODE_MASK) != AES_FLAGS_ECB)
527531
atmel_aes_set_iv_as_last_ciphertext_block(dd);
528532

529533
if (dd->is_async)
@@ -1130,7 +1134,8 @@ static int atmel_aes_crypt(struct skcipher_request *req, unsigned long mode)
11301134
rctx = skcipher_request_ctx(req);
11311135
rctx->mode = mode;
11321136

1133-
if (!(mode & AES_FLAGS_ENCRYPT) && (req->src == req->dst)) {
1137+
if ((mode & AES_FLAGS_OPMODE_MASK) != AES_FLAGS_ECB &&
1138+
!(mode & AES_FLAGS_ENCRYPT) && req->src == req->dst) {
11341139
unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
11351140

11361141
if (req->cryptlen >= ivsize)

drivers/crypto/atmel-tdes.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,14 @@ atmel_tdes_set_iv_as_last_ciphertext_block(struct atmel_tdes_dev *dd)
593593
static void atmel_tdes_finish_req(struct atmel_tdes_dev *dd, int err)
594594
{
595595
struct skcipher_request *req = dd->req;
596+
struct atmel_tdes_reqctx *rctx = skcipher_request_ctx(req);
596597

597598
clk_disable_unprepare(dd->iclk);
598599

599600
dd->flags &= ~TDES_FLAGS_BUSY;
600601

601-
atmel_tdes_set_iv_as_last_ciphertext_block(dd);
602+
if ((rctx->mode & TDES_FLAGS_OPMODE_MASK) != TDES_FLAGS_ECB)
603+
atmel_tdes_set_iv_as_last_ciphertext_block(dd);
602604

603605
req->base.complete(&req->base, err);
604606
}
@@ -728,7 +730,8 @@ static int atmel_tdes_crypt(struct skcipher_request *req, unsigned long mode)
728730

729731
rctx->mode = mode;
730732

731-
if (!(mode & TDES_FLAGS_ENCRYPT) && req->src == req->dst) {
733+
if ((mode & TDES_FLAGS_OPMODE_MASK) != TDES_FLAGS_ECB &&
734+
!(mode & TDES_FLAGS_ENCRYPT) && req->src == req->dst) {
732735
unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
733736

734737
if (req->cryptlen >= ivsize)

0 commit comments

Comments
 (0)