Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45fe93df authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Herbert Xu
Browse files

crypto: algapi - make crypto_xor() take separate dst and src arguments



There are quite a number of occurrences in the kernel of the pattern

  if (dst != src)
          memcpy(dst, src, walk.total % AES_BLOCK_SIZE);
  crypto_xor(dst, final, walk.total % AES_BLOCK_SIZE);

or

  crypto_xor(keystream, src, nbytes);
  memcpy(dst, keystream, nbytes);

where crypto_xor() is preceded or followed by a memcpy() invocation
that is only there because crypto_xor() uses its output parameter as
one of the inputs. To avoid having to add new instances of this pattern
in the arm64 code, which will be refactored to implement non-SIMD
fallbacks, add an alternative implementation called crypto_xor_cpy(),
taking separate input and output arguments. This removes the need for
the separate memcpy().

Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent a7c391f0
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -285,9 +285,7 @@ static int ctr_encrypt(struct skcipher_request *req)

		ce_aes_ctr_encrypt(tail, NULL, (u8 *)ctx->key_enc,
				   num_rounds(ctx), blocks, walk.iv);
		if (tdst != tsrc)
			memcpy(tdst, tsrc, nbytes);
		crypto_xor(tdst, tail, nbytes);
		crypto_xor_cpy(tdst, tsrc, tail, nbytes);
		err = skcipher_walk_done(&walk, 0);
	}
	kernel_neon_end();
+2 −3
Original line number Diff line number Diff line
@@ -221,9 +221,8 @@ static int ctr_encrypt(struct skcipher_request *req)
			u8 *dst = walk.dst.virt.addr + blocks * AES_BLOCK_SIZE;
			u8 *src = walk.src.virt.addr + blocks * AES_BLOCK_SIZE;

			if (dst != src)
				memcpy(dst, src, walk.total % AES_BLOCK_SIZE);
			crypto_xor(dst, final, walk.total % AES_BLOCK_SIZE);
			crypto_xor_cpy(dst, src, final,
				       walk.total % AES_BLOCK_SIZE);

			err = skcipher_walk_done(&walk, 0);
			break;
+1 −3
Original line number Diff line number Diff line
@@ -241,9 +241,7 @@ static int ctr_encrypt(struct skcipher_request *req)

		aes_ctr_encrypt(tail, NULL, (u8 *)ctx->key_enc, rounds,
				blocks, walk.iv, first);
		if (tdst != tsrc)
			memcpy(tdst, tsrc, nbytes);
		crypto_xor(tdst, tail, nbytes);
		crypto_xor_cpy(tdst, tsrc, tail, nbytes);
		err = skcipher_walk_done(&walk, 0);
	}
	kernel_neon_end();
+2 −3
Original line number Diff line number Diff line
@@ -224,9 +224,8 @@ static int ctr_encrypt(struct skcipher_request *req)
			u8 *dst = walk.dst.virt.addr + blocks * AES_BLOCK_SIZE;
			u8 *src = walk.src.virt.addr + blocks * AES_BLOCK_SIZE;

			if (dst != src)
				memcpy(dst, src, walk.total % AES_BLOCK_SIZE);
			crypto_xor(dst, final, walk.total % AES_BLOCK_SIZE);
			crypto_xor_cpy(dst, src, final,
				       walk.total % AES_BLOCK_SIZE);

			err = skcipher_walk_done(&walk, 0);
			break;
+1 −2
Original line number Diff line number Diff line
@@ -344,8 +344,7 @@ static void ctr_crypt_final(struct crypto_sparc64_aes_ctx *ctx,

	ctx->ops->ecb_encrypt(&ctx->key[0], (const u64 *)ctrblk,
			      keystream, AES_BLOCK_SIZE);
	crypto_xor((u8 *) keystream, src, nbytes);
	memcpy(dst, keystream, nbytes);
	crypto_xor_cpy(dst, (u8 *) keystream, src, nbytes);
	crypto_inc(ctrblk, AES_BLOCK_SIZE);
}

Loading