mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-23 18:15:35 +00:00
Fix bug in mpi_safe_cond_assign()
This commit is contained in:
parent
918148193d
commit
3e3d2b818c
|
@ -222,6 +222,7 @@ int mpi_safe_cond_assign( mpi *X, mpi *Y, unsigned char assign )
|
|||
MPI_CHK( mpi_grow( X, Y->n ) );
|
||||
|
||||
/* Do the conditional assign safely */
|
||||
X->s = X->s * (1 - assign) + Y->s * assign;
|
||||
for( i = 0; i < X->n; i++ )
|
||||
X->p[i] = X->p[i] * (1 - assign) + Y->p[i] * assign;
|
||||
|
||||
|
|
|
@ -206,13 +206,22 @@ Test mpi_shrink #8
|
|||
mpi_shrink:4:0:0:1
|
||||
|
||||
Test mpi_safe_cond_assign #1
|
||||
mpi_safe_cond_assign:"01":"02"
|
||||
mpi_safe_cond_assign:+1:"01":+1:"02"
|
||||
|
||||
Test mpi_safe_cond_assign #2
|
||||
mpi_safe_cond_assign:"FF000000000000000001":"02"
|
||||
mpi_safe_cond_assign:+1:"FF000000000000000001":+1:"02"
|
||||
|
||||
Test mpi_safe_cond_assign #3
|
||||
mpi_safe_cond_assign:"01":"FF000000000000000002"
|
||||
mpi_safe_cond_assign:+1:"01":+1:"FF000000000000000002"
|
||||
|
||||
Test mpi_safe_cond_assign #4
|
||||
mpi_safe_cond_assign:+1:"01":-1:"02"
|
||||
|
||||
Test mpi_safe_cond_assign #5
|
||||
mpi_safe_cond_assign:-1:"01":+1:"02"
|
||||
|
||||
Test mpi_safe_cond_assign #6
|
||||
mpi_safe_cond_assign:-1:"01":-1:"02"
|
||||
|
||||
Base test mpi_add_abs #1
|
||||
mpi_add_abs:10:"12345678":10:"642531":10:"12988209"
|
||||
|
|
|
@ -309,13 +309,16 @@ void mpi_shrink( int before, int used, int min, int after )
|
|||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_safe_cond_assign( char *x_str, char *y_str )
|
||||
void mpi_safe_cond_assign( int x_sign, char *x_str,
|
||||
int y_sign, char *y_str )
|
||||
{
|
||||
mpi X, Y, XX;
|
||||
mpi_init( &X ); mpi_init( &Y ); mpi_init( &XX );
|
||||
|
||||
TEST_ASSERT( mpi_read_string( &X, 16, x_str ) == 0 );
|
||||
X.s = x_sign;
|
||||
TEST_ASSERT( mpi_read_string( &Y, 16, y_str ) == 0 );
|
||||
Y.s = y_sign;
|
||||
TEST_ASSERT( mpi_copy( &XX, &X ) == 0 );
|
||||
|
||||
TEST_ASSERT( mpi_safe_cond_assign( &X, &Y, 0 ) == 0 );
|
||||
|
|
Loading…
Reference in a new issue