Skip to content

Commit 7cfc2ab

Browse files
committed
crypto: lskcipher - Copy IV in lskcipher glue code always
The lskcipher glue code for skcipher needs to copy the IV every time rather than only on the first and last request. Otherwise those algorithms that use IV to perform chaining may break, e.g., CBC. This is because crypto_skcipher_import/export do not include the IV as part of the saved state. Reported-by: [email protected] Fixes: 662ea18 ("crypto: skcipher - Make use of internal state") Signed-off-by: Herbert Xu <[email protected]>
1 parent c0ec2a7 commit 7cfc2ab

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

crypto/lskcipher.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,12 @@ static int crypto_lskcipher_crypt_sg(struct skcipher_request *req,
212212

213213
ivsize = crypto_lskcipher_ivsize(tfm);
214214
ivs = PTR_ALIGN(ivs, crypto_skcipher_alignmask(skcipher) + 1);
215+
memcpy(ivs, req->iv, ivsize);
215216

216217
flags = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
217218

218219
if (req->base.flags & CRYPTO_SKCIPHER_REQ_CONT)
219220
flags |= CRYPTO_LSKCIPHER_FLAG_CONT;
220-
else
221-
memcpy(ivs, req->iv, ivsize);
222221

223222
if (!(req->base.flags & CRYPTO_SKCIPHER_REQ_NOTFINAL))
224223
flags |= CRYPTO_LSKCIPHER_FLAG_FINAL;
@@ -234,8 +233,7 @@ static int crypto_lskcipher_crypt_sg(struct skcipher_request *req,
234233
flags |= CRYPTO_LSKCIPHER_FLAG_CONT;
235234
}
236235

237-
if (flags & CRYPTO_LSKCIPHER_FLAG_FINAL)
238-
memcpy(req->iv, ivs, ivsize);
236+
memcpy(req->iv, ivs, ivsize);
239237

240238
return err;
241239
}

0 commit comments

Comments
 (0)