[FFmpeg-cvslog] aes: improve test program and add fate test

Mans Rullgard git at videolan.org
Fri Jul 1 05:45:51 CEST 2011


ffmpeg | branch: master | Mans Rullgard <mans at mansr.com> | Wed Jun 29 23:27:07 2011 +0100| [744765a9c58107951136a3552f441662f231e91d] | committer: Mans Rullgard

aes: improve test program and add fate test

Signed-off-by: Mans Rullgard <mans at mansr.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=744765a9c58107951136a3552f441662f231e91d
---

 libavutil/aes.c |   54 +++++++++++++++++++++++++++++++++---------------------
 tests/fate2.mak |    5 +++++
 2 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/libavutil/aes.c b/libavutil/aes.c
index 346676b..72ddf99 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -203,12 +203,14 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) {
 }
 
 #ifdef TEST
+#include <string.h>
 #include "lfg.h"
 #include "log.h"
 
-int main(void){
+int main(int argc, char **argv)
+{
     int i,j;
-    AVAES ae, ad, b;
+    AVAES b;
     uint8_t rkey[2][16]= {
         {0},
         {0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3, 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59}};
@@ -219,37 +221,47 @@ int main(void){
         {0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf},
         {0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65}};
     uint8_t temp[16];
-    AVLFG prng;
+    int err = 0;
 
-    av_aes_init(&ae, "PI=3.141592654..", 128, 0);
-    av_aes_init(&ad, "PI=3.141592654..", 128, 1);
     av_log_set_level(AV_LOG_DEBUG);
-    av_lfg_init(&prng, 1);
 
     for(i=0; i<2; i++){
         av_aes_init(&b, rkey[i], 128, 1);
         av_aes_crypt(&b, temp, rct[i], 1, NULL, 1);
         for(j=0; j<16; j++)
-            if(rpt[i][j] != temp[j])
+            if(rpt[i][j] != temp[j]) {
                 av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n", j, rpt[i][j], temp[j]);
+                err = 1;
+            }
     }
 
-    for(i=0; i<10000; i++){
-        for(j=0; j<16; j++){
-            pt[j] = av_lfg_get(&prng);
-        }
-{START_TIMER
-        av_aes_crypt(&ae, temp, pt, 1, NULL, 0);
-        if(!(i&(i-1)))
-            av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", temp[0], temp[5], temp[10], temp[15]);
-        av_aes_crypt(&ad, temp, temp, 1, NULL, 1);
-STOP_TIMER("aes")}
-        for(j=0; j<16; j++){
-            if(pt[j] != temp[j]){
-                av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n", i,j, pt[j], temp[j]);
+    if (argc > 1 && !strcmp(argv[1], "-t")) {
+        AVAES ae, ad;
+        AVLFG prng;
+
+        av_aes_init(&ae, "PI=3.141592654..", 128, 0);
+        av_aes_init(&ad, "PI=3.141592654..", 128, 1);
+        av_lfg_init(&prng, 1);
+
+        for(i=0; i<10000; i++){
+            for(j=0; j<16; j++){
+                pt[j] = av_lfg_get(&prng);
+            }
+            {
+                START_TIMER;
+                av_aes_crypt(&ae, temp, pt, 1, NULL, 0);
+                if(!(i&(i-1)))
+                    av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", temp[0], temp[5], temp[10], temp[15]);
+                av_aes_crypt(&ad, temp, temp, 1, NULL, 1);
+                STOP_TIMER("aes");
+            }
+            for(j=0; j<16; j++){
+                if(pt[j] != temp[j]){
+                    av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n", i,j, pt[j], temp[j]);
+                }
             }
         }
     }
-    return 0;
+    return err;
 }
 #endif
diff --git a/tests/fate2.mak b/tests/fate2.mak
index d247ded..ad0309f 100644
--- a/tests/fate2.mak
+++ b/tests/fate2.mak
@@ -222,6 +222,11 @@ fate-adler32: libavutil/adler32-test$(EXESUF)
 fate-adler32: CMD = run libavutil/adler32-test
 fate-adler32: REF = /dev/null
 
+FATE_TESTS += fate-aes
+fate-aes: libavutil/aes-test$(EXESUF)
+fate-aes: CMD = run libavutil/aes-test
+fate-aes: REF = /dev/null
+
 FATE_TESTS += fate-musepack7
 fate-musepack7: CMD = pcm -i $(SAMPLES)/musepack/inside-mp7.mpc
 fate-musepack7: CMP = oneoff



More information about the ffmpeg-cvslog mailing list