Bignum: Add test for improved prime generation

This commit is contained in:
Janos Follath 2018-08-14 15:31:54 +01:00 committed by Darryl Green
parent f301d23ceb
commit a3cb7eb8ad
2 changed files with 15 additions and 3 deletions

View file

@ -708,6 +708,18 @@ Test mbedtls_mpi_gen_prime (Safe)
depends_on:MBEDTLS_GENPRIME
mbedtls_mpi_gen_prime:128:MBEDTLS_MPI_GEN_PRIME_FLAG_DH:0
Test mbedtls_mpi_gen_prime (Safe with lower error rate)
depends_on:MBEDTLS_GENPRIME
mbedtls_mpi_gen_prime:128:MBEDTLS_MPI_GEN_PRIME_FLAG_DH | MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR:0
Test mbedtls_mpi_gen_prime standard RSA #1 (lower error rate)
depends_on:MBEDTLS_GENPRIME
mbedtls_mpi_gen_prime:1024:MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR:0
Test mbedtls_mpi_gen_prime standard RSA #2 (lower error rate)
depends_on:MBEDTLS_GENPRIME
mbedtls_mpi_gen_prime:1536:MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR:0
Test bit getting (Value bit 25)
mbedtls_mpi_get_bit:10:"49979687":25:1

View file

@ -809,14 +809,14 @@ exit:
/* END_CASE */
/* BEGIN_CASE depends_on:MBEDTLS_GENPRIME */
void mbedtls_mpi_gen_prime( int bits, int safe, int ref_ret )
void mbedtls_mpi_gen_prime( int bits, int flags, int ref_ret )
{
mbedtls_mpi X;
int my_ret;
mbedtls_mpi_init( &X );
my_ret = mbedtls_mpi_gen_prime( &X, bits, safe, rnd_std_rand, NULL );
my_ret = mbedtls_mpi_gen_prime( &X, bits, flags, rnd_std_rand, NULL );
TEST_ASSERT( my_ret == ref_ret );
if( ref_ret == 0 )
@ -827,7 +827,7 @@ void mbedtls_mpi_gen_prime( int bits, int safe, int ref_ret )
TEST_ASSERT( actual_bits <= (size_t) bits + 1 );
TEST_ASSERT( mbedtls_mpi_is_prime( &X, rnd_std_rand, NULL ) == 0 );
if( safe )
if( flags & MBEDTLS_MPI_GEN_PRIME_FLAG_DH )
{
/* X = ( X - 1 ) / 2 */
TEST_ASSERT( mbedtls_mpi_shift_r( &X, 1 ) == 0 );