]> Cypherpunks.ru repositories - pyssss.git/blobdiff - ssss.py
Raise copyright years
[pyssss.git] / ssss.py
diff --git a/ssss.py b/ssss.py
index 170e44eeb92cb3729bd7b51a50fe2029ffb97676..771c188f14f1e1863a7c2212cf016581957790b9 100644 (file)
--- a/ssss.py
+++ b/ssss.py
@@ -1,19 +1,19 @@
 # coding: utf-8
-# pyssss -- Pure Python Shamir's secret sharing scheme implementation
-# Copyright (C) 2015 Sergey Matveev <stargrave@stargrave.org>
+# ssss -- Pure Python Shamir's secret sharing scheme implementation
+# Copyright (C) 2015-2024 Sergey Matveev <stargrave@stargrave.org>
 #
 # This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, version 3 of the # License.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+# GNU Lesser General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program.  If not, see
+# <http://www.gnu.org/licenses/>.
 """ Shamir's secret sharing scheme implementation.
 
 https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing
@@ -21,12 +21,12 @@ https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing
 
 from os import urandom
 
-from pygost.gost3410 import bytes2long
-from pygost.gost3410 import long2bytes
+from pygost.utils import bytes2long
+from pygost.utils import long2bytes
 
 
 SECRET_LEN = 32
-POLY = 115792089237316195423570985008687907853269984665640564039457584007913129640997L
+POLY = 115792089237316195423570985008687907853269984665640564039457584007913129640997  # pylint: disable=line-too-long
 
 
 def _lshift(x, bits):
@@ -36,7 +36,7 @@ def _lshift(x, bits):
 def _field_mult(x, y):
     b = x
     z = b if y & 1 == 1 else 0
-    for i in xrange(1, SECRET_LEN * 8):
+    for i in range(1, SECRET_LEN * 8):
         b = _lshift(b, 1)
         if (b >> (SECRET_LEN * 8)) & 1 == 1:
             b ^= POLY
@@ -47,7 +47,7 @@ def _field_mult(x, y):
 
 def _horner(t, x, coef):
     y = coef[t - 1]
-    for i in xrange(t - 1, 0, -1):
+    for i in range(t - 1, 0, -1):
         y = _field_mult(y, x)
         y ^= coef[i - 1]
     return y
@@ -69,7 +69,7 @@ def _field_invert(x):
 
 def _calculate_li0(t, x, i):
     li0 = 1
-    for j in xrange(t):
+    for j in range(t):
         if j == i:
             continue
         li0 = _field_mult(li0, x[j])
@@ -92,10 +92,10 @@ def split(secret, n, t):
     coef = [bytes2long(secret[::-1])]
     if n < 0 or t < 0 or n < t or not secret:
         raise ValueError("Invalid parameters specified")
-    for i in xrange(1, t):
+    for i in range(1, t):
         coef.append(bytes2long(urandom(SECRET_LEN)))
     out = []
-    for i in xrange(1, n + 1):
+    for i in range(1, n + 1):
         out.append((i, long2bytes(_horner(t, i, coef))[::-1]))
     return out
 
@@ -116,9 +116,9 @@ def combine(t, parts):
         raise ValueError("Invalid parameters specified")
     if len(parts) != len(set(s[1] for s in parts)):
         raise ValueError("Equal parts found")
-    x, y = zip(*[(s[0], bytes2long(s[1][::-1])) for s in parts])
+    x, y = list(zip(*[(s[0], bytes2long(s[1][::-1])) for s in parts]))
     sec = 0
-    for i in xrange(t):
+    for i in range(t):
         li0 = _calculate_li0(t, x, i)
         li0si = _field_mult(li0, y[i])
         sec = sec ^ li0si