Add test for mpi_gen_prime()
This commit is contained in:
parent
fab2a3c3d6
commit
15f58a86f7
2 changed files with 46 additions and 0 deletions
|
@ -656,6 +656,22 @@ Test mpi_is_prime #20
|
|||
depends_on:POLARSSL_GENPRIME
|
||||
mpi_is_prime:10:"49979687":0
|
||||
|
||||
Test mpi_gen_prime (Too small)
|
||||
depends_on:POLARSSL_GENPRIME
|
||||
mpi_gen_prime:2:0:POLARSSL_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
Test mpi_gen_prime (OK, minimum size)
|
||||
depends_on:POLARSSL_GENPRIME
|
||||
mpi_gen_prime:3:0:0
|
||||
|
||||
Test mpi_gen_prime (Larger)
|
||||
depends_on:POLARSSL_GENPRIME
|
||||
mpi_gen_prime:128:0:0
|
||||
|
||||
Test mpi_gen_prime (Safe)
|
||||
depends_on:POLARSSL_GENPRIME
|
||||
mpi_gen_prime:128:1:0
|
||||
|
||||
Test bit getting (Value bit 25)
|
||||
mpi_get_bit:10:"49979687":25:1
|
||||
|
||||
|
|
|
@ -719,6 +719,36 @@ void mpi_is_prime( int radix_X, char *input_X, int div_result )
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:POLARSSL_GENPRIME */
|
||||
void mpi_gen_prime( int bits, int safe, int ref_ret )
|
||||
{
|
||||
mpi X;
|
||||
int my_ret;
|
||||
|
||||
mpi_init( &X );
|
||||
|
||||
my_ret = mpi_gen_prime( &X, bits, safe, rnd_std_rand, NULL );
|
||||
TEST_ASSERT( my_ret == ref_ret );
|
||||
|
||||
if( ref_ret == 0 )
|
||||
{
|
||||
size_t actual_bits = mpi_msb( &X );
|
||||
|
||||
TEST_ASSERT( actual_bits >= (size_t) bits );
|
||||
TEST_ASSERT( actual_bits <= (size_t) bits + 1 );
|
||||
|
||||
TEST_ASSERT( mpi_is_prime( &X, rnd_std_rand, NULL ) == 0 );
|
||||
if( safe )
|
||||
{
|
||||
mpi_shift_r( &X, 1 ); /* X = ( X - 1 ) / 2 */
|
||||
TEST_ASSERT( mpi_is_prime( &X, rnd_std_rand, NULL ) == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
mpi_free( &X );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_shift_l( int radix_X, char *input_X, int shift_X, int radix_A,
|
||||
char *input_A)
|
||||
|
|
Loading…
Reference in a new issue