lkml.org 
[lkml]   [2019]   [Sep]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [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.

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.

> 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.

> 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.

Arnd

\
 
 \ /
  Last update: 2019-09-30 23:09    [W:0.117 / U:22.556 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site