summaryrefslogtreecommitdiffstats
path: root/crypto/chacha20poly1305.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2015-12-06 02:51:38 +0100
committerHerbert Xu <herbert@gondor.apana.org.au>2015-12-09 20:16:04 +0800
commit161151d79ff4f7ed35d4ebb0eb7727a517c34ef2 (patch)
tree8987b80f9b613c8a30280f73873dad1239247a83 /crypto/chacha20poly1305.c
parent3d5b1ecdea6fb94f8c61554fcb2ba776a2d3d0e6 (diff)
downloadlinux-stable-161151d79ff4f7ed35d4ebb0eb7727a517c34ef2.tar.gz
linux-stable-161151d79ff4f7ed35d4ebb0eb7727a517c34ef2.tar.bz2
linux-stable-161151d79ff4f7ed35d4ebb0eb7727a517c34ef2.zip
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: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/chacha20poly1305.c')
-rw-r--r--crypto/chacha20poly1305.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/crypto/chacha20poly1305.c b/crypto/chacha20poly1305.c
index 99c3cce01290..7b6b935cef23 100644
--- a/crypto/chacha20poly1305.c
+++ b/crypto/chacha20poly1305.c
@@ -130,6 +130,9 @@ static int chacha_decrypt(struct aead_request *req)
struct scatterlist *src, *dst;
int err;
+ if (rctx->cryptlen == 0)
+ goto skip;
+
chacha_iv(creq->iv, req, 1);
sg_init_table(rctx->src, 2);
@@ -150,6 +153,7 @@ static int chacha_decrypt(struct aead_request *req)
if (err)
return err;
+skip:
return poly_verify_tag(req);
}
@@ -415,6 +419,9 @@ static int chacha_encrypt(struct aead_request *req)
struct scatterlist *src, *dst;
int err;
+ if (req->cryptlen == 0)
+ goto skip;
+
chacha_iv(creq->iv, req, 1);
sg_init_table(rctx->src, 2);
@@ -435,6 +442,7 @@ static int chacha_encrypt(struct aead_request *req)
if (err)
return err;
+skip:
return poly_genkey(req);
}