mirror of
https://github.com/torvalds/linux.git
synced 2025-08-15 14:11:42 +02:00

Fix build warnings with W=1 that started appearing after
commit a934a57a42
("scripts/misc-check: check missing #include
<linux/export.h> when W=1").
While at it, also sort the include lists alphabetically. (Keep
asm/irqflags.h last, as otherwise it doesn't build on alpha.)
This handles all of lib/crypto/, but not arch/*/lib/crypto/. The
exports in arch/*/lib/crypto/ will go away when the code is properly
integrated into lib/crypto/ as planned.
Link: https://lore.kernel.org/r/20250613184814.50173-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
72 lines
2 KiB
C
72 lines
2 KiB
C
// SPDX-License-Identifier: GPL-2.0 OR MIT
|
|
/*
|
|
* Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
|
*
|
|
* This is an implementation of the BLAKE2s hash and PRF functions.
|
|
*
|
|
* Information: https://blake2.net/
|
|
*
|
|
*/
|
|
|
|
#include <crypto/internal/blake2s.h>
|
|
#include <linux/bug.h>
|
|
#include <linux/export.h>
|
|
#include <linux/init.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/string.h>
|
|
#include <linux/types.h>
|
|
|
|
static inline void blake2s_set_lastblock(struct blake2s_state *state)
|
|
{
|
|
state->f[0] = -1;
|
|
}
|
|
|
|
void blake2s_update(struct blake2s_state *state, const u8 *in, size_t inlen)
|
|
{
|
|
const size_t fill = BLAKE2S_BLOCK_SIZE - state->buflen;
|
|
|
|
if (unlikely(!inlen))
|
|
return;
|
|
if (inlen > fill) {
|
|
memcpy(state->buf + state->buflen, in, fill);
|
|
blake2s_compress(state, state->buf, 1, BLAKE2S_BLOCK_SIZE);
|
|
state->buflen = 0;
|
|
in += fill;
|
|
inlen -= fill;
|
|
}
|
|
if (inlen > BLAKE2S_BLOCK_SIZE) {
|
|
const size_t nblocks = DIV_ROUND_UP(inlen, BLAKE2S_BLOCK_SIZE);
|
|
blake2s_compress(state, in, nblocks - 1, BLAKE2S_BLOCK_SIZE);
|
|
in += BLAKE2S_BLOCK_SIZE * (nblocks - 1);
|
|
inlen -= BLAKE2S_BLOCK_SIZE * (nblocks - 1);
|
|
}
|
|
memcpy(state->buf + state->buflen, in, inlen);
|
|
state->buflen += inlen;
|
|
}
|
|
EXPORT_SYMBOL(blake2s_update);
|
|
|
|
void blake2s_final(struct blake2s_state *state, u8 *out)
|
|
{
|
|
WARN_ON(IS_ENABLED(DEBUG) && !out);
|
|
blake2s_set_lastblock(state);
|
|
memset(state->buf + state->buflen, 0,
|
|
BLAKE2S_BLOCK_SIZE - 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, state->outlen);
|
|
memzero_explicit(state, sizeof(*state));
|
|
}
|
|
EXPORT_SYMBOL(blake2s_final);
|
|
|
|
static int __init blake2s_mod_init(void)
|
|
{
|
|
if (IS_ENABLED(CONFIG_CRYPTO_SELFTESTS) &&
|
|
WARN_ON(!blake2s_selftest()))
|
|
return -ENODEV;
|
|
return 0;
|
|
}
|
|
|
|
module_init(blake2s_mod_init);
|
|
MODULE_DESCRIPTION("BLAKE2s hash function");
|
|
MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");
|