--- a/Utilities/crypto/py3PBKDF2.py Sat Mar 11 14:35:22 2017 +0100 +++ b/Utilities/crypto/py3PBKDF2.py Sat Mar 11 18:08:42 2017 +0100 @@ -36,10 +36,10 @@ @param digestMod hash function @return hashed password (bytes) """ - hash = password + pwHash = password for i in range(iterations): - hash = hmac.new(salt, hash, digestMod).digest() - return hash + pwHash = hmac.new(salt, pwHash, digestMod).digest() + return pwHash def hashPasswordTuple(password, digestMod=hashlib.sha512, iterations=10000, @@ -56,9 +56,9 @@ """ salt = os.urandom(saltSize) password = password.encode("utf-8") - hash = pbkdf2(password, salt, iterations, digestMod) + pwHash = pbkdf2(password, salt, iterations, digestMod) digestname = digestMod.__name__.replace("openssl_", "") - return digestname, iterations, salt, hash + return digestname, iterations, salt, pwHash def hashPassword(password, digestMod=hashlib.sha512, iterations=10000, @@ -72,22 +72,22 @@ @param saltSize size of the salt (integer) @return hashed password entry according to PBKDF2 specification (string) """ - digestname, iterations, salt, hash = \ + digestname, iterations, salt, pwHash = \ hashPasswordTuple(password, digestMod, iterations, saltSize) return Delimiter.join([ digestname, str(iterations), base64.b64encode(salt).decode("ascii"), - base64.b64encode(hash).decode("ascii") + base64.b64encode(pwHash).decode("ascii") ]) -def verifyPassword(password, hash): +def verifyPassword(password, pwHash): """ Module function to verify a password against a hash encoded password. @param password clear text password (string) - @param hash hash encoded password in the form + @param pwHash hash encoded password in the form 'digestmod$iterations$salt$hashed_password' as produced by the hashPassword function (string) @return flag indicating a successfull verification (boolean) @@ -95,7 +95,7 @@ digest is not one of the known ones """ try: - digestname, iterations, salt, pwHash = hash.split(Delimiter) + digestname, iterations, salt, pwHash = pwHash.split(Delimiter) except ValueError: raise ValueError( "Expected hash encoded password in format " @@ -105,7 +105,7 @@ if digestname not in Hashes.keys(): raise ValueError( "Unsupported hash algorithm '{0}' for hash encoded password '{1}'." - .format(digestname, hash)) + .format(digestname, pwHash)) iterations = int(iterations) salt = base64.b64decode(salt.encode("ascii")) @@ -135,7 +135,7 @@ if digestname not in Hashes.keys(): raise ValueError( "Unsupported hash algorithm '{0}' for hash parameters '{1}'." - .format(digestname, hash)) + .format(digestname, hashParameters)) iterations = int(iterations) salt = base64.b64decode(salt.encode("ascii"))