Skip to content

Commit b86e684

Browse files
author
Hanno Becker
committed
Move/remove param validation in mbedtls_rsa_rsaes_pkcs1_v15_encrypt
- The validity of the input and output parameters is checked by parameter validation. - A PRNG is required in public mode only (even though it's also recommended in private mode), so move the check to the corresponding branch.
1 parent a9020f2 commit b86e684

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

library/rsa.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,10 +1223,6 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
12231223
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V15 )
12241224
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
12251225

1226-
// We don't check p_rng because it won't be dereferenced here
1227-
if( f_rng == NULL || input == NULL || output == NULL )
1228-
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
1229-
12301226
olen = ctx->len;
12311227

12321228
/* first comparison checks for overflow */
@@ -1238,6 +1234,9 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
12381234
*p++ = 0;
12391235
if( mode == MBEDTLS_RSA_PUBLIC )
12401236
{
1237+
if( f_rng == NULL )
1238+
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
1239+
12411240
*p++ = MBEDTLS_RSA_CRYPT;
12421241

12431242
while( nb_pad-- > 0 )

0 commit comments

Comments
 (0)