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>
diff --git a/library/constant_time.c b/library/constant_time.c
index d108b13..f0b9aa3 100644
--- a/library/constant_time.c
+++ b/library/constant_time.c
@@ -744,9 +744,9 @@
/*
* 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 @@
* 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.
*/