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
144152static 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
323310int 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