Skip to content

Commit 5804ba7

Browse files
authored
Merge pull request wolfSSL#9194 from dgarske/cryptocb_only_test
Fixes for crypto callback only (no filesystem and keygen)
2 parents 5501111 + 6698cb7 commit 5804ba7

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

wolfcrypt/src/rsa.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4820,7 +4820,8 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
48204820
{
48214821
#ifndef WC_NO_RNG
48224822
#if !defined(WOLFSSL_CRYPTOCELL) && \
4823-
(!defined(WOLFSSL_SE050) || defined(WOLFSSL_SE050_NO_RSA))
4823+
(!defined(WOLFSSL_SE050) || defined(WOLFSSL_SE050_NO_RSA)) && \
4824+
!defined(WOLF_CRYPTO_CB_ONLY_RSA)
48244825
#ifdef WOLFSSL_SMALL_STACK
48254826
mp_int *p = NULL;
48264827
mp_int *q = NULL;
@@ -4911,6 +4912,11 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
49114912
/* fall-through when unavailable */
49124913
#endif
49134914
}
4915+
#if !defined(WOLF_CRYPTO_CB_FIND) && defined(WOLF_CRYPTO_CB_ONLY_RSA)
4916+
else {
4917+
err = NO_VALID_DEVID;
4918+
}
4919+
#endif
49144920
#endif
49154921

49164922
#ifndef WOLF_CRYPTO_CB_ONLY_RSA

wolfcrypt/test/test.c

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

27662766
#endif /* NO_MAIN_DRIVER */
27672767

2768+
#if defined(WOLF_CRYPTO_CB_ONLY_ECC) || defined(WOLF_CRYPTO_CB_ONLY_RSA)
2769+
#undef NO_WRITE_TEMP_FILES
2770+
#define NO_WRITE_TEMP_FILES
2771+
#endif
2772+
27682773
/* helper to save DER, convert to PEM and save PEM */
27692774
#if !defined(NO_ASN) && (defined(HAVE_ECC) || !defined(NO_DSA) || \
2770-
(!defined(NO_RSA) && (defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)))) \
2771-
&& !defined(WOLF_CRYPTO_CB_ONLY_ECC)
2775+
(!defined(NO_RSA) && (defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN))))
27722776

27732777
#if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
27742778
#define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, fD, fP, pT, WC_TEST_RET_LN)
@@ -21956,6 +21960,13 @@ static wc_test_ret_t rsa_keygen_test(WC_RNG* rng)
2195621960
int keySz = 2048;
2195721961
#endif
2195821962

21963+
#ifdef WOLF_CRYPTO_CB_ONLY_RSA
21964+
if (devId == INVALID_DEVID) {
21965+
/* must call keygen with devId */
21966+
return 0;
21967+
}
21968+
#endif
21969+
2195921970
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
2196021971
if (! genKey)
2196121972
ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
@@ -59660,6 +59671,7 @@ static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
5966059671

5966159672
#ifdef WOLFSSL_KEY_GEN
5966259673
WC_RNG rng;
59674+
word32 keySz = 2048;
5966359675
#endif
5966459676

5966559677
#ifdef USE_CERT_BUFFERS_1024
@@ -59717,15 +59729,15 @@ static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
5971759729
* wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success)
5971859730
*/
5971959731
ctx->exampleVar = 99;
59720-
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
59732+
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, &rng);
5972159733
if (ret != 0)
5972259734
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
5972359735
/* wc_MakeRsaKey() -> rsa cb ->
5972459736
* myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID)
5972559737
* wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure)
5972659738
*/
5972759739
ctx->exampleVar = 1;
59728-
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
59740+
ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, &rng);
5972959741
if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
5973059742
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
5973159743
} else

0 commit comments

Comments
 (0)