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

Implementation for legacy (tor1) relay cell encryption. More...

#include "core/or/or.h"
#include "lib/crypt_ops/crypto_cipher.h"
#include "lib/crypt_ops/crypto_util.h"
#include "core/crypto/hs_ntor.h"
#include "core/crypto/relay_crypto_tor1.h"
#include "lib/cc/ctassert.h"
#include "core/or/cell_st.h"
#include "core/crypto/relay_crypto_st.h"

Go to the source code of this file.

Macros

#define V0_DIGEST_OFFSET   5
 
#define V0_DIGEST_LEN   4
 
#define V0_RECOGNIZED_OFFSET   1
 

Functions

static void tor1_set_digest_v0 (crypto_digest_t *digest, cell_t *cell, uint8_t *buf)
 
static int tor1_relay_digest_matches_v0 (crypto_digest_t *digest, cell_t *cell, uint8_t *buf)
 
static bool relay_cell_is_recognized_v0 (const cell_t *cell)
 
static void tor1_crypt_one_payload (crypto_cipher_t *cipher, uint8_t *in)
 
void tor1_crypt_client_originate (tor1_crypt_t *tor1, cell_t *cell)
 
void tor1_crypt_relay_originate (tor1_crypt_t *tor1, cell_t *cell)
 
void tor1_crypt_client_forward (tor1_crypt_t *tor1, cell_t *cell)
 
void tor1_crypt_relay_backward (tor1_crypt_t *tor1, cell_t *cell)
 
bool tor1_crypt_relay_forward (tor1_crypt_t *tor1, cell_t *cell)
 
bool tor1_crypt_client_backward (tor1_crypt_t *tor1, cell_t *cell)
 
size_t tor1_key_material_len (bool is_hs)
 
int tor1_crypt_init (tor1_crypt_t *crypto, const char *key_data, size_t key_data_len, int reverse, int is_hs_v3)
 
void tor1_crypt_assert_ok (const tor1_crypt_t *crypto)
 
void tor1_crypt_clear (tor1_crypt_t *crypto)
 

Detailed Description

Implementation for legacy (tor1) relay cell encryption.

Definition in file relay_crypto_tor1.c.

Macro Definition Documentation

◆ V0_DIGEST_LEN

#define V0_DIGEST_LEN   4

Definition at line 24 of file relay_crypto_tor1.c.

◆ V0_DIGEST_OFFSET

#define V0_DIGEST_OFFSET   5

Definition at line 23 of file relay_crypto_tor1.c.

◆ V0_RECOGNIZED_OFFSET

#define V0_RECOGNIZED_OFFSET   1

Definition at line 25 of file relay_crypto_tor1.c.

Function Documentation

◆ relay_cell_is_recognized_v0()

static bool relay_cell_is_recognized_v0 ( const cell_t cell)
inlinestatic

Definition at line 91 of file relay_crypto_tor1.c.

◆ tor1_crypt_assert_ok()

void tor1_crypt_assert_ok ( const tor1_crypt_t crypto)

Assert that crypto is valid and set.

Definition at line 296 of file relay_crypto_tor1.c.

◆ tor1_crypt_clear()

void tor1_crypt_clear ( tor1_crypt_t crypto)

Definition at line 305 of file relay_crypto_tor1.c.

◆ tor1_crypt_client_backward()

bool tor1_crypt_client_backward ( tor1_crypt_t tor1,
cell_t cell 
)

Decrypt cell using the cryptographic material in tor1.

Return true when this cell is recognized and authenticated as coming from the relay that also holds this cryptographic material.

This method should be used by clients on incoming cells.

Definition at line 181 of file relay_crypto_tor1.c.

◆ tor1_crypt_client_forward()

void tor1_crypt_client_forward ( tor1_crypt_t tor1,
cell_t cell 
)

Encrypt cell using the cryptographic material in tor1.

This method should be used by clients for cryptographic layers that are not the final recipient of the cell.

Definition at line 140 of file relay_crypto_tor1.c.

◆ tor1_crypt_client_originate()

void tor1_crypt_client_originate ( tor1_crypt_t tor1,
cell_t cell 
)

Encrypt and authenticate cell using the cryptographic material in tor1.

This method should be used for the first encryption performed by the client - that is, the one corresponding to the exit node.

Definition at line 114 of file relay_crypto_tor1.c.

◆ tor1_crypt_init()

int tor1_crypt_init ( tor1_crypt_t crypto,
const char *  key_data,
size_t  key_data_len,
int  reverse,
int  is_hs_v3 
)

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 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 222 of file relay_crypto_tor1.c.

◆ tor1_crypt_one_payload()

static void tor1_crypt_one_payload ( crypto_cipher_t *  cipher,
uint8_t *  in 
)
static

Apply cipher to CELL_PAYLOAD_SIZE bytes of in (in place).

Note that we use the same operation for encrypting and for decrypting.

Definition at line 102 of file relay_crypto_tor1.c.

Referenced by tor1_crypt_client_backward(), tor1_crypt_client_forward(), tor1_crypt_client_originate(), tor1_crypt_relay_backward(), tor1_crypt_relay_forward(), and tor1_crypt_relay_originate().

◆ tor1_crypt_relay_backward()

void tor1_crypt_relay_backward ( tor1_crypt_t tor1,
cell_t cell 
)

Encrypt cell using the cryptographic material in tor1.

This method should be used by relays on cells that are moving toward the client.

Definition at line 150 of file relay_crypto_tor1.c.

◆ tor1_crypt_relay_forward()

bool tor1_crypt_relay_forward ( tor1_crypt_t tor1,
cell_t cell 
)

Decrypt cell using the cryptographic material in tor1.

Return true when we are the destination for this cell.

This method should be used by relays on cells that are moving away from the client.

Definition at line 162 of file relay_crypto_tor1.c.

◆ tor1_crypt_relay_originate()

void tor1_crypt_relay_originate ( tor1_crypt_t tor1,
cell_t cell 
)

Encrypt and authenticate cell, using the cryptographic material in tor1.

This method should be used by relays when originating cells toward the client.

Definition at line 128 of file relay_crypto_tor1.c.

◆ tor1_key_material_len()

size_t tor1_key_material_len ( bool  is_hs)

Return the number of bytes that tor1_crypt_init expects.

Definition at line 196 of file relay_crypto_tor1.c.

Referenced by relay_crypto_key_material_len().

◆ tor1_relay_digest_matches_v0()

static int tor1_relay_digest_matches_v0 ( crypto_digest_t digest,
cell_t cell,
uint8_t *  buf 
)
static

Does the digest for this circuit indicate that this cell is for us?

Update digest from the payload of cell (with the integrity part set to 0). If the integrity part is valid, return 1 and save the full digest in the 20-byte buffer buf, else restore digest and cell to their original state and return 0.

Definition at line 49 of file relay_crypto_tor1.c.

◆ tor1_set_digest_v0()

static void tor1_set_digest_v0 ( crypto_digest_t digest,
cell_t cell,
uint8_t *  buf 
)
static

Update digest from the payload of cell. Assign integrity part to cell. Record full 20-byte digest in buf.

Definition at line 31 of file relay_crypto_tor1.c.

Referenced by tor1_crypt_client_originate(), and tor1_crypt_relay_originate().