2

I am coding my own version of TOR and I am trying to set up circuit management. I looked at the TOR spec and it says:

To prevent CircID collisions, when one node sends a CREATE/CREATE2 cell to another, it chooses from only one half of the possible values based on the ORs' public identity keys.

I would like to implement this approach in my code as well, but I don't understand how can the node figure out what values are possible, and determine the CircID, using the OR's identity keys?

I interpret from this that there is a way to pass information using identity keys, but I couldn't find any relevant explanation, and checking the TOR-design.html also didn't help.

1 Answer 1

2

A circuit ID identifies a circuit on an OR connection. If this OR connection is between two relays, either relay can make new circuits on that OR connection. If a relay wants to create a new circuit, it chooses a circuit ID and sends a CREATE2 cell containing that circuit ID to the other relay.

There's a collision problem when the two relays try to make new circuits at the same time. Each relay will send a CREATE2 cell to the other, but they might have accidentally chosen the same circuit ID.

To prevent this, one relay will only choose circuit IDs with the most-significant bit (MSB) set to 1, and the other will choose circuit IDs with the MSB set to 0. This effectively splits the possible circuit IDs into two groups, and each relay chooses from one of the groups.

Each relay needs to know which group it should choose circuit IDs from (the group with the MSB=0 or the group with the MSB=1). The two relays compare their public identity keys. The relay with the lower key uses the MSB=0 group, and the relay with the higher key uses the MSB=1 group.

How circuit IDs are chosen: get_unique_circ_id_by_chan

Where the MSB is chosen: high_bit

Where the keys are compared: if (crypto_pk_cmp_keys(our_identity, identity_rcvd) < 0)

2
  • First of all thank you very much for answering. If I understood correctly, you are also saying that each node's Circuit IDs are relative to the connection? For example node 'A' can have a circuit ID of '2' with both node 'B' and node 'C', yet he would still be able to differentiate between those circuits based on the relevant node?
    – saarmz
    Commented Apr 7, 2023 at 20:52
  • 1
    Right, a relay can have two circuits with the same circuit ID, as long as they are on different connections to different relays (different OR connections).
    – Steve
    Commented Apr 7, 2023 at 21:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .