1 /* Copyright (c) 2017-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 * \brief Contains circuit and connection identifier code for the whole HS
10 #include "lib/crypt_ops/crypto_util.h"
11 #include "feature/hs/hs_ident.h"
13 /** Return a newly allocated circuit identifier. The given public key is copied
14 * identity_pk into the identifier. */
16 hs_ident_circuit_new(const ed25519_public_key_t
*identity_pk
)
18 hs_ident_circuit_t
*ident
= tor_malloc_zero(sizeof(*ident
));
19 ed25519_pubkey_copy(&ident
->identity_pk
, identity_pk
);
23 /** Free the given circuit identifier. */
25 hs_ident_circuit_free_(hs_ident_circuit_t
*ident
)
30 memwipe(ident
, 0, sizeof(hs_ident_circuit_t
));
34 /** For a given circuit identifier src, return a newly allocated copy of it.
37 hs_ident_circuit_dup(const hs_ident_circuit_t
*src
)
39 hs_ident_circuit_t
*ident
= tor_malloc_zero(sizeof(*ident
));
40 memcpy(ident
, src
, sizeof(*ident
));
44 /** For a given directory connection identifier src, return a newly allocated
45 * copy of it. This can't fail. */
47 hs_ident_dir_conn_dup(const hs_ident_dir_conn_t
*src
)
49 hs_ident_dir_conn_t
*ident
= tor_malloc_zero(sizeof(*ident
));
50 memcpy(ident
, src
, sizeof(*ident
));
54 /** Free the given directory connection identifier. */
56 hs_ident_dir_conn_free_(hs_ident_dir_conn_t
*ident
)
61 memwipe(ident
, 0, sizeof(hs_ident_dir_conn_t
));
65 /** Initialized the allocated ident object with identity_pk and blinded_pk.
66 * None of them can be NULL since a valid directory connection identifier must
67 * have all fields set. */
69 hs_ident_dir_conn_init(const ed25519_public_key_t
*identity_pk
,
70 const ed25519_public_key_t
*blinded_pk
,
71 hs_ident_dir_conn_t
*ident
)
73 tor_assert(identity_pk
);
74 tor_assert(blinded_pk
);
77 ed25519_pubkey_copy(&ident
->identity_pk
, identity_pk
);
78 ed25519_pubkey_copy(&ident
->blinded_pk
, blinded_pk
);
81 /** Return a newly allocated edge connection identifier. The given public key
82 * identity_pk is copied into the identifier. */
83 hs_ident_edge_conn_t
*
84 hs_ident_edge_conn_new(const ed25519_public_key_t
*identity_pk
)
86 hs_ident_edge_conn_t
*ident
= tor_malloc_zero(sizeof(*ident
));
87 ed25519_pubkey_copy(&ident
->identity_pk
, identity_pk
);
91 /** Free the given edge connection identifier. */
93 hs_ident_edge_conn_free_(hs_ident_edge_conn_t
*ident
)
98 memwipe(ident
, 0, sizeof(hs_ident_edge_conn_t
));
102 /** Return true if the given ident is valid for an introduction circuit. */
104 hs_ident_intro_circ_is_valid(const hs_ident_circuit_t
*ident
)
110 if (ed25519_public_key_is_zero(&ident
->identity_pk
)) {
114 if (ed25519_public_key_is_zero(&ident
->intro_auth_pk
)) {