diff options
Diffstat (limited to 'src/crypto')
-rw-r--r-- | src/crypto/include/zinc/blake2s.h | 39 | ||||
-rw-r--r-- | src/crypto/zinc/blake2s/blake2s.c | 10 |
2 files changed, 9 insertions, 40 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, diff --git a/src/crypto/zinc/blake2s/blake2s.c b/src/crypto/zinc/blake2s/blake2s.c index 69b2b4e..29382da 100644 --- a/src/crypto/zinc/blake2s/blake2s.c +++ b/src/crypto/zinc/blake2s/blake2s.c @@ -230,14 +230,20 @@ void blake2s_update(struct blake2s_state *state, const u8 *in, size_t inlen) } EXPORT_SYMBOL(blake2s_update); -void __blake2s_final(struct blake2s_state *state) +void blake2s_final(struct blake2s_state *state, u8 *out, const size_t outlen) { +#ifdef DEBUG + BUG_ON(!out || !outlen || outlen > BLAKE2S_OUTBYTES); +#endif blake2s_set_lastblock(state); memset(state->buf + state->buflen, 0, BLAKE2S_BLOCKBYTES - state->buflen); /* Padding */ blake2s_compress(state, state->buf, 1, state->buflen); + cpu_to_le32_array(state->h, ARRAY_SIZE(state->h)); + memcpy(out, state->h, outlen); + memzero_explicit(state, sizeof(*state)); } -EXPORT_SYMBOL(__blake2s_final); +EXPORT_SYMBOL(blake2s_final); void blake2s_hmac(u8 *out, const u8 *in, const u8 *key, const size_t outlen, const size_t inlen, const size_t keylen) |