| 398 | } |
| 399 | |
| 400 | static struct hop_params *generate_hop_params( |
| 401 | const tal_t *ctx, |
| 402 | const u8 *sessionkey, |
| 403 | struct sphinx_path *path) |
| 404 | { |
| 405 | int i, j, num_hops = tal_count(path->hops); |
| 406 | struct pubkey temp; |
| 407 | u8 blind[BLINDING_FACTOR_SIZE]; |
| 408 | struct hop_params *params = tal_arr(ctx, struct hop_params, num_hops); |
| 409 | |
| 410 | /* Initialize the first hop with the raw information */ |
| 411 | if (secp256k1_ec_pubkey_create(secp256k1_ctx, |
| 412 | ¶ms[0].ephemeralkey.pubkey, |
| 413 | path->session_key->data) != 1) |
| 414 | return NULL; |
| 415 | |
| 416 | if (!sphinx_create_shared_secret( |
| 417 | ¶ms[0].secret, &path->hops[0].pubkey, path->session_key)) |
| 418 | return NULL; |
| 419 | |
| 420 | compute_blinding_factor( |
| 421 | ¶ms[0].ephemeralkey, ¶ms[0].secret, |
| 422 | params[0].blind); |
| 423 | |
| 424 | /* Recursively compute all following ephemeral public keys, |
| 425 | * secrets and blinding factors |
| 426 | */ |
| 427 | for (i = 1; i < num_hops; i++) { |
| 428 | if (!blind_group_element( |
| 429 | ¶ms[i].ephemeralkey, |
| 430 | ¶ms[i - 1].ephemeralkey, |
| 431 | params[i - 1].blind)) |
| 432 | return NULL; |
| 433 | |
| 434 | /* Blind this hop's point with all previous blinding factors |
| 435 | * Order is indifferent, multiplication is commutative. |
| 436 | */ |
| 437 | memcpy(&blind, sessionkey, 32); |
| 438 | temp = path->hops[i].pubkey; |
| 439 | if (!blind_group_element(&temp, &temp, blind)) |
| 440 | return NULL; |
| 441 | for (j = 0; j < i; j++) |
| 442 | if (!blind_group_element( |
| 443 | &temp, |
| 444 | &temp, |
| 445 | params[j].blind)) |
| 446 | return NULL; |
| 447 | |
| 448 | /* Now hash temp and store it. This requires us to |
| 449 | * DER-serialize first and then skip the sign byte. |
| 450 | */ |
| 451 | u8 der[PUBKEY_CMPR_LEN]; |
| 452 | pubkey_to_der(der, &temp); |
| 453 | struct sha256 h; |
| 454 | sha256(&h, der, sizeof(der)); |
| 455 | memcpy(¶ms[i].secret, &h, sizeof(h)); |
| 456 | |
| 457 | compute_blinding_factor( |
no test coverage detected