Esempio n. 1
0
/*
 * If this function is called with a non NULL settings value then it must be
 * called prior to any threads making calls to any OpenSSL functions,
 * i.e. passing a non-null settings value is assumed to be single-threaded.
 */
int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
{
    static int stoperrset = 0;

    if (stopped) {
        if (!stoperrset) {
            /*
             * We only ever set this once to avoid getting into an infinite
             * loop where the error system keeps trying to init and fails so
             * sets an error etc
             */
            stoperrset = 1;
            SSLerr(SSL_F_OPENSSL_INIT_SSL_LIBRARY_START, ERR_R_INIT_FAIL);
        }
        return 0;
    }

    if (!OPENSSL_init_crypto(opts | OPENSSL_INIT_ADD_ALL_CIPHERS
                             | OPENSSL_INIT_ADD_ALL_DIGESTS, settings))
        return 0;

    ossl_init_once_run(&ssl_base, ossl_init_ssl_base);

    if (opts & OPENSSL_INIT_NO_LOAD_SSL_STRINGS)
        ossl_init_once_run(&ssl_strings, ossl_init_no_load_ssl_strings);

    if (opts & OPENSSL_INIT_LOAD_SSL_STRINGS)
        ossl_init_once_run(&ssl_strings, ossl_init_load_ssl_strings);

    return 1;
}
Esempio n. 2
0
/*
 * If this function is called with a non NULL settings value then it must be
 * called prior to any threads making calls to any OpenSSL functions,
 * i.e. passing a non-null settings value is assumed to be single-threaded.
 */
int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings)
{
    static int stoperrset = 0;

    if (stopped) {
        if (!stoperrset) {
            /*
             * We only ever set this once to avoid getting into an infinite
             * loop where the error system keeps trying to init and fails so
             * sets an error etc
             */
            stoperrset = 1;
            CRYPTOerr(CRYPTO_F_OPENSSL_INIT_CRYPTO, ERR_R_INIT_FAIL);
        }
        return 0;
    }

    ossl_init_once_run(&base, ossl_init_base);

    if (opts & OPENSSL_INIT_NO_LOAD_CRYPTO_STRINGS)
        ossl_init_once_run(&load_crypto_strings,
                           ossl_init_no_load_crypto_strings);

    if (opts & OPENSSL_INIT_LOAD_CRYPTO_STRINGS)
        ossl_init_once_run(&load_crypto_strings, ossl_init_load_crypto_strings);

    if (opts & OPENSSL_INIT_NO_ADD_ALL_CIPHERS)
        ossl_init_once_run(&add_all_ciphers, ossl_init_no_add_algs);

    if (opts & OPENSSL_INIT_ADD_ALL_CIPHERS)
        ossl_init_once_run(&add_all_ciphers, ossl_init_add_all_ciphers);

    if (opts & OPENSSL_INIT_NO_ADD_ALL_DIGESTS)
        ossl_init_once_run(&add_all_digests, ossl_init_no_add_algs);

    if (opts & OPENSSL_INIT_ADD_ALL_DIGESTS)
        ossl_init_once_run(&add_all_digests, ossl_init_add_all_digests);

    if (opts & OPENSSL_INIT_NO_LOAD_CONFIG) {
        ossl_init_once_run(&config, ossl_init_no_config);
    }

    if (opts & OPENSSL_INIT_LOAD_CONFIG) {
        CRYPTO_w_lock(CRYPTO_LOCK_INIT);
        config_filename = (settings == NULL) ? NULL : settings->config_name;
        ossl_init_once_run(&config, ossl_init_config);
        CRYPTO_w_unlock(CRYPTO_LOCK_INIT);
    }

    if (opts & OPENSSL_INIT_ASYNC) {
        ossl_init_once_run(&async, ossl_init_async);
    }

#ifndef OPENSSL_NO_ENGINE
    if (opts & OPENSSL_INIT_ENGINE_OPENSSL) {
        ossl_init_once_run(&engine_openssl, ossl_init_engine_openssl);
    }
# if !defined(OPENSSL_NO_HW) && \
    (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
    if (opts & OPENSSL_INIT_ENGINE_CRYPTODEV) {
        ossl_init_once_run(&engine_cryptodev, ossl_init_engine_cryptodev);
    }
# endif
# ifndef OPENSSL_NO_RDRAND
    if (opts & OPENSSL_INIT_ENGINE_RDRAND) {
        ossl_init_once_run(&engine_rdrand, ossl_init_engine_rdrand);
    }
# endif
    if (opts & OPENSSL_INIT_ENGINE_DYNAMIC) {
        ossl_init_once_run(&engine_dynamic, ossl_init_engine_dynamic);
    }
# ifndef OPENSSL_NO_STATIC_ENGINE
#  if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
    if (opts & OPENSSL_INIT_ENGINE_PADLOCK) {
        ossl_init_once_run(&engine_padlock, ossl_init_engine_padlock);
    }
#  endif
#  if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
    if (opts & OPENSSL_INIT_ENGINE_CAPI) {
        ossl_init_once_run(&engine_capi, ossl_init_engine_capi);
    }
#  endif
    if (opts & OPENSSL_INIT_ENGINE_DASYNC) {
        ossl_init_once_run(&engine_dasync, ossl_init_engine_dasync);
    }
# endif
    if (opts & (OPENSSL_INIT_ENGINE_ALL_BUILTIN
                | OPENSSL_INIT_ENGINE_DASYNC | OPENSSL_INIT_ENGINE_OPENSSL)) {
        ENGINE_register_all_complete();
    }
#endif

    if (opts & OPENSSL_INIT_ZLIB) {
        ossl_init_once_run(&zlib, ossl_init_zlib);
    }

    return 1;
}