summaryrefslogtreecommitdiffhomepage
path: root/src/crypto/include
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-09-19 02:56:34 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-09-19 23:29:45 +0200
commitcb8af686daad9b45451a91906441f9749ea3ed71 (patch)
tree2ab5c6d14458cee94cba94b87f07103b418bb480 /src/crypto/include
parent57fd00dbd4da0c9ba6da84aefb80f4f4920a051c (diff)
blake2s: simplify final function
Suggested-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/crypto/include')
-rw-r--r--src/crypto/include/zinc/blake2s.h39
1 files changed, 1 insertions, 38 deletions
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,