^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2019 Linaro Ltd <ard.biesheuvel@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <asm/cpufeature.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <asm/neon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "aegis.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) void crypto_aegis128_init_neon(void *state, const void *key, const void *iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) void crypto_aegis128_update_neon(void *state, const void *msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) void crypto_aegis128_encrypt_chunk_neon(void *state, void *dst, const void *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) unsigned int size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) void crypto_aegis128_decrypt_chunk_neon(void *state, void *dst, const void *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) unsigned int size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) void crypto_aegis128_final_neon(void *state, void *tag_xor, uint64_t assoclen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) uint64_t cryptlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) int aegis128_have_aes_insn __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) bool crypto_aegis128_have_simd(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) if (cpu_have_feature(cpu_feature(AES))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) aegis128_have_aes_insn = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return IS_ENABLED(CONFIG_ARM64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) void crypto_aegis128_init_simd(union aegis_block *state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) const union aegis_block *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) const u8 *iv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) crypto_aegis128_init_neon(state, key, iv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) void crypto_aegis128_update_simd(union aegis_block *state, const void *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) crypto_aegis128_update_neon(state, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) void crypto_aegis128_encrypt_chunk_simd(union aegis_block *state, u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) const u8 *src, unsigned int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) crypto_aegis128_encrypt_chunk_neon(state, dst, src, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void crypto_aegis128_decrypt_chunk_simd(union aegis_block *state, u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) const u8 *src, unsigned int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) crypto_aegis128_decrypt_chunk_neon(state, dst, src, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) void crypto_aegis128_final_simd(union aegis_block *state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) union aegis_block *tag_xor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u64 assoclen, u64 cryptlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) kernel_neon_begin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) crypto_aegis128_final_neon(state, tag_xor, assoclen, cryptlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) kernel_neon_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }