mbedtls/tests
Janos Follath 0b74161502 Bignum: Add tests for primality testing
Primality tests have to deal with different distribution when generating
primes and when validating primes.
These new tests are testing if mbedtls_mpi_is_prime() is working
properly in the latter setting.

The new tests involve pseudoprimes with maximum number of
non-witnesses. The non-witnesses were generated by printing them
from mpi_miller_rabin(). The pseudoprimes were generated by the
following function:

void gen_monier( mbedtls_mpi* res, int nbits )
{
    mbedtls_mpi p_2x_plus_1, p_4x_plus_1, x, tmp;

    mbedtls_mpi_init( &p_2x_plus_1 );
    mbedtls_mpi_init( &p_4x_plus_1 );
    mbedtls_mpi_init( &x ); mbedtls_mpi_init( &tmp );

    do
    {
        mbedtls_mpi_gen_prime( &p_2x_plus_1, nbits >> 1, 0,
                               rnd_std_rand, NULL );
        mbedtls_mpi_sub_int( &x, &p_2x_plus_1, 1 );
        mbedtls_mpi_div_int( &x, &tmp, &x, 2 );

        if( mbedtls_mpi_get_bit( &x, 0 ) == 0 )
            continue;

        mbedtls_mpi_mul_int( &p_4x_plus_1, &x, 4 );
        mbedtls_mpi_add_int( &p_4x_plus_1, &p_4x_plus_1, 1 );

        if( mbedtls_mpi_is_prime( &p_4x_plus_1, rnd_std_rand,
                                  NULL ) == 0 )
            break;

    } while( 1 );

    mbedtls_mpi_mul_mpi( res, &p_2x_plus_1, &p_4x_plus_1 );
}
2018-10-19 09:21:15 +01:00
..
data_files Fix parsing of PKCS#8 encoded Elliptic Curve keys. 2018-03-28 11:29:21 +02:00
git-scripts Add check-files.py to pre-push.sh 2018-06-05 11:57:21 +01:00
scripts Merge remote-tracking branch 'public/pr/779' into mbedtls-2.7 2018-07-24 13:38:44 +01:00
suites Bignum: Add tests for primality testing 2018-10-19 09:21:15 +01:00
.gitignore Move some ignore patterns to subdirectories 2015-01-28 15:33:23 +00:00
CMakeLists.txt Support out-of-tree testing with CMake 2018-03-21 12:28:59 +01:00
compat.sh Fix multiple quality issues in the source 2018-06-08 11:14:43 +01:00
Descriptions.txt
Makefile Make DLEXT var configurable in programs and tests makefiles 2018-03-27 20:04:18 +01:00
ssl-opt.sh ssl-opt.sh: change expected output for large srv packet test with SSLv3 2018-09-26 22:53:13 +01:00