跳轉到內容

OpenSSL/初始化

來自華夏公益教科書,開放的書籍,開放的世界

初始化

[編輯 | 編輯原始碼]

要初始化 libcrypto 和 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);

或者僅初始化 libcrypto,不初始化 libssl

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

注意:OPENSSL_config 會呼叫 ENGINE_load_builtin_engines,因此如果您呼叫 OPENSSL_config,則不需要呼叫 ENGINE_load_builtin_engines(事實上,這樣做似乎會導致記憶體洩漏)。

執行緒

[編輯 | 編輯原始碼]

OpenSSL 無法識別 pthreads 或 Windows 執行緒。因此,如果您的程式是多執行緒的,則必須編寫回調,將 OpenSSL 連線到 pthreads 或 Windows 執行緒(或者兩者,如果您的程式是跨平臺的)。


Clipboard

要做到
解釋如何設定執行緒回撥


不是必需的,因為資源將在程序終止時釋放,但您可以執行以下操作

ERR_free_strings ();
RAND_cleanup ();
EVP_cleanup ();
// this seems to cause double-frees for me: ENGINE_cleanup ();
CONF_modules_free ();
ERR_remove_state (0);
華夏公益教科書