@@ -1159,14 +1159,21 @@ static int whTest_CryptoEccExportPublicDma(whClientContext* ctx, int devId,
11591159 int ret = 0 ;
11601160 whKeyId keyId = WH_KEYID_ERASED ;
11611161 ecc_key pubKey [1 ] = {0 };
1162- uint8_t hash [TEST_ECC_KEYSIZE ] = {0 };
1162+ /* Non-zero digest: wolfCrypt rejects all-zero hashes with ECC_BAD_ARG_E
1163+ * unless WC_ALLOW_ECC_ZERO_HASH is defined. */
1164+ uint8_t hash [TEST_ECC_KEYSIZE ];
11631165 uint8_t sig [ECC_MAX_SIG_SIZE ] = {0 };
11641166 word32 sigLen = sizeof (sig );
11651167 int verified = 0 ;
11661168 byte derBuf [ECC_BUFSIZE ];
11671169 uint16_t derSz = sizeof (derBuf );
1170+ word32 i ;
11681171 (void )devId ;
11691172
1173+ for (i = 0 ; i < sizeof (hash ); i ++ ) {
1174+ hash [i ] = (uint8_t )(i + 1 );
1175+ }
1176+
11701177 ret = wh_Client_EccMakeCacheKey (
11711178 ctx , TEST_ECC_KEYSIZE , TEST_ECC_CURVE_ID , & keyId ,
11721179 WH_NVM_FLAGS_USAGE_SIGN | WH_NVM_FLAGS_USAGE_VERIFY |
@@ -2461,13 +2468,18 @@ static int whTest_Ed25519ImportToServer(whClientContext* ctx, int devId,
24612468 }
24622469 }
24632470
2471+ /* Write each out-keyId immediately after its import succeeds so the
2472+ * caller can evict it if a later step fails. */
24642473 if (ret == 0 ) {
24652474 ret = wh_Client_Ed25519ImportKey (
24662475 ctx , key , & signKeyId , WH_NVM_FLAGS_USAGE_SIGN , labelLen , label );
24672476 if (ret != 0 ) {
24682477 WH_ERROR_PRINT ("Failed to import Ed25519 key to server: %d\n" , ret );
24692478 }
24702479 else {
2480+ if (outSignKeyId != NULL ) {
2481+ * outSignKeyId = signKeyId ;
2482+ }
24712483 /* remove key material from local key structure */
24722484 wc_ed25519_free (key );
24732485 ret = wc_ed25519_init_ex (key , NULL , devId );
@@ -2490,6 +2502,9 @@ static int whTest_Ed25519ImportToServer(whClientContext* ctx, int devId,
24902502 "Failed to import Ed25519 public key to server: %d\n" , ret );
24912503 }
24922504 else {
2505+ if (outVerifyKeyId != NULL ) {
2506+ * outVerifyKeyId = verifyKeyId ;
2507+ }
24932508 /* remove key material from local key structure */
24942509 wc_ed25519_free (pubKey );
24952510 ret = wc_ed25519_init_ex (pubKey , NULL , devId );
@@ -2503,15 +2518,6 @@ static int whTest_Ed25519ImportToServer(whClientContext* ctx, int devId,
25032518 }
25042519 }
25052520
2506- if (ret == 0 ) {
2507- if (outSignKeyId != NULL ) {
2508- * outSignKeyId = signKeyId ;
2509- }
2510- if (outVerifyKeyId != NULL ) {
2511- * outVerifyKeyId = verifyKeyId ;
2512- }
2513- }
2514-
25152521 return ret ;
25162522}
25172523
@@ -2582,18 +2588,25 @@ static int whTest_CryptoEd25519Inline(whClientContext* ctx, int devId,
25822588 }
25832589
25842590 if (ret == 0 ) {
2585- /* Corrupt signature to ensure verification fails */
2591+ /* Corrupt signature to ensure verification fails. wolfCrypt may
2592+ * signal rejection either as ret==0 with verified==0, or as
2593+ * ret==SIG_VERIFY_E (path-dependent inside wolfCrypt). Anything
2594+ * else is a real error. */
25862595 sig [0 ] ^= 0xFF ;
25872596 verified = 0 ;
25882597 ret = wc_ed25519_verify_msg (sig , sigSz , msg , msgSz , & verified , pubKey );
2589- if (ret == 0 && verified == 1 ) {
2598+ if (verified != 0 ) {
25902599 WH_ERROR_PRINT (
25912600 "Modified Ed25519 signature unexpectedly verified\n" );
25922601 ret = -1 ;
25932602 }
2594- else {
2603+ else if ( ret == 0 || ret == SIG_VERIFY_E ) {
25952604 ret = 0 ;
25962605 }
2606+ else {
2607+ WH_ERROR_PRINT (
2608+ "wc_ed25519_verify_msg of tampered sig errored: %d\n" , ret );
2609+ }
25972610 }
25982611
25992612 if (ret == 0 ) {
@@ -2677,19 +2690,24 @@ static int whTest_CryptoEd25519ServerKey(whClientContext* ctx, int devId,
26772690 }
26782691
26792692 if (ret == 0 ) {
2693+ /* Same shape as the inline tampered-sig case above. */
26802694 sig [0 ] ^= 0xAA ;
26812695 verified = 0 ;
26822696 ret = wh_Client_Ed25519Verify (ctx , pubKey , sig , sigSz , msg ,
26832697 (uint32_t )sizeof (msg ), (uint8_t )Ed25519 ,
26842698 NULL , 0 , & verified );
2685- if (ret == 0 && verified == 1 ) {
2699+ if (verified != 0 ) {
26862700 WH_ERROR_PRINT ("Modified server Ed25519 signature unexpectedly "
26872701 "verified\n" );
26882702 ret = -1 ;
26892703 }
2690- else {
2704+ else if ( ret == 0 || ret == SIG_VERIFY_E ) {
26912705 ret = 0 ;
26922706 }
2707+ else {
2708+ WH_ERROR_PRINT (
2709+ "Server Ed25519 verify of tampered sig errored: %d\n" , ret );
2710+ }
26932711 }
26942712
26952713 if (!WH_KEYID_ISERASED (signKeyId )) {
0 commit comments