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