OpenSSL/Initialization

Initialization
To initialize both libcrypto and libssl:

[first, set up threading callbacks if your program is multithreaded] SSL_load_error_strings ; SSL_library_init ; OpenSSL_add_all_algorithms ; OPENSSL_config (NULL);

Or to initialize libcrypto only, without libssl:

[first, set up threading callbacks if your program is multithreaded] ERR_load_crypto_strings ; OpenSSL_add_all_algorithms ; OPENSSL_config (NULL);

Note:  calls , so there is no need to call   if you call   (indeed, doing so seems to result in a memory leak).

Threading
OpenSSL does not have any knowledge of pthreads or Windows threads. Therefore, if your program is multithreaded, you must write callbacks which glue OpenSSL to pthreads or Windows threads (or both, if your program is cross-platform).

Cleanup
Not really necessary, since resources will be freed on process termination, but you could do:

ERR_free_strings ; RAND_cleanup ; EVP_cleanup ; // this seems to cause double-frees for me: ENGINE_cleanup ; CONF_modules_free ; ERR_remove_state (0);