Initialize locking sooner
@@ -49,11 +49,17 @@ int s2n_disable_atexit(void) {
int s2n_init(void)
{
main_thread = pthread_self();
+ /* Should run before any init method that calls libcrypto methods
+ * to ensure we don't try to call methods that don't exist.
+ * It doesn't require any locks since it only deals with values that
+ * should be constant, so can run before s2n_locking_init. */
POSIX_GUARD_RESULT(s2n_libcrypto_validate_runtime());
- POSIX_GUARD(s2n_fips_init());
+ /* Must run before any init method that allocates memory. */
POSIX_GUARD(s2n_mem_init());
- POSIX_GUARD_RESULT(s2n_rand_init());
+ /* Must run before any init method that calls libcrypto methods. */
POSIX_GUARD_RESULT(s2n_locking_init());
+ POSIX_GUARD(s2n_fips_init());
+ POSIX_GUARD_RESULT(s2n_rand_init());
POSIX_GUARD(s2n_cipher_suites_init());
POSIX_GUARD(s2n_security_policies_init());
POSIX_GUARD(s2n_config_defaults_init());
@@ -82,9 +88,9 @@ static bool s2n_cleanup_atexit_impl(void)
/* the configs need to be wiped before resetting the memory callbacks */
s2n_wipe_static_configs();
- return s2n_result_is_ok(s2n_locking_cleanup()) &&
- s2n_result_is_ok(s2n_rand_cleanup_thread()) &&
+ return s2n_result_is_ok(s2n_rand_cleanup_thread()) &&
s2n_result_is_ok(s2n_rand_cleanup()) &&
+ s2n_result_is_ok(s2n_locking_cleanup()) &&
(s2n_mem_cleanup() == S2N_SUCCESS);
}
