[FFmpeg-devel] [PATCH 7/7] checkasm: add tests for AES

Rodger Combs rodger.combs at gmail.com
Mon Oct 12 05:20:08 CEST 2015


---
 tests/checkasm/Makefile   |  2 +-
 tests/checkasm/aes.c      | 85 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/checkasm/checkasm.c |  1 +
 tests/checkasm/checkasm.h |  1 +
 4 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 tests/checkasm/aes.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index c29ceef..5529e98 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -13,7 +13,7 @@ CHECKASMOBJS-$(CONFIG_AVCODEC) += $(AVCODECOBJS-yes)
 
 -include $(SRC_PATH)/tests/checkasm/$(ARCH)/Makefile
 
-CHECKASMOBJS += $(CHECKASMOBJS-yes) checkasm.o
+CHECKASMOBJS += $(CHECKASMOBJS-yes) aes.o checkasm.o
 CHECKASMOBJS := $(sort $(CHECKASMOBJS:%=tests/checkasm/%))
 
 -include $(CHECKASMOBJS:.o=.d)
diff --git a/tests/checkasm/aes.c b/tests/checkasm/aes.c
new file mode 100644
index 0000000..9c141a1
--- /dev/null
+++ b/tests/checkasm/aes.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2015 Rodger Combs <rodger.combs at gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "checkasm.h"
+#include "libavutil/aes.h"
+#include "libavutil/internal.h"
+
+void checkasm_check_aes(void)
+{
+    int i, j;
+    DECLARE_ALIGNED(32, AVAES, enc);
+    DECLARE_ALIGNED(32, AVAES, dec);
+    uint8_t rkey[2][16] = {
+        { 0 },
+        { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3,
+          0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 }
+    };
+    uint8_t pt[32], rpt[2][16]= {
+        { 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad,
+          0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 },
+        { 0 }
+    };
+    uint8_t rct[2][16]= {
+        { 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[2][32];
+    uint8_t iv[2][16];
+
+    av_log_set_level(AV_LOG_DEBUG);
+
+    av_aes_init(&dec, rkey[0], 128, 1);
+    if (check_func(dec.crypt, "aes_decrypt")) {
+        declare_func(void, AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv);
+        for (i = 0; i < 2; i++) {
+            av_aes_init(&dec, rkey[i], 128, 1);
+            call_ref(&dec, temp[0], rct[i], 1, NULL);
+            call_new(&dec, temp[1], rct[i], 1, NULL);
+            for (j = 0; j < 16; j++) {
+                if (rpt[i][j] != temp[1][j]) {
+                    fail();
+                }
+            }
+            bench_new(&dec, temp[1], rct[i], 1, NULL);
+        }
+    }
+    report("decrypt");
+    av_aes_init(&enc, (const uint8_t*)"PI=3.141592654..", 128, 0);
+    if (check_func(enc.crypt, "aes_encrypt")) {
+        declare_func(void, AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv);
+        av_aes_init(&dec, (const uint8_t*)"PI=3.141592654..", 128, 1);
+        for (j = 0; j < 32; j++)
+            pt[j] = rnd() & 0xFF;
+        for (j = 0; j < 16; j++)
+            iv[0][j] = iv[1][j] = rnd() & 0xFF;
+        call_ref(&enc, temp[0], pt, 2, iv[0]);
+        call_new(&enc, temp[1], pt, 2, iv[1]);
+        for (j = 0; j < 16; j++) {
+            if (temp[0][j] != temp[1][j]) {
+                fail();
+            }
+        }
+        bench_new(&enc, temp[1], pt, 1, NULL);
+    }
+    report("encrypt");
+}
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 2e3d393..63213b5 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -57,6 +57,7 @@ static const struct {
     const char *name;
     void (*func)(void);
 } tests[] = {
+    { "aes", checkasm_check_aes },
 #if CONFIG_AVCODEC
     #if CONFIG_ALAC_DECODER
         { "alacdsp", checkasm_check_alacdsp },
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 1775a25..3b39e16 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -29,6 +29,7 @@
 #include "libavutil/lfg.h"
 #include "libavutil/timer.h"
 
+void checkasm_check_aes(void);
 void checkasm_check_alacdsp(void);
 void checkasm_check_bswapdsp(void);
 void checkasm_check_flacdsp(void);
-- 
2.6.0



More information about the ffmpeg-devel mailing list