Skip to content

Commit 2f660d0

Browse files
author
Hanno Becker
committed
Forbid passing NULL input buffers to RSA encryption routines
1 parent b86e684 commit 2f660d0

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

include/mbedtls/rsa.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,7 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
601601
* #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
602602
* \param ilen The length of the plaintext in Bytes.
603603
* \param input The input data to encrypt. This must be a readable
604-
* buffer of size \p ilen Bytes. It may be \c NULL if
605-
* `ilen == 0`.
604+
* buffer of size \p ilen Bytes. This must not be \c NULL.
606605
* \param output The output buffer. This must be a writable buffer
607606
* of length \c ctx->len Bytes. For example, \c 256 Bytes
608607
* for an 2048-bit RSA modulus.
@@ -642,8 +641,7 @@ int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx,
642641
* #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
643642
* \param ilen The length of the plaintext in Bytes.
644643
* \param input The input data to encrypt. This must be a readable
645-
* buffer of size \p ilen Bytes. It may be \c NULL if
646-
* `ilen == 0`.
644+
* buffer of size \p ilen Bytes. This must not be \c NULL.
647645
* \param output The output buffer. This must be a writable buffer
648646
* of length \c ctx->len Bytes. For example, \c 256 Bytes
649647
* for an 2048-bit RSA modulus.
@@ -687,8 +685,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
687685
* \param label_len The length of the label in Bytes.
688686
* \param ilen The length of the plaintext buffer \p input in Bytes.
689687
* \param input The input data to encrypt. This must be a readable
690-
* buffer of size \p ilen Bytes. It may be \c NULL if
691-
* `ilen == 0`.
688+
* buffer of size \p ilen Bytes. This must not be \c NULL.
692689
* \param output The output buffer. This must be a writable buffer
693690
* of length \c ctx->len Bytes. For example, \c 256 Bytes
694691
* for an 2048-bit RSA modulus.

library/rsa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx,
11351135
RSA_VALIDATE_RET( mode == MBEDTLS_RSA_PRIVATE ||
11361136
mode == MBEDTLS_RSA_PUBLIC );
11371137
RSA_VALIDATE_RET( output != NULL );
1138-
RSA_VALIDATE_RET( ilen == 0 || input != NULL );
1138+
RSA_VALIDATE_RET( input != NULL );
11391139
RSA_VALIDATE_RET( label_len == 0 || label != NULL );
11401140

11411141
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V21 )
@@ -1218,7 +1218,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
12181218
RSA_VALIDATE_RET( mode == MBEDTLS_RSA_PRIVATE ||
12191219
mode == MBEDTLS_RSA_PUBLIC );
12201220
RSA_VALIDATE_RET( output != NULL );
1221-
RSA_VALIDATE_RET( ilen == 0 || input != NULL );
1221+
RSA_VALIDATE_RET( input != NULL );
12221222

12231223
if( mode == MBEDTLS_RSA_PRIVATE && ctx->padding != MBEDTLS_RSA_PKCS_V15 )
12241224
return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA );
@@ -1285,7 +1285,7 @@ int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx,
12851285
RSA_VALIDATE_RET( mode == MBEDTLS_RSA_PRIVATE ||
12861286
mode == MBEDTLS_RSA_PUBLIC );
12871287
RSA_VALIDATE_RET( output != NULL );
1288-
RSA_VALIDATE_RET( ilen == 0 || input != NULL );
1288+
RSA_VALIDATE_RET( input != NULL );
12891289

12901290
switch( ctx->padding )
12911291
{

0 commit comments

Comments
 (0)