@@ -30403,9 +30403,9 @@ static wc_test_ret_t rsa_certreq_test(RsaKey* key, RsaKey* keypub,
3040330403 * WOLFSSL_CERT_REQ && !WOLFSSL_NO_MALLOC */
3040430404
3040530405#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_ONLY_KEY_ID) && \
30406- ! defined(WOLFSSL_SE050_NO_RSA ) && !defined(WOLFSSL_SE050_NO_RSA_VERIFY ) && \
30407- !defined(WOLFSSL_NO_MALLOC ) && !defined(WOLFSSL_RSA_PUBLIC_ONLY ) && \
30408- !defined(WOLFSSL_RSA_VERIFY_ONLY)
30406+ defined(WOLFSSL_KEY_GEN ) && !defined(WOLFSSL_SE050_NO_RSA ) && \
30407+ !defined(WOLFSSL_SE050_NO_RSA_VERIFY ) && !defined(WOLFSSL_NO_MALLOC ) && \
30408+ !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined( WOLFSSL_RSA_VERIFY_ONLY)
3040930409
3041030410/* SE050 key ID for the ONLY_KEY_ID RSA test. Must be < SE050_KEYID_START. */
3041130411#define SE050_ONLYKEYID_TEST_RSA_ID 51
@@ -30438,6 +30438,15 @@ static wc_test_ret_t rsa_se050_onlykeyid_test(WC_RNG* rng)
3043830438 return WC_TEST_RET_ENC_EC(ret);
3043930439 swInit = 1;
3044030440
30441+ /* An invalid key size must fail cleanly. This drives the early 'goto out'
30442+ * cleanup in wc_MakeRsaKey(), which under WOLFSSL_CHECK_MEM_ZERO must not
30443+ * scan the never-initialized stack temporaries. */
30444+ ret = wc_MakeRsaKey(&swKey, 0, WC_RSA_EXPONENT, rng);
30445+ if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
30446+ ret = WC_TEST_RET_ENC_NC;
30447+ goto done;
30448+ }
30449+
3044130450 /* Key generation must produce a software key (keyIdSet == 0). */
3044230451 ret = wc_MakeRsaKey(&swKey, 2048, WC_RSA_EXPONENT, rng);
3044330452 if (ret != 0) { ret = WC_TEST_RET_ENC_EC(ret); goto done; }
@@ -30878,9 +30887,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
3087830887#endif
3087930888
3088030889#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_ONLY_KEY_ID) && \
30881- ! defined(WOLFSSL_SE050_NO_RSA ) && !defined(WOLFSSL_SE050_NO_RSA_VERIFY ) && \
30882- !defined(WOLFSSL_NO_MALLOC ) && !defined(WOLFSSL_RSA_PUBLIC_ONLY ) && \
30883- !defined(WOLFSSL_RSA_VERIFY_ONLY)
30890+ defined(WOLFSSL_KEY_GEN ) && !defined(WOLFSSL_SE050_NO_RSA ) && \
30891+ !defined(WOLFSSL_SE050_NO_RSA_VERIFY ) && !defined(WOLFSSL_NO_MALLOC ) && \
30892+ !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined( WOLFSSL_RSA_VERIFY_ONLY)
3088430893 ret = rsa_se050_onlykeyid_test(&rng);
3088530894 if (ret != 0) {
3088630895 printf("rsa_se050_onlykeyid_test failed!\n");
@@ -43985,6 +43994,20 @@ static wc_test_ret_t ecc_se050_onlykeyid_test(WC_RNG* rng)
4398543994 if (ret != 0) { ret = WC_TEST_RET_ENC_EC(ret); goto done; }
4398643995 if (verify != 1) { ret = WC_TEST_RET_ENC_NC; goto done; }
4398743996
43997+ /* A corrupted signature must be rejected on the hardware route. The SE050
43998+ * port reports a failed hardware verify as WC_HW_E with res still 0 (the
43999+ * SSS API does not distinguish a bad signature from an operation failure),
44000+ * matching the always-offload SE050 build's error mapping. */
44001+ sigHw[10] ^= 0x01;
44002+ verify = 1;
44003+ ret = wc_ecc_verify_hash(sigHw, sigHwSz, hash, (word32)sizeof(hash),
44004+ &verify, &hwKey);
44005+ sigHw[10] ^= 0x01;
44006+ if (ret != WC_NO_ERR_TRACE(WC_HW_E) || verify != 0) {
44007+ ret = WC_TEST_RET_ENC_NC; goto done;
44008+ }
44009+ ret = 0;
44010+
4398844011#if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_SE050_NO_ECDHE)
4398944012 {
4399044013 /* ECDH with the software key must match ECDH with the same key after it
@@ -44012,6 +44035,12 @@ static wc_test_ret_t ecc_se050_onlykeyid_test(WC_RNG* rng)
4401244035 ret = wc_ecc_shared_secret(&hwKey, &peer, secretHw, &secretHwSz);
4401344036 if (ret != 0) { ret = WC_TEST_RET_ENC_EC(ret); goto ecdh_done; }
4401444037
44038+ /* The peer was and must remain a software key (keyIdSet == 0) */
44039+ if (peer.keyIdSet != 0) {
44040+ ret = WC_TEST_RET_ENC_NC;
44041+ goto ecdh_done;
44042+ }
44043+
4401544044 if (secretSwSz != secretHwSz ||
4401644045 XMEMCMP(secretSw, secretHw, secretSwSz) != 0) {
4401744046 ret = WC_TEST_RET_ENC_NC;
0 commit comments