Ñò *qRc @s0dZddklZddklZddklZddklZyddk l Z l Z Wnbe j oVddkZ ddkZeidd !djoddkZ qÅdd klZ nXd „Zd efd„ƒYZddd„Zeeƒe_d„Zd„Zedjo eƒndS(s1.1iÿÿÿÿ(tpack(tb2a_hex(trandint(t b64encode(tHMACtSHANiii(tsha1cCsMdig}t||ƒD])\}}|tt|ƒt|ƒAƒq~ƒS(Nt(tjointziptchrtord(tatbt_[1]txty((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pytstrxor]stPBKDF2cBsVeZdZdeed„Zd„Zd„Zd„Zd„Z d„Z d„Z RS( sÐPBKDF2.py : PKCS#5 v2.0 Password-Based Key Derivation This implementation takes a passphrase and a salt (and optionally an iteration count, a digest module, and a MAC module) and provides a file-like object from which an arbitrarily-sized key can be read. If the passphrase and/or salt are unicode objects, they are encoded as UTF-8 before they are processed. The idea behind PBKDF2 is to derive a cryptographic key from a passphrase and a salt. PBKDF2 may also be used as a strong salted password hash. The 'crypt' function is provided for that purpose. Remember: Keys generated using PBKDF2 are only as strong as the passphrases they are derived from. iècCsIt|ƒp |i}n||_||_|i||||iƒdS(N(tcallabletnewt_PBKDF2__macmodulet_PBKDF2__digestmodulet_setupt _pseudorandom(tselft passphrasetsaltt iterationst digestmodulet macmodule((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pyt__init__ts     cCs%|id|d|d|iƒiƒS(s&Pseudorandom function. e.g. HMAC-SHA1tkeytmsgt digestmod(RRtdigest(RR R!((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pyR|scCsÙ|iotdƒ‚nt|iƒ}|ig}|i}xe||joW|d7}|djotdƒ‚n|i|ƒ}|i|ƒ|t|ƒ7}qAWdi|ƒ}|| }|||_||_|S(s'Read the specified number of key bytes.sfile-like object is closedilÿÿsderived key too longR( tclosedt ValueErrortlent _PBKDF2__buft_PBKDF2__blockNumt OverflowErrort _PBKDF2__ftappendR(Rtbytestsizetblockstitblocktbuftretval((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pytreads$          cCs•d|jo |djpt‚|i|i|itd|ƒƒ}|}xBtdd|iƒD]*}|i|i|ƒ}t||ƒ}qcW|S(Nilÿÿs!Li(tAssertionErrort _PBKDF2__prft_PBKDF2__passphraset _PBKDF2__saltRtxranget_PBKDF2__iterationsR(RR/tUtresulttj((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pyt__f—s!%cCst|i|ƒƒS(sxRead the specified number of octets. Return them as hexadecimal. Note that len(obj.hexread(n)) == 2*n. (RR3(Rtoctets((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pythexread¡scCs)t|tƒo|idƒ}nt|tƒptdƒ‚nt|tƒo|idƒ}nt|tƒptdƒ‚nt|ttfƒptdƒ‚n|djotdƒ‚nt|ƒptdƒ‚n||_ ||_ ||_ ||_ d|_ d |_t|_dS( NsUTF-8s!passphrase must be str or unicodessalt must be str or unicodesiterations must be an integerisiterations must be at least 1sprf must be callableiR(t isinstancetunicodetencodetstrt TypeErrortinttlongR%RR6R7R9R5R(R'tFalseR$(RRRRtprf((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pyR¨s*        cCs?|ip1|`|`|`|`|`|`t|_ndS(sClose the stream.N(R$R6R7R9R5R(R'tTrue(R((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pytcloseÈs ( t__name__t __module__t__doc__tSHA1RRRR3R*R?RRJ(((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pyR`s    cCsæ|djo tƒ}nt|tƒo|idƒ}nt|tƒptdƒ‚nt|tƒo|idƒ}nt|tƒptdƒ‚n|idƒo|idƒdd!\}}}|d jo d }q=t |d ƒ}|d |jot d ƒ‚n|}|djpt d ƒ‚q=nd}x2|D]*}||jot d|fƒ‚qJqJW|djp |d jod }d|}nd||f}t |||ƒi dƒ}|dt |dƒS(sºPBKDF2-based unix crypt(3) replacement. The number of iterations specified in the salt overrides the 'iterations' parameter. The effective hash length is 192 bits. sus-asciissalt must be a stringsUTF-8s word must be a string or unicodes$p5k2$s$iiRiis%xs Invalid saltis@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./sIllegal character %r in salts$p5k2$$s $p5k2$%x$%sis./N(tNonet _makesaltR@RARBRCRDt startswithtsplitRER%RR3R(twordRRtdummyt convertedtallowedtchtrawhash((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pytcryptÓs>      c CsOdig}tdƒD]}|tdtddƒƒq~ƒ}t|dƒS(s€Return a 48-bit pseudorandom salt for crypt(). This function is not suitable for generating cryptographic secrets. Ris@Hiiÿÿs./(RtrangeRRR(RR/t binarysalt((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pyRP sBcCsddkl}tdddƒidƒ}|dƒ}||jotdƒ‚ntddd ƒid ƒ}d }||jotdƒ‚ntd d dd ƒid ƒ}d}||jotdƒ‚ntd ddd ƒid ƒ}d}||jotdƒ‚ntdddƒ}|idƒ}||idƒ7}||idƒ7}||idƒ7}||idƒ7}tdddƒidƒ}||jotdƒ‚ntddƒ}d}||jotdƒ‚ntddƒ}d}||jotdƒ‚ntd d!d"d#ƒ}d$}||jotdƒ‚ntd%d&ƒ}d&}||jotdƒ‚nd'S((sModule self-testiÿÿÿÿ(ta2b_hextpasswordsATHENA.MIT.EDUraeburniit cdedb5281bb2f801565a1122b2563515sself-test failedi°i t@5c08eb61fdf71e4e4ec3cf6ba1f5512ba7e52ddbc5e5142f708a31e2e62b1e13tXi@spass phrase equals block sizet@139c30c0966bc32ba55fdbf212530ac9c5ec59f1a452f5cc9ad940fea0598ed1iAspass phrase exceeds block sizet@9ccad6d468770cd51b10e6a68721be611a8b4d282601db3b36be9246915ec82at kickstartt workbenchiiiii(tcloadmtexecs,$p5k2$$exec$r1EWMCMk7Rlv3L/RNcFXviDefYa0hlqltgnus$p5k2$c$u9HvcT4d$.....s1$p5k2$c$u9HvcT4d$Sd1gwSVCLZYAuqZ25piRnbBEoAesaa/gtdclttUsch7fURi s1$p5k2$d$tUsch7fU$nqDkaxMDOFBeJsTSfABsyn.PYUXilHwLuΙωαννηςs0$p5k2$$KosHgqNo$9mjN8gqjt02hDoP0c2J0ABtLIwtot8cQN(tbinasciiR\RR3t RuntimeErrorR?RY(R\R;texpectedtf((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pyt test_pbkdf2sV           t__main__(ii(t __version__tstructRRjRtrandomRt beaker.utilRt Crypto.HashRRRNt ImportErrorthmactsyst version_infotshathashlibRRtobjectRRORYt staticmethodRPRnRK(((s8/usr/lib/python2.6/site-packages/beaker/crypto/pbkdf2.pytCs(   s7  O