mirror of
https://github.com/cuberite/polarssl.git
synced 2025-09-29 16:32:32 -04:00
Make AES-CBC more efficient
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
6f40f8bf01
commit
797c4ff365
@ -1068,36 +1068,45 @@ int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const unsigned char *ivp = iv;
|
||||||
|
|
||||||
if (mode == MBEDTLS_AES_DECRYPT) {
|
if (mode == MBEDTLS_AES_DECRYPT) {
|
||||||
|
if (length >= 16) {
|
||||||
|
unsigned char temp2[16];
|
||||||
|
memcpy(temp, input + length - 16, 16);
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
memcpy(temp, input, 16);
|
ret = mbedtls_aes_crypt_ecb(ctx, mode, input, temp2);
|
||||||
ret = mbedtls_aes_crypt_ecb(ctx, mode, input, output);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_xor(output, output, iv, 16);
|
mbedtls_xor(output, temp2, ivp, 16);
|
||||||
|
|
||||||
memcpy(iv, temp, 16);
|
ivp = input;
|
||||||
|
|
||||||
input += 16;
|
input += 16;
|
||||||
output += 16;
|
output += 16;
|
||||||
length -= 16;
|
length -= 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(iv, temp, 16);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
mbedtls_xor(output, input, iv, 16);
|
mbedtls_xor(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) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
memcpy(iv, output, 16);
|
ivp = output;
|
||||||
|
|
||||||
input += 16;
|
input += 16;
|
||||||
output += 16;
|
output += 16;
|
||||||
length -= 16;
|
length -= 16;
|
||||||
}
|
}
|
||||||
|
memcpy(iv, ivp, 16);
|
||||||
}
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user