[Ffmpeg-devel] [PATCH] cbc decoding for aes

Reimar Döffinger Reimar.Doeffinger
Sun Jan 14 22:27:37 CET 2007


Hello,
added this to test. Speed for my sample movie file is about the same as
with libgcrypt.
Should I apply or do you have some better/other implementation in mind
already?

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavutil/aes.c
===================================================================
--- libavutil/aes.c	(revision 7502)
+++ libavutil/aes.c	(working copy)
@@ -49,6 +49,11 @@
     state[1] ^= round_key[1];
 }
 
+static inline void copyblock(uint64_t dst[2], const uint64_t src[2]){
+    dst[0] = src[0];
+    dst[1] = src[1];
+}
+
 #define SUBSHIFT0(s, box)         s[0]=box[s[ 0]]; s[ 4]=box[s[ 4]];          s[ 8]=box[s[ 8]]; s[12]=box[s[12]];
 #define SUBSHIFT1(s, box) t=s[0]; s[0]=box[s[ 4]]; s[ 4]=box[s[ 8]];          s[ 8]=box[s[12]]; s[12]=box[t];
 #define SUBSHIFT2(s, box) t=s[0]; s[0]=box[s[ 8]]; s[ 8]=box[    t]; t=s[ 4]; s[ 4]=box[s[12]]; s[12]=box[t];
@@ -95,6 +100,17 @@
     crypt(a, 0, inv_sbox, dec_multbl);
 }
 
+void av_aes_cbc_decrypt(AVAES *a, uint8_t *mem, int blockcnt, uint8_t *iv) {
+    while (blockcnt-- > 0) {
+        copyblock(a->state, mem);
+        crypt(a, 0, inv_sbox, dec_multbl);
+        addkey(a->state, iv);
+        copyblock(iv, mem);
+        copyblock(mem, a->state);
+        mem += 16;
+    }
+}
+
 void av_aes_encrypt(AVAES *a){
     crypt(a, 2, sbox, enc_multbl);
 }



More information about the ffmpeg-devel mailing list