mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 08:55:40 +01:00
Add flow monitor protection to mbedtls_platform_memcmp()
Signed-off-by: Piotr Nowicki <piotr.nowicki@arm.com>
This commit is contained in:
parent
2d21e3e47b
commit
4aaa34c03f
@ -125,22 +125,25 @@ int mbedtls_platform_memcmp( const void *buf1, const void *buf2, size_t num )
|
|||||||
volatile unsigned char diff = 0;
|
volatile unsigned char diff = 0;
|
||||||
|
|
||||||
size_t i = num;
|
size_t i = num;
|
||||||
|
size_t flow_counter = 0;
|
||||||
size_t start_offset = (size_t) mbedtls_platform_random_in_range( num );
|
size_t start_offset = (size_t) mbedtls_platform_random_in_range( num );
|
||||||
|
|
||||||
for( i = start_offset; i < num; i++ )
|
for( i = start_offset; i < num; i++ )
|
||||||
{
|
{
|
||||||
unsigned char x = A[i], y = B[i];
|
unsigned char x = A[i], y = B[i];
|
||||||
|
flow_counter++;
|
||||||
diff |= x ^ y;
|
diff |= x ^ y;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i = 0; i < start_offset; i++ )
|
for( i = 0; i < start_offset; i++ )
|
||||||
{
|
{
|
||||||
unsigned char x = A[i], y = B[i];
|
unsigned char x = A[i], y = B[i];
|
||||||
|
flow_counter++;
|
||||||
diff |= x ^ y;
|
diff |= x ^ y;
|
||||||
}
|
}
|
||||||
|
|
||||||
return( diff );
|
/* Return 0 only when diff is 0 and flow_counter is equal to num */
|
||||||
|
return( (int) diff | (int) ( flow_counter ^ num ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t mbedtls_platform_random_in_range( size_t num )
|
uint32_t mbedtls_platform_random_in_range( size_t num )
|
||||||
|
Loading…
Reference in New Issue
Block a user