Tor 0.4.9.2-alpha-dev
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Macros | Enumerations | Functions
relay_crypto.h File Reference

Header for relay_crypto.c. More...

Go to the source code of this file.

Macros

#define MAX_RELAY_KEY_MATERIAL_LEN   224
 

Enumerations

enum  relay_crypto_alg_t {
  RELAY_CRYPTO_ALG_TOR1 , RELAY_CRYPTO_ALG_TOR1_HSC , RELAY_CRYPTO_ALG_TOR1_HSS , RELAY_CRYPTO_ALG_CGO_CLIENT ,
  RELAY_CRYPTO_ALG_CGO_RELAY
}
 

Functions

ssize_t relay_crypto_key_material_len (relay_crypto_alg_t alg)
 
int relay_crypto_init (relay_crypto_alg_t alg, relay_crypto_t *crypto, const char *key_data, size_t key_data_len)
 
int relay_decrypt_cell (circuit_t *circ, cell_t *cell, cell_direction_t cell_direction, crypt_path_t **layer_hint, char *recognized)
 
void relay_encrypt_cell_outbound (cell_t *cell, origin_circuit_t *or_circ, crypt_path_t *layer_hint)
 
void relay_encrypt_cell_inbound (cell_t *cell, or_circuit_t *or_circ)
 
void relay_crypto_clear (relay_crypto_t *crypto)
 
void relay_crypto_assert_ok (const relay_crypto_t *crypto)
 
const uint8_t * relay_crypto_get_sendme_tag (relay_crypto_t *crypto, size_t *len_out)
 
size_t relay_crypto_sendme_tag_len (const relay_crypto_t *crypto)
 

Detailed Description

Header for relay_crypto.c.

Definition in file relay_crypto.h.

Macro Definition Documentation

◆ MAX_RELAY_KEY_MATERIAL_LEN

#define MAX_RELAY_KEY_MATERIAL_LEN   224

Largest possible return value for relay_crypto_key_material_len.

Definition at line 36 of file relay_crypto.h.

Enumeration Type Documentation

◆ relay_crypto_alg_t

Enumeration to identify which relay crypto algorithm is in use.

Enumerator
RELAY_CRYPTO_ALG_TOR1 

Tor1 relay crypto, as used for ordinary circuit hops.

RELAY_CRYPTO_ALG_TOR1_HSC 

Tor1 relay crypto, as used as an onion service client for the shared virtual HS hop created with an INTRODUCE/RENVEZVOUS handshake.

RELAY_CRYPTO_ALG_TOR1_HSS 

Tor1 relay crypto, as used as an onion service for the shared virtual HS hop created with an INTRODUCE/RENVEZVOUS handshake.

RELAY_CRYPTO_ALG_CGO_CLIENT 

CGO crypto, as used at a client

RELAY_CRYPTO_ALG_CGO_RELAY 

CGO crypto, as used at a relay

Definition at line 16 of file relay_crypto.h.

Function Documentation

◆ relay_crypto_assert_ok()

void relay_crypto_assert_ok ( const relay_crypto_t crypto)

Assert that crypto is valid and set.

Definition at line 402 of file relay_crypto.c.

◆ relay_crypto_clear()

void relay_crypto_clear ( relay_crypto_t crypto)

Release all storage held inside crypto, but do not free crypto itself: it lives inside another object.

Definition at line 290 of file relay_crypto.c.

Referenced by cpath_free().

◆ relay_crypto_get_sendme_tag()

const uint8_t * relay_crypto_get_sendme_tag ( relay_crypto_t crypto,
size_t *  len_out 
)

Return the sendme tag within the crypto object, along with its length.

This is the digest from the most recent cell that we originated or recognized, in either direction. Calls to any encryption function on crypto may invalidate this digest.

Definition at line 39 of file relay_crypto.c.

Referenced by cpath_get_sendme_tag().

◆ relay_crypto_init()

int relay_crypto_init ( relay_crypto_alg_t  alg,
relay_crypto_t crypto,
const char *  key_data,
size_t  key_data_len 
)

Initialize crypto from the key material in key_data.

If is_hs_v3 is set, this cpath will be used for next gen hidden service circuits and key_data must be at least HS_NTOR_KEY_EXPANSION_KDF_OUT_LEN bytes in length.

If is_hs_v3 is not set, key_data must contain CPATH_KEY_MATERIAL_LEN bytes, which are used as follows:

  • 20 to initialize f_digest
  • 20 to initialize b_digest
  • 16 to key f_crypto
  • 16 to key b_crypto

(If 'reverse' is true, then f_XX and b_XX are swapped.)

Return 0 if init was successful, else -1 if it failed.

Definition at line 349 of file relay_crypto.c.

Referenced by cpath_init_circuit_crypto().

◆ relay_crypto_key_material_len()

ssize_t relay_crypto_key_material_len ( relay_crypto_alg_t  alg)

Return the amount of key material we need to initialize the given relay crypto algorithm.

Return -1 if the algorithm is unrecognized.

Definition at line 385 of file relay_crypto.c.

◆ relay_crypto_sendme_tag_len()

size_t relay_crypto_sendme_tag_len ( const relay_crypto_t crypto)

Return the length of SENDME tags generated by crypto.

Definition at line 56 of file relay_crypto.c.

◆ relay_decrypt_cell()

int relay_decrypt_cell ( circuit_t circ,
cell_t cell,
cell_direction_t  cell_direction,
crypt_path_t **  layer_hint,
char *  recognized 
)

Do the appropriate en/decryptions for cell arriving on circ in direction cell_direction.

If cell_direction == CELL_DIRECTION_IN:

  • If we're at the origin (we're the OP), for hops 1..N, decrypt cell. If recognized, stop.
  • Else (we're not the OP), encrypt one hop. Cell is not recognized.

If cell_direction == CELL_DIRECTION_OUT:

  • decrypt one hop. Check if recognized.

If cell is recognized, set *recognized to 1, and set *layer_hint to the hop that recognized it.

Return -1 to indicate that we should mark the circuit for close, else return 0.

Definition at line 151 of file relay_crypto.c.

Referenced by circuit_receive_relay_cell().

◆ relay_encrypt_cell_inbound()

void relay_encrypt_cell_inbound ( cell_t cell,
or_circuit_t or_circ 
)

Encrypt a cell cell that we are creating, and sending on circuit to the origin.

The integrity field and recognized field of cell's relay headers must be set to zero.

Definition at line 267 of file relay_crypto.c.

◆ relay_encrypt_cell_outbound()

void relay_encrypt_cell_outbound ( cell_t cell,
origin_circuit_t circ,
crypt_path_t layer_hint 
)

Encrypt a cell cell that we are creating, and sending outbound on circ until the hop corresponding to layer_hint.

The integrity field and recognized field of cell's relay headers must be set to zero.

Definition at line 244 of file relay_crypto.c.