Yes, the MAC algorithm works the same way on both sides. It is a mathematical function that computes the tag from the key and the message. On the sender side, the message is processed as follows:
- Calculate T = MAC(key, raw_message).
- Send the raw_message and the tag value T. Many communication protocols append them in this order but anything will do as long as the receiver agrees on the format.
On the receiver side, the processing goes as follows:
- Parse the received data is parsed as a raw message and a tag value.
- Calculate T' = MAC(key, received_raw_message).
- Compare T' with received_T. If the values are equal then the message is authentic, otherwise it is not.
SSL does use a MAC to verify data integrity. Strictly speaking, the MAC itself only ensures authenticity, not integrity: a MAC alone does not protect against replay attacks, whereby an adversary repeats a legitimate message. To protect against replay attacks, protocols such as SSL include a nonce in the authenticated message: if the message is genuine and contains the expected nonce, then it hasn't been modified or switched in transit.