Fix AES-CBC for in-place operation
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
b19b63a639
commit
262d8ced79
1 changed files with 12 additions and 17 deletions
|
@ -1071,27 +1071,22 @@ int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx,
|
|||
const unsigned char *ivp = iv;
|
||||
|
||||
if (mode == MBEDTLS_AES_DECRYPT) {
|
||||
if (length >= 16) {
|
||||
unsigned char temp2[16];
|
||||
memcpy(temp, input + length - 16, 16);
|
||||
|
||||
while (length > 0) {
|
||||
memcpy(temp, input, 16);
|
||||
ret = mbedtls_aes_crypt_ecb(ctx, mode, input, temp2);
|
||||
if (ret != 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_xor(output, temp2, ivp, 16);
|
||||
mbedtls_xor(output, temp2, iv, 16);
|
||||
|
||||
ivp = input;
|
||||
memcpy(iv, temp, 16);
|
||||
|
||||
input += 16;
|
||||
output += 16;
|
||||
length -= 16;
|
||||
}
|
||||
|
||||
memcpy(iv, temp, 16);
|
||||
}
|
||||
} else {
|
||||
while (length > 0) {
|
||||
mbedtls_xor(output, input, ivp, 16);
|
||||
|
|
Loading…
Reference in a new issue