mirror of
				https://github.com/Mbed-TLS/mbedtls.git
				synced 2025-11-03 20:33:16 +03:00 
			
		
		
		
	Skip redundant checks for NULL f_rng
Unless MBEDTLS_ECP_NO_INTERNAL_RNG is defined, it's no longer possible for f_rng to be NULL at the places that randomize coordinates. Eliminate the NULL check in this case: - it makes it clearer to reviewers that randomization always happens (unless the user opted out at compile time) - a NULL check in a place where it's easy to prove the value is never NULL might upset or confuse static analyzers (including humans) - removing the check saves a bit of code size Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
		@@ -1948,7 +1948,9 @@ static int ecp_mul_comb_core( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R
 | 
			
		||||
        i = d;
 | 
			
		||||
        MBEDTLS_MPI_CHK( ecp_select_comb( grp, R, T, T_size, x[i] ) );
 | 
			
		||||
        MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &R->Z, 1 ) );
 | 
			
		||||
#if defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
 | 
			
		||||
        if( f_rng != 0 )
 | 
			
		||||
#endif
 | 
			
		||||
            MBEDTLS_MPI_CHK( ecp_randomize_jac( grp, R, f_rng, p_rng ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -2081,7 +2083,9 @@ final_norm:
 | 
			
		||||
     *
 | 
			
		||||
     * Avoid the leak by randomizing coordinates before we normalize them.
 | 
			
		||||
     */
 | 
			
		||||
#if defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
 | 
			
		||||
    if( f_rng != 0 )
 | 
			
		||||
#endif
 | 
			
		||||
        MBEDTLS_MPI_CHK( ecp_randomize_jac( grp, RR, f_rng, p_rng ) );
 | 
			
		||||
 | 
			
		||||
    MBEDTLS_ECP_BUDGET( MBEDTLS_ECP_OPS_INV );
 | 
			
		||||
@@ -2484,7 +2488,9 @@ static int ecp_mul_mxz( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
 | 
			
		||||
    MOD_ADD( RP.X );
 | 
			
		||||
 | 
			
		||||
    /* Randomize coordinates of the starting point */
 | 
			
		||||
#if defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
 | 
			
		||||
    if( f_rng != NULL )
 | 
			
		||||
#endif
 | 
			
		||||
        MBEDTLS_MPI_CHK( ecp_randomize_mxz( grp, &RP, f_rng, p_rng ) );
 | 
			
		||||
 | 
			
		||||
    /* Loop invariant: R = result so far, RP = R + P */
 | 
			
		||||
@@ -2517,7 +2523,9 @@ static int ecp_mul_mxz( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
 | 
			
		||||
     *
 | 
			
		||||
     * Avoid the leak by randomizing coordinates before we normalize them.
 | 
			
		||||
     */
 | 
			
		||||
#if defined(MBEDTLS_ECP_NO_INTERNAL_RNG)
 | 
			
		||||
    if( f_rng != NULL )
 | 
			
		||||
#endif
 | 
			
		||||
        MBEDTLS_MPI_CHK( ecp_randomize_mxz( grp, R, f_rng, p_rng ) );
 | 
			
		||||
 | 
			
		||||
    MBEDTLS_MPI_CHK( ecp_normalize_mxz( grp, R ) );
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user