def add512bit(a, b):
- """Add two 512 integers
- """
- a = bytearray(a)
- b = bytearray(b)
- cb = 0
- res = bytearray(64)
- for i in range(64):
- cb = a[i] + b[i] + (cb >> 8)
- res[i] = cb & 0xff
- return res
+ a = int.from_bytes(a, "little")
+ b = int.from_bytes(b, "little")
+ r = (a + b) % (1 << 512)
+ return r.to_bytes(512 // 8, "little")
def g(n, hsh, msg):