Skip to content

Commit 7baa2c9

Browse files
committed
Fix for crypto callback only
1 parent dc421a0 commit 7baa2c9

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)
@@ -21950,6 +21954,13 @@ static wc_test_ret_t rsa_keygen_test(WC_RNG* rng)
2195021954
int keySz = 2048;
2195121955
#endif
2195221956

21957+
#ifdef WOLF_CRYPTO_CB_ONLY_RSA
21958+
if (devId == INVALID_DEVID) {
21959+
/* must call keygen with devId */
21960+
return 0;
21961+
}
21962+
#endif
21963+
2195321964
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
2195421965
if (! genKey)
2195521966
ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
@@ -59617,6 +59628,7 @@ static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
5961759628

5961859629
#ifdef WOLFSSL_KEY_GEN
5961959630
WC_RNG rng;
59631+
word32 keySz = 2048;
5962059632
#endif
5962159633

5962259634
#ifdef USE_CERT_BUFFERS_1024
@@ -59674,15 +59686,15 @@ static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
5967459686
* wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success)
5967559687
*/
5967659688
ctx->exampleVar = 99;
59677-
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
59689+
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, &rng);
5967859690
if (ret != 0)
5967959691
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
5968059692
/* wc_MakeRsaKey() -> rsa cb ->
5968159693
* myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID)
5968259694
* wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure)
5968359695
*/
5968459696
ctx->exampleVar = 1;
59685-
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
59697+
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, &rng);
5968659698
if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
5968759699
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
5968859700
} else

0 commit comments

Comments
 (0)