Skip to content

Commit e096fc7

Browse files
committed
Add ML-KEM with Curve25519 and NISTp384
1. Reorganize the KEX test to allow for testing any KEX algorithm. Add test cases for the new algorithms to the KEX test. 2. Reorder the cannedKexAlgoNames with the ML-KEM algos first. 3. Add the new algos to wolfSSH_GetText(). 4. Add comments and whitespace cleanup.
1 parent 2b8c9b5 commit e096fc7

File tree

3 files changed

+61
-40
lines changed

3 files changed

+61
-40
lines changed

src/internal.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,14 @@
146146
Set when ECC or SHA2-512 are disabled. Set to disable use of ECDSA server
147147
authentication with prime NISTP521.
148148
WOLFSSH_NO_NISTP256_MLKEM768_SHA256
149-
Set when ML-KEM is disabled in wolfssl. Set to disable use of ECDHE with
150-
prime NISTP256 hybridized with post-quantum ML-KEM 768.
149+
Set when ML-KEM, ECC, or SHA2-256 are disabled in wolfssl. Set to disable
150+
use of ECDHE with prime NISTP256 hybridized with post-quantum ML-KEM 768.
151+
WOLFSSH_NO_NISTP384_MLKEM1024_SHA384
152+
Set when ML-KEM, ECC, or SHA2-384 are disabled in wolfssl. Set to disable
153+
use of ECDHE with prime NISTP384 hybridized with post-quantum ML-KEM 1024.
154+
WOLFSSH_NO_CURVE25519_MLKEM768_SHA256
155+
Set when ML-KEM, Curve25519, or SHA2-256 are disabled in wolfssl. Set to
156+
disable use of Curve25519 hybridized with post-quantum ML-KEM 768.
151157
WOLFSSH_NO_AES_CBC_SOFT_DISABLE
152158
AES-CBC is normally soft-disabled. The default configuration will not
153159
advertise the availability of AES-CBC algorithms during KEX. AES-CBC
@@ -847,14 +853,14 @@ int wolfSSH_TestIsMessageAllowed(WOLFSSH* ssh, byte msg, byte state)
847853

848854

849855
static const char cannedKexAlgoNames[] =
850-
#if !defined(WOLFSSH_NO_NISTP256_MLKEM768_SHA256)
851-
"mlkem768nistp256-sha256,"
856+
#if !defined(WOLFSSH_NO_CURVE25519_MLKEM768_SHA256)
857+
"mlkem768x25519-sha256,"
852858
#endif
853859
#if !defined(WOLFSSH_NO_NISTP384_MLKEM1024_SHA384)
854860
"mlkem1024nistp384-sha384,"
855861
#endif
856-
#if !defined(WOLFSSH_NO_CURVE25519_MLKEM768_SHA256)
857-
"mlkem768x25519-sha256,"
862+
#if !defined(WOLFSSH_NO_NISTP256_MLKEM768_SHA256)
863+
"mlkem768nistp256-sha256,"
858864
#endif
859865
#ifndef WOLFSSH_NO_CURVE25519_SHA256
860866
"curve25519-sha256,"

src/ssh.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3199,7 +3199,22 @@ size_t wolfSSH_GetText(WOLFSSH *ssh, WS_Text id, char *str, size_t strSz)
31993199

32003200
#ifndef WOLFSSH_NO_NISTP256_MLKEM768_SHA256
32013201
case ID_NISTP256_MLKEM768_SHA256:
3202-
ret = WSNPRINTF(str, strSz, "%s", "ECDH-MLKEM768");
3202+
ret = WSNPRINTF(str, strSz, "%s",
3203+
"ECDH-NISTP256-MLKEM768");
3204+
break;
3205+
#endif
3206+
3207+
#ifndef WOLFSSH_NO_NISTP384_MLKEM1024_SHA384
3208+
case ID_NISTP384_MLKEM1024_SHA384:
3209+
ret = WSNPRINTF(str, strSz, "%s",
3210+
"ECDH-NISTP384-MLKEM1024");
3211+
break;
3212+
#endif
3213+
3214+
#ifndef WOLFSSH_NO_CURVE25519_MLKEM768_SHA256
3215+
case ID_CURVE25519_MLKEM768_SHA256:
3216+
ret = WSNPRINTF(str, strSz, "%s",
3217+
"ECDH-CURVE25519-MLKEM768");
32033218
break;
32043219
#endif
32053220

tests/kex.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@
138138

139139

140140
#if !defined(NO_WOLFSSH_SERVER) && !defined(NO_WOLFSSH_CLIENT) && \
141-
!defined(SINGLE_THREADED) && !defined(WOLFSSH_TEST_BLOCK) && \
142-
!defined(WOLFSSH_NO_DH_GROUP16_SHA512) && !defined(WOLFSSH_NO_HMAC_SHA2_512)
141+
!defined(SINGLE_THREADED) && !defined(WOLFSSH_TEST_BLOCK)
143142

