From: Nick Mathewson Date: Wed, 28 May 2025 12:27:58 +0000 (-0400) Subject: Rename two "record_*_digest functions to "save". X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed67ef78ab16cfaaee2e16dab94c28a940aa6b6d;p=thirdparty%2Ftor.git Rename two "record_*_digest functions to "save". This makes an important distinction: "recording" a digest puts it in the expected-sendme queue, whereas "saving" a digest makes a temporary copy inside the relay_crypto_t. --- diff --git a/src/core/crypto/relay_crypto.c b/src/core/crypto/relay_crypto.c index 00d8feb360..39a678ebfb 100644 --- a/src/core/crypto/relay_crypto.c +++ b/src/core/crypto/relay_crypto.c @@ -109,7 +109,10 @@ tor1_crypt_one_payload(crypto_cipher_t *cipher, uint8_t *in) crypto_cipher_crypt_inplace(cipher, (char*) in, CELL_PAYLOAD_SIZE); } -/** Return the sendme_digest within the crypto object. */ +/** Return the sendme_digest within the crypto object. + * + * Before calling this function, you must call relay_crypto_save_sendme_digest. + */ uint8_t * relay_crypto_get_sendme_digest(relay_crypto_t *crypto) { @@ -117,11 +120,15 @@ relay_crypto_get_sendme_digest(relay_crypto_t *crypto) return crypto->sendme_digest; } -/** Record the cell digest, indicated by is_foward_digest or not, as the - * SENDME cell digest. */ +/** Save the cell digest, indicated by is_foward_digest or not, as the + * SENDME cell digest inside this relay_crypto_t. + * + * This function must be called before relay_crypto_get_sendme_digest + * will work correctly. + */ void -relay_crypto_record_sendme_digest(relay_crypto_t *crypto, - bool is_foward_digest) +tor1_save_sendme_digest(relay_crypto_t *crypto, + bool is_foward_digest) { struct crypto_digest_t *digest; @@ -233,7 +240,7 @@ relay_encrypt_cell_outbound(cell_t *cell, cpath_set_cell_forward_digest(layer_hint, cell); /* Record cell digest as the SENDME digest if need be. */ - sendme_record_sending_cell_digest(TO_CIRCUIT(circ), layer_hint); + sendme_save_sending_cell_digest(TO_CIRCUIT(circ), layer_hint); thishop = layer_hint; /* moving from farthest to nearest hop */ @@ -260,7 +267,7 @@ relay_encrypt_cell_inbound(cell_t *cell, tor1_set_digest_v0(or_circ->crypto.b_digest, cell); /* Record cell digest as the SENDME digest if need be. */ - sendme_record_sending_cell_digest(TO_CIRCUIT(or_circ), NULL); + sendme_save_sending_cell_digest(TO_CIRCUIT(or_circ), NULL); /* encrypt one layer */ tor1_crypt_one_payload(or_circ->crypto.b_crypto, cell->payload); diff --git a/src/core/crypto/relay_crypto.h b/src/core/crypto/relay_crypto.h index a735b696ec..341c612fca 100644 --- a/src/core/crypto/relay_crypto.h +++ b/src/core/crypto/relay_crypto.h @@ -29,8 +29,8 @@ void relay_crypto_assert_ok(const relay_crypto_t *crypto); uint8_t *relay_crypto_get_sendme_digest(relay_crypto_t *crypto); -void relay_crypto_record_sendme_digest(relay_crypto_t *crypto, - bool is_foward_digest); +void tor1_save_sendme_digest(relay_crypto_t *crypto, + bool is_foward_digest); void tor1_crypt_one_payload(crypto_cipher_t *cipher, uint8_t *in); diff --git a/src/core/or/crypt_path.c b/src/core/or/crypt_path.c index 9214bbc26f..b2cf7a8d59 100644 --- a/src/core/or/crypt_path.c +++ b/src/core/or/crypt_path.c @@ -213,13 +213,14 @@ cpath_get_sendme_digest(crypt_path_t *cpath) return relay_crypto_get_sendme_digest(&cpath->pvt_crypto); } -/** Record the cell digest, indicated by is_foward_digest or not, as the - * SENDME cell digest. */ +/** Save the cell digest, indicated by is_foward_digest or not, as the + * SENDME cell digest inside the cpath's relay_crypto_t. + */ void -cpath_sendme_record_cell_digest(crypt_path_t *cpath, bool is_foward_digest) +cpath_sendme_save_cell_digest(crypt_path_t *cpath, bool is_foward_digest) { tor_assert(cpath); - relay_crypto_record_sendme_digest(&cpath->pvt_crypto, is_foward_digest); + tor1_save_sendme_digest(&cpath->pvt_crypto, is_foward_digest); } /************ other cpath functions ***************************/ diff --git a/src/core/or/crypt_path.h b/src/core/or/crypt_path.h index 7a95fec2b4..dfd2ed4857 100644 --- a/src/core/or/crypt_path.h +++ b/src/core/or/crypt_path.h @@ -27,7 +27,7 @@ cpath_crypt_cell(const crypt_path_t *cpath, uint8_t *payload, bool is_decrypt); struct crypto_digest_t * cpath_get_incoming_digest(const crypt_path_t *cpath); -void cpath_sendme_record_cell_digest(crypt_path_t *cpath, +void cpath_sendme_save_cell_digest(crypt_path_t *cpath, bool is_foward_digest); void diff --git a/src/core/or/relay.c b/src/core/or/relay.c index 84dfe00157..6616b92d77 100644 --- a/src/core/or/relay.c +++ b/src/core/or/relay.c @@ -267,7 +267,7 @@ circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, /* Recognized cell, the cell digest has been updated, we'll record it for * the SENDME if need be. */ - sendme_record_received_cell_digest(circ, layer_hint); + sendme_save_received_cell_digest(circ, layer_hint); relay_msg_t msg_buf; if (relay_msg_decode_cell_in_place(format, cell, &msg_buf) < 0) { diff --git a/src/core/or/sendme.c b/src/core/or/sendme.c index 933170d9f0..426495d745 100644 --- a/src/core/or/sendme.c +++ b/src/core/or/sendme.c @@ -720,11 +720,12 @@ sendme_record_cell_digest_on_circ(circuit_t *circ, crypt_path_t *cpath) record_cell_digest_on_circ(circ, sendme_digest); } -/* Called once we decrypted a cell and recognized it. Record the cell digest - * as the next sendme digest only if the next cell we'll send on the circuit +/* Called once we decrypted a cell and recognized it. Save the cell digest + * as the next sendme digest in the cpath's relay_crypto_t, + * only if the next cell we'll send on the circuit * is expected to be a SENDME. */ void -sendme_record_received_cell_digest(circuit_t *circ, crypt_path_t *cpath) +sendme_save_received_cell_digest(circuit_t *circ, crypt_path_t *cpath) { tor_assert(circ); @@ -737,18 +738,19 @@ sendme_record_received_cell_digest(circuit_t *circ, crypt_path_t *cpath) if (cpath) { /* Record incoming digest. */ - cpath_sendme_record_cell_digest(cpath, false); + cpath_sendme_save_cell_digest(cpath, false); } else { /* Record forward digest. */ - relay_crypto_record_sendme_digest(&TO_OR_CIRCUIT(circ)->crypto, true); + tor1_save_sendme_digest(&TO_OR_CIRCUIT(circ)->crypto, true); } } -/* Called once we encrypted a cell. Record the cell digest as the next sendme - * digest only if the next cell we expect to receive is a SENDME so we can - * match the digests. */ +/* Called once we encrypted a cell. Save the cell digest as the next sendme + * as the next sendme digest in the cpath's relay_crypto_t + * only if the we expect to receive a SENDME matching this cell's digest. + */ void -sendme_record_sending_cell_digest(circuit_t *circ, crypt_path_t *cpath) +sendme_save_sending_cell_digest(circuit_t *circ, crypt_path_t *cpath) { tor_assert(circ); @@ -759,10 +761,10 @@ sendme_record_sending_cell_digest(circuit_t *circ, crypt_path_t *cpath) if (cpath) { /* Record the forward digest. */ - cpath_sendme_record_cell_digest(cpath, true); + cpath_sendme_save_cell_digest(cpath, true); } else { /* Record the incoming digest. */ - relay_crypto_record_sendme_digest(&TO_OR_CIRCUIT(circ)->crypto, false); + tor1_save_sendme_digest(&TO_OR_CIRCUIT(circ)->crypto, false); } end: diff --git a/src/core/or/sendme.h b/src/core/or/sendme.h index bc1daef23d..fe6dc74542 100644 --- a/src/core/or/sendme.h +++ b/src/core/or/sendme.h @@ -38,8 +38,8 @@ int sendme_note_stream_data_packaged(edge_connection_t *conn, size_t len); /* Record cell digest on circuit. */ void sendme_record_cell_digest_on_circ(circuit_t *circ, crypt_path_t *cpath); /* Record cell digest as the SENDME digest. */ -void sendme_record_received_cell_digest(circuit_t *circ, crypt_path_t *cpath); -void sendme_record_sending_cell_digest(circuit_t *circ, crypt_path_t *cpath); +void sendme_save_received_cell_digest(circuit_t *circ, crypt_path_t *cpath); +void sendme_save_sending_cell_digest(circuit_t *circ, crypt_path_t *cpath); /* Private section starts. */ #ifdef SENDME_PRIVATE