onion_ntor.h 2.4 KB

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