diff options
author | Jim Newsome <jnewsome@torproject.org> | 2023-11-08 11:18:07 -0600 |
---|---|---|
committer | Jim Newsome <jnewsome@torproject.org> | 2023-11-08 11:42:38 -0600 |
commit | d09b6b372b8cbf664f490d0a007432aca9e964e6 (patch) | |
tree | 3b4cb200a09818c8f55ef27b5e096a335b5e1804 /spec/tor-spec/relay-cells.md | |
parent | b567eaf9e6b84111ea019d7c89a39e671fbaaf13 (diff) | |
download | torspec-d09b6b372b8cbf664f490d0a007432aca9e964e6.tar.gz torspec-d09b6b372b8cbf664f490d0a007432aca9e964e6.zip |
relay-cells.md: reformat code blocks
Diffstat (limited to 'spec/tor-spec/relay-cells.md')
-rw-r--r-- | spec/tor-spec/relay-cells.md | 117 |
1 files changed, 58 insertions, 59 deletions
diff --git a/spec/tor-spec/relay-cells.md b/spec/tor-spec/relay-cells.md index add1f42..78a8f46 100644 --- a/spec/tor-spec/relay-cells.md +++ b/spec/tor-spec/relay-cells.md @@ -15,45 +15,42 @@ End nodes that accept streams may be: The payload of each unencrypted RELAY cell consists of: -```text - Relay command [1 byte] - 'Recognized' [2 bytes] - StreamID [2 bytes] - Digest [4 bytes] - Length [2 bytes] - Data [Length bytes] - Padding [PAYLOAD_LEN - 11 - Length bytes] - - The relay commands are: - - 1 -- RELAY_BEGIN [forward] - 2 -- RELAY_DATA [forward or backward] - 3 -- RELAY_END [forward or backward] - 4 -- RELAY_CONNECTED [backward] - 5 -- RELAY_SENDME [forward or backward] [sometimes control] - 6 -- RELAY_EXTEND [forward] [control] - 7 -- RELAY_EXTENDED [backward] [control] - 8 -- RELAY_TRUNCATE [forward] [control] - 9 -- RELAY_TRUNCATED [backward] [control] - 10 -- RELAY_DROP [forward or backward] [control] - 11 -- RELAY_RESOLVE [forward] - 12 -- RELAY_RESOLVED [backward] - 13 -- RELAY_BEGIN_DIR [forward] - 14 -- RELAY_EXTEND2 [forward] [control] - 15 -- RELAY_EXTENDED2 [backward] [control] - - 16..18 -- Reserved for UDP; Not yet in use, see prop339. - - 19..22 -- Reserved for Conflux, see prop329. - - 32..40 -- Used for hidden services; see rend-spec-{v2,v3}.txt. - - 41..42 -- Used for circuit padding; see Section 3 of padding-spec.txt. - - Used for flow control; see Section 4 of prop324. - 43 -- XON [forward or backward] - 44 -- XOFF [forward or backward] -``` +| Field | Size +| ----- | ---- +| Relay command | 1 byte +| 'Recognized' | 2 bytes +| StreamID | 2 bytes +| Digest | 4 bytes +| Length | 2 bytes +| Data | Length bytes +| Padding | PAYLOAD_LEN - 11 - Length bytes + +The relay commands are: + +| Command | Identifier | Direction | Control? +| ------- | ---------- | --------- | -------- +| 1 | RELAY_BEGIN | forward | +| 2 | RELAY_DATA | forward or backward | +| 3 | RELAY_END | forward or backward | +| 4 | RELAY_CONNECTED | backward | +| 5 | RELAY_SENDME | forward or backward | sometimes control +| 6 | RELAY_EXTEND | forward | control +| 7 | RELAY_EXTENDED | backward | control +| 8 | RELAY_TRUNCATE | forward | control +| 9 | RELAY_TRUNCATED | backward | control +| 10 | RELAY_DROP | forward or backward | control +| 11 | RELAY_RESOLVE | forward | +| 12 | RELAY_RESOLVED | backward | +| 13 | RELAY_BEGIN_DIR | forward | +| 14 | RELAY_EXTEND2 | forward | control +| 15 | RELAY_EXTENDED2 | backward | control +| 16..18 | Reserved for UDP; Not yet in use, see prop339. +| 19..22 | Reserved for Conflux, see prop329. +| 32..40 | Used for hidden services; see rend-spec-{v2,v3}.txt. +| 41..42 | Used for circuit padding; see Section 3 of padding-spec.txt. +| | Used for flow control; see Section 4 of prop324. +| 43 | XON | forward or backward | +| 44 | XOFF | forward or backward | Commands labelled as "forward" must only be sent by the originator of the circuit. Commands labelled as "backward" must only be sent by @@ -127,34 +124,36 @@ single field, namely 'Recognized' is not sufficient, as outlined above. When ENCRYPTING a RELAY cell, an implementation does the following: ```text - # Encode the cell in binary (recognized and digest set to zero) - tmp = cmd + [0, 0] + stream_id + [0, 0, 0, 0] + length + data + padding +# Encode the cell in binary (recognized and digest set to zero) +tmp = cmd + [0, 0] + stream_id + [0, 0, 0, 0] + length + data + padding - # Update the digest with the encoded data - digest_state = hash_update(digest_state, tmp) - digest = hash_calculate(digest_state) +# Update the digest with the encoded data +digest_state = hash_update(digest_state, tmp) +digest = hash_calculate(digest_state) - # The encoded data is the same as above with the digest field not being - # zero anymore - encoded = cmd + [0, 0] + stream_id + digest[0..4] + length + data + - padding +# The encoded data is the same as above with the digest field not being +# zero anymore +encoded = cmd + [0, 0] + stream_id + digest[0..4] + length + data + + padding - # Now we can encrypt the cell by adding the onion layers ... +# Now we can encrypt the cell by adding the onion layers ... +``` - When DECRYPTING a RELAY cell, an implementation does the following: + When DECRYPTING a RELAY cell, an implementation does the following: - decrypted = decrypt(cell) +```text +decrypted = decrypt(cell) - # Replace the digest field in decrypted by zeros - tmp = decrypted[0..5] + [0, 0, 0, 0] + decrypted[9..] +# Replace the digest field in decrypted by zeros +tmp = decrypted[0..5] + [0, 0, 0, 0] + decrypted[9..] - # Update the digest field with the decrypted data and its digest field - # set to zero - digest_state = hash_update(digest_state, tmp) - digest = hash_calculate(digest_state) +# Update the digest field with the decrypted data and its digest field +# set to zero +digest_state = hash_update(digest_state, tmp) +digest = hash_calculate(digest_state) - if digest[0..4] == decrypted[5..9] - # The cell has been fully decrypted ... +if digest[0..4] == decrypted[5..9] + # The cell has been fully decrypted ... ``` The caveat itself is that only the binary data with the digest bytes set to |