Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1284684

[PATCH 2/2] chacha20poly1305: Skip encryption/decryption for 0-len

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From "Jason A. Donenfeld" <Jason@zx2c4.com>
Newsgroups linux.kernel
Subject [PATCH 2/2] chacha20poly1305: Skip encryption/decryption for 0-len
Date Sun, 06 Dec 2015 03:00:02 +0100
Message-ID <qCwMi-nF-7@gated-at.bofh.it> (permalink)
References <qCwMi-nF-9@gated-at.bofh.it>
X-Original-To herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Netdev <netdev@vger.kernel.org>, martin@strongswan.org
Dkim-Signature v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=mail; bh=6XvS Fbu/8xtEKj1/+dlT5AqwLrs=; b=dg/fu7v6o2tWgDFrWSigt0Ge3WFZXVmnZtfY fhtK3DjIbcRyM6vwAQIy2cpDn7/9KFcpxMfs+4GvepiiRCCSZ9FMjC1GY+DQ9oq9 hU1QErWjNzOAnES8Yu+iSHHmLxMXIGYspE733DotSrG1dwdgHRD7VhYEUtVGtTrF IoSXPHPGpI51+i8jQ2CKOhenYSmVwC4pAMLPZzf4nHZDVYpzHop/+euJqIQsrcOs ZE8yUmSshI6FTj5HytcoT0nPmgtIMW75dPUknFUlY49vE8yI+8wBkFZmdDzqjfV7 h9n7IeOtmrGxlli0dFSnf299zy7NxwyTPHOFHd6F/uBsvQJyeQ==
X-Mailer git-send-email 2.6.3
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 59
Organization linux.* mail to news gateway
X-Original-Cc "Jason A. Donenfeld" <Jason@zx2c4.com>, stable@vger.kernel.org
X-Original-Date Sun, 6 Dec 2015 02:51:38 +0100
X-Original-Message-ID <1449366698-2422-2-git-send-email-Jason@zx2c4.com>
X-Original-References <1449366698-2422-1-git-send-email-Jason@zx2c4.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1284684

Show key headers only | View raw


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>
Cc: <stable@vger.kernel.org>
---
 crypto/chacha20poly1305.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/crypto/chacha20poly1305.c b/crypto/chacha20poly1305.c
index 99c3cce..7b6b935 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);
 }
 
-- 
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[PATCH 2/2] chacha20poly1305: Skip encryption/decryption for 0-len "Jason A. Donenfeld" <Jason@zx2c4.com> - 2015-12-06 03:00 +0100
  Re: [PATCH 2/2] chacha20poly1305: Skip encryption/decryption for  0-len Herbert Xu <herbert@gondor.apana.org.au> - 2015-12-09 13:30 +0100

csiph-web