From patchwork Sun Dec 6 01:51:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 7776161 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D474D9F30B for ; Sun, 6 Dec 2015 01:58:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 057BB20452 for ; Sun, 6 Dec 2015 01:58:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2896120439 for ; Sun, 6 Dec 2015 01:58:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753437AbbLFB6h (ORCPT ); Sat, 5 Dec 2015 20:58:37 -0500 Received: from frisell.zx2c4.com ([192.95.5.64]:49620 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751540AbbLFB6h (ORCPT ); Sat, 5 Dec 2015 20:58:37 -0500 X-Greylist: delayed 398 seconds by postgrey-1.27 at vger.kernel.org; Sat, 05 Dec 2015 20:58:33 EST Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTP id a8537dac; Sun, 6 Dec 2015 01:51:22 +0000 (UTC) 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== Received: by frisell.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 89234dfd TLS version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO; Sun, 6 Dec 2015 01:51:21 +0000 (UTC) From: "Jason A. Donenfeld" To: herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, Netdev , martin@strongswan.org Cc: "Jason A. Donenfeld" , stable@vger.kernel.org Subject: [PATCH 2/2] chacha20poly1305: Skip encryption/decryption for 0-len Date: Sun, 6 Dec 2015 02:51:38 +0100 Message-Id: <1449366698-2422-2-git-send-email-Jason@zx2c4.com> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1449366698-2422-1-git-send-email-Jason@zx2c4.com> References: <1449366698-2422-1-git-send-email-Jason@zx2c4.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: --- 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); }