mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 04:35:46 +01:00
Reliably zeroize sensitive data in Crypt-and-Hash sample application
The AES sample application programs/aes/crypt_and_hash could miss zeroizing the stack-based key buffer in case of an error during operation. This commit fixes this and also clears all command line arguments (one of which might be the key) before exit.
This commit is contained in:
parent
e513cf7f26
commit
8188d392af
@ -220,8 +220,6 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
}
|
||||
|
||||
memset( argv[6], 0, strlen( argv[6] ) );
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
filesize = fseek( fin, 0L, SEEK_END );
|
||||
#else
|
||||
@ -299,8 +297,6 @@ int main( int argc, char *argv[] )
|
||||
|
||||
}
|
||||
|
||||
memset( key, 0, sizeof( key ) );
|
||||
|
||||
if( cipher_setkey( &cipher_ctx, digest, cipher_info->key_length,
|
||||
POLARSSL_ENCRYPT ) != 0 )
|
||||
{
|
||||
@ -434,8 +430,6 @@ int main( int argc, char *argv[] )
|
||||
md_finish( &md_ctx, digest );
|
||||
}
|
||||
|
||||
memset( key, 0, sizeof( key ) );
|
||||
|
||||
if( cipher_setkey( &cipher_ctx, digest, cipher_info->key_length,
|
||||
POLARSSL_DECRYPT ) != 0 )
|
||||
{
|
||||
@ -539,7 +533,16 @@ exit:
|
||||
if( fout )
|
||||
fclose( fout );
|
||||
|
||||
/* Zeroize all command line arguments to also cover
|
||||
the case when the user has missed or reordered some,
|
||||
in which case the key might not be in argv[6]. */
|
||||
for( i = 0; i < argc; i++ )
|
||||
memset( argv[i], 0, strlen( argv[i] ) );
|
||||
|
||||
memset( IV, 0, sizeof( IV ) );
|
||||
memset( key, 0, sizeof( key ) );
|
||||
memset( buffer, 0, sizeof( buffer ) );
|
||||
memset( output, 0, sizeof( output ) );
|
||||
memset( digest, 0, sizeof( digest ) );
|
||||
|
||||
cipher_free( &cipher_ctx );
|
||||
|
Loading…
Reference in New Issue
Block a user