Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6886640imu; Thu, 31 Jan 2019 01:06:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN4hlYedMgHlKf/AmiZEiXUYQrQh1biFiVjHZts/mWAYSFeah6gKGIvn79FafQ0VX08H9TUB X-Received: by 2002:a62:5301:: with SMTP id h1mr33727888pfb.17.1548925562013; Thu, 31 Jan 2019 01:06:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548925561; cv=none; d=google.com; s=arc-20160816; b=GP1eYlu59VumFtUhB3ZAZIlatxhSswa/HyPrOuaF/2IcuWrCH+YLTbEDeXlsOxyQKT QjrkpFrngDUrUjJv+a5g2XPLr4sUmEf5IrKC7kr/g4bkwZFtEw57cLl6qJqMCZTPTL1O Iw2gzFUf2ZznGY5oz2sdQTKzuNnmjy140/caEc3hOvTXMcTi3B0AFDwXWoLz0Q7nTB3B XhNBGiKzIPygxlcgX61xBzmje7th51t8RZLd1qByjZq6WL10F6hgNvrQ3rW8+yTY0YyL qM/O85SbYB0XZ8RTMsHDePDe3Z2nsqabH4yToJLnifMzoXeWubGRYDD8yWOPNi3uVs1E wboA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=hIuaQy3oXLliDQ1OXJvDPvmuJ+EYkvpUsfkbj+cxM90=; b=l4EEQ1JqT4YWdlIJT8QyndO1Nl3I5N1PnMfrOuIVD6I0SVsyX3EuLXVa0mZKV6Y3lZ 3p2aBNuq/xMOZLc3tVpWPvWmJJflyaI/88CS+CM4d8wwzuc2Q+DmyjUSu8cCfFlUGqyM L76K+UN3MC18ckVQEk7cc8Lf6oUaoeJUaTzALHMmarQASDd44XzTU3MA1KLZkniGpEGL bQSU6ygExv+zONWbzpOpTal7ml0r7QpwReNxObnN35CCQiWAiJF8kma/PN0qCO7k36D8 PNTJ3nPP/ZqWntVNTaGoiaedz0NmXxvfkNDBdni4fzapX3xhqmxX4ZAck5vJGN8OzA2i W2lA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u131si4048410pgb.594.2019.01.31.01.05.46; Thu, 31 Jan 2019 01:06:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726434AbfAaJF3 (ORCPT + 99 others); Thu, 31 Jan 2019 04:05:29 -0500 Received: from mail-oi1-f194.google.com ([209.85.167.194]:36758 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725895AbfAaJF3 (ORCPT ); Thu, 31 Jan 2019 04:05:29 -0500 Received: by mail-oi1-f194.google.com with SMTP id x23so2129923oix.3 for ; Thu, 31 Jan 2019 01:05:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hIuaQy3oXLliDQ1OXJvDPvmuJ+EYkvpUsfkbj+cxM90=; b=gnmyk271UAKqrzskpAjSf9JcQeyrtoE6PTB3DMnX6kB2sgjaictVHKNN+cUuBu5jD0 elnLYCdBGgtQYB7B9O7oOyr2+QVqWoFZ1t6meiK28RcUqkQnCSFYgeSkoOyee7IyD+6q woJPRy0eqU1NCA0WCEl2j/D6vm59lV/0W5DssIA+tX+s2rkHBj/wjlUDBoPGVUApb6of IUBrOKkIx4/XIxLGYmuqiKbLPZUZAHIKaGIakX0ott6lJ1UK01bpaVa3goBmQfErqCIR yBpxZvQBAyp2oG5nv79Apn0+1O60nz9/5kyZBL8pgDbv5atmincAPcyPl2EnJrozB/WL VNuw== X-Gm-Message-State: AJcUukfEimXDyQsUnzz8Lh3/vgVBvMNNuV/PHUAKg2Xg1/UIZ1kSQJi7 fNxSAzIIeVaNGcsyeQMtG7aiHv9IKKAcHD7n6tjD8g== X-Received: by 2002:aca:4b8f:: with SMTP id y137mr15119422oia.132.1548925528134; Thu, 31 Jan 2019 01:05:28 -0800 (PST) MIME-Version: 1.0 References: <20190123224926.250525-1-ebiggers@kernel.org> <20190123224926.250525-3-ebiggers@kernel.org> In-Reply-To: <20190123224926.250525-3-ebiggers@kernel.org> From: Ondrej Mosnacek Date: Thu, 31 Jan 2019 10:05:17 +0100 Message-ID: Subject: Re: [RFC/RFT PATCH 02/15] crypto: morus - fix handling chunked inputs To: Eric Biggers Cc: linux-crypto@vger.kernel.org, Herbert Xu , Linux kernel mailing list , "Jason A . Donenfeld" , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Eric, On Wed, Jan 23, 2019 at 11:52 PM Eric Biggers wrote: > From: Eric Biggers > > The generic MORUS implementations all fail the improved AEAD tests > because they produce the wrong result with some data layouts. Fix them. > > Fixes: 396be41f16fd ("crypto: morus - Add generic MORUS AEAD implementations") > Cc: # v4.18+ > Cc: Ondrej Mosnacek > Signed-off-by: Eric Biggers > --- > crypto/morus1280.c | 13 +++++++------ > crypto/morus640.c | 13 +++++++------ > 2 files changed, 14 insertions(+), 12 deletions(-) > > diff --git a/crypto/morus1280.c b/crypto/morus1280.c > index 3889c188f266..b83576b4eb55 100644 > --- a/crypto/morus1280.c > +++ b/crypto/morus1280.c > @@ -366,18 +366,19 @@ static void crypto_morus1280_process_crypt(struct morus1280_state *state, > const struct morus1280_ops *ops) > { > struct skcipher_walk walk; > - u8 *dst; > - const u8 *src; > > ops->skcipher_walk_init(&walk, req, false); > > while (walk.nbytes) { > - src = walk.src.virt.addr; > - dst = walk.dst.virt.addr; > + unsigned int nbytes = walk.nbytes; > > - ops->crypt_chunk(state, dst, src, walk.nbytes); > + if (nbytes < walk.total) > + nbytes = round_down(nbytes, walk.stride); > > - skcipher_walk_done(&walk, 0); > + ops->crypt_chunk(state, walk.dst.virt.addr, walk.src.virt.addr, > + nbytes); > + > + skcipher_walk_done(&walk, walk.nbytes - nbytes); > } Hm... I assume the problem was that skcipher_walk may give you nbytes that is not rounded to the algorithm's walksize (aka walk.stride) even in the middle of the stream, right? I must have misread the code in skcipher.c and assumed that it automatically makes every step of a round size, with the exception of the very last one, which may include a final partial block. Thinking about it now it makes sense to me that this isn't the case, since for stream ciphers it would mean some unnecessary memcpy'ing in the skcipher_walk code... Maybe you could explain the problem in one or two sentences in the commit message(s), since the contract of skcipher_walk doesn't seem to be documented anywhere and so it is not obvious why the change is necessary. Thank you for all your work on this - the improved testmgr tests were long needed! > } > > diff --git a/crypto/morus640.c b/crypto/morus640.c > index da06ec2f6a80..b6a477444f6d 100644 > --- a/crypto/morus640.c > +++ b/crypto/morus640.c > @@ -365,18 +365,19 @@ static void crypto_morus640_process_crypt(struct morus640_state *state, > const struct morus640_ops *ops) > { > struct skcipher_walk walk; > - u8 *dst; > - const u8 *src; > > ops->skcipher_walk_init(&walk, req, false); > > while (walk.nbytes) { > - src = walk.src.virt.addr; > - dst = walk.dst.virt.addr; > + unsigned int nbytes = walk.nbytes; > > - ops->crypt_chunk(state, dst, src, walk.nbytes); > + if (nbytes < walk.total) > + nbytes = round_down(nbytes, walk.stride); > > - skcipher_walk_done(&walk, 0); > + ops->crypt_chunk(state, walk.dst.virt.addr, walk.src.virt.addr, > + nbytes); > + > + skcipher_walk_done(&walk, walk.nbytes - nbytes); > } > } > > -- > 2.20.1.321.g9e740568ce-goog > -- Ondrej Mosnacek Associate Software Engineer, Security Technologies Red Hat, Inc.