MCPcopy Create free account
hub / github.com/ElementsProject/lightning / parse_onionpacket

Function parse_onionpacket

common/sphinx.c:168–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168struct onionpacket *parse_onionpacket(const tal_t *ctx,
169 const u8 *src,
170 const size_t srclen,
171 enum onion_wire *failcode)
172{
173 struct onionpacket *dest = tal(ctx, struct onionpacket);
174 const u8 *cursor = src;
175 size_t max = srclen;
176
177 dest->version = fromwire_u8(&cursor, &max);
178 if (dest->version != 0x00) {
179 // FIXME add logging
180 *failcode = WIRE_INVALID_ONION_VERSION;
181 return tal_free(dest);
182 }
183
184 fromwire_pubkey(&cursor, &max, &dest->ephemeralkey);
185 if (cursor == NULL) {
186 *failcode = WIRE_INVALID_ONION_KEY;
187 return tal_free(dest);
188 }
189
190 /* If max underflows, this returns NULL and fromwire fails. */
191 dest->routinginfo = fromwire_tal_arrn(dest, &cursor, &max,
192 max - HMAC_SIZE);
193 fromwire_hmac(&cursor, &max, &dest->hmac);
194
195 assert(max == 0);
196 if (cursor == NULL) {
197 *failcode = WIRE_INVALID_REALM;
198 return tal_free(dest);
199 }
200
201 return dest;
202}
203
204/*
205 * Generate a pseudo-random byte stream of length `dstlen` from key `k` and

Callers 7

handle_onion_messageFunction · 0.50
json_sendonionFunction · 0.50
peer_accepted_htlcFunction · 0.50
channel_added_their_htlcFunction · 0.50
next_onionFunction · 0.50
mainFunction · 0.50
decode_with_privkeyFunction · 0.50

Calls 5

tal_freeFunction · 0.85
fromwire_pubkeyFunction · 0.85
fromwire_hmacFunction · 0.70
fromwire_u8Function · 0.50
fromwire_tal_arrnFunction · 0.50

Tested by 2

next_onionFunction · 0.40
mainFunction · 0.40