mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-28 00:21:48 +03:00
fix bug in get_one_and_zeros_padding()
add test case (“0000000082”) which fails with the old implementation.
This commit is contained in:
@ -516,14 +516,14 @@ static int get_one_and_zeros_padding( unsigned char *input, size_t input_len,
|
||||
if( NULL == input || NULL == data_len )
|
||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||
|
||||
bad = 0xFF;
|
||||
bad = 0x80;
|
||||
*data_len = 0;
|
||||
for( i = input_len; i > 0; i-- )
|
||||
{
|
||||
prev_done = done;
|
||||
done |= ( input[i-1] != 0 );
|
||||
done |= ( input[i - 1] != 0 );
|
||||
*data_len |= ( i - 1 ) * ( done != prev_done );
|
||||
bad &= ( input[i-1] ^ 0x80 ) | ( done == prev_done );
|
||||
bad ^= input[i - 1] * ( done != prev_done );
|
||||
}
|
||||
|
||||
return( MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) );
|
||||
|
Reference in New Issue
Block a user