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

diff --git a/ChangeLog b/ChangeLog
index 8c576a6..539256b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,6 +24,8 @@
      parity bits, to prevent mistakes in copying data. (Closes ticket #33)
    * Loads of minimal changes to better support WINCE as a build target
      (Credits go to Marco Lizza)
+   * Added POLARSSL_MPI_WINDOW_SIZE definition to allow easier time to memory
+     trade-off
 
 Bugfix
    * Fixed faulty HMAC-MD2 implementation. Found by dibac. (Closes
diff --git a/include/polarssl/bignum.h b/include/polarssl/bignum.h
index 7938406..1e46d12 100644
--- a/include/polarssl/bignum.h
+++ b/include/polarssl/bignum.h
@@ -46,6 +46,17 @@
 #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
  */
 #if defined(POLARSSL_HAVE_INT8)
diff --git a/library/bignum.c b/library/bignum.c
index c00697e..d4035b6 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -1377,7 +1377,7 @@
     size_t i, j, nblimbs;
     size_t bufsize, nbits;
     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 )
         return( POLARSSL_ERR_MPI_BAD_INPUT_DATA );
@@ -1394,6 +1394,9 @@
     wsize = ( i > 671 ) ? 6 : ( i > 239 ) ? 5 :
             ( i >  79 ) ? 4 : ( i >  23 ) ? 3 : 1;
 
+    if( wsize > POLARSSL_MPI_WINDOW_SIZE )
+        wsize = POLARSSL_MPI_WINDOW_SIZE;
+
     j = N->n + 1;
     MPI_CHK( mpi_grow( X, j ) );
     MPI_CHK( mpi_grow( &W[1],  j ) );