linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pascal Van Leeuwen <pvanleeuwen@verimatrix.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Antoine Tenart <antoine.tenart@bootlin.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Pascal van Leeuwen <pascalvanl@gmail.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Eric Biggers <ebiggers@google.com>,
	"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 2/3] crypto: inside-secure - Reduce stack usage
Date: Mon, 30 Sep 2019 21:09:10 +0000	[thread overview]
Message-ID: <CH2PR20MB29682E2C514733F290CFA3CECA820@CH2PR20MB2968.namprd20.prod.outlook.com> (raw)
In-Reply-To: <CAK8P3a0PeocENP6c=ENVrq2X8x-vinM6qhPRDDi_WEf6y73AOQ@mail.gmail.com>

> -----Original Message-----
> From: Arnd Bergmann <arnd@arndb.de>
> Sent: Monday, September 30, 2019 10:12 PM
> To: Pascal Van Leeuwen <pvanleeuwen@verimatrix.com>
> Cc: Antoine Tenart <antoine.tenart@bootlin.com>; Herbert Xu <herbert@gondor.apana.org.au>;
> David S. Miller <davem@davemloft.net>; Pascal van Leeuwen <pascalvanl@gmail.com>; Ard
> Biesheuvel <ard.biesheuvel@linaro.org>; Eric Biggers <ebiggers@google.com>; linux-
> crypto@vger.kernel.org; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH 2/3] crypto: inside-secure - Reduce stack usage
> 
> On Mon, Sep 30, 2019 at 9:04 PM Pascal Van Leeuwen
> <pvanleeuwen@verimatrix.com> wrote:
> 
> > > Alternatively, it should be possible to shrink these allocations
> > > as the extra buffers appear to be largely unnecessary, but doing
> > > this would be a much more invasive change.
> > >
> > Actually, for HMAC-SHA512 you DO need all that buffer space.
> > You could shrink it to 2 * ctx->state_sz but then your simple indexing
> > is no longer going to fly. Not sure if that would be worth the effort.
> 
> Stack allocations can no longer be dynamically sized in the kernel,
> so that would not work.
> 
I was actually referring to your kzalloc, not to the original stack
based implementation ...

> What I noticed though is that the largest part of safexcel_ahash_export_state
> is used in the 'cache' member, and this is apparently only referenced inside of
> safexcel_hmac_init_iv, which you call twice. If that cache can be allocated
> only once, you save SHA512_BLOCK_SIZE bytes in one of the two paths.
> 
Well ... hmmm ... "my"... This is not originally "my" code. And until you
brought this up, I did not fully realise it was using this export_state
struct to store those digests. Seems to have something to do with directly
taking the crypto_ahash_export state output, which is much more than that,
in case you need to continue the hash (which you don't here).

I guess you need to "catch" that output somewhere, so probably you could
save a bit of memory but I doubt it would be a significant improvement.

> > I don't like the part where you dynamically allocate the cryto_aes_ctx
> > though, I think that was not necessary considering its a lot smaller.
> 
> I count 484 bytes for it, which is really large.
> 
Maybe I should've counted myself ... totally unexpectedly huge. Why??
Anyway, glad I got rid of it already then.

> > And it conflicts with another change I have waiting that gets rid of
> > aes_expandkey and that struct alltogether (since it was really just
> > abused to do a key size check, which was very wasteful since the
> > function actually generates all roundkeys we don't need at all ...)
> 
> Right, this is what I noticed there. With 480 of the 484 bytes gone,
> you are well below the warning limit even without the other change.
> 
And by "other change" you mean the safexcel_ahash_export_state?
Ok, good to known, although I do like to improve that one as well,
but preferably by not exporting the cache so I don't need the full
struct.

Regards,
Pascal van Leeuwen
Silicon IP Architect, Multi-Protocol Engines @ Verimatrix
www.insidesecure.com


  reply	other threads:[~2019-09-30 21:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-30 12:14 [PATCH 1/3] crypto: inside-secure - Fix a maybe-uninitialized warning Arnd Bergmann
2019-09-30 12:14 ` [PATCH 2/3] crypto: inside-secure - Reduce stack usage Arnd Bergmann
2019-09-30 19:04   ` Pascal Van Leeuwen
2019-09-30 20:11     ` Arnd Bergmann
2019-09-30 21:09       ` Pascal Van Leeuwen [this message]
2019-10-01 18:49         ` Arnd Bergmann
2019-10-10 12:40   ` Herbert Xu
2019-09-30 12:14 ` [PATCH 3/3] crypto: inside-secure - Remove #ifdef checks Arnd Bergmann
2019-09-30 13:04   ` Bjorn Helgaas
2019-10-10 12:55   ` Herbert Xu
2019-10-17 13:26   ` Pascal Van Leeuwen
2019-10-17 13:47     ` Arnd Bergmann
2019-10-17 14:14       ` Pascal Van Leeuwen
2019-09-30 18:50 ` [PATCH 1/3] crypto: inside-secure - Fix a maybe-uninitialized warning Pascal Van Leeuwen
2019-10-10 12:54 ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CH2PR20MB29682E2C514733F290CFA3CECA820@CH2PR20MB2968.namprd20.prod.outlook.com \
    --to=pvanleeuwen@verimatrix.com \
    --cc=antoine.tenart@bootlin.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb.de \
    --cc=davem@davemloft.net \
    --cc=ebiggers@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pascalvanl@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).