# Buggy code
def _init_libcrypto():
    """
    Set up libcrypto argtypes and initialize the library
    """
    libcrypto = _load_libcrypto()

    libcrypto.RSA_new.argtypes = ()
    libcrypto.RSA_new.restype = c_void_p
    libcrypto.RSA_free.argtypes = (c_void_p,)
    libcrypto.RSA_size.argtype = c_void_p
    libcrypto.BIO_new_mem_buf.argtypes = (c_char_p, c_int)
    libcrypto.BIO_new_mem_buf.restype = c_void_p
    libcrypto.BIO_free.argtypes = (c_void_p,)
    libcrypto.PEM_read_bio_RSAPrivateKey.argtypes = (
        c_void_p,
        c_void_p,
        c_void_p,
        c_void_p,
    )
    libcrypto.PEM_read_bio_RSAPrivateKey.restype = c_void_p
    libcrypto.PEM_read_bio_RSA_PUBKEY.argtypes = (
        c_void_p,
        c_void_p,
        c_void_p,
        c_void_p,
    )
    libcrypto.PEM_read_bio_RSA_PUBKEY.restype = c_void_p
    libcrypto.RSA_private_encrypt.argtypes = (
        c_int,
        c_char_p,
        c_char_p,
        c_void_p,
        c_int,
    )
    libcrypto.RSA_public_decrypt.argtypes = (c_int, c_char_p, c_char_p, c_void_p, c_int)

    try:
        libcrypto.OPENSSL_init_crypto(
            OPENSSL_INIT_NO_LOAD_CONFIG
            | OPENSSL_INIT_ADD_ALL_CIPHERS
            | OPENSSL_INIT_ADD_ALL_DIGESTS,
            None,
        )
    except AttributeError:
        # Support for OpenSSL < 1.1 (OPENSSL_API_COMPAT < 0x10100000L)
        libcrypto.OPENSSL_no_config()
        libcrypto.OPENSSL_add_all_algorithms_noconf()

    return libcrypto


# Traceback (OSError)
Traceback (most recent call last):
File "/usr/bin/salt", line 10, in <module>
salt_main()
File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 480, in salt_main
import salt.cli.salt
File "/usr/lib/python2.7/site-packages/salt/cli/salt.py", line 10, in <module>
import salt.utils.job
File "/usr/lib/python2.7/site-packages/salt/utils/job.py", line 11, in <module>
import salt.minion
File "/usr/lib/python2.7/site-packages/salt/minion.py", line 75, in <module>
import salt.client
File "/usr/lib/python2.7/site-packages/salt/client/__init__.py", line 30, in <module>
import salt.config
File "/usr/lib/python2.7/site-packages/salt/config/__init__.py", line 98, in <module>
_DFLT_IPC_WBUFFER = _gather_buffer_space() * .5
File "/usr/lib/python2.7/site-packages/salt/config/__init__.py", line 88, in _gather_buffer_space
import salt.grains.core
File "/usr/lib/python2.7/site-packages/salt/grains/core.py", line 44, in <module>
import salt.utils.dns
File "/usr/lib/python2.7/site-packages/salt/utils/dns.py", line 32, in <module>
import salt.modules.cmdmod
File "/usr/lib/python2.7/site-packages/salt/modules/cmdmod.py", line 34, in <module>
import salt.utils.templates
File "/usr/lib/python2.7/site-packages/salt/utils/templates.py", line 32, in <module>
import salt.utils.http
File "/usr/lib/python2.7/site-packages/salt/utils/http.py", line 41, in <module>
import salt.loader
File "/usr/lib/python2.7/site-packages/salt/loader.py", line 28, in <module>
import salt.utils.event
File "/usr/lib/python2.7/site-packages/salt/utils/event.py", line 74, in <module>
import salt.payload
File "/usr/lib/python2.7/site-packages/salt/payload.py", line 17, in <module>
import salt.crypt
File "/usr/lib/python2.7/site-packages/salt/crypt.py", line 68, in <module>
import salt.utils.rsax931
File "/usr/lib/python2.7/site-packages/salt/utils/rsax931.py", line 86, in <module>
libcrypto = _init_libcrypto()
File "/usr/lib/python2.7/site-packages/salt/utils/rsax931.py", line 77, in _init_libcrypto
raise OSError("Failed to initialize OpenSSL library (OPENSSL_init_crypto failed)")
OSError: Failed to initialize OpenSSL library (OPENSSL_init_crypto failed)

# Fixed code
def _init_libcrypto():
    """
    Set up libcrypto argtypes and initialize the library
    """
    libcrypto = _load_libcrypto()

    libcrypto.RSA_new.argtypes = ()
    libcrypto.RSA_new.restype = c_void_p
    libcrypto.RSA_free.argtypes = (c_void_p,)
    libcrypto.RSA_size.argtype = c_void_p
    libcrypto.BIO_new_mem_buf.argtypes = (c_char_p, c_int)
    libcrypto.BIO_new_mem_buf.restype = c_void_p
    libcrypto.BIO_free.argtypes = (c_void_p,)
    libcrypto.PEM_read_bio_RSAPrivateKey.argtypes = (
        c_void_p,
        c_void_p,
        c_void_p,
        c_void_p,
    )
    libcrypto.PEM_read_bio_RSAPrivateKey.restype = c_void_p
    libcrypto.PEM_read_bio_RSA_PUBKEY.argtypes = (
        c_void_p,
        c_void_p,
        c_void_p,
        c_void_p,
    )
    libcrypto.PEM_read_bio_RSA_PUBKEY.restype = c_void_p
    libcrypto.RSA_private_encrypt.argtypes = (
        c_int,
        c_char_p,
        c_char_p,
        c_void_p,
        c_int,
    )
    libcrypto.RSA_public_decrypt.argtypes = (c_int, c_char_p, c_char_p, c_void_p, c_int)

    try:
        libcrypto.OPENSSL_init_crypto()
    except AttributeError:
        # Support for OpenSSL < 1.1 (OPENSSL_API_COMPAT < 0x10100000L)
        libcrypto.OPENSSL_no_config()
        libcrypto.OPENSSL_add_all_algorithms_noconf()

    return libcrypto