mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-29 22:14:15 +01:00
Check HMAC in constant-time in crypt_and_hash
This commit is contained in:
parent
0d7702c3ee
commit
424cd6943c
@ -76,6 +76,7 @@ int main( int argc, char *argv[] )
|
||||
unsigned char digest[POLARSSL_MD_MAX_SIZE];
|
||||
unsigned char buffer[1024];
|
||||
unsigned char output[1024];
|
||||
unsigned char diff;
|
||||
|
||||
const cipher_info_t *cipher_info;
|
||||
const md_info_t *md_info;
|
||||
@ -476,7 +477,12 @@ int main( int argc, char *argv[] )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( memcmp( digest, buffer, md_get_size( md_info ) ) != 0 )
|
||||
/* Use constant-time buffer comparison */
|
||||
diff = 0;
|
||||
for( i = 0; i < md_get_size( md_info ); i++ )
|
||||
diff |= digest[i] ^ buffer[i];
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
fprintf( stderr, "HMAC check failed: wrong key, "
|
||||
"or file corrupted.\n" );
|
||||
|
Loading…
Reference in New Issue
Block a user