- Added POLARSSL_MPI_WINDOW_SIZE definition to allow easier time to memory trade-off

This commit is contained in:
Paul Bakker 2011-11-25 11:52:11 +00:00
parent 2e6d5328d5
commit b6d5f08051
3 changed files with 17 additions and 1 deletions

View file

@ -24,6 +24,8 @@ Changes
parity bits, to prevent mistakes in copying data. (Closes ticket #33) parity bits, to prevent mistakes in copying data. (Closes ticket #33)
* Loads of minimal changes to better support WINCE as a build target * Loads of minimal changes to better support WINCE as a build target
(Credits go to Marco Lizza) (Credits go to Marco Lizza)
* Added POLARSSL_MPI_WINDOW_SIZE definition to allow easier time to memory
trade-off
Bugfix Bugfix
* Fixed faulty HMAC-MD2 implementation. Found by dibac. (Closes * Fixed faulty HMAC-MD2 implementation. Found by dibac. (Closes

View file

@ -45,6 +45,17 @@
*/ */
#define POLARSSL_MPI_MAX_LIMBS 10000 #define POLARSSL_MPI_MAX_LIMBS 10000
/*
* Maximum window size used for modular exponentiation. Default: 6
* Minimum value: 1. Maximum value: 6.
*
* Result is an array of ( 2 << POLARSSL_MPI_WINDOW_SIZE ) MPIs used
* for the sliding window calculation. (So 64 by default)
*
* Reduction in size, reduces speed.
*/
#define POLARSSL_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */
/* /*
* Define the base integer type, architecture-wise * Define the base integer type, architecture-wise
*/ */

View file

@ -1377,7 +1377,7 @@ int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR )
size_t i, j, nblimbs; size_t i, j, nblimbs;
size_t bufsize, nbits; size_t bufsize, nbits;
t_uint ei, mm, state; t_uint ei, mm, state;
mpi RR, T, W[64]; mpi RR, T, W[ 2 << POLARSSL_MPI_WINDOW_SIZE ];
if( mpi_cmp_int( N, 0 ) < 0 || ( N->p[0] & 1 ) == 0 ) if( mpi_cmp_int( N, 0 ) < 0 || ( N->p[0] & 1 ) == 0 )
return( POLARSSL_ERR_MPI_BAD_INPUT_DATA ); return( POLARSSL_ERR_MPI_BAD_INPUT_DATA );
@ -1394,6 +1394,9 @@ int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR )
wsize = ( i > 671 ) ? 6 : ( i > 239 ) ? 5 : wsize = ( i > 671 ) ? 6 : ( i > 239 ) ? 5 :
( i > 79 ) ? 4 : ( i > 23 ) ? 3 : 1; ( i > 79 ) ? 4 : ( i > 23 ) ? 3 : 1;
if( wsize > POLARSSL_MPI_WINDOW_SIZE )
wsize = POLARSSL_MPI_WINDOW_SIZE;
j = N->n + 1; j = N->n + 1;
MPI_CHK( mpi_grow( X, j ) ); MPI_CHK( mpi_grow( X, j ) );
MPI_CHK( mpi_grow( &W[1], j ) ); MPI_CHK( mpi_grow( &W[1], j ) );