From: Sergey Matveev Date: Tue, 31 May 2022 13:16:04 +0000 (+0300) Subject: Simpler and slightly faster 512-bit-addition code X-Git-Tag: 5.12~8 X-Git-Url: http://www.git.cypherpunks.ru/?p=pygost.git;a=commitdiff_plain;h=d7cf18d77f96e9a69cde610523e7a84efc8bc76a Simpler and slightly faster 512-bit-addition code --- diff --git a/pygost/gost34112012.py b/pygost/gost34112012.py index f1a7acc..48d7ae2 100644 --- a/pygost/gost34112012.py +++ b/pygost/gost34112012.py @@ -184,16 +184,10 @@ LCache = _lcache() 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):