Skip to content

Commit 303cafc

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 d5d02ae commit 303cafc

File tree

3 files changed

+66
-40
lines changed

3 files changed

+66
-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: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,17 @@
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+
#if !defined(WOLFSSH_NO_DH_GROUP16_SHA512) \
144+
|| !defined(WOLFSSH_NO_CURVE25519_MLKEM768_SHA256) \
145+
|| !defined(WOLFSSH_NO_NISTP384_MLKEM1024_SHA384)
146+
147+
#define KEXTEST_AVAILABLE
148+
#endif
149+
#endif
150+
151+
#ifdef KEXTEST_AVAILABLE
144152
static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
145153
{
146154
static char password[] = "upthehill";
@@ -163,7 +171,7 @@ static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
163171
#define NUMARGS 12
164172
#define ARGLEN 32
165173

166-
/*
174+
/*
167175
* Macro: ADD_ARG
168176
* Purpose: Adds a string argument to the argument list.
169177
* Parameters:
@@ -185,7 +193,7 @@ static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
185193
WSTRNCPY((argList)[(argListCount)++], (arg), ARGLEN); \
186194
} while (0)
187195

188-
/*
196+
/*
189197
* Macro: ADD_ARG_INT
190198
* Purpose: Adds an integer argument to the argument list as a string.
191199
* Parameters:
@@ -209,7 +217,7 @@ static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
209217
} while (0)
210218

211219

212-
static int wolfSSH_wolfSSH_Group16_512(void)
220+
static int wolfSSH_KexTest_Connect(const char* kex)
213221
{
214222
tcp_ready ready;
215223
THREAD_TYPE serverThread;
@@ -226,27 +234,6 @@ static int wolfSSH_wolfSSH_Group16_512(void)
226234
int serverArgc = 0;
227235
int clientArgc = 0;
228236

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-
250237
InitTcpReady(&ready);
251238

252239
ADD_ARG(serverArgv, serverArgc, "echoserver");
@@ -257,7 +244,7 @@ static int wolfSSH_wolfSSH_Group16_512(void)
257244
ADD_ARG(serverArgv, serverArgc, "-0");
258245
#endif
259246
ADD_ARG(serverArgv, serverArgc, "-x");
260-
ADD_ARG(serverArgv, serverArgc, "diffie-hellman-group16-sha512");
247+
ADD_ARG(serverArgv, serverArgc, kex);
261248
ADD_ARG(serverArgv, serverArgc, "-m");
262249
ADD_ARG(serverArgv, serverArgc, "hmac-sha2-512");
263250
ADD_ARG(serverArgv, serverArgc, "-c");
@@ -318,18 +305,27 @@ static int wolfSSH_wolfSSH_Group16_512(void)
318305
return EXIT_SUCCESS;
319306
}
320307

321-
#endif
308+
#endif /* KEXTEST_AVAILABLE */
322309

323310
int wolfSSH_KexTest(int argc, char** argv)
324311
{
325312
(void)argc;
326313
(void)argv;
327314

328315

329-
#if defined(NO_WOLFSSH_SERVER) || defined(NO_WOLFSSH_CLIENT) || \
330-
defined(SINGLE_THREADED) || defined(WOLFSSH_TEST_BLOCK)
316+
#if !defined(KEXTEST_AVAILABLE)
331317
return 77;
332318
#else
319+
WSTARTTCP();
320+
321+
#if defined(DEBUG_WOLFSSH)
322+
wolfSSH_Debugging_ON();
323+
#endif
324+
325+
#if !defined(WOLFSSL_TIRTOS)
326+
ChangeToWolfSshRoot();
327+
#endif
328+
333329
AssertIntEQ(wolfSSH_Init(), WS_SUCCESS);
334330

335331
#if defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,2)
@@ -341,14 +337,23 @@ int wolfSSH_KexTest(int argc, char** argv)
341337
}
342338
#endif /* HAVE_FIPS */
343339

344-
#if !defined(WOLFSSH_NO_DH_GROUP16_SHA512) && !defined(WOLFSSH_NO_HMAC_SHA2_512)
345-
wolfSSH_wolfSSH_Group16_512();
340+
#if !defined(WOLFSSH_NO_DH_GROUP16_SHA512)
341+
AssertIntEQ(wolfSSH_KexTest_Connect("diffie-hellman-group16-sha512"),
342+
EXIT_SUCCESS);
343+
#endif
344+
#if !defined(WOLFSSH_NO_CURVE25519_MLKEM768_SHA256)
345+
AssertIntEQ(wolfSSH_KexTest_Connect("mlkem768x25519-sha256"),
346+
EXIT_SUCCESS);
347+
#endif
348+
#if !defined(WOLFSSH_NO_NISTP384_MLKEM1024_SHA384)
349+
AssertIntEQ(wolfSSH_KexTest_Connect("mlkem1024nistp384-sha384"),
350+
EXIT_SUCCESS);
346351
#endif
347352

348353
AssertIntEQ(wolfSSH_Cleanup(), WS_SUCCESS);
349354

350355
return 0;
351-
#endif
356+
#endif /* KEXTEST_AVAILABLE */
352357
}
353358

354359

0 commit comments

Comments
 (0)