simplified more CRYPT logic and removed hmac_hash, functionality included in simple_hash, thanks David

This commit is contained in:
mdipierro
2012-08-09 23:34:37 -05:00
parent 853c065e01
commit 91c891b32f
3 changed files with 12 additions and 17 deletions
+8 -12
View File
@@ -42,10 +42,15 @@ def simple_hash(text, key='', salt = '', digest_alg = 'md5'):
"""
if not digest_alg:
raise RuntimeError, "simple_hash with digest_alg=None"
elif not isinstance(digest_alg,str):
elif not isinstance(digest_alg,str): # manual approach
h = digest_alg(text+key+salt)
elif key: # backward compatile
return hmac_hash(text, key+salt, digest_alg)
elif digest_alg.startswith('pbkdf2'): # latest and coolest!
iterations, keylen, alg = digest_alg[7:-1].split(',')
return pbkdf2_hex(text, salt, int(iterations),
int(keylen),get_digest(alg))
elif key: # use hmac
digest_alg = get_digest(digest_alg)
h = hmac.new(key+salt,value,digest_alg)
else: # compatible with third party systems
h = hashlib.new(digest_alg)
h.update(text+salt)
@@ -82,15 +87,6 @@ DIGEST_ALG_BY_SIZE = {
512/4: 'sha512',
}
def hmac_hash(value, salt, digest_alg='md5'):
if isinstance(digest_alg,str) and digest_alg.startswith('pbkdf2'):
iterations, keylen, alg = digest_alg[7:-1].split(',')
return pbkdf2_hex(value, salt, int(iterations),
int(keylen),get_digest(alg))
digest_alg = get_digest(digest_alg)
d = hmac.new(salt,value,digest_alg)
return d.hexdigest()
### compute constant ctokens
def initialize_urandom():