mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 11:35:44 +01:00
Make get_zeros_padding() constant-time
This commit is contained in:
parent
6c32990114
commit
e68bf171eb
@ -533,14 +533,19 @@ static void add_zeros_padding( unsigned char *output,
|
||||
static int get_zeros_padding( unsigned char *input, size_t input_len,
|
||||
size_t *data_len )
|
||||
{
|
||||
unsigned char *p = input + input_len - 1;
|
||||
size_t i;
|
||||
unsigned char done = 0, prev_done;
|
||||
|
||||
if( NULL == input || NULL == data_len )
|
||||
return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
|
||||
|
||||
while( *p == 0x00 && p > input )
|
||||
--p;
|
||||
|
||||
*data_len = *p == 0x00 ? 0 : p - input + 1;
|
||||
*data_len = 0;
|
||||
for( i = input_len; i > 0; i-- )
|
||||
{
|
||||
prev_done = done;
|
||||
done |= ( input[i-1] != 0 );
|
||||
*data_len |= i * ( done != prev_done );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user