; Od?d@d>d6dAd?dBdCdDd8dCd;d:dDd@dd<d=d7dBd9dAdBd@dAd>dCd7d8d:d;ddDd<ddBd=dDd?d9d6dAd9d8d7d6d<dCd:d;d@d?d>d=g@dEdFdGdHdIdJdKdLdFdMdNdOdPdIdQddOdEdRdSdJdKddNdMdPdHdRdLdGdSdQdQdPdRdLdFdMdNdJdEdOdHddKdEdGdRdPdGddHdIdQdSdFdOdIdJdSdMdKdLdNg@dTdUddVdUdWdXdYdZd[d\d]d^dTd_d`dYdXdaddWddVdad[d_d]dZdd\d`d^dZd]d^d`dVdUdd^d]dWdadYdUd[d\dd[d\dYdXdTd_d`ddWdTdXdVd_dZddag@dbdcdddedfdgdhddidjdkdldmdndldkdjdbdgdfddddedhdodpdndmdpdodcdidpdldodkdbdcdidodjdpdhddcdedmddddjdddhdkdbdfdidndmdgdfdedndldgg@dqdrdsddtdudvdwdxdydzdsd{d|d}dvd~d{dudtdwd}ddzdydd|dqdd~drdxdd~d}dwdsdyddzdqd|dtdudrdxdudtdwddvd}dzdsd|dvdxdrd{ddydqd~d{g@fZ ddd]dTd/ddddWdZd^dXdddddxddddddddddddddddYdUd_daddddd\d`dVd[ddddddddddddddddddddg@ddEddddddd ddddddddDdddddddddddddddd&dddddddddd$dddddddddddddddddddddg@ddmd#dd,dddd8ddddddddddddddddddddddddyddddddddddddd d d d d ddddddddddddddg@ddAdGddMddSddbdd d!d"d#d$d%d?d:d&d'd(d)d*d+d,d-d.d/d0d1d2d3d d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRg@dd&d/dSd ddTdUd]dVddWdXdYdZd[dAd\d]d^d_d`dadbdcdddedfdgdhdidjdbdkdldmdndodpdqdrdsdtdudvdwdxdyddzd{d|d}d~ddddddddddg@ddydMddDdddd dd7ddddddmddddddddddddddddEddNdddddddddddddddddddddddddddddg@ddGdYdd,ddddddUdddddddddddddddddddddddddddddddddddddddddddddddddddddg@dd?d#dd8d>dddddddddddxddddddddddddd d d dWd d dddddddddddddddddddd d!d"d#d$d%d&d'd(d)g@fZ dddmdmdmdmdmdmddmdmdmdmdmdmdfZ d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWddmd8dd dXdYdZdMdd[d\dXdYdZdMdd[d\d]d^d_d`ddadbdcdddedfdgdhdidjdkdldmdndodxdpddqdrdsdxdpddqdrdsdtdudvdwdxdydzd{d|d}dd~ddddddddddddddd)ddddgZ dZ dZdZdZdZdZdZedjo endS(sUnix crypt(3) password hash algorithm. This is a port to Python of the standard Unix password crypt function. It's a single self-contained source file that works with any version of Python from version 1.5 or higher. The code is based on Eric Young's optimised crypt in C. Python fcrypt is intended for users whose Python installation has not had the crypt module enabled, or whose C library doesn't include the crypt function. See the documentation for the Python crypt module for more information: http://www.python.org/doc/current/lib/module-crypt.html The crypt() function is a one-way hash function, intended to hide a password such that the only way to find out the original password is to guess values until you get a match. If you need to encrypt and decrypt data, this is not the module for you. There are at least two packages providing Python cryptography support: M2Crypto at , and amkCrypto at . Functions: crypt() -- return hashed password s Carey Evans s1.2s 6 May 2001sgmichal j wallace for inspiring me to write this. Eric Young for the C code this module was copied from.scryptNiiiiiiiiiiiiiiiiii i iii i i iiii ii i iiAi@i@i@Ai@ii@i@iii@i@Ai@@iAi@@iiiiiiiiiiiiiiiii@iiAi@iiAi@iiiAiiAi@ii ii ii iii ii i i ii iii@i@i@iii@i@ii@ii@i@ii i i ii i i i ii i i i ii ii i iii i i0i i0 i i0i  i0 i i0i  i0 i i0i  i0 i i i i i i i i i i0i  i0 i i0 i i0 i i0i  i0 i  i0 i  i0 i i i i ii i i i i ii$i$i i i$ i$ iii$i$i i i$ i$ ii i i i i ii i i i i iii$i$i i i$ i$ iii$i$i i i$ i$ iiiiiiiiiiiiiiiiiiiiiiiiiiiiii i i i iiiii i i i iiiii i i i iiiii i i i iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii0i0i i0i i0iiiiiiii i0i i0i i0i i0iiiiiiii i0i i0i i0i i0iiiiiiii i0i i0i i0i i0iiiiiiiiiii i iii i iii i iii i i i i ii ii ii ii ii ii i i ii i i  ii i i  ii i i  iiiiiiiiiii i(i(i i i(i(i i i(i(i i i(i(iiiiiiiiiiiiiii i i(i(i i i(i(i i i(i(i i i(i(iii i i i i i i i i i"i"i"i"i i i i i" i" i" i" iiiiiiii(i(i(i(i(i(i(i(i i i i"i"i"i"i (i (i (i (i"(i"(i"(i"(iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii i i i iiiiiiiiiiiiiiiiii!i#i$i%i&i'i(i)i*i+i,i-i.i/i1i2i3i4i5i6i7i8i9i:i;i<i=i>i?iAiBiCiDs@./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzcCs*|d>|Ad@}||A|d?d@ASdS(sClever bit manipulation.iii?N(sast(sast((sK/mnt/gmirror/ports/www/zope-exuserfolder/work/exUserFolder/fcrypt/fcrypt.pys _HPERM_OPscCs8||?|A|@}||A}|||>A}||fSdS(sCleverer bit manipulation.N(sasnsbsmst(sasbsnsmst((sK/mnt/gmirror/ports/www/zope-exuserfolder/work/exUserFolder/fcrypt/fcrypt.pys_PERM_OPs  cCstid|\} } | d@d>} | d@d>} t| | dd\} } t| } t| } t| | dd\} } t| | dd\} } t| | dd\} } | d @d >| d @B| d @d ?B| d?d @B} | d@} t}t \}}}}}}} }dgtd} xttD]} || o(| d?| d>B} | d?| d>B} n%| d?| d>B} | d?| d>B} | d@} | d@} || d@|| d?d@| d?d@BB|| d?d@| d?d@BB|| d?d@| d?d@B| d?d@BB}|| d@|| d?d@| d?d@BB| | d?d@B|| d?d@| d?d@BB}|d >|d @Bd!@| d| <|d ?|d"@B}|d>|d#?d@B}|d!@| d| d  .     nVcCs?t\}}}}}} } } t dt dd}d}}x5t dD]'} ||f\}}x |D]} ||d?d@A}||@}||@}||d>A|A|| A}||d>A|A|| dA}|d?d@|d >B}|||d @||d ?d @A| |d?d @A| |d ?d @A||d @A||d ?d @A||d?d @A| |d ?d @A|Af\}}qjWqKW|d?d @|d@d>B}|d?d @|d@d>B}t||dd\}}t||d d\}}t||dd\}}t||dd\}}t||dd\}}||fSdS(sDUse the key schedule ks and salt E0, E1 to create the password hash.iiiiiiiiii?iiiiiUUUUii3333iN(s_SPtranssSP0sSP1sSP2sSP3sSP4sSP5sSP6sSP7sranges _ITERATIONSsinnerslsrsjsistsE0susE1skss_PERM_OP(skssE0sE1sinnersSP0sSP1sSP2sSP3sSP4sSP5sSP6sSP7sisjslsrsust((sK/mnt/gmirror/ports/www/zope-exuserfolder/work/exUserFolder/fcrypt/fcrypt.pys_bodys0    c CsFt|djo|d}ntt|d}tt|dd>}t|dd } t | ||\}} t i dt id || \}}|d?d @|d >d @|d ?d @B|d>d@g}|d|dg}xD|D]<} x3tdddD]} |it| | ?d@qWqWti|d dSdS(sGenerate an encrypted hash from the passed password. If the password is longer than eight characters, only the first eight will be used. The first two characters of the salt are used to modify the encryption algorithm used to generate in the hash in one of 4096 different ways. The characters for the salt must be alphanumeric, '.' or '/'. The returned hash begins with the two characters of the salt, and should be passed as the salt to verify the password. Example: >>> from fcrypt import crypt >>> password = 'AlOtBsOl' >>> salt = 'cE' >>> hash = crypt(password, salt) >>> hash 'cEpWz5IUCShqM' >>> crypt(password, hash) == hash 1 >>> crypt('IaLaIoK', hash) == hash 0 In practice, you would read the password using something like the getpass module, and generate the salt randomly: >>> import random, string >>> saltchars = string.letters + string.digits + './' >>> salt = random.choice(saltchars) + random.choice(saltchars) isAAiiisis>iis