I read about Hash Length Extension attacks here and here. From the articles I gained that this attack relies on the data structure, in the way that the secret has to be prefixed to the data (please correct me if I'm wrong). If that was the case, would it be a reasonable defense mechanism against this kind of attack to simply move the secret in the data structure?

From the article:

let secret = "secret"
let data = "data"
let H = md5()
let signature = hash(secret || data)

Would this (i.e. moving the secret to the middle of the signature):

let signature = hash( string.Format( "{0}{1}{2}", data.Substring( 0, ( int ) ( data.Length / 2 ) ), secret, data.Substring( ( int ) ( data.Length / 2 ) ) ) );

be safe?

  • you can just swap the order of input to data || secret or use a sponge-based hash. hash(secret || hash(secret || data)) would also work. – dandavis Sep 7 '17 at 19:05
  • 1
    This attack still applies. ​ ​ – user49075 Sep 7 '17 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.