| .. | .. |
|---|
| 6 | 6 | #include <crypto/algapi.h> |
|---|
| 7 | 7 | #include <crypto/internal/hash.h> |
|---|
| 8 | 8 | #include <crypto/internal/poly1305.h> |
|---|
| 9 | +#include <crypto/internal/simd.h> |
|---|
| 9 | 10 | #include <linux/crypto.h> |
|---|
| 10 | 11 | #include <linux/jump_label.h> |
|---|
| 11 | 12 | #include <linux/kernel.h> |
|---|
| 12 | 13 | #include <linux/module.h> |
|---|
| 13 | | -#include <asm/fpu/api.h> |
|---|
| 14 | | -#include <asm/simd.h> |
|---|
| 14 | +#include <linux/sizes.h> |
|---|
| 15 | 15 | #include <asm/intel-family.h> |
|---|
| 16 | +#include <asm/simd.h> |
|---|
| 16 | 17 | |
|---|
| 17 | 18 | asmlinkage void poly1305_init_x86_64(void *ctx, |
|---|
| 18 | | - const u8 key[POLY1305_KEY_SIZE]); |
|---|
| 19 | + const u8 key[POLY1305_BLOCK_SIZE]); |
|---|
| 19 | 20 | asmlinkage void poly1305_blocks_x86_64(void *ctx, const u8 *inp, |
|---|
| 20 | 21 | const size_t len, const u32 padbit); |
|---|
| 21 | 22 | asmlinkage void poly1305_emit_x86_64(void *ctx, u8 mac[POLY1305_DIGEST_SIZE], |
|---|
| .. | .. |
|---|
| 80 | 81 | state->is_base2_26 = 0; |
|---|
| 81 | 82 | } |
|---|
| 82 | 83 | |
|---|
| 83 | | -static void poly1305_simd_init(void *ctx, const u8 key[POLY1305_KEY_SIZE]) |
|---|
| 84 | +static void poly1305_simd_init(void *ctx, const u8 key[POLY1305_BLOCK_SIZE]) |
|---|
| 84 | 85 | { |
|---|
| 85 | 86 | poly1305_init_x86_64(ctx, key); |
|---|
| 86 | 87 | } |
|---|
| .. | .. |
|---|
| 94 | 95 | BUILD_BUG_ON(SZ_4K < POLY1305_BLOCK_SIZE || |
|---|
| 95 | 96 | SZ_4K % POLY1305_BLOCK_SIZE); |
|---|
| 96 | 97 | |
|---|
| 97 | | - if (!IS_ENABLED(CONFIG_AS_AVX) || !static_branch_likely(&poly1305_use_avx) || |
|---|
| 98 | + if (!static_branch_likely(&poly1305_use_avx) || |
|---|
| 98 | 99 | (len < (POLY1305_BLOCK_SIZE * 18) && !state->is_base2_26) || |
|---|
| 99 | | - !may_use_simd()) { |
|---|
| 100 | + !crypto_simd_usable()) { |
|---|
| 100 | 101 | convert_to_base2_64(ctx); |
|---|
| 101 | 102 | poly1305_blocks_x86_64(ctx, inp, len, padbit); |
|---|
| 102 | 103 | return; |
|---|
| .. | .. |
|---|
| 108 | 109 | kernel_fpu_begin(); |
|---|
| 109 | 110 | if (IS_ENABLED(CONFIG_AS_AVX512) && static_branch_likely(&poly1305_use_avx512)) |
|---|
| 110 | 111 | poly1305_blocks_avx512(ctx, inp, bytes, padbit); |
|---|
| 111 | | - else if (IS_ENABLED(CONFIG_AS_AVX2) && static_branch_likely(&poly1305_use_avx2)) |
|---|
| 112 | + else if (static_branch_likely(&poly1305_use_avx2)) |
|---|
| 112 | 113 | poly1305_blocks_avx2(ctx, inp, bytes, padbit); |
|---|
| 113 | 114 | else |
|---|
| 114 | 115 | poly1305_blocks_avx(ctx, inp, bytes, padbit); |
|---|
| .. | .. |
|---|
| 122 | 123 | static void poly1305_simd_emit(void *ctx, u8 mac[POLY1305_DIGEST_SIZE], |
|---|
| 123 | 124 | const u32 nonce[4]) |
|---|
| 124 | 125 | { |
|---|
| 125 | | - if (!IS_ENABLED(CONFIG_AS_AVX) || !static_branch_likely(&poly1305_use_avx)) |
|---|
| 126 | + if (!static_branch_likely(&poly1305_use_avx)) |
|---|
| 126 | 127 | poly1305_emit_x86_64(ctx, mac, nonce); |
|---|
| 127 | 128 | else |
|---|
| 128 | 129 | poly1305_emit_avx(ctx, mac, nonce); |
|---|
| 129 | 130 | } |
|---|
| 130 | 131 | |
|---|
| 131 | | -void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 *key) |
|---|
| 132 | +void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE]) |
|---|
| 132 | 133 | { |
|---|
| 133 | 134 | poly1305_simd_init(&dctx->h, key); |
|---|
| 134 | 135 | dctx->s[0] = get_unaligned_le32(&key[16]); |
|---|
| .. | .. |
|---|
| 157 | 158 | dctx->s[1] = get_unaligned_le32(&inp[4]); |
|---|
| 158 | 159 | dctx->s[2] = get_unaligned_le32(&inp[8]); |
|---|
| 159 | 160 | dctx->s[3] = get_unaligned_le32(&inp[12]); |
|---|
| 160 | | - inp += POLY1305_BLOCK_SIZE; |
|---|
| 161 | | - len -= POLY1305_BLOCK_SIZE; |
|---|
| 162 | 161 | acc += POLY1305_BLOCK_SIZE; |
|---|
| 163 | 162 | dctx->sset = true; |
|---|
| 164 | 163 | } |
|---|
| .. | .. |
|---|
| 260 | 259 | |
|---|
| 261 | 260 | static int __init poly1305_simd_mod_init(void) |
|---|
| 262 | 261 | { |
|---|
| 263 | | - if (IS_ENABLED(CONFIG_AS_AVX) && boot_cpu_has(X86_FEATURE_AVX) && |
|---|
| 262 | + if (boot_cpu_has(X86_FEATURE_AVX) && |
|---|
| 264 | 263 | cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL)) |
|---|
| 265 | 264 | static_branch_enable(&poly1305_use_avx); |
|---|
| 266 | | - if (IS_ENABLED(CONFIG_AS_AVX2) && boot_cpu_has(X86_FEATURE_AVX) && |
|---|
| 267 | | - boot_cpu_has(X86_FEATURE_AVX2) && |
|---|
| 265 | + if (boot_cpu_has(X86_FEATURE_AVX) && boot_cpu_has(X86_FEATURE_AVX2) && |
|---|
| 268 | 266 | cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL)) |
|---|
| 269 | 267 | static_branch_enable(&poly1305_use_avx2); |
|---|
| 270 | 268 | if (IS_ENABLED(CONFIG_AS_AVX512) && boot_cpu_has(X86_FEATURE_AVX) && |
|---|