]> Cypherpunks.ru repositories - pygost.git/commitdiff
Simpler and slightly faster 512-bit-addition code
authorSergey Matveev <stargrave@stargrave.org>
Tue, 31 May 2022 13:16:04 +0000 (16:16 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 31 May 2022 13:16:04 +0000 (16:16 +0300)
pygost/gost34112012.py

index f1a7acc84a9dc9f1e28377d2ad46548136b3f168..48d7ae2e7bb22185804ab63e0c201d1f7f22a6e0 100644 (file)
@@ -184,16 +184,10 @@ LCache = _lcache()
 
 
 def add512bit(a, b):
 
 
 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):
 
 
 def g(n, hsh, msg):