From 388f9b2d0ff843fa7dbb59251d9ce29ffc0568ee Mon Sep 17 00:00:00 2001 From: Daniel Otte Date: Fri, 21 Aug 2020 12:34:29 +0200 Subject: [PATCH 1/4] adjusting size of sliding window array to correct size. Probably the `W[2 << MBEDTLS_MPI_WINDOW_SIZE]` notation is based on a transcription of 2**MBEDTLS_MPI_WINDOW_SIZE. Signed-off-by: Daniel Otte --- library/bignum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/bignum.c b/library/bignum.c index 9325632b42c5..fa97d19f7231 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -2101,7 +2101,7 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, size_t i, j, nblimbs; size_t bufsize, nbits; mbedtls_mpi_uint ei, mm, state; - mbedtls_mpi RR, T, W[ 2 << MBEDTLS_MPI_WINDOW_SIZE ], Apos; + mbedtls_mpi RR, T, W[ 1 << MBEDTLS_MPI_WINDOW_SIZE ], Apos; int neg; MPI_VALIDATE_RET( X != NULL ); From 4374dc493df688e2c684f230b0c4ac8a0a5c2548 Mon Sep 17 00:00:00 2001 From: Daniel Otte Date: Mon, 7 Sep 2020 13:06:40 +0200 Subject: [PATCH 2/4] fixing spelling mistakes (window <-- windows) Signed-off-by: Daniel Otte --- include/mbedtls/bignum.h | 2 +- include/mbedtls/config.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mbedtls/bignum.h b/include/mbedtls/bignum.h index 0d019b9c44e7..8ab2dd526ed5 100644 --- a/include/mbedtls/bignum.h +++ b/include/mbedtls/bignum.h @@ -66,7 +66,7 @@ * * Reduction in size, reduces speed. */ -#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */ +#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum window size used. */ #endif /* !MBEDTLS_MPI_WINDOW_SIZE */ #if !defined(MBEDTLS_MPI_MAX_SIZE) diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h index 6f457daa0c6f..900aa7e0bba1 100644 --- a/include/mbedtls/config.h +++ b/include/mbedtls/config.h @@ -3414,7 +3414,7 @@ */ /* MPI / BIGNUM options */ -//#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum windows size used. */ +//#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum window size used. */ //#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */ /* CTR_DRBG options */ From 608615168a42293175792f9c4c0f557da60d1e4b Mon Sep 17 00:00:00 2001 From: Daniel Otte Date: Mon, 7 Sep 2020 13:07:14 +0200 Subject: [PATCH 3/4] adjusting comment on sliding window memory usage. The comment now uses '**' as exponentiation operator. Signed-off-by: Daniel Otte --- include/mbedtls/bignum.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbedtls/bignum.h b/include/mbedtls/bignum.h index 8ab2dd526ed5..637360e30f18 100644 --- a/include/mbedtls/bignum.h +++ b/include/mbedtls/bignum.h @@ -61,7 +61,7 @@ * Maximum window size used for modular exponentiation. Default: 6 * Minimum value: 1. Maximum value: 6. * - * Result is an array of ( 2 << MBEDTLS_MPI_WINDOW_SIZE ) MPIs used + * Result is an array of ( 2 ** MBEDTLS_MPI_WINDOW_SIZE ) MPIs used * for the sliding window calculation. (So 64 by default) * * Reduction in size, reduces speed. From b9da1dd335f60a07c7547f16c08d6529209007ac Mon Sep 17 00:00:00 2001 From: Daniel Otte Date: Mon, 7 Sep 2020 13:08:10 +0200 Subject: [PATCH 4/4] adding entry file to ChangeLog.d for PR3592 Signed-off-by: Daniel Otte --- ChangeLog.d/adjusting sliding_window_size_PR3592.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ChangeLog.d/adjusting sliding_window_size_PR3592.txt diff --git a/ChangeLog.d/adjusting sliding_window_size_PR3592.txt b/ChangeLog.d/adjusting sliding_window_size_PR3592.txt new file mode 100644 index 000000000000..608956541372 --- /dev/null +++ b/ChangeLog.d/adjusting sliding_window_size_PR3592.txt @@ -0,0 +1,3 @@ +Changes + * Reduce stack usage significantly during sliding window exponentiation. + Reported in #3591 and fix contributed in #3592 by Daniel Otte.