Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
Correct style and free entropy context prior to freeing the ctr drbg context,
as the latter keeps a reference to the entropy context. While it doesn't cause
any problems the way it was before because the ctr drbg context is not used any
longer after freeing the entropy, it's nonetheless cleaner this way.
  • Loading branch information
Hanno Becker committed Oct 9, 2017
1 parent 71e5713 commit 68e6f34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions programs/pkey/pk_decrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ int main( int argc, char *argv[] )
goto exit;
}

for( i=0; fscanf( f, "%02X", &c ) > 0 &&
i < (int) sizeof( buf ); i++ )
for( i = 0; fscanf( f, "%02X", &c ) > 0 &&
i < (int) sizeof( buf ); i++ )
{
buf[i] = (unsigned char) c;
}
Expand Down Expand Up @@ -148,9 +148,10 @@ int main( int argc, char *argv[] )
ret = 0;

exit:

mbedtls_pk_free( &pk );
mbedtls_ctr_drbg_free( &ctr_drbg );
mbedtls_entropy_free( &entropy );
mbedtls_ctr_drbg_free( &ctr_drbg );

#if defined(MBEDTLS_ERROR_C)
if( ret != 0 )
Expand Down
3 changes: 2 additions & 1 deletion programs/pkey/pk_encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ int main( int argc, char *argv[] )
mbedtls_printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );

exit:

mbedtls_pk_free( &pk );
mbedtls_ctr_drbg_free( &ctr_drbg );
mbedtls_entropy_free( &entropy );
mbedtls_ctr_drbg_free( &ctr_drbg );

#if defined(MBEDTLS_ERROR_C)
if( ret != 0 )
Expand Down

0 comments on commit 68e6f34

Please sign in to comment.