From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arnd Bergmann Subject: Re: [PATCH v4 11/14] treewide: Prepare to remove VLA usage for AHASH_REQUEST_ON_STACK Date: Mon, 16 Jul 2018 09:24:06 +0200 Message-ID: References: <20180711203619.1020-1-keescook@chromium.org> <20180711203619.1020-12-keescook@chromium.org> <20180713004038.lwibdesz7ohhoind@gondor.apana.org.au> <20180713062204.2o7gz5xri374nii6@gondor.apana.org.au> <20180715024430.n6bcnb4k7cm3ugtj@gondor.apana.org.au> <20180716000118.nna5jkgcjxofbsup@gondor.apana.org.au> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Giovanni Cabiddu , Herbert Xu , Mike Snitzer , Eric Biggers , "Gustavo A. R. Silva" , qat-linux@intel.com, Linux Kernel Mailing List , Masahiro Yamada , dm-devel@redhat.com, "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Lars Persson , Tim Chen , "David S. Miller" , Alasdair Kergon , Rabin Vincent To: Kees Cook Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com List-Id: linux-crypto.vger.kernel.org On Mon, Jul 16, 2018 at 5:39 AM, Kees Cook wrote: > On Sun, Jul 15, 2018 at 5:01 PM, Herbert Xu wrote: >> On Sat, Jul 14, 2018 at 07:59:09PM -0700, Kees Cook wrote: >>> On Sat, Jul 14, 2018 at 7:44 PM, Herbert Xu wrote: >>> > On Fri, Jul 13, 2018 at 08:07:10PM -0700, Kees Cook wrote: >>> >> >>> >> On a plane today I started converting all these to shash. IIUC, it >>> >> just looks like this (apologies for whitespace damage): >>> > >>> > Yes if it doesn't actually make use of SGs then shash would be >>> > the way to go. However, for SG users ahash is the best interface. >>> >>> Nearly all of them artificially build an sg explicitly to use the >>> ahash interface. :P >>> >>> So, I'll take that as a "yes, do these conversions." :) Thanks! >> >> Yeah anything that's doing a single-element SG list should just >> be converted. > > There are a few that are multiple element SG list, but it's a locally > allocated array of SGs, and filled with data. All easily replaced with > just calls to ..._update() instead of sg helpers. For example > net/wireless/lib80211_crypt_tkip.c: > > - sg_init_table(sg, 2); > - sg_set_buf(&sg[0], hdr, 16); > - sg_set_buf(&sg[1], data, data_len); > ... > - ahash_request_set_tfm(req, tfm_michael); > - ahash_request_set_callback(req, 0, NULL, NULL); > - ahash_request_set_crypt(req, sg, mic, data_len + 16); > - err = crypto_ahash_digest(req); > - ahash_request_zero(req); > + err = crypto_shash_init(desc); > + if (err) > + goto out; > + err = crypto_shash_update(desc, hdr, 16); > + if (err) > + goto out; > + err = crypto_shash_update(desc, data, data_len); > + if (err) > + goto out; > + err = crypto_shash_final(desc, mic); > + > +out: > + shash_desc_zero(desc); > return err; There may be a little overhead in calling crypto_shash_update()/ crypto_shash_final() repeatedly compared to calling crypto_ahash_digest() once. It's probably no worse (or maybe better) in this case, since we call only three times and there is less indirection, but if there are any cases with a long sglist, it would be good to measure the performance difference. Arnd