forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/arch/x86/crypto/poly1305_glue.c
....@@ -6,16 +6,17 @@
66 #include <crypto/algapi.h>
77 #include <crypto/internal/hash.h>
88 #include <crypto/internal/poly1305.h>
9
+#include <crypto/internal/simd.h>
910 #include <linux/crypto.h>
1011 #include <linux/jump_label.h>
1112 #include <linux/kernel.h>
1213 #include <linux/module.h>
13
-#include <asm/fpu/api.h>
14
-#include <asm/simd.h>
14
+#include <linux/sizes.h>
1515 #include <asm/intel-family.h>
16
+#include <asm/simd.h>
1617
1718 asmlinkage void poly1305_init_x86_64(void *ctx,
18
- const u8 key[POLY1305_KEY_SIZE]);
19
+ const u8 key[POLY1305_BLOCK_SIZE]);
1920 asmlinkage void poly1305_blocks_x86_64(void *ctx, const u8 *inp,
2021 const size_t len, const u32 padbit);
2122 asmlinkage void poly1305_emit_x86_64(void *ctx, u8 mac[POLY1305_DIGEST_SIZE],
....@@ -80,7 +81,7 @@
8081 state->is_base2_26 = 0;
8182 }
8283
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])
8485 {
8586 poly1305_init_x86_64(ctx, key);
8687 }
....@@ -94,9 +95,9 @@
9495 BUILD_BUG_ON(SZ_4K < POLY1305_BLOCK_SIZE ||
9596 SZ_4K % POLY1305_BLOCK_SIZE);
9697
97
- if (!IS_ENABLED(CONFIG_AS_AVX) || !static_branch_likely(&poly1305_use_avx) ||
98
+ if (!static_branch_likely(&poly1305_use_avx) ||
9899 (len < (POLY1305_BLOCK_SIZE * 18) && !state->is_base2_26) ||
99
- !may_use_simd()) {
100
+ !crypto_simd_usable()) {
100101 convert_to_base2_64(ctx);
101102 poly1305_blocks_x86_64(ctx, inp, len, padbit);
102103 return;
....@@ -108,7 +109,7 @@
108109 kernel_fpu_begin();
109110 if (IS_ENABLED(CONFIG_AS_AVX512) && static_branch_likely(&poly1305_use_avx512))
110111 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))
112113 poly1305_blocks_avx2(ctx, inp, bytes, padbit);
113114 else
114115 poly1305_blocks_avx(ctx, inp, bytes, padbit);
....@@ -122,13 +123,13 @@
122123 static void poly1305_simd_emit(void *ctx, u8 mac[POLY1305_DIGEST_SIZE],
123124 const u32 nonce[4])
124125 {
125
- if (!IS_ENABLED(CONFIG_AS_AVX) || !static_branch_likely(&poly1305_use_avx))
126
+ if (!static_branch_likely(&poly1305_use_avx))
126127 poly1305_emit_x86_64(ctx, mac, nonce);
127128 else
128129 poly1305_emit_avx(ctx, mac, nonce);
129130 }
130131
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])
132133 {
133134 poly1305_simd_init(&dctx->h, key);
134135 dctx->s[0] = get_unaligned_le32(&key[16]);
....@@ -157,8 +158,6 @@
157158 dctx->s[1] = get_unaligned_le32(&inp[4]);
158159 dctx->s[2] = get_unaligned_le32(&inp[8]);
159160 dctx->s[3] = get_unaligned_le32(&inp[12]);
160
- inp += POLY1305_BLOCK_SIZE;
161
- len -= POLY1305_BLOCK_SIZE;
162161 acc += POLY1305_BLOCK_SIZE;
163162 dctx->sset = true;
164163 }
....@@ -260,11 +259,10 @@
260259
261260 static int __init poly1305_simd_mod_init(void)
262261 {
263
- if (IS_ENABLED(CONFIG_AS_AVX) && boot_cpu_has(X86_FEATURE_AVX) &&
262
+ if (boot_cpu_has(X86_FEATURE_AVX) &&
264263 cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL))
265264 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) &&
268266 cpu_has_xfeatures(XFEATURE_MASK_SSE | XFEATURE_MASK_YMM, NULL))
269267 static_branch_enable(&poly1305_use_avx2);
270268 if (IS_ENABLED(CONFIG_AS_AVX512) && boot_cpu_has(X86_FEATURE_AVX) &&