Bignum: Declare loop variable in loop head
In the new bignum files (bignum_core.c, bignum_mod_raw.c and bignum_mod.c) the loop variables are declared in the loop head wherever this change is beneficial. There are loops where the loop variable is used after the end of the loop (this might not be good practice, but that is out of scope for this commit) and others where there are several loop variables and declaring them there would hurt readability. Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
parent
620c58ced9
commit
cc93908b88
1 changed files with 4 additions and 6 deletions
|
@ -216,7 +216,6 @@ int mbedtls_mpi_core_write_le( const mbedtls_mpi_uint *X,
|
|||
{
|
||||
size_t stored_bytes = nx * ciL;
|
||||
size_t bytes_to_copy;
|
||||
size_t i;
|
||||
|
||||
if( stored_bytes < buflen )
|
||||
{
|
||||
|
@ -228,14 +227,14 @@ int mbedtls_mpi_core_write_le( const mbedtls_mpi_uint *X,
|
|||
|
||||
/* The output buffer is smaller than the allocated size of X.
|
||||
* However X may fit if its leading bytes are zero. */
|
||||
for( i = bytes_to_copy; i < stored_bytes; i++ )
|
||||
for( size_t i = bytes_to_copy; i < stored_bytes; i++ )
|
||||
{
|
||||
if( GET_BYTE( X, i ) != 0 )
|
||||
return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL );
|
||||
}
|
||||
}
|
||||
|
||||
for( i = 0; i < bytes_to_copy; i++ )
|
||||
for( size_t i = 0; i < bytes_to_copy; i++ )
|
||||
buf[i] = GET_BYTE( X, i );
|
||||
|
||||
if( stored_bytes < buflen )
|
||||
|
@ -255,7 +254,6 @@ int mbedtls_mpi_core_write_be( const mbedtls_mpi_uint *X,
|
|||
size_t stored_bytes;
|
||||
size_t bytes_to_copy;
|
||||
unsigned char *p;
|
||||
size_t i;
|
||||
|
||||
stored_bytes = nx * ciL;
|
||||
|
||||
|
@ -276,14 +274,14 @@ int mbedtls_mpi_core_write_be( const mbedtls_mpi_uint *X,
|
|||
* However X may fit if its leading bytes are zero. */
|
||||
bytes_to_copy = buflen;
|
||||
p = buf;
|
||||
for( i = bytes_to_copy; i < stored_bytes; i++ )
|
||||
for( size_t i = bytes_to_copy; i < stored_bytes; i++ )
|
||||
{
|
||||
if( GET_BYTE( X, i ) != 0 )
|
||||
return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL );
|
||||
}
|
||||
}
|
||||
|
||||
for( i = 0; i < bytes_to_copy; i++ )
|
||||
for( size_t i = 0; i < bytes_to_copy; i++ )
|
||||
p[bytes_to_copy - i - 1] = GET_BYTE( X, i );
|
||||
|
||||
return( 0 );
|
||||
|
|
Loading…
Reference in a new issue