Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: x86/sm3 - Use API partial block handling

Use the Crypto API partial block handling.

Also remove the unnecessary SIMD fallback path.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+10 -44
+10 -44
arch/x86/crypto/sm3_avx_glue.c
··· 10 10 11 11 #include <crypto/internal/hash.h> 12 12 #include <crypto/internal/simd.h> 13 - #include <linux/init.h> 14 - #include <linux/module.h> 15 - #include <linux/types.h> 16 13 #include <crypto/sm3.h> 17 14 #include <crypto/sm3_base.h> 18 - #include <asm/simd.h> 15 + #include <linux/cpufeature.h> 16 + #include <linux/kernel.h> 17 + #include <linux/module.h> 19 18 20 19 asmlinkage void sm3_transform_avx(struct sm3_state *state, 21 20 const u8 *data, int nblocks); ··· 22 23 static int sm3_avx_update(struct shash_desc *desc, const u8 *data, 23 24 unsigned int len) 24 25 { 25 - struct sm3_state *sctx = shash_desc_ctx(desc); 26 - 27 - if (!crypto_simd_usable() || 28 - (sctx->count % SM3_BLOCK_SIZE) + len < SM3_BLOCK_SIZE) { 29 - sm3_update(sctx, data, len); 30 - return 0; 31 - } 26 + int remain; 32 27 33 28 /* 34 29 * Make sure struct sm3_state begins directly with the SM3 ··· 31 38 BUILD_BUG_ON(offsetof(struct sm3_state, state) != 0); 32 39 33 40 kernel_fpu_begin(); 34 - sm3_base_do_update(desc, data, len, sm3_transform_avx); 41 + remain = sm3_base_do_update_blocks(desc, data, len, sm3_transform_avx); 35 42 kernel_fpu_end(); 36 - 37 - return 0; 43 + return remain; 38 44 } 39 45 40 46 static int sm3_avx_finup(struct shash_desc *desc, const u8 *data, 41 47 unsigned int len, u8 *out) 42 48 { 43 - if (!crypto_simd_usable()) { 44 - struct sm3_state *sctx = shash_desc_ctx(desc); 45 - 46 - if (len) 47 - sm3_update(sctx, data, len); 48 - 49 - sm3_final(sctx, out); 50 - return 0; 51 - } 52 - 53 49 kernel_fpu_begin(); 54 - if (len) 55 - sm3_base_do_update(desc, data, len, sm3_transform_avx); 56 - sm3_base_do_finalize(desc, sm3_transform_avx); 50 + sm3_base_do_finup(desc, data, len, sm3_transform_avx); 57 51 kernel_fpu_end(); 58 - 59 - return sm3_base_finish(desc, out); 60 - } 61 - 62 - static int sm3_avx_final(struct shash_desc *desc, u8 *out) 63 - { 64 - if (!crypto_simd_usable()) { 65 - sm3_final(shash_desc_ctx(desc), out); 66 - return 0; 67 - } 68 - 69 - kernel_fpu_begin(); 70 - sm3_base_do_finalize(desc, sm3_transform_avx); 71 - kernel_fpu_end(); 72 - 73 52 return sm3_base_finish(desc, out); 74 53 } 75 54 ··· 49 84 .digestsize = SM3_DIGEST_SIZE, 50 85 .init = sm3_base_init, 51 86 .update = sm3_avx_update, 52 - .final = sm3_avx_final, 53 87 .finup = sm3_avx_finup, 54 - .descsize = sizeof(struct sm3_state), 88 + .descsize = SM3_STATE_SIZE, 55 89 .base = { 56 90 .cra_name = "sm3", 57 91 .cra_driver_name = "sm3-avx", 58 92 .cra_priority = 300, 93 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY | 94 + CRYPTO_AHASH_ALG_FINUP_MAX, 59 95 .cra_blocksize = SM3_BLOCK_SIZE, 60 96 .cra_module = THIS_MODULE, 61 97 }