#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; uint8_t *ciphertext; size_t ciphertext_len; uint8_t tag[TAG_BYTES]; 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 }, .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, }, .ciphertext_len = 64, .ciphertext = (uint8_t[]) { 0x86, 0x09, 0xbe, 0x90, 0xa2, 0x9f, 0xa0, 0xed, 0x9a, 0xf6, 0xeb, 0x8d, 0x96, 0x0e, 0x83, 0x81, 0x0a, 0x6b, 0x00, 0xf4, 0x76, 0x99, 0xf4, 0x62, 0x4e, 0x3d, 0x91, 0x4c, 0x95, 0x96, 0x56, 0x91, 0x94, 0xf2, 0x29, 0x55, 0x20, 0x11, 0x2c, 0x93, 0x15, 0x23, 0x59, 0xe2, 0xa3, 0xc4, 0xc4, 0x62, 0xbb, 0xa3, 0x11, 0xf1, 0x39, 0xa2, 0xe2, 0xc9, 0x47, 0x6b, 0xe5, 0x6a, 0x97, 0x07, 0xc0, 0x87 }, .tag = { 0x2e, 0xe5, 0xbf, 0x50, 0x87, 0x71, 0x17, 0x40, 0x1b, 0xa7, 0xe9, 0xed, 0xd5, 0xcb, 0xec, 0x6d }, .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 }, .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 }, .ciphertext_len = 66, .ciphertext = (uint8_t[]) { 0x86, 0x09, 0xbe, 0x90, 0xa2, 0x9f, 0xa0, 0xed, 0x9a, 0xf6, 0xeb, 0x8d, 0x96, 0x0e, 0x83, 0x81, 0x0a, 0x6b, 0x00, 0xf4, 0x76, 0x99, 0xf4, 0x62, 0x4e, 0x3d, 0x91, 0x4c, 0x95, 0x96, 0x56, 0x91, 0x94, 0xf2, 0x29, 0x55, 0x20, 0x11, 0x2c, 0x93, 0x15, 0x23, 0x59, 0xe2, 0xa3, 0xc4, 0xc4, 0x62, 0xbb, 0xa3, 0x11, 0xf1, 0x39, 0xa2, 0xe2, 0xc9, 0x47, 0x6b, 0xe5, 0x6a, 0x97, 0x07, 0xc0, 0x87, 0x4f, 0x09 }, .tag = { 0x04, 0x10, 0xbc, 0x6f, 0xe5, 0x88, 0xe0, 0xd5, 0x09, 0x59, 0x26, 0x17, 0x12, 0x49, 0x35, 0x9a }, .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() { int diff = 0; for (const vector *v=VECTORS; vciphertext_len]; if (! lilliput_ae_decrypt( v->ciphertext_len, v->ciphertext, v->auth_len, v->auth, v->key, v->nonce, v->tag, message )) { REPORT_INVALID(v->name); diff++; continue; } if (memcmp(message, v->message, v->ciphertext_len) != 0) { REPORT_DIFFERENCE(v->name, "ciphertext"); diff++; } } return diff; }