Re: [PATCH v6 8/8] crypto, x86/sha: Eliminate casts on asm implementations

From: Eric Biggers
Date: Thu Nov 21 2019 - 22:06:25 EST


On Thu, Nov 21, 2019 at 05:03:34PM -0800, Kees Cook wrote:
> -asmlinkage void sha1_transform_ssse3(u32 *digest, const char *data,
> - unsigned int rounds);
> +asmlinkage void sha1_transform_ssse3(struct sha1_state *digest,
> + const u8 *data, int rounds);

Can you please use:

asmlinkage void sha1_transform_ssse3(struct sha1_state *state,
const u8 *data, int blocks);

I.e., rename 'digest' => 'state' and 'rounds' => 'blocks'.

(Or alternatively 'sst' instead of 'state' would be okay since that's what
sha{1,256,512}_block_fn uses, but 'state' seems much clearer to me.)

Similarly for the other sha{1,256,512}_transform_*() functions.

'digest' is confusing because it would typically be understood to mean the final
digest, or maybe also the hash chaining state (e.g. u32[5] for SHA-1) if it's
interpreted loosely. I don't think it would typically be understand to also
include buffered data like struct sha1_state does.

'rounds' is confusing because the parameter is actually the number of blocks,
not the number of rounds -- the latter being fixed for each SHA-* algorithm.
Since sha{1,256,512}_block_fn already call it 'blocks' and this patch has to
update the type of this parameter anyway, let's use that.

> #ifdef CONFIG_AS_AVX
> -asmlinkage void sha1_transform_avx(u32 *digest, const char *data,
> - unsigned int rounds);
> +asmlinkage void sha1_transform_avx(struct sha1_state *digest,
> + const u8 *data, int rounds);
>

This patch is also still missing updates to the corresponding comments in the
assembly files:

sha1_transform_avx()
sha1_transform_avx2()
sha256_transform_avx()
sha256_transform_rorx()
sha512_transform_ssse3() [references to D, M, and L remain]
sha512_transform_avx()
sha512_transform_rorx()

FWIW, this patch is also independent from 1-7, so it could be sent out
separately if it makes things any easier for you.

Thanks,

- Eric