diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2018-11-28 11:02:02 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2018-11-28 11:02:02 +0100 |
| commit | 253ba2a44878542d50877fcc10461491ecd67085 (patch) | |
| tree | cd66101a474d5555eff3253b31658d60e357a6ba /crypto_aead/lilliputaei192v1/ref | |
| parent | 7bbd4e2aeb37430aa17e99e1f9acd2d31c2fc034 (diff) | |
| download | lilliput-ae-implem-253ba2a44878542d50877fcc10461491ecd67085.tar.xz | |
Ajout de Lilliput-AE-Ⅰ avec k=192 bits
Diffstat (limited to 'crypto_aead/lilliputaei192v1/ref')
| -rw-r--r-- | crypto_aead/lilliputaei192v1/ref/Makefile | 12 | ||||
| -rw-r--r-- | crypto_aead/lilliputaei192v1/ref/parameters.h | 23 | ||||
| l--------- | crypto_aead/lilliputaei192v1/ref/src | 1 | ||||
| -rw-r--r-- | crypto_aead/lilliputaei192v1/ref/test/helpers.h | 33 | ||||
| -rw-r--r-- | crypto_aead/lilliputaei192v1/ref/test/test-ae-roundtrip.c | 121 |
5 files changed, 190 insertions, 0 deletions
diff --git a/crypto_aead/lilliputaei192v1/ref/Makefile b/crypto_aead/lilliputaei192v1/ref/Makefile new file mode 100644 index 0000000..5853669 --- /dev/null +++ b/crypto_aead/lilliputaei192v1/ref/Makefile @@ -0,0 +1,12 @@ +tests = test-ae-roundtrip + +include src/common.mk + +results/test-ae-roundtrip: results/src/lilliput-ae-i.o results/src/cipher.o results/src/tweakey.o results/src/constants.o | results + +results/test-*.o: test/helpers.h parameters.h +results/test-ae-roundtrip.o: src/lilliput-ae.h + +# TODO: should add order-only prerequisites to remove mkdirs inside recipes +# TODO: add valgrind, although it does not seem to play well with ASAN +# TODO: should use gcc -M... to generate .o -> .h dependencies diff --git a/crypto_aead/lilliputaei192v1/ref/parameters.h b/crypto_aead/lilliputaei192v1/ref/parameters.h new file mode 100644 index 0000000..061fb63 --- /dev/null +++ b/crypto_aead/lilliputaei192v1/ref/parameters.h @@ -0,0 +1,23 @@ +#ifndef PARAMETERS_H +#define PARAMETERS_H + +#define TWEAK_LENGTH_BITS 192 +#define KEY_LENGTH_BITS 192 +#define TWEAKEY_LENGTH_BITS (TWEAK_LENGTH_BITS+KEY_LENGTH_BITS) +#define ROUND_TWEAKEY_LENGTH_BITS 64 +#define BLOCK_LENGTH_BITS 128 +#define NONCE_LENGTH_BITS 120 +#define TAG_LENGTH_BITS 128 + +#define TWEAK_BYTES (TWEAK_LENGTH_BITS/8) +#define KEY_BYTES (KEY_LENGTH_BITS/8) +#define TWEAKEY_BYTES (TWEAKEY_LENGTH_BITS/8) +#define ROUND_TWEAKEY_BYTES (ROUND_TWEAKEY_LENGTH_BITS/8) +#define BLOCK_BYTES (BLOCK_LENGTH_BITS/8) +#define NONCE_BYTES (NONCE_LENGTH_BITS/8) +#define TAG_BYTES (TAG_LENGTH_BITS/8) + + +#define ROUNDS 36 + +#endif /* PARAMETERS_H */ diff --git a/crypto_aead/lilliputaei192v1/ref/src b/crypto_aead/lilliputaei192v1/ref/src new file mode 120000 index 0000000..dabb0e1 --- /dev/null +++ b/crypto_aead/lilliputaei192v1/ref/src @@ -0,0 +1 @@ +../../../src
\ No newline at end of file diff --git a/crypto_aead/lilliputaei192v1/ref/test/helpers.h b/crypto_aead/lilliputaei192v1/ref/test/helpers.h new file mode 100644 index 0000000..0e1b3c2 --- /dev/null +++ b/crypto_aead/lilliputaei192v1/ref/test/helpers.h @@ -0,0 +1,33 @@ +#ifndef HELPERS_H +#define HELPERS_H + +#include <stdint.h> +#include <stdio.h> + +#include "parameters.h" + + +#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) + +#define REPORT_INVALID(VECTOR) do { \ + fprintf(stderr, "%s: vector %s: ciphertext/tag invalid\n", \ + __FILE__, (VECTOR)); \ + } while (0) + + +static inline FILE* open_dump_file(const char *folder, const char* vector, const char *name) +{ + 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/lilliputaei192v1/ref/test/test-ae-roundtrip.c b/crypto_aead/lilliputaei192v1/ref/test/test-ae-roundtrip.c new file mode 100644 index 0000000..ff8c639 --- /dev/null +++ b/crypto_aead/lilliputaei192v1/ref/test/test-ae-roundtrip.c @@ -0,0 +1,121 @@ +#include <stdio.h> +#include <stdint.h> +#include <string.h> + +#include "lilliput-ae.h" + +#include "helpers.h" + + +struct vector +{ + char *name; + uint8_t key[KEY_BYTES]; + uint8_t nonce[NONCE_BYTES]; + size_t auth_len; + uint8_t *auth; + size_t message_len; + uint8_t *message; +}; + +typedef struct vector vector; + + +/* Keys and nonces generated with /dev/urandom. */ + +const vector VECTORS[] = { + { + .name = "short", + .key = { + 0x06, 0xf4, 0x60, 0x05, 0x12, 0x4b, 0xfd, 0xda, + 0x8f, 0xfc, 0x55, 0x1c, 0xaa, 0xef, 0x81, 0x60, + 0x08, 0xb3, 0xe0, 0xa6, 0xad, 0xcb, 0x68, 0x05 + }, + .nonce = { + 0xcd, 0x6f, 0x24, 0xe1, 0xf8, 0xcd, 0x64, 0xde, + 0x18, 0x2f, 0x92, 0xab, 0xdb, 0xfa, 0xff + }, + .auth_len = 8, + .auth = (uint8_t*)"deadbeef", + .message_len = 4, + .message = (uint8_t[]){ + 0xde, 0xad, 0xbe, 0xef + } + }, + { + .name = "block-sized", + .key = { + 0xa0, 0x3d, 0x36, 0xef, 0xef, 0xdd, 0x72, 0xad, + 0x35, 0xa1, 0x2b, 0xe2, 0x3d, 0x1e, 0x43, 0x94, + 0x38, 0x0f, 0x00, 0x4d, 0x8d, 0x78, 0xbc, 0x02 + }, + .nonce = { + 0xcd, 0x7d, 0xb0, 0xa0, 0x62, 0xdf, 0xda, 0x0a, + 0x23, 0x7a, 0x17, 0x32, 0x60, 0x42, 0xef + }, + .auth_len = 13, + .auth = (uint8_t*)"some metadata", + .message_len = 2*BLOCK_BYTES, + .message = (uint8_t*)"32-byte long, i.e. 2*BLOCK_BYTES" + }, + { + .name = "arbitrarily long", + .key = { + 0x96, 0x6f, 0x23, 0x89, 0xb4, 0xa4, 0x00, 0x7c, + 0x9a, 0x9f, 0x34, 0x01, 0xb0, 0x73, 0x27, 0x56, + 0x09, 0xce, 0x17, 0xeb, 0xdc, 0xd6, 0xa7, 0x06 + }, + .nonce = { + 0x59, 0x41, 0xa7, 0x53, 0x0f, 0xde, 0xf1, 0xb1, + 0xca, 0xd5, 0x80, 0xc4, 0x1c, 0x16, 0x2b + }, + .auth_len = 30, + .auth = (uint8_t*)"a bunch of associated metadata", + .message_len = 59, + .message = (uint8_t*)"here comes the placeholder: foobar ipsum dolor sit baz quux" + } +}; + + +int main() +{ + int diff = 0; + + for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++) + { + uint8_t ciphertext[v->message_len]; + uint8_t tag[TAG_BYTES]; + + lilliput_ae_encrypt( + v->message_len, v->message, + v->auth_len, v->auth, + v->key, v->nonce, + ciphertext, + tag + ); + + uint8_t deciphered[v->message_len]; + bool valid = lilliput_ae_decrypt( + v->message_len, ciphertext, + v->auth_len, v->auth, + v->key, v->nonce, tag, + deciphered + ); + + if (!valid) + { + REPORT_INVALID(v->name); + diff++; + continue; + } + + if (memcmp(deciphered, v->message, v->message_len) != 0) + { + REPORT_DIFFERENCE(v->name, "deciphered plaintext"); + diff++; + continue; + } + } + + return diff; +} |
