Do not replace a HS descriptor with a different replica of itself
[tor.git] / src / or / onion.h
blobd62f032b878890f92aa36c41e2185dca85eb14ea
1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2013, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file onion.h
9 * \brief Header file for onion.c.
10 **/
12 #ifndef TOR_ONION_H
13 #define TOR_ONION_H
15 struct create_cell_t;
16 int onion_pending_add(or_circuit_t *circ, struct create_cell_t *onionskin);
17 or_circuit_t *onion_next_task(struct create_cell_t **onionskin_out);
18 int onion_num_pending(uint16_t handshake_type);
19 void onion_pending_remove(or_circuit_t *circ);
20 void clear_pending_onions(void);
22 typedef struct server_onion_keys_t {
23 uint8_t my_identity[DIGEST_LEN];
24 crypto_pk_t *onion_key;
25 crypto_pk_t *last_onion_key;
26 #ifdef CURVE25519_ENABLED
27 di_digest256_map_t *curve25519_key_map;
28 curve25519_keypair_t *junk_keypair;
29 #endif
30 } server_onion_keys_t;
32 #define MAX_ONIONSKIN_CHALLENGE_LEN 255
33 #define MAX_ONIONSKIN_REPLY_LEN 255
35 void setup_server_onion_keys(server_onion_keys_t *keys);
36 void release_server_onion_keys(server_onion_keys_t *keys);
38 void onion_handshake_state_release(onion_handshake_state_t *state);
40 int onion_skin_create(int type,
41 const extend_info_t *node,
42 onion_handshake_state_t *state_out,
43 uint8_t *onion_skin_out);
44 int onion_skin_server_handshake(int type,
45 const uint8_t *onion_skin, size_t onionskin_len,
46 const server_onion_keys_t *keys,
47 uint8_t *reply_out,
48 uint8_t *keys_out, size_t key_out_len,
49 uint8_t *rend_nonce_out);
50 int onion_skin_client_handshake(int type,
51 const onion_handshake_state_t *handshake_state,
52 const uint8_t *reply, size_t reply_len,
53 uint8_t *keys_out, size_t key_out_len,
54 uint8_t *rend_authenticator_out);
56 /** A parsed CREATE, CREATE_FAST, or CREATE2 cell. */
57 typedef struct create_cell_t {
58 /** The cell command. One of CREATE{,_FAST,2} */
59 uint8_t cell_type;
60 /** One of the ONION_HANDSHAKE_TYPE_* values */
61 uint16_t handshake_type;
62 /** The number of bytes used in <b>onionskin</b>. */
63 uint16_t handshake_len;
64 /** The client-side message for the circuit creation handshake. */
65 uint8_t onionskin[CELL_PAYLOAD_SIZE - 4];
66 } create_cell_t;
68 /** A parsed CREATED, CREATED_FAST, or CREATED2 cell. */
69 typedef struct created_cell_t {
70 /** The cell command. One of CREATED{,_FAST,2} */
71 uint8_t cell_type;
72 /** The number of bytes used in <b>reply</b>. */
73 uint16_t handshake_len;
74 /** The server-side message for the circuit creation handshake. */
75 uint8_t reply[CELL_PAYLOAD_SIZE - 2];
76 } created_cell_t;
78 /** A parsed RELAY_EXTEND or RELAY_EXTEND2 cell */
79 typedef struct extend_cell_t {
80 /** One of RELAY_EXTEND or RELAY_EXTEND2 */
81 uint8_t cell_type;
82 /** An IPv4 address and port for the node we're connecting to. */
83 tor_addr_port_t orport_ipv4;
84 /** An IPv6 address and port for the node we're connecting to. Not currently
85 * used. */
86 tor_addr_port_t orport_ipv6;
87 /** Identity fingerprint of the node we're conecting to.*/
88 uint8_t node_id[DIGEST_LEN];
89 /** The "create cell" embedded in this extend cell. Note that unlike the
90 * create cells we generate ourself, this once can have a handshake type we
91 * don't recognize. */
92 create_cell_t create_cell;
93 } extend_cell_t;
95 /** A parsed RELAY_EXTEND or RELAY_EXTEND2 cell */
96 typedef struct extended_cell_t {
97 /** One of RELAY_EXTENDED or RELAY_EXTENDED2. */
98 uint8_t cell_type;
99 /** The "created cell" embedded in this extended cell. */
100 created_cell_t created_cell;
101 } extended_cell_t;
103 void create_cell_init(create_cell_t *cell_out, uint8_t cell_type,
104 uint16_t handshake_type, uint16_t handshake_len,
105 const uint8_t *onionskin);
106 int create_cell_parse(create_cell_t *cell_out, const cell_t *cell_in);
107 int created_cell_parse(created_cell_t *cell_out, const cell_t *cell_in);
108 int extend_cell_parse(extend_cell_t *cell_out, const uint8_t command,
109 const uint8_t *payload_in, size_t payload_len);
110 int extended_cell_parse(extended_cell_t *cell_out, const uint8_t command,
111 const uint8_t *payload_in, size_t payload_len);
113 int create_cell_format(cell_t *cell_out, const create_cell_t *cell_in);
114 int create_cell_format_relayed(cell_t *cell_out, const create_cell_t *cell_in);
115 int created_cell_format(cell_t *cell_out, const created_cell_t *cell_in);
116 int extend_cell_format(uint8_t *command_out, uint16_t *len_out,
117 uint8_t *payload_out, const extend_cell_t *cell_in);
118 int extended_cell_format(uint8_t *command_out, uint16_t *len_out,
119 uint8_t *payload_out, const extended_cell_t *cell_in);
121 #endif