[PATCH] tls: Use a new marshalling API for uncompressed EC points
Xiangfei Ding
xfding at google.com
Fri Nov 27 02:28:51 PST 2026
After reviewing the specification, we concluded that it is better to
offer a safe API for wpa_supplicant to serialize EC points in
uncompressed point form in hope for improving maintainability.
Signed-off-by: Xiangfei Ding <xfding at google.com>
---
src/crypto/crypto_openssl.c | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/src/crypto/crypto_openssl.c b/src/crypto/crypto_openssl.c
index f67d46e9e..2f89a3071 100644
--- a/src/crypto/crypto_openssl.c
+++ b/src/crypto/crypto_openssl.c
@@ -31,6 +31,9 @@
#else /* OpenSSL version >= 3.0 */
#include <openssl/cmac.h>
#endif /* OpenSSL version >= 3.0 */
+#ifdef OPENSSL_IS_BORINGSSL
+#include <openssl/bytestring.h>
+#endif /* OPENSSL_IS_BORINGSSL */
#ifdef CONFIG_DPP3
#if OPENSSL_VERSION_NUMBER >= 0x30200000L
#include <openssl/hpke.h>
@@ -3667,7 +3670,7 @@ void crypto_ec_key_deinit(struct crypto_ec_key *key)
}
-#ifdef OPENSSL_IS_BORINGSSL
+#if defined(OPENSSL_IS_BORINGSSL) && BORINGSSL_API_VERSION < 45
/* BoringSSL version of i2d_PUBKEY() always outputs public EC key using
* uncompressed form so define a custom function to export EC pubkey using
@@ -3691,7 +3694,7 @@ ASN1_SEQUENCE(EC_COMP_PUBKEY) = {
IMPLEMENT_ASN1_FUNCTIONS(EC_COMP_PUBKEY);
-#endif /* OPENSSL_IS_BORINGSSL */
+#endif /* OPENSSL_IS_BORINGSSL && BORINGSSL_API_VERSION < 45 */
struct wpabuf * crypto_ec_key_get_subject_public_key(struct crypto_ec_key *key)
@@ -3743,8 +3746,28 @@ struct wpabuf * crypto_ec_key_get_subject_public_key(struct crypto_ec_key *key)
EVP_PKEY_free(copy);
return buf;
-#else /* OpenSSL version >= 3.0 */
-#ifdef OPENSSL_IS_BORINGSSL
+#elif defined(OPENSSL_IS_BORINGSSL) && BORINGSSL_API_VERSION >= 45
+ CBB cbb;
+ uint8_t *der = NULL;
+ size_t der_len = 0;
+ struct wpabuf *ret;
+
+ CBB_zero(&cbb);
+ if (!CBB_init(&cbb, 0) ||
+ !EVP_marshal_public_key_with_ec_point_format(
+ &cbb, pkey, POINT_CONVERSION_COMPRESSED) ||
+ !CBB_finish(&cbb, &der, &der_len)) {
+ wpa_printf(MSG_ERROR,
+ "BoringSSL: Failed to build DER encoded public key: %s",
+ ERR_error_string(ERR_get_error(), NULL));
+ CBB_cleanup(&cbb);
+ return NULL;
+ }
+
+ ret = wpabuf_alloc_copy(der, der_len);
+ OPENSSL_free(der);
+ return ret;
+#elif defined(OPENSSL_IS_BORINGSSL)
unsigned char *der = NULL;
int der_len;
const EC_KEY *eckey;
@@ -3805,7 +3828,7 @@ fail:
OPENSSL_free(der);
BN_CTX_free(ctx);
return ret;
-#else /* OPENSSL_IS_BORINGSSL */
+#else /* OpenSSL version >= 3.0 */
unsigned char *der = NULL;
int der_len;
struct wpabuf *buf;
@@ -3829,7 +3852,6 @@ fail:
buf = wpabuf_alloc_copy(der, der_len);
OPENSSL_free(der);
return buf;
-#endif /* OPENSSL_IS_BORINGSSL */
#endif /* OpenSSL version >= 3.0 */
}
--
2.56.1.839.g22a8290db9-goog
More information about the Hostap
mailing list