# 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:
        if (
            libcrypto.OPENSSL_init_crypto(
                OPENSSL_INIT_NO_LOAD_CONFIG
                | OPENSSL_INIT_ADD_ALL_CIPHERS
                | OPENSSL_INIT_ADD_ALL_DIGESTS,
                None,
            )
            != 1
        ):
            raise OSError(
                "Failed to initialize OpenSSL library (OPENSSL_init_crypto failed)"
            )
    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)
Python 2.7.14 (default, Oct 12 2017, 15:50:02) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import salt.utils.rsax931
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/alex/programming/salt-python/bugreport/lib/python2.7/site-packages/salt/utils/rsax931.py", line 86, in <module>
libcrypto = _init_libcrypto()
File "/home/alex/programming/salt-python/bugreport/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(
            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