simplify because relay_crypt_one_payload can't fail

This commit is contained in:
Roger Dingledine 2017-05-28 01:51:22 -04:00
parent 6fcaf83c98
commit 084b64ba2e

View File

@ -184,18 +184,12 @@ relay_digest_matches(crypto_digest_t *digest, cell_t *cell)
/** Apply <b>cipher</b> to CELL_PAYLOAD_SIZE bytes of <b>in</b> /** Apply <b>cipher</b> to CELL_PAYLOAD_SIZE bytes of <b>in</b>
* (in place). * (in place).
* *
* If <b>encrypt_mode</b> is 1 then encrypt, else decrypt. * Note that we use the same operation for encrypting and for decrypting.
*
* Returns 0.
*/ */
static int static void
relay_crypt_one_payload(crypto_cipher_t *cipher, uint8_t *in, relay_crypt_one_payload(crypto_cipher_t *cipher, uint8_t *in)
int encrypt_mode)
{ {
(void)encrypt_mode;
crypto_cipher_crypt_inplace(cipher, (char*) in, CELL_PAYLOAD_SIZE); crypto_cipher_crypt_inplace(cipher, (char*) in, CELL_PAYLOAD_SIZE);
return 0;
} }
/** /**
@ -449,8 +443,8 @@ relay_crypt(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction,
do { /* Remember: cpath is in forward order, that is, first hop first. */ do { /* Remember: cpath is in forward order, that is, first hop first. */
tor_assert(thishop); tor_assert(thishop);
if (relay_crypt_one_payload(thishop->b_crypto, cell->payload, 0) < 0) /* decrypt one layer */
return -1; relay_crypt_one_payload(thishop->b_crypto, cell->payload);
relay_header_unpack(&rh, cell->payload); relay_header_unpack(&rh, cell->payload);
if (rh.recognized == 0) { if (rh.recognized == 0) {
@ -467,19 +461,14 @@ relay_crypt(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction,
log_fn(LOG_PROTOCOL_WARN, LD_OR, log_fn(LOG_PROTOCOL_WARN, LD_OR,
"Incoming cell at client not recognized. Closing."); "Incoming cell at client not recognized. Closing.");
return -1; return -1;
} else { /* we're in the middle. Just one crypt. */ } else {
if (relay_crypt_one_payload(TO_OR_CIRCUIT(circ)->p_crypto, /* We're in the middle. Encrypt one layer. */
cell->payload, 1) < 0) relay_crypt_one_payload(TO_OR_CIRCUIT(circ)->p_crypto, cell->payload);
return -1;
// log_fn(LOG_DEBUG,"Skipping recognized check, because we're not "
// "the client.");
} }
} else /* cell_direction == CELL_DIRECTION_OUT */ { } else /* cell_direction == CELL_DIRECTION_OUT */ {
/* we're in the middle. Just one crypt. */ /* We're in the middle. Decrypt one layer. */
if (relay_crypt_one_payload(TO_OR_CIRCUIT(circ)->n_crypto, relay_crypt_one_payload(TO_OR_CIRCUIT(circ)->n_crypto, cell->payload);
cell->payload, 0) < 0)
return -1;
relay_header_unpack(&rh, cell->payload); relay_header_unpack(&rh, cell->payload);
if (rh.recognized == 0) { if (rh.recognized == 0) {
@ -526,10 +515,8 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
do { do {
tor_assert(thishop); tor_assert(thishop);
/* XXXX RD This is a bug, right? */ /* XXXX RD This is a bug, right? */
log_debug(LD_OR,"crypting a layer of the relay cell."); log_debug(LD_OR,"encrypting a layer of the relay cell.");
if (relay_crypt_one_payload(thishop->f_crypto, cell->payload, 1) < 0) { relay_crypt_one_payload(thishop->f_crypto, cell->payload);
return -1;
}
thishop = thishop->prev; thishop = thishop->prev;
} while (thishop != TO_ORIGIN_CIRCUIT(circ)->cpath->prev); } while (thishop != TO_ORIGIN_CIRCUIT(circ)->cpath->prev);
@ -546,8 +533,8 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
or_circ = TO_OR_CIRCUIT(circ); or_circ = TO_OR_CIRCUIT(circ);
chan = or_circ->p_chan; chan = or_circ->p_chan;
relay_set_digest(or_circ->p_digest, cell); relay_set_digest(or_circ->p_digest, cell);
if (relay_crypt_one_payload(or_circ->p_crypto, cell->payload, 1) < 0) /* encrypt one layer */
return -1; relay_crypt_one_payload(or_circ->p_crypto, cell->payload);
} }
++stats_n_relay_cells_relayed; ++stats_n_relay_cells_relayed;