ó ö 5Xc @ sdZddlmZddlZejeƒZddlmZddl m Z ddl m Z ddl mZmZmZmZmZdd d d gZdd lmZed eƒe dddddeddƒeƒZiadZd„Zddd„Zddd„ZdS(s¡passlib.pbkdf2 - PBKDF2 support this module is getting increasingly poorly named. maybe rename to "kdf" since it's getting more key derivation functions added. iÿÿÿÿ(tdivisionN(tExpectedTypeError(tdeprecated_function(tnative_string_types(tnorm_hash_namet lookup_hashtpbkdf1t pbkdf2_hmact compile_hmacRtget_prfRtpbkdf2(twarnsŠthe module 'passlib.utils.pbkdf2' is deprecated as of Passlib 1.7, and will be removed in Passlib 2.0, please use 'passlib.crypto' insteadt deprecateds1.7tremoveds1.8t func_modulet replacements$passlib.crypto.digest.norm_hash_namethmac_shmac-c sÏ|tkrt|St|tƒr|jtƒsHtd|fƒ‚nt|dƒj‰‡fd†}||jj f}nBt |ƒr¯t |ddƒƒ}||f}nt |ddƒ‚|t|<|S(sLookup pseudo-random family (PRF) by name. :arg name: This must be the name of a recognized prf. Currently this only recognizes names with the format :samp:`hmac-{digest}`, where :samp:`{digest}` is the name of a hash function such as ``md5``, ``sha256``, etc. todo: restore text about callables. :raises ValueError: if the name is not known :raises TypeError: if the name is not a callable or string :returns: a tuple of :samp:`({prf_func}, {digest_size})`, where: * :samp:`{prf_func}` is a function implementing the specified PRF, and has the signature ``prf_func(secret, message) -> digest``. * :samp:`{digest_size}` is an integer indicating the number of bytes the function returns. Usage example:: >>> from passlib.utils.pbkdf2 import get_prf >>> hmac_sha256, dsize = get_prf("hmac-sha256") >>> hmac_sha256 >>> dsize 32 >>> digest = hmac_sha256('password', 'message') .. deprecated:: 1.7 This function is deprecated, and will be removed in Passlib 2.0. This only related replacement is :func:`passlib.crypto.digest.compile_hmac`. sunknown prf algorithm: %ric stˆ|ƒ|ƒS(N(R(tkeytmsg(tdigest(s8/usr/lib/python2.7/site-packages/passlib/utils/pbkdf2.pythmachstxtysstr or callablesprf name( t _prf_cachet isinstanceRt startswitht_HMAC_PREFIXESt ValueErrorRtnamet digest_infot digest_sizetcallabletlenR(RRtrecordR((Rs8/usr/lib/python2.7/site-packages/passlib/utils/pbkdf2.pyR 9s)   tsha1cC st|||||ƒS(sLpkcs#5 password-based key derivation v1.5 :arg secret: passphrase to use to generate key :arg salt: salt string to use when generating key :param rounds: number of rounds to use to generate key :arg keylen: number of bytes to generate (if ``None``, uses digest's native size) :param hash: hash function to use. must be name of a hash recognized by hashlib. :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. .. deprecated:: 1.7 This has been relocated to :func:`passlib.crypto.digest.pbkdf1`, and this version will be removed in Passlib 2.0. *Note the call signature has changed.* (t_pbkdf1(tsecrettsalttroundstkeylenthash((s8/usr/lib/python2.7/site-packages/passlib/utils/pbkdf2.pyRwss hmac-sha1cC sZt|ƒs+t|tƒr:|jtƒ r:tdƒ‚n|d}t|||||ƒS(sWpkcs#5 password-based key derivation v2.0 :arg secret: passphrase to use to generate key :arg salt: salt string to use when generating key :param rounds: number of rounds to use to generate key :arg keylen: number of bytes to generate. if set to ``None``, will use digest size of selected prf. :param prf: psuedo-random family to use for key strengthening. this must be a string starting with ``"hmac-"``, followed by the name of a known digest. this defaults to ``"hmac-sha1"`` (the only prf explicitly listed in the PBKDF2 specification) .. rst-class:: warning .. versionchanged 1.7: This argument no longer supports arbitrary PRF callables -- These were rarely / never used, and created too many unwanted codepaths. :returns: raw bytes of generated key .. deprecated:: 1.7 This has been deprecated in favor of :func:`passlib.crypto.digest.pbkdf2_hmac`, and will be removed in Passlib 2.0. *Note the call signature has changed.* s1non-HMAC prfs are not supported as of Passlib 1.7i(RRRRRtNotImplementedErrorR(R$R%R&R'tprfR((s8/usr/lib/python2.7/site-packages/passlib/utils/pbkdf2.pyR •s%+ (Rshmac-(t__doc__t __future__Rtloggingt getLoggert__name__tlogt passlib.excRtpasslib.utils.decorRtpasslib.utils.compatRtpasslib.crypto.digestRRRR#RRt__all__twarningsR tDeprecationWarningRRR tNoneR (((s8/usr/lib/python2.7/site-packages/passlib/utils/pbkdf2.pyts* (  >