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