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

Function generate_header_padding

common/sphinx.c:287–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287static void generate_header_padding(void *dst, size_t dstlen,
288 size_t fixed_size,
289 const struct sphinx_path *path,
290 struct hop_params *params)
291{
292 struct secret key;
293 size_t fillerStart, fillerEnd, fillerSize;
294
295 memset(dst, 0, dstlen);
296 for (int i = 0; i < tal_count(path->hops) - 1; i++) {
297 subkey_from_hmac("rho", &params[i].secret, &key);
298
299 /* Sum up how many bytes have been used by previous hops,
300 * that gives us the start in the stream */
301 fillerSize = 0;
302 for (int j = 0; j < i; j++)
303 fillerSize += sphinx_hop_size(&path->hops[j]);
304 fillerStart = fixed_size - fillerSize;
305
306 /* The filler will dangle off of the end by the current
307 * hop-size, we'll make sure to copy it into the correct
308 * position in the next step. */
309 fillerEnd = fixed_size + sphinx_hop_size(&path->hops[i]);
310
311 /* Apply the cipher-stream to the part of the filler that'll
312 * be added by this hop */
313 xor_cipher_stream_off(&key, fillerStart,
314 dst, fillerEnd - fillerStart);
315 }
316}
317
318static void generate_prefill(void *dst, size_t dstlen,
319 size_t fixed_size,

Callers 1

create_onionpacketFunction · 0.85

Calls 3

sphinx_hop_sizeFunction · 0.85
xor_cipher_stream_offFunction · 0.85
subkey_from_hmacFunction · 0.70

Tested by

no test coverage detected