summaryrefslogtreecommitdiff
path: root/cesar/cp2/secu/test/src/test-aes.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp2/secu/test/src/test-aes.c')
-rw-r--r--cesar/cp2/secu/test/src/test-aes.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/cesar/cp2/secu/test/src/test-aes.c b/cesar/cp2/secu/test/src/test-aes.c
new file mode 100644
index 0000000000..ad84bb4bcd
--- /dev/null
+++ b/cesar/cp2/secu/test/src/test-aes.c
@@ -0,0 +1,66 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/test-aes.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "lib/bitstream.h"
+#include "string.h"
+
+#include "cp2/secu/aes.h"
+
+void
+test_case_aes (test_t test)
+{
+ aes_context aes;
+
+ u8 key[16] = {0x00, 0x01, 0x02, 0x03, 0x05, 0x06, 0x07, 0x08, 0x0A,
+ 0x0B, 0x0C, 0x0D, 0x0F, 0x10, 0x11, 0x12};
+
+ u8 input [16] = {0x50, 0x68, 0x12, 0xA4, 0x5F, 0x08, 0xC8, 0x89, 0xB9,
+ 0x7F, 0x59, 0x80, 0x03, 0x8B, 0x83, 0x59};
+
+ u8 result [16] = {0xD8, 0xF5, 0x32, 0x53, 0x82, 0x89, 0xEF, 0x7D, 0x06,
+ 0xB5, 0x06, 0xA4, 0xFD, 0x5B, 0xE9, 0xC9};
+
+ u8 output [16];
+
+ aes_set_key (&aes, key);
+ aes_encrypt (&aes, input, output);
+
+ test_case_begin (test, "AES");
+
+ test_begin (test, "Verify")
+ {
+ test_fail_if (bitstream_memcmp(output, result, 16) != true,
+ "Wrong encryption");
+
+ aes_decrypt (&aes, output, output);
+ test_fail_if (bitstream_memcmp(output, input, 16) != true,
+ "Wrong encryption");
+ }
+ test_end;
+}
+
+int
+main (void)
+{
+ test_t test;
+
+ test_init (test, 0, NULL);
+
+ test_case_aes (test);
+
+ test_result (test);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}