Skip to content

Commit 4495da4

Browse files
authored
Merge pull request #8778 from rlm2002/ghi8772
add NULL reference checks to RSA functions
2 parents 91af907 + 7ae2c24 commit 4495da4

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

wolfcrypt/src/rsa.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,6 +3761,9 @@ int wc_RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out, RsaKey* key)
37613761
WC_RNG* rng;
37623762
int ret;
37633763
#ifdef WC_RSA_BLINDING
3764+
if (key == NULL) {
3765+
return BAD_FUNC_ARG;
3766+
}
37643767
rng = key->rng;
37653768
#else
37663769
rng = NULL;
@@ -3782,6 +3785,9 @@ int wc_RsaPrivateDecryptInline_ex(byte* in, word32 inLen, byte** out,
37823785
WC_RNG* rng;
37833786
int ret;
37843787
#ifdef WC_RSA_BLINDING
3788+
if (key == NULL) {
3789+
return BAD_FUNC_ARG;
3790+
}
37853791
rng = key->rng;
37863792
#else
37873793
rng = NULL;
@@ -3802,6 +3808,9 @@ int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out,
38023808
WC_RNG* rng;
38033809
int ret;
38043810
#ifdef WC_RSA_BLINDING
3811+
if (key == NULL) {
3812+
return BAD_FUNC_ARG;
3813+
}
38053814
rng = key->rng;
38063815
#else
38073816
rng = NULL;
@@ -3823,6 +3832,9 @@ int wc_RsaPrivateDecrypt_ex(const byte* in, word32 inLen, byte* out,
38233832
WC_RNG* rng;
38243833
int ret;
38253834
#ifdef WC_RSA_BLINDING
3835+
if (key == NULL) {
3836+
return BAD_FUNC_ARG;
3837+
}
38263838
rng = key->rng;
38273839
#else
38283840
rng = NULL;
@@ -3843,6 +3855,9 @@ int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, RsaKey* key)
38433855
WC_RNG* rng;
38443856
int ret;
38453857
#ifdef WC_RSA_BLINDING
3858+
if (key == NULL) {
3859+
return BAD_FUNC_ARG;
3860+
}
38463861
rng = key->rng;
38473862
#else
38483863
rng = NULL;
@@ -3951,6 +3966,9 @@ int wc_RsaPSS_VerifyInline_ex(byte* in, word32 inLen, byte** out,
39513966
WC_RNG* rng;
39523967
int ret;
39533968
#ifdef WC_RSA_BLINDING
3969+
if (key == NULL) {
3970+
return BAD_FUNC_ARG;
3971+
}
39543972
rng = key->rng;
39553973
#else
39563974
rng = NULL;
@@ -4006,6 +4024,9 @@ int wc_RsaPSS_Verify_ex(byte* in, word32 inLen, byte* out, word32 outLen,
40064024
WC_RNG* rng;
40074025
int ret;
40084026
#ifdef WC_RSA_BLINDING
4027+
if (key == NULL) {
4028+
return BAD_FUNC_ARG;
4029+
}
40094030
rng = key->rng;
40104031
#else
40114032
rng = NULL;
@@ -4192,6 +4213,9 @@ int wc_RsaPSS_VerifyCheckInline(byte* in, word32 inLen, byte** out,
41924213

41934214
saltLen = hLen;
41944215
#ifdef WOLFSSL_SHA512
4216+
if (key == NULL) {
4217+
return BAD_FUNC_ARG;
4218+
}
41954219
/* See FIPS 186-4 section 5.5 item (e). */
41964220
bits = mp_count_bits(&key->n);
41974221
if (bits == 1024 && hLen == WC_SHA512_DIGEST_SIZE)
@@ -4238,6 +4262,9 @@ int wc_RsaPSS_VerifyCheck(byte* in, word32 inLen, byte* out, word32 outLen,
42384262

42394263
saltLen = hLen;
42404264
#ifdef WOLFSSL_SHA512
4265+
if (key == NULL) {
4266+
return BAD_FUNC_ARG;
4267+
}
42414268
/* See FIPS 186-4 section 5.5 item (e). */
42424269
bits = mp_count_bits(&key->n);
42434270
if (bits == 1024 && hLen == WC_SHA512_DIGEST_SIZE)

0 commit comments

Comments
 (0)