18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2019 Linaro Ltd <ard.biesheuvel@linaro.org> 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <asm/cpufeature.h> 78c2ecf20Sopenharmony_ci#include <asm/neon.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include "aegis.h" 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_civoid crypto_aegis128_init_neon(void *state, const void *key, const void *iv); 128c2ecf20Sopenharmony_civoid crypto_aegis128_update_neon(void *state, const void *msg); 138c2ecf20Sopenharmony_civoid crypto_aegis128_encrypt_chunk_neon(void *state, void *dst, const void *src, 148c2ecf20Sopenharmony_ci unsigned int size); 158c2ecf20Sopenharmony_civoid crypto_aegis128_decrypt_chunk_neon(void *state, void *dst, const void *src, 168c2ecf20Sopenharmony_ci unsigned int size); 178c2ecf20Sopenharmony_civoid crypto_aegis128_final_neon(void *state, void *tag_xor, uint64_t assoclen, 188c2ecf20Sopenharmony_ci uint64_t cryptlen); 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ciint aegis128_have_aes_insn __ro_after_init; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cibool crypto_aegis128_have_simd(void) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci if (cpu_have_feature(cpu_feature(AES))) { 258c2ecf20Sopenharmony_ci aegis128_have_aes_insn = 1; 268c2ecf20Sopenharmony_ci return true; 278c2ecf20Sopenharmony_ci } 288c2ecf20Sopenharmony_ci return IS_ENABLED(CONFIG_ARM64); 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_civoid crypto_aegis128_init_simd(union aegis_block *state, 328c2ecf20Sopenharmony_ci const union aegis_block *key, 338c2ecf20Sopenharmony_ci const u8 *iv) 348c2ecf20Sopenharmony_ci{ 358c2ecf20Sopenharmony_ci kernel_neon_begin(); 368c2ecf20Sopenharmony_ci crypto_aegis128_init_neon(state, key, iv); 378c2ecf20Sopenharmony_ci kernel_neon_end(); 388c2ecf20Sopenharmony_ci} 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_civoid crypto_aegis128_update_simd(union aegis_block *state, const void *msg) 418c2ecf20Sopenharmony_ci{ 428c2ecf20Sopenharmony_ci kernel_neon_begin(); 438c2ecf20Sopenharmony_ci crypto_aegis128_update_neon(state, msg); 448c2ecf20Sopenharmony_ci kernel_neon_end(); 458c2ecf20Sopenharmony_ci} 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_civoid crypto_aegis128_encrypt_chunk_simd(union aegis_block *state, u8 *dst, 488c2ecf20Sopenharmony_ci const u8 *src, unsigned int size) 498c2ecf20Sopenharmony_ci{ 508c2ecf20Sopenharmony_ci kernel_neon_begin(); 518c2ecf20Sopenharmony_ci crypto_aegis128_encrypt_chunk_neon(state, dst, src, size); 528c2ecf20Sopenharmony_ci kernel_neon_end(); 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_civoid crypto_aegis128_decrypt_chunk_simd(union aegis_block *state, u8 *dst, 568c2ecf20Sopenharmony_ci const u8 *src, unsigned int size) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci kernel_neon_begin(); 598c2ecf20Sopenharmony_ci crypto_aegis128_decrypt_chunk_neon(state, dst, src, size); 608c2ecf20Sopenharmony_ci kernel_neon_end(); 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_civoid crypto_aegis128_final_simd(union aegis_block *state, 648c2ecf20Sopenharmony_ci union aegis_block *tag_xor, 658c2ecf20Sopenharmony_ci u64 assoclen, u64 cryptlen) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci kernel_neon_begin(); 688c2ecf20Sopenharmony_ci crypto_aegis128_final_neon(state, tag_xor, assoclen, cryptlen); 698c2ecf20Sopenharmony_ci kernel_neon_end(); 708c2ecf20Sopenharmony_ci} 71