onion_ntor.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright (c) 2012-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef TOR_ONION_NTOR_H
  4. #define TOR_ONION_NTOR_H
  5. #include "torint.h"
  6. #include "crypto_curve25519.h"
  7. #include "di_ops.h"
  8. /** State to be maintained by a client between sending an ntor onionskin
  9. * and receiving a reply. */
  10. typedef struct ntor_handshake_state_t ntor_handshake_state_t;
  11. /** Length of an ntor onionskin, as sent from the client to server. */
  12. #define NTOR_ONIONSKIN_LEN 84
  13. /** Length of an ntor reply, as sent from server to client. */
  14. #define NTOR_REPLY_LEN 64
  15. void ntor_handshake_state_free_(ntor_handshake_state_t *state);
  16. #define ntor_handshake_state_free(state) \
  17. FREE_AND_NULL(ntor_handshake_state_t, ntor_handshake_state_free_, (state))
  18. int onion_skin_ntor_create(const uint8_t *router_id,
  19. const curve25519_public_key_t *router_key,
  20. ntor_handshake_state_t **handshake_state_out,
  21. uint8_t *onion_skin_out);
  22. int onion_skin_ntor_server_handshake(const uint8_t *onion_skin,
  23. const di_digest256_map_t *private_keys,
  24. const curve25519_keypair_t *junk_keypair,
  25. const uint8_t *my_node_id,
  26. uint8_t *handshake_reply_out,
  27. uint8_t *key_out,
  28. size_t key_out_len);
  29. int onion_skin_ntor_client_handshake(
  30. const ntor_handshake_state_t *handshake_state,
  31. const uint8_t *handshake_reply,
  32. uint8_t *key_out,
  33. size_t key_out_len,
  34. const char **msg_out);
  35. #ifdef ONION_NTOR_PRIVATE
  36. /** Storage held by a client while waiting for an ntor reply from a server. */
  37. struct ntor_handshake_state_t {
  38. /** Identity digest of the router we're talking to. */
  39. uint8_t router_id[DIGEST_LEN];
  40. /** Onion key of the router we're talking to. */
  41. curve25519_public_key_t pubkey_B;
  42. /**
  43. * Short-lived keypair for use with this handshake.
  44. * @{ */
  45. curve25519_secret_key_t seckey_x;
  46. curve25519_public_key_t pubkey_X;
  47. /** @} */
  48. };
  49. #endif /* defined(ONION_NTOR_PRIVATE) */
  50. #endif /* !defined(TOR_ONION_NTOR_H) */