void entropy_free( entropy_context *ctx ) { ((void) ctx); #if defined(POLARSSL_THREADING_C) polarssl_mutex_free( &ctx->mutex ); #endif }
void entropy_free( entropy_context *ctx ) { #if defined(POLARSSL_HAVEGE_C) havege_free( &ctx->havege_data ); #endif polarssl_zeroize( ctx, sizeof( entropy_context ) ); #if defined(POLARSSL_THREADING_C) polarssl_mutex_free( &ctx->mutex ); #endif }
/* * Free the components of an RSA key */ void shrsa_free( shrsa_context *ctx ) { shmpi_free( &ctx->Vi ); shmpi_free( &ctx->Vf ); shmpi_free( &ctx->RQ ); shmpi_free( &ctx->RP ); shmpi_free( &ctx->RN ); shmpi_free( &ctx->QP ); shmpi_free( &ctx->DQ ); shmpi_free( &ctx->DP ); shmpi_free( &ctx->Q ); shmpi_free( &ctx->P ); shmpi_free( &ctx->D ); shmpi_free( &ctx->E ); shmpi_free( &ctx->N ); #if defined(RSA_THREADING_C) polarssl_mutex_free( &ctx->mutex ); #endif }
/* * Free the components of an RSA key */ void rsa_free( rsa_context *ctx ) { #if !defined(POLARSSL_RSA_NO_CRT) mpi_free( &ctx->Vi ); mpi_free( &ctx->Vf ); #endif mpi_free( &ctx->RQ ); mpi_free( &ctx->RP ); mpi_free( &ctx->RN ); mpi_free( &ctx->QP ); mpi_free( &ctx->DQ ); mpi_free( &ctx->DP ); mpi_free( &ctx->Q ); mpi_free( &ctx->P ); mpi_free( &ctx->D ); mpi_free( &ctx->E ); mpi_free( &ctx->N ); #if defined(POLARSSL_THREADING_C) polarssl_mutex_free( &ctx->mutex ); #endif }
void ssl_cache_free( ssl_cache_context *cache ) { ssl_cache_entry *cur, *prv; cur = cache->chain; while( cur != NULL ) { prv = cur; cur = cur->next; ssl_session_free( &prv->session ); #if defined(POLARSSL_X509_CRT_PARSE_C) polarssl_free( prv->peer_cert.p ); #endif /* POLARSSL_X509_CRT_PARSE_C */ polarssl_free( prv ); } #if defined(POLARSSL_THREADING_C) polarssl_mutex_free( &cache->mutex ); #endif }
int main( int argc, char *argv[] ) { int ret; int listen_fd; int client_fd = -1; entropy_context entropy; x509_crt srvcert; pk_context pkey; #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) unsigned char alloc_buf[100000]; #endif #if defined(POLARSSL_SSL_CACHE_C) ssl_cache_context cache; #endif ((void) argc); ((void) argv); #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) ); #endif #if defined(POLARSSL_SSL_CACHE_C) ssl_cache_init( &cache ); base_info.cache = &cache; #endif memset( threads, 0, sizeof(threads) ); polarssl_mutex_init( &debug_mutex ); /* * We use only a single entropy source that is used in all the threads. */ entropy_init( &entropy ); base_info.entropy = &entropy; /* * 1. Load the certificates and private RSA key */ polarssl_printf( "\n . Loading the server cert. and key..." ); fflush( stdout ); x509_crt_init( &srvcert ); /* * This demonstration program uses embedded test certificates. * Instead, you may want to use x509_crt_parse_file() to read the * server and CA certificates, as well as pk_parse_keyfile(). */ ret = x509_crt_parse( &srvcert, (const unsigned char *) test_srv_crt, strlen( test_srv_crt ) ); if( ret != 0 ) { polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret ); goto exit; } ret = x509_crt_parse( &srvcert, (const unsigned char *) test_ca_list, strlen( test_ca_list ) ); if( ret != 0 ) { polarssl_printf( " failed\n ! x509_crt_parse returned %d\n\n", ret ); goto exit; } pk_init( &pkey ); ret = pk_parse_key( &pkey, (const unsigned char *) test_srv_key, strlen( test_srv_key ), NULL, 0 ); if( ret != 0 ) { polarssl_printf( " failed\n ! pk_parse_key returned %d\n\n", ret ); goto exit; } base_info.ca_chain = srvcert.next; base_info.server_cert = &srvcert; base_info.server_key = &pkey; polarssl_printf( " ok\n" ); /* * 2. Setup the listening TCP socket */ polarssl_printf( " . Bind on https://localhost:4433/ ..." ); fflush( stdout ); if( ( ret = net_bind( &listen_fd, NULL, 4433 ) ) != 0 ) { polarssl_printf( " failed\n ! net_bind returned %d\n\n", ret ); goto exit; } polarssl_printf( " ok\n" ); reset: #ifdef POLARSSL_ERROR_C if( ret != 0 ) { char error_buf[100]; polarssl_strerror( ret, error_buf, 100 ); polarssl_printf( " [ main ] Last error was: -0x%04x - %s\n", -ret, error_buf ); } #endif /* * 3. Wait until a client connects */ client_fd = -1; polarssl_printf( " [ main ] Waiting for a remote connection\n" ); if( ( ret = net_accept( listen_fd, &client_fd, NULL ) ) != 0 ) { polarssl_printf( " [ main ] failed: net_accept returned -0x%04x\n", ret ); goto exit; } polarssl_printf( " [ main ] ok\n" ); polarssl_printf( " [ main ] Creating a new thread\n" ); if( ( ret = thread_create( client_fd ) ) != 0 ) { polarssl_printf( " [ main ] failed: thread_create returned %d\n", ret ); net_close( client_fd ); goto reset; } ret = 0; goto reset; exit: x509_crt_free( &srvcert ); pk_free( &pkey ); #if defined(POLARSSL_SSL_CACHE_C) ssl_cache_free( &cache ); #endif entropy_free( &entropy ); polarssl_mutex_free( &debug_mutex ); #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) memory_buffer_alloc_free(); #endif #if defined(_WIN32) polarssl_printf( " Press Enter to exit this program.\n" ); fflush( stdout ); getchar(); #endif return( ret ); }