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/polyval - 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>

+20 -52
+20 -52
arch/x86/crypto/polyval-clmulni_glue.c
··· 16 16 * operations. 17 17 */ 18 18 19 - #include <crypto/algapi.h> 19 + #include <asm/cpu_device_id.h> 20 + #include <asm/fpu/api.h> 20 21 #include <crypto/internal/hash.h> 21 - #include <crypto/internal/simd.h> 22 22 #include <crypto/polyval.h> 23 - #include <linux/crypto.h> 24 - #include <linux/init.h> 23 + #include <crypto/utils.h> 24 + #include <linux/errno.h> 25 25 #include <linux/kernel.h> 26 26 #include <linux/module.h> 27 - #include <asm/cpu_device_id.h> 28 - #include <asm/simd.h> 27 + #include <linux/string.h> 29 28 30 29 #define POLYVAL_ALIGN 16 31 30 #define POLYVAL_ALIGN_ATTR __aligned(POLYVAL_ALIGN) ··· 41 42 42 43 struct polyval_desc_ctx { 43 44 u8 buffer[POLYVAL_BLOCK_SIZE]; 44 - u32 bytes; 45 45 }; 46 46 47 47 asmlinkage void clmul_polyval_update(const struct polyval_tfm_ctx *keys, ··· 55 57 static void internal_polyval_update(const struct polyval_tfm_ctx *keys, 56 58 const u8 *in, size_t nblocks, u8 *accumulator) 57 59 { 58 - if (likely(crypto_simd_usable())) { 59 - kernel_fpu_begin(); 60 - clmul_polyval_update(keys, in, nblocks, accumulator); 61 - kernel_fpu_end(); 62 - } else { 63 - polyval_update_non4k(keys->key_powers[NUM_KEY_POWERS-1], in, 64 - nblocks, accumulator); 65 - } 60 + kernel_fpu_begin(); 61 + clmul_polyval_update(keys, in, nblocks, accumulator); 62 + kernel_fpu_end(); 66 63 } 67 64 68 65 static void internal_polyval_mul(u8 *op1, const u8 *op2) 69 66 { 70 - if (likely(crypto_simd_usable())) { 71 - kernel_fpu_begin(); 72 - clmul_polyval_mul(op1, op2); 73 - kernel_fpu_end(); 74 - } else { 75 - polyval_mul_non4k(op1, op2); 76 - } 67 + kernel_fpu_begin(); 68 + clmul_polyval_mul(op1, op2); 69 + kernel_fpu_end(); 77 70 } 78 71 79 72 static int polyval_x86_setkey(struct crypto_shash *tfm, ··· 101 112 { 102 113 struct polyval_desc_ctx *dctx = shash_desc_ctx(desc); 103 114 const struct polyval_tfm_ctx *tctx = polyval_tfm_ctx(desc->tfm); 104 - u8 *pos; 105 115 unsigned int nblocks; 106 - unsigned int n; 107 116 108 - if (dctx->bytes) { 109 - n = min(srclen, dctx->bytes); 110 - pos = dctx->buffer + POLYVAL_BLOCK_SIZE - dctx->bytes; 111 - 112 - dctx->bytes -= n; 113 - srclen -= n; 114 - 115 - while (n--) 116 - *pos++ ^= *src++; 117 - 118 - if (!dctx->bytes) 119 - internal_polyval_mul(dctx->buffer, 120 - tctx->key_powers[NUM_KEY_POWERS-1]); 121 - } 122 - 123 - while (srclen >= POLYVAL_BLOCK_SIZE) { 117 + do { 124 118 /* Allow rescheduling every 4K bytes. */ 125 119 nblocks = min(srclen, 4096U) / POLYVAL_BLOCK_SIZE; 126 120 internal_polyval_update(tctx, src, nblocks, dctx->buffer); 127 121 srclen -= nblocks * POLYVAL_BLOCK_SIZE; 128 122 src += nblocks * POLYVAL_BLOCK_SIZE; 129 - } 123 + } while (srclen >= POLYVAL_BLOCK_SIZE); 130 124 131 - if (srclen) { 132 - dctx->bytes = POLYVAL_BLOCK_SIZE - srclen; 133 - pos = dctx->buffer; 134 - while (srclen--) 135 - *pos++ ^= *src++; 136 - } 137 - 138 - return 0; 125 + return srclen; 139 126 } 140 127 141 - static int polyval_x86_final(struct shash_desc *desc, u8 *dst) 128 + static int polyval_x86_finup(struct shash_desc *desc, const u8 *src, 129 + unsigned int len, u8 *dst) 142 130 { 143 131 struct polyval_desc_ctx *dctx = shash_desc_ctx(desc); 144 132 const struct polyval_tfm_ctx *tctx = polyval_tfm_ctx(desc->tfm); 145 133 146 - if (dctx->bytes) { 134 + if (len) { 135 + crypto_xor(dctx->buffer, src, len); 147 136 internal_polyval_mul(dctx->buffer, 148 137 tctx->key_powers[NUM_KEY_POWERS-1]); 149 138 } ··· 135 168 .digestsize = POLYVAL_DIGEST_SIZE, 136 169 .init = polyval_x86_init, 137 170 .update = polyval_x86_update, 138 - .final = polyval_x86_final, 171 + .finup = polyval_x86_finup, 139 172 .setkey = polyval_x86_setkey, 140 173 .descsize = sizeof(struct polyval_desc_ctx), 141 174 .base = { 142 175 .cra_name = "polyval", 143 176 .cra_driver_name = "polyval-clmulni", 144 177 .cra_priority = 200, 178 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY, 145 179 .cra_blocksize = POLYVAL_BLOCK_SIZE, 146 180 .cra_ctxsize = POLYVAL_CTX_SIZE, 147 181 .cra_module = THIS_MODULE,