mbedtls_mpi_mod_read/write: remove redundant checks
The function isn't documented as accepting null pointer, and there's no
reason why it should be. Just let it dereference the pointer.
The null/zero checks are only marginally useful: they validate that m
and r are properly populated objects, not freshly initialized ones. For
that, it's enough to check that the pointers aren't null or that the
sizes aren't zero, we don't need to check both.
Also, use separate if statements for unrelated checks.
Signed-off-by: Janos Follath <janos.follath@arm.com>
diff --git a/library/bignum_mod.c b/library/bignum_mod.c
index 3cb3c43..f07307c 100644
--- a/library/bignum_mod.c
+++ b/library/bignum_mod.c
@@ -203,11 +203,11 @@
{
int ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
- if ( r == NULL || m == NULL )
- goto cleanup;
- if ( r->p == NULL || m->p == NULL || r->limbs > m->limbs ||
- r->limbs == 0 || m->limbs == 0 )
+ /* Do our best to check if r and m have been set up */
+ if ( r->limbs == 0 || m->limbs == 0 )
+ goto cleanup;
+ if ( r->limbs > m->limbs )
goto cleanup;
ret = mbedtls_mpi_mod_raw_read( r->p, m, buf, buflen, ext_rep );
@@ -232,11 +232,10 @@
{
int ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
- if ( r == NULL || m == NULL )
+ /* Do our best to check if r and m have been set up */
+ if ( r->limbs == 0 || m->limbs == 0 )
goto cleanup;
-
- if ( r->p == NULL || m->p == NULL || r->limbs > m->limbs ||
- r->limbs == 0 || m->limbs == 0 )
+ if ( r->limbs > m->limbs )
goto cleanup;
if ( m->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY)