mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Extract the crypto parts of circuit_package_relay_cell.
This commit is contained in:
parent
2989326054
commit
320dcf65b7
@ -487,6 +487,42 @@ relay_decrypt_cell(circuit_t *circ, cell_t *cell,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypt a cell <b>cell</b> that we are creating, and sending outbound on
|
||||||
|
* <b>circ</b> until the hop corresponding to <b>layer_hint</b>.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
relay_encrypt_cell_outbound(cell_t *cell,
|
||||||
|
origin_circuit_t *circ,
|
||||||
|
crypt_path_t *layer_hint)
|
||||||
|
{
|
||||||
|
crypt_path_t *thishop; /* counter for repeated crypts */
|
||||||
|
relay_set_digest(layer_hint->f_digest, cell);
|
||||||
|
|
||||||
|
thishop = layer_hint;
|
||||||
|
/* moving from farthest to nearest hop */
|
||||||
|
do {
|
||||||
|
tor_assert(thishop);
|
||||||
|
log_debug(LD_OR,"encrypting a layer of the relay cell.");
|
||||||
|
relay_crypt_one_payload(thishop->f_crypto, cell->payload);
|
||||||
|
|
||||||
|
thishop = thishop->prev;
|
||||||
|
} while (thishop != circ->cpath->prev);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypt a cell <b>cell</b> that we are creating, and sending on
|
||||||
|
* <b>circuit</b> to the origin.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
relay_encrypt_cell_inbound(cell_t *cell,
|
||||||
|
or_circuit_t *or_circ)
|
||||||
|
{
|
||||||
|
relay_set_digest(or_circ->p_digest, cell);
|
||||||
|
/* encrypt one layer */
|
||||||
|
relay_crypt_one_payload(or_circ->p_crypto, cell->payload);
|
||||||
|
}
|
||||||
|
|
||||||
/** Package a relay cell from an edge:
|
/** Package a relay cell from an edge:
|
||||||
* - Encrypt it to the right layer
|
* - Encrypt it to the right layer
|
||||||
* - Append it to the appropriate cell_queue on <b>circ</b>.
|
* - Append it to the appropriate cell_queue on <b>circ</b>.
|
||||||
@ -505,7 +541,6 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cell_direction == CELL_DIRECTION_OUT) {
|
if (cell_direction == CELL_DIRECTION_OUT) {
|
||||||
crypt_path_t *thishop; /* counter for repeated crypts */
|
|
||||||
chan = circ->n_chan;
|
chan = circ->n_chan;
|
||||||
if (!chan) {
|
if (!chan) {
|
||||||
log_warn(LD_BUG,"outgoing relay cell sent from %s:%d has n_chan==NULL."
|
log_warn(LD_BUG,"outgoing relay cell sent from %s:%d has n_chan==NULL."
|
||||||
@ -528,20 +563,8 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
|
|||||||
return 0; /* just drop it */
|
return 0; /* just drop it */
|
||||||
}
|
}
|
||||||
|
|
||||||
relay_set_digest(layer_hint->f_digest, cell);
|
relay_encrypt_cell_outbound(cell, TO_ORIGIN_CIRCUIT(circ), layer_hint);
|
||||||
|
|
||||||
thishop = layer_hint;
|
|
||||||
/* moving from farthest to nearest hop */
|
|
||||||
do {
|
|
||||||
tor_assert(thishop);
|
|
||||||
log_debug(LD_OR,"encrypting a layer of the relay cell.");
|
|
||||||
relay_crypt_one_payload(thishop->f_crypto, cell->payload);
|
|
||||||
|
|
||||||
thishop = thishop->prev;
|
|
||||||
} while (thishop != TO_ORIGIN_CIRCUIT(circ)->cpath->prev);
|
|
||||||
|
|
||||||
} else { /* incoming cell */
|
} else { /* incoming cell */
|
||||||
or_circuit_t *or_circ;
|
|
||||||
if (CIRCUIT_IS_ORIGIN(circ)) {
|
if (CIRCUIT_IS_ORIGIN(circ)) {
|
||||||
/* We should never package an _incoming_ cell from the circuit
|
/* We should never package an _incoming_ cell from the circuit
|
||||||
* origin; that means we messed up somewhere. */
|
* origin; that means we messed up somewhere. */
|
||||||
@ -549,11 +572,9 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
|
|||||||
assert_circuit_ok(circ);
|
assert_circuit_ok(circ);
|
||||||
return 0; /* just drop it */
|
return 0; /* just drop it */
|
||||||
}
|
}
|
||||||
or_circ = TO_OR_CIRCUIT(circ);
|
or_circuit_t *or_circ = TO_OR_CIRCUIT(circ);
|
||||||
|
relay_encrypt_cell_inbound(cell, or_circ);
|
||||||
chan = or_circ->p_chan;
|
chan = or_circ->p_chan;
|
||||||
relay_set_digest(or_circ->p_digest, cell);
|
|
||||||
/* encrypt one layer */
|
|
||||||
relay_crypt_one_payload(or_circ->p_crypto, cell->payload);
|
|
||||||
}
|
}
|
||||||
++stats_n_relay_cells_relayed;
|
++stats_n_relay_cells_relayed;
|
||||||
|
|
||||||
|
@ -90,8 +90,12 @@ void circuit_clear_cell_queue(circuit_t *circ, channel_t *chan);
|
|||||||
|
|
||||||
void stream_choice_seed_weak_rng(void);
|
void stream_choice_seed_weak_rng(void);
|
||||||
|
|
||||||
int relay_crypt(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction,
|
int relay_decrypt_cell(circuit_t *circ, cell_t *cell,
|
||||||
crypt_path_t **layer_hint, char *recognized);
|
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);
|
||||||
|
|
||||||
circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids);
|
circid_t packed_cell_get_circid(const packed_cell_t *cell, int wide_circ_ids);
|
||||||
|
|
||||||
|
@ -518,7 +518,8 @@ bench_cell_ops(void)
|
|||||||
for (i = 0; i < iters; ++i) {
|
for (i = 0; i < iters; ++i) {
|
||||||
char recognized = 0;
|
char recognized = 0;
|
||||||
crypt_path_t *layer_hint = NULL;
|
crypt_path_t *layer_hint = NULL;
|
||||||
relay_crypt(TO_CIRCUIT(or_circ), cell, d, &layer_hint, &recognized);
|
relay_decrypt_cell(TO_CIRCUIT(or_circ), cell, d,
|
||||||
|
&layer_hint, &recognized);
|
||||||
}
|
}
|
||||||
end = perftime();
|
end = perftime();
|
||||||
printf("%sbound cells: %.2f ns per cell. (%.2f ns per byte of payload)\n",
|
printf("%sbound cells: %.2f ns per cell. (%.2f ns per byte of payload)\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user