Commit 161151d7 authored by Jason A. Donenfeld's avatar Jason A. Donenfeld Committed by Herbert Xu

crypto: chacha20poly1305 - Skip encryption/decryption for 0-len

If the length of the plaintext is zero, there's no need to waste cycles
on encryption and decryption. Using the chacha20poly1305 construction
for zero-length plaintexts is a common way of using a shared encryption
key for AAD authentication.
Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 3d5b1ecd
...@@ -130,6 +130,9 @@ static int chacha_decrypt(struct aead_request *req) ...@@ -130,6 +130,9 @@ static int chacha_decrypt(struct aead_request *req)
struct scatterlist *src, *dst; struct scatterlist *src, *dst;
int err; int err;
if (rctx->cryptlen == 0)
goto skip;
chacha_iv(creq->iv, req, 1); chacha_iv(creq->iv, req, 1);
sg_init_table(rctx->src, 2); sg_init_table(rctx->src, 2);
...@@ -150,6 +153,7 @@ static int chacha_decrypt(struct aead_request *req) ...@@ -150,6 +153,7 @@ static int chacha_decrypt(struct aead_request *req)
if (err) if (err)
return err; return err;
skip:
return poly_verify_tag(req); return poly_verify_tag(req);
} }
...@@ -415,6 +419,9 @@ static int chacha_encrypt(struct aead_request *req) ...@@ -415,6 +419,9 @@ static int chacha_encrypt(struct aead_request *req)
struct scatterlist *src, *dst; struct scatterlist *src, *dst;
int err; int err;
if (req->cryptlen == 0)
goto skip;
chacha_iv(creq->iv, req, 1); chacha_iv(creq->iv, req, 1);
sg_init_table(rctx->src, 2); sg_init_table(rctx->src, 2);
...@@ -435,6 +442,7 @@ static int chacha_encrypt(struct aead_request *req) ...@@ -435,6 +442,7 @@ static int chacha_encrypt(struct aead_request *req)
if (err) if (err)
return err; return err;
skip:
return poly_genkey(req); return poly_genkey(req);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment