1 /* Copyright (c) 2017, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 * \brief Contains circuit and connection identifier code for the whole HS
12 /* Return a newly allocated circuit identifier. The given public key is copied
13 * identity_pk into the identifier. */
15 hs_ident_circuit_new(const ed25519_public_key_t
*identity_pk
,
16 hs_ident_circuit_type_t circuit_type
)
18 tor_assert(circuit_type
== HS_IDENT_CIRCUIT_INTRO
||
19 circuit_type
== HS_IDENT_CIRCUIT_RENDEZVOUS
);
20 hs_ident_circuit_t
*ident
= tor_malloc_zero(sizeof(*ident
));
21 ed25519_pubkey_copy(&ident
->identity_pk
, identity_pk
);
22 ident
->circuit_type
= circuit_type
;
26 /* Free the given circuit identifier. */
28 hs_ident_circuit_free(hs_ident_circuit_t
*ident
)
33 memwipe(ident
, 0, sizeof(hs_ident_circuit_t
));
37 /* For a given circuit identifier src, return a newly allocated copy of it.
40 hs_ident_circuit_dup(const hs_ident_circuit_t
*src
)
42 hs_ident_circuit_t
*ident
= tor_malloc_zero(sizeof(*ident
));
43 memcpy(ident
, src
, sizeof(*ident
));
47 /* For a given directory connection identifier src, return a newly allocated
48 * copy of it. This can't fail. */
50 hs_ident_dir_conn_dup(const hs_ident_dir_conn_t
*src
)
52 hs_ident_dir_conn_t
*ident
= tor_malloc_zero(sizeof(*ident
));
53 memcpy(ident
, src
, sizeof(*ident
));
57 /* Free the given directory connection identifier. */
59 hs_ident_dir_conn_free(hs_ident_dir_conn_t
*ident
)
64 memwipe(ident
, 0, sizeof(hs_ident_dir_conn_t
));
68 /* Initialized the allocated ident object with identity_pk and blinded_pk.
69 * None of them can be NULL since a valid directory connection identifier must
70 * have all fields set. */
72 hs_ident_dir_conn_init(const ed25519_public_key_t
*identity_pk
,
73 const ed25519_public_key_t
*blinded_pk
,
74 hs_ident_dir_conn_t
*ident
)
76 tor_assert(identity_pk
);
77 tor_assert(blinded_pk
);
80 ed25519_pubkey_copy(&ident
->identity_pk
, identity_pk
);
81 ed25519_pubkey_copy(&ident
->blinded_pk
, blinded_pk
);
84 /* Return a newly allocated edge connection identifier. The given public key
85 * identity_pk is copied into the identifier. */
86 hs_ident_edge_conn_t
*
87 hs_ident_edge_conn_new(const ed25519_public_key_t
*identity_pk
)
89 hs_ident_edge_conn_t
*ident
= tor_malloc_zero(sizeof(*ident
));
90 ed25519_pubkey_copy(&ident
->identity_pk
, identity_pk
);
94 /* Free the given edge connection identifier. */
96 hs_ident_edge_conn_free(hs_ident_edge_conn_t
*ident
)
101 memwipe(ident
, 0, sizeof(hs_ident_edge_conn_t
));
105 /* Return true if the given ident is valid for an introduction circuit. */
107 hs_ident_intro_circ_is_valid(const hs_ident_circuit_t
*ident
)
113 if (ed25519_public_key_is_zero(&ident
->identity_pk
)) {
117 if (ed25519_public_key_is_zero(&ident
->intro_auth_pk
)) {