From d7cf18d77f96e9a69cde610523e7a84efc8bc76a Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Tue, 31 May 2022 16:16:04 +0300 Subject: [PATCH] Simpler and slightly faster 512-bit-addition code --- pygost/gost34112012.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) 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): -- 2.44.0