]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Module test for SAE hash-to-element crypto routines
authorJouni Malinen <jouni@codeaurora.org>
Tue, 27 Aug 2019 13:33:15 +0000 (16:33 +0300)
committerJouni Malinen <j@w1.fi>
Tue, 15 Oct 2019 12:39:22 +0000 (15:39 +0300)
Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
src/common/common_module_tests.c

index 0263709ecdb8ce03cccfb11e7fcb46bf8d97db04..fb0cf43e31c836564d7a0b48c36ba8c7bc93253b 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] = {
+               0x19, 0xd3, 0x37, 0xc9, 0x30, 0x79, 0x2b, 0x47,
+               0x2b, 0x14, 0x5f, 0xc1, 0x5b, 0x98, 0x64, 0x0a,
+               0x0e, 0x7d, 0x3b, 0xb0, 0x7d, 0xc0, 0xad, 0xee,
+               0x6f, 0xc9, 0xdf, 0x75, 0xde, 0xc2, 0xd6, 0x94
+       };
+       const u8 pwe_19_y[32] = {
+               0xb7, 0x8a, 0x02, 0x39, 0x20, 0x29, 0xe7, 0xf4,
+               0x52, 0x41, 0x3d, 0x35, 0x8c, 0x88, 0xd9, 0x16,
+               0xc8, 0x90, 0xba, 0x40, 0xd9, 0x93, 0xe3, 0x2d,
+               0xd0, 0x0f, 0xfb, 0x58, 0xee, 0x62, 0x74, 0x98
+       };
+       const u8 pwe_15[384] = {
+               0x59, 0x00, 0x9a, 0x32, 0xbb, 0x37, 0x84, 0x60,
+               0x27, 0xeb, 0x70, 0x20, 0x57, 0x34, 0xf1, 0xb4,
+               0xde, 0x1b, 0x48, 0xfc, 0x0e, 0xa5, 0xb8, 0x65,
+               0xb1, 0xa0, 0xd4, 0xb9, 0x42, 0x1d, 0x6d, 0xdf,
+               0x8b, 0x86, 0xeb, 0x4a, 0x2c, 0x2e, 0x38, 0x06,
+               0x52, 0xae, 0x67, 0x39, 0xed, 0x7d, 0x0c, 0xd0,
+               0xea, 0x30, 0x6e, 0x50, 0xe7, 0xb1, 0x8d, 0x91,
+               0xf0, 0x05, 0x1f, 0x16, 0xf5, 0x45, 0xa7, 0x37,
+               0x21, 0x0d, 0x8a, 0x69, 0x9a, 0xd1, 0xf1, 0x8c,
+               0x2b, 0xbb, 0xd8, 0x21, 0xa2, 0x8f, 0xcc, 0xd1,
+               0x35, 0x98, 0x66, 0xf3, 0x3c, 0x03, 0xba, 0x70,
+               0x72, 0x4e, 0xe4, 0x23, 0xb5, 0x2e, 0x96, 0x5f,
+               0xdd, 0xd1, 0xae, 0x71, 0xb1, 0xc1, 0x4b, 0x69,
+               0x4e, 0x60, 0x0a, 0x08, 0x02, 0xa1, 0x6e, 0x80,
+               0x68, 0x0a, 0xe7, 0x97, 0x9f, 0x5b, 0xbf, 0xa8,
+               0x77, 0xda, 0x5b, 0x26, 0x13, 0x0a, 0xab, 0x92,
+               0x79, 0x87, 0xa3, 0x85, 0x78, 0x74, 0xae, 0xae,
+               0x01, 0xf0, 0x31, 0x8a, 0xc3, 0x96, 0xce, 0xaa,
+               0x57, 0xbf, 0xb3, 0x57, 0xce, 0x2d, 0x2d, 0x36,
+               0xda, 0x02, 0x5b, 0x12, 0xeb, 0xff, 0x13, 0x00,
+               0x9e, 0xf7, 0xae, 0xe0, 0x47, 0xa4, 0x5d, 0x0a,
+               0x88, 0x65, 0xbc, 0x66, 0x23, 0x3e, 0xf2, 0xf1,
+               0xa0, 0x64, 0x5c, 0x6b, 0xdc, 0x81, 0xe9, 0x3c,
+               0x46, 0x4f, 0x83, 0xcf, 0x9f, 0x55, 0x33, 0x8f,
+               0xaa, 0x60, 0x4b, 0xd7, 0x21, 0x73, 0x6b, 0xdb,
+               0x26, 0xad, 0x2f, 0xb7, 0xe2, 0x42, 0x56, 0x33,
+               0xdb, 0xd6, 0xb2, 0x3a, 0x7d, 0x75, 0x87, 0xda,
+               0x86, 0xc4, 0xe9, 0x41, 0x8d, 0x63, 0x19, 0x8e,
+               0x8b, 0x17, 0x95, 0xfe, 0x2b, 0x96, 0xa0, 0x38,
+               0xf1, 0xe2, 0x1d, 0x42, 0xa9, 0xe3, 0x8a, 0xa1,
+               0x61, 0x62, 0x10, 0xf8, 0xb3, 0xb2, 0x2c, 0x7b,
+               0xdf, 0xba, 0x74, 0xb2, 0x5b, 0xf6, 0xa9, 0xae,
+               0x1d, 0x21, 0x0d, 0xc0, 0x48, 0x20, 0xfc, 0x28,
+               0xf6, 0x22, 0xd2, 0xf6, 0x9c, 0x71, 0x3f, 0x9f,
+               0x32, 0xd6, 0xbb, 0x9b, 0xd3, 0x87, 0x25, 0xcf,
+               0x62, 0xd1, 0x68, 0xba, 0x55, 0x3b, 0x74, 0x2b,
+               0x1d, 0x5a, 0xe4, 0x94, 0x59, 0x3b, 0x13, 0x21,
+               0x15, 0x87, 0x3b, 0x09, 0x0e, 0xcf, 0x35, 0x60,
+               0x04, 0xa8, 0xde, 0xa1, 0x09, 0xca, 0xb8, 0x35,
+               0x1e, 0x16, 0x61, 0xed, 0xa1, 0x1f, 0x8c, 0x92,
+               0x83, 0xa5, 0x27, 0x92, 0xf2, 0x80, 0xc3, 0xcb,
+               0xdd, 0x3c, 0x0c, 0xf5, 0x8d, 0x69, 0xb3, 0xe4,
+               0xd5, 0x49, 0x4d, 0x62, 0xcb, 0xb8, 0xe3, 0x9f,
+               0x89, 0xb5, 0x57, 0xff, 0xef, 0x12, 0x37, 0x05,
+               0xb6, 0x35, 0xe5, 0xc6, 0xd9, 0x23, 0xe2, 0xeb,
+               0xe4, 0x0d, 0x1a, 0x30, 0x8f, 0x73, 0x70, 0x3a,
+               0xef, 0x5a, 0xd1, 0x8c, 0x18, 0x34, 0x1e, 0xf0,
+               0xb9, 0x08, 0x57, 0xab, 0xcb, 0x5c, 0x87, 0x10
+       };
+       int pt_groups[] = { 19, 20, 21, 25, 26, 28, 29, 30, 15, 0 };
+       struct sae_pt *pt_info, *pt;
+       u8 addr1b[ETH_ALEN] = { 0x3b, 0x36, 0xc2, 0x8b, 0x83, 0x03 };
+       u8 addr2b[ETH_ALEN] = { 0x58, 0x36, 0xc0, 0x64, 0x2d, 0x31 };
 
        os_memset(&sae, 0, sizeof(sae));
        buf = wpabuf_alloc(1000);
@@ -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);