]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - src/common/common_module_tests.c
Add attribute for dwell time in QCA vendor scan
[thirdparty/hostap.git] / src / common / common_module_tests.c
index 30c52476bbed8a3f622ea50be76dbd7a445980fd..7694c96b4393f6c764f6d7a32644f5780957d766 100644 (file)
@@ -11,6 +11,7 @@
 #include "utils/common.h"
 #include "utils/module_tests.h"
 #include "crypto/crypto.h"
+#include "crypto/dh_groups.h"
 #include "ieee802_11_common.h"
 #include "ieee802_11_defs.h"
 #include "gas.h"
@@ -258,6 +259,7 @@ static int sae_tests(void)
        /* IEEE P802.11-REVmd/D2.1, Annex J.10 */
        const u8 addr1[ETH_ALEN] = { 0x82, 0x7b, 0x91, 0x9d, 0xd4, 0xb9 };
        const u8 addr2[ETH_ALEN] = { 0x1e, 0xec, 0x49, 0xea, 0x64, 0x88 };
+       const char *ssid = "byteme";
        const char *pw = "mekmitasdigoat";
        const char *pwid = "psk4internet";
        const u8 local_rand[] = {
@@ -338,6 +340,72 @@ static int sae_tests(void)
        };
        struct wpabuf *buf = NULL;
        struct crypto_bignum *mask = NULL;
