Skip to content

Commit a50c3c2

Browse files
krish2718cursoragent
authored andcommitted
[noup] crypto: Guard EC point ops when ECP curves are disabled
TF-PSA-Crypto only defines MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED and exposes mbedtls_ecp_muladd() when at least one Weierstrass or Montgomery curve is enabled via MBEDTLS_ECP_DP_*_ENABLED. WPA3/SAE enables CRYPTO_MBEDTLS_CRYPTO_EC without always selecting PSA_WANT_ECC_SECP_*, so azure_iot_hub-style builds (WIFI_NM_WPA_SUPPLICANT_WPA3, MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS, PSA_WANT_ALG_ECDH/ECDSA only) can compile crypto_ec_point_from_bin() and crypto_ec_point_add() with no matching curve support and trigger -Wunused-variable and implicit declaration errors. Wrap the helpers in the same MBEDTLS_ECP_*_ENABLED guards used in private/ecp.h and return failure when the builtins are not available. Assisted-by: Cursor: Auto Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c2d85cb commit a50c3c2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/crypto/crypto_mbedtls_alt.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,9 +2303,13 @@ struct crypto_ec_point *crypto_ec_point_from_bin(struct crypto_ec *e, const u8 *
23032303
if (TEST_FAIL())
23042304
return NULL;
23052305

2306+
#if !defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED) && !defined(MBEDTLS_ECP_MONTGOMERY_ENABLED)
2307+
return NULL;
2308+
#else
23062309
size_t len = CRYPTO_EC_plen(e);
23072310
mbedtls_ecp_point *p = os_malloc(sizeof(*p));
23082311
u8 buf[1 + MBEDTLS_MPI_MAX_SIZE * 2];
2312+
23092313
if (p == NULL)
23102314
return NULL;
23112315
mbedtls_ecp_point_init(p);
@@ -2336,6 +2340,7 @@ struct crypto_ec_point *crypto_ec_point_from_bin(struct crypto_ec *e, const u8 *
23362340
mbedtls_ecp_point_free(p);
23372341
os_free(p);
23382342
return NULL;
2343+
#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED || MBEDTLS_ECP_MONTGOMERY_ENABLED */
23392344
}
23402345

23412346
int crypto_ec_point_add(struct crypto_ec *e,
@@ -2346,6 +2351,9 @@ int crypto_ec_point_add(struct crypto_ec *e,
23462351
if (TEST_FAIL())
23472352
return -1;
23482353

2354+
#if !defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED)
2355+
return -1;
2356+
#else
23492357
/* mbedtls does not provide an mbedtls_ecp_point add function */
23502358
mbedtls_mpi one;
23512359
mbedtls_mpi_init(&one);
@@ -2354,8 +2362,10 @@ int crypto_ec_point_add(struct crypto_ec *e,
23542362
(const mbedtls_ecp_point *)a, &one, (const mbedtls_ecp_point *)b) ?
23552363
-1 :
23562364
0;
2365+
23572366
mbedtls_mpi_free(&one);
23582367
return ret;
2368+
#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */
23592369
}
23602370

23612371
int crypto_ec_point_mul(struct crypto_ec *e,

0 commit comments

Comments
 (0)