Skip to content

Commit

Permalink
Changed names of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
armicron committed Mar 23, 2017
1 parent e86dab3 commit 750a7d2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions warrant/aws_srp.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ def compute_hkdf(ikm, salt):
return hmac_hash[:16]


def calculate_u(A, B):
def calculate_u(big_a, big_b):
"""
Calculate the client's value U which is the hash of A and B
:param {Long integer} A Large A value.
:param {Long integer} B Server B value.
:param {Long integer} big_a Large A value.
:param {Long integer} big_b Server B value.
:return {Long integer} Computed U value.
"""
UHexHash = hex_hash(pad_hex(A) + pad_hex(B))
return hex_to_long(UHexHash)
u_hex_hash = hex_hash(pad_hex(big_a) + pad_hex(big_b))
return hex_to_long(u_hex_hash)


class AWSSRP(object):
Expand Down Expand Up @@ -122,24 +122,24 @@ def calculate_a(self):
raise ValueError('Safety check for A failed')
return big_a

def get_password_authentication_key(self, username, password, serverBValue, salt):
def get_password_authentication_key(self, username, password, server_b_value, salt):
"""
Calculates the final hkdf based on computed S value, and computed U value and the key
:param {String} username Username.
:param {String} password Password.
:param {Long integer} serverBValue Server B value.
:param {Long integer} server_b_value Server B value.
:param {Long integer} salt Generated salt.
:return {Buffer} Computed HKDF value.
"""
u_value = calculate_u(self.large_a_value, serverBValue)
u_value = calculate_u(self.large_a_value, server_b_value)
if u_value == 0:
raise ValueError('U cannot be zero.')
username_password = '%s%s:%s' % (self.pool_id.split('_')[1], username, password)
username_password_hash = hash_sha256(username_password.encode('utf-8'))

x_value = hex_to_long(hex_hash(pad_hex(salt) + username_password_hash))
g_mod_pow_xn = pow(self.g, x_value, self.big_n)
int_value2 = serverBValue - self.k * g_mod_pow_xn
int_value2 = server_b_value - self.k * g_mod_pow_xn
s_value = pow(int_value2, self.small_a_value + u_value * x_value, self.big_n)
hkdf = compute_hkdf(bytearray.fromhex(pad_hex(s_value)),
bytearray.fromhex(pad_hex(long_to_hex(u_value))))
Expand Down

0 comments on commit 750a7d2

Please sign in to comment.