lilliput-ae-reference-implementation

Implementations of Lilliput-AE submitted to the NIST LWC standardization process
git clone https://git.kevinlegouguec.net/lilliput-ae-reference-implementation
Log | Files | Refs | README

commit 1a8a1c0f98e39907af61d181d318fd45f3ce93ca
parent 1b70dc0fdb7c445f526a51ced73e531ac31cf438
Author: Kévin Le Gouguec <kevin.legouguec@airbus.com>
Date:   Wed, 21 Nov 2018 10:56:29 +0100

Remaniement de la gestion des tests

Permettra d'ajouter un nouveau test plus facilement.

Diffstat:
Mcrypto_aead/lilliputaei128v1/ref/Makefile | 18++++++++++--------
Rcrypto_aead/lilliputaei128v1/ref/test/tweakey-ref/tweakey_full.txt -> crypto_aead/lilliputaei128v1/ref/test/test-tweakey-ref/tweakey_full.txt | 0
Rcrypto_aead/lilliputaei128v1/ref/test/tweakey-ref/tweakey_null.txt -> crypto_aead/lilliputaei128v1/ref/test/test-tweakey-ref/tweakey_null.txt | 0
Rcrypto_aead/lilliputaei128v1/ref/test/tweakey-ref/tweakey_order.txt -> crypto_aead/lilliputaei128v1/ref/test/test-tweakey-ref/tweakey_order.txt | 0
Rcrypto_aead/lilliputaei128v1/ref/test/tweakey-ref/tweakey_random.txt -> crypto_aead/lilliputaei128v1/ref/test/test-tweakey-ref/tweakey_random.txt | 0
Acrypto_aead/lilliputaei128v1/ref/test/test-tweakey.c | 119+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dcrypto_aead/lilliputaei128v1/ref/test/tweakey.c | 113-------------------------------------------------------------------------------
Dcrypto_aead/lilliputaei128v1/ref/test/tweakey.sh | 8--------
8 files changed, 129 insertions(+), 129 deletions(-)

diff --git a/crypto_aead/lilliputaei128v1/ref/Makefile b/crypto_aead/lilliputaei128v1/ref/Makefile @@ -1,4 +1,6 @@ -.PHONY: clean test-tweakey +tests = test-tweakey + +.PHONY: clean $(tests) nist_flags = -std=c99 -Wall -Wextra -Wshadow -fsanitize=address,undefined -O2 @@ -15,16 +17,16 @@ results/%.o: %.c @mkdir -p $(dir $@) gcc -c -I. $< $(nist_flags) -Werror -o $@ -results/test-%: results/test/%.o - -results/test-tweakey: results/test/tweakey.o results/tweakey.o results/constants.o | results +results/test-%: results/test/test-%.o gcc $^ $(nist_flags) -Werror -o $@ -test-tweakey: results/test-tweakey - mkdir -p results/tweakey - ./results/test-tweakey - ./test/tweakey.sh test/tweakey-ref results/tweakey +$(tests): %: results/% + mkdir -p results/$@-output + ./results/$@ results/$@-output + diff -ru test/$*-ref results/$@-output + +results/test-tweakey: results/tweakey.o results/constants.o | results results/test-tweakey.o: tweakey.h results/tweakey.o: tweakey.h constants.h diff --git a/crypto_aead/lilliputaei128v1/ref/test/tweakey-ref/tweakey_full.txt b/crypto_aead/lilliputaei128v1/ref/test/test-tweakey-ref/tweakey_full.txt diff --git a/crypto_aead/lilliputaei128v1/ref/test/tweakey-ref/tweakey_null.txt b/crypto_aead/lilliputaei128v1/ref/test/test-tweakey-ref/tweakey_null.txt diff --git a/crypto_aead/lilliputaei128v1/ref/test/tweakey-ref/tweakey_order.txt b/crypto_aead/lilliputaei128v1/ref/test/test-tweakey-ref/tweakey_order.txt diff --git a/crypto_aead/lilliputaei128v1/ref/test/tweakey-ref/tweakey_random.txt b/crypto_aead/lilliputaei128v1/ref/test/test-tweakey-ref/tweakey_random.txt diff --git a/crypto_aead/lilliputaei128v1/ref/test/test-tweakey.c b/crypto_aead/lilliputaei128v1/ref/test/test-tweakey.c @@ -0,0 +1,119 @@ +#include <inttypes.h> +#include <stdio.h> + +#include "tweakey.h" + + +#define ARRAY_NB(A) (sizeof(A)/sizeof(A[0])) +#define ARRAY_END(A) (A+ARRAY_NB(A)) + + +#define ROUNDS 32 + + +struct vector_input +{ + char * name; + uint8_t key[KEY_BYTES]; + uint8_t tweak[TWEAK_BYTES]; +}; + +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 = { + 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 + } + } +}; + + +FILE* open_dump_file(const char *folder, const char *name) +{ + char filename[128]; + snprintf(filename, sizeof(filename), "%s/tweakey_%s.txt", folder, name); + return fopen(filename, "w"); +} + + +int main(int argc, char const * const *argv) +{ + if (argc < 2) + { + fprintf(stderr, "usage: %s OUTPUT-FOLDER\n", argv[0]); + return 1; + } + + for (vector_input* input=VECTORS; input<ARRAY_END(VECTORS); input++) + { + printf("%s\n", input->name); + FILE* dump = open_dump_file(argv[1], 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_BYTES]; + tweakey_state_extract(&tk, rtk, 0); + + for (uint8_t i=1; i<ROUNDS; i++) + { + fprintf(dump, " Round Tweakey %"PRIu8"\n", i); + tweakey_state_update(&tk); + tweakey_state_extract(&tk, rtk, i); + } + + fclose(dump); + } +} diff --git a/crypto_aead/lilliputaei128v1/ref/test/tweakey.c b/crypto_aead/lilliputaei128v1/ref/test/tweakey.c @@ -1,113 +0,0 @@ -#include <inttypes.h> -#include <stdio.h> - -#include "tweakey.h" - - -#define ARRAY_NB(A) (sizeof(A)/sizeof(A[0])) -#define ARRAY_END(A) (A+ARRAY_NB(A)) - - -#define ROUNDS 32 - - -struct vector_input -{ - char * name; - uint8_t key[KEY_BYTES]; - uint8_t tweak[TWEAK_BYTES]; -}; - -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 = { - 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 - } - } -}; - - -FILE* open_dump_file(const char * name) -{ - char filename[128]; - snprintf(filename, sizeof(filename), "results/tweakey/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_BYTES]; - tweakey_state_extract(&tk, rtk, 0); - - for (uint8_t i=1; i<ROUNDS; i++) - { - fprintf(dump, " Round Tweakey %"PRIu8"\n", i); - tweakey_state_update(&tk); - tweakey_state_extract(&tk, rtk, i); - } - - fclose(dump); - } -} diff --git a/crypto_aead/lilliputaei128v1/ref/test/tweakey.sh b/crypto_aead/lilliputaei128v1/ref/test/tweakey.sh @@ -1,8 +0,0 @@ -#!/bin/bash - -set -eu - -reference=$1 -actual=$2 - -diff -ru ${reference} ${actual}