crypto: chacha20poly1305 - Skip encryption/decryption for 0-len
[cascardo/linux.git] / crypto / chacha20poly1305.c
index 99c3cce..7b6b935 100644 (file)
@@ -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);
 }