onion_crypto.h (2965B)
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-2021, The Tor Project, Inc. */ 5 /* See LICENSE for licensing information */ 6 7 /** 8 * \file onion_crypto.h 9 * \brief Header file for onion_crypto.c. 10 **/ 11 12 #ifndef TOR_ONION_CRYPTO_H 13 #define TOR_ONION_CRYPTO_H 14 15 #include "lib/crypt_ops/crypto_ed25519.h" 16 #include "core/crypto/relay_crypto.h" 17 18 typedef struct server_onion_keys_t { 19 uint8_t my_identity[DIGEST_LEN]; 20 ed25519_public_key_t my_ed_identity; 21 crypto_pk_t *onion_key; 22 crypto_pk_t *last_onion_key; 23 struct di_digest256_map_t *curve25519_key_map; 24 struct curve25519_keypair_t *junk_keypair; 25 } server_onion_keys_t; 26 27 void onion_handshake_state_release(onion_handshake_state_t *state); 28 29 /** 30 * Parameters negotiated as part of a circuit handshake. 31 */ 32 typedef struct circuit_params_t { 33 /** Is true if congestion control is enabled in consensus or param, 34 * as per congestion_control_enabled() result. */ 35 bool cc_enabled; 36 /** The number of cells in a sendme increment. Only used if cc_enabled=1. */ 37 uint8_t sendme_inc_cells; 38 39 /** Which algorithm did we negotiate? */ 40 relay_crypto_alg_t crypto_alg; 41 /** Which cell format did we negotiate? */ 42 relay_cell_fmt_t cell_fmt; 43 } circuit_params_t; 44 45 int onion_skin_create(int type, 46 const extend_info_t *node, 47 onion_handshake_state_t *state_out, 48 uint8_t *onion_skin_out, 49 size_t onion_skin_out_maxlen); 50 int onion_skin_server_handshake(int type, 51 const uint8_t *onion_skin, size_t onionskin_len, 52 const server_onion_keys_t *keys, 53 const circuit_params_t *ns_params, 54 uint8_t *reply_out, 55 size_t reply_out_maxlen, 56 uint8_t *keys_out, size_t *keys_len_out, 57 uint8_t *rend_nonce_out, 58 circuit_params_t *negotiated_params_out); 59 int onion_skin_client_handshake(int type, 60 const onion_handshake_state_t *handshake_state, 61 const uint8_t *reply, size_t reply_len, 62 uint8_t *keys_out, size_t *keys_out_len, 63 uint8_t *rend_authenticator_out, 64 circuit_params_t *negotiated_params_out, 65 const char **msg_out); 66 67 server_onion_keys_t *server_onion_keys_new(void); 68 void server_onion_keys_free_(server_onion_keys_t *keys); 69 #define server_onion_keys_free(keys) \ 70 FREE_AND_NULL(server_onion_keys_t, server_onion_keys_free_, (keys)) 71 72 struct trn_extension_st; 73 struct trn_extension_field_st; 74 const struct trn_extension_field_st *trn_extension_find( 75 const struct trn_extension_st *ext, 76 uint8_t ext_type); 77 78 #endif /* !defined(TOR_ONION_CRYPTO_H) */