From 2b806fad7b65f1c0ae91c03d50c15378c466e232 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 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/library/bignum.c b/library/bignum.c index 8223b4cb6..e46ce0b52 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -889,23 +889,22 @@ int mpi_add_abs( mpi *X, const mpi *A, const mpi *B ) { int ret; size_t i, j; - t_uint *o, *p, c; + mpi_uint *o, *p, c; + 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. - mpi TB; - mpi_init( &TB ); - MBEDTLS_MPI_CHK( mpi_copy( &TB, B ) ); + MPI_CHK( mpi_copy( &TB, B ) ); - return mpi_add_abs( X, A, &TB ); + B = &TB; } - - B = A; A = X; } if( X != A ) @@ -942,6 +941,10 @@ int mpi_add_abs( mpi *X, const mpi *A, const mpi *B ) } cleanup: + if( &TB == B ) + { + mpi_free( &TB ); + } return( ret ); }