| 830 | } |
| 831 | |
| 832 | struct onionreply *wrap_onionreply(const tal_t *ctx, |
| 833 | const struct secret *shared_secret, |
| 834 | const struct onionreply *reply) |
| 835 | { |
| 836 | struct secret key; |
| 837 | struct onionreply *result = tal(ctx, struct onionreply); |
| 838 | |
| 839 | /* BOLT #4: |
| 840 | * |
| 841 | * The erring node then generates a new key, using the key type `ammag`. |
| 842 | * This key is then used to generate a pseudo-random stream, which is |
| 843 | * in turn applied to the packet using `XOR`. |
| 844 | */ |
| 845 | subkey_from_hmac("ammag", shared_secret, &key); |
| 846 | result->contents = tal_dup_talarr(result, u8, reply->contents); |
| 847 | xor_cipher_stream(result->contents, &key, tal_bytelen(result->contents)); |
| 848 | return result; |
| 849 | } |
| 850 | |
| 851 | u8 *unwrap_onionreply(const tal_t *ctx, |
| 852 | const struct secret *shared_secrets, |