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

Rodger Combs rodger.combs at gmail.com
Wed Oct 28 11:39:34 CET 2015


---
 tests/checkasm/Makefile   |  2 +-
 tests/checkasm/aes.c      | 64 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/checkasm/checkasm.c |  1 +
 tests/checkasm/checkasm.h |  1 +
 4 files changed, 67 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..c550211
--- /dev/null
+++ b/tests/checkasm/aes.c
@@ -0,0 +1,64 @@
+/*
+ * 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/aes_internal.h"
+#include "libavutil/internal.h"
+
+#define MAX_COUNT 16
+
+void checkasm_check_aes(void)
+{
+    int i, j, d;
+    AVAES b;
+    uint8_t pt[MAX_COUNT * 16];
+    uint8_t temp[2][MAX_COUNT * 16];
+    uint8_t iv[2][16];
+
+    for (d = 0; d <= 1; d++) {
+        for (i = 128; i <= 256; i += 64) {
+            av_aes_init(&b, (const uint8_t*)"PI=3.1415926535897932384626433..", i, d);
+            if (check_func(b.crypt, "aes_%scrypt_%i", d ? "de" : "en", i)) {
+                declare_func(void, AVAES *a, uint8_t *dst, const uint8_t *src,
+                             int count, uint8_t *iv, int rounds);
+                int count = (rnd() & (MAX_COUNT - 1)) + 1;
+                for (j = 0; j < 16 * MAX_COUNT; j++)
+                    pt[j] = rnd();
+                for (j = 0; j < 16; j++)
+                    iv[0][j] = iv[1][j] = rnd();
+                call_ref(&b, temp[0], pt, count, iv[0], b.rounds);
+                call_new(&b, temp[1], pt, count, iv[1], b.rounds);
+                if (memcmp(temp[0], temp[1], sizeof(16 * count)))
+                    fail();
+                if (memcmp(iv[0], iv[1], sizeof(iv[0])))
+                    fail();
+                call_ref(&b, temp[0], pt, count, NULL, b.rounds);
+                call_new(&b, temp[1], pt, count, NULL, b.rounds);
+                if (memcmp(temp[0], temp[1], sizeof(16 * count)))
+                    fail();
+                if (memcmp(iv[0], iv[1], sizeof(iv[0])))
+                    fail();
+                bench_new(&b, temp[1], pt, MAX_COUNT, NULL, b.rounds);
+            }
+        }
+        report("%scrypt", d ? "de" : "en");
+    }
+}
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index e875120..f5b28dc 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.2



More information about the ffmpeg-devel mailing list