0
$\begingroup$

I was doing the cryptopals challenge 29, and I found something weird. When I try to create a forged hash for a forged message I get always the same hash for different forged messages.

    def attack(self, hash, message, payload, oracle):
        for k in range(100):
            forged = self.glue_padding(b'a' * k + message)[k:] + payload
            ml = (k + len(forged)) * 8
            r = self.get_register(hash)
            sha1 = SHA1(payload, r, ml)
            forged_hash = sha1.digest()
            # SAME VALUE
            print(forged_hash)
            if oracle.validate(forged, forged_hash):
                print("[*] forged message : " + str(forged))
                return True
        return False

is this the normal behaviour?

$\endgroup$
  • $\begingroup$ There are several things you do to the input parameters before feeding it to SHA-1 algorithm in your code, and even the function itself seems to accept multiple arguments (where SHA-1 only has one: the message). I'd try and print out the direct input to SHA-1 (in case there is a collision anyway), and you'll likely find that it is identical as well. $\endgroup$ – Maarten Bodewes Nov 26 '19 at 20:12
1
$\begingroup$

Is this the normal behaviour?

No, it is not. While it is known that SHA-1 collisions can be found, it's a lot more work than what you do.

It's likely to be a bug in your code. I went through your code, and I'm not sure whether you might be computing the hash of the same preimage each iteration - that would certainly cause each hash to be the same.

| improve this answer | |
$\endgroup$
  • $\begingroup$ I found out that in fact I pass to the SHA1() always the same values, so it's always the same the digest() $\endgroup$ – meowmeowxw Nov 26 '19 at 17:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.