mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-24 19:18:08 +00:00
Make get_zeros_padding() constant-time
This commit is contained in:
parent
6c32990114
commit
e68bf171eb
1 changed files with 10 additions and 5 deletions
|
@ -533,14 +533,19 @@ static void add_zeros_padding( unsigned char *output,
|
||||||
static int get_zeros_padding( unsigned char *input, size_t input_len,
|
static int get_zeros_padding( unsigned char *input, size_t input_len,
|
||||||
size_t *data_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 )
|
if( NULL == input || NULL == data_len )
|
||||||
return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
|
return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
|
||||||
|
|
||||||
while( *p == 0x00 && p > input )
|
*data_len = 0;
|
||||||
--p;
|
for( i = input_len; i > 0; i-- )
|
||||||
|
{
|
||||||
*data_len = *p == 0x00 ? 0 : p - input + 1;
|
prev_done = done;
|
||||||
|
done |= ( input[i-1] != 0 );
|
||||||
|
*data_len |= i * ( done != prev_done );
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue