diff options
Diffstat (limited to 'src/hello/hello-ng.c')
-rw-r--r-- | src/hello/hello-ng.c | 145 |
1 files changed, 72 insertions, 73 deletions
diff --git a/src/hello/hello-ng.c b/src/hello/hello-ng.c index 29ab17f9b..f44fff032 100644 --- a/src/hello/hello-ng.c +++ b/src/hello/hello-ng.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file hello/hello-ng.c | 22 | * @file hello/hello-ng.c |
@@ -33,8 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * Binary block we sign when we sign an address. | 34 | * Binary block we sign when we sign an address. |
35 | */ | 35 | */ |
36 | struct SignedAddress | 36 | struct SignedAddress { |
37 | { | ||
38 | /** | 37 | /** |
39 | * Purpose must be #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS | 38 | * Purpose must be #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS |
40 | */ | 39 | */ |
@@ -63,7 +62,7 @@ struct SignedAddress | |||
63 | * @param result_size[out] set to size of @a result | 62 | * @param result_size[out] set to size of @a result |
64 | */ | 63 | */ |
65 | void | 64 | void |
66 | GNUNET_HELLO_sign_address ( | 65 | GNUNET_HELLO_sign_address( |
67 | const char *address, | 66 | const char *address, |
68 | enum GNUNET_NetworkType nt, | 67 | enum GNUNET_NetworkType nt, |
69 | struct GNUNET_TIME_Absolute mono_time, | 68 | struct GNUNET_TIME_Absolute mono_time, |
@@ -75,22 +74,22 @@ GNUNET_HELLO_sign_address ( | |||
75 | struct GNUNET_CRYPTO_EddsaSignature sig; | 74 | struct GNUNET_CRYPTO_EddsaSignature sig; |
76 | char *sig_str; | 75 | char *sig_str; |
77 | 76 | ||
78 | sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); | 77 | sa.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); |
79 | sa.purpose.size = htonl (sizeof (sa)); | 78 | sa.purpose.size = htonl(sizeof(sa)); |
80 | sa.mono_time = GNUNET_TIME_absolute_hton (mono_time); | 79 | sa.mono_time = GNUNET_TIME_absolute_hton(mono_time); |
81 | GNUNET_CRYPTO_hash (address, strlen (address), &sa.h_addr); | 80 | GNUNET_CRYPTO_hash(address, strlen(address), &sa.h_addr); |
82 | GNUNET_assert (GNUNET_YES == | 81 | GNUNET_assert(GNUNET_YES == |
83 | GNUNET_CRYPTO_eddsa_sign (private_key, &sa.purpose, &sig)); | 82 | GNUNET_CRYPTO_eddsa_sign(private_key, &sa.purpose, &sig)); |
84 | sig_str = NULL; | 83 | sig_str = NULL; |
85 | (void) GNUNET_STRINGS_base64_encode (&sig, sizeof (sig), &sig_str); | 84 | (void)GNUNET_STRINGS_base64_encode(&sig, sizeof(sig), &sig_str); |
86 | *result_size = | 85 | *result_size = |
87 | 1 + GNUNET_asprintf ((char **) result, | 86 | 1 + GNUNET_asprintf((char **)result, |
88 | "%s;%llu;%u;%s", | 87 | "%s;%llu;%u;%s", |
89 | sig_str, | 88 | sig_str, |
90 | (unsigned long long) mono_time.abs_value_us, | 89 | (unsigned long long)mono_time.abs_value_us, |
91 | (unsigned int) nt, | 90 | (unsigned int)nt, |
92 | address); | 91 | address); |
93 | GNUNET_free (sig_str); | 92 | GNUNET_free(sig_str); |
94 | } | 93 | } |
95 | 94 | ||
96 | 95 | ||
@@ -105,11 +104,11 @@ GNUNET_HELLO_sign_address ( | |||
105 | * @return NULL on error, otherwise the address | 104 | * @return NULL on error, otherwise the address |
106 | */ | 105 | */ |
107 | char * | 106 | char * |
108 | GNUNET_HELLO_extract_address (const void *raw, | 107 | GNUNET_HELLO_extract_address(const void *raw, |
109 | size_t raw_size, | 108 | size_t raw_size, |
110 | const struct GNUNET_PeerIdentity *pid, | 109 | const struct GNUNET_PeerIdentity *pid, |
111 | enum GNUNET_NetworkType *nt, | 110 | enum GNUNET_NetworkType *nt, |
112 | struct GNUNET_TIME_Absolute *mono_time) | 111 | struct GNUNET_TIME_Absolute *mono_time) |
113 | { | 112 | { |
114 | const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key; | 113 | const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key; |
115 | const char *raws = raw; | 114 | const char *raws = raw; |
@@ -124,59 +123,59 @@ GNUNET_HELLO_extract_address (const void *raw, | |||
124 | struct GNUNET_CRYPTO_EddsaSignature *sig; | 123 | struct GNUNET_CRYPTO_EddsaSignature *sig; |
125 | 124 | ||
126 | if ('\0' != raws[raw_size]) | 125 | if ('\0' != raws[raw_size]) |
127 | { | 126 | { |
128 | GNUNET_break_op (0); | 127 | GNUNET_break_op(0); |
129 | return NULL; | 128 | return NULL; |
130 | } | 129 | } |
131 | if (NULL == (sc = strchr (raws, ';'))) | 130 | if (NULL == (sc = strchr(raws, ';'))) |
132 | { | 131 | { |
133 | GNUNET_break_op (0); | 132 | GNUNET_break_op(0); |
134 | return NULL; | 133 | return NULL; |
135 | } | 134 | } |
136 | if (NULL == (sc2 = strchr (sc + 1, ';'))) | 135 | if (NULL == (sc2 = strchr(sc + 1, ';'))) |
137 | { | 136 | { |
138 | GNUNET_break_op (0); | 137 | GNUNET_break_op(0); |
139 | return NULL; | 138 | return NULL; |
140 | } | 139 | } |
141 | if (NULL == (sc3 = strchr (sc2 + 1, ';'))) | 140 | if (NULL == (sc3 = strchr(sc2 + 1, ';'))) |
142 | { | 141 | { |
143 | GNUNET_break_op (0); | 142 | GNUNET_break_op(0); |
144 | return NULL; | 143 | return NULL; |
145 | } | 144 | } |
146 | if (1 != sscanf (sc + 1, "%llu;%u;", &raw_us, &raw_nt)) | 145 | if (1 != sscanf(sc + 1, "%llu;%u;", &raw_us, &raw_nt)) |
147 | { | 146 | { |
148 | GNUNET_break_op (0); | 147 | GNUNET_break_op(0); |
149 | return NULL; | 148 | return NULL; |
150 | } | 149 | } |
151 | raw_mono_time.abs_value_us = raw_us; | 150 | raw_mono_time.abs_value_us = raw_us; |
152 | sig = NULL; | 151 | sig = NULL; |
153 | if (sizeof (struct GNUNET_CRYPTO_EddsaSignature) != | 152 | if (sizeof(struct GNUNET_CRYPTO_EddsaSignature) != |
154 | GNUNET_STRINGS_base64_decode (raws, sc - raws, (void **) &sig)) | 153 | GNUNET_STRINGS_base64_decode(raws, sc - raws, (void **)&sig)) |
155 | { | 154 | { |
156 | GNUNET_break_op (0); | 155 | GNUNET_break_op(0); |
157 | GNUNET_free_non_null (sig); | 156 | GNUNET_free_non_null(sig); |
158 | return NULL; | 157 | return NULL; |
159 | } | 158 | } |
160 | raw_addr = sc3 + 1; | 159 | raw_addr = sc3 + 1; |
161 | 160 | ||
162 | sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); | 161 | sa.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); |
163 | sa.purpose.size = htonl (sizeof (sa)); | 162 | sa.purpose.size = htonl(sizeof(sa)); |
164 | sa.mono_time = GNUNET_TIME_absolute_hton (raw_mono_time); | 163 | sa.mono_time = GNUNET_TIME_absolute_hton(raw_mono_time); |
165 | GNUNET_CRYPTO_hash (raw_addr, strlen (raw_addr), &sa.h_addr); | 164 | GNUNET_CRYPTO_hash(raw_addr, strlen(raw_addr), &sa.h_addr); |
166 | if (GNUNET_YES != | 165 | if (GNUNET_YES != |
167 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, | 166 | GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, |
168 | &sa.purpose, | 167 | &sa.purpose, |
169 | sig, | 168 | sig, |
170 | public_key)) | 169 | public_key)) |
171 | { | 170 | { |
172 | GNUNET_break_op (0); | 171 | GNUNET_break_op(0); |
173 | GNUNET_free (sig); | 172 | GNUNET_free(sig); |
174 | return NULL; | 173 | return NULL; |
175 | } | 174 | } |
176 | GNUNET_free (sig); | 175 | GNUNET_free(sig); |
177 | *mono_time = raw_mono_time; | 176 | *mono_time = raw_mono_time; |
178 | *nt = (enum GNUNET_NetworkType) raw_nt; | 177 | *nt = (enum GNUNET_NetworkType)raw_nt; |
179 | return GNUNET_strdup (raw_addr); | 178 | return GNUNET_strdup(raw_addr); |
180 | } | 179 | } |
181 | 180 | ||
182 | 181 | ||
@@ -188,12 +187,12 @@ GNUNET_HELLO_extract_address (const void *raw, | |||
188 | * @return NULL if the address is mal-formed, otherwise the prefix | 187 | * @return NULL if the address is mal-formed, otherwise the prefix |
189 | */ | 188 | */ |
190 | char * | 189 | char * |
191 | GNUNET_HELLO_address_to_prefix (const char *address) | 190 | GNUNET_HELLO_address_to_prefix(const char *address) |
192 | { | 191 | { |
193 | const char *dash; | 192 | const char *dash; |
194 | 193 | ||
195 | dash = strchr (address, '-'); | 194 | dash = strchr(address, '-'); |
196 | if (NULL == dash) | 195 | if (NULL == dash) |
197 | return NULL; | 196 | return NULL; |
198 | return GNUNET_strndup (address, dash - address); | 197 | return GNUNET_strndup(address, dash - address); |
199 | } | 198 | } |