From 3fc644f246ec88bcb2f1ace61206fd0199f4de3f Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Sun, 25 Oct 2015 14:24:10 +0100 Subject: [PATCH] Removed recursion from fix #309. --- library/bignum.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/library/bignum.c b/library/bignum.c index 5e2512343..9c38117b0 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -859,22 +859,21 @@ int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi int ret; size_t i, j; mbedtls_mpi_uint *o, *p, c; + mbedtls_mpi TB; if( X == B ) { + B = A; A = X; + if( B == A ) { // Making a temporary copy instead of shifting by one to deny // the possibility of corresponding side-channel attacks. - mbedtls_mpi TB; - mbedtls_mpi_init( &TB ); MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TB, B ) ); - return mbedtls_mpi_add_abs( X, A, &TB ); + B = &TB; } - - B = A; A = X; } if( X != A ) @@ -911,6 +910,10 @@ int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi } cleanup: + if( &TB == B ) + { + mbedtls_mpi_free( &TB ); + } return( ret ); }