Failure Packet
An onion-encrypted failure packet from an intermediate node: +----------------+----------------------------------+-----------------+----------------------+-----+ | HMAC(32 bytes) | failure message length (2 bytes) | failure message | pad length (2 bytes) | pad | +----------------+----------------------------------+-----------------+----------------------+-----+ with failure message length + pad length = 256
Functions
Create a failure packet that will be returned to the sender. Each intermediate hop will add a layer of encryption and forward to the previous hop. Note that malicious intermediate hops may drop the packet or alter it (which breaks the mac).
Decrypt a failure packet. Node shared secrets are applied until the packet's MAC becomes valid, which means that it was sent by the corresponding node. Note that malicious nodes in the route may have altered the packet, triggering a decryption failure.