Remove argument checking from constant time functions
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
diff --git a/library/bignum_core.c b/library/bignum_core.c
index 6aa1e00..9adc4ef 100644
--- a/library/bignum_core.c
+++ b/library/bignum_core.c
@@ -162,59 +162,36 @@
}
}
-int mbedtls_mpi_core_cond_assign( mbedtls_mpi_uint *X,
- size_t X_limbs,
- const mbedtls_mpi_uint *Y,
- size_t Y_limbs,
- unsigned char assign )
+void mbedtls_mpi_core_cond_assign( mbedtls_mpi_uint *X,
+ size_t X_limbs,
+ const mbedtls_mpi_uint *Y,
+ size_t Y_limbs,
+ unsigned char assign )
{
- if( X_limbs < Y_limbs )
- return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL );
+ /* all-bits 1 if assign is 1, all-bits 0 if assign is 0 */
+ mbedtls_mpi_uint limb_mask = mbedtls_ct_mpi_uint_mask( assign );
- if( X != NULL && Y != NULL )
- {
- /* all-bits 1 if assign is 1, all-bits 0 if assign is 0 */
- mbedtls_mpi_uint limb_mask = mbedtls_ct_mpi_uint_mask( assign );
+ mbedtls_ct_mpi_uint_cond_assign( Y_limbs, X, Y, assign );
- mbedtls_ct_mpi_uint_cond_assign( X_limbs, X, Y, assign );
-
- for( size_t i = Y_limbs; i < X_limbs; i++ )
- X[i] &= ~limb_mask;
-
- return( 0 );
- }
-
- return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
+ for( size_t i = Y_limbs; i < X_limbs; i++ )
+ X[i] &= ~limb_mask;
}
-int mbedtls_mpi_core_cond_swap( mbedtls_mpi_uint *X,
- size_t X_limbs,
- mbedtls_mpi_uint *Y,
- size_t Y_limbs,
- unsigned char swap )
+void mbedtls_mpi_core_cond_swap( mbedtls_mpi_uint *X,
+ size_t X_limbs,
+ mbedtls_mpi_uint *Y,
+ size_t Y_limbs,
+ unsigned char swap )
{
- if( X == Y )
- return( 0 );
+ /* all-bits 1 if swap is 1, all-bits 0 if swap is 0 */
+ mbedtls_mpi_uint limb_mask = mbedtls_ct_mpi_uint_mask( swap );
- if( X_limbs != Y_limbs )
- return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL );
-
- if( X != NULL && Y != NULL )
+ for( size_t i = 0; i < X_limbs; i++ )
{
- /* all-bits 1 if swap is 1, all-bits 0 if swap is 0 */
- mbedtls_mpi_uint limb_mask = mbedtls_ct_mpi_uint_mask( swap );
-
- for( size_t i = 0; i < X_limbs; i++ )
- {
- mbedtls_mpi_uint tmp = X[i];
- X[i] = ( X[i] & ~limb_mask ) | ( Y[i] & limb_mask );
- Y[i] = ( Y[i] & ~limb_mask ) | ( tmp & limb_mask );
- }
-
- return( 0 );
+ mbedtls_mpi_uint tmp = X[i];
+ X[i] = ( X[i] & ~limb_mask ) | ( Y[i] & limb_mask );
+ Y[i] = ( Y[i] & ~limb_mask ) | ( tmp & limb_mask );
}
-
- return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
}
int mbedtls_mpi_core_read_le( mbedtls_mpi_uint *X,
diff --git a/library/bignum_core.h b/library/bignum_core.h
index 24650fe..a538ece 100644
--- a/library/bignum_core.h
+++ b/library/bignum_core.h
@@ -93,17 +93,12 @@
* \warning If \p assign is neither 0 nor 1, the result of this function
* is indeterminate, and the resulting value in \p X might be
* neither its original value nor the value in \p Y.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
- * large enough to hold the value in \p Y.
- * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p X or \p Y is invalid.
*/
-int mbedtls_mpi_core_cond_assign( mbedtls_mpi_uint *X,
- size_t X_limbs,
- const mbedtls_mpi_uint *Y,
- size_t Y_limbs,
- unsigned char assign );
+void mbedtls_mpi_core_cond_assign( mbedtls_mpi_uint *X,
+ size_t X_limbs,
+ const mbedtls_mpi_uint *Y,
+ size_t Y_limbs,
+ unsigned char assign );
/**
* \brief Perform a safe conditional copy of MPI which doesn't reveal whether
@@ -126,17 +121,12 @@
* \warning If \p swap is neither 0 nor 1, the result of this function
* is indeterminate, and both \p X and \p Y might end up with
* values different to either of the original ones.
- *
- * \return \c 0 if successful.
- * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the size of
- * \p X and \p Y is differ.
- * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p X or \p Y is invalid.
*/
-int mbedtls_mpi_core_cond_swap( mbedtls_mpi_uint *X,
- size_t X_limbs,
- mbedtls_mpi_uint *Y,
- size_t Y_limbs,
- unsigned char swap );
+void mbedtls_mpi_core_cond_swap( mbedtls_mpi_uint *X,
+ size_t X_limbs,
+ mbedtls_mpi_uint *Y,
+ size_t Y_limbs,
+ unsigned char swap );
/** Import X from unsigned binary data, little-endian.
*