Commit 3d8fb63e authored by Paul Bakker's avatar Paul Bakker
Browse files

Added missing MPI_CHK around mpi functions

parent a9c16d28
......@@ -109,7 +109,7 @@ int asn1_write_mpi( unsigned char **p, unsigned char *start, mpi *X )
return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
(*p) -= len;
mpi_write_binary( X, *p, len );
MPI_CHK( mpi_write_binary( X, *p, len ) );
// DER format assumes 2s complement for numbers, so the leftmost bit
// should be 0 for positive numbers and 1 for negative numbers.
......@@ -126,7 +126,10 @@ int asn1_write_mpi( unsigned char **p, unsigned char *start, mpi *X )
ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_INTEGER ) );
return( (int) len );
ret = (int) len;
cleanup:
return( ret );
}
#endif /* POLARSSL_BIGNUM_C */
......
......@@ -92,8 +92,9 @@ static int dhm_check_range( const mpi *param, const mpi *P )
int ret = POLARSSL_ERR_DHM_BAD_INPUT_DATA;
mpi_init( &L ); mpi_init( &U );
mpi_lset( &L, 2 );
mpi_sub_int( &U, P, 2 );
MPI_CHK( mpi_lset( &L, 2 ) );
MPI_CHK( mpi_sub_int( &U, P, 2 ) );
if( mpi_cmp_mpi( param, &L ) >= 0 &&
mpi_cmp_mpi( param, &U ) <= 0 )
......@@ -101,8 +102,8 @@ static int dhm_check_range( const mpi *param, const mpi *P )
ret = 0;
}
cleanup:
mpi_free( &L ); mpi_free( &U );
return( ret );
}
......@@ -153,7 +154,7 @@ int dhm_make_params( dhm_context *ctx, int x_size,
mpi_fill_random( &ctx->X, x_size, f_rng, p_rng );
while( mpi_cmp_mpi( &ctx->X, &ctx->P ) >= 0 )
mpi_shift_r( &ctx->X, 1 );
MPI_CHK( mpi_shift_r( &ctx->X, 1 ) );
if( count++ > 10 )
return( POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED );
......@@ -239,7 +240,7 @@ int dhm_make_public( dhm_context *ctx, int x_size,
mpi_fill_random( &ctx->X, x_size, f_rng, p_rng );
while( mpi_cmp_mpi( &ctx->X, &ctx->P ) >= 0 )
mpi_shift_r( &ctx->X, 1 );
MPI_CHK( mpi_shift_r( &ctx->X, 1 ) );
if( count++ > 10 )
return( POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED );
......@@ -312,7 +313,7 @@ static int dhm_update_blinding( dhm_context *ctx,
mpi_fill_random( &ctx->Vi, mpi_size( &ctx->P ), f_rng, p_rng );
while( mpi_cmp_mpi( &ctx->Vi, &ctx->P ) >= 0 )
mpi_shift_r( &ctx->Vi, 1 );
MPI_CHK( mpi_shift_r( &ctx->Vi, 1 ) );
if( count++ > 10 )
return( POLARSSL_ERR_MPI_NOT_ACCEPTABLE );
......
......@@ -1125,7 +1125,7 @@ static int ecp_randomize_jac( const ecp_group *grp, ecp_point *pt,
mpi_fill_random( &l, p_size, f_rng, p_rng );
while( mpi_cmp_mpi( &l, &grp->P ) >= 0 )
mpi_shift_r( &l, 1 );
MPI_CHK( mpi_shift_r( &l, 1 ) );
if( count++ > 10 )
return( POLARSSL_ERR_ECP_RANDOM_FAILED );
......@@ -1510,7 +1510,7 @@ static int ecp_randomize_mxz( const ecp_group *grp, ecp_point *P,
mpi_fill_random( &l, p_size, f_rng, p_rng );
while( mpi_cmp_mpi( &l, &grp->P ) >= 0 )
mpi_shift_r( &l, 1 );
MPI_CHK( mpi_shift_r( &l, 1 ) );
if( count++ > 10 )
return( POLARSSL_ERR_ECP_RANDOM_FAILED );
......@@ -1598,7 +1598,7 @@ static int ecp_mul_mxz( ecp_group *grp, ecp_point *R,
ecp_point_init( &RP ); mpi_init( &PX );
/* Save PX and read from P before writing to R, in case P == R */
mpi_copy( &PX, &P->X );
MPI_CHK( mpi_copy( &PX, &P->X ) );
MPI_CHK( ecp_copy( &RP, P ) );
/* Set R to zero in modified x/z coordinates */
......
......@@ -1233,7 +1233,7 @@ static int ecp_mod_p255( mpi *N )
M.n++; /* Make room for multiplication by 19 */
/* N = A0 */
mpi_set_bit( N, 255, 0 );
MPI_CHK( mpi_set_bit( N, 255, 0 ) );
for( i = P255_WIDTH; i < N->n; i++ )
N->p[i] = 0;
......
......@@ -1486,6 +1486,7 @@ static int myrand( void *rng_state, unsigned char *output, size_t len )
*/
int rsa_self_test( int verbose )
{
int ret = 0;
#if defined(POLARSSL_PKCS1_V15)
size_t len;
rsa_context rsa;
......@@ -1499,14 +1500,14 @@ int rsa_self_test( int verbose )
rsa_init( &rsa, RSA_PKCS_V15, 0 );
rsa.len = KEY_LEN;
mpi_read_string( &rsa.N , 16, RSA_N );
mpi_read_string( &rsa.E , 16, RSA_E );
mpi_read_string( &rsa.D , 16, RSA_D );
mpi_read_string( &rsa.P , 16, RSA_P );
mpi_read_string( &rsa.Q , 16, RSA_Q );
mpi_read_string( &rsa.DP, 16, RSA_DP );
mpi_read_string( &rsa.DQ, 16, RSA_DQ );
mpi_read_string( &rsa.QP, 16, RSA_QP );
MPI_CHK( mpi_read_string( &rsa.N , 16, RSA_N ) );
MPI_CHK( mpi_read_string( &rsa.E , 16, RSA_E ) );
MPI_CHK( mpi_read_string( &rsa.D , 16, RSA_D ) );
MPI_CHK( mpi_read_string( &rsa.P , 16, RSA_P ) );
MPI_CHK( mpi_read_string( &rsa.Q , 16, RSA_Q ) );
MPI_CHK( mpi_read_string( &rsa.DP, 16, RSA_DP ) );
MPI_CHK( mpi_read_string( &rsa.DQ, 16, RSA_DQ ) );
MPI_CHK( mpi_read_string( &rsa.QP, 16, RSA_QP ) );
if( verbose != 0 )
polarssl_printf( " RSA key validation: " );
......@@ -1586,11 +1587,12 @@ int rsa_self_test( int verbose )
polarssl_printf( "passed\n\n" );
#endif /* POLARSSL_SHA1_C */
cleanup:
rsa_free( &rsa );
#else /* POLARSSL_PKCS1_V15 */
((void) verbose);
#endif /* POLARSSL_PKCS1_V15 */
return( 0 );
return( ret );
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment