Equal hashes for different messages when doing key length extension attack sha1 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?
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.