From a849803dc9aa139ce209d7b8ccf0bd57b52929c8 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 19 Sep 2018 02:56:34 +0200 Subject: blake2s: simplify final function Suggested-by: Eric Biggers --- src/crypto/include/zinc/blake2s.h | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) (limited to 'src/crypto/include') diff --git a/src/crypto/include/zinc/blake2s.h b/src/crypto/include/zinc/blake2s.h index 9512815..7a4382c 100644 --- a/src/crypto/include/zinc/blake2s.h +++ b/src/crypto/include/zinc/blake2s.h @@ -29,44 +29,7 @@ void blake2s_init(struct blake2s_state *state, const size_t outlen); void blake2s_init_key(struct blake2s_state *state, const size_t outlen, const void *key, const size_t keylen); void blake2s_update(struct blake2s_state *state, const u8 *in, size_t inlen); -void __blake2s_final(struct blake2s_state *state); -static inline void blake2s_final(struct blake2s_state *state, u8 *out, - const size_t outlen) -{ - int i; - -#ifdef DEBUG - BUG_ON(!out || !outlen || outlen > BLAKE2S_OUTBYTES); -#endif - __blake2s_final(state); - - if (__builtin_constant_p(outlen) && !(outlen % sizeof(u32))) { - if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) || - IS_ALIGNED((unsigned long)out, __alignof__(u32))) { - __le32 *outwords = (__le32 *)out; - - for (i = 0; i < outlen / sizeof(u32); ++i) - outwords[i] = cpu_to_le32(state->h[i]); - } else { - __le32 buffer[BLAKE2S_OUTBYTES]; - - for (i = 0; i < outlen / sizeof(u32); ++i) - buffer[i] = cpu_to_le32(state->h[i]); - memcpy(out, buffer, outlen); - memzero_explicit(buffer, sizeof(buffer)); - } - } else { - u8 buffer[BLAKE2S_OUTBYTES] __aligned(__alignof__(u32)); - __le32 *outwords = (__le32 *)buffer; - - for (i = 0; i < 8; ++i) - outwords[i] = cpu_to_le32(state->h[i]); - memcpy(out, buffer, outlen); - memzero_explicit(buffer, sizeof(buffer)); - } - - memzero_explicit(state, sizeof(*state)); -} +void blake2s_final(struct blake2s_state *state, u8 *out, const size_t outlen); static inline void blake2s(u8 *out, const u8 *in, const u8 *key, const size_t outlen, const size_t inlen, -- cgit v1.2.3-59-g8ed1b