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 | 97b7018 | 2020-11-17 14:32:13 +0100 | [diff] [blame] | 17 | int crypto_aegis128_final_neon(void *state, void *tag_xor, |
| 18 | unsigned int assoclen, |
| 19 | unsigned int cryptlen, |
| 20 | unsigned int authsize); |
Ard Biesheuvel | a439763 | 2019-08-12 01:59:11 +0300 | [diff] [blame] | 21 | |
Ard Biesheuvel | 1984296 | 2019-08-12 01:59:12 +0300 | [diff] [blame] | 22 | int aegis128_have_aes_insn __ro_after_init; |
| 23 | |
Ard Biesheuvel | a439763 | 2019-08-12 01:59:11 +0300 | [diff] [blame] | 24 | bool crypto_aegis128_have_simd(void) |
| 25 | { |
Ard Biesheuvel | 1984296 | 2019-08-12 01:59:12 +0300 | [diff] [blame] | 26 | if (cpu_have_feature(cpu_feature(AES))) { |
| 27 | aegis128_have_aes_insn = 1; |
| 28 | return true; |
| 29 | } |
| 30 | return IS_ENABLED(CONFIG_ARM64); |
Ard Biesheuvel | a439763 | 2019-08-12 01:59:11 +0300 | [diff] [blame] | 31 | } |
| 32 | |
Herbert Xu | 0914999 | 2021-03-08 16:41:32 +1100 | [diff] [blame] | 33 | void crypto_aegis128_init_simd(struct aegis_state *state, |
Ard Biesheuvel | 5282826 | 2019-10-14 18:16:45 +0200 | [diff] [blame] | 34 | const union aegis_block *key, |
| 35 | const u8 *iv) |
| 36 | { |
| 37 | kernel_neon_begin(); |
| 38 | crypto_aegis128_init_neon(state, key, iv); |
| 39 | kernel_neon_end(); |
| 40 | } |
| 41 | |
Herbert Xu | 0914999 | 2021-03-08 16:41:32 +1100 | [diff] [blame] | 42 | void crypto_aegis128_update_simd(struct aegis_state *state, const void *msg) |
Ard Biesheuvel | a439763 | 2019-08-12 01:59:11 +0300 | [diff] [blame] | 43 | { |
| 44 | kernel_neon_begin(); |
| 45 | crypto_aegis128_update_neon(state, msg); |
| 46 | kernel_neon_end(); |
| 47 | } |
| 48 | |
Herbert Xu | 0914999 | 2021-03-08 16:41:32 +1100 | [diff] [blame] | 49 | void crypto_aegis128_encrypt_chunk_simd(struct aegis_state *state, u8 *dst, |
Ard Biesheuvel | a439763 | 2019-08-12 01:59:11 +0300 | [diff] [blame] | 50 | const u8 *src, unsigned int size) |
| 51 | { |
| 52 | kernel_neon_begin(); |
| 53 | crypto_aegis128_encrypt_chunk_neon(state, dst, src, size); |
| 54 | kernel_neon_end(); |
| 55 | } |
| 56 | |
Herbert Xu | 0914999 | 2021-03-08 16:41:32 +1100 | [diff] [blame] | 57 | void crypto_aegis128_decrypt_chunk_simd(struct aegis_state *state, u8 *dst, |
Ard Biesheuvel | a439763 | 2019-08-12 01:59:11 +0300 | [diff] [blame] | 58 | const u8 *src, unsigned int size) |
| 59 | { |
| 60 | kernel_neon_begin(); |
| 61 | crypto_aegis128_decrypt_chunk_neon(state, dst, src, size); |
| 62 | kernel_neon_end(); |
| 63 | } |
Ard Biesheuvel | 5282826 | 2019-10-14 18:16:45 +0200 | [diff] [blame] | 64 | |
Herbert Xu | 0914999 | 2021-03-08 16:41:32 +1100 | [diff] [blame] | 65 | int crypto_aegis128_final_simd(struct aegis_state *state, |
Ard Biesheuvel | 97b7018 | 2020-11-17 14:32:13 +0100 | [diff] [blame] | 66 | union aegis_block *tag_xor, |
| 67 | unsigned int assoclen, |
| 68 | unsigned int cryptlen, |
| 69 | unsigned int authsize) |
Ard Biesheuvel | 5282826 | 2019-10-14 18:16:45 +0200 | [diff] [blame] | 70 | { |
Ard Biesheuvel | 97b7018 | 2020-11-17 14:32:13 +0100 | [diff] [blame] | 71 | int ret; |
| 72 | |
Ard Biesheuvel | 5282826 | 2019-10-14 18:16:45 +0200 | [diff] [blame] | 73 | kernel_neon_begin(); |
Ard Biesheuvel | 97b7018 | 2020-11-17 14:32:13 +0100 | [diff] [blame] | 74 | ret = crypto_aegis128_final_neon(state, tag_xor, assoclen, cryptlen, |
| 75 | authsize); |
Ard Biesheuvel | 5282826 | 2019-10-14 18:16:45 +0200 | [diff] [blame] | 76 | kernel_neon_end(); |
Ard Biesheuvel | 97b7018 | 2020-11-17 14:32:13 +0100 | [diff] [blame] | 77 | |
| 78 | return ret; |
Ard Biesheuvel | 5282826 | 2019-10-14 18:16:45 +0200 | [diff] [blame] | 79 | } |