Skip to content

Commit ada225a

Browse files
committed
Align wolfSSL_set1_groups_list() arg handling with OpenSSL
Align the argument parsing and handling of input group names to align it with OpenSSL behavior: * Do a case-insensitive comparison of the input names with our names * Add aliases for "MLKEMxxx" groups without underscores in addition to our names with underscores (keep our for backward compatibility) * Extend unit tests for both
1 parent 68381e0 commit ada225a

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/ssl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13910,6 +13910,10 @@ const WOLF_EC_NIST_NAME kNistCurves[] = {
1391013910
{CURVE_NAME("ML_KEM_512"), WOLFSSL_ML_KEM_512, WOLFSSL_ML_KEM_512},
1391113911
{CURVE_NAME("ML_KEM_768"), WOLFSSL_ML_KEM_768, WOLFSSL_ML_KEM_768},
1391213912
{CURVE_NAME("ML_KEM_1024"), WOLFSSL_ML_KEM_1024, WOLFSSL_ML_KEM_1024},
13913+
/* Aliases accepting the OpenSSL/IANA spelling without underscores. */
13914+
{CURVE_NAME("MLKEM512"), WOLFSSL_ML_KEM_512, WOLFSSL_ML_KEM_512},
13915+
{CURVE_NAME("MLKEM768"), WOLFSSL_ML_KEM_768, WOLFSSL_ML_KEM_768},
13916+
{CURVE_NAME("MLKEM1024"), WOLFSSL_ML_KEM_1024, WOLFSSL_ML_KEM_1024},
1391313917
#if defined(HAVE_ECC)
1391413918
#ifdef WOLFSSL_PQC_HYBRIDS
1391513919
{CURVE_NAME("SecP256r1MLKEM768"), WOLFSSL_SECP256R1MLKEM768,
@@ -14008,7 +14012,7 @@ int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names,
1400814012

1400914013
for (nist_name = kNistCurves; nist_name->name != NULL; nist_name++) {
1401014014
if (len == nist_name->name_len &&
14011-
XSTRNCMP(name, nist_name->name, (size_t)len) == 0) {
14015+
XSTRNCASECMP(name, nist_name->name, (size_t)len) == 0) {
1401214016
curve = nist_name->curve;
1401314017
break;
1401414018
}

tests/api/test_ssl_ext.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,29 @@ int test_wolfSSL_set1_groups_list_ext(void)
166166
ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "P-256"), WOLFSSL_SUCCESS);
167167
ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "P-256"), WOLFSSL_SUCCESS);
168168

169+
/* Group name matching is case-insensitive, matching OpenSSL behavior.
170+
* P-256 is the same curve as secp256r1; use it for the mixed-case list so
171+
* the test does not depend on additional curves being compiled in. */
172+
ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "p-256"), WOLFSSL_SUCCESS);
173+
ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "p-256"), WOLFSSL_SUCCESS);
174+
ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "p-256:SECP256R1"),
175+
WOLFSSL_SUCCESS);
176+
ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "p-256:SECP256R1"),
177+
WOLFSSL_SUCCESS);
178+
179+
#if defined(WOLFSSL_HAVE_MLKEM) && !defined(WOLFSSL_NO_ML_KEM) && \
180+
!defined(WOLFSSL_TLS_NO_MLKEM_STANDALONE)
181+
/* ML-KEM groups are accepted by both the wolfSSL spelling ("ML_KEM_512")
182+
* and the OpenSSL/IANA spelling without underscores ("MLKEM512"). These
183+
* standalone (non-hybrid) ML-KEM groups are only usable as TLS key
184+
* exchange when WOLFSSL_TLS_NO_MLKEM_STANDALONE is not defined. */
185+
ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "ML_KEM_512"),
186+
WOLFSSL_SUCCESS);
187+
ExpectIntEQ(wolfSSL_CTX_set1_groups_list(ctx, "MLKEM512"), WOLFSSL_SUCCESS);
188+
ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "MLKEM768"), WOLFSSL_SUCCESS);
189+
ExpectIntEQ(wolfSSL_set1_groups_list(ssl, "mlkem1024"), WOLFSSL_SUCCESS);
190+
#endif
191+
169192
wolfSSL_free(ssl);
170193
wolfSSL_CTX_free(ctx);
171194
#endif

0 commit comments

Comments
 (0)