1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Improve PBKDF2 with CMAC perf by ~16%

10x perf in cmac_multiply_by_u; 2% uplift in AES-CMAC benchmarks

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
Dave Rodgman
2024-03-05 15:35:59 +00:00
parent 31403a4ca8
commit 7f86d356b1

View File

@ -58,7 +58,7 @@ static int cmac_multiply_by_u(unsigned char *output,
const unsigned char R_128 = 0x87;
const unsigned char R_64 = 0x1B;
unsigned char R_n, mask;
unsigned char overflow = 0x00;
uint32_t overflow = 0x00;
int i;
if (blocksize == MBEDTLS_AES_BLOCK_SIZE) {
@ -69,9 +69,12 @@ static int cmac_multiply_by_u(unsigned char *output,
return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
}
for (i = (int) blocksize - 1; i >= 0; i--) {
output[i] = input[i] << 1 | overflow;
overflow = input[i] >> 7;
for (i = (int) blocksize - 4; i >= 0; i -= 4) {
uint32_t i32 = MBEDTLS_GET_UINT32_BE(&input[i], 0);
uint32_t new_overflow = i32 >> 31;
i32 = (i32 << 1) | overflow;
MBEDTLS_PUT_UINT32_BE(i32, &output[i], 0);
overflow = new_overflow;
}
/* mask = ( input[0] >> 7 ) ? 0xff : 0x00