mirror of
https://github.com/torvalds/linux.git
synced 2026-05-29 17:43:52 +02:00
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>
This commit is contained in:
parent
2cfe41630a
commit
d5a582a782
|
|
@ -15,17 +15,15 @@
|
|||
* ARMv8 Crypto Extensions instructions to implement the finite field operations.
|
||||
*/
|
||||
|
||||
#include <crypto/algapi.h>
|
||||
#include <asm/neon.h>
|
||||
#include <crypto/internal/hash.h>
|
||||
#include <crypto/internal/simd.h>
|
||||
#include <crypto/polyval.h>
|
||||
#include <linux/crypto.h>
|
||||
#include <linux/init.h>
|
||||
#include <crypto/utils.h>
|
||||
#include <linux/cpufeature.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/cpufeature.h>
|
||||
#include <asm/neon.h>
|
||||
#include <asm/simd.h>
|
||||
#include <linux/string.h>
|
||||
|
||||
#define NUM_KEY_POWERS 8
|
||||
|
||||
|
|
@ -38,7 +36,6 @@ struct polyval_tfm_ctx {
|
|||
|
||||
struct polyval_desc_ctx {
|
||||
u8 buffer[POLYVAL_BLOCK_SIZE];
|
||||
u32 bytes;
|
||||
};
|
||||
|
||||
asmlinkage void pmull_polyval_update(const struct polyval_tfm_ctx *keys,
|
||||
|
|
@ -48,25 +45,16 @@ asmlinkage void pmull_polyval_mul(u8 *op1, const u8 *op2);
|
|||
static void internal_polyval_update(const struct polyval_tfm_ctx *keys,
|
||||
const u8 *in, size_t nblocks, u8 *accumulator)
|
||||
{
|
||||
if (likely(crypto_simd_usable())) {
|
||||
kernel_neon_begin();
|
||||
pmull_polyval_update(keys, in, nblocks, accumulator);
|
||||
kernel_neon_end();
|
||||
} else {
|
||||
polyval_update_non4k(keys->key_powers[NUM_KEY_POWERS-1], in,
|
||||
nblocks, accumulator);
|
||||
}
|
||||
kernel_neon_begin();
|
||||
pmull_polyval_update(keys, in, nblocks, accumulator);
|
||||
kernel_neon_end();
|
||||
}
|
||||
|
||||
static void internal_polyval_mul(u8 *op1, const u8 *op2)
|
||||
{
|
||||
if (likely(crypto_simd_usable())) {
|
||||
kernel_neon_begin();
|
||||
pmull_polyval_mul(op1, op2);
|
||||
kernel_neon_end();
|
||||
} else {
|
||||
polyval_mul_non4k(op1, op2);
|
||||
}
|
||||
kernel_neon_begin();
|
||||
pmull_polyval_mul(op1, op2);
|
||||
kernel_neon_end();
|
||||
}
|
||||
|
||||
static int polyval_arm64_setkey(struct crypto_shash *tfm,
|
||||
|
|
@ -103,49 +91,27 @@ static int polyval_arm64_update(struct shash_desc *desc,
|
|||
{
|
||||
struct polyval_desc_ctx *dctx = shash_desc_ctx(desc);
|
||||
const struct polyval_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
|
||||
u8 *pos;
|
||||
unsigned int nblocks;
|
||||
unsigned int n;
|
||||
|
||||
if (dctx->bytes) {
|
||||
n = min(srclen, dctx->bytes);
|
||||
pos = dctx->buffer + POLYVAL_BLOCK_SIZE - dctx->bytes;
|
||||
|
||||
dctx->bytes -= n;
|
||||
srclen -= n;
|
||||
|
||||
while (n--)
|
||||
*pos++ ^= *src++;
|
||||
|
||||
if (!dctx->bytes)
|
||||
internal_polyval_mul(dctx->buffer,
|
||||
tctx->key_powers[NUM_KEY_POWERS-1]);
|
||||
}
|
||||
|
||||
while (srclen >= POLYVAL_BLOCK_SIZE) {
|
||||
do {
|
||||
/* allow rescheduling every 4K bytes */
|
||||
nblocks = min(srclen, 4096U) / POLYVAL_BLOCK_SIZE;
|
||||
internal_polyval_update(tctx, src, nblocks, dctx->buffer);
|
||||
srclen -= nblocks * POLYVAL_BLOCK_SIZE;
|
||||
src += nblocks * POLYVAL_BLOCK_SIZE;
|
||||
}
|
||||
} while (srclen >= POLYVAL_BLOCK_SIZE);
|
||||
|
||||
if (srclen) {
|
||||
dctx->bytes = POLYVAL_BLOCK_SIZE - srclen;
|
||||
pos = dctx->buffer;
|
||||
while (srclen--)
|
||||
*pos++ ^= *src++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return srclen;
|
||||
}
|
||||
|
||||
static int polyval_arm64_final(struct shash_desc *desc, u8 *dst)
|
||||
static int polyval_arm64_finup(struct shash_desc *desc, const u8 *src,
|
||||
unsigned int len, u8 *dst)
|
||||
{
|
||||
struct polyval_desc_ctx *dctx = shash_desc_ctx(desc);
|
||||
const struct polyval_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm);
|
||||
|
||||
if (dctx->bytes) {
|
||||
if (len) {
|
||||
crypto_xor(dctx->buffer, src, len);
|
||||
internal_polyval_mul(dctx->buffer,
|
||||
tctx->key_powers[NUM_KEY_POWERS-1]);
|
||||
}
|
||||
|
|
@ -159,13 +125,14 @@ static struct shash_alg polyval_alg = {
|
|||
.digestsize = POLYVAL_DIGEST_SIZE,
|
||||
.init = polyval_arm64_init,
|
||||
.update = polyval_arm64_update,
|
||||
.final = polyval_arm64_final,
|
||||
.finup = polyval_arm64_finup,
|
||||
.setkey = polyval_arm64_setkey,
|
||||
.descsize = sizeof(struct polyval_desc_ctx),
|
||||
.base = {
|
||||
.cra_name = "polyval",
|
||||
.cra_driver_name = "polyval-ce",
|
||||
.cra_priority = 200,
|
||||
.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY,
|
||||
.cra_blocksize = POLYVAL_BLOCK_SIZE,
|
||||
.cra_ctxsize = sizeof(struct polyval_tfm_ctx),
|
||||
.cra_module = THIS_MODULE,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user