Improved on the fix of #309 and extended the test to cover subroutines.
diff --git a/library/bignum.c b/library/bignum.c
index 73ea453..8223b4c 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -893,12 +893,19 @@
if( X == B )
{
- const mpi *T;
+ if( B == A )
+ {
+ // Making a temporary copy instead of shifting by one to deny
+ // the possibility of corresponding side-channel attacks.
+ mpi TB;
- if( B == A)
- return mpi_shift_l( X, 1 );
+ mpi_init( &TB );
+ MBEDTLS_MPI_CHK( mpi_copy( &TB, B ) );
- T = A; A = X; B = T;
+ return mpi_add_abs( X, A, &TB );
+ }
+
+ B = A; A = X;
}
if( X != A )