xref: /linux/crypto/aegis128-neon.c (revision f4b369c6fe0ceaba2da2daff8c9eb415f85926dd)
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>
7*88a7999eSArd Biesheuvel #include <asm/simd.h>
8a4397635SArd Biesheuvel 
9a4397635SArd Biesheuvel #include "aegis.h"
104e3901faSArnd 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 {
27*88a7999eSArd Biesheuvel 	scoped_ksimd()
2852828263SArd Biesheuvel 		crypto_aegis128_init_neon(state, key, iv);
2952828263SArd Biesheuvel }
3052828263SArd Biesheuvel 
crypto_aegis128_update_simd(struct aegis_state * state,const void * msg)3109149997SHerbert Xu void crypto_aegis128_update_simd(struct aegis_state *state, const void *msg)
32a4397635SArd Biesheuvel {
33*88a7999eSArd Biesheuvel 	scoped_ksimd()
34a4397635SArd Biesheuvel 		crypto_aegis128_update_neon(state, msg);
35a4397635SArd Biesheuvel }
36a4397635SArd Biesheuvel 
crypto_aegis128_encrypt_chunk_simd(struct aegis_state * state,u8 * dst,const u8 * src,unsigned int size)3709149997SHerbert Xu void crypto_aegis128_encrypt_chunk_simd(struct aegis_state *state, u8 *dst,
38a4397635SArd Biesheuvel 					const u8 *src, unsigned int size)
39a4397635SArd Biesheuvel {
40*88a7999eSArd Biesheuvel 	scoped_ksimd()
41a4397635SArd Biesheuvel 		crypto_aegis128_encrypt_chunk_neon(state, dst, src, size);
42a4397635SArd Biesheuvel }
43a4397635SArd Biesheuvel 
crypto_aegis128_decrypt_chunk_simd(struct aegis_state * state,u8 * dst,const u8 * src,unsigned int size)4409149997SHerbert Xu void crypto_aegis128_decrypt_chunk_simd(struct aegis_state *state, u8 *dst,
45a4397635SArd Biesheuvel 					const u8 *src, unsigned int size)
46a4397635SArd Biesheuvel {
47*88a7999eSArd Biesheuvel 	scoped_ksimd()
48a4397635SArd Biesheuvel 		crypto_aegis128_decrypt_chunk_neon(state, dst, src, size);
49a4397635SArd Biesheuvel }
5052828263SArd Biesheuvel 
crypto_aegis128_final_simd(struct aegis_state * state,union aegis_block * tag_xor,unsigned int assoclen,unsigned int cryptlen,unsigned int authsize)5109149997SHerbert Xu int crypto_aegis128_final_simd(struct aegis_state *state,
5252828263SArd Biesheuvel 			       union aegis_block *tag_xor,
5397b70180SArd Biesheuvel 			       unsigned int assoclen,
5497b70180SArd Biesheuvel 			       unsigned int cryptlen,
5597b70180SArd Biesheuvel 			       unsigned int authsize)
5652828263SArd Biesheuvel {
57*88a7999eSArd Biesheuvel 	scoped_ksimd()
58*88a7999eSArd Biesheuvel 		return crypto_aegis128_final_neon(state, tag_xor, assoclen,
59*88a7999eSArd Biesheuvel 						  cryptlen, authsize);
6052828263SArd Biesheuvel }
61