diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2018-11-22 13:34:22 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2018-11-22 14:51:13 +0100 |
| commit | bd03e27a8be67357b441bbdae00ce10447bd55e7 (patch) | |
| tree | 12d154328f38be5f38987c5bc811eef21eee4b47 | |
| parent | 0ea51ff949b689a6db9b823a18a83098707a9717 (diff) | |
| download | lilliput-ae-implem-bd03e27a8be67357b441bbdae00ce10447bd55e7.tar.xz | |
Remaniement de la suite de test
La comparaison avec les sorties attendues est faite directement dans
le code ; libre au développeur d'aller differ les répertoires en cas
de problème.
5 files changed, 94 insertions, 26 deletions
diff --git a/crypto_aead/lilliputaei128v1/ref/Makefile b/crypto_aead/lilliputaei128v1/ref/Makefile index 44fbd03..7befdd2 100644 --- a/crypto_aead/lilliputaei128v1/ref/Makefile +++ b/crypto_aead/lilliputaei128v1/ref/Makefile @@ -24,7 +24,6 @@ test: $(tests) $(tests): %: results/% @mkdir -p results/$@-output ./results/$@ results/$@-output - diff -ru test/$*-ref results/$@-output results/test-tbc-decrypt: results/cipher.o results/tweakey.o results/constants.o | results diff --git a/crypto_aead/lilliputaei128v1/ref/test/helpers.h b/crypto_aead/lilliputaei128v1/ref/test/helpers.h index f4e5208..2cb8e69 100644 --- a/crypto_aead/lilliputaei128v1/ref/test/helpers.h +++ b/crypto_aead/lilliputaei128v1/ref/test/helpers.h @@ -10,14 +10,21 @@ #define ARRAY_NB(A) (sizeof(A)/sizeof(A[0])) #define ARRAY_END(A) (A+ARRAY_NB(A)) +#define REPORT_DIFFERENCE(VECTOR, ELEMENT) do { \ + fprintf(stderr, "%s: vector %s: %s differs from expected\n", \ + __FILE__, (VECTOR), (ELEMENT)); \ + } while (0) + static inline FILE* open_dump_file(const char *folder, const char* vector, const char *name) { - char filename[128]; + size_t filename_len = snprintf(NULL, 0, "%s/%s_%s.txt", folder, vector, name); + char filename[filename_len+1]; snprintf(filename, sizeof(filename), "%s/%s_%s.txt", folder, vector, name); return fopen(filename, "w"); } + #endif /* HELPERS_H */ diff --git a/crypto_aead/lilliputaei128v1/ref/test/test-tbc-decrypt.c b/crypto_aead/lilliputaei128v1/ref/test/test-tbc-decrypt.c index 57bdab2..928dd27 100644 --- a/crypto_aead/lilliputaei128v1/ref/test/test-tbc-decrypt.c +++ b/crypto_aead/lilliputaei128v1/ref/test/test-tbc-decrypt.c @@ -1,24 +1,26 @@ #include <inttypes.h> #include <stdio.h> +#include <string.h> #include "cipher.h" #include "helpers.h" -struct vector_input +struct vector { - char * name; + char *name; uint8_t key[KEY_BYTES]; uint8_t tweak[TWEAK_BYTES]; uint8_t ciphertext[BLOCK_BYTES]; + uint8_t message[BLOCK_BYTES]; }; -typedef struct vector_input vector_input; +typedef struct vector vector; /* [0]: LSB */ -vector_input VECTORS[] = { +const vector VECTORS[] = { { .name = "order", .tweak = { @@ -33,6 +35,10 @@ vector_input VECTORS[] = { .ciphertext = { 0x68, 0x4f, 0x71, 0x4a, 0xff, 0xa6, 0xa0, 0x4e, 0xc3, 0x4a, 0x5d, 0x69, 0x49, 0x9d, 0x71, 0xe4 + }, + .message = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f } }, { @@ -49,6 +55,10 @@ vector_input VECTORS[] = { .ciphertext = { 0xf5, 0xc3, 0xae, 0xae, 0x23, 0x01, 0x1f, 0xb0, 0xc9, 0x5d, 0x53, 0x26, 0x67, 0xd3, 0xd8, 0xdf + }, + .message = { + 0xbc, 0xd7, 0xf0, 0x29, 0x84, 0xb6, 0xc8, 0xf9, + 0x9c, 0x9d, 0x1d, 0xbd, 0x0d, 0x30, 0x94, 0x0b } } }; @@ -62,14 +72,23 @@ int main(int argc, char const * const *argv) return 1; } - for (vector_input* input=VECTORS; input<ARRAY_END(VECTORS); input++) + int diff = 0; + + for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++) { - printf("%s\n", input->name); - FILE* dump = open_dump_file(argv[1], "tbc-decrypt", input->name); + FILE *dump = open_dump_file(argv[1], "tbc-decrypt", v->name); uint8_t message[BLOCK_BYTES]; - lilliput_tbc_decrypt(input->key, input->tweak, input->ciphertext, message, dump); + lilliput_tbc_decrypt(v->key, v->tweak, v->ciphertext, message, dump); + + if (memcmp(message, v->message, sizeof(message)) != 0) + { + REPORT_DIFFERENCE(v->name, "decrypted message"); + diff++; + } fclose(dump); } + + return diff; } diff --git a/crypto_aead/lilliputaei128v1/ref/test/test-tbc-encrypt.c b/crypto_aead/lilliputaei128v1/ref/test/test-tbc-encrypt.c index 21b7cfd..69ddf10 100644 --- a/crypto_aead/lilliputaei128v1/ref/test/test-tbc-encrypt.c +++ b/crypto_aead/lilliputaei128v1/ref/test/test-tbc-encrypt.c @@ -1,24 +1,26 @@ #include <inttypes.h> #include <stdio.h> +#include <string.h> #include "cipher.h" #include "helpers.h" -struct vector_input +struct vector { - char * name; + char *name; uint8_t key[KEY_BYTES]; uint8_t tweak[TWEAK_BYTES]; uint8_t message[BLOCK_BYTES]; + uint8_t ciphertext[BLOCK_BYTES]; }; -typedef struct vector_input vector_input; +typedef struct vector vector; /* [0]: LSB */ -vector_input VECTORS[] = { +const vector VECTORS[] = { { .name = "order", .tweak = { @@ -33,6 +35,10 @@ vector_input VECTORS[] = { .message = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + }, + .ciphertext = { + 0x68, 0x4f, 0x71, 0x4a, 0xff, 0xa6, 0xa0, 0x4e, + 0xc3, 0x4a, 0x5d, 0x69, 0x49, 0x9d, 0x71, 0xe4 } }, { @@ -49,6 +55,10 @@ vector_input VECTORS[] = { .message = { 0xbc, 0xd7, 0xf0, 0x29, 0x84, 0xb6, 0xc8, 0xf9, 0x9c, 0x9d, 0x1d, 0xbd, 0x0d, 0x30, 0x94, 0x0b + }, + .ciphertext = { + 0xf5, 0xc3, 0xae, 0xae, 0x23, 0x01, 0x1f, 0xb0, + 0xc9, 0x5d, 0x53, 0x26, 0x67, 0xd3, 0xd8, 0xdf } } }; @@ -62,14 +72,23 @@ int main(int argc, char const * const *argv) return 1; } - for (vector_input* input=VECTORS; input<ARRAY_END(VECTORS); input++) + int diff = 0; + + for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++) { - printf("%s\n", input->name); - FILE* dump = open_dump_file(argv[1], "tbc-encrypt", input->name); + FILE *dump = open_dump_file(argv[1], "tbc-encrypt", v->name); uint8_t ciphertext[BLOCK_BYTES]; - lilliput_tbc_encrypt(input->key, input->tweak, input->message, ciphertext, dump); + lilliput_tbc_encrypt(v->key, v->tweak, v->message, ciphertext, dump); + + if (memcmp(ciphertext, v->ciphertext, sizeof(ciphertext)) != 0) + { + REPORT_DIFFERENCE(v->name, "ciphertext"); + diff++; + } fclose(dump); } + + return diff; } diff --git a/crypto_aead/lilliputaei128v1/ref/test/test-tweakey.c b/crypto_aead/lilliputaei128v1/ref/test/test-tweakey.c index 2d3ef0d..96abe77 100644 --- a/crypto_aead/lilliputaei128v1/ref/test/test-tweakey.c +++ b/crypto_aead/lilliputaei128v1/ref/test/test-tweakey.c @@ -1,23 +1,25 @@ #include <inttypes.h> #include <stdio.h> +#include <string.h> #include "tweakey.h" #include "helpers.h" -struct vector_input +struct vector { - char * name; + char *name; uint8_t key[KEY_BYTES]; uint8_t tweak[TWEAK_BYTES]; + uint8_t last_rtk[TWEAKEY_BYTES]; }; -typedef struct vector_input vector_input; +typedef struct vector vector; /* [0]: LSB */ -vector_input VECTORS[] = { +const vector VECTORS[] = { { .name = "full", .tweak = { @@ -28,6 +30,9 @@ vector_input VECTORS[] = { .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 } }, { @@ -40,7 +45,11 @@ vector_input VECTORS[] = { .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", @@ -52,6 +61,9 @@ vector_input VECTORS[] = { .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f + }, + .last_rtk = { + 0xac, 0x92, 0x86, 0x9b, 0xae, 0xba, 0x8f, 0xa7 } }, { @@ -64,6 +76,9 @@ vector_input VECTORS[] = { .key = { 0xc1, 0x96, 0xc6, 0x0a, 0x02, 0x73, 0x91, 0x68, 0x7f, 0xf4, 0x23, 0x4d, 0x3d, 0xd5, 0xf9, 0x9b + }, + .last_rtk = { + 0xe6, 0xe3, 0x5e, 0x39, 0xf1, 0xf2, 0xa6, 0xac } } }; @@ -77,15 +92,16 @@ int main(int argc, char const * const *argv) return 1; } - for (vector_input* input=VECTORS; input<ARRAY_END(VECTORS); input++) + int diff = 0; + + for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++) { - printf("%s\n", input->name); - FILE* dump = open_dump_file(argv[1], "tweakey", input->name); + FILE *dump = open_dump_file(argv[1], "tweakey", v->name); fprintf(dump, "Building Tweakey :\n"); tweakey_state tk; - tweakey_state_init(&tk, input->key, input->tweak, dump); + tweakey_state_init(&tk, v->key, v->tweak, dump); fprintf(dump, "Tweakey Schedule\n"); @@ -99,6 +115,14 @@ int main(int argc, char const * const *argv) tweakey_state_extract(&tk, rtk, i); } + if (memcmp(rtk, v->last_rtk, sizeof(rtk)) != 0) + { + REPORT_DIFFERENCE(v->name, "last RTK"); + diff++; + } + fclose(dump); } + + return diff; } |
