Tor  0.4.7.0-alpha-dev
hs_ident.c
Go to the documentation of this file.
1 /* Copyright (c) 2017-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * \file hs_ident.c
6  * \brief Contains circuit and connection identifier code for the whole HS
7  * subsystem.
8  **/
9 
11 #include "feature/hs/hs_ident.h"
12 
13 /** Return a newly allocated circuit identifier. The given public key is copied
14  * identity_pk into the identifier. */
17 {
18  hs_ident_circuit_t *ident = tor_malloc_zero(sizeof(*ident));
19  ed25519_pubkey_copy(&ident->identity_pk, identity_pk);
20  return ident;
21 }
22 
23 /** Free the given circuit identifier. */
24 void
26 {
27  if (ident == NULL) {
28  return;
29  }
30  memwipe(ident, 0, sizeof(hs_ident_circuit_t));
31  tor_free(ident);
32 }
33 
34 /** For a given circuit identifier src, return a newly allocated copy of it.
35  * This can't fail. */
38 {
39  hs_ident_circuit_t *ident = tor_malloc_zero(sizeof(*ident));
40  memcpy(ident, src, sizeof(*ident));
41  return ident;
42 }
43 
44 /** For a given directory connection identifier src, return a newly allocated
45  * copy of it. This can't fail. */
48 {
49  hs_ident_dir_conn_t *ident = tor_malloc_zero(sizeof(*ident));
50  memcpy(ident, src, sizeof(*ident));
51  return ident;
52 }
53 
54 /** Free the given directory connection identifier. */
55 void
57 {
58  if (ident == NULL) {
59  return;
60  }
61  memwipe(ident, 0, sizeof(hs_ident_dir_conn_t));
62  tor_free(ident);
63 }
64 
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. */
68 void
70  const ed25519_public_key_t *blinded_pk,
71  hs_ident_dir_conn_t *ident)
72 {
73  tor_assert(identity_pk);
74  tor_assert(blinded_pk);
75  tor_assert(ident);
76 
77  ed25519_pubkey_copy(&ident->identity_pk, identity_pk);
78  ed25519_pubkey_copy(&ident->blinded_pk, blinded_pk);
79 }
80 
81 /** Return a newly allocated edge connection identifier. The given public key
82  * identity_pk is copied into the identifier. */
85 {
86  hs_ident_edge_conn_t *ident = tor_malloc_zero(sizeof(*ident));
87  ed25519_pubkey_copy(&ident->identity_pk, identity_pk);
88  return ident;
89 }
90 
91 /** Free the given edge connection identifier. */
92 void
94 {
95  if (ident == NULL) {
96  return;
97  }
98  memwipe(ident, 0, sizeof(hs_ident_edge_conn_t));
99  tor_free(ident);
100 }
101 
102 /** Return true if the given ident is valid for an introduction circuit. */
103 int
105 {
106  if (ident == NULL) {
107  goto invalid;
108  }
109 
111  goto invalid;
112  }
113 
115  goto invalid;
116  }
117 
118  /* Valid. */
119  return 1;
120  invalid:
121  return 0;
122 }
void ed25519_pubkey_copy(ed25519_public_key_t *dest, const ed25519_public_key_t *src)
int ed25519_public_key_is_zero(const ed25519_public_key_t *pubkey)
void memwipe(void *mem, uint8_t byte, size_t sz)
Definition: crypto_util.c:55
Common functions for cryptographic routines.
void hs_ident_edge_conn_free_(hs_ident_edge_conn_t *ident)
Definition: hs_ident.c:93
void hs_ident_dir_conn_free_(hs_ident_dir_conn_t *ident)
Definition: hs_ident.c:56
hs_ident_circuit_t * hs_ident_circuit_dup(const hs_ident_circuit_t *src)
Definition: hs_ident.c:37
hs_ident_dir_conn_t * hs_ident_dir_conn_dup(const hs_ident_dir_conn_t *src)
Definition: hs_ident.c:47
void hs_ident_circuit_free_(hs_ident_circuit_t *ident)
Definition: hs_ident.c:25
hs_ident_edge_conn_t * hs_ident_edge_conn_new(const ed25519_public_key_t *identity_pk)
Definition: hs_ident.c:84
void hs_ident_dir_conn_init(const ed25519_public_key_t *identity_pk, const ed25519_public_key_t *blinded_pk, hs_ident_dir_conn_t *ident)
Definition: hs_ident.c:69
hs_ident_circuit_t * hs_ident_circuit_new(const ed25519_public_key_t *identity_pk)
Definition: hs_ident.c:16
int hs_ident_intro_circ_is_valid(const hs_ident_circuit_t *ident)
Definition: hs_ident.c:104
Header file containing circuit and connection identifier data for the whole HS subsystem.
#define tor_free(p)
Definition: malloc.h:52
ed25519_public_key_t intro_auth_pk
Definition: hs_ident.h:51
ed25519_public_key_t identity_pk
Definition: hs_ident.h:45
ed25519_public_key_t blinded_pk
Definition: hs_ident.h:95
ed25519_public_key_t identity_pk
Definition: hs_ident.h:90
ed25519_public_key_t identity_pk
Definition: hs_ident.h:106
#define tor_assert(expr)
Definition: util_bug.h:102