Commit 2fe55987 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Herbert Xu

crypto: arm64/chacha - use combined SIMD/ALU routine for more speed

To some degree, most known AArch64 micro-architectures appear to be
able to issue ALU instructions in parellel to SIMD instructions
without affecting the SIMD throughput. This means we can use the ALU
to process a fifth ChaCha block while the SIMD is processing four
blocks in parallel.
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent f2ca1cbd
This diff is collapsed.
...@@ -38,22 +38,23 @@ asmlinkage void hchacha_block_neon(const u32 *state, u32 *out, int nrounds); ...@@ -38,22 +38,23 @@ asmlinkage void hchacha_block_neon(const u32 *state, u32 *out, int nrounds);
static void chacha_doneon(u32 *state, u8 *dst, const u8 *src, static void chacha_doneon(u32 *state, u8 *dst, const u8 *src,
int bytes, int nrounds) int bytes, int nrounds)
{ {
u8 buf[CHACHA_BLOCK_SIZE];
if (bytes < CHACHA_BLOCK_SIZE) {
memcpy(buf, src, bytes);
chacha_block_xor_neon(state, buf, buf, nrounds);
memcpy(dst, buf, bytes);
return;
}
while (bytes > 0) { while (bytes > 0) {
chacha_4block_xor_neon(state, dst, src, nrounds, int l = min(bytes, CHACHA_BLOCK_SIZE * 5);
min(bytes, CHACHA_BLOCK_SIZE * 4));
bytes -= CHACHA_BLOCK_SIZE * 4; if (l <= CHACHA_BLOCK_SIZE) {
src += CHACHA_BLOCK_SIZE * 4; u8 buf[CHACHA_BLOCK_SIZE];
dst += CHACHA_BLOCK_SIZE * 4;
state[12] += 4; memcpy(buf, src, l);
chacha_block_xor_neon(state, buf, buf, nrounds);
memcpy(dst, buf, l);
state[12] += 1;
break;
}
chacha_4block_xor_neon(state, dst, src, nrounds, l);
bytes -= CHACHA_BLOCK_SIZE * 5;
src += CHACHA_BLOCK_SIZE * 5;
dst += CHACHA_BLOCK_SIZE * 5;
state[12] += 5;
} }
} }
...@@ -72,7 +73,7 @@ static int chacha_neon_stream_xor(struct skcipher_request *req, ...@@ -72,7 +73,7 @@ static int chacha_neon_stream_xor(struct skcipher_request *req,
unsigned int nbytes = walk.nbytes; unsigned int nbytes = walk.nbytes;
if (nbytes < walk.total) if (nbytes < walk.total)
nbytes = round_down(nbytes, walk.stride); nbytes = rounddown(nbytes, walk.stride);
kernel_neon_begin(); kernel_neon_begin();
chacha_doneon(state, walk.dst.virt.addr, walk.src.virt.addr, chacha_doneon(state, walk.dst.virt.addr, walk.src.virt.addr,
...@@ -131,7 +132,7 @@ static struct skcipher_alg algs[] = { ...@@ -131,7 +132,7 @@ static struct skcipher_alg algs[] = {
.max_keysize = CHACHA_KEY_SIZE, .max_keysize = CHACHA_KEY_SIZE,
.ivsize = CHACHA_IV_SIZE, .ivsize = CHACHA_IV_SIZE,
.chunksize = CHACHA_BLOCK_SIZE, .chunksize = CHACHA_BLOCK_SIZE,
.walksize = 4 * CHACHA_BLOCK_SIZE, .walksize = 5 * CHACHA_BLOCK_SIZE,
.setkey = crypto_chacha20_setkey, .setkey = crypto_chacha20_setkey,
.encrypt = chacha_neon, .encrypt = chacha_neon,
.decrypt = chacha_neon, .decrypt = chacha_neon,
...@@ -147,7 +148,7 @@ static struct skcipher_alg algs[] = { ...@@ -147,7 +148,7 @@ static struct skcipher_alg algs[] = {
.max_keysize = CHACHA_KEY_SIZE, .max_keysize = CHACHA_KEY_SIZE,
.ivsize = XCHACHA_IV_SIZE, .ivsize = XCHACHA_IV_SIZE,
.chunksize = CHACHA_BLOCK_SIZE, .chunksize = CHACHA_BLOCK_SIZE,
.walksize = 4 * CHACHA_BLOCK_SIZE, .walksize = 5 * CHACHA_BLOCK_SIZE,
.setkey = crypto_chacha20_setkey, .setkey = crypto_chacha20_setkey,
.encrypt = xchacha_neon, .encrypt = xchacha_neon,
.decrypt = xchacha_neon, .decrypt = xchacha_neon,
...@@ -163,7 +164,7 @@ static struct skcipher_alg algs[] = { ...@@ -163,7 +164,7 @@ static struct skcipher_alg algs[] = {
.max_keysize = CHACHA_KEY_SIZE, .max_keysize = CHACHA_KEY_SIZE,
.ivsize = XCHACHA_IV_SIZE, .ivsize = XCHACHA_IV_SIZE,
.chunksize = CHACHA_BLOCK_SIZE, .chunksize = CHACHA_BLOCK_SIZE,
.walksize = 4 * CHACHA_BLOCK_SIZE, .walksize = 5 * CHACHA_BLOCK_SIZE,
.setkey = crypto_chacha12_setkey, .setkey = crypto_chacha12_setkey,
.encrypt = xchacha_neon, .encrypt = xchacha_neon,
.decrypt = xchacha_neon, .decrypt = xchacha_neon,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment