Create mbedtls_cf_size_if function

Add a constant-time function with size_t parameter for choosing
between two integer values, like the ?: ternary operator.

Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
gabor-mezei-arm 2021-09-27 15:47:00 +02:00
parent c29a3da599
commit 65cefdbfcb
No known key found for this signature in database
GPG key ID: 106F5A41ECC305BD
2 changed files with 8 additions and 0 deletions

View file

@ -295,6 +295,12 @@ unsigned mbedtls_cf_uint_if( unsigned cond, unsigned if1, unsigned if0 )
return( ( mask & if1 ) | (~mask & if0 ) );
}
size_t mbedtls_cf_size_if( unsigned cond, size_t if1, size_t if0 )
{
size_t mask = mbedtls_cf_size_mask( cond );
return( ( mask & if1 ) | (~mask & if0 ) );
}
/**
* Select between two sign values in constant-time.
*

View file

@ -59,6 +59,8 @@ unsigned mbedtls_cf_mpi_uint_lt( const mbedtls_mpi_uint x,
unsigned mbedtls_cf_uint_if( unsigned cond, unsigned if1, unsigned if0 );
size_t mbedtls_cf_size_if( unsigned cond, size_t if1, size_t if0 );
int mbedtls_cf_cond_select_sign( int a, int b, unsigned char second );
#if defined(MBEDTLS_BIGNUM_C)