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