|
| 1 | +/* SPDX-License-Identifier: MIT |
| 2 | + * |
| 3 | + * Copyright (C) 2015-2018 Jason A. Donenfeld <[email protected]>. All Rights Reserved. |
| 4 | + */ |
| 5 | + |
| 6 | +#include <asm/hwcap.h> |
| 7 | +#include <asm/neon.h> |
| 8 | + |
| 9 | +asmlinkage void poly1305_init_arm(void *ctx, const u8 key[16]); |
| 10 | +asmlinkage void poly1305_blocks_arm(void *ctx, const u8 *inp, const size_t len, |
| 11 | + const u32 padbit); |
| 12 | +asmlinkage void poly1305_emit_arm(void *ctx, u8 mac[16], const u32 nonce[4]); |
| 13 | +#if IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && \ |
| 14 | + (defined(CONFIG_64BIT) || __LINUX_ARM_ARCH__ >= 7) |
| 15 | +#define ARM_USE_NEON |
| 16 | +asmlinkage void poly1305_blocks_neon(void *ctx, const u8 *inp, const size_t len, |
| 17 | + const u32 padbit); |
| 18 | +asmlinkage void poly1305_emit_neon(void *ctx, u8 mac[16], const u32 nonce[4]); |
| 19 | +#endif |
| 20 | + |
| 21 | +static bool poly1305_use_neon __ro_after_init; |
| 22 | + |
| 23 | +static void __init poly1305_fpu_init(void) |
| 24 | +{ |
| 25 | +#if defined(CONFIG_ARM64) |
| 26 | + poly1305_use_neon = elf_hwcap & HWCAP_ASIMD; |
| 27 | +#elif defined(CONFIG_ARM) |
| 28 | + poly1305_use_neon = elf_hwcap & HWCAP_NEON; |
| 29 | +#endif |
| 30 | +} |
| 31 | + |
| 32 | +static inline bool poly1305_init_arch(void *ctx, |
| 33 | + const u8 key[POLY1305_KEY_SIZE]) |
| 34 | +{ |
| 35 | + poly1305_init_arm(ctx, key); |
| 36 | + return true; |
| 37 | +} |
| 38 | + |
| 39 | +static inline bool poly1305_blocks_arch(void *ctx, const u8 *inp, |
| 40 | + const size_t len, const u32 padbit, |
| 41 | + simd_context_t *simd_context) |
| 42 | +{ |
| 43 | +#if defined(ARM_USE_NEON) |
| 44 | + if (poly1305_use_neon && simd_use(simd_context)) { |
| 45 | + poly1305_blocks_neon(ctx, inp, len, padbit); |
| 46 | + return true; |
| 47 | + } |
| 48 | +#endif |
| 49 | + poly1305_blocks_arm(ctx, inp, len, padbit); |
| 50 | + return true; |
| 51 | +} |
| 52 | + |
| 53 | +static inline bool poly1305_emit_arch(void *ctx, u8 mac[POLY1305_MAC_SIZE], |
| 54 | + const u32 nonce[4], |
| 55 | + simd_context_t *simd_context) |
| 56 | +{ |
| 57 | +#if defined(ARM_USE_NEON) |
| 58 | + if (poly1305_use_neon && simd_use(simd_context)) { |
| 59 | + poly1305_emit_neon(ctx, mac, nonce); |
| 60 | + return true; |
| 61 | + } |
| 62 | +#endif |
| 63 | + poly1305_emit_arm(ctx, mac, nonce); |
| 64 | + return true; |
| 65 | +} |
0 commit comments