| 736 | } |
| 737 | |
| 738 | struct onionreply *wrap_onionreply(const tal_t *ctx, |
| 739 | const struct secret *shared_secret, |
| 740 | const struct onionreply *reply) |
| 741 | { |
| 742 | struct secret key; |
| 743 | struct onionreply *result = tal(ctx, struct onionreply); |
| 744 | |
| 745 | /* BOLT #4: |
| 746 | * |
| 747 | * The erring node then generates a new key, using the key type `ammag`. |
| 748 | * This key is then used to generate a pseudo-random stream, which is |
| 749 | * in turn applied to the packet using `XOR`. |
| 750 | * |
| 751 | * The obfuscation step is repeated by every hop along the return path. |
| 752 | */ |
| 753 | subkey_from_hmac("ammag", shared_secret, &key); |
| 754 | result->contents = tal_dup_talarr(result, u8, reply->contents); |
| 755 | xor_cipher_stream(result->contents, &key, tal_bytelen(result->contents)); |
| 756 | return result; |
| 757 | } |
| 758 | |
| 759 | u8 *unwrap_onionreply(const tal_t *ctx, |
| 760 | const struct secret *shared_secrets, |