Jump to content

OpenSSL/Initialization

From Wikibooks, open books for an open world

Initialization

[edit | edit source]

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: OPENSSL_config calls ENGINE_load_builtin_engines, so there is no need to call ENGINE_load_builtin_engines if you call OPENSSL_config (indeed, doing so seems to result in a memory leak).

Threading

[edit | edit source]

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).


Clipboard

To do:
explain how to set up threading callbacks


Cleanup

[edit | edit source]

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);