Skip to content

Instantly share code, notes, and snippets.

@brake
Last active October 12, 2016 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brake/18ab6f269fdef090034d1805308422c6 to your computer and use it in GitHub Desktop.
Save brake/18ab6f269fdef090034d1805308422c6 to your computer and use it in GitHub Desktop.
Example Key Derivation Function based on Pycrypto module
from binascii import unhexlify
from functools import partial
from Crypto.Protocol import KDF
from Crypto.Hash import SHA512, HMAC
_SALT = unhexlify('48B755AB80CD1C3DA61182D3DCD2E3A2CA869B783618FF6551FB4B0CDC3B8066') # some salt
_KEY_LENGTH = 32
key_derivation_fn = partial(
KDF.PBKDF2,
salt=_SALT,
dkLen=_KEY_LENGTH,
count=5000,
prf=lambda p,s: HMAC.new(p,s,SHA512).digest()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment