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

Function parse_onionpacket

common/sphinx.c:196–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196struct onionpacket *parse_onionpacket(const tal_t *ctx,
197 const u8 *src,
198 const size_t srclen,
199 enum onion_wire *failcode)
200{
201 struct onionpacket *dest = tal(ctx, struct onionpacket);
202 const u8 *cursor = src;
203 size_t max = srclen;
204
205 dest->version = fromwire_u8(&cursor, &max);
206 if (dest->version != 0x00) {
207 // FIXME add logging
208 *failcode = WIRE_INVALID_ONION_VERSION;
209 return tal_free(dest);
210 }
211
212 fromwire_pubkey(&cursor, &max, &dest->ephemeralkey);
213 if (cursor == NULL) {
214 *failcode = WIRE_INVALID_ONION_KEY;
215 return tal_free(dest);
216 }
217
218 /* If max underflows, this returns NULL and fromwire fails. */
219 dest->routinginfo = fromwire_tal_arrn(dest, &cursor, &max,
220 max - HMAC_SIZE);
221 fromwire_hmac(&cursor, &max, &dest->hmac);
222
223 assert(max == 0);
224 if (cursor == NULL) {
225 *failcode = WIRE_INVALID_ONION_HMAC;
226 return tal_free(dest);
227 }
228
229 return dest;
230}
231
232/*
233 * Generate a pseudo-random byte stream of length `dstlen` from key `k` and

Callers 10

json_sendonionFunction · 0.85
json_injectpaymentonionFunction · 0.85
peer_accepted_htlcFunction · 0.85
channel_added_their_htlcFunction · 0.85
decode_onionFunction · 0.85
onion_message_parseFunction · 0.85
next_onionFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
decode_with_privkeyFunction · 0.85

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 3

next_onionFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68