Use mbedtls_xor_no_simd from cmac and cbc
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
03bb526c24
commit
a0b166e11e
2 changed files with 7 additions and 21 deletions
|
@ -1040,23 +1040,6 @@ int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx,
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
||||||
|
|
||||||
#if defined(__ARM_NEON) && defined(__aarch64__)
|
|
||||||
/* Avoid using the NEON implementation of mbedtls_xor. Because of the dependency on
|
|
||||||
* the result for the next block in CBC, and the cost of transferring that data from
|
|
||||||
* NEON registers, it is faster to use the following on aarch64.
|
|
||||||
* For 32-bit arm, NEON should be faster. */
|
|
||||||
#define CBC_XOR_16(r, a, b) do { \
|
|
||||||
mbedtls_put_unaligned_uint64(r, \
|
|
||||||
mbedtls_get_unaligned_uint64(a) ^ \
|
|
||||||
mbedtls_get_unaligned_uint64(b)); \
|
|
||||||
mbedtls_put_unaligned_uint64(r + 8, \
|
|
||||||
mbedtls_get_unaligned_uint64(a + 8) ^ \
|
|
||||||
mbedtls_get_unaligned_uint64(b + 8)); \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define CBC_XOR_16(r, a, b) mbedtls_xor(r, a, b, 16)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AES-CBC buffer encryption/decryption
|
* AES-CBC buffer encryption/decryption
|
||||||
*/
|
*/
|
||||||
|
@ -1099,7 +1082,10 @@ int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx,
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
CBC_XOR_16(output, output, iv);
|
/* Avoid using the NEON implementation of mbedtls_xor. Because of the dependency on
|
||||||
|
* the result for the next block in CBC, and the cost of transferring that data from
|
||||||
|
* NEON registers, NEON is slower on aarch64. */
|
||||||
|
mbedtls_xor_no_simd(output, output, iv, 16);
|
||||||
|
|
||||||
memcpy(iv, temp, 16);
|
memcpy(iv, temp, 16);
|
||||||
|
|
||||||
|
@ -1109,7 +1095,7 @@ int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
CBC_XOR_16(output, input, ivp);
|
mbedtls_xor_no_simd(output, input, ivp, 16);
|
||||||
|
|
||||||
ret = mbedtls_aes_crypt_ecb(ctx, mode, output, output);
|
ret = mbedtls_aes_crypt_ecb(ctx, mode, output, output);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
|
|
@ -237,7 +237,7 @@ int mbedtls_cipher_cmac_update(mbedtls_cipher_context_t *ctx,
|
||||||
input,
|
input,
|
||||||
block_size - cmac_ctx->unprocessed_len);
|
block_size - cmac_ctx->unprocessed_len);
|
||||||
|
|
||||||
mbedtls_xor(state, cmac_ctx->unprocessed_block, state, block_size);
|
mbedtls_xor_no_simd(state, cmac_ctx->unprocessed_block, state, block_size);
|
||||||
|
|
||||||
if ((ret = mbedtls_cipher_update(ctx, state, block_size, state,
|
if ((ret = mbedtls_cipher_update(ctx, state, block_size, state,
|
||||||
&olen)) != 0) {
|
&olen)) != 0) {
|
||||||
|
@ -255,7 +255,7 @@ int mbedtls_cipher_cmac_update(mbedtls_cipher_context_t *ctx,
|
||||||
/* Iterate across the input data in block sized chunks, excluding any
|
/* Iterate across the input data in block sized chunks, excluding any
|
||||||
* final partial or complete block */
|
* final partial or complete block */
|
||||||
for (j = 1; j < n; j++) {
|
for (j = 1; j < n; j++) {
|
||||||
mbedtls_xor(state, input, state, block_size);
|
mbedtls_xor_no_simd(state, input, state, block_size);
|
||||||
|
|
||||||
if ((ret = mbedtls_cipher_update(ctx, state, block_size, state,
|
if ((ret = mbedtls_cipher_update(ctx, state, block_size, state,
|
||||||
&olen)) != 0) {
|
&olen)) != 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue