Re: [RFC PATCH 4.10 1/6] crypto/sha256: Refactor the API so it can be used without shash

From: Andy Lutomirski
Date: Fri Dec 23 2016 - 21:27:24 EST


On Fri, Dec 23, 2016 at 6:22 PM, Andy Lutomirski <luto@xxxxxxxxxx> wrote:
> There are some pieecs of kernel code that want to compute SHA256
> directly without going through the crypto core. Adjust the exported
> API to decouple it from the crypto core.
>
> I suspect this will very slightly speed up the SHA256 shash operations
> as well by reducing the amount of indirection involved.
>

I should also mention: there's a nice potential cleanup that's
possible on top of this. Currently, most of the accelerated SHA256
implementations just swap out the block function. Another approach to
enabling this would be to restructure sha256_update along the lines
of:

sha256_block_fn_t fn = arch_sha256_block_fn(len);
sha256_base_do_update(sctx, data, len, arch_sha256_block_fn(len));

The idea being that arch code can decide whether to use an accelerated
block function based on context (x86, for example, can't always use
xmm regs) and length (on x86, using the accelerated versions for short
digests is very slow due to the state save/restore that happens) and
then the core code can just use it.

This would allow a lot of the boilerplate that this patch was forced
to modify to be deleted outright.

--Andy