onion.h 3.5 KB

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