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