diff options
Diffstat (limited to 'crypto_aead/lilliputaei128v1')
7 files changed, 85 insertions, 25 deletions
diff --git a/crypto_aead/lilliputaei128v1/ref/cipher.c b/crypto_aead/lilliputaei128v1/ref/cipher.c index dba7e90..31f7f02 100644 --- a/crypto_aead/lilliputaei128v1/ref/cipher.c +++ b/crypto_aead/lilliputaei128v1/ref/cipher.c @@ -7,6 +7,8 @@ #include "parameters.h" #include "tweakey.h" +#include "debug.h" + enum permutation { @@ -96,6 +98,11 @@ void lilliput_tbc_encrypt( FILE *debug ) { + debug_dump_lanes(debug, "Tweak :", TWEAK_BYTES, tweak, 0); + debug_dump_lanes(debug, "Key :", KEY_BYTES, key, 0); + debug_dump_buffer(debug, "Message :", BLOCK_BYTES, message, 0); + fprintf(debug, "\n"); + cipher_state X; _state_init(&X, message, debug); @@ -110,6 +117,9 @@ void lilliput_tbc_encrypt( _one_round_egfn(&X, RTK[ROUNDS-1], PERMUTATION_NONE); memcpy(ciphertext, X.X, BLOCK_BYTES); + + debug_dump_buffer(debug, "Ciphertext :", BLOCK_BYTES, ciphertext, 0); + } void lilliput_tbc_decrypt( diff --git a/crypto_aead/lilliputaei128v1/ref/debug.h b/crypto_aead/lilliputaei128v1/ref/debug.h index e107019..934a287 100644 --- a/crypto_aead/lilliputaei128v1/ref/debug.h +++ b/crypto_aead/lilliputaei128v1/ref/debug.h @@ -26,3 +26,22 @@ static inline void debug_dump_lanes(FILE *output, const char *header, size_t len } fprintf(output, "\n"); } + +static inline void debug_dump_buffer(FILE *output, const char *header, size_t len, const uint8_t buf[len], int indent) +{ + if (!output) + { + return; + } + + fprintf(output, "%s\n", header); + + fprintf(output, "%*s", indent, ""); + for (size_t b=0; b<len; b++) + { + /* start with MSB */ + size_t byte_index = len-1-b; + fprintf(output, "%*s%02x", 5, "", buf[byte_index]); + } + fprintf(output, "\n"); +} diff --git a/crypto_aead/lilliputaei128v1/ref/test/helpers.h b/crypto_aead/lilliputaei128v1/ref/test/helpers.h index 876cbcd..96e5184 100644 --- a/crypto_aead/lilliputaei128v1/ref/test/helpers.h +++ b/crypto_aead/lilliputaei128v1/ref/test/helpers.h @@ -10,16 +10,6 @@ #define ARRAY_END(A) (A+ARRAY_NB(A)) -struct vector_input -{ - char * name; - uint8_t key[KEY_BYTES]; - uint8_t tweak[TWEAK_BYTES]; -}; - -typedef struct vector_input vector_input; - - static inline FILE* open_dump_file(const char *folder, const char* vector, const char *name) { char filename[128]; diff --git a/crypto_aead/lilliputaei128v1/ref/test/test-cipher-ref/cipher_order.txt b/crypto_aead/lilliputaei128v1/ref/test/test-cipher-ref/cipher_order.txt index 586078f..7dc7178 100644 --- a/crypto_aead/lilliputaei128v1/ref/test/test-cipher-ref/cipher_order.txt +++ b/crypto_aead/lilliputaei128v1/ref/test/test-cipher-ref/cipher_order.txt @@ -1,14 +1,14 @@ Tweak : -17 16 15 14 13 12 11 10 -0f 0e 0d 0c 0b 0a 09 08 -07 06 05 04 03 02 01 00 + 17 16 15 14 13 12 11 10 + 0f 0e 0d 0c 0b 0a 09 08 + 07 06 05 04 03 02 01 00 Key : -0f 0e 0d 0c 0b 0a 09 08 -07 06 05 04 03 02 01 00 + 0f 0e 0d 0c 0b 0a 09 08 + 07 06 05 04 03 02 01 00 Message : -0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 + 0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00 One round EGFN round : 0 State : diff --git a/crypto_aead/lilliputaei128v1/ref/test/test-cipher-ref/cipher_random.txt b/crypto_aead/lilliputaei128v1/ref/test/test-cipher-ref/cipher_random.txt index ab77e18..2762d7b 100644 --- a/crypto_aead/lilliputaei128v1/ref/test/test-cipher-ref/cipher_random.txt +++ b/crypto_aead/lilliputaei128v1/ref/test/test-cipher-ref/cipher_random.txt @@ -1,14 +1,14 @@ Tweak : -4d d2 b3 2a 12 43 8d 7d -21 26 90 90 fa 2e f8 df -84 1c 11 81 10 f3 43 a8 + 4d d2 b3 2a 12 43 8d 7d + 21 26 90 90 fa 2e f8 df + 84 1c 11 81 10 f3 43 a8 Key : -9b f9 d5 3d 4d 23 f4 7f -68 91 73 02 0a c6 96 c1 + 9b f9 d5 3d 4d 23 f4 7f + 68 91 73 02 0a c6 96 c1 Message : -0b 94 30 0d bd 1d 9d 9c f9 c8 b6 84 29 f0 d7 bc + 0b 94 30 0d bd 1d 9d 9c f9 c8 b6 84 29 f0 d7 bc One round EGFN round : 0 State : diff --git a/crypto_aead/lilliputaei128v1/ref/test/test-cipher.c b/crypto_aead/lilliputaei128v1/ref/test/test-cipher.c index 6bc807f..c56e5fb 100644 --- a/crypto_aead/lilliputaei128v1/ref/test/test-cipher.c +++ b/crypto_aead/lilliputaei128v1/ref/test/test-cipher.c @@ -6,9 +6,18 @@ #include "helpers.h" -/* [0]: LSB */ +struct vector_input +{ + char * name; + uint8_t key[KEY_BYTES]; + uint8_t tweak[TWEAK_BYTES]; + uint8_t message[BLOCK_BYTES]; +}; + +typedef struct vector_input vector_input; +/* [0]: LSB */ vector_input VECTORS[] = { { .name = "order", @@ -20,6 +29,10 @@ vector_input VECTORS[] = { .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f + }, + .message = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, } }, { @@ -32,11 +45,31 @@ vector_input VECTORS[] = { .key = { 0xc1, 0x96, 0xc6, 0x0a, 0x02, 0x73, 0x91, 0x68, 0x7f, 0xf4, 0x23, 0x4d, 0x3d, 0xd5, 0xf9, 0x9b + }, + .message = { + 0xbc, 0xd7, 0xf0, 0x29, 0x84, 0xb6, 0xc8, 0xf9, + 0x9c, 0x9d, 0x1d, 0xbd, 0x0d, 0x30, 0x94, 0x0b } } }; -int main() +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], "cipher", input->name); + + uint8_t ciphertext[BLOCK_BYTES]; + lilliput_tbc_encrypt(input->key, input->tweak, input->message, ciphertext, dump); + + fclose(dump); + } } diff --git a/crypto_aead/lilliputaei128v1/ref/test/test-tweakey.c b/crypto_aead/lilliputaei128v1/ref/test/test-tweakey.c index 8449ea4..2d3ef0d 100644 --- a/crypto_aead/lilliputaei128v1/ref/test/test-tweakey.c +++ b/crypto_aead/lilliputaei128v1/ref/test/test-tweakey.c @@ -6,9 +6,17 @@ #include "helpers.h" -/* [0]: LSB */ +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", |
