Skip to content

Commit 3070242

Browse files
committed
mpi_lt_mpi_ct: fix condition handling
The code previously only set the done flag if the return value was one. This led to overriding the correct return value later on.
1 parent 0b1ae0e commit 3070242

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

library/bignum.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,26 +1224,25 @@ int mbedtls_mpi_lt_mpi_ct( const mbedtls_mpi *X, const mbedtls_mpi *Y,
12241224
for( i = X->n; i > 0; i-- )
12251225
{
12261226
/*
1227-
* If Y->p[i - 1] < X->p[i - 1] and both X and Y are negative, then
1228-
* X < Y.
1227+
* If Y->p[i - 1] < X->p[i - 1] then X < Y is true if and only if both
1228+
* X and Y are negative.
12291229
*
12301230
* Again even if we can make a decision, we just mark the result and
12311231
* the fact that we are done and continue looping.
12321232
*/
1233-
cond = ct_lt_mpi_uint( Y->p[i - 1], X->p[i - 1] ) & X_is_negative;
1234-
*ret |= cond & ( 1 - done );
1233+
cond = ct_lt_mpi_uint( Y->p[i - 1], X->p[i - 1] );
1234+
*ret |= cond & ( 1 - done ) & X_is_negative;
12351235
done |= cond;
12361236

12371237
/*
1238-
* If X->p[i - 1] < Y->p[i - 1] and both X and Y are positive, then
1239-
* X < Y.
1238+
* If X->p[i - 1] < Y->p[i - 1] then X < Y is true if and only if both
1239+
* X and Y are positive.
12401240
*
12411241
* Again even if we can make a decision, we just mark the result and
12421242
* the fact that we are done and continue looping.
12431243
*/
1244-
cond = ct_lt_mpi_uint( X->p[i - 1], Y->p[i - 1] )
1245-
& ( 1 - X_is_negative );
1246-
*ret |= cond & ( 1 - done );
1244+
cond = ct_lt_mpi_uint( X->p[i - 1], Y->p[i - 1] );
1245+
*ret |= cond & ( 1 - done ) & ( 1 - X_is_negative );
12471246
done |= cond;
12481247
}
12491248

0 commit comments

Comments
 (0)