#include #include #include #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 = { 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; vmessage_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; }