143+
#define KEXTEST_AVAILABLE
144+
#endif
145+
146+
#ifdef KEXTEST_AVAILABLE
144147
static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
145148
{
146149
static char password[] = "upthehill";
@@ -163,7 +166,7 @@ static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
163166
#define NUMARGS 12
164167
#define ARGLEN 32
165168

166-
/*
169+
/*
167170
* Macro: ADD_ARG
168171
* Purpose: Adds a string argument to the argument list.
169172
* Parameters:
@@ -185,7 +188,7 @@ static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
185188
WSTRNCPY((argList)[(argListCount)++], (arg), ARGLEN); \
186189
} while (0)
187190

188-
/*
191+
/*
189192
* Macro: ADD_ARG_INT
190193
* Purpose: Adds an integer argument to the argument list as a string.
191194
* Parameters:
@@ -209,7 +212,7 @@ static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
209212
} while (0)
210213

211214

212-
static int wolfSSH_wolfSSH_Group16_512(void)
215+
static int wolfSSH_KexTest_Connect(const char* kex)
213216
{
214217
tcp_ready ready;
215218
THREAD_TYPE serverThread;
@@ -226,27 +229,6 @@ static int wolfSSH_wolfSSH_Group16_512(void)
226229
int serverArgc = 0;
227230
int clientArgc = 0;
228231

229-
WSTARTTCP();
230-
231-
#if defined(DEBUG_WOLFSSH)
232-
wolfSSH_Debugging_ON();
233-
#endif
234-
235-
wolfSSH_Init();
236-
237-
#if defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,2)
238-
{
239-
int i;
240-
for (i = 0; i < FIPS_CAST_COUNT; i++) {
241-
wc_RunCast_fips(i);
242-
}
243-
}
244-
#endif /* HAVE_FIPS */
245-
246-
#if !defined(WOLFSSL_TIRTOS)
247-
ChangeToWolfSshRoot();
248-
#endif
249-
250232
InitTcpReady(&ready);
251233

252234
ADD_ARG(serverArgv, serverArgc, "echoserver");
@@ -257,7 +239,7 @@ static int wolfSSH_wolfSSH_Group16_512(void)
257239
ADD_ARG(serverArgv, serverArgc, "-0");
258240
#endif
259241
ADD_ARG(serverArgv, serverArgc, "-x");
260-
ADD_ARG(serverArgv, serverArgc, "diffie-hellman-group16-sha512");
242+
ADD_ARG(serverArgv, serverArgc, kex);
261243
ADD_ARG(serverArgv, serverArgc, "-m");
262244
ADD_ARG(serverArgv, serverArgc, "hmac-sha2-512");
263245
ADD_ARG(serverArgv, serverArgc, "-c");
@@ -318,18 +300,27 @@ static int wolfSSH_wolfSSH_Group16_512(void)
318300
return EXIT_SUCCESS;
319301
}
320302

321-
#endif
303+
#endif /* KEXTEST_AVAILABLE */
322304

323305
int wolfSSH_KexTest(int argc, char** argv)
324306
{
325307
(void)argc;
326308
(void)argv;
327309

328310

329-
#if defined(NO_WOLFSSH_SERVER) || defined(NO_WOLFSSH_CLIENT) || \
330-
defined(SINGLE_THREADED) || defined(WOLFSSH_TEST_BLOCK)
311+
#if !defined(KEXTEST_AVAILABLE)
331312
return 77;
332313
#else
314+
WSTARTTCP();
315+
316+
#if defined(DEBUG_WOLFSSH)
317+
wolfSSH_Debugging_ON();
318+
#endif
319+
320+
#if !defined(WOLFSSL_TIRTOS)
321+
ChangeToWolfSshRoot();
322+
#endif
323+
333324
AssertIntEQ(wolfSSH_Init(), WS_SUCCESS);
334325

335326
#if defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,2)
@@ -341,14 +332,23 @@ int wolfSSH_KexTest(int argc, char** argv)
341332
}
342333
#endif /* HAVE_FIPS */
343334

344-
#if !defined(WOLFSSH_NO_DH_GROUP16_SHA512) && !defined(WOLFSSH_NO_HMAC_SHA2_512)
345-
wolfSSH_wolfSSH_Group16_512();
335+
#if !defined(WOLFSSH_NO_DH_GROUP16_SHA512)
336+
AssertIntEQ(wolfSSH_KexTest_Connect("diffie-hellman-group16-sha512"),
337+
EXIT_SUCCESS);
338+
#endif
339+
#if !defined(WOLFSSH_NO_CURVE25519_MLKEM768_SHA256)
340+
AssertIntEQ(wolfSSH_KexTest_Connect("mlkem768x25519-sha256"),
341+
EXIT_SUCCESS);
342+
#endif
343+
#if !defined(WOLFSSH_NO_NISTP384_MLKEM1024_SHA384)
344+
AssertIntEQ(wolfSSH_KexTest_Connect("mlkem1024nistp384-sha384"),
345+
EXIT_SUCCESS);
346346
#endif
347347

348348
AssertIntEQ(wolfSSH_Cleanup(), WS_SUCCESS);
349349

350350
return 0;
351-
#endif
351+
#endif /* KEXTEST_AVAILABLE */
352352
}
353353

354354

0 commit comments

Comments
 (0)