From 1ffefaca1e13203ca03a439e2513c51d0f755a29 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Sat, 28 Sep 2013 15:23:03 +0200 Subject: [PATCH] Introduced entropy_free() --- include/polarssl/entropy.h | 7 +++++++ library/entropy.c | 5 +++++ programs/pkey/dh_client.c | 1 + programs/pkey/dh_genprime.c | 1 + programs/pkey/dh_server.c | 1 + programs/pkey/ecdsa.c | 1 + programs/pkey/gen_key.c | 1 + programs/pkey/pk_decrypt.c | 1 + programs/pkey/pk_encrypt.c | 1 + programs/pkey/pk_sign.c | 1 + programs/pkey/rsa_decrypt.c | 1 + programs/pkey/rsa_encrypt.c | 1 + programs/pkey/rsa_genkey.c | 1 + programs/pkey/rsa_sign_pss.c | 1 + programs/random/gen_entropy.c | 1 + programs/random/gen_random_ctr_drbg.c | 1 + programs/ssl/ssl_client1.c | 1 + programs/ssl/ssl_client2.c | 1 + programs/ssl/ssl_fork_server.c | 1 + programs/ssl/ssl_mail_client.c | 1 + programs/ssl/ssl_server.c | 1 + programs/ssl/ssl_server2.c | 1 + programs/test/o_p_test.c | 1 + programs/test/ssl_test.c | 1 + programs/x509/cert_app.c | 1 + programs/x509/cert_req.c | 1 + programs/x509/cert_write.c | 1 + tests/suites/test_suite_rsa.function | 1 + 28 files changed, 38 insertions(+) diff --git a/include/polarssl/entropy.h b/include/polarssl/entropy.h index ea27848db..e334c2247 100644 --- a/include/polarssl/entropy.h +++ b/include/polarssl/entropy.h @@ -116,6 +116,13 @@ entropy_context; */ void entropy_init( entropy_context *ctx ); +/** + * \brief Free the data in the context + * + * \param ctx Entropy context to free + */ +void entropy_free( entropy_context *ctx ); + /** * \brief Adds an entropy source to poll * diff --git a/library/entropy.c b/library/entropy.c index 2352bcff4..d43f9833c 100644 --- a/library/entropy.c +++ b/library/entropy.c @@ -64,6 +64,11 @@ void entropy_init( entropy_context *ctx ) #endif /* POLARSSL_NO_DEFAULT_ENTROPY_SOURCES */ } +void entropy_free( entropy_context *ctx ) +{ + ((void) ctx); +} + int entropy_add_source( entropy_context *ctx, f_source_ptr f_source, void *p_source, size_t threshold ) diff --git a/programs/pkey/dh_client.c b/programs/pkey/dh_client.c index 4410eb6fe..18027fa65 100644 --- a/programs/pkey/dh_client.c +++ b/programs/pkey/dh_client.c @@ -275,6 +275,7 @@ exit: net_close( server_fd ); rsa_free( &rsa ); dhm_free( &dhm ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); diff --git a/programs/pkey/dh_genprime.c b/programs/pkey/dh_genprime.c index f773f1e42..2089fb632 100644 --- a/programs/pkey/dh_genprime.c +++ b/programs/pkey/dh_genprime.c @@ -143,6 +143,7 @@ int main( int argc, char *argv[] ) exit: mpi_free( &G ); mpi_free( &P ); mpi_free( &Q ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " Press Enter to exit this program.\n" ); diff --git a/programs/pkey/dh_server.c b/programs/pkey/dh_server.c index 584ff08da..d2b6cc48d 100644 --- a/programs/pkey/dh_server.c +++ b/programs/pkey/dh_server.c @@ -276,6 +276,7 @@ exit: net_close( client_fd ); rsa_free( &rsa ); dhm_free( &dhm ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); diff --git a/programs/pkey/ecdsa.c b/programs/pkey/ecdsa.c index efe671616..add74c6d6 100644 --- a/programs/pkey/ecdsa.c +++ b/programs/pkey/ecdsa.c @@ -179,6 +179,7 @@ exit: ecdsa_free( &ctx_verify ); ecdsa_free( &ctx_sign ); + entropy_free( &entropy ); return( ret ); } diff --git a/programs/pkey/gen_key.c b/programs/pkey/gen_key.c index 3cf682b8a..19f46a400 100644 --- a/programs/pkey/gen_key.c +++ b/programs/pkey/gen_key.c @@ -269,6 +269,7 @@ exit: } pk_free( &key ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); diff --git a/programs/pkey/pk_decrypt.c b/programs/pkey/pk_decrypt.c index a6ae28108..bf3455dfc 100644 --- a/programs/pkey/pk_decrypt.c +++ b/programs/pkey/pk_decrypt.c @@ -136,6 +136,7 @@ int main( int argc, char *argv[] ) ret = 0; exit: + entropy_free( &entropy ); #if defined(POLARSSL_ERROR_C) polarssl_strerror( ret, (char *) buf, sizeof(buf) ); diff --git a/programs/pkey/pk_encrypt.c b/programs/pkey/pk_encrypt.c index aa202b00e..149e7ddfe 100644 --- a/programs/pkey/pk_encrypt.c +++ b/programs/pkey/pk_encrypt.c @@ -136,6 +136,7 @@ int main( int argc, char *argv[] ) printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" ); exit: + entropy_free( &entropy ); #if defined(POLARSSL_ERROR_C) polarssl_strerror( ret, (char *) buf, sizeof(buf) ); diff --git a/programs/pkey/pk_sign.c b/programs/pkey/pk_sign.c index 5a874b336..67ac0b414 100644 --- a/programs/pkey/pk_sign.c +++ b/programs/pkey/pk_sign.c @@ -149,6 +149,7 @@ int main( int argc, char *argv[] ) exit: pk_free( &pk ); + entropy_free( &entropy ); #if defined(POLARSSL_ERROR_C) polarssl_strerror( ret, (char *) buf, sizeof(buf) ); diff --git a/programs/pkey/rsa_decrypt.c b/programs/pkey/rsa_decrypt.c index 36ac80953..02d30c8ed 100644 --- a/programs/pkey/rsa_decrypt.c +++ b/programs/pkey/rsa_decrypt.c @@ -160,6 +160,7 @@ int main( int argc, char *argv[] ) ret = 0; exit: + entropy_free( &entropy ); #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); diff --git a/programs/pkey/rsa_encrypt.c b/programs/pkey/rsa_encrypt.c index c444c1afa..2ed27e23e 100644 --- a/programs/pkey/rsa_encrypt.c +++ b/programs/pkey/rsa_encrypt.c @@ -148,6 +148,7 @@ int main( int argc, char *argv[] ) printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" ); exit: + entropy_free( &entropy ); #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); diff --git a/programs/pkey/rsa_genkey.c b/programs/pkey/rsa_genkey.c index f92c50b6e..7711776ef 100644 --- a/programs/pkey/rsa_genkey.c +++ b/programs/pkey/rsa_genkey.c @@ -150,6 +150,7 @@ exit: fclose( fpriv ); rsa_free( &rsa ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " Press Enter to exit this program.\n" ); diff --git a/programs/pkey/rsa_sign_pss.c b/programs/pkey/rsa_sign_pss.c index 06fc2e07b..fecfcc26e 100644 --- a/programs/pkey/rsa_sign_pss.c +++ b/programs/pkey/rsa_sign_pss.c @@ -156,6 +156,7 @@ int main( int argc, char *argv[] ) exit: pk_free( &pk ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); diff --git a/programs/random/gen_entropy.c b/programs/random/gen_entropy.c index 38c104c92..e0cbe528a 100644 --- a/programs/random/gen_entropy.c +++ b/programs/random/gen_entropy.c @@ -81,6 +81,7 @@ int main( int argc, char *argv[] ) cleanup: fclose( f ); + entropy_free( &entropy ); return( ret ); } diff --git a/programs/random/gen_random_ctr_drbg.c b/programs/random/gen_random_ctr_drbg.c index fcdc2eec1..32b8521d3 100644 --- a/programs/random/gen_random_ctr_drbg.c +++ b/programs/random/gen_random_ctr_drbg.c @@ -111,6 +111,7 @@ cleanup: printf("\n"); fclose( f ); + entropy_free( &entropy ); return( ret ); } diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c index 2c6e7c868..efb210e46 100644 --- a/programs/ssl/ssl_client1.c +++ b/programs/ssl/ssl_client1.c @@ -277,6 +277,7 @@ exit: x509_crt_free( &cacert ); net_close( server_fd ); ssl_free( &ssl ); + entropy_free( &entropy ); memset( &ssl, 0, sizeof( ssl ) ); diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index f518d39f7..2093d1a6a 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -913,6 +913,7 @@ exit: #endif ssl_session_free( &saved_session ); ssl_free( &ssl ); + entropy_free( &entropy ); memset( &ssl, 0, sizeof( ssl ) ); diff --git a/programs/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c index 3d4c7d3b3..02de364ba 100644 --- a/programs/ssl/ssl_fork_server.c +++ b/programs/ssl/ssl_fork_server.c @@ -361,6 +361,7 @@ exit: x509_crt_free( &srvcert ); pk_free( &pkey ); ssl_free( &ssl ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " Press Enter to exit this program.\n" ); diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c index edee85db7..70ba6221e 100644 --- a/programs/ssl/ssl_mail_client.c +++ b/programs/ssl/ssl_mail_client.c @@ -791,6 +791,7 @@ exit: x509_crt_free( &cacert ); pk_free( &pkey ); ssl_free( &ssl ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c index 2a528cb07..b4883aae7 100644 --- a/programs/ssl/ssl_server.c +++ b/programs/ssl/ssl_server.c @@ -367,6 +367,7 @@ exit: #if defined(POLARSSL_SSL_CACHE_C) ssl_cache_free( &cache ); #endif + entropy_free( &entropy ); #if defined(_WIN32) printf( " Press Enter to exit this program.\n" ); diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index 2d81e755e..a6ff57fea 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -963,6 +963,7 @@ exit: #endif ssl_free( &ssl ); + entropy_free( &entropy ); #if defined(POLARSSL_SSL_CACHE_C) ssl_cache_free( &cache ); diff --git a/programs/test/o_p_test.c b/programs/test/o_p_test.c index bf54752c9..0665098f6 100644 --- a/programs/test/o_p_test.c +++ b/programs/test/o_p_test.c @@ -252,6 +252,7 @@ int main( int argc, char *argv[] ) printf( "String value (PolarSSL Private Encrypt, OpenSSL Public Decrypt): '%s'\n", o_priv_decrypted ); exit: + entropy_free( &entropy ); #ifdef WIN32 printf( " + Press Enter to exit this program.\n" ); diff --git a/programs/test/ssl_test.c b/programs/test/ssl_test.c index 20907d8db..debdb073e 100644 --- a/programs/test/ssl_test.c +++ b/programs/test/ssl_test.c @@ -401,6 +401,7 @@ exit: x509_crt_free( &srvcert ); pk_free( &pkey ); ssl_free( &ssl ); + entropy_free( &entropy ); net_close( client_fd ); return( ret ); diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c index dedac9420..c43e662af 100644 --- a/programs/x509/cert_app.c +++ b/programs/x509/cert_app.c @@ -449,6 +449,7 @@ exit: x509_crt_free( &cacert ); x509_crt_free( &clicert ); pk_free( &pkey ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); diff --git a/programs/x509/cert_req.c b/programs/x509/cert_req.c index c6d7dff72..dc45f9496 100644 --- a/programs/x509/cert_req.c +++ b/programs/x509/cert_req.c @@ -329,6 +329,7 @@ exit: x509write_csr_free( &req ); pk_free( &key ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); diff --git a/programs/x509/cert_write.c b/programs/x509/cert_write.c index ba00dc3de..94dfa1ddc 100644 --- a/programs/x509/cert_write.c +++ b/programs/x509/cert_write.c @@ -650,6 +650,7 @@ exit: pk_free( &loaded_subject_key ); pk_free( &loaded_issuer_key ); mpi_free( &serial ); + entropy_free( &entropy ); #if defined(_WIN32) printf( " + Press Enter to exit this program.\n" ); diff --git a/tests/suites/test_suite_rsa.function b/tests/suites/test_suite_rsa.function index dfd2c96af..9bc8a24bf 100644 --- a/tests/suites/test_suite_rsa.function +++ b/tests/suites/test_suite_rsa.function @@ -528,6 +528,7 @@ void rsa_gen_key( int nrbits, int exponent, int result) } rsa_free( &ctx ); + entropy_free( &entropy ); } /* END_CASE */