xref: /openbmc/linux/crypto/aegis128-neon.c (revision 09149997)
1a4397635SArd Biesheuvel // SPDX-License-Identifier: GPL-2.0-or-later
2a4397635SArd Biesheuvel /*
3a4397635SArd Biesheuvel  * Copyright (C) 2019 Linaro Ltd <ard.biesheuvel@linaro.org>
4a4397635SArd Biesheuvel  */
5a4397635SArd Biesheuvel 
6a4397635SArd Biesheuvel #include <asm/cpufeature.h>
7a4397635SArd Biesheuvel #include <asm/neon.h>
8a4397635SArd Biesheuvel 
9a4397635SArd Biesheuvel #include "aegis.h"
10a4397635SArd Biesheuvel 
1152828263SArd Biesheuvel void crypto_aegis128_init_neon(void *state, const void *key, const void *iv);
12a4397635SArd Biesheuvel void crypto_aegis128_update_neon(void *state, const void *msg);
13a4397635SArd Biesheuvel void crypto_aegis128_encrypt_chunk_neon(void *state, void *dst, const void *src,
14a4397635SArd Biesheuvel 					unsigned int size);
15a4397635SArd Biesheuvel void crypto_aegis128_decrypt_chunk_neon(void *state, void *dst, const void *src,
16a4397635SArd Biesheuvel 					unsigned int size);
1797b70180SArd Biesheuvel int crypto_aegis128_final_neon(void *state, void *tag_xor,
1897b70180SArd Biesheuvel 			       unsigned int assoclen,
1997b70180SArd Biesheuvel 			       unsigned int cryptlen,
2097b70180SArd Biesheuvel 			       unsigned int authsize);
21a4397635SArd Biesheuvel 
2219842963SArd Biesheuvel int aegis128_have_aes_insn __ro_after_init;
2319842963SArd Biesheuvel 
24a4397635SArd Biesheuvel bool crypto_aegis128_have_simd(void)
25a4397635SArd Biesheuvel {
2619842963SArd Biesheuvel 	if (cpu_have_feature(cpu_feature(AES))) {
2719842963SArd Biesheuvel 		aegis128_have_aes_insn = 1;
2819842963SArd Biesheuvel 		return true;
2919842963SArd Biesheuvel 	}
3019842963SArd Biesheuvel 	return IS_ENABLED(CONFIG_ARM64);
31a4397635SArd Biesheuvel }
32a4397635SArd Biesheuvel 
33*09149997SHerbert Xu void crypto_aegis128_init_simd(struct aegis_state *state,
3452828263SArd Biesheuvel 			       const union aegis_block *key,
3552828263SArd Biesheuvel 			       const u8 *iv)
3652828263SArd Biesheuvel {
3752828263SArd Biesheuvel 	kernel_neon_begin();
3852828263SArd Biesheuvel 	crypto_aegis128_init_neon(state, key, iv);
3952828263SArd Biesheuvel 	kernel_neon_end();
4052828263SArd Biesheuvel }
4152828263SArd Biesheuvel 
42*09149997SHerbert Xu void crypto_aegis128_update_simd(struct aegis_state *state, const void *msg)
43a4397635SArd Biesheuvel {
44a4397635SArd Biesheuvel 	kernel_neon_begin();
45a4397635SArd Biesheuvel 	crypto_aegis128_update_neon(state, msg);
46a4397635SArd Biesheuvel 	kernel_neon_end();
47a4397635SArd Biesheuvel }
48a4397635SArd Biesheuvel 
49*09149997SHerbert Xu void crypto_aegis128_encrypt_chunk_simd(struct aegis_state *state, u8 *dst,
50a4397635SArd Biesheuvel 					const u8 *src, unsigned int size)
51a4397635SArd Biesheuvel {
52a4397635SArd Biesheuvel 	kernel_neon_begin();
53a4397635SArd Biesheuvel 	crypto_aegis128_encrypt_chunk_neon(state, dst, src, size);
54a4397635SArd Biesheuvel 	kernel_neon_end();
55a4397635SArd Biesheuvel }
56a4397635SArd Biesheuvel 
57*09149997SHerbert Xu void crypto_aegis128_decrypt_chunk_simd(struct aegis_state *state, u8 *dst,
58a4397635SArd Biesheuvel 					const u8 *src, unsigned int size)
59a4397635SArd Biesheuvel {
60a4397635SArd Biesheuvel 	kernel_neon_begin();
61a4397635SArd Biesheuvel 	crypto_aegis128_decrypt_chunk_neon(state, dst, src, size);
62a4397635SArd Biesheuvel 	kernel_neon_end();
63a4397635SArd Biesheuvel }
6452828263SArd Biesheuvel 
65*09149997SHerbert Xu int crypto_aegis128_final_simd(struct aegis_state *state,
6652828263SArd Biesheuvel 			       union aegis_block *tag_xor,
6797b70180SArd Biesheuvel 			       unsigned int assoclen,
6897b70180SArd Biesheuvel 			       unsigned int cryptlen,
6997b70180SArd Biesheuvel 			       unsigned int authsize)
7052828263SArd Biesheuvel {
7197b70180SArd Biesheuvel 	int ret;
7297b70180SArd Biesheuvel 
7352828263SArd Biesheuvel 	kernel_neon_begin();
7497b70180SArd Biesheuvel 	ret = crypto_aegis128_final_neon(state, tag_xor, assoclen, cryptlen,
7597b70180SArd Biesheuvel 					 authsize);
7652828263SArd Biesheuvel 	kernel_neon_end();
7797b70180SArd Biesheuvel 
7897b70180SArd Biesheuvel 	return ret;
7952828263SArd Biesheuvel }
80