| 804 | } |
| 805 | |
| 806 | struct onionreply *wrap_onionreply(const tal_t *ctx, |
| 807 | const struct secret *shared_secret, |
| 808 | const struct onionreply *reply) |
| 809 | { |
| 810 | struct secret key; |
| 811 | struct onionreply *result = tal(ctx, struct onionreply); |
| 812 | |
| 813 | /* BOLT #4: |
| 814 | * |
| 815 | * The erring node then generates a new key, using the key type `ammag`. |
| 816 | * This key is then used to generate a pseudo-random stream, which is |
| 817 | * in turn applied to the packet using `XOR`. |
| 818 | */ |
| 819 | subkey_from_hmac("ammag", shared_secret, &key); |
| 820 | result->contents = tal_dup_talarr(result, u8, reply->contents); |
| 821 | xor_cipher_stream(result->contents, &key, tal_bytelen(result->contents)); |
| 822 | return result; |
| 823 | } |
| 824 | |
| 825 | u8 *unwrap_onionreply(const tal_t *ctx, |
| 826 | const struct secret *shared_secrets, |