summaryrefslogtreecommitdiff
path: root/lib/crypto/mips/chacha.h
blob: 15b39c744c2828606d164a375990377eb5d22d8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * ChaCha and HChaCha functions (MIPS optimized)
 *
 * Copyright (C) 2019 Linaro, Ltd. <ard.biesheuvel@linaro.org>
 */

#include <linux/kernel.h>
#include <linux/sizes.h>

asmlinkage void chacha_crypt_mips(struct chacha_state *state, u8 *dst,
				  const u8 *src, size_t bytes, int nrounds);
asmlinkage void hchacha_block_arch(const struct chacha_state *state,
				   u32 out[HCHACHA_OUT_WORDS], int nrounds);

static void chacha_crypt_arch(struct chacha_state *state, u8 *dst,
			      const u8 *src, size_t bytes, int nrounds)
{
	/*
	 * chacha_crypt_mips() compares the length as a signed value, so pass
	 * it at most 1 GiB at a time.
	 */
	do {
		size_t todo = min(bytes, SZ_1G);

		chacha_crypt_mips(state, dst, src, todo, nrounds);
		bytes -= todo;
		src += todo;
		dst += todo;
	} while (bytes);
}