1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-07 06:42:56 +03:00

Bignum: Apply naming conventions

Numbers:

- A, B for mbedtls_mpi_uint* operands
- a, b for mbedtls_mpi_uint operands
- X or x for result
- HAC references where applicable

Lengths:

- Reserve size or length for length/size in bytes or byte buffers.
- For length of mbedtls_mpi_uint* buffers use limbs
- Length parameters are qualified if possible (eg. input_length or
  a_limbs)

Setup functions:

- The parameters match the corresponding structure member's name
- The structure to set up is a standard lower case name even if in other
  functions different naming conventions would apply

Scope of changes/conventions:

- bignum_core
- bignum_mod
- bignum_mod_raw

Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
Janos Follath
2022-08-19 12:24:40 +01:00
parent 6b8a4ad0d8
commit b7a88eca42
8 changed files with 185 additions and 179 deletions

View File

@@ -744,9 +744,9 @@ cleanup:
/*
* Compare unsigned values in constant time
*/
unsigned mbedtls_mpi_core_lt_ct( const mbedtls_mpi_uint *X,
const mbedtls_mpi_uint *Y,
size_t len )
unsigned mbedtls_mpi_core_lt_ct( const mbedtls_mpi_uint *A,
const mbedtls_mpi_uint *B,
size_t limbs )
{
unsigned ret, cond, done;
@@ -754,31 +754,31 @@ unsigned mbedtls_mpi_core_lt_ct( const mbedtls_mpi_uint *X,
* their scope. */
ret = cond = done = 0;
for( size_t i = len; i > 0; i-- )
for( size_t i = limbs; i > 0; i-- )
{
/*
* If Y[i - 1] < X[i - 1] then X < Y is false and the result must
* If B[i - 1] < A[i - 1] then A < B is false and the result must
* remain 0.
*
* Again even if we can make a decision, we just mark the result and
* the fact that we are done and continue looping.
*/
cond = mbedtls_ct_mpi_uint_lt( Y[i - 1], X[i - 1] );
cond = mbedtls_ct_mpi_uint_lt( B[i - 1], A[i - 1] );
done |= cond;
/*
* If X[i - 1] < Y[i - 1] then X < Y is true.
* If A[i - 1] < B[i - 1] then A < B is true.
*
* Again even if we can make a decision, we just mark the result and
* the fact that we are done and continue looping.
*/
cond = mbedtls_ct_mpi_uint_lt( X[i - 1], Y[i - 1] );
cond = mbedtls_ct_mpi_uint_lt( A[i - 1], B[i - 1] );
ret |= cond & ( 1 - done );
done |= cond;
}
/*
* If all the limbs were equal, then the numbers are equal, X < Y is false
* If all the limbs were equal, then the numbers are equal, A < B is false
* and leaving the result 0 is correct.
*/