+       const u8 pwe_19_x[32] = {
+               0xc9, 0x30, 0x49, 0xb9, 0xe6, 0x40, 0x00, 0xf8,
+               0x48, 0x20, 0x16, 0x49, 0xe9, 0x99, 0xf2, 0xb5,
+               0xc2, 0x2d, 0xea, 0x69, 0xb5, 0x63, 0x2c, 0x9d,
+               0xf4, 0xd6, 0x33, 0xb8, 0xaa, 0x1f, 0x6c, 0x1e
+       };
+       const u8 pwe_19_y[32] = {
+               0x73, 0x63, 0x4e, 0x94, 0xb5, 0x3d, 0x82, 0xe7,
+               0x38, 0x3a, 0x8d, 0x25, 0x81, 0x99, 0xd9, 0xdc,
+               0x1a, 0x5e, 0xe8, 0x26, 0x9d, 0x06, 0x03, 0x82,
+               0xcc, 0xbf, 0x33, 0xe6, 0x14, 0xff, 0x59, 0xa0
+       };
+       const u8 pwe_15[384] = {
+               0x69, 0x68, 0x73, 0x65, 0x8f, 0x65, 0x31, 0x42,
+               0x9f, 0x97, 0x39, 0x6f, 0xb8, 0x5f, 0x89, 0xe1,
+               0xfc, 0xd2, 0xf6, 0x92, 0x19, 0xa9, 0x0e, 0x82,
+               0x2f, 0xf7, 0xf4, 0xbc, 0x0b, 0xd8, 0xa7, 0x9f,
+               0xf0, 0x80, 0x35, 0x31, 0x6f, 0xca, 0xe1, 0xa5,
+               0x39, 0x77, 0xdc, 0x11, 0x2b, 0x0b, 0xfe, 0x2e,
+               0x6f, 0x65, 0x6d, 0xc7, 0xd4, 0xa4, 0x5b, 0x08,
+               0x1f, 0xd9, 0xbb, 0xe2, 0x22, 0x85, 0x31, 0x81,
+               0x79, 0x70, 0xbe, 0xa1, 0x66, 0x58, 0x4a, 0x09,
+               0x3c, 0x57, 0x34, 0x3c, 0x9d, 0x57, 0x8f, 0x42,
+               0x58, 0xd0, 0x39, 0x81, 0xdb, 0x8f, 0x79, 0xa2,
+               0x1b, 0x01, 0xcd, 0x27, 0xc9, 0xae, 0xcf, 0xcb,
+               0x9c, 0xdb, 0x1f, 0x84, 0xb8, 0x88, 0x4e, 0x8f,
+               0x50, 0x66, 0xb4, 0x29, 0x83, 0x1e, 0xb9, 0x89,
+               0x0c, 0xa5, 0x47, 0x21, 0xba, 0x10, 0xd5, 0xaa,
+               0x1a, 0x80, 0xce, 0xf1, 0x4c, 0xad, 0x16, 0xda,
+               0x57, 0xb2, 0x41, 0x8a, 0xbe, 0x4b, 0x8c, 0xb0,
+               0xb2, 0xeb, 0xf7, 0xa8, 0x0e, 0x3e, 0xcf, 0x22,
+               0x8f, 0xd8, 0xb6, 0xdb, 0x79, 0x9c, 0x9b, 0x80,
+               0xaf, 0xd7, 0x14, 0xad, 0x51, 0x82, 0xf4, 0x64,
+               0xb6, 0x3f, 0x4c, 0x6c, 0xe5, 0x3f, 0xaa, 0x6f,
+               0xbf, 0x3d, 0xc2, 0x3f, 0x77, 0xfd, 0xcb, 0xe1,
+               0x9c, 0xe3, 0x1e, 0x8a, 0x0e, 0x97, 0xe2, 0x2b,
+               0xe2, 0xdd, 0x37, 0x39, 0x88, 0xc2, 0x8e, 0xbe,
+               0xfa, 0xac, 0x3d, 0x5b, 0x62, 0x2e, 0x1e, 0x74,
+               0xa0, 0x9a, 0xf8, 0xed, 0xfa, 0xe1, 0xce, 0x9c,
+               0xab, 0xbb, 0xdc, 0x36, 0xb1, 0x28, 0x46, 0x3c,
+               0x7e, 0xa8, 0xbd, 0xb9, 0x36, 0x4c, 0x26, 0x75,
+               0xe0, 0x17, 0x73, 0x1f, 0xe0, 0xfe, 0xf6, 0x49,
+               0xfa, 0xa0, 0x45, 0xf4, 0x44, 0x05, 0x20, 0x27,
+               0x25, 0xc2, 0x99, 0xde, 0x27, 0x8b, 0x70, 0xdc,
+               0x54, 0x60, 0x90, 0x02, 0x1e, 0x29, 0x97, 0x9a,
+               0xc4, 0xe7, 0xb6, 0xf5, 0x8b, 0xae, 0x7c, 0x34,
+               0xaa, 0xef, 0x9b, 0xc6, 0x30, 0xf2, 0x80, 0x8d,
+               0x80, 0x78, 0xc2, 0x55, 0x63, 0xa0, 0xa1, 0x38,
+               0x70, 0xfb, 0xf4, 0x74, 0x8d, 0xcd, 0x87, 0x90,
+               0xb4, 0x54, 0xc3, 0x75, 0xdf, 0x10, 0xc5, 0xb6,
+               0xb2, 0x08, 0x59, 0x61, 0xe6, 0x68, 0xa5, 0x82,
+               0xf8, 0x8f, 0x47, 0x30, 0x43, 0xb4, 0xdc, 0x31,
+               0xfc, 0xbc, 0x69, 0xe7, 0xb4, 0x94, 0xb0, 0x6a,
+               0x60, 0x59, 0x80, 0x2e, 0xd3, 0xa4, 0xe8, 0x97,
+               0xa2, 0xa3, 0xc9, 0x08, 0x4b, 0x27, 0x6c, 0xc1,
+               0x37, 0xe8, 0xfc, 0x5c, 0xe2, 0x54, 0x30, 0x3e,
+               0xf8, 0xfe, 0xa2, 0xfc, 0xbb, 0xbd, 0x88, 0x6c,
+               0x92, 0xa3, 0x2a, 0x40, 0x7a, 0x2c, 0x22, 0x38,
+               0x8c, 0x86, 0x86, 0xfe, 0xb9, 0xd4, 0x6b, 0xd6,
+               0x47, 0x88, 0xa7, 0xf6, 0x8e, 0x0f, 0x14, 0xad,
+               0x1e, 0xac, 0xcf, 0x33, 0x01, 0x99, 0xc1, 0x62
+       };
+       int pt_groups[] = { 19, 20, 21, 25, 26, 28, 29, 30, 15, 0 };
+       struct sae_pt *pt_info, *pt;
+       const u8 addr1b[ETH_ALEN] = { 0x00, 0x09, 0x5b, 0x66, 0xec, 0x1e };
+       const u8 addr2b[ETH_ALEN] = { 0x00, 0x0b, 0x6b, 0xd9, 0x02, 0x46 };
 
        os_memset(&sae, 0, sizeof(sae));
        buf = wpabuf_alloc(1000);
@@ -377,7 +445,7 @@ static int sae_tests(void)
        }
 
        if (sae_parse_commit(&sae, peer_commit, sizeof(peer_commit), NULL, NULL,
-                   NULL) != 0 ||
+                            NULL, 0) != 0 ||
            sae_process_commit(&sae) < 0)
                goto fail;
 
@@ -411,6 +479,62 @@ static int sae_tests(void)
        if (sae_check_confirm(&sae, peer_confirm, sizeof(peer_confirm)) < 0)
                goto fail;
 
+       pt_info = sae_derive_pt(pt_groups,
+                               (const u8 *) ssid, os_strlen(ssid),
+                               (const u8 *) pw, os_strlen(pw), pwid);
+       if (!pt_info)
+               goto fail;
+
+       for (pt = pt_info; pt; pt = pt->next) {
+               if (pt->group == 19) {
+                       struct crypto_ec_point *pwe;
+                       u8 bin[SAE_MAX_ECC_PRIME_LEN * 2];
+                       size_t prime_len = sizeof(pwe_19_x);
+
+                       pwe = sae_derive_pwe_from_pt_ecc(pt, addr1b, addr2b);
+                       if (!pwe) {
+                               sae_deinit_pt(pt);
+                               goto fail;
+                       }
+                       if (crypto_ec_point_to_bin(pt->ec, pwe, bin,
+                                                  bin + prime_len) < 0 ||
+                           os_memcmp(pwe_19_x, bin, prime_len) != 0 ||
+                           os_memcmp(pwe_19_y, bin + prime_len,
+                                     prime_len) != 0) {
+                               wpa_printf(MSG_ERROR,
+                                          "SAE: PT/PWE test vector mismatch");
+                               crypto_ec_point_deinit(pwe, 1);
+                               sae_deinit_pt(pt);
+                               goto fail;
+                       }
+                       crypto_ec_point_deinit(pwe, 1);
+               }
+
+               if (pt->group == 15) {
+                       struct crypto_bignum *pwe;
+                       u8 bin[SAE_MAX_PRIME_LEN];
+                       size_t prime_len = sizeof(pwe_15);
+
+                       pwe = sae_derive_pwe_from_pt_ffc(pt, addr1b, addr2b);
+                       if (!pwe) {
+                               sae_deinit_pt(pt);
+                               goto fail;
+                       }
+                       if (crypto_bignum_to_bin(pwe, bin, sizeof(bin),
+                                                prime_len) < 0 ||
+                           os_memcmp(pwe_15, bin, prime_len) != 0) {
+                               wpa_printf(MSG_ERROR,
+                                          "SAE: PT/PWE test vector mismatch");
+                               crypto_bignum_deinit(pwe, 1);
+                               sae_deinit_pt(pt);
+                               goto fail;
+                       }
+                       crypto_bignum_deinit(pwe, 1);
+               }
+       }
+
+       sae_deinit_pt(pt_info);
+
        ret = 0;
 fail:
        sae_clear_data(&sae);