I am trying to understand the design of Tor(onion router). I am reading the original paper on the 2nd generation onion routing system. Where, under integrity checking on streams, they say, "When Alice negotiates a key with a new hop, they each initialize a SHA-1 digest with a derivative of that key. Then they each incrementally add to SHA-1 digest the contents of all relay cells they create, and include with each relay cell the first four bytes of the current digest. Each also keeps a SHA-1 digest of data received, to verify that the received hashes are correct."
How does this work?
What I think is happening: I believe, after initializing a new SHA-1 digest, all the contents of new relay cell are XORed with the digest to produce new "digest". And the first 4 bytes from this digest is put in the digest field of the relay cell and sent. Back at Bob(OR), a similar process is repeated and the first 4 bytes of the recently computed "digest" is compared with the one received.
I understand that this helps in preventing an insider attack at modifying the cell contents as the attacker must be able to deduce the current digest state. However, I don't understand the use of calculating SHA-1 of the cell contents at Bob's end and how it helps verify that the received hashes are correct.