summaryrefslogtreecommitdiff
path: root/crypto_aead/lilliputaeii256v1
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2018-11-28 17:57:45 +0100
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2018-11-28 17:57:45 +0100
commitef586cbef9eaff6a4409d777cd6102ec68e2e47a (patch)
tree418600deb7e0fec41c5092786c2c26d76787e3ee /crypto_aead/lilliputaeii256v1
parente124470b330742fbe0c6f0099d08fdf96070f6b8 (diff)
downloadlilliput-ae-implem-ef586cbef9eaff6a4409d777cd6102ec68e2e47a.tar.xz
Ajout de Lilliput-Ⅱ-256
Diffstat (limited to 'crypto_aead/lilliputaeii256v1')
-rw-r--r--crypto_aead/lilliputaeii256v1/ref/Makefile12
-rw-r--r--crypto_aead/lilliputaeii256v1/ref/_parameters.h9
l---------crypto_aead/lilliputaeii256v1/ref/src1
-rw-r--r--crypto_aead/lilliputaeii256v1/ref/test/test-ae-roundtrip.c124
-rw-r--r--crypto_aead/lilliputaeii256v1/ref/test/traces-ae-256-ii.c129
-rw-r--r--crypto_aead/lilliputaeii256v1/ref/test/traces-tbc-256-ii.c62
6 files changed, 337 insertions, 0 deletions
diff --git a/crypto_aead/lilliputaeii256v1/ref/Makefile b/crypto_aead/lilliputaeii256v1/ref/Makefile
new file mode 100644
index 0000000..906e1f0
--- /dev/null
+++ b/crypto_aead/lilliputaeii256v1/ref/Makefile
@@ -0,0 +1,12 @@
+tests = test-ae-roundtrip
+
+traces = traces-ae-256-ii traces-tbc-256-ii
+
+include src/common.mk
+
+results/test-ae-roundtrip: results/src/lilliput-ae-ii.o results/src/cipher.o results/src/tweakey.o results/src/constants.o | results
+
+results/traces-ae-256-ii: results/src/lilliput-ae-ii.o results/src/cipher.o results/src/tweakey.o results/src/constants.o | results/src
+results/traces-tbc-256-ii: results/src/cipher.o results/src/tweakey.o results/src/constants.o | results/src
+
+results/test-ae-roundtrip.o: src/lilliput-ae.h
diff --git a/crypto_aead/lilliputaeii256v1/ref/_parameters.h b/crypto_aead/lilliputaeii256v1/ref/_parameters.h
new file mode 100644
index 0000000..8bd0430
--- /dev/null
+++ b/crypto_aead/lilliputaeii256v1/ref/_parameters.h
@@ -0,0 +1,9 @@
+#ifndef _PARAMETERS_H
+#define _PARAMETERS_H
+
+#define KEY_LENGTH_BITS 256
+#define ROUNDS 42
+
+#define TWEAK_LENGTH_BITS 128
+
+#endif /* _PARAMETERS_H */
diff --git a/crypto_aead/lilliputaeii256v1/ref/src b/crypto_aead/lilliputaeii256v1/ref/src
new file mode 120000
index 0000000..dabb0e1
--- /dev/null
+++ b/crypto_aead/lilliputaeii256v1/ref/src
@@ -0,0 +1 @@
+../../../src \ No newline at end of file
diff --git a/crypto_aead/lilliputaeii256v1/ref/test/test-ae-roundtrip.c b/crypto_aead/lilliputaeii256v1/ref/test/test-ae-roundtrip.c
new file mode 100644
index 0000000..cd2ea42
--- /dev/null
+++ b/crypto_aead/lilliputaeii256v1/ref/test/test-ae-roundtrip.c
@@ -0,0 +1,124 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "lilliput-ae.h"
+
+#include "test-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 = {
+ 0x69, 0x5a, 0x10, 0x7a, 0x34, 0xb6, 0x80, 0xc1,
+ 0x54, 0x85, 0xca, 0xc0, 0xfb, 0xf6, 0x09, 0x4c,
+ 0x9d, 0xd7, 0x04, 0xfa, 0x1a, 0xb7, 0xb9, 0x22,
+ 0x52, 0xea, 0x36, 0xd3, 0x12, 0x51, 0x3f, 0x86
+ },
+ .nonce = {
+ 0x85, 0xc6, 0x6b, 0xf4, 0x82, 0x99, 0x3a, 0x14,
+ 0x87, 0x7e, 0x45, 0x48, 0xe4, 0x51, 0x6c
+ },
+ .auth_len = 8,
+ .auth = (uint8_t*)"deadbeef",
+ .message_len = 4,
+ .message = (uint8_t[]){
+ 0xde, 0xad, 0xbe, 0xef
+ }
+ },
+ {
+ .name = "block-sized",
+ .key = {
+ 0x9c, 0x59, 0x6a, 0xfb, 0x07, 0x67, 0xd7, 0x52,
+ 0xae, 0xfb, 0xde, 0x3f, 0x9b, 0x68, 0x69, 0x60,
+ 0x22, 0x48, 0x77, 0x95, 0x6f, 0xba, 0x5e, 0x17,
+ 0x25, 0x2a, 0xa0, 0x7f, 0x0e, 0xd8, 0xc3, 0x16
+ },
+ .nonce = {
+ 0x2f, 0xae, 0xfb, 0xa5, 0xd0, 0xc8, 0x2c, 0xc2,
+ 0xb5, 0x16, 0x2e, 0xcc, 0xf8, 0x4f, 0xc8
+ },
+ .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 = {
+ 0xe3, 0x95, 0x7d, 0xc3, 0xc3, 0x29, 0x81, 0x0a,
+ 0x06, 0x20, 0x33, 0xf9, 0x05, 0x6e, 0xb0, 0x45,
+ 0x81, 0x33, 0x64, 0x7d, 0x9f, 0x31, 0x8f, 0x98,
+ 0x1c, 0x97, 0x06, 0x95, 0x6a, 0xe9, 0x93, 0x54
+ },
+ .nonce = {
+ 0x34, 0x87, 0x0f, 0xf9, 0x75, 0x49, 0x4c, 0x02,
+ 0x6c, 0xac, 0x50, 0xfc, 0xc8, 0xe9, 0xed
+ },
+ .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;
+}
diff --git a/crypto_aead/lilliputaeii256v1/ref/test/traces-ae-256-ii.c b/crypto_aead/lilliputaeii256v1/ref/test/traces-ae-256-ii.c
new file mode 100644
index 0000000..343617f
--- /dev/null
+++ b/crypto_aead/lilliputaeii256v1/ref/test/traces-ae-256-ii.c
@@ -0,0 +1,129 @@
+#include <stdio.h>
+#include <stdint.h>
+
+#include "lilliput-ae.h"
+
+#include "debug.h"
+#include "test-helpers.h"
+
+
+FILE *DUMP;
+
+
+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;
+
+
+const vector VECTORS[] = {
+ {
+ .name = "order",
+ .key = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
+ },
+ .nonce = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e
+ },
+ .auth_len = 64,
+ .auth = (uint8_t[]) {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
+ },
+ .message_len = 64,
+ .message = (uint8_t[]) {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
+ }
+ },
+ {
+ .name = "order-padded",
+ .key = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
+ },
+ .nonce = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e
+ },
+ .auth_len = 66,
+ .auth = (uint8_t[]) {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x01
+ },
+ .message_len = 66,
+ .message = (uint8_t[]) {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x01
+ }
+ }
+};
+
+
+int main()
+{
+ for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++)
+ {
+ debug_open_dump("ae-256-ii", v->name);
+ debug_dump_buffer("message", v->message_len, v->message, 0);
+ debug_dump_buffer("associated data", v->auth_len, v->auth, 0);
+ debug_dump_buffer("key", KEY_BYTES, v->key, 0);
+ debug_dump_buffer("nonce", NONCE_BYTES, v->nonce, 0);
+
+ 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
+ );
+
+ debug_dump_buffer("ciphertext", v->message_len, ciphertext, 0);
+ debug_dump_buffer("tag", TAG_BYTES, tag, 0);
+
+ fclose(DUMP);
+ }
+}
diff --git a/crypto_aead/lilliputaeii256v1/ref/test/traces-tbc-256-ii.c b/crypto_aead/lilliputaeii256v1/ref/test/traces-tbc-256-ii.c
new file mode 100644
index 0000000..217d335
--- /dev/null
+++ b/crypto_aead/lilliputaeii256v1/ref/test/traces-tbc-256-ii.c
@@ -0,0 +1,62 @@
+#include <stdio.h>
+#include <stdint.h>
+
+#include "cipher.h"
+
+#include "debug.h"
+#include "test-helpers.h"
+
+
+FILE *DUMP;
+
+
+struct vector
+{
+ char *name;
+ uint8_t key[KEY_BYTES];
+ uint8_t tweak[TWEAK_BYTES];
+ uint8_t message[BLOCK_BYTES];
+};
+
+typedef struct vector vector;
+
+
+const vector VECTORS[] = {
+ {
+ .name = "order",
+ .key = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
+ },
+ .tweak = {
+ 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
+ }
+ }
+};
+
+
+int main()
+{
+ for (const vector *v=VECTORS; v<ARRAY_END(VECTORS); v++)
+ {
+ debug_open_dump("tbc-256-ii", v->name);
+ debug_dump_buffer("message", BLOCK_BYTES, v->message, 0);
+ debug_dump_buffer("key", KEY_BYTES, v->key, 0);
+ debug_dump_buffer("tweak", TWEAK_BYTES, v->tweak, 0);
+
+ uint8_t ciphertext[BLOCK_BYTES];
+
+ lilliput_tbc_encrypt(v->key, v->tweak, v->message, ciphertext);
+
+ debug_dump_buffer("ciphertext", BLOCK_BYTES, ciphertext, 0);
+
+ fclose(DUMP);
+ }
+}