Merge "Source and destination buffers may point to same buffer"
This commit is contained in:
committed by
Android (Google) Code Review
commit
a4506542df
@@ -1134,6 +1134,7 @@ OEMCryptoResult SessionContext::DecryptCBC(
|
||||
AES_KEY aes_key;
|
||||
AES_set_decrypt_key(&key[0], AES_BLOCK_SIZE * 8, &aes_key);
|
||||
uint8_t iv[AES_BLOCK_SIZE];
|
||||
uint8_t next_iv[AES_BLOCK_SIZE];
|
||||
memcpy(iv, &initial_iv[0], AES_BLOCK_SIZE);
|
||||
|
||||
size_t l = 0;
|
||||
@@ -1151,11 +1152,14 @@ OEMCryptoResult SessionContext::DecryptCBC(
|
||||
memcpy(&clear_data[l], &cipher_data[l], size);
|
||||
} else {
|
||||
uint8_t aes_output[AES_BLOCK_SIZE];
|
||||
// Save the iv for the next block, in case cipher_data is in the same
|
||||
// buffer as clear_data.
|
||||
memcpy(next_iv, &cipher_data[l], AES_BLOCK_SIZE);
|
||||
AES_decrypt(&cipher_data[l], aes_output, &aes_key);
|
||||
for (size_t n = 0; n < AES_BLOCK_SIZE; n++) {
|
||||
clear_data[l + n] = aes_output[n] ^ iv[n];
|
||||
}
|
||||
memcpy(iv, &cipher_data[l], AES_BLOCK_SIZE);
|
||||
memcpy(iv, next_iv, AES_BLOCK_SIZE);
|
||||
}
|
||||
l += size;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user