From a5d3e583ff88328241b6936addcd4ea47b8563b0 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 12 Aug 2016 17:36:54 -0500 Subject: [PATCH] unit: Add DH5 pubkey generation test --- Makefile.am | 3 +- unit/test-wsc.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 83c18660..9ae95bea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -183,7 +183,8 @@ unit_test_ssid_security_SOURCES = unit/test-ssid-security.c src/ie.h src/ie.c \ src/scan.h src/scan.c unit_test_ssid_security_LDADD = ell/libell-internal.la -unit_test_wsc_SOURCES = unit/test-wsc.c src/wscutil.h src/wscutil.c +unit_test_wsc_SOURCES = unit/test-wsc.c src/wscutil.h src/wscutil.c \ + src/crypto.h src/crypto.c unit_test_wsc_LDADD = ell/libell-internal.la TESTS = $(unit_tests) diff --git a/unit/test-wsc.c b/unit/test-wsc.c index 503d190c..dbe91398 100644 --- a/unit/test-wsc.c +++ b/unit/test-wsc.c @@ -31,6 +31,7 @@ #include #include "src/wscutil.h" +#include "src/crypto.h" static const unsigned char wsc_attrs1[] = { 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, 0x44, 0x00, 0x01, 0x02, 0x10, 0x41, @@ -404,6 +405,88 @@ static void wsc_test_uuid_from_addr(const void *data) assert(!memcmp(test->expected_uuid, uuid, 16)); } +static const unsigned char dh_private_key_1[] = { + 0x4b, 0x5e, 0x01, 0xfa, 0x2b, 0xd4, 0x91, 0xac, 0x34, 0x04, 0x28, 0xfb, + 0xe2, 0x5d, 0x06, 0x2d, 0x1a, 0xe7, 0x6c, 0xd0, 0xa3, 0x9d, 0x4a, 0x27, + 0x24, 0x51, 0x79, 0xdc, 0xa7, 0x47, 0x24, 0x1d, 0x19, 0x26, 0x9e, 0xb8, + 0xa0, 0x6e, 0xd9, 0x7e, 0x07, 0x4e, 0x02, 0xe1, 0xb2, 0x4e, 0x31, 0x12, + 0xa2, 0xc1, 0x41, 0x73, 0x6a, 0x43, 0xe2, 0x0e, 0xc8, 0xec, 0xb7, 0x41, + 0xdc, 0x25, 0x4c, 0x30, 0xd0, 0x3f, 0xa7, 0x97, 0x9f, 0x2e, 0xdc, 0x59, + 0x0d, 0x7a, 0x24, 0xcb, 0x1b, 0xc2, 0x8d, 0x30, 0xc5, 0x04, 0xc3, 0x50, + 0x61, 0xa7, 0xd2, 0xbd, 0x79, 0xb3, 0xec, 0xd2, 0xf5, 0x10, 0x20, 0x32, + 0x0c, 0x7a, 0xfd, 0x0c, 0xde, 0x07, 0x22, 0x94, 0x2d, 0x42, 0x16, 0xc8, + 0xa7, 0x17, 0x70, 0x16, 0x46, 0x72, 0xaa, 0xb5, 0xa7, 0xdc, 0xc0, 0xee, + 0x7d, 0xe8, 0x36, 0x0b, 0xba, 0x04, 0xd5, 0x5c, 0x5d, 0x40, 0x65, 0x58, + 0xd8, 0xe8, 0x9a, 0x27, 0xd2, 0xb3, 0x39, 0x2a, 0xe7, 0xfc, 0x16, 0x59, + 0xc6, 0x6c, 0x2f, 0xad, 0x6f, 0xd2, 0x0d, 0xf4, 0xb0, 0x8b, 0xdf, 0x9a, + 0x88, 0x84, 0xf9, 0x2a, 0xc4, 0x64, 0xb7, 0xb5, 0xe0, 0xf7, 0x3a, 0x8a, + 0xeb, 0xd0, 0xde, 0xad, 0x1b, 0x0a, 0x44, 0xf2, 0x6f, 0xf5, 0xce, 0x8c, + 0x70, 0xd6, 0x67, 0x1b, 0xb2, 0xa5, 0x9f, 0xeb, 0x63, 0x7f, 0x21, 0xdc, +}; + +static const unsigned char dh_public_key_1[] = { + 0xb2, 0xfc, 0xd6, 0x4f, 0xf6, 0x71, 0x5a, 0x33, 0x84, 0x60, 0x4a, 0xe8, + 0x2c, 0x1e, 0x55, 0x4a, 0xdb, 0xd5, 0x18, 0x17, 0x91, 0xa6, 0xf5, 0x70, + 0xcd, 0x23, 0xd7, 0x12, 0x6e, 0x4c, 0xaf, 0x27, 0x9a, 0x4e, 0xf5, 0x37, + 0xea, 0x8f, 0x03, 0xc9, 0x0e, 0x79, 0xc5, 0x8d, 0x37, 0xf8, 0xfb, 0x11, + 0xa1, 0x39, 0x19, 0x9b, 0x5a, 0x3a, 0x66, 0x36, 0x6d, 0xfb, 0xae, 0xed, + 0xfc, 0xa5, 0x90, 0xcb, 0xb3, 0xe1, 0xd5, 0x92, 0x2e, 0xe9, 0x99, 0xbd, + 0x0b, 0x93, 0x82, 0x57, 0xe1, 0xbd, 0x70, 0x17, 0xa7, 0x78, 0x7a, 0x0a, + 0xff, 0x42, 0x06, 0x95, 0x2c, 0x0b, 0x6c, 0x1a, 0x6b, 0x2f, 0x6b, 0xed, + 0x42, 0xa5, 0x60, 0x8a, 0xb0, 0xb5, 0x79, 0x1b, 0xa9, 0xe6, 0x15, 0x17, + 0xa3, 0x6c, 0xe9, 0x84, 0xb3, 0x77, 0x48, 0x9b, 0x7a, 0x4d, 0x04, 0xf6, + 0xb8, 0x27, 0xe5, 0x0c, 0xcb, 0x76, 0xfc, 0x3c, 0x65, 0x49, 0xd7, 0x28, + 0x06, 0x8d, 0x99, 0x18, 0x0f, 0xa7, 0x35, 0xb2, 0x9d, 0x15, 0x35, 0x51, + 0xea, 0x83, 0xb6, 0x4d, 0x14, 0xb0, 0x21, 0xa4, 0x82, 0x1f, 0xb8, 0x73, + 0x2b, 0x15, 0x1d, 0x48, 0x99, 0x9f, 0x32, 0x2c, 0xe1, 0xe1, 0xab, 0x66, + 0x3f, 0xb4, 0x40, 0x79, 0xe8, 0x96, 0xe1, 0x9d, 0x54, 0x8b, 0xb6, 0x7f, + 0x1a, 0x5b, 0x5f, 0x09, 0x9f, 0x40, 0xa7, 0x8b, 0xc8, 0xf6, 0x27, 0x80, +}; + +struct dh_generate_pubkey_test { + const uint8_t *private_key; + uint32_t private_key_size; + const uint8_t *public_key; + uint32_t public_key_size; +}; + +static const struct dh_generate_pubkey_test dh_generate_pubkey_test_data_1 = { + .private_key = dh_private_key_1, + .private_key_size = sizeof(dh_private_key_1), + .public_key = dh_public_key_1, + .public_key_size = sizeof(dh_public_key_1), +}; + +static void wsc_test_dh_generate_pubkey(const void *data) +{ + const struct dh_generate_pubkey_test *test = data; + struct l_key *private; + struct l_key *generator; + struct l_key *prime; + uint8_t public_key[test->private_key_size]; + size_t len; + + generator = l_key_new(L_KEY_RAW, crypto_dh5_generator, + crypto_dh5_generator_size); + assert(generator); + + prime = l_key_new(L_KEY_RAW, crypto_dh5_prime, crypto_dh5_prime_size); + assert(prime); + + private = l_key_new(L_KEY_RAW, test->private_key, + test->private_key_size); + assert(private); + + assert(l_key_compute_dh_public(generator, private, prime, + public_key, &len)); + assert(len == test->public_key_size); + assert(!memcmp(public_key, test->public_key, test->public_key_size)); + + l_key_free(prime); + l_key_free(generator); + l_key_free(private); +} + static const unsigned char eap_wsc_m1[] = { 0x01, 0x00, 0x01, 0x78, 0x02, 0x01, 0x01, 0x78, 0xfe, 0x00, 0x37, 0x2a, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, @@ -555,6 +638,10 @@ int main(int argc, char *argv[]) l_test_add("/wsc/gen_uuid/1", wsc_test_uuid_from_addr, &uuid_from_addr_data_1); + l_test_add("/wsc/diffie-hellman/generate pubkey", + wsc_test_dh_generate_pubkey, + &dh_generate_pubkey_test_data_1); + l_test_add("/wsc/parse/m1 1", wsc_test_parse_m1, &m1_data_1); return l_test_run();