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: arm64/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 -53
+20 -53
arch/arm64/crypto/polyval-ce-glue.c
··· 15 15 * ARMv8 Crypto Extensions instructions to implement the finite field operations. 16 16 */ 17 17 18 - #include <crypto/algapi.h> 18 + #include <asm/neon.h> 19 19 #include <crypto/internal/hash.h> 20 - #include <crypto/internal/simd.h> 21 20 #include <crypto/polyval.h> 22 - #include <linux/crypto.h> 23 - #include <linux/init.h> 21 + #include <crypto/utils.h> 22 + #include <linux/cpufeature.h> 23 + #include <linux/errno.h> 24 24 #include <linux/kernel.h> 25 25 #include <linux/module.h> 26 - #include <linux/cpufeature.h> 27 - #include <asm/neon.h> 28 - #include <asm/simd.h> 26 + #include <linux/string.h> 29 27 30 28 #define NUM_KEY_POWERS 8 31 29 ··· 36 38 37 39 struct polyval_desc_ctx { 38 40 u8 buffer[POLYVAL_BLOCK_SIZE]; 39 - u32 bytes; 40 41 }; 41 42 42 43 asmlinkage void pmull_polyval_update(const struct polyval_tfm_ctx *keys, ··· 45 48 static void internal_polyval_update(const struct polyval_tfm_ctx *keys, 46 49 const u8 *in, size_t nblocks, u8 *accumulator) 47 50 { 48 - if (likely(crypto_simd_usable())) { 49 - kernel_neon_begin(); 50 - pmull_polyval_update(keys, in, nblocks, accumulator); 51 - kernel_neon_end(); 52 - } else { 53 - polyval_update_non4k(keys->key_powers[NUM_KEY_POWERS-1], in, 54 - nblocks, accumulator); 55 - } 51 + kernel_neon_begin(); 52 + pmull_polyval_update(keys, in, nblocks, accumulator); 53 + kernel_neon_end(); 56 54 } 57 55 58 56 static void internal_polyval_mul(u8 *op1, const u8 *op2) 59 57 { 60 - if (likely(crypto_simd_usable())) { 61 - kernel_neon_begin(); 62 - pmull_polyval_mul(op1, op2); 63 - kernel_neon_end(); 64 - } else { 65 - polyval_mul_non4k(op1, op2); 66 - } 58 + kernel_neon_begin(); 59 + pmull_polyval_mul(op1, op2); 60 + kernel_neon_end(); 67 61 } 68 62 69 63 static int polyval_arm64_setkey(struct crypto_shash *tfm, ··· 91 103 { 92 104 struct polyval_desc_ctx *dctx = shash_desc_ctx(desc); 93 105 const struct polyval_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); 94 - u8 *pos; 95 106 unsigned int nblocks; 96 - unsigned int n; 97 107 98 - if (dctx->bytes) { 99 - n = min(srclen, dctx->bytes); 100 - pos = dctx->buffer + POLYVAL_BLOCK_SIZE - dctx->bytes; 101 - 102 - dctx->bytes -= n; 103 - srclen -= n; 104 - 105 - while (n--) 106 - *pos++ ^= *src++; 107 - 108 - if (!dctx->bytes) 109 - internal_polyval_mul(dctx->buffer, 110 - tctx->key_powers[NUM_KEY_POWERS-1]); 111 - } 112 - 113 - while (srclen >= POLYVAL_BLOCK_SIZE) { 108 + do { 114 109 /* allow rescheduling every 4K bytes */ 115 110 nblocks = min(srclen, 4096U) / POLYVAL_BLOCK_SIZE; 116 111 internal_polyval_update(tctx, src, nblocks, dctx->buffer); 117 112 srclen -= nblocks * POLYVAL_BLOCK_SIZE; 118 113 src += nblocks * POLYVAL_BLOCK_SIZE; 119 - } 114 + } while (srclen >= POLYVAL_BLOCK_SIZE); 120 115 121 - if (srclen) { 122 - dctx->bytes = POLYVAL_BLOCK_SIZE - srclen; 123 - pos = dctx->buffer; 124 - while (srclen--) 125 - *pos++ ^= *src++; 126 - } 127 - 128 - return 0; 116 + return srclen; 129 117 } 130 118 131 - static int polyval_arm64_final(struct shash_desc *desc, u8 *dst) 119 + static int polyval_arm64_finup(struct shash_desc *desc, const u8 *src, 120 + unsigned int len, u8 *dst) 132 121 { 133 122 struct polyval_desc_ctx *dctx = shash_desc_ctx(desc); 134 123 const struct polyval_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); 135 124 136 - if (dctx->bytes) { 125 + if (len) { 126 + crypto_xor(dctx->buffer, src, len); 137 127 internal_polyval_mul(dctx->buffer, 138 128 tctx->key_powers[NUM_KEY_POWERS-1]); 139 129 } ··· 125 159 .digestsize = POLYVAL_DIGEST_SIZE, 126 160 .init = polyval_arm64_init, 127 161 .update = polyval_arm64_update, 128 - .final = polyval_arm64_final, 162 + .finup = polyval_arm64_finup, 129 163 .setkey = polyval_arm64_setkey, 130 164 .descsize = sizeof(struct polyval_desc_ctx), 131 165 .base = { 132 166 .cra_name = "polyval", 133 167 .cra_driver_name = "polyval-ce", 134 168 .cra_priority = 200, 169 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY, 135 170 .cra_blocksize = POLYVAL_BLOCK_SIZE, 136 171 .cra_ctxsize = sizeof(struct polyval_tfm_ctx), 137 172 .cra_module = THIS_MODULE,