mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-28 18:28:23 -05:00
tests: Move AES-CBC test cases into hwsim framework
Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
e438fb0d3a
commit
477f83131f
@ -335,6 +335,75 @@ static int test_eax(void)
|
||||
}
|
||||
|
||||
|
||||
static int test_cbc(void)
|
||||
{
|
||||
struct cbc_test_vector {
|
||||
u8 key[16];
|
||||
u8 iv[16];
|
||||
u8 plain[32];
|
||||
u8 cipher[32];
|
||||
size_t len;
|
||||
} vectors[] = {
|
||||
{
|
||||
{ 0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b,
|
||||
0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06 },
|
||||
{ 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30,
|
||||
0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41 },
|
||||
"Single block msg",
|
||||
{ 0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8,
|
||||
0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a },
|
||||
16
|
||||
},
|
||||
{
|
||||
{ 0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0,
|
||||
0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a },
|
||||
{ 0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28,
|
||||
0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58 },
|
||||
{ 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 },
|
||||
{ 0xd2, 0x96, 0xcd, 0x94, 0xc2, 0xcc, 0xcf, 0x8a,
|
||||
0x3a, 0x86, 0x30, 0x28, 0xb5, 0xe1, 0xdc, 0x0a,
|
||||
0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9,
|
||||
0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1 },
|
||||
32
|
||||
}
|
||||
};
|
||||
int ret = 0;
|
||||
u8 *buf;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(vectors); i++) {
|
||||
struct cbc_test_vector *tv = &vectors[i];
|
||||
|
||||
buf = os_malloc(tv->len);
|
||||
if (buf == NULL) {
|
||||
ret++;
|
||||
break;
|
||||
}
|
||||
|
||||
os_memcpy(buf, tv->plain, tv->len);
|
||||
if (aes_128_cbc_encrypt(tv->key, tv->iv, buf, tv->len) ||
|
||||
os_memcmp(buf, tv->cipher, tv->len) != 0) {
|
||||
wpa_printf(MSG_ERROR, "AES-CBC encrypt %d failed", i);
|
||||
ret++;
|
||||
}
|
||||
|
||||
os_memcpy(buf, tv->cipher, tv->len);
|
||||
if (aes_128_cbc_decrypt(tv->key, tv->iv, buf, tv->len) ||
|
||||
os_memcmp(buf, tv->plain, tv->len) != 0) {
|
||||
wpa_printf(MSG_ERROR, "AES-CBC decrypt %d failed", i);
|
||||
ret++;
|
||||
}
|
||||
|
||||
os_free(buf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int crypto_module_tests(void)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -342,7 +411,8 @@ int crypto_module_tests(void)
|
||||
wpa_printf(MSG_INFO, "crypto module tests");
|
||||
if (test_siv() ||
|
||||
test_omac1() ||
|
||||
test_eax())
|
||||
test_eax() ||
|
||||
test_cbc())
|
||||
ret = -1;
|
||||
|
||||
return ret;
|
||||
|
@ -51,71 +51,6 @@ static void test_aes_perf(void)
|
||||
}
|
||||
|
||||
|
||||
static int test_cbc(void)
|
||||
{
|
||||
struct cbc_test_vector {
|
||||
u8 key[16];
|
||||
u8 iv[16];
|
||||
u8 plain[32];
|
||||
u8 cipher[32];
|
||||
size_t len;
|
||||
} vectors[] = {
|
||||
{
|
||||
{ 0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b,
|
||||
0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06 },
|
||||
{ 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30,
|
||||
0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41 },
|
||||
"Single block msg",
|
||||
{ 0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8,
|
||||
0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a },
|
||||
16
|
||||
},
|
||||
{
|
||||
{ 0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0,
|
||||
0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a },
|
||||
{ 0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28,
|
||||
0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58 },
|
||||
{ 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 },
|
||||
{ 0xd2, 0x96, 0xcd, 0x94, 0xc2, 0xcc, 0xcf, 0x8a,
|
||||
0x3a, 0x86, 0x30, 0x28, 0xb5, 0xe1, 0xdc, 0x0a,
|
||||
0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9,
|
||||
0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1 },
|
||||
32
|
||||
}
|
||||
};
|
||||
int ret = 0;
|
||||
u8 *buf;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(vectors); i++) {
|
||||
struct cbc_test_vector *tv = &vectors[i];
|
||||
buf = malloc(tv->len);
|
||||
if (buf == NULL) {
|
||||
ret++;
|
||||
break;
|
||||
}
|
||||
memcpy(buf, tv->plain, tv->len);
|
||||
if (aes_128_cbc_encrypt(tv->key, tv->iv, buf, tv->len) ||
|
||||
memcmp(buf, tv->cipher, tv->len) != 0) {
|
||||
printf("AES-CBC encrypt %d failed\n", i);
|
||||
ret++;
|
||||
}
|
||||
memcpy(buf, tv->cipher, tv->len);
|
||||
if (aes_128_cbc_decrypt(tv->key, tv->iv, buf, tv->len) ||
|
||||
memcmp(buf, tv->plain, tv->len) != 0) {
|
||||
printf("AES-CBC decrypt %d failed\n", i);
|
||||
ret++;
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GCM test vectors from
|
||||
* http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-spec.pdf
|
||||
@ -934,8 +869,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
test_aes_perf();
|
||||
|
||||
ret += test_cbc();
|
||||
|
||||
ret += test_gcm();
|
||||
|
||||
if (ret)
|
||||
|
Loading…
Reference in New Issue
Block a user