.. | .. |
---|
4 | 4 | */ |
---|
5 | 5 | |
---|
6 | 6 | #include <crypto/internal/blake2s.h> |
---|
7 | | -#include <crypto/internal/hash.h> |
---|
| 7 | +#include <crypto/internal/simd.h> |
---|
8 | 8 | |
---|
9 | 9 | #include <linux/types.h> |
---|
10 | 10 | #include <linux/jump_label.h> |
---|
11 | 11 | #include <linux/kernel.h> |
---|
12 | 12 | #include <linux/module.h> |
---|
| 13 | +#include <linux/sizes.h> |
---|
13 | 14 | |
---|
14 | 15 | #include <asm/cpufeature.h> |
---|
15 | 16 | #include <asm/fpu/api.h> |
---|
.. | .. |
---|
26 | 27 | static __ro_after_init DEFINE_STATIC_KEY_FALSE(blake2s_use_ssse3); |
---|
27 | 28 | static __ro_after_init DEFINE_STATIC_KEY_FALSE(blake2s_use_avx512); |
---|
28 | 29 | |
---|
29 | | -void blake2s_compress_arch(struct blake2s_state *state, |
---|
30 | | - const u8 *block, size_t nblocks, |
---|
31 | | - const u32 inc) |
---|
| 30 | +void blake2s_compress(struct blake2s_state *state, const u8 *block, |
---|
| 31 | + size_t nblocks, const u32 inc) |
---|
32 | 32 | { |
---|
33 | 33 | /* SIMD disables preemption, so relax after processing each page. */ |
---|
34 | 34 | BUILD_BUG_ON(SZ_4K / BLAKE2S_BLOCK_SIZE < 8); |
---|
35 | 35 | |
---|
36 | | - if (!static_branch_likely(&blake2s_use_ssse3) || !may_use_simd()) { |
---|
| 36 | + if (!static_branch_likely(&blake2s_use_ssse3) || !crypto_simd_usable()) { |
---|
37 | 37 | blake2s_compress_generic(state, block, nblocks, inc); |
---|
38 | 38 | return; |
---|
39 | 39 | } |
---|
.. | .. |
---|
54 | 54 | block += blocks * BLAKE2S_BLOCK_SIZE; |
---|
55 | 55 | } while (nblocks); |
---|
56 | 56 | } |
---|
57 | | -EXPORT_SYMBOL(blake2s_compress_arch); |
---|
58 | | - |
---|
59 | | -static int crypto_blake2s_update_x86(struct shash_desc *desc, |
---|
60 | | - const u8 *in, unsigned int inlen) |
---|
61 | | -{ |
---|
62 | | - return crypto_blake2s_update(desc, in, inlen, blake2s_compress_arch); |
---|
63 | | -} |
---|
64 | | - |
---|
65 | | -static int crypto_blake2s_final_x86(struct shash_desc *desc, u8 *out) |
---|
66 | | -{ |
---|
67 | | - return crypto_blake2s_final(desc, out, blake2s_compress_arch); |
---|
68 | | -} |
---|
69 | | - |
---|
70 | | -#define BLAKE2S_ALG(name, driver_name, digest_size) \ |
---|
71 | | - { \ |
---|
72 | | - .base.cra_name = name, \ |
---|
73 | | - .base.cra_driver_name = driver_name, \ |
---|
74 | | - .base.cra_priority = 200, \ |
---|
75 | | - .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, \ |
---|
76 | | - .base.cra_blocksize = BLAKE2S_BLOCK_SIZE, \ |
---|
77 | | - .base.cra_ctxsize = sizeof(struct blake2s_tfm_ctx), \ |
---|
78 | | - .base.cra_module = THIS_MODULE, \ |
---|
79 | | - .digestsize = digest_size, \ |
---|
80 | | - .setkey = crypto_blake2s_setkey, \ |
---|
81 | | - .init = crypto_blake2s_init, \ |
---|
82 | | - .update = crypto_blake2s_update_x86, \ |
---|
83 | | - .final = crypto_blake2s_final_x86, \ |
---|
84 | | - .descsize = sizeof(struct blake2s_state), \ |
---|
85 | | - } |
---|
86 | | - |
---|
87 | | -static struct shash_alg blake2s_algs[] = { |
---|
88 | | - BLAKE2S_ALG("blake2s-128", "blake2s-128-x86", BLAKE2S_128_HASH_SIZE), |
---|
89 | | - BLAKE2S_ALG("blake2s-160", "blake2s-160-x86", BLAKE2S_160_HASH_SIZE), |
---|
90 | | - BLAKE2S_ALG("blake2s-224", "blake2s-224-x86", BLAKE2S_224_HASH_SIZE), |
---|
91 | | - BLAKE2S_ALG("blake2s-256", "blake2s-256-x86", BLAKE2S_256_HASH_SIZE), |
---|
92 | | -}; |
---|
| 57 | +EXPORT_SYMBOL(blake2s_compress); |
---|
93 | 58 | |
---|
94 | 59 | static int __init blake2s_mod_init(void) |
---|
95 | 60 | { |
---|
96 | | - if (!boot_cpu_has(X86_FEATURE_SSSE3)) |
---|
97 | | - return 0; |
---|
98 | | - |
---|
99 | | - static_branch_enable(&blake2s_use_ssse3); |
---|
| 61 | + if (boot_cpu_has(X86_FEATURE_SSSE3)) |
---|
| 62 | + static_branch_enable(&blake2s_use_ssse3); |
---|
100 | 63 | |
---|
101 | 64 | if (IS_ENABLED(CONFIG_AS_AVX512) && |
---|
102 | 65 | boot_cpu_has(X86_FEATURE_AVX) && |
---|
.. | .. |
---|
107 | 70 | XFEATURE_MASK_AVX512, NULL)) |
---|
108 | 71 | static_branch_enable(&blake2s_use_avx512); |
---|
109 | 72 | |
---|
110 | | - return IS_REACHABLE(CONFIG_CRYPTO_HASH) ? |
---|
111 | | - crypto_register_shashes(blake2s_algs, |
---|
112 | | - ARRAY_SIZE(blake2s_algs)) : 0; |
---|
113 | | -} |
---|
114 | | - |
---|
115 | | -static void __exit blake2s_mod_exit(void) |
---|
116 | | -{ |
---|
117 | | - if (IS_REACHABLE(CONFIG_CRYPTO_HASH) && boot_cpu_has(X86_FEATURE_SSSE3)) |
---|
118 | | - crypto_unregister_shashes(blake2s_algs, ARRAY_SIZE(blake2s_algs)); |
---|
| 73 | + return 0; |
---|
119 | 74 | } |
---|
120 | 75 | |
---|
121 | 76 | module_init(blake2s_mod_init); |
---|
122 | | -module_exit(blake2s_mod_exit); |
---|
123 | 77 | |
---|
124 | | -MODULE_ALIAS_CRYPTO("blake2s-128"); |
---|
125 | | -MODULE_ALIAS_CRYPTO("blake2s-128-x86"); |
---|
126 | | -MODULE_ALIAS_CRYPTO("blake2s-160"); |
---|
127 | | -MODULE_ALIAS_CRYPTO("blake2s-160-x86"); |
---|
128 | | -MODULE_ALIAS_CRYPTO("blake2s-224"); |
---|
129 | | -MODULE_ALIAS_CRYPTO("blake2s-224-x86"); |
---|
130 | | -MODULE_ALIAS_CRYPTO("blake2s-256"); |
---|
131 | | -MODULE_ALIAS_CRYPTO("blake2s-256-x86"); |
---|
132 | 78 | MODULE_LICENSE("GPL v2"); |
---|