more constant-time computation

This commit is contained in:
NIIBE Yutaka
2013-12-23 10:13:04 +09:00
parent 67d4f1b441
commit b7c4e3a9c2
2 changed files with 7 additions and 3 deletions

View File

@@ -1,3 +1,8 @@
2013-12-23 Niibe Yutaka <gniibe@fsij.org>
* polarssl/library/bignum.c (mpi_montmul): Computation
time should not depends on input.
2013-12-20 Niibe Yutaka <gniibe@fsij.org>
* Version 1.1.0.

View File

@@ -1386,12 +1386,11 @@ static void mpi_montg_init( t_uint *mm, const mpi *N )
*/
static void mpi_montmul( const mpi *B, const mpi *N, t_uint mm, mpi *T )
{
size_t i, n, m;
size_t i, n;
t_uint u0, u1, *d, c = 0;
d = T->p;
n = N->n;
m = ( B->n < n ) ? B->n : n;
for( i = 0; i < n; i++ )
{
@@ -1402,7 +1401,7 @@ static void mpi_montmul( const mpi *B, const mpi *N, t_uint mm, mpi *T )
d[n] = c;
u1 = ( d[0] + u0 * B->p[0] ) * mm;
mpi_mul_hlp( m, B->p, d, u0 );
mpi_mul_hlp( n, B->p, d, u0 );
c = mpi_mul_hlp( n, N->p, d, u1 );
d++;
}