Current File : //usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyc
�
�;Xc@@s�dZddlZddlZeje�ZddlmZmZm	Z	m
Z
ddlmZddl
mZmZmZmZddljjZddgZdZdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddefZdfZdgZedI�ZedJ�ZedK�ZedL�ZdMej ej!ej"ej#fdN��YZ$de$fdO��YZ%de$fdP��YZ&dS(hs9passlib.handlers.sha2_crypt - SHA256-Crypt / SHA512-Crypti����N(t
safe_cryptt
test_cryptt
repeat_stringt
to_unicode(th64(tbyte_elem_valuetut
uascii_to_strtunicodetsha512_crypttsha256_crypttiiiiiiii
iiiiii
iiiiiiiiiiiiiiii	iii*i+i,i-i.i/i0i1i2i3i4i i5i6i!i7i"i#i8i9i$i:i%i&i;i<i'i=i(i)i>i?cCs�t|t�r!|jd�}nt|t�s6t�t|krctjj|rWt	nt
��nt|�}d|ko�dkns�td��t|t�s�td��|jd�}t|�}|dks�td��|r�tj
}t}ntj}t}||||�j�}|||�}	|	j}
|
t||��|}x.|r�|
|d	@rt|n|�|d	L}q[W|	j�}|d
kr�t|||�j�|�}
nU||�}|j}|d	}x|r||�|d	8}q�Wt|j�|�}
t|
�|ks0t�||dt|d��j�| }t|�|ksvtd
��|
|
}|
|}|
||||
||
||g}gtD] \}}||||f^q�}|}t|d�\}}xQ|rIx:|D]2\}}|||||�j��j�}qW|d	8}q�W|r�|d	?}x>|| D]2\}}|||||�j��j�}qeW|d	@r�||||d�j�}q�ntj||�jd�S(s�perform raw sha256-crypt / sha512-crypt

    this function provides a pure-python implementation of the internals
    for the SHA256-Crypt and SHA512-Crypt algorithms; it doesn't
    handle any of the parsing/validation of the hash strings themselves.

    :arg pwd: password chars/bytes to hash
    :arg salt: salt chars to use
    :arg rounds: linear rounds cost
    :arg use_512: use sha512-crypt instead of sha256-crypt mode

    :returns:
        encoded checksum chars
    sutf-8i�i�ɚ;sinvalid roundsssalt not unicodetasciiissalt too largeii`iissalt_len somehow > hash_len!i*(t
isinstanceRtencodetbytestAssertionErrort_BNULLtuhtexctNullPasswordErrorR	R
tlenthashlibtsha512t_512_transpose_maptsha256t_256_transpose_maptdigesttupdateRRt_c_digest_offsetstdivmodRtencode_transposed_bytestdecode(tpwdtsalttroundstuse_512tpwd_lentsalt_lent
hash_constt
transpose_maptdbta_ctxta_ctx_updatetitdatdpttmp_ctxttmp_ctx_updatetdstdp_dptdp_dstpermsteventoddtdatatdctblocksttailtpairs((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyt_raw_sha2_crypt8sl!!(					"	
	
(.

$-	*
*
$srounds=t$t0t_SHA2_CommoncBs�eZdZdZejZdZejZdZ	dZ
dZeZ
dZeZdd	�Zd
�Zd�Zed��Zd
�ZdZdZed��Zd�Zed��Zd�ZRS(sBclass containing common code shared by sha256_crypt & sha512_cryptR"R#timplicit_roundst	salt_sizeii�i�ɚ;tlinearcKsJtt|�j|�|dkr=|jo7|jdk}n||_dS(Ni�(tsuperR?t__init__tNonetuse_defaultsR#R@(tselfR@tkwds((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyRDscCs|j|d|jdk�S(Ntrelaxed(t
_norm_salttchecksumRE(RGR"((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyt_parse_saltscCs|j|d|jdk�S(NRI(t_norm_roundsRKRE(RGR#((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyt
_parse_rounds#scCsvt|dd�}|j}|j|�s?tjj|��nt|�dksWt�|djt	�}|djt
�r�tt
�dks�t�|jd�d}|jt�r�|tkr�tjj
|��nt|�}t}nd}t}t|�dkr|\}}n7t|�dkr?|d}d}ntjj|��|d	|d
|d|pldd|�S(
NRthashiiii�iiR#R"RKR@(Rtidentt
startswithRRtInvalidHashErrorRRtsplitt_UDOLLARt_UROUNDStpopt_UZEROtZeroPaddedRoundsErrortinttFalsetTrueREtMalformedHashError(tclsRORPtpartsR#R@R"tchk((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pytfrom_string's4			
	cCs�|jdkrI|jrItd�|j|j|jp?td�f}n4td�|j|j|j|jpvtd�f}t|�S(Ni�s%s%s$%sts%srounds=%d$%s$%s(R#R@RRPR"RKR(RGRO((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyt	to_stringTstos_crypttbuiltincCs+t|j�r#|j|j�tStSdS(N(Rt
_test_hasht_set_calc_checksum_backendt_calc_checksum_os_cryptR[RZ(R]((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyt_load_backend_os_cryptiscCskt||j��}|rZ|j}|j|j�rK||dtksQt�||S|j|�SdS(Ni(RRbt
checksum_sizeRQRPRTRt_calc_checksum_builtin(RGtsecretROtcs((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyRgqs	-	cCs|j|j�tS(N(RfRjR[(R]((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyt_load_backend_builtin�scCst||j|j|j�S(N(R<R"R#t_cdb_use_512(RGRk((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyRj�s(ssaltsroundssimplicit_roundsRAN(RcRd(t__name__t
__module__t__doc__tsetting_kwdsRtHASH64_CHARStchecksum_charst
max_salt_sizet
salt_charst
min_roundst
max_roundstrounds_costRZRnREt_rounds_prefixR@RDRLRNtclassmethodR`RbtbackendsReRhRgRmRj(((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyR?�s,				-		cBs2eZdZdZed�ZdZdZdZRS(s.This class implements the SHA256-Crypt password hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, and a variable number of rounds.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 0-16 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 535000, must be between 1000 and 999999999, inclusive.

    :type implicit_rounds: bool
    :param implicit_rounds:
        this is an internal option which generally doesn't need to be touched.

        this flag determines whether the hash should omit the rounds parameter
        when encoding it to a string; this is only permitted by the spec for rounds=5000,
        and the flag is ignored otherwise. the spec requires the two different
        encodings be preserved as they are, instead of normalizing them.

    :type relaxed: bool
    :param relaxed:
        By default, providing an invalid value for one of the other
        keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
        and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
        will be issued instead. Correctable errors include ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6
    R
s$5$i+i�)ttests?$5$rounds=1000$test$QmQADEXMG8POI5WDsaeho0P36yK3Tcrgboabng6bkb/(R}s?$5$rounds=1000$test$QmQADEXMG8POI5WDsaeho0P36yK3Tcrgboabng6bkb/(	RoRpRqtnameRRPRitdefault_roundsRe(((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyR
�s$cBs8eZdZdZed�ZdZeZdZ	dZ
RS(s.This class implements the SHA512-Crypt password hash, and follows the :ref:`password-hash-api`.

    It supports a variable-length salt, and a variable number of rounds.

    The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:

    :type salt: str
    :param salt:
        Optional salt string.
        If not specified, one will be autogenerated (this is recommended).
        If specified, it must be 0-16 characters, drawn from the regexp range ``[./0-9A-Za-z]``.

    :type rounds: int
    :param rounds:
        Optional number of rounds to use.
        Defaults to 656000, must be between 1000 and 999999999, inclusive.

    :type implicit_rounds: bool
    :param implicit_rounds:
        this is an internal option which generally doesn't need to be touched.

        this flag determines whether the hash should omit the rounds parameter
        when encoding it to a string; this is only permitted by the spec for rounds=5000,
        and the flag is ignored otherwise. the spec requires the two different
        encodings be preserved as they are, instead of normalizing them.

    :type relaxed: bool
    :param relaxed:
        By default, providing an invalid value for one of the other
        keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
        and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
        will be issued instead. Correctable errors include ``rounds``
        that are too small or too large, and ``salt`` strings that are too long.

        .. versionadded:: 1.6
    R	s$6$iVi�
R}sj$6$rounds=1000$test$2M/Lx6MtobqjLjobw0Wmo4Q5OFx5nVLJvmgseatA6oMnyWeBdRDx4DU.1H3eGmse6pgsOgDisWBGI5c7TZauS0(stestsj$6$rounds=1000$test$2M/Lx6MtobqjLjobw0Wmo4Q5OFx5nVLJvmgseatA6oMnyWeBdRDx4DU.1H3eGmse6pgsOgDisWBGI5c7TZauS0(RoRpRqR~RRPRiR[RnRRe(((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyR	�s$(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii(ii( ii
iiiiiiiii
iiiiiiiiiiiiiiiiiii	ii(@i*iiii+iiii,i-iiii.iiii/i0iiii1iiii2i3ii	i
i4ii ii5i6i!ii
i7i"i#ii8i9i$iii:i%i&ii;i<i'iii=i(i)ii>i?('RqRtloggingt	getLoggerRotlogt
passlib.utilsRRRRtpasslib.utils.binaryRtpasslib.utils.compatRRRRtpasslib.utils.handlerstutilsthandlersRt__all__RRRRRZR<RURTRWtHasManyBackendst	HasRoundstHasSalttGenericHandlerR?R
R	(((s?/usr/lib/python2.7/site-packages/passlib/handlers/sha2_crypt.pyt<module>s6""	��;