Add a test vector for AES-SIV

This verifies that the AES-SIV implementation results matches RFC 5297
test vector A.1.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2014-10-19 11:18:07 +03:00
parent f7072600be
commit a709c5e29f

View file

@ -11,6 +11,7 @@
#include "common.h"
#include "crypto/crypto.h"
#include "crypto/aes_wrap.h"
#include "crypto/aes_siv.h"
#define BLOCK_SIZE 16
@ -438,6 +439,61 @@ static int test_gcm(void)
}
static int test_siv(void)
{
u8 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
};
u8 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
};
u8 plaintext[] = {
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee
};
u8 iv_c[] = {
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
};
u8 out[2 * BLOCK_SIZE + sizeof(plaintext)];
const u8 *addr[1];
size_t len[1];
addr[0] = ad;
len[0] = sizeof(ad);
if (aes_siv_encrypt(key, plaintext, sizeof(plaintext),
1, addr, len, out)) {
printf("AES-SIV mode encryption failed\n");
return 1;
}
if (memcmp(out, iv_c, sizeof(iv_c)) != 0) {
printf("AES-SIV mode encryption returned invalid cipher "
"text\n");
return 1;
}
if (aes_siv_decrypt(key, iv_c, sizeof(iv_c), 1, addr, len, out)) {
printf("AES-SIV mode decryption failed\n");
return 1;
}
if (memcmp(out, plaintext, sizeof(plaintext)) != 0) {
printf("AES-SIV mode decryption returned invalid plain text\n");
return 1;
}
printf("AES-SIV test passed\n");
return 0;
}
/* OMAC1 AES-128 test vectors from
* http://csrc.nist.gov/CryptoToolkit/modes/proposedmodes/omac/omac-ad.pdf
* which are same as the examples from NIST SP800-38B
@ -1076,6 +1132,8 @@ int main(int argc, char *argv[])
ret += test_gcm();
ret += test_siv();
if (ret)
printf("FAILED!\n");