This module provides a couple of key derivation functions, as well as supporting utilities. Primarily, it offers pbkdf2(), which provides the ability to generate an arbitrary length key using the PBKDF2 key derivation algorithm, as specified in rfc 2898. This function can be helpful in creating password hashes using schemes which have been based around the pbkdf2 algorithm.
pkcs#5 password-based key derivation v1.5
| Parameters: |
|
|---|---|
| Returns: | raw bytes of generated key |
Note
This algorithm has been deprecated, new code should use PBKDF2. Among other limitations, keylen cannot be larger than the digest size of the specified hash.
pkcs#5 password-based key derivation v2.0
| Parameters: |
|
|---|---|
| Returns: | raw bytes of generated key |
Note
The details of PBKDF1 and PBKDF2 are specified in RFC 2898.
Normalize hash function name
| Parameters: |
|
|---|---|
| Returns: | Hash name, returned as native str. |
lookup pseudo-random family (prf) by name.
| Parameters: | name – this must be the name of a recognized prf. currently this only recognizes names with the format hmac-digest, where digest is the name of a hash function such as md5, sha256, etc. this can also be a callable with the signature prf(secret, message) -> digest, in which case it will be returned unchanged. |
|---|---|
| Raises: |
|
| Returns: | a tuple of (func, digest_size).
|
usage example:
>>> from passlib.utils.pbkdf2 import get_prf
>>> hmac_sha256, dsize = get_prf("hmac-sha256")
>>> hmac_sha256
<function hmac_sha256 at 0x1e37c80>
>>> dsize
32
>>> digest = hmac_sha256('password', 'message')
this function will attempt to return the fastest implementation it can find; if M2Crypto is present, and supports the specified prf, M2Crypto.EVP.hmac() will be used behind the scenes.