summaryrefslogtreecommitdiff
path: root/crypto_aead
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2018-11-20 10:02:57 +0100
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2018-11-20 10:02:57 +0100
commitf14a2f281a2da7df2dae192cb38eddc288790c4e (patch)
tree24f3c2919e0e01b1ed6bd9d1cc2ed83e3f19424a /crypto_aead
parentf1ffcea01936c33fd2428e06d07f3755068cda15 (diff)
downloadlilliput-ae-implem-f14a2f281a2da7df2dae192cb38eddc288790c4e.tar.xz
Ajout d'une ébauche de code de référence
Lilliput-AE-Ⅰ-128 d'abord, pour comparer aux vecteurs obtenus par Léo.
Diffstat (limited to 'crypto_aead')
-rw-r--r--crypto_aead/lilliputaei128v1/ref/Makefile24
-rw-r--r--crypto_aead/lilliputaei128v1/ref/test-tweakey.c108
-rw-r--r--crypto_aead/lilliputaei128v1/ref/tweakey.c29
-rw-r--r--crypto_aead/lilliputaei128v1/ref/tweakey.h34
4 files changed, 195 insertions, 0 deletions
diff --git a/crypto_aead/lilliputaei128v1/ref/Makefile b/crypto_aead/lilliputaei128v1/ref/Makefile
new file mode 100644
index 0000000..891d0e3
--- /dev/null
+++ b/crypto_aead/lilliputaei128v1/ref/Makefile
@@ -0,0 +1,24 @@
+
+.PHONY: clean run-test-tweakey
+
+
+nist_flags = -std=c99 -Wall -Wextra -Wshadow -fsanitize=address,undefined -O2
+
+
+clean:
+ -rm *.o
+ -rm test-tweakey
+ -rm tweakey_*.txt
+
+%.o: %.c
+ gcc -c $< $(nist_flags) -o $@
+
+test-tweakey: test-tweakey.o tweakey.o
+ gcc $^ $(nist_flags) -o $@
+
+run-test-tweakey: test-tweakey
+ ./test-tweakey
+
+
+test-tweakey.o: tweakey.h
+tweakey.o: tweakey.h
diff --git a/crypto_aead/lilliputaei128v1/ref/test-tweakey.c b/crypto_aead/lilliputaei128v1/ref/test-tweakey.c
new file mode 100644
index 0000000..946f7c9
--- /dev/null
+++ b/crypto_aead/lilliputaei128v1/ref/test-tweakey.c
@@ -0,0 +1,108 @@
+#include <stdint.h>
+#include <stdio.h>
+
+#include "tweakey.h"
+
+
+#define ARRAY_NB(A) (sizeof(A)/sizeof(A[0]))
+#define ARRAY_END(A) (A+ARRAY_NB(A))
+
+
+struct vector_input
+{
+ char * name;
+ uint8_t key[KEY_LENGTH_BITS/8];
+ uint8_t tweak[TWEAK_LENGTH_BITS/8];
+};
+
+typedef struct vector_input vector_input;
+
+
+/* [0]: LSB */
+
+
+vector_input 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
+ }
+ },
+ {
+ .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
+ }
+ },
+ {
+ .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
+ }
+ },
+ {
+ .name = "random",
+ .tweak = {
+ 0xcf, 0x4c, 0xd4, 0x0b, 0x5e, 0x04, 0x2d, 0x26,
+ 0xa5, 0x19, 0x5b, 0x52, 0x73, 0xff, 0x12, 0xd2,
+ 0x39, 0x33, 0x28, 0x90, 0xc5, 0x0e, 0x33, 0x25
+ },
+ .key = {
+ 0xa2, 0x28, 0x13, 0x19, 0x00, 0xd1, 0xf1, 0xf3,
+ 0xa9, 0xca, 0x44, 0x73, 0x56, 0x16, 0xae, 0xb4,
+ }
+ }
+};
+
+
+FILE* open_dump_file(const char * name)
+{
+ char filename[128];
+ snprintf(filename, sizeof(filename), "tweakey_%s.txt", name);
+ return fopen(filename, "w");
+}
+
+
+int main()
+{
+ for (vector_input* input=VECTORS; input<ARRAY_END(VECTORS); input++)
+ {
+ printf("%s\n", input->name);
+ FILE* dump = open_dump_file(input->name);
+
+ fprintf(dump, "Building Tweakey :\n");
+
+ tweakey_state tk;
+ tweakey_state_init(&tk, input->key, input->tweak, dump);
+
+ fprintf(dump, "Tweakey Schedule\n");
+
+ uint8_t rtk[ROUND_TWEAKEY_BITS/8];
+ for (uint8_t i=0; i<32; i++)
+ {
+ tweakey_state_extract(&tk, rtk, i);
+ tweakey_state_update(&tk);
+ }
+ tweakey_state_extract(&tk, rtk, 32);
+
+ fclose(dump);
+ }
+}
diff --git a/crypto_aead/lilliputaei128v1/ref/tweakey.c b/crypto_aead/lilliputaei128v1/ref/tweakey.c
new file mode 100644
index 0000000..340a85b
--- /dev/null
+++ b/crypto_aead/lilliputaei128v1/ref/tweakey.c
@@ -0,0 +1,29 @@
+#include "tweakey.h"
+
+
+void tweakey_state_init(
+ tweakey_state *TK,
+ const uint8_t key[KEY_LENGTH_BITS/8],
+ const uint8_t tweak[TWEAK_LENGTH_BITS/8],
+ FILE* debug
+)
+{
+
+}
+
+
+void tweakey_state_extract(
+ const tweakey_state *TK,
+ uint8_t round_tweakey[ROUND_TWEAKEY_BITS/8], /* output */
+ uint8_t i /* round constant */
+)
+{
+
+}
+
+
+void tweakey_state_update(tweakey_state *TK)
+{
+
+}
+
diff --git a/crypto_aead/lilliputaei128v1/ref/tweakey.h b/crypto_aead/lilliputaei128v1/ref/tweakey.h
new file mode 100644
index 0000000..8018f9c
--- /dev/null
+++ b/crypto_aead/lilliputaei128v1/ref/tweakey.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include <stddef.h>
+#include <stdio.h> /* debug */
+#include <stdint.h>
+
+
+#define TWEAK_LENGTH_BITS 192
+#define KEY_LENGTH_BITS 128
+#define ROUND_TWEAKEY_BITS 64
+
+
+struct tweakey_state
+{
+ FILE* debug;
+};
+
+typedef struct tweakey_state tweakey_state;
+
+
+void tweakey_state_init(
+ tweakey_state *TK,
+ const uint8_t key[KEY_LENGTH_BITS/8],
+ const uint8_t tweak[TWEAK_LENGTH_BITS/8],
+ FILE* debug
+);
+
+void tweakey_state_extract(
+ const tweakey_state *TK,
+ uint8_t round_tweakey[ROUND_TWEAKEY_BITS/8], /* output */
+ uint8_t i /* round constant */
+);
+
+void tweakey_state_update(tweakey_state *TK);