summaryrefslogtreecommitdiff
path: root/libavutil/xtea.c
diff options
context:
space:
mode:
authorGiorgio Vazzana <mywing81@gmail.com>2012-09-30 16:00:19 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-09-30 17:51:45 +0200
commit8c3ee93be5ef757b12da81d14029f74c78b942ee (patch)
tree287603e6d7027e4fabdbed8a29b91f6fae85a9c6 /libavutil/xtea.c
parenta0321dadfde0e000de4e67cf9c709b8c667a02f8 (diff)
downloadffmpeg-8c3ee93be5ef757b12da81d14029f74c78b942ee.tar.gz
xtea: fix CBC mode when src=dst
In CBC mode, when src=dst and we are decrypting a block different from the first one, we need to save the current block of ciphertext (which will constitute the initialization vector for the next block) before we overwrite it. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/xtea.c')
-rw-r--r--libavutil/xtea.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/libavutil/xtea.c b/libavutil/xtea.c
index bfc613dc47..f2dfe99a46 100644
--- a/libavutil/xtea.c
+++ b/libavutil/xtea.c
@@ -152,15 +152,22 @@ void av_xtea_crypt(AVXTEA *ctx, uint8_t *dst, const uint8_t *src, int count,
uint8_t *iv, int decrypt)
{
int i;
+ uint8_t iv_tmp[8];
if (decrypt) {
while (count--) {
+ if (src == dst)
+ memcpy(iv_tmp, src, 8);
+
xtea_crypt_ecb(ctx, dst, src, decrypt);
if (iv) {
for (i = 0; i < 8; i++)
dst[i] = dst[i] ^ iv[i];
- memcpy(iv, src, 8);
+ if (src == dst)
+ memcpy(iv, iv_tmp, 8);
+ else
+ memcpy(iv, src, 8);
}
src += 8;