Skip to content

Commit 50beceb

Browse files
klassertherbertx
authored andcommitted
crypto: authenc - Move saved IV in front of the ablkcipher request
In crypto_authenc_encrypt() we save the IV behind the ablkcipher request. To save space on the request, we overwrite the ablkcipher request with a ahash request after encryption. So the IV may be overwritten by the ahash request. This patch fixes this by placing the IV in front of the ablkcipher/ahash request. Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent cbb9bf6 commit 50beceb

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

‎crypto/authenc.c‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,13 @@ static int crypto_authenc_encrypt(struct aead_request *req)
386386
{
387387
struct crypto_aead *authenc = crypto_aead_reqtfm(req);
388388
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
389-
struct ablkcipher_request *abreq = aead_request_ctx(req);
389+
struct authenc_request_ctx *areq_ctx = aead_request_ctx(req);
390390
struct crypto_ablkcipher *enc = ctx->enc;
391391
struct scatterlist *dst = req->dst;
392392
unsigned int cryptlen = req->cryptlen;
393-
u8 *iv = (u8 *)(abreq + 1) + crypto_ablkcipher_reqsize(enc);
393+
struct ablkcipher_request *abreq = (void *)(areq_ctx->tail
394+
+ ctx->reqoff);
395+
u8 *iv = (u8 *)abreq - crypto_ablkcipher_ivsize(enc);
394396
int err;
395397

396398
ablkcipher_request_set_tfm(abreq, enc);
@@ -546,10 +548,6 @@ static int crypto_authenc_init_tfm(struct crypto_tfm *tfm)
546548
if (IS_ERR(auth))
547549
return PTR_ERR(auth);
548550

549-
ctx->reqoff = ALIGN(2 * crypto_ahash_digestsize(auth) +
550-
crypto_ahash_alignmask(auth),
551-
crypto_ahash_alignmask(auth) + 1);
552-
553551
enc = crypto_spawn_skcipher(&ictx->enc);
554552
err = PTR_ERR(enc);
555553
if (IS_ERR(enc))
@@ -558,13 +556,18 @@ static int crypto_authenc_init_tfm(struct crypto_tfm *tfm)
558556
ctx->auth = auth;
559557
ctx->enc = enc;
560558

561-
tfm->crt_aead.reqsize = max_t(unsigned int,
562-
crypto_ahash_reqsize(auth) + ctx->reqoff +
563-
sizeof(struct authenc_request_ctx) +
559+
ctx->reqoff = ALIGN(2 * crypto_ahash_digestsize(auth) +
560+
crypto_ahash_alignmask(auth),
561+
crypto_ahash_alignmask(auth) + 1) +
562+
crypto_ablkcipher_ivsize(enc);
563+
564+
tfm->crt_aead.reqsize = sizeof(struct authenc_request_ctx) +
565+
ctx->reqoff +
566+
max_t(unsigned int,
567+
crypto_ahash_reqsize(auth) +
564568
sizeof(struct ahash_request),
565569
sizeof(struct skcipher_givcrypt_request) +
566-
crypto_ablkcipher_reqsize(enc) +
567-
crypto_ablkcipher_ivsize(enc));
570+
crypto_ablkcipher_reqsize(enc));
568571

569572
return 0;
570573

0 commit comments

Comments
 (0)