unit: test for AES-SIV

This commit is contained in:
James Prestwood 2019-04-17 11:21:30 -07:00 committed by Denis Kenzior
parent 5e28b314a7
commit ea228bc8ab
1 changed files with 40 additions and 0 deletions

View File

@ -364,6 +364,45 @@ static void aes_wrap_test(const void *data)
assert(!memcmp(buf, key_data, sizeof(key_data)));
}
static void aes_siv_test(const void *data)
{
/* RFC5297 Appendix A.1 Test Vectors */
const uint8_t key[] = {
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6,
0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0, 0xf0, 0xf1, 0xf2, 0xf3,
0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd,
0xfe, 0xff
};
const uint8_t ad[] = {
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
0x24, 0x25, 0x26, 0x27
};
const uint8_t plaintext[] = {
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
0xbb, 0xcc, 0xdd, 0xee
};
const uint8_t encrypted[] = {
0x85, 0x63, 0x2d, 0x07, 0xc6, 0xe8, 0xf3, 0x7f, 0x95, 0x0a,
0xcd, 0x32, 0x0a, 0x2e, 0xcc, 0x93, 0x40, 0xc0, 0x2b, 0x96,
0x90, 0xc4, 0xdc, 0x04, 0xda, 0xef, 0x7f, 0x6a, 0xfe, 0x5c
};
struct iovec iov[1];
uint8_t outbuf[sizeof(plaintext) + 16];
uint8_t decrypted[sizeof(plaintext)];
iov[0].iov_base = (void *)ad;
iov[0].iov_len = sizeof(ad);
assert(aes_siv_encrypt(key, sizeof(key), plaintext, sizeof(plaintext),
iov, 1, outbuf));
assert(memcmp(outbuf, encrypted, sizeof(outbuf)) == 0);
assert(aes_siv_decrypt(key, sizeof(key), encrypted, sizeof(encrypted), iov, 1,
decrypted));
assert(memcmp(decrypted, plaintext, sizeof(decrypted)) == 0);
}
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@ -396,6 +435,7 @@ int main(int argc, char *argv[])
l_test_add("/AES Key-wrap/Wrap & unwrap",
aes_wrap_test, NULL);
l_test_add("/AES-SIV", aes_siv_test, NULL);
done:
return l_test_run();