* [PATCH 4/4] unit: add unit test for DPP crypto operations
@ 2021-12-06 21:03 James Prestwood
0 siblings, 0 replies; 2+ messages in thread
From: James Prestwood @ 2021-12-06 21:03 UTC (permalink / raw)
To: iwd
[-- Attachment #1: Type: text/plain, Size: 6625 bytes --]
---
Makefile.am | 7 ++-
unit/test-dpp.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 153 insertions(+), 1 deletion(-)
create mode 100644 unit/test-dpp.c
diff --git a/Makefile.am b/Makefile.am
index 25269a0d..5e33a48f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -394,7 +394,8 @@ unit_tests = unit/test-cmac-aes \
unit/test-crypto unit/test-eapol unit/test-mpdu \
unit/test-ie unit/test-util unit/test-ssid-security \
unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \
- unit/test-eap-sim unit/test-sae unit/test-p2p unit/test-band
+ unit/test-eap-sim unit/test-sae unit/test-p2p unit/test-band \
+ unit/test-dpp
if CLIENT
unit_tests += unit/test-client
@@ -547,6 +548,10 @@ unit_test_p2p_SOURCES = unit/test-p2p.c src/wscutil.h src/wscutil.c \
src/band.h src/band.c
unit_test_p2p_LDADD = $(ell_ldadd)
+unit_test_dpp_SOURCES = unit/test-dpp.c src/dpp-util.h src/dpp-util.c \
+ src/util.h src/util.c src/crypto.h src/crypto.c
+unit_test_dpp_LDADD = $(ell_ldadd)
+
TESTS = $(unit_tests)
EXTRA_DIST = src/genbuiltin src/iwd.service.in src/net.connman.iwd.service \
diff --git a/unit/test-dpp.c b/unit/test-dpp.c
new file mode 100644
index 00000000..d687bba0
--- /dev/null
+++ b/unit/test-dpp.c
@@ -0,0 +1,147 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 2021 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <ell/ell.h>
+
+#include "src/dpp-util.h"
+#include "src/util.h"
+
+/*
+ * B.2 Test Vectors for DPP Authentication Using P-256 for
+ * Responder-only Authentication
+ */
+const char *i_proto_public_bytes = "50a532ae2a07207276418d2fa630295d45569be425aa634f02014d00a7d1f61a";
+const char *r_boot_public_bytes = "09c585a91b4df9fd25a045201885c39cc5cfae397ddaeda957dec57fa0e3503f";
+const char *r_boot_private_bytes = "54ce181a98525f217216f59b245f60e9df30ac7f6b26c939418cfc3c42d1afa0";
+const char *r_proto_private_bytes = "f798ed2e19286f6a6efe210b1863badb99af2a14b497634dbfd2a97394fb5aa5";
+const char *r_proto_public_bytes = "5e3fb3576884887f17c3203d8a3a6c2fac722ef0e2201b61ac73bc655c709a90";
+const char *k1_bytes = "3d832a02ed6d7fc1dc96d2eceab738cf01c0028eb256be33d5a21a720bfcf949";
+const char *k2_bytes = "ca08bdeeef838ddf897a5f01f20bb93dc5a895cb86788ca8c00a7664899bc310";
+const char *ke_bytes = "c8882a8ab30c878467822534138c704ede0ab1e873fe03b601a7908463fec87a";
+const char *mx_bytes = "dde2878117d69745be4f916a2dd14269d783d1d788c603bb8746beabbd1dbbbc";
+const char *nx_bytes = "92118478b75c21c2c59340c842b5bce560a535f60bc37a75fe390d738c58d8e8";
+const char *i_nonce_bytes = "13f4602a16daeb69712263b9c46cba31";
+const char *r_nonce_bytes = "3d0cfb011ca916d796f7029ff0b43393";
+const char *i_auth_bytes = "787d1189b526448d2901e7f6c22775ce514fce52fc886c1e924f2fbb8d97b210";
+const char *r_auth_bytes = "43509ef7137d8c2fbe66d802ae09dedd94d41b8cbfafb4954782014ff4a3f91c";
+
+#define HEX2BUF(s, buf, _len) { \
+ unsigned char *_tmp = l_util_from_hexstring(s, NULL); \
+ memcpy(buf, _tmp, _len); \
+ l_free(_tmp); \
+}
+
+#define CHECK_FROM_STR(str, bytes, __len) \
+({ \
+ uint64_t __tmp[L_ECC_MAX_DIGITS]; \
+ HEX2BUF(str, __tmp, __len); \
+ assert(!memcmp(bytes, __tmp, __len)); \
+})
+
+static void test_key_derivation(const void *data)
+{
+ uint64_t tmp[L_ECC_MAX_DIGITS];
+ const struct l_ecc_curve *curve = l_ecc_curve_from_ike_group(19);
+ struct l_ecc_point *i_proto_public;
+ struct l_ecc_point *r_boot_public;
+ struct l_ecc_scalar *r_boot_private;
+ struct l_ecc_scalar *r_proto_private;
+ struct l_ecc_point *r_proto_public;
+ struct l_ecc_scalar *m, *n;
+ uint64_t k1[L_ECC_MAX_DIGITS];
+ uint64_t k2[L_ECC_MAX_DIGITS];
+ uint64_t ke[L_ECC_MAX_DIGITS];
+ uint8_t i_nonce[16];
+ uint8_t r_nonce[16];
+ uint64_t r_auth[L_ECC_MAX_DIGITS];
+ uint64_t i_auth[L_ECC_MAX_DIGITS];
+
+ HEX2BUF(i_proto_public_bytes, tmp, 32);
+ i_proto_public = l_ecc_point_from_data(curve,
+ L_ECC_POINT_TYPE_COMPLIANT,
+ tmp, 32);
+ assert(i_proto_public);
+
+ HEX2BUF(r_boot_public_bytes, tmp, 32);
+ r_boot_public = l_ecc_point_from_data(curve,
+ L_ECC_POINT_TYPE_COMPLIANT,
+ tmp, 32);
+ assert(r_boot_public);
+
+ HEX2BUF(r_proto_public_bytes, tmp, 32);
+ r_proto_public = l_ecc_point_from_data(curve,
+ L_ECC_POINT_TYPE_COMPLIANT,
+ tmp, 32);
+ assert(r_proto_public);
+
+ HEX2BUF(r_boot_private_bytes, tmp, 32);
+ r_boot_private = l_ecc_scalar_new(curve, tmp, 32);
+ assert(r_boot_private);
+
+ HEX2BUF(r_proto_private_bytes, tmp, 32);
+ r_proto_private = l_ecc_scalar_new(curve, tmp, 32);
+ assert(r_proto_private);
+
+ m = dpp_derive_k1(i_proto_public, r_boot_private, k1);
+ assert(m);
+
+ CHECK_FROM_STR(k1_bytes, k1, 32);
+ l_ecc_scalar_get_data(m, tmp, sizeof(tmp));
+ CHECK_FROM_STR(mx_bytes, tmp, 32);
+
+ n = dpp_derive_k2(i_proto_public, r_proto_private, k2);
+ assert(n);
+
+ CHECK_FROM_STR(k2_bytes, k2, 32);
+ l_ecc_scalar_get_data(n, tmp, sizeof(tmp));
+ CHECK_FROM_STR(nx_bytes, tmp, 32);
+
+ HEX2BUF(i_nonce_bytes, i_nonce, 16);
+ HEX2BUF(r_nonce_bytes, r_nonce, 16);
+ dpp_derive_ke(i_nonce, r_nonce, m, n, ke);
+
+ CHECK_FROM_STR(ke_bytes, ke, 32);
+
+ dpp_derive_r_auth(i_nonce, r_nonce, 16, i_proto_public, r_proto_public,
+ r_boot_public, r_auth);
+ CHECK_FROM_STR(r_auth_bytes, r_auth, 32);
+
+ dpp_derive_i_auth(r_nonce, i_nonce, 16, r_proto_public, i_proto_public,
+ r_boot_public, i_auth);
+ CHECK_FROM_STR(i_auth_bytes, i_auth, 32);
+}
+
+int main(int argc, char *argv[])
+{
+ l_test_init(&argc, &argv);
+
+ l_test_add("DPP test key derivation", test_key_derivation, NULL);
+
+ return l_test_run();
+}
--
2.31.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 4/4] unit: add unit test for DPP crypto operations
@ 2021-12-06 22:37 Denis Kenzior
0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-12-06 22:37 UTC (permalink / raw)
To: iwd
[-- Attachment #1: Type: text/plain, Size: 1464 bytes --]
Hi James,
On 12/6/21 3:03 PM, James Prestwood wrote:
> ---
> Makefile.am | 7 ++-
> unit/test-dpp.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 153 insertions(+), 1 deletion(-)
> create mode 100644 unit/test-dpp.c
>
<snip>
> @@ -547,6 +548,10 @@ unit_test_p2p_SOURCES = unit/test-p2p.c src/wscutil.h src/wscutil.c \
> src/band.h src/band.c
> unit_test_p2p_LDADD = $(ell_ldadd)
>
> +unit_test_dpp_SOURCES = unit/test-dpp.c src/dpp-util.h src/dpp-util.c \
> + src/util.h src/util.c src/crypto.h src/crypto.c
I had to add src/band.[ch] here
> +unit_test_dpp_LDADD = $(ell_ldadd)
> +
> TESTS = $(unit_tests)
>
> EXTRA_DIST = src/genbuiltin src/iwd.service.in src/net.connman.iwd.service \
<snip>
> +const char *i_proto_public_bytes = "50a532ae2a07207276418d2fa630295d45569be425aa634f02014d00a7d1f61a";
I changed some of these data lines to be 80 char / line compliant.
Applied, but I'm seeing this:
TEST: DPP test key derivation
=================================================================
==17289==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 536 byte(s) in 7 object(s) allocated from:
#0 0x7f88cc96d0f8 in __interceptor_malloc
(/usr/lib/gcc/x86_64-pc-linux-gnu/9.4.0/libasan.so.5+0x10c0f8)
#1 0x4199d2 in l_malloc ell/util.c:62
SUMMARY: AddressSanitizer: 536 byte(s) leaked in 7 allocation(s).
Regards,
-Denis
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-06 22:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-06 21:03 [PATCH 4/4] unit: add unit test for DPP crypto operations James Prestwood
-- strict thread matches above, loose matches on Subject: below --
2021-12-06 22:37 Denis Kenzior
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox