Use new CT interface in mbedtls_mpi_core_lt_ct
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
231a516682
commit
8ac9a1df24
2 changed files with 15 additions and 19 deletions
|
@ -166,15 +166,11 @@ mbedtls_ct_condition_t mbedtls_mpi_core_uint_le_mpi(mbedtls_mpi_uint min,
|
||||||
return mbedtls_ct_bool_or(msll_mask, min_le_lsl);
|
return mbedtls_ct_bool_or(msll_mask, min_le_lsl);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned mbedtls_mpi_core_lt_ct(const mbedtls_mpi_uint *A,
|
mbedtls_ct_condition_t mbedtls_mpi_core_lt_ct(const mbedtls_mpi_uint *A,
|
||||||
const mbedtls_mpi_uint *B,
|
const mbedtls_mpi_uint *B,
|
||||||
size_t limbs)
|
size_t limbs)
|
||||||
{
|
{
|
||||||
unsigned ret, cond, done;
|
mbedtls_ct_condition_t ret = MBEDTLS_CT_FALSE, cond = MBEDTLS_CT_FALSE, done = MBEDTLS_CT_FALSE;
|
||||||
|
|
||||||
/* The value of any of these variables is either 0 or 1 for the rest of
|
|
||||||
* their scope. */
|
|
||||||
ret = cond = done = 0;
|
|
||||||
|
|
||||||
for (size_t i = limbs; i > 0; i--) {
|
for (size_t i = limbs; i > 0; i--) {
|
||||||
/*
|
/*
|
||||||
|
@ -184,8 +180,8 @@ unsigned mbedtls_mpi_core_lt_ct(const mbedtls_mpi_uint *A,
|
||||||
* Again even if we can make a decision, we just mark the result and
|
* Again even if we can make a decision, we just mark the result and
|
||||||
* the fact that we are done and continue looping.
|
* the fact that we are done and continue looping.
|
||||||
*/
|
*/
|
||||||
cond = mbedtls_ct_mpi_uint_lt(B[i - 1], A[i - 1]);
|
cond = mbedtls_ct_bool_lt(B[i - 1], A[i - 1]);
|
||||||
done |= cond;
|
done = mbedtls_ct_bool_or(done, cond);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If A[i - 1] < B[i - 1] then A < B is true.
|
* If A[i - 1] < B[i - 1] then A < B is true.
|
||||||
|
@ -193,9 +189,9 @@ unsigned mbedtls_mpi_core_lt_ct(const mbedtls_mpi_uint *A,
|
||||||
* Again even if we can make a decision, we just mark the result and
|
* Again even if we can make a decision, we just mark the result and
|
||||||
* the fact that we are done and continue looping.
|
* the fact that we are done and continue looping.
|
||||||
*/
|
*/
|
||||||
cond = mbedtls_ct_mpi_uint_lt(A[i - 1], B[i - 1]);
|
cond = mbedtls_ct_bool_lt(A[i - 1], B[i - 1]);
|
||||||
ret |= cond & (1 - done);
|
ret = mbedtls_ct_bool_or(ret, mbedtls_ct_bool_and(cond, mbedtls_ct_bool_not(done)));
|
||||||
done |= cond;
|
done = mbedtls_ct_bool_or(done, cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -161,13 +161,13 @@ mbedtls_ct_condition_t mbedtls_mpi_core_uint_le_mpi(mbedtls_mpi_uint min,
|
||||||
* \param limbs The number of limbs in \p A and \p B.
|
* \param limbs The number of limbs in \p A and \p B.
|
||||||
* This must not be 0.
|
* This must not be 0.
|
||||||
*
|
*
|
||||||
* \return The result of the comparison:
|
* \return MBEDTLS_CT_TRUE if \p A is less than \p B.
|
||||||
* \c 1 if \p A is less than \p B.
|
* MBEDTLS_CT_FALSE if \p A is greater than or equal to \p B.
|
||||||
* \c 0 if \p A is greater than or equal to \p B.
|
|
||||||
*/
|
*/
|
||||||
unsigned mbedtls_mpi_core_lt_ct(const mbedtls_mpi_uint *A,
|
mbedtls_ct_condition_t mbedtls_mpi_core_lt_ct(const mbedtls_mpi_uint *A,
|
||||||
const mbedtls_mpi_uint *B,
|
const mbedtls_mpi_uint *B,
|
||||||
size_t limbs);
|
size_t limbs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Perform a safe conditional copy of an MPI which doesn't reveal
|
* \brief Perform a safe conditional copy of an MPI which doesn't reveal
|
||||||
* whether assignment was done or not.
|
* whether assignment was done or not.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue