From 6698cb76167d8deb592b252c7b29c1562340793f Mon Sep 17 00:00:00 2001 From: David Garske Date: Wed, 10 Sep 2025 16:03:31 -0700 Subject: [PATCH] Fix for crypto callback only --- wolfcrypt/src/rsa.c | 8 +++++++- wolfcrypt/test/test.c | 20 ++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index 759c795ff..c74aadcea 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -4816,7 +4816,8 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng) { #ifndef WC_NO_RNG #if !defined(WOLFSSL_CRYPTOCELL) && \ - (!defined(WOLFSSL_SE050) || defined(WOLFSSL_SE050_NO_RSA)) + (!defined(WOLFSSL_SE050) || defined(WOLFSSL_SE050_NO_RSA)) && \ + !defined(WOLF_CRYPTO_CB_ONLY_RSA) #ifdef WOLFSSL_SMALL_STACK mp_int *p = NULL; mp_int *q = NULL; @@ -4907,6 +4908,11 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng) /* fall-through when unavailable */ #endif } + #if !defined(WOLF_CRYPTO_CB_FIND) && defined(WOLF_CRYPTO_CB_ONLY_RSA) + else { + err = NO_VALID_DEVID; + } + #endif #endif #ifndef WOLF_CRYPTO_CB_ONLY_RSA diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 5b15e4c5d..0f4d93745 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -2761,10 +2761,14 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\ #endif /* NO_MAIN_DRIVER */ +#if defined(WOLF_CRYPTO_CB_ONLY_ECC) || defined(WOLF_CRYPTO_CB_ONLY_RSA) + #undef NO_WRITE_TEMP_FILES + #define NO_WRITE_TEMP_FILES +#endif + /* helper to save DER, convert to PEM and save PEM */ #if !defined(NO_ASN) && (defined(HAVE_ECC) || !defined(NO_DSA) || \ -(!defined(NO_RSA) && (defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)))) \ - && !defined(WOLF_CRYPTO_CB_ONLY_ECC) +(!defined(NO_RSA) && (defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)))) #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES) #define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, fD, fP, pT, WC_TEST_RET_LN) @@ -21952,6 +21956,13 @@ static wc_test_ret_t rsa_keygen_test(WC_RNG* rng) int keySz = 2048; #endif +#ifdef WOLF_CRYPTO_CB_ONLY_RSA + if (devId == INVALID_DEVID) { + /* must call keygen with devId */ + return 0; + } +#endif + #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (! genKey) ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa); @@ -59624,6 +59635,7 @@ static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx) #ifdef WOLFSSL_KEY_GEN WC_RNG rng; + word32 keySz = 2048; #endif #ifdef USE_CERT_BUFFERS_1024 @@ -59681,7 +59693,7 @@ static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx) * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success) */ ctx->exampleVar = 99; - ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng); + ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, &rng); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); /* wc_MakeRsaKey() -> rsa cb -> @@ -59689,7 +59701,7 @@ static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx) * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure) */ ctx->exampleVar = 1; - ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng); + ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, &rng); if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb); } else