I've been reading about HMAC protecting from length extension attacks, but if the message already specifies it size, is HMAC adding any advantange to simple hashing after prepending a secret?
As example consider a protocol where the message is
user +
server + // to prevent attackers sending the same message to others
timestamp + // to avoid replay
message_content_size + // to avoid extension attacks
message_content +
signature
where the signature is sha256(user_secret + everything except the signature)
.
Is HMAC providing anything more in this case?
In other words if the problem is length extension, isn't just adding length field to the message enough? This way no extension is possible and I don't see how can you compute the correct hash of a modified message without knowing the secret...