--- Codeville/SRP.py.orig 2020-12-15 07:22:56 UTC +++ Codeville/SRP.py @@ -34,7 +34,7 @@ class ImproperKeyValue(Exception): pass def hash(s): """Hash a value with some hashing algorithm.""" if type(s) != type(''): - s = long_to_string(s) + s = long_to_string(s) return sha.new(s).digest() @@ -85,7 +85,7 @@ def client_key(user, passphrase, s, B, u, keys, key_fu # We don't trust the host. Perhaps the host is being spoofed. if B <= 0 or n <= B: - raise ImproperKeyValue + raise ImproperKeyValue # Calculate the shared, secret session key. @@ -93,7 +93,7 @@ def client_key(user, passphrase, s, B, u, keys, key_fu v = 3 * pow(g, x, n) t = B if t < v: - t = t + n + t = t + n S = pow(t - v, a + u * x, n) K = hash(S) @@ -118,21 +118,21 @@ def host_begin(user, A, s, v): # order to break the protocol. if A <= 0 or n <= A: - raise ImproperKeyValue + raise ImproperKeyValue # Pick our random public keys. B = 0 while B == 0: - b = random_long(ablen) - B = ((3*v) + pow(g, b, n)) % n + b = random_long(ablen) + B = ((3*v) + pow(g, b, n)) % n u = pow(g, random_long(tlen), n) # Calculate the (private, shared secret) session key. t = (A * pow(v, u, n)) % n if t <= 1 or t + 1 == n: - raise ImproperKeyValue # WeakKeyValue -- could be our fault so retry + raise ImproperKeyValue # WeakKeyValue -- could be our fault so retry S = pow(t, b, n) K = hash(S) --- Codeville/entropy.py.orig 2020-12-15 07:23:19 UTC +++ Codeville/entropy.py @@ -31,14 +31,14 @@ def string_to_long(s): """Convert a string of bytes into a long integer.""" r = 0 for c in s: - r = (r << 8) + ord(c) + r = (r << 8) + ord(c) return r def long_to_string(i, length=0): """Convert a long integer into a string of bytes.""" s = '' while i > 0: - s = chr(i & 255) + s - i = i >> 8 + s = chr(i & 255) + s + i = i >> 8 s = '\x00' * (length - len(s)) + s return s