Tor  0.4.7.0-alpha-dev
Macros | Functions | Variables
crypto_init.c File Reference

Initialize and shut down Tor's crypto library and subsystem. More...

#include "orconfig.h"
#include "lib/crypt_ops/crypto_init.h"
#include "lib/crypt_ops/crypto_curve25519.h"
#include "lib/crypt_ops/crypto_dh.h"
#include "lib/crypt_ops/crypto_ed25519.h"
#include "lib/crypt_ops/crypto_openssl_mgt.h"
#include "lib/crypt_ops/crypto_nss_mgt.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/crypt_ops/crypto_sys.h"
#include "lib/crypt_ops/crypto_options_st.h"
#include "lib/conf/conftypes.h"
#include "lib/log/util_bug.h"
#include "lib/subsys/subsys.h"
#include "ext/siphash.h"
#include "lib/crypt_ops/crypto_options.inc"

Go to the source code of this file.

Macros

#define CRYPTO_PRIVATE
 
#define CRYPTO_OPTIONS_MAGIC   0x68757368
 
#define CONF_CONTEXT   LL_TABLE
 

Functions

int crypto_init_siphash_key (void)
 
int crypto_early_init (void)
 
int crypto_global_init (int useAccel, const char *accelName, const char *accelDir)
 
void crypto_thread_cleanup (void)
 
int crypto_global_cleanup (void)
 
void crypto_prefork (void)
 
void crypto_postfork (void)
 
const char * crypto_get_library_name (void)
 
const char * crypto_get_library_version_string (void)
 
const char * crypto_get_header_version_string (void)
 
int tor_is_using_nss (void)
 
static int subsys_crypto_initialize (void)
 
static void subsys_crypto_shutdown (void)
 
static void subsys_crypto_prefork (void)
 
static void subsys_crypto_postfork (void)
 
static void subsys_crypto_thread_cleanup (void)
 
static int crypto_options_validate (const void *arg, char **msg_out)
 
static int crypto_set_options (void *arg)
 

Variables

static int crypto_early_initialized_ = 0
 
static int crypto_global_initialized_ = 0
 
static int have_seeded_siphash = 0
 
static const config_format_t crypto_options_fmt
 
const struct subsys_fns_t sys_crypto
 

Detailed Description

Initialize and shut down Tor's crypto library and subsystem.

Definition in file crypto_init.c.

Macro Definition Documentation

◆ CRYPTO_OPTIONS_MAGIC

#define CRYPTO_OPTIONS_MAGIC   0x68757368

Magic number for crypto_options_t.

Definition at line 259 of file crypto_init.c.

Function Documentation

◆ crypto_early_init()

int crypto_early_init ( void  )

Initialize the crypto library. Return 0 on success, -1 on failure.

Definition at line 59 of file crypto_init.c.

Referenced by crypto_global_init().

◆ crypto_get_header_version_string()

const char* crypto_get_header_version_string ( void  )

Return the version of the crypto library we're using, as given in the headers.

Definition at line 204 of file crypto_init.c.

◆ crypto_get_library_name()

const char* crypto_get_library_name ( void  )

Return the name of the crypto library we're using.

Definition at line 178 of file crypto_init.c.

Referenced by options_init_from_torrc().

◆ crypto_get_library_version_string()

const char* crypto_get_library_version_string ( void  )

Return the version of the crypto library we are using, as given in the library.

Definition at line 191 of file crypto_init.c.

Referenced by options_init_from_torrc().

◆ crypto_global_cleanup()

int crypto_global_cleanup ( void  )

Uninitialize the crypto library. Return 0 on success. Does not detect failure.

Definition at line 129 of file crypto_init.c.

◆ crypto_global_init()

int crypto_global_init ( int  useAccel,
const char *  accelName,
const char *  accelDir 
)

Initialize the crypto library. Return 0 on success, -1 on failure.

Definition at line 88 of file crypto_init.c.

Referenced by crypto_set_options().

◆ crypto_init_siphash_key()

int crypto_init_siphash_key ( void  )

Set up the siphash key if we haven't already done so.

Definition at line 44 of file crypto_init.c.

◆ crypto_options_validate()

static int crypto_options_validate ( const void *  arg,
char **  msg_out 
)
static

Return 0 if arg is a valid crypto_options_t. Otherwise return -1 and set *msg_out to a freshly allocated error string.

Definition at line 266 of file crypto_init.c.

◆ crypto_postfork()

void crypto_postfork ( void  )

Run operations that the crypto library requires to be happy again after forking.

Definition at line 169 of file crypto_init.c.

◆ crypto_prefork()

void crypto_prefork ( void  )

Run operations that the crypto library requires to be happy again after forking.

Definition at line 153 of file crypto_init.c.

◆ crypto_set_options()

static int crypto_set_options ( void *  arg)
static

Invoked from subsysmgr.c when a new set of options arrives.

Definition at line 302 of file crypto_init.c.

◆ crypto_thread_cleanup()

void crypto_thread_cleanup ( void  )

Free crypto resources held by this thread.

Definition at line 116 of file crypto_init.c.

◆ tor_is_using_nss()

int tor_is_using_nss ( void  )

Return true iff Tor is using the NSS library.

Definition at line 216 of file crypto_init.c.

Variable Documentation

◆ crypto_early_initialized_

int crypto_early_initialized_ = 0
static

Boolean: has our crypto library been initialized? (early phase)

Definition at line 35 of file crypto_init.c.

Referenced by crypto_early_init().

◆ crypto_global_initialized_

int crypto_global_initialized_ = 0
static

Boolean: has our crypto library been initialized? (late phase)

Definition at line 38 of file crypto_init.c.

Referenced by crypto_global_init().

◆ crypto_options_fmt

const config_format_t crypto_options_fmt
static
Initial value:
= {
.size = sizeof(crypto_options_t),
.magic = { "crypto_options_t",
offsetof(crypto_options_t, magic) },
.vars = crypto_options_t_vars,
.validate_fn = crypto_options_validate,
}
static int crypto_options_validate(const void *arg, char **msg_out)
Definition: crypto_init.c:266
#define CRYPTO_OPTIONS_MAGIC
Definition: crypto_init.c:259

Declares the configuration options for this module.

Definition at line 289 of file crypto_init.c.

◆ sys_crypto

const struct subsys_fns_t sys_crypto
Initial value:
= {
.name = "crypto",
.supported = true,
.level = -60,
.initialize = subsys_crypto_initialize,
.shutdown = subsys_crypto_shutdown,
.prefork = subsys_crypto_prefork,
.postfork = subsys_crypto_postfork,
.thread_cleanup = subsys_crypto_thread_cleanup,
.options_format = &crypto_options_fmt,
.set_options = crypto_set_options,
}
static const config_format_t crypto_options_fmt
Definition: crypto_init.c:289
static int crypto_set_options(void *arg)
Definition: crypto_init.c:302
#define SUBSYS_DECLARE_LOCATION()
Definition: subsys.h:211

Definition at line 302 of file crypto_init.c.