From: Giorgio Vazzana <mywin...@gmail.com>

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.
---
 libavutil/xtea.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavutil/xtea.c b/libavutil/xtea.c
index bf5db11..41aed2b 100644
--- a/libavutil/xtea.c
+++ b/libavutil/xtea.c
@@ -70,15 +70,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;
-- 
1.7.9.4

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to