summaryrefslogtreecommitdiff
path: root/test/i-128/test-tweakey.c
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2018-12-04 08:15:59 +0100
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2018-12-04 10:40:58 +0100
commitdded798f1a038c8482fcc5d41824a9161d0a60c2 (patch)
treea52436ee5e61d639aaceaeae2efb587a6e68f57b /test/i-128/test-tweakey.c
parent950bd7432cd486d29503444b0557d7a1452efd07 (diff)
downloadlilliput-ae-implem-dded798f1a038c8482fcc5d41824a9161d0a60c2.tar.xz
[WIP] screw with folders organization
Diffstat (limited to 'test/i-128/test-tweakey.c')
-rw-r--r--test/i-128/test-tweakey.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/test/i-128/test-tweakey.c b/test/i-128/test-tweakey.c
new file mode 100644
index 0000000..2b0bad5
--- /dev/null
+++ b/test/i-128/test-tweakey.c
@@ -0,0 +1,113 @@
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "tweakey.h"
+
+#include "test-helpers.h"
+
+
+struct vector
+{
+ char *name;
+ uint8_t key[KEY_BYTES];
+ uint8_t tweak[TWEAK_BYTES];
+ uint8_t last_rtk[TWEAKEY_BYTES];
+};
+
+typedef struct vector vector;
+
+
+/* [0]: LSB */
+const vector VECTORS[] = {
+ {
+ .name = "full",
+ .tweak = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+ },
+ .key = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+ },
+ .last_rtk = {
+ 0x42, 0x5d, 0x5d, 0x5d, 0x5d, 0x5d, 0x5d, 0x5d
+ }
+ },
+ {
+ .name = "null",
+ .tweak = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ },
+ .key = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ },
+ .last_rtk = {
+ 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ }
+
+ },
+ {
+ .name = "order",
+ .tweak = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
+ },
+ .key = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
+ },
+ .last_rtk = {
+ 0xa5, 0x92, 0x9b, 0xa7, 0x86, 0x8f, 0xb3, 0xae
+ }
+ },
+ {
+ .name = "random",
+ .tweak = {
+ 0xa8, 0x43, 0xf3, 0x10, 0x81, 0x11, 0x1c, 0x84,
+ 0xdf, 0xf8, 0x2e, 0xfa, 0x90, 0x90, 0x26, 0x21,
+ 0x7d, 0x8d, 0x43, 0x12, 0x2a, 0xb3, 0xd2, 0x4d
+ },
+ .key = {
+ 0xc1, 0x96, 0xc6, 0x0a, 0x02, 0x73, 0x91, 0x68,
+ 0x7f, 0xf4, 0x23, 0x4d, 0x3d, 0xd5, 0xf9, 0x9b
+ },
+ .last_rtk = {
+ 0xed, 0xe3, 0x39, 0xac, 0x5e, 0xa6, 0xf9, 0xf1
+ }
+ }
+};
+
+
+int main()
+{
+ int diff = 0;
+
+ for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++)
+ {
+ uint8_t tk[TWEAKEY_BYTES];
+ tweakey_state_init(tk, v->key, v->tweak);
+
+ uint8_t rtk[ROUND_TWEAKEY_BYTES];
+ tweakey_state_extract(tk, 0, rtk);
+
+ for (uint8_t i=1; i<ROUNDS; i++)
+ {
+ tweakey_state_update(tk);
+ tweakey_state_extract(tk, i, rtk);
+ }
+
+ if (memcmp(rtk, v->last_rtk, sizeof(rtk)) != 0)
+ {
+ REPORT_DIFFERENCE(v->name, "last RTK");
+ diff++;
+ }
+ }
+
+ return diff;
+}