xref: /openbmc/linux/crypto/aegis128-neon.c (revision 4e3901fa)
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"
10*4e3901faSArnd Bergmann #include "aegis-neon.h"
11a4397635SArd Biesheuvel 
1219842963SArd Biesheuvel int aegis128_have_aes_insn __ro_after_init;
1319842963SArd Biesheuvel 
crypto_aegis128_have_simd(void)14a4397635SArd Biesheuvel bool crypto_aegis128_have_simd(void)
15a4397635SArd Biesheuvel {
1619842963SArd Biesheuvel 	if (cpu_have_feature(cpu_feature(AES))) {
1719842963SArd Biesheuvel 		aegis128_have_aes_insn = 1;
1819842963SArd Biesheuvel 		return true;
1919842963SArd Biesheuvel 	}
2019842963SArd Biesheuvel 	return IS_ENABLED(CONFIG_ARM64);
21a4397635SArd Biesheuvel }
22a4397635SArd Biesheuvel 
crypto_aegis128_init_simd(struct aegis_state * state,const union aegis_block * key,const u8 * iv)2309149997SHerbert Xu void crypto_aegis128_init_simd(struct aegis_state *state,
2452828263SArd Biesheuvel 			       const union aegis_block *key,
2552828263SArd Biesheuvel 			       const u8 *iv)
2652828263SArd Biesheuvel {
2752828263SArd Biesheuvel 	kernel_neon_begin();
2852828263SArd Biesheuvel 	crypto_aegis128_init_neon(state, key, iv);
2952828263SArd Biesheuvel 	kernel_neon_end();
3052828263SArd Biesheuvel }
3152828263SArd Biesheuvel 
crypto_aegis128_update_simd(struct aegis_state * state,const void * msg)3209149997SHerbert Xu void crypto_aegis128_update_simd(struct aegis_state *state, const void *msg)
33a4397635SArd Biesheuvel {
34a4397635SArd Biesheuvel 	kernel_neon_begin();
35a4397635SArd Biesheuvel 	crypto_aegis128_update_neon(state, msg);
36a4397635SArd Biesheuvel 	kernel_neon_end();
37a4397635SArd Biesheuvel }
38a4397635SArd Biesheuvel 
crypto_aegis128_encrypt_chunk_simd(struct aegis_state * state,u8 * dst,const u8 * src,unsigned int size)3909149997SHerbert Xu void crypto_aegis128_encrypt_chunk_simd(struct aegis_state *state, u8 *dst,
40a4397635SArd Biesheuvel 					const u8 *src, unsigned int size)
41a4397635SArd Biesheuvel {
42a4397635SArd Biesheuvel 	kernel_neon_begin();
43a4397635SArd Biesheuvel 	crypto_aegis128_encrypt_chunk_neon(state, dst, src, size);
44a4397635SArd Biesheuvel 	kernel_neon_end();
45a4397635SArd Biesheuvel }
46a4397635SArd Biesheuvel 
crypto_aegis128_decrypt_chunk_simd(struct aegis_state * state,u8 * dst,const u8 * src,unsigned int size)4709149997SHerbert Xu void crypto_aegis128_decrypt_chunk_simd(struct aegis_state *state, u8 *dst,
48a4397635SArd Biesheuvel 					const u8 *src, unsigned int size)
49a4397635SArd Biesheuvel {
50a4397635SArd Biesheuvel 	kernel_neon_begin();
51a4397635SArd Biesheuvel 	crypto_aegis128_decrypt_chunk_neon(state, dst, src, size);
52a4397635SArd Biesheuvel 	kernel_neon_end();
53a4397635SArd Biesheuvel }
5452828263SArd Biesheuvel 
crypto_aegis128_final_simd(struct aegis_state * state,union aegis_block * tag_xor,unsigned int assoclen,unsigned int cryptlen,unsigned int authsize)5509149997SHerbert Xu int crypto_aegis128_final_simd(struct aegis_state *state,
5652828263SArd Biesheuvel 			       union aegis_block *tag_xor,
5797b70180SArd Biesheuvel 			       unsigned int assoclen,
5897b70180SArd Biesheuvel 			       unsigned int cryptlen,
5997b70180SArd Biesheuvel 			       unsigned int authsize)
6052828263SArd Biesheuvel {
6197b70180SArd Biesheuvel 	int ret;
6297b70180SArd Biesheuvel 
6352828263SArd Biesheuvel 	kernel_neon_begin();
6497b70180SArd Biesheuvel 	ret = crypto_aegis128_final_neon(state, tag_xor, assoclen, cryptlen,
6597b70180SArd Biesheuvel 					 authsize);
6652828263SArd Biesheuvel 	kernel_neon_end();
6797b70180SArd Biesheuvel 
6897b70180SArd Biesheuvel 	return ret;
6952828263SArd Biesheuvel }
70