mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 03:25:46 +01:00
Improved on the previous fix and added a test case to cover both types
of carries.
This commit is contained in:
parent
2b806fad7b
commit
2db440d2f1
@ -889,22 +889,11 @@ int mpi_add_abs( mpi *X, const mpi *A, const mpi *B )
|
||||
{
|
||||
int ret;
|
||||
size_t i, j;
|
||||
mpi_uint *o, *p, c;
|
||||
mpi TB;
|
||||
mpi_uint *o, *p, c, tmp;
|
||||
|
||||
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_init( &TB );
|
||||
MPI_CHK( mpi_copy( &TB, B ) );
|
||||
|
||||
B = &TB;
|
||||
}
|
||||
const mpi *T = A; A = X; B = T;
|
||||
}
|
||||
|
||||
if( X != A )
|
||||
@ -923,10 +912,14 @@ int mpi_add_abs( mpi *X, const mpi *A, const mpi *B )
|
||||
|
||||
o = B->p; p = X->p; c = 0;
|
||||
|
||||
/*
|
||||
* tmp is used because it might happen that p == o
|
||||
*/
|
||||
for( i = 0; i < j; i++, o++, p++ )
|
||||
{
|
||||
tmp= *o;
|
||||
*p += c; c = ( *p < c );
|
||||
*p += *o; c += ( *p < *o );
|
||||
*p += tmp; c += ( *p < tmp );
|
||||
}
|
||||
|
||||
while( c != 0 )
|
||||
@ -941,10 +934,13 @@ int mpi_add_abs( mpi *X, const mpi *A, const mpi *B )
|
||||
}
|
||||
|
||||
cleanup:
|
||||
<<<<<<< HEAD
|
||||
if( &TB == B )
|
||||
{
|
||||
mpi_free( &TB );
|
||||
}
|
||||
=======
|
||||
>>>>>>> 6c9226809370... Improved on the previous fix and added a test case to cover both types
|
||||
|
||||
return( ret );
|
||||
}
|
||||
|
@ -301,6 +301,9 @@ mpi_add_mpi_inplace:10:"12345678":10:"24691356"
|
||||
Test mpi_add_mpi inplace #2
|
||||
mpi_add_mpi_inplace:10:"643808006803554439230129854961492699151386107534013432918073439524138264842370630061369715394739134090922937332590384720397133335969549256322620979036686633213903952966175107096769180017646161851573147596390153":10:"1287616013607108878460259709922985398302772215068026865836146879048276529684741260122739430789478268181845874665180769440794266671939098512645241958073373266427807905932350214193538360035292323703146295192780306"
|
||||
|
||||
Test mpi_add_mpi inplace #3
|
||||
mpi_add_mpi_inplace:16:"ffffffffffffffffffffffffffffffff":16:"01fffffffffffffffffffffffffffffffe"
|
||||
|
||||
Test mpi_add_int #1
|
||||
mpi_add_int:10:"2039568783564019774057658669290345772801939933143482630947726464532830627227012776329":9871232:10:"2039568783564019774057658669290345772801939933143482630947726464532830627227022647561"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user