mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-24 20:48:19 +00:00
Make GCM tag check "constant-time"
This commit is contained in:
parent
07f8fa5a69
commit
20d6a17af9
1 changed files with 11 additions and 4 deletions
|
@ -357,15 +357,22 @@ int gcm_auth_decrypt( gcm_context *ctx,
|
|||
unsigned char *output )
|
||||
{
|
||||
unsigned char check_tag[16];
|
||||
size_t i;
|
||||
int diff;
|
||||
|
||||
gcm_crypt_and_tag( ctx, GCM_DECRYPT, length, iv, iv_len, add, add_len, input, output, tag_len, check_tag );
|
||||
|
||||
if( memcmp( check_tag, tag, tag_len ) == 0 )
|
||||
return( 0 );
|
||||
/* Check tag in "constant-time" */
|
||||
for( diff = 0, i = 0; i < tag_len; i++ )
|
||||
diff |= tag[i] ^ check_tag[i];
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
memset( output, 0, length );
|
||||
|
||||
return( POLARSSL_ERR_GCM_AUTH_FAILED );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_SELF_TEST)
|
||||
|
|
Loading…
Reference in a new issue