24#include "core/or/or_circuit_st.h"
54 uint32_t received_integrity, calculated_integrity;
61 memcpy(&received_integrity, rh.
integrity, 4);
74 if (calculated_integrity != received_integrity) {
80 memcpy(rh.
integrity, &received_integrity, 4);
85 memwipe(&backup_digest, 0,
sizeof(backup_digest));
112 bool is_foward_digest)
119 if (is_foward_digest) {
162 if (thishop->
state != CPATH_STATE_OPEN) {
164 "Relay cell before first created cell? Closing.");
178 *layer_hint = thishop;
183 thishop = thishop->
next;
184 }
while (thishop != cpath && thishop->
state == CPATH_STATE_OPEN);
186 "Incoming cell at client not recognized. Closing.");
202 if (relay_digest_matches(crypto->
f_digest, cell)) {
227 sendme_record_sending_cell_digest(
TO_CIRCUIT(circ), layer_hint);
229 thishop = layer_hint;
233 log_debug(
LD_OR,
"encrypting a layer of the relay cell.");
236 thishop = thishop->
prev;
254 sendme_record_sending_cell_digest(
TO_CIRCUIT(or_circ), NULL);
269 crypto_cipher_free(crypto->
f_crypto);
270 crypto_cipher_free(crypto->
b_crypto);
294 const char *key_data,
size_t key_data_len,
295 int reverse,
int is_hs_v3)
298 crypto_cipher_t *tmp_crypto;
299 size_t digest_len = 0;
300 size_t cipher_key_len = 0;
308 if (is_hs_v3 && BUG(key_data_len != HS_NTOR_KEY_EXPANSION_KDF_OUT_LEN)) {
310 }
else if (!is_hs_v3 && BUG(key_data_len != CPATH_KEY_MATERIAL_LEN)) {
330 const int cipher_key_bits = (int) cipher_key_len * 8;
338 log_warn(
LD_BUG,
"Forward cipher initialization failed.");
343 key_data+(2*digest_len)+cipher_key_len,
346 log_warn(
LD_BUG,
"Backward cipher initialization failed.");
Fixed-size cell structure.
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
or_circuit_t * TO_OR_CIRCUIT(circuit_t *x)
Header file for circuitlist.c.
#define CIRCUIT_IS_ORIGIN(c)
Header file for config.c.
struct crypto_digest_t * cpath_get_incoming_digest(const crypt_path_t *cpath)
void cpath_crypt_cell(const crypt_path_t *cpath, uint8_t *payload, bool is_decrypt)
void cpath_set_cell_forward_digest(crypt_path_t *cpath, cell_t *cell)
Header file for crypt_path.c.
crypto_cipher_t * crypto_cipher_new_with_bits(const char *key, int bits)
void crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *buf, size_t len)
Headers for crypto_cipher.c.
#define CIPHER256_KEY_LEN
void crypto_digest_checkpoint(crypto_digest_checkpoint_t *checkpoint, const crypto_digest_t *digest)
void crypto_digest_restore(crypto_digest_t *digest, const crypto_digest_checkpoint_t *checkpoint)
void crypto_digest_get_digest(crypto_digest_t *digest, char *out, size_t out_len)
#define crypto_digest_free(d)
crypto_digest_t * crypto_digest256_new(digest_algorithm_t algorithm)
void crypto_digest_add_bytes(crypto_digest_t *digest, const char *data, size_t len)
crypto_digest_t * crypto_digest_new(void)
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
#define log_fn(severity, domain, args,...)
Master header file for Tor-specific functionality.
#define CELL_PAYLOAD_SIZE
Origin circuit structure.
void relay_header_pack(uint8_t *dest, const relay_header_t *src)
void relay_header_unpack(relay_header_t *dest, const uint8_t *src)
Header for relay_crypto.c.
void relay_encrypt_cell_outbound(cell_t *cell, origin_circuit_t *or_circ, crypt_path_t *layer_hint)
uint8_t * relay_crypto_get_sendme_digest(relay_crypto_t *crypto)
void relay_crypto_assert_ok(const relay_crypto_t *crypto)
int relay_crypto_init(relay_crypto_t *crypto, const char *key_data, size_t key_data_len, int reverse, int is_hs_v3)
void relay_crypto_record_sendme_digest(relay_crypto_t *crypto, bool is_foward_digest)
void relay_set_digest(crypto_digest_t *digest, cell_t *cell)
int relay_decrypt_cell(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction, crypt_path_t **layer_hint, char *recognized)
void relay_crypto_clear(relay_crypto_t *crypto)
void relay_encrypt_cell_inbound(cell_t *cell, or_circuit_t *or_circ)
void relay_crypt_one_payload(crypto_cipher_t *cipher, uint8_t *in)
Header file for sendme.c.
uint8_t payload[CELL_PAYLOAD_SIZE]
struct crypt_path_t * prev
struct crypt_path_t * next
struct crypto_digest_t * b_digest
struct crypto_digest_t * f_digest
uint8_t sendme_digest[DIGEST_LEN]
struct crypto_cipher_t * f_crypto
struct crypto_cipher_t * b_crypto