blob: a7856915ec85b4172eceff31442f024d7d00809f [file] [log] [blame]
Ard Biesheuvela4397632019-08-12 01:59:11 +03001// 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 Biesheuvel52828262019-10-14 18:16:45 +020011void crypto_aegis128_init_neon(void *state, const void *key, const void *iv);
Ard Biesheuvela4397632019-08-12 01:59:11 +030012void crypto_aegis128_update_neon(void *state, const void *msg);
13void crypto_aegis128_encrypt_chunk_neon(void *state, void *dst, const void *src,
14 unsigned int size);
15void crypto_aegis128_decrypt_chunk_neon(void *state, void *dst, const void *src,
16 unsigned int size);
Ard Biesheuvel97b70182020-11-17 14:32:13 +010017int crypto_aegis128_final_neon(void *state, void *tag_xor,
18 unsigned int assoclen,
19 unsigned int cryptlen,
20 unsigned int authsize);
Ard Biesheuvela4397632019-08-12 01:59:11 +030021
Ard Biesheuvel19842962019-08-12 01:59:12 +030022int aegis128_have_aes_insn __ro_after_init;
23
Ard Biesheuvela4397632019-08-12 01:59:11 +030024bool crypto_aegis128_have_simd(void)
25{
Ard Biesheuvel19842962019-08-12 01:59:12 +030026 if (cpu_have_feature(cpu_feature(AES))) {
27 aegis128_have_aes_insn = 1;
28 return true;
29 }
30 return IS_ENABLED(CONFIG_ARM64);
Ard Biesheuvela4397632019-08-12 01:59:11 +030031}
32
Herbert Xu09149992021-03-08 16:41:32 +110033void crypto_aegis128_init_simd(struct aegis_state *state,
Ard Biesheuvel52828262019-10-14 18:16:45 +020034 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 Xu09149992021-03-08 16:41:32 +110042void crypto_aegis128_update_simd(struct aegis_state *state, const void *msg)
Ard Biesheuvela4397632019-08-12 01:59:11 +030043{
44 kernel_neon_begin();
45 crypto_aegis128_update_neon(state, msg);
46 kernel_neon_end();
47}
48
Herbert Xu09149992021-03-08 16:41:32 +110049void crypto_aegis128_encrypt_chunk_simd(struct aegis_state *state, u8 *dst,
Ard Biesheuvela4397632019-08-12 01:59:11 +030050 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 Xu09149992021-03-08 16:41:32 +110057void crypto_aegis128_decrypt_chunk_simd(struct aegis_state *state, u8 *dst,
Ard Biesheuvela4397632019-08-12 01:59:11 +030058 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 Biesheuvel52828262019-10-14 18:16:45 +020064
Herbert Xu09149992021-03-08 16:41:32 +110065int crypto_aegis128_final_simd(struct aegis_state *state,
Ard Biesheuvel97b70182020-11-17 14:32:13 +010066 union aegis_block *tag_xor,
67 unsigned int assoclen,
68 unsigned int cryptlen,
69 unsigned int authsize)
Ard Biesheuvel52828262019-10-14 18:16:45 +020070{
Ard Biesheuvel97b70182020-11-17 14:32:13 +010071 int ret;
72
Ard Biesheuvel52828262019-10-14 18:16:45 +020073 kernel_neon_begin();
Ard Biesheuvel97b70182020-11-17 14:32:13 +010074 ret = crypto_aegis128_final_neon(state, tag_xor, assoclen, cryptlen,
75 authsize);
Ard Biesheuvel52828262019-10-14 18:16:45 +020076 kernel_neon_end();
Ard Biesheuvel97b70182020-11-17 14:32:13 +010077
78 return ret;
Ard Biesheuvel52828262019-10-14 18:16:45 +020079}