Improve valid MAC detection

Implement constant time string comparison as well as double HMAC
verification for encryption MACs.