/** * PHP doesn't support user land threads but we still have to initialize * the library. * * Use following link for additional details: * 'https://www.openssl.org/docs/man1.0.1/crypto/threads.html' * 'https://wiki.openssl.org/index.php/Library_Initialization' */ #include #include #include #include void __attribute__((constructor)) TCLink_OpenSSLInit(void); void __attribute__((destructor)) TCLink_OpenSSLCleanup(void); /** * * Initialize the OpenSSL library. * Also sets up static callback functions required for multi-thread safety. */ void TCLink_OpenSSLInit(void) { int ret; #if OPENSSL_VERSION_NUMBER < 0x10100000L SSL_load_error_strings(); ret = SSL_library_init(); assert(ret == 1); #else ret = OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CRYPTO_STRINGS | OPENSSL_INIT_ADD_ALL_CIPHERS | OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_LOAD_CONFIG | OPENSSL_INIT_ASYNC | #ifdef OPENSSL_INIT_NO_ATEXIT OPENSSL_INIT_NO_ATEXIT | #endif #ifdef OPENSSL_INIT_ATFORK OPENSSL_INIT_ATFORK | #endif OPENSSL_INIT_LOAD_SSL_STRINGS, NULL); assert(ret == 1); #endif } /** * * De-initializes the OpenSSL library. * Performs cleanup required for global data structures. */ void TCLink_OpenSSLCleanup(void) { #if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_cleanup(); CRYPTO_cleanup_all_ex_data(); ERR_free_strings(); #else OPENSSL_cleanup(); #endif }