25#include "core/or/or_circuit_st.h"
32#define V0_DIGEST_OFFSET 5
33#define V0_DIGEST_LEN 4
34#define V0_RECOGNIZED_OFFSET 1
42 char integrity[V0_DIGEST_LEN];
48 memcpy(cell->
payload + V0_DIGEST_OFFSET, integrity, V0_DIGEST_LEN);
60 uint32_t received_integrity, calculated_integrity;
63 CTASSERT(
sizeof(uint32_t) == V0_DIGEST_LEN);
67 memcpy(&received_integrity, cell->
payload + V0_DIGEST_OFFSET, V0_DIGEST_LEN);
68 memset(cell->
payload + V0_DIGEST_OFFSET, 0, V0_DIGEST_LEN);
80 if (calculated_integrity != received_integrity) {
86 memcpy(cell->
payload + V0_DIGEST_OFFSET, &received_integrity,
91 memwipe(&backup_digest, 0,
sizeof(backup_digest));
96relay_cell_is_recognized_v0(
const cell_t *cell)
124 bool is_foward_digest)
131 if (is_foward_digest) {
172 if (thishop->
state != CPATH_STATE_OPEN) {
174 "Relay cell before first created cell? Closing.");
183 if (relay_cell_is_recognized_v0(cell)) {
188 *layer_hint = thishop;
193 thishop = thishop->
next;
194 }
while (thishop != cpath && thishop->
state == CPATH_STATE_OPEN);
196 "Incoming cell at client not recognized. Closing.");
209 if (relay_cell_is_recognized_v0(cell)) {
211 if (relay_digest_matches_v0(crypto->
f_digest, cell)) {
236 sendme_record_sending_cell_digest(
TO_CIRCUIT(circ), layer_hint);
238 thishop = layer_hint;
242 log_debug(
LD_OR,
"encrypting a layer of the relay cell.");
245 thishop = thishop->
prev;
263 sendme_record_sending_cell_digest(
TO_CIRCUIT(or_circ), NULL);
278 crypto_cipher_free(crypto->
f_crypto);
279 crypto_cipher_free(crypto->
b_crypto);
303 const char *key_data,
size_t key_data_len,
304 int reverse,
int is_hs_v3)
307 crypto_cipher_t *tmp_crypto;
308 size_t digest_len = 0;
309 size_t cipher_key_len = 0;
317 if (is_hs_v3 && BUG(key_data_len != HS_NTOR_KEY_EXPANSION_KDF_OUT_LEN)) {
319 }
else if (!is_hs_v3 && BUG(key_data_len != CPATH_KEY_MATERIAL_LEN)) {
339 const int cipher_key_bits = (int) cipher_key_len * 8;
347 log_warn(
LD_BUG,
"Forward cipher initialization failed.");
352 key_data+(2*digest_len)+cipher_key_len,
355 log_warn(
LD_BUG,
"Backward cipher initialization failed.");
static uint16_t get_uint16(const void *cp)
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.
Compile-time assertions: CTASSERT(expression).
CTASSERT(NUMBER_SECOND_GUARDS< 20)
#define log_fn(severity, domain, args,...)
Master header file for Tor-specific functionality.
#define CELL_PAYLOAD_SIZE
Origin circuit structure.
Header for relay_crypto.c.
void relay_set_digest_v0(crypto_digest_t *digest, cell_t *cell)
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)
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