@@ -418,6 +418,16 @@ static int test_lms_xmss_verify_cryptocb(int devIdArg, wc_CryptoInfo* info,
418418 if ((info != NULL ) && (info -> algo_type == WC_ALGO_TYPE_PK ) &&
419419 (info -> pk .type == WC_PK_TYPE_PQC_STATEFUL_SIG_VERIFY )) {
420420 test_lms_xmss_verify_calls ++ ;
421+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
422+ if (ctx != NULL ) {
423+ int result = * (const int * )ctx ;
424+ if (result < 0 ) {
425+ return result ;
426+ }
427+ * info -> pk .pqc_stateful_sig_verify .res = result ;
428+ return 0 ;
429+ }
430+ #endif
421431 * info -> pk .pqc_stateful_sig_verify .res = 1 ;
422432 return 0 ;
423433 }
@@ -591,18 +601,26 @@ int test_wc_LmsKey_reload_devid_verify(void)
591601 byte msg [] = "test message for LMS signing" ;
592602 byte * sig = NULL ;
593603 word32 sigSz = 0 ;
604+ void * reply = NULL ;
605+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
606+ int verifyResult = 1 ;
607+ reply = & verifyResult ;
608+ #endif
594609
595610 /* Zero so cleanup is safe if an early alloc failure skips init. */
596611 XMEMSET (& key , 0 , sizeof (key ));
597612 test_lms_xmss_verify_calls = 0 ;
598613
599614 ExpectIntEQ (wc_CryptoCb_RegisterDevice (TEST_LMS_XMSS_CRYPTOCB_DEVID ,
600- test_lms_xmss_verify_cryptocb , NULL ), 0 );
615+ test_lms_xmss_verify_cryptocb , reply ), 0 );
601616
602617 /* No read callback, so the reload leaves the state with the device. */
603618 ExpectIntEQ (wc_LmsKey_Init (& key , NULL , TEST_LMS_XMSS_CRYPTOCB_DEVID ), 0 );
604619 ExpectIntEQ (test_lms_set_params (& key ), 0 );
605620 ExpectIntEQ (wc_LmsKey_Reload (& key ), 0 );
621+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
622+ ExpectIntEQ (wc_LmsKey_Reload (& key ), WC_NO_ERR_TRACE (BAD_STATE_E ));
623+ #endif
606624 ExpectNull (key .priv_data );
607625
608626 /* Only the signature length is checked before the device is asked, so the
@@ -614,6 +632,15 @@ int test_wc_LmsKey_reload_devid_verify(void)
614632 XMEMSET (sig , 0 , sigSz );
615633 ExpectIntEQ (wc_LmsKey_Verify (& key , sig , sigSz , msg , sizeof (msg )), 0 );
616634 ExpectIntEQ (test_lms_xmss_verify_calls , 1 );
635+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
636+ verifyResult = 0 ;
637+ ExpectIntEQ (wc_LmsKey_Verify (& key , sig , sigSz , msg , sizeof (msg )),
638+ WC_NO_ERR_TRACE (SIG_VERIFY_E ));
639+ verifyResult = WC_NO_ERR_TRACE (WC_HW_E );
640+ ExpectIntEQ (wc_LmsKey_Verify (& key , sig , sigSz , msg , sizeof (msg )),
641+ WC_NO_ERR_TRACE (WC_HW_E ));
642+ ExpectIntEQ (test_lms_xmss_verify_calls , 3 );
643+ #endif
617644 }
618645
619646 XFREE (sig , NULL , DYNAMIC_TYPE_TMP_BUFFER );
@@ -773,8 +800,22 @@ static int test_lms_xmss_keygen_cryptocb(int devIdArg, wc_CryptoInfo* info,
773800
774801 if ((info != NULL ) && (info -> algo_type == WC_ALGO_TYPE_PK ) &&
775802 (info -> pk .type == WC_PK_TYPE_PQC_STATEFUL_SIG_KEYGEN )) {
803+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
804+ if (ctx != NULL ) {
805+ return ((const int * )ctx )[0 ];
806+ }
807+ #endif
776808 return 0 ;
777809 }
810+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
811+ if ((ctx != NULL ) && (info != NULL ) &&
812+ (info -> algo_type == WC_ALGO_TYPE_PK ) &&
813+ (info -> pk .type == WC_PK_TYPE_PQC_STATEFUL_SIG_SIGS_LEFT )) {
814+ * info -> pk .pqc_stateful_sig_sigs_left .sigsLeft =
815+ (word32 )((const int * )ctx )[1 ];
816+ return 0 ;
817+ }
818+ #endif
778819 return CRYPTOCB_UNAVAILABLE ;
779820}
780821#endif
@@ -809,6 +850,33 @@ int test_wc_LmsKey_keygen_no_sigsleft(void)
809850 WC_NO_ERR_TRACE (BAD_STATE_E ));
810851
811852 wc_LmsKey_Free (& key );
853+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
854+ {
855+ static const struct {
856+ int reply [2 ]; /* Keygen result and remaining signatures. */
857+ int expected ;
858+ } cases [] = {
859+ {{ 0 , 1 }, 0 },
860+ {{ 0 , 0 }, WC_NO_ERR_TRACE (BAD_STATE_E )},
861+ {{ WC_NO_ERR_TRACE (WC_HW_E ), 0 }, WC_NO_ERR_TRACE (WC_HW_E )}
862+ };
863+ unsigned int i ;
864+
865+ wc_CryptoCb_UnRegisterDevice (TEST_LMS_XMSS_CRYPTOCB_DEVID );
866+ for (i = 0 ; i < sizeof (cases ) / sizeof (cases [0 ]); i ++ ) {
867+ int reply [2 ];
868+ XMEMCPY (reply , cases [i ].reply , sizeof (reply ));
869+ ExpectIntEQ (wc_CryptoCb_RegisterDevice (TEST_LMS_XMSS_CRYPTOCB_DEVID ,
870+ test_lms_xmss_keygen_cryptocb , reply ), 0 );
871+ ExpectIntEQ (wc_LmsKey_Init (& key , NULL ,
872+ TEST_LMS_XMSS_CRYPTOCB_DEVID ), 0 );
873+ ExpectIntEQ (test_lms_set_params (& key ), 0 );
874+ ExpectIntEQ (wc_LmsKey_MakeKey (& key , & rng ), cases [i ].expected );
875+ wc_LmsKey_Free (& key );
876+ wc_CryptoCb_UnRegisterDevice (TEST_LMS_XMSS_CRYPTOCB_DEVID );
877+ }
878+ }
879+ #endif
812880 wc_FreeRng (& rng );
813881 wc_CryptoCb_UnRegisterDevice (TEST_LMS_XMSS_CRYPTOCB_DEVID );
814882#endif
@@ -1178,18 +1246,26 @@ int test_wc_XmssKey_reload_devid_verify(void)
11781246 byte msg [] = "test message for XMSS signing" ;
11791247 byte * sig = NULL ;
11801248 word32 sigSz = 0 ;
1249+ void * reply = NULL ;
1250+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
1251+ int verifyResult = 1 ;
1252+ reply = & verifyResult ;
1253+ #endif
11811254
11821255 /* Zero so cleanup is safe if an early alloc failure skips init. */
11831256 XMEMSET (& key , 0 , sizeof (key ));
11841257 test_lms_xmss_verify_calls = 0 ;
11851258
11861259 ExpectIntEQ (wc_CryptoCb_RegisterDevice (TEST_LMS_XMSS_CRYPTOCB_DEVID ,
1187- test_lms_xmss_verify_cryptocb , NULL ), 0 );
1260+ test_lms_xmss_verify_cryptocb , reply ), 0 );
11881261
11891262 /* No read callback, so the reload leaves the state with the device. */
11901263 ExpectIntEQ (wc_XmssKey_Init (& key , NULL , TEST_LMS_XMSS_CRYPTOCB_DEVID ), 0 );
11911264 ExpectIntEQ (wc_XmssKey_SetParamStr (& key , "XMSS-SHA2_10_256" ), 0 );
11921265 ExpectIntEQ (wc_XmssKey_Reload (& key ), 0 );
1266+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
1267+ ExpectIntEQ (wc_XmssKey_Reload (& key ), WC_NO_ERR_TRACE (BAD_STATE_E ));
1268+ #endif
11931269 ExpectNull (key .sk );
11941270
11951271 /* Only the signature length is checked before the device is asked, so the
@@ -1201,6 +1277,15 @@ int test_wc_XmssKey_reload_devid_verify(void)
12011277 XMEMSET (sig , 0 , sigSz );
12021278 ExpectIntEQ (wc_XmssKey_Verify (& key , sig , sigSz , msg , sizeof (msg )), 0 );
12031279 ExpectIntEQ (test_lms_xmss_verify_calls , 1 );
1280+ #if !defined(HAVE_SELFTEST ) && !defined(HAVE_FIPS )
1281+ verifyResult = 0 ;
1282+ ExpectIntEQ (wc_XmssKey_Verify (& key , sig , sigSz , msg , sizeof (msg )),
1283+ WC_NO_ERR_TRACE (SIG_VERIFY_E ));
1284+ verifyResult = WC_NO_ERR_TRACE (WC_HW_E );
1285+ ExpectIntEQ (wc_XmssKey_Verify (& key , sig , sigSz , msg , sizeof (msg )),
1286+ WC_NO_ERR_TRACE (WC_HW_E ));
1287+ ExpectIntEQ (test_lms_xmss_verify_calls , 3 );
1288+ #endif
12041289 }
12051290
12061291 XFREE (sig , NULL , DYNAMIC_TYPE_TMP_BUFFER );
@@ -2627,6 +2712,48 @@ int test_wc_LmsDecisionCoverage(void)
26272712
26282713 ExpectIntEQ (wc_LmsKey_Init (& key , NULL , INVALID_DEVID ), 0 );
26292714
2715+ #if defined(WOLF_PRIVATE_KEY_ID ) && !defined(HAVE_SELFTEST ) && \
2716+ !defined(HAVE_FIPS )
2717+ {
2718+ static const byte id [] = {1 };
2719+ char label [LMS_MAX_LABEL_LEN + 2 ];
2720+ LmsKey identified ;
2721+
2722+ XMEMSET (& identified , 0 , sizeof (identified ));
2723+ ExpectIntEQ (wc_LmsKey_InitId (NULL , id , 1 , NULL , INVALID_DEVID ),
2724+ WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
2725+ ExpectIntEQ (wc_LmsKey_InitId (& identified , NULL , 1 , NULL ,
2726+ INVALID_DEVID ), WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
2727+ ExpectIntEQ (wc_LmsKey_InitId (& identified , id , -1 , NULL ,
2728+ INVALID_DEVID ), WC_NO_ERR_TRACE (BUFFER_E ));
2729+ ExpectIntEQ (wc_LmsKey_InitId (& identified , id , LMS_MAX_ID_LEN + 1 ,
2730+ NULL , INVALID_DEVID ), WC_NO_ERR_TRACE (BUFFER_E ));
2731+ ExpectIntEQ (wc_LmsKey_InitId (& identified , NULL , 0 , NULL ,
2732+ INVALID_DEVID ), 0 );
2733+ wc_LmsKey_Free (& identified );
2734+ ExpectIntEQ (wc_LmsKey_InitId (& identified , id , 0 , NULL ,
2735+ INVALID_DEVID ), 0 );
2736+ wc_LmsKey_Free (& identified );
2737+ ExpectIntEQ (wc_LmsKey_InitId (& identified , id , 1 , NULL ,
2738+ INVALID_DEVID ), 0 );
2739+ wc_LmsKey_Free (& identified );
2740+
2741+ XMEMSET (label , 'a' , sizeof (label ) - 1 );
2742+ label [sizeof (label ) - 1 ] = '\0' ;
2743+ ExpectIntEQ (wc_LmsKey_InitLabel (NULL , "key" , NULL , INVALID_DEVID ),
2744+ WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
2745+ ExpectIntEQ (wc_LmsKey_InitLabel (& identified , NULL , NULL ,
2746+ INVALID_DEVID ), WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
2747+ ExpectIntEQ (wc_LmsKey_InitLabel (& identified , "" , NULL ,
2748+ INVALID_DEVID ), WC_NO_ERR_TRACE (BUFFER_E ));
2749+ ExpectIntEQ (wc_LmsKey_InitLabel (& identified , label , NULL ,
2750+ INVALID_DEVID ), WC_NO_ERR_TRACE (BUFFER_E ));
2751+ ExpectIntEQ (wc_LmsKey_InitLabel (& identified , "key" , NULL ,
2752+ INVALID_DEVID ), 0 );
2753+ wc_LmsKey_Free (& identified );
2754+ }
2755+ #endif
2756+
26302757 /* wc_LmsKey_SetParameters: unknown (levels,height,winternitz) triple ->
26312758 * table search exhausts and returns BAD_FUNC_ARG. Independence: vary one
26322759 * coordinate at a time away from the known-good L1/H5/W8 set (the others
@@ -2954,6 +3081,48 @@ int test_wc_XmssDecisionCoverage(void)
29543081 WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
29553082 ExpectIntEQ (wc_XmssKey_Init (& key , NULL , INVALID_DEVID ), 0 );
29563083
3084+ #if defined(WOLF_PRIVATE_KEY_ID ) && !defined(HAVE_SELFTEST ) && \
3085+ !defined(HAVE_FIPS )
3086+ {
3087+ static const byte id [] = {1 };
3088+ char label [XMSS_MAX_LABEL_LEN + 2 ];
3089+ XmssKey identified ;
3090+
3091+ XMEMSET (& identified , 0 , sizeof (identified ));
3092+ ExpectIntEQ (wc_XmssKey_InitId (NULL , id , 1 , NULL , INVALID_DEVID ),
3093+ WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
3094+ ExpectIntEQ (wc_XmssKey_InitId (& identified , NULL , 1 , NULL ,
3095+ INVALID_DEVID ), WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
3096+ ExpectIntEQ (wc_XmssKey_InitId (& identified , id , -1 , NULL ,
3097+ INVALID_DEVID ), WC_NO_ERR_TRACE (BUFFER_E ));
3098+ ExpectIntEQ (wc_XmssKey_InitId (& identified , id , XMSS_MAX_ID_LEN + 1 ,
3099+ NULL , INVALID_DEVID ), WC_NO_ERR_TRACE (BUFFER_E ));
3100+ ExpectIntEQ (wc_XmssKey_InitId (& identified , NULL , 0 , NULL ,
3101+ INVALID_DEVID ), 0 );
3102+ wc_XmssKey_Free (& identified );
3103+ ExpectIntEQ (wc_XmssKey_InitId (& identified , id , 0 , NULL ,
3104+ INVALID_DEVID ), 0 );
3105+ wc_XmssKey_Free (& identified );
3106+ ExpectIntEQ (wc_XmssKey_InitId (& identified , id , 1 , NULL ,
3107+ INVALID_DEVID ), 0 );
3108+ wc_XmssKey_Free (& identified );
3109+
3110+ XMEMSET (label , 'a' , sizeof (label ) - 1 );
3111+ label [sizeof (label ) - 1 ] = '\0' ;
3112+ ExpectIntEQ (wc_XmssKey_InitLabel (NULL , "key" , NULL , INVALID_DEVID ),
3113+ WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
3114+ ExpectIntEQ (wc_XmssKey_InitLabel (& identified , NULL , NULL ,
3115+ INVALID_DEVID ), WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
3116+ ExpectIntEQ (wc_XmssKey_InitLabel (& identified , "" , NULL ,
3117+ INVALID_DEVID ), WC_NO_ERR_TRACE (BUFFER_E ));
3118+ ExpectIntEQ (wc_XmssKey_InitLabel (& identified , label , NULL ,
3119+ INVALID_DEVID ), WC_NO_ERR_TRACE (BUFFER_E ));
3120+ ExpectIntEQ (wc_XmssKey_InitLabel (& identified , "key" , NULL ,
3121+ INVALID_DEVID ), 0 );
3122+ wc_XmssKey_Free (& identified );
3123+ }
3124+ #endif
3125+
29573126 /* wc_XmssKey_SetParamStr: NULL key vs NULL str (independence pair), then
29583127 * an unknown parameter string -> BAD_FUNC_ARG from the lookup. */
29593128 ExpectIntEQ (wc_XmssKey_SetParamStr (NULL , "XMSS-SHA2_10_256" ),
@@ -3139,6 +3308,16 @@ int test_wc_LmsKey_make_key_id_dev(void)
31393308 wc_LmsKey_Free (& key );
31403309
31413310 wc_CryptoCb_UnRegisterDevice (TEST_LMS_XMSS_CRYPTOCB_DEVID );
3311+ #if !defined(HAVE_SELFTEST ) && !defined(WOLF_CRYPTO_CB_ONLY_LMS ) && \
3312+ !defined(WOLF_CRYPTO_CB_FIND )
3313+ /* Without the registered device, key generation checks the software
3314+ * key's storage callbacks. The fresh key has no write callback. */
3315+ ExpectIntEQ (wc_LmsKey_InitId (& key , id , (int )sizeof (id ), NULL ,
3316+ TEST_LMS_XMSS_CRYPTOCB_DEVID ), 0 );
3317+ ExpectIntEQ (test_lms_set_params (& key ), 0 );
3318+ ExpectIntEQ (wc_LmsKey_MakeKey (& key , & rng ), WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
3319+ wc_LmsKey_Free (& key );
3320+ #endif
31423321 DoExpectIntEQ (wc_FreeRng (& rng ), 0 );
31433322#endif
31443323 return EXPECT_RESULT ();
@@ -3180,6 +3359,16 @@ int test_wc_XmssKey_make_key_id_dev(void)
31803359 wc_XmssKey_Free (& key );
31813360
31823361 wc_CryptoCb_UnRegisterDevice (TEST_LMS_XMSS_CRYPTOCB_DEVID );
3362+ #if !defined(HAVE_SELFTEST ) && !defined(WOLF_CRYPTO_CB_ONLY_XMSS ) && \
3363+ !defined(WOLF_CRYPTO_CB_FIND )
3364+ /* Without the registered device, key generation checks the software
3365+ * key's storage callbacks. The fresh key has no write callback. */
3366+ ExpectIntEQ (wc_XmssKey_InitId (& key , id , (int )sizeof (id ), NULL ,
3367+ TEST_LMS_XMSS_CRYPTOCB_DEVID ), 0 );
3368+ ExpectIntEQ (wc_XmssKey_SetParamStr (& key , "XMSS-SHA2_10_256" ), 0 );
3369+ ExpectIntEQ (wc_XmssKey_MakeKey (& key , & rng ), WC_NO_ERR_TRACE (BAD_FUNC_ARG ));
3370+ wc_XmssKey_Free (& key );
3371+ #endif
31833372 DoExpectIntEQ (wc_FreeRng (& rng ), 0 );
31843373#endif
31853374 return EXPECT_RESULT ();
0 commit comments