Merge pull request #5299 from paul-elliott-arm/crypt_and_hash_prog_2.x

Backport 2.x: Add checks for return values to md functions in crypt and hash
This commit is contained in:
Gilles Peskine 2021-12-09 23:32:52 +01:00 committed by GitHub
commit 4a5396ec25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -281,10 +281,27 @@ int main( int argc, char *argv[] )
p = argv[2]; p = argv[2];
mbedtls_md_starts( &md_ctx ); if( mbedtls_md_starts( &md_ctx ) != 0 )
mbedtls_md_update( &md_ctx, buffer, 8 ); {
mbedtls_md_update( &md_ctx, (unsigned char *) p, strlen( p ) ); mbedtls_fprintf( stderr, "mbedtls_md_starts() returned error\n" );
mbedtls_md_finish( &md_ctx, digest ); goto exit;
}
if( mbedtls_md_update( &md_ctx, buffer, 8 ) != 0 )
{
mbedtls_fprintf( stderr, "mbedtls_md_update() returned error\n" );
goto exit;
}
if( mbedtls_md_update( &md_ctx, ( unsigned char * ) p, strlen( p ) )
!= 0 )
{
mbedtls_fprintf( stderr, "mbedtls_md_update() returned error\n" );
goto exit;
}
if( mbedtls_md_finish( &md_ctx, digest ) != 0 )
{
mbedtls_fprintf( stderr, "mbedtls_md_finish() returned error\n" );
goto exit;
}
memcpy( IV, digest, 16 ); memcpy( IV, digest, 16 );
@ -306,10 +323,30 @@ int main( int argc, char *argv[] )
for( i = 0; i < 8192; i++ ) for( i = 0; i < 8192; i++ )
{ {
mbedtls_md_starts( &md_ctx ); if( mbedtls_md_starts( &md_ctx ) != 0 )
mbedtls_md_update( &md_ctx, digest, 32 ); {
mbedtls_md_update( &md_ctx, key, keylen ); mbedtls_fprintf( stderr,
mbedtls_md_finish( &md_ctx, digest ); "mbedtls_md_starts() returned error\n" );
goto exit;
}
if( mbedtls_md_update( &md_ctx, digest, 32 ) != 0 )
{
mbedtls_fprintf( stderr,
"mbedtls_md_update() returned error\n" );
goto exit;
}
if( mbedtls_md_update( &md_ctx, key, keylen ) != 0 )
{
mbedtls_fprintf( stderr,
"mbedtls_md_update() returned error\n" );
goto exit;
}
if( mbedtls_md_finish( &md_ctx, digest ) != 0 )
{
mbedtls_fprintf( stderr,
"mbedtls_md_finish() returned error\n" );
goto exit;
}
} }