mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2025-12-24 00:06:32 +01:00
Make all hash checking in programs constant-time
This commit is contained in:
parent
424cd6943c
commit
291f9af935
5 changed files with 35 additions and 5 deletions
|
|
@ -75,6 +75,7 @@ int main( int argc, char *argv[] )
|
|||
unsigned char key[512];
|
||||
unsigned char digest[32];
|
||||
unsigned char buffer[1024];
|
||||
unsigned char diff;
|
||||
|
||||
aes_context aes_ctx;
|
||||
sha256_context sha_ctx;
|
||||
|
|
@ -397,7 +398,12 @@ int main( int argc, char *argv[] )
|
|||
goto exit;
|
||||
}
|
||||
|
||||
if( memcmp( digest, buffer, 32 ) != 0 )
|
||||
/* Use constant-time buffer comparison */
|
||||
diff = 0;
|
||||
for( i = 0; i < 32; i++ )
|
||||
diff |= digest[i] ^ buffer[i];
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
fprintf( stderr, "HMAC check failed: wrong key, "
|
||||
"or file corrupted.\n" );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue