Skip to content

Commit 6698cb7

Browse files
committed
Fix for crypto callback only
1 parent 436a06e commit 6698cb7

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

wolfcrypt/src/rsa.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4816,7 +4816,8 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
48164816
{
48174817
#ifndef WC_NO_RNG
48184818
#if !defined(WOLFSSL_CRYPTOCELL) && \
4819-
(!defined(WOLFSSL_SE050) || defined(WOLFSSL_SE050_NO_RSA))
4819+
(!defined(WOLFSSL_SE050) || defined(WOLFSSL_SE050_NO_RSA)) && \
4820+
!defined(WOLF_CRYPTO_CB_ONLY_RSA)
48204821
#ifdef WOLFSSL_SMALL_STACK
48214822
mp_int *p = NULL;
48224823
mp_int *q = NULL;
@@ -4907,6 +4908,11 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
49074908
/* fall-through when unavailable */
49084909
#endif
49094910
}
4911+
#if !defined(WOLF_CRYPTO_CB_FIND) && defined(WOLF_CRYPTO_CB_ONLY_RSA)
4912+
else {
4913+
err = NO_VALID_DEVID;
4914+
}
4915+
#endif
49104916
#endif
49114917

49124918
#ifndef WOLF_CRYPTO_CB_ONLY_RSA

wolfcrypt/test/test.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,10 +2761,14 @@ options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
27612761

27622762
#endif /* NO_MAIN_DRIVER */
27632763

2764+
#if defined(WOLF_CRYPTO_CB_ONLY_ECC) || defined(WOLF_CRYPTO_CB_ONLY_RSA)
2765+
#undef NO_WRITE_TEMP_FILES
2766+
#define NO_WRITE_TEMP_FILES
2767+
#endif
2768+
27642769
/* helper to save DER, convert to PEM and save PEM */
27652770
#if !defined(NO_ASN) && (defined(HAVE_ECC) || !defined(NO_DSA) || \
2766-
(!defined(NO_RSA) && (defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)))) \
2767-
&& !defined(WOLF_CRYPTO_CB_ONLY_ECC)
2771+
(!defined(NO_RSA) && (defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN))))
27682772

27692773
#if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
27702774
#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)
2195221956
int keySz = 2048;
2195321957
#endif
2195421958

21959+
#ifdef WOLF_CRYPTO_CB_ONLY_RSA
21960+
if (devId == INVALID_DEVID) {
21961+
/* must call keygen with devId */
21962+
return 0;
21963+
}
21964+
#endif
21965+
2195521966
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
2195621967
if (! genKey)
2195721968
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)
5962459635

5962559636
#ifdef WOLFSSL_KEY_GEN
5962659637
WC_RNG rng;
59638+
word32 keySz = 2048;
5962759639
#endif
5962859640

5962959641
#ifdef USE_CERT_BUFFERS_1024
@@ -59681,15 +59693,15 @@ static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
5968159693
* wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success)
5968259694
*/
5968359695
ctx->exampleVar = 99;
59684-
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
59696+
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, &rng);
5968559697
if (ret != 0)
5968659698
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
5968759699
/* wc_MakeRsaKey() -> rsa cb ->
5968859700
* myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID)
5968959701
* wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure)
5969059702
*/
5969159703
ctx->exampleVar = 1;
59692-
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
59704+
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, &rng);
5969359705
if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
5969459706
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
5969559707
} else

0 commit comments

Comments
 (0)