From 48eab260e9a70ed88ef28900483b0964f847ef17 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Thu, 25 Jun 2009 21:25:49 +0000 Subject: [PATCH] - Corrected is_prime() results for 0, 1 and 2 (found by code coverage tests) --- ChangeLog | 2 ++ library/bignum.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5dc686e4a2..b72b055d65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,8 @@ Bug fixes value in mpi_mod_mpi() and mpi_mod_int(). Resulting change also affects mpi_write_string() (found by code coverage tests). + * Corrected is_prime() results for 0, 1 and 2 (found by + code coverage tests). = Version 0.11.1 released on 2009-05-17 * Fixed missing functionality for SHA-224, SHA-256, SHA384, diff --git a/library/bignum.c b/library/bignum.c index d1646f090d..aa7230fdb7 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -1683,7 +1683,11 @@ int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng ) mpi W, R, T, A, RR; unsigned char *p; - if( mpi_cmp_int( X, 0 ) == 0 ) + if( mpi_cmp_int( X, 0 ) == 0 || + mpi_cmp_int( X, 1 ) == 0 ) + return( POLARSSL_ERR_MPI_NOT_ACCEPTABLE ); + + if( mpi_cmp_int( X, 2 ) == 0 ) return( 0 ); mpi_init( &W, &R, &T, &A, &RR, NULL );