1 The code for hostapd-mbedtls did not work when used for OWE association.
3 When handling association requests, the buffer offsets and length assumptions were incorrect, leading to never calculating the y point, thus denying association.
5 Also when crafting the association response, the buffer contained the trailing key-type.
7 Fix up both issues to adhere to the specification and make hostapd-mbedtls work with the OWE security type.
9 --- a/src/crypto/crypto_mbedtls.c
10 +++ b/src/crypto/crypto_mbedtls.c
11 @@ -2299,25 +2299,30 @@ struct crypto_ecdh * crypto_ecdh_init2(i
12 struct wpabuf * crypto_ecdh_get_pubkey(struct crypto_ecdh *ecdh, int inc_y)
14 mbedtls_ecp_group *grp = &ecdh->grp;
15 - size_t len = CRYPTO_EC_plen(grp);
16 + size_t prime_len = CRYPTO_EC_plen(grp);
17 + size_t output_len = prime_len;
18 + u8 output_offset = 0;
21 #ifdef MBEDTLS_ECP_MONTGOMERY_ENABLED
24 #ifdef MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED
25 - if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS)
26 - len = inc_y ? len*2+1 : len+1;
27 + if (mbedtls_ecp_get_type(grp) == MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS) {
28 + output_len = inc_y ? prime_len * 2 + 1 : prime_len + 1;
32 - struct wpabuf *buf = wpabuf_alloc(len);
35 + if (output_len > sizeof(buf))
38 inc_y = inc_y ? MBEDTLS_ECP_PF_UNCOMPRESSED : MBEDTLS_ECP_PF_COMPRESSED;
39 - if (mbedtls_ecp_point_write_binary(grp, &ecdh->Q, inc_y, &len,
40 - wpabuf_mhead_u8(buf), len) == 0) {
41 - wpabuf_put(buf, len);
43 + if (mbedtls_ecp_point_write_binary(grp, &ecdh->Q, inc_y, &output_len,
44 + buf, output_len) == 0) {
45 + return wpabuf_alloc_copy(buf + output_offset, output_len - output_offset);
52 @@ -2379,10 +2384,7 @@ struct wpabuf * crypto_ecdh_set_peerkey(
53 os_memcpy(buf+2, key, len);
55 len >>= 1; /*(repurpose len to prime_len)*/
57 - else if (key[0] == 0x02 || key[0] == 0x03) { /* (inc_y == 0) */
58 - --len; /*(repurpose len to prime_len)*/
60 + } else { /* (inc_y == 0) */
61 /* mbedtls_ecp_point_read_binary() does not currently support
62 * MBEDTLS_ECP_PF_COMPRESSED format (buf[1] = 0x02 or 0x03)
63 * (returns MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) */
64 @@ -2390,22 +2392,21 @@ struct wpabuf * crypto_ecdh_set_peerkey(
65 /* derive y, amend buf[] with y for UNCOMPRESSED format */
66 if (sizeof(buf)-2 < len*2 || len == 0)
69 buf[0] = (u8)(1+len*2);
71 + os_memcpy(buf+2, key, len);
74 mbedtls_mpi_init(&bn);
75 - int ret = mbedtls_mpi_read_binary(&bn, key+1, len)
76 - || crypto_mbedtls_short_weierstrass_derive_y(grp, &bn,
78 + int ret = mbedtls_mpi_read_binary(&bn, key, len)
79 + || crypto_mbedtls_short_weierstrass_derive_y(grp, &bn, 0)
80 || mbedtls_mpi_write_binary(&bn, buf+2+len, len);
81 mbedtls_mpi_free(&bn);
86 - if (key[0] == 0) /*(repurpose len to prime_len)*/
87 - len = CRYPTO_EC_plen(grp);
89 if (mbedtls_ecdh_read_public(&ecdh->ctx, buf, buf[0]+1))