mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-28 18:28:23 -05:00
tests: Move OMAC1-AES test cases into hwsim module tests
This makes sure the test cases are executed automatically with rest of the hwsim tests. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
942b75468d
commit
304d40e904
@ -10,6 +10,7 @@
|
||||
|
||||
#include "utils/common.h"
|
||||
#include "crypto/aes_siv.h"
|
||||
#include "crypto/aes_wrap.h"
|
||||
#include "crypto/aes.h"
|
||||
|
||||
|
||||
@ -143,12 +144,122 @@ static int test_siv(void)
|
||||
}
|
||||
|
||||
|
||||
/* 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
|
||||
* http://csrc.nist.gov/CryptoToolkit/modes/800-38_Series_Publications/SP800-38B.pdf
|
||||
*/
|
||||
|
||||
struct omac1_test_vector {
|
||||
u8 k[16];
|
||||
u8 msg[64];
|
||||
int msg_len;
|
||||
u8 tag[16];
|
||||
};
|
||||
|
||||
static struct omac1_test_vector omac1_test_vectors[] =
|
||||
{
|
||||
{
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ },
|
||||
0,
|
||||
{ 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
|
||||
0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46 }
|
||||
},
|
||||
{
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a},
|
||||
16,
|
||||
{ 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
|
||||
0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c }
|
||||
},
|
||||
{
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
|
||||
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
|
||||
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
|
||||
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11 },
|
||||
40,
|
||||
{ 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
|
||||
0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27 }
|
||||
},
|
||||
{
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
|
||||
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
|
||||
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
|
||||
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
|
||||
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
|
||||
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
|
||||
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 },
|
||||
64,
|
||||
{ 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
|
||||
0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe }
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
static int test_omac1_vector(struct omac1_test_vector *tv, unsigned int i)
|
||||
{
|
||||
u8 result[24];
|
||||
|
||||
if (omac1_aes_128(tv->k, tv->msg, tv->msg_len, result) ||
|
||||
os_memcmp(result, tv->tag, 16) != 0) {
|
||||
wpa_printf(MSG_ERROR, "OMAC1-AES-128 test vector %u failed", i);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tv->msg_len > 1) {
|
||||
const u8 *addr[2];
|
||||
size_t len[2];
|
||||
|
||||
addr[0] = tv->msg;
|
||||
len[0] = 1;
|
||||
addr[1] = tv->msg + 1;
|
||||
len[1] = tv->msg_len - 1;
|
||||
|
||||
if (omac1_aes_128_vector(tv->k, 2, addr, len, result) ||
|
||||
os_memcmp(result, tv->tag, 16) != 0) {
|
||||
wpa_printf(MSG_ERROR,
|
||||
"OMAC1-AES-128(vector) test vector %u failed",
|
||||
i);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int test_omac1(void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(omac1_test_vectors); i++) {
|
||||
if (test_omac1_vector(&omac1_test_vectors[i], i))
|
||||
return 1;
|
||||
}
|
||||
|
||||
wpa_printf(MSG_INFO, "OMAC1-AES-128 test cases passed");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int crypto_module_tests(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
wpa_printf(MSG_INFO, "crypto module tests");
|
||||
if (test_siv())
|
||||
if (test_siv() ||
|
||||
test_omac1())
|
||||
ret = -1;
|
||||
|
||||
return ret;
|
||||
|
@ -438,68 +438,6 @@ static int test_gcm(void)
|
||||
}
|
||||
|
||||
|
||||
/* 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
|
||||
* http://csrc.nist.gov/CryptoToolkit/modes/800-38_Series_Publications/SP800-38B.pdf
|
||||
*/
|
||||
|
||||
struct omac1_test_vector {
|
||||
u8 k[16];
|
||||
u8 msg[64];
|
||||
int msg_len;
|
||||
u8 tag[16];
|
||||
};
|
||||
|
||||
static struct omac1_test_vector test_vectors[] =
|
||||
{
|
||||
{
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ },
|
||||
0,
|
||||
{ 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
|
||||
0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46 }
|
||||
},
|
||||
{
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a},
|
||||
16,
|
||||
{ 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
|
||||
0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c }
|
||||
},
|
||||
{
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
|
||||
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
|
||||
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
|
||||
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11 },
|
||||
40,
|
||||
{ 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
|
||||
0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27 }
|
||||
},
|
||||
{
|
||||
{ 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c },
|
||||
{ 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
|
||||
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
|
||||
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
|
||||
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
|
||||
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
|
||||
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
|
||||
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 },
|
||||
64,
|
||||
{ 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
|
||||
0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe }
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
static int test_key_wrap(void)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -1029,10 +967,7 @@ static int test_nist_key_wrap_ad(const char *fname)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
u8 result[24];
|
||||
int ret = 0;
|
||||
unsigned int i;
|
||||
struct omac1_test_vector *tv;
|
||||
|
||||
if (argc >= 3 && os_strcmp(argv[1], "NIST-KW-AE") == 0)
|
||||
ret += test_nist_key_wrap_ae(argv[2]);
|
||||
@ -1043,33 +978,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
test_aes_perf();
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(test_vectors); i++) {
|
||||
tv = &test_vectors[i];
|
||||
if (omac1_aes_128(tv->k, tv->msg, tv->msg_len, result) ||
|
||||
memcmp(result, tv->tag, 16) != 0) {
|
||||
printf("OMAC1-AES-128 test vector %d failed\n", i);
|
||||
ret++;
|
||||
}
|
||||
|
||||
if (tv->msg_len > 1) {
|
||||
const u8 *addr[2];
|
||||
size_t len[2];
|
||||
|
||||
addr[0] = tv->msg;
|
||||
len[0] = 1;
|
||||
addr[1] = tv->msg + 1;
|
||||
len[1] = tv->msg_len - 1;
|
||||
|
||||
if (omac1_aes_128_vector(tv->k, 2, addr, len,
|
||||
result) ||
|
||||
memcmp(result, tv->tag, 16) != 0) {
|
||||
printf("OMAC1-AES-128(vector) test vector %d "
|
||||
"failed\n", i);
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret += test_eax();
|
||||
|
||||
ret += test_cbc();
|
||||
|
Loading…
Reference in New Issue
Block a user