tests: Add module tests for AES-SIV
This moves the AES-SIV test case from tests/test-aes.c to be part of wpa_supplicant module testing framework with a new src/crypto/crypto_module_tests.c component. In addition, the second test vector from RFC 5297 is also included for additional coverage. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
f6ebbcf62a
commit
942b75468d
4 changed files with 162 additions and 58 deletions
155
src/crypto/crypto_module_tests.c
Normal file
155
src/crypto/crypto_module_tests.c
Normal file
|
@ -0,0 +1,155 @@
|
||||||
|
/*
|
||||||
|
* crypto module tests
|
||||||
|
* Copyright (c) 2014-2015, Jouni Malinen <j@w1.fi>
|
||||||
|
*
|
||||||
|
* This software may be distributed under the terms of the BSD license.
|
||||||
|
* See README for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "utils/includes.h"
|
||||||
|
|
||||||
|
#include "utils/common.h"
|
||||||
|
#include "crypto/aes_siv.h"
|
||||||
|
#include "crypto/aes.h"
|
||||||
|
|
||||||
|
|
||||||
|
static int test_siv(void)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_MESH
|
||||||
|
/* RFC 5297, A.1. Deterministic Authenticated Encryption Example */
|
||||||
|
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
|
||||||
|
};
|
||||||
|
/* RFC 5297, A.2. Nonce-Based Authenticated Encryption Example */
|
||||||
|
u8 key_2[] = {
|
||||||
|
0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78,
|
||||||
|
0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70,
|
||||||
|
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
|
||||||
|
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
|
||||||
|
};
|
||||||
|
u8 ad1_2[] = {
|
||||||
|
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||||
|
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
|
||||||
|
0xde, 0xad, 0xda, 0xda, 0xde, 0xad, 0xda, 0xda,
|
||||||
|
0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
|
||||||
|
0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00
|
||||||
|
};
|
||||||
|
u8 ad2_2[] = {
|
||||||
|
0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80,
|
||||||
|
0x90, 0xa0
|
||||||
|
};
|
||||||
|
u8 nonce_2[] = {
|
||||||
|
0x09, 0xf9, 0x11, 0x02, 0x9d, 0x74, 0xe3, 0x5b,
|
||||||
|
0xd8, 0x41, 0x56, 0xc5, 0x63, 0x56, 0x88, 0xc0
|
||||||
|
};
|
||||||
|
u8 plaintext_2[] = {
|
||||||
|
0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
|
||||||
|
0x73, 0x6f, 0x6d, 0x65, 0x20, 0x70, 0x6c, 0x61,
|
||||||
|
0x69, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x20, 0x74,
|
||||||
|
0x6f, 0x20, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70,
|
||||||
|
0x74, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20,
|
||||||
|
0x53, 0x49, 0x56, 0x2d, 0x41, 0x45, 0x53
|
||||||
|
};
|
||||||
|
u8 iv_c_2[] = {
|
||||||
|
0x7b, 0xdb, 0x6e, 0x3b, 0x43, 0x26, 0x67, 0xeb,
|
||||||
|
0x06, 0xf4, 0xd1, 0x4b, 0xff, 0x2f, 0xbd, 0x0f,
|
||||||
|
0xcb, 0x90, 0x0f, 0x2f, 0xdd, 0xbe, 0x40, 0x43,
|
||||||
|
0x26, 0x60, 0x19, 0x65, 0xc8, 0x89, 0xbf, 0x17,
|
||||||
|
0xdb, 0xa7, 0x7c, 0xeb, 0x09, 0x4f, 0xa6, 0x63,
|
||||||
|
0xb7, 0xa3, 0xf7, 0x48, 0xba, 0x8a, 0xf8, 0x29,
|
||||||
|
0xea, 0x64, 0xad, 0x54, 0x4a, 0x27, 0x2e, 0x9c,
|
||||||
|
0x48, 0x5b, 0x62, 0xa3, 0xfd, 0x5c, 0x0d
|
||||||
|
};
|
||||||
|
u8 out[2 * AES_BLOCK_SIZE + sizeof(plaintext_2)];
|
||||||
|
const u8 *addr[3];
|
||||||
|
size_t len[3];
|
||||||
|
|
||||||
|
/* RFC 5297, A.1. Deterministic Authenticated Encryption Example */
|
||||||
|
addr[0] = ad;
|
||||||
|
len[0] = sizeof(ad);
|
||||||
|
|
||||||
|
if (aes_siv_encrypt(key, plaintext, sizeof(plaintext),
|
||||||
|
1, addr, len, out)) {
|
||||||
|
wpa_printf(MSG_ERROR, "AES-SIV mode encryption failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (os_memcmp(out, iv_c, sizeof(iv_c)) != 0) {
|
||||||
|
wpa_printf(MSG_ERROR,
|
||||||
|
"AES-SIV mode encryption returned invalid cipher text");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aes_siv_decrypt(key, iv_c, sizeof(iv_c), 1, addr, len, out)) {
|
||||||
|
wpa_printf(MSG_ERROR, "AES-SIV mode decryption failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (os_memcmp(out, plaintext, sizeof(plaintext)) != 0) {
|
||||||
|
wpa_printf(MSG_ERROR,
|
||||||
|
"AES-SIV mode decryption returned invalid plain text");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RFC 5297, A.2. Nonce-Based Authenticated Encryption Example */
|
||||||
|
addr[0] = ad1_2;
|
||||||
|
len[0] = sizeof(ad1_2);
|
||||||
|
addr[1] = ad2_2;
|
||||||
|
len[1] = sizeof(ad2_2);
|
||||||
|
addr[2] = nonce_2;
|
||||||
|
len[2] = sizeof(nonce_2);
|
||||||
|
|
||||||
|
if (aes_siv_encrypt(key_2, plaintext_2, sizeof(plaintext_2),
|
||||||
|
3, addr, len, out)) {
|
||||||
|
wpa_printf(MSG_ERROR, "AES-SIV mode encryption failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (os_memcmp(out, iv_c_2, sizeof(iv_c_2)) != 0) {
|
||||||
|
wpa_printf(MSG_ERROR,
|
||||||
|
"AES-SIV mode encryption returned invalid cipher text");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aes_siv_decrypt(key_2, iv_c_2, sizeof(iv_c_2), 3, addr, len, out)) {
|
||||||
|
wpa_printf(MSG_ERROR, "AES-SIV mode decryption failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (os_memcmp(out, plaintext_2, sizeof(plaintext_2)) != 0) {
|
||||||
|
wpa_printf(MSG_ERROR,
|
||||||
|
"AES-SIV mode decryption returned invalid plain text");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wpa_printf(MSG_INFO, "AES-SIV test cases passed");
|
||||||
|
#endif /* CONFIG_MESH */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int crypto_module_tests(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
wpa_printf(MSG_INFO, "crypto module tests");
|
||||||
|
if (test_siv())
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -11,7 +11,6 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "crypto/crypto.h"
|
#include "crypto/crypto.h"
|
||||||
#include "crypto/aes_wrap.h"
|
#include "crypto/aes_wrap.h"
|
||||||
#include "crypto/aes_siv.h"
|
|
||||||
|
|
||||||
#define BLOCK_SIZE 16
|
#define BLOCK_SIZE 16
|
||||||
|
|
||||||
|
@ -439,61 +438,6 @@ 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
|
/* OMAC1 AES-128 test vectors from
|
||||||
* http://csrc.nist.gov/CryptoToolkit/modes/proposedmodes/omac/omac-ad.pdf
|
* http://csrc.nist.gov/CryptoToolkit/modes/proposedmodes/omac/omac-ad.pdf
|
||||||
* which are same as the examples from NIST SP800-38B
|
* which are same as the examples from NIST SP800-38B
|
||||||
|
@ -1132,8 +1076,6 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
ret += test_gcm();
|
ret += test_gcm();
|
||||||
|
|
||||||
ret += test_siv();
|
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
printf("FAILED!\n");
|
printf("FAILED!\n");
|
||||||
|
|
||||||
|
|
|
@ -1523,6 +1523,7 @@ CFLAGS += -DCONFIG_MODULE_TESTS
|
||||||
OBJS += wpas_module_tests.o
|
OBJS += wpas_module_tests.o
|
||||||
OBJS += ../src/utils/utils_module_tests.o
|
OBJS += ../src/utils/utils_module_tests.o
|
||||||
OBJS += ../src/common/common_module_tests.o
|
OBJS += ../src/common/common_module_tests.o
|
||||||
|
OBJS += ../src/crypto/crypto_module_tests.o
|
||||||
ifdef CONFIG_WPS
|
ifdef CONFIG_WPS
|
||||||
OBJS += ../src/wps/wps_module_tests.o
|
OBJS += ../src/wps/wps_module_tests.o
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -98,5 +98,11 @@ int wpas_module_tests(void)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
int crypto_module_tests(void);
|
||||||
|
if (crypto_module_tests() < 0)
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue