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-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
9 * \brief Header file for onion.c.
16 struct curve25519_keypair_t
;
17 struct curve25519_public_key_t
;
18 #include "lib/crypt_ops/crypto_ed25519.h"
20 #define MAX_ONIONSKIN_CHALLENGE_LEN 255
21 #define MAX_ONIONSKIN_REPLY_LEN 255
23 /** A parsed CREATE, CREATE_FAST, or CREATE2 cell. */
24 typedef struct create_cell_t
{
25 /** The cell command. One of CREATE{,_FAST,2} */
27 /** One of the ONION_HANDSHAKE_TYPE_* values */
28 uint16_t handshake_type
;
29 /** The number of bytes used in <b>onionskin</b>. */
30 uint16_t handshake_len
;
31 /** The client-side message for the circuit creation handshake. */
32 uint8_t onionskin
[CELL_PAYLOAD_SIZE
- 4];
35 /** A parsed CREATED, CREATED_FAST, or CREATED2 cell. */
36 typedef struct created_cell_t
{
37 /** The cell command. One of CREATED{,_FAST,2} */
39 /** The number of bytes used in <b>reply</b>. */
40 uint16_t handshake_len
;
41 /** The server-side message for the circuit creation handshake. */
42 uint8_t reply
[CELL_PAYLOAD_SIZE
- 2];
45 /** A parsed RELAY_EXTEND or RELAY_EXTEND2 cell */
46 typedef struct extend_cell_t
{
47 /** One of RELAY_EXTEND or RELAY_EXTEND2 */
49 /** An IPv4 address and port for the node we're connecting to. */
50 tor_addr_port_t orport_ipv4
;
51 /** An IPv6 address and port for the node we're connecting to. Not currently
53 tor_addr_port_t orport_ipv6
;
54 /** Identity fingerprint of the node we're conecting to.*/
55 uint8_t node_id
[DIGEST_LEN
];
56 /** Ed25519 public identity key. Zero if not set. */
57 struct ed25519_public_key_t ed_pubkey
;
58 /** The "create cell" embedded in this extend cell. Note that unlike the
59 * create cells we generate ourself, this once can have a handshake type we
61 create_cell_t create_cell
;
64 /** A parsed RELAY_EXTEND or RELAY_EXTEND2 cell */
65 typedef struct extended_cell_t
{
66 /** One of RELAY_EXTENDED or RELAY_EXTENDED2. */
68 /** The "created cell" embedded in this extended cell. */
69 created_cell_t created_cell
;
72 void create_cell_init(create_cell_t
*cell_out
, uint8_t cell_type
,
73 uint16_t handshake_type
, uint16_t handshake_len
,
74 const uint8_t *onionskin
);
75 int create_cell_parse(create_cell_t
*cell_out
, const cell_t
*cell_in
);
76 int created_cell_parse(created_cell_t
*cell_out
, const cell_t
*cell_in
);
77 int extend_cell_parse(extend_cell_t
*cell_out
, const uint8_t command
,
78 const uint8_t *payload_in
, size_t payload_len
);
79 int extended_cell_parse(extended_cell_t
*cell_out
, const uint8_t command
,
80 const uint8_t *payload_in
, size_t payload_len
);
82 int create_cell_format(cell_t
*cell_out
, const create_cell_t
*cell_in
);
83 int create_cell_format_relayed(cell_t
*cell_out
, const create_cell_t
*cell_in
);
84 int created_cell_format(cell_t
*cell_out
, const created_cell_t
*cell_in
);
85 int extend_cell_format(uint8_t *command_out
, uint16_t *len_out
,
86 uint8_t *payload_out
, const extend_cell_t
*cell_in
);
87 int extended_cell_format(uint8_t *command_out
, uint16_t *len_out
,
88 uint8_t *payload_out
, const extended_cell_t
*cell_in
);
90 #endif /* !defined(TOR_ONION_H) */