+
    THi.]                    <  a  0 t $ R t^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHtHtHtHt ^ RIHt ^ RIHt . R0OtR1tR2t. R3OtRR4RR5RR6R
R6RR7RR8RR5RR9RR:RR;RR<RR=RR4RR>RR;/tR t/ tR]R&   R tR t R?R lt!R  R! lt"R@R" lt# ! R# R	]4      t$Rs%0 RAmt&RBR$ R% llt']! ]PP                  PS                  R&4      4      '       d   ]'! 4        ]*! R' ]+! R(4       4       4      t,]*! R) ]+! R(4       4       4      t-RCR* R+ llt.RDR, lt/RDR- R. llt0R/.t1R# )Ezlpasslib.crypto.digest -- crytographic helpers used by the password hashes in passlib

.. versionadded:: 1.7
)annotationsN)warn)exc)logger)SequenceMixinas_boolto_bytesto_native_str)unicode_or_bytes)memoized_propertyHashInfomd5sha1sha224sha256sha384sha512blake2bblake2smd4sha3_224sha3_256sha3_384sha3_512shake128shake256c                     / p \        \        P                  R0,          4       F2  p\        V4      pVP                  VP
                  3WP                  &   K4  	  V # )z
internal helper used to generate ``_fallback_info`` dict.
currently only run manually to update the above list;
not invoked at runtime.
r   )sortedhashlibalgorithms_availablelookup_hashdigest_size
block_sizename)outalginfos      7/usr/lib/python3/dist-packages/passlib/crypto/digest.py_gen_fallback_infor(   Z   sP     Cg22eW<=3**DOO<II > J    zdict[str, str]_hash_info_cachec                   T p\        V \        4      '       g   \        V RR4      p \        P                  ! RRV P                  4       P                  4       4      p V P                  R4      '       d   V R,          p V P                  R4      p R pV! V 4      pV'       d   V# \        P                  ! R	V 4      pV'       d   VP                  R
RR4      w  rVpV'       d	   WV,          pTpV'       d*   VRV,           ,          pV'       d
   VR,          pW,          pV! V4      pV'       d   V# \        P                  ! RVVV4       W3# T pV P                  RR4      p\        P                  ! RVVV4       W3# )a!  
internal helper used by :func:`lookup_hash` --
normalize arbitrary hash name to hashlib format.
if name not recognized, returns dummy record and issues a warning.

:arg name:
    unnormalized name

:returns:
    tuple with 2+ elements: ``(hashlib_name, iana_name|None, ... 0+ aliases)``.
zutf-8z	hash namez[_ /]-zscram-:   NNz-plusc                4    \          F  pW9   g   K  Vu # 	  R # N)_known_hash_names)r#   rows   & r'   check_table&_get_hash_aliases.<locals>.check_table   s    $C{
 % r)   z8(?i)^(?P<name>[a-z]+)-?(?P<rev>\d)?-?(?P<size>\d{3,4})?$r#   revsize_z0normalizing unrecognized hash name %r => %r / %rz;normalizing unrecognized hash name and format %r => %r / %r)
isinstancestrr	   resubstriplower
startswithremovesuffixmatchgroupr   r&   replacewarning)	r#   origr2   resultm	iana_namer4   r5   hashlib_names	   &        r'   _get_hash_aliasesrH   k   sc    DdC  T7K866'3

 2 2 45D  Bx  ) F 	LdSA  !wwvuf=	I t#I# LY'M 	>		
$ "" 	||C-I		
 ""r)   c                H  a a S P                  R4      '       g   S R
9  d    \        \        S 4      # \        P                  o S! S R4       RV V3R llpS Vn        RVn        RS : R2Vn        V#   \         d     LLi ; i  \         d     Mi ; iS R8X  d	   ^ RI	H
p T# R	# )z
internal helper used by :func:`lookup_hash` --
lookup hash constructor by name

:arg name:
    name (normalized to hashlib format, e.g. ``"sha256"``)

:returns:
    hash constructor, e.g. ``hashlib.sha256()``;
    or None if hash can't be located.
r6   r)   c                   < S! SV 4      # r/    )msgr#   new_ssl_hashs   &r'   const_get_hash_const.<locals>.const   s    c**r)   r   zwrapper for hashlib.new(z3),
generated by passlib.crypto.digest.lookup_hash()r   )r   N)new
algorithmsr)   )r=   getattrr   AttributeErrorrP   __name__
__module____doc__
ValueErrorpasslib.crypto._md4r   )r#   rN   r   rM   s   f  @r'   _get_hash_constrZ      s     ??3D0E$E	7D))
 ;;LT3	+ 	+ $&th /? ? 	 -  		  " u}+

 s#   A1 	B 1A?>A?BBFc                  a	 \         p W0,          #   \        \        3 d     Mi ; iT'       d   RpRp\        T \        4      '       dl   \        T 4      pT^ ,          o	S	'       g   Q hS	T 8w  d   \        S	TR7      pYcT &   T# \        S	4      pT'       d    \        '       d   S	\        9  d	   R
T	3R llpM\        T \        4      '       d   T # \        T 4      '       d?   T p\        T! 4       P                  4      pT^ ,          o	\        S	4      pTf   M!YJ d   MRpM\        P                  ! T RR4      h\        YuTR7      pTe   YcT&   T'       d;   T F4  o	S	'       g   K  TP                  S	4      RT39   g   Q S	: R	24       hYcS	&   K6  	  T# )a  
Returns a :class:`HashInfo` record containing information about a given hash function.
Can be used to look up a hash constructor by name, normalize hash name representation, etc.

:arg digest:
    This can be any of:

    * A string containing a :mod:`!hashlib` digest name (e.g. ``"sha256"``),
    * A string containing an IANA-assigned hash name,
    * A digest constructor function (e.g. ``hashlib.sha256``).

    Case is ignored, underscores are converted to hyphens,
    and various other cleanups are made.

:param required:
    By default (True), this function will throw an :exc:`~passlib.exc.UnknownHashError` if no hash constructor
    can be found, or if the hash is not actually available.

    If this flag is False, it will instead return a dummy :class:`!HashInfo` record
    which will defer throwing the error until it's constructor function is called.
    This is mainly used by :func:`norm_hash_name`.

:param return_unknown:

    .. deprecated:: 1.7.3

        deprecated, and will be removed in passlib 2.0.
        this acts like inverse of **required**.

:returns HashInfo:
    :class:`HashInfo` instance containing information about specified digest.

    Multiple calls resolving to the same hash should always
    return the same :class:`!HashInfo` instance.
FTrequiredc                "   < \        S: R 24      h)z2 disabled for fips by passlib set_mock_fips_mode())rX   )sourcer#   s   &r'   rN   lookup_hash.<locals>.const5  s     hPQ r)   Nzdigest name or constructordigest)rN   namesr]   z already in cacherR   )r*   KeyError	TypeErrorr7   r
   rH   r    rZ   mock_fips_mode_fips_algorithmsr   callabler#   r   ExpectedTypeErrorget)
ra   return_unknownr]   cachecache_by_name	name_listr&   rN   other_constr#   s
   &&&      @r'   r    r       s   R E}i  
  M&*++%f-	|t 6>th7D &MK  % ^^4D(D
 
FH	%	%	&		 %egll3	|%d+ !  "M ##F,H(SS %8DD eDtyy4,6T4(BS8TT6"d  Ks    %%c                   V ^8  d   QhRR/# )   returnNonerK   )formats   "r'   __annotate__rt   f  s       r)   c                 .    \         P                  4        R # r/   )r*   clearrK   r)   r'   clear_lookup_hash_cacherw   f  s    r)   c                    \        V RR7      pVP                  '       d,   \        RVP                  ,           \        P
                  4       VR8X  d   VP                  # VR8X  d   VP                  # \        RV: 24      h)a  Normalize hash function name (convenience wrapper for :func:`lookup_hash`).

:arg name:
    Original hash function name.

    This name can be a Python :mod:`~hashlib` digest name,
    a SCRAM mechanism name, IANA assigned hash name, etc.
    Case is ignored, and underscores are converted to hyphens.

:param format:
    Naming convention to normalize to.
    Possible values are:

    * ``"hashlib"`` (the default) - normalizes name to be compatible
      with Python's :mod:`!hashlib`.

    * ``"iana"`` - normalizes name to IANA-assigned hash function name.
      For hashes which IANA hasn't assigned a name for, this issues a warning,
      and then uses a heuristic to return a "best guess" name.

:returns:
    Hash name, returned as native :class:`!str`.
Fr\   znorm_hash_name(): r   ianazunknown format: )	r    unknownr   
error_textr   PasslibRuntimeWarningr#   rF   rX   )r#   rs   r&   s   && r'   norm_hash_namer}   j  sj    0 te,D|||!DOO3S5N5NOyy~~
'z2
33r)   c                  `    ] tR tRtRtRtRtR
tRtRt	Rt
RtRtRR ltR tR t]R 4       tR	tR# )r   i  a  
Record containing information about a given hash algorithm, as returned :func:`lookup_hash`.

This class exposes the following attributes:

.. autoattribute:: const
.. autoattribute:: digest_size
.. autoattribute:: block_size
.. autoattribute:: name
.. autoattribute:: iana_name
.. autoattribute:: aliases
.. autoattribute:: supported

This object can also be treated a 3-element sequence
containing ``(const, digest_size, block_size)``.
NFc                2  a aa V^ ,          ;oS n         V^,          S n        VR,          S n        R VVV 3R llpVf*   V\        9   d   RS: 2pMRS: 2pRS n        V! V4       R#  V! 4       pTS n
        TP                  S n        TP                  S n        \        TP                  4       4      TP                  8w  d   \        S P                   : R24      hTP                   S P                   8w  d=   \!        RS P                   : RT: RTP                   : 2\"        P$                  4       R# R#   \
         dY   pR\        T4      P                  4       9   d   S: R	2pM R
S: R\        T4      P                   RT R2pT! T4        Rp?R# Rp?ii ; i)z
initialize new instance.
:arg const:
    hash constructor
:arg names:
    list of 2+ names. should be list of ``(name, iana_name, ... 0+ aliases)``.
    names must be lower-case. only iana name may be None.
:rp   NNc                    V ^8  d   QhRRRR/# )rp   rL   r8   rq   rr   rK   )rs   s   "r'   rt   'HashInfo.__init__.<locals>.__annotate__  s     	I 	I 	I 	Ir)   c                  <a  RV V3R llpS'       d   V! 4        S Sn         VSn        \        P                  ! \        4      ;_uu_ 4        \
        S,          w  Sn        Sn        RRR4       R#   + '       g   i     R# ; i)zK
helper that installs stub constructor which throws specified error <msg>.
c                2   < \         P                  ! SS4      hr/   )r   UnknownHashError)r_   rL   r#   s   &r'   rN   8HashInfo.__init__.<locals>.use_stub_const.<locals>.const  s    **355r)   NrR   )r{   rN   
contextlibsuppressrc   _fallback_infor!   r"   )rL   rN   r#   r]   selfs   f r'   use_stub_const)HashInfo.__init__.<locals>.use_stub_const  s[    
6 6  !DODJ$$X..4B44H1 $/ /...s   A00B	Nzunsupported hash: zunknown hash: Tzdisabled for fipsz hash disabled for fipszinternal error in z constructor
(z: )z  constructor failed sanity checkzinconsistent digest name: z resolved to z, which reports name as )r#   rF   aliasesr0   rz   rX   r8   r<   typerU   rN   r!   r"   lenra   RuntimeErrorr   r   r|   )	r   rN   rb   r]   r   rL   hasherrr#   s	   f&&f    @r'   __init__HashInfo.__init__  s    !8#tyqRy	I 	I& =))*4(3&th/#3	7D 
++// t{{}!1!11$)).NOPP 99		!,TYYMuiOghlhqhqgtu)) "-  
	
 #c#hnn&66 78*4(/$s)BTBTAUUWX[W\\]^3
	s   )D3 3F>AFFc                	\    R V P                   : RV P                  : RV P                  : R2# )z<lookup_hash(z): digest_size=z block_size=r   )r#   r!   r"   r   s   &r'   __repr__HashInfo.__repr__  s1    tyym?4;K;K:Nl[_[j[jZmmnoor)   c                	H    V P                   V P                  V P                  3# r/   )rN   r!   r"   r   s   &r'   	_as_tupleHashInfo._as_tuple
  s    zz4++T__<<r)   c                    V P                   RJ # )za
whether hash is available for use
(if False, constructor will throw UnknownHashError if called)
N)r{   r   s   &r'   	supportedHashInfo.supported  s     $&&r)   )r   r"   rN   r!   r{   rF   r#   rz   rK   T)rU   rV   __qualname____firstlineno__rW   r#   rF   r   rN   r!   r"   r{   rz   r   r   r   r   r   __static_attributes__rK   r)   r'   r   r     se    $ D I G E K J J GM^p= ' 'r)   c                    V ^8  d   QhRRRR/# )rp   enableboolrq   rr   rK   )rs   s   "r'   rt   rt   .  s        r)   c                    V s \        4        R# )zO
UT helper which monkeypatches lookup_hash() internals to replicate FIPS mode.
N)re   rw   )r   s   &r'   _set_mock_fips_moder   .  s    
 Nr)   PASSLIB_MOCK_FIPS_MODEc              #  2   "   T F  q^\,          x  K  	  R# 5i)\   NrK   .0xs   & r'   	<genexpr>r   <       1jt88j      c              #  2   "   T F  q^6,          x  K  	  R# 5i)6   NrK   r   s   & r'   r   r   =  r   r   c               $    V ^8  d   QhRRRRRR/# )rp   ra   r8   keyzstr | bytes	multipartr   rK   )rs   s   "r'   rt   rt   @  s&     L L L; L4 Lr)   c                  a	a
 \        V 4      pVw  rEpV^8  g   Q R4       h\        V\        4      '       g   \        VRR7      p\	        V4      pWv8  d   V! V4      P                  4       pTpWv8  d   VRWg,
          ,          ,          pV! VP                  \        4      4      P                  o	V! VP                  \        4      4      P                  o
V'       d	   V	V
3R lpMV	V
3R lpW8n
        V# )aV  
This function returns an efficient HMAC function, hardcoded with a specific digest & key.
It can be used via ``hmac = compile_hmac(digest, key)``.

:arg digest:
    digest name or constructor.

:arg key:
    secret key as :class:`!bytes` or :class:`!str` (str will be encoded using utf-8).

:param multipart:
    request a multipart constructor instead (see return description).

:returns:
    By default, the returned function has the signature ``hmac(msg) -> digest output``.

    However, if ``multipart=True``, the returned function has the signature
    ``hmac() -> update, finalize``, where ``update(msg)`` may be called multiple times,
    and ``finalize() -> digest_output`` may be repeatedly called at any point to
    calculate the HMAC digest so far.

    The returned object will also have a ``digest_info`` attribute, containing
    a :class:`lookup_hash` instance for the specified digest.

This function exists, and has the weird signature it does, in order to squeeze as
provide as much efficiency as possible, by omitting much of the setup cost
and features of the stdlib :mod:`hmac` module.
zblock size too smallr   param    c                 >   <a S! 4       oVV3R lp SP                   V 3# )z)generated by compile_hmac(multipart=True)c                 p   < S! 4       p V P                  SP                  4       4       V P                  4       # r/   updatera   )outer_outer_copyinners    r'   finalize,compile_hmac.<locals>.hmac.<locals>.finalizez  s(    #U\\^,||~%r)   )r   )r   r   _inner_copyr   s    @r'   hmaccompile_hmac.<locals>.hmacv  s     ME&
 <<))r)   c                   < S! 4       pVP                  V 4       S! 4       pVP                  VP                  4       4       VP                  4       # )zgenerated by compile_hmac()r   )rL   r   r   r   r   s   &  r'   r   r     s;    MELLMELL(<<>!r)   )r    r7   bytesr   r   ra   	translate	_TRANS_36copy	_TRANS_5Cdigest_info)ra   r   r   r   rN   r!   r"   klenr   r   r   s   &&&      @@r'   compile_hmacr   @  s    @ f%K%0"E
333 c5!!s%(s8DCj!w*+,, i0166Ki0166K		*	" #Kr)   c                   \        V 4      w  rVp\        VRR7      p\        VRR7      p\        V\        4      '       g   \        P
                  ! VRR4      hV^8  d   \        R4      hVf   TpMY\        V\        4      '       g   \        P
                  ! VRR	4      hV^ 8  d   \        R
4      hWF8  d   \        RV: RV: 24      hW,           p\        V4       F  p	V! V4      P                  4       pK  	  VRV # )a  pkcs#5 password-based key derivation v1.5

:arg digest:
    digest name or constructor.

:arg secret:
    secret to use when generating the key.
    may be :class:`!bytes` or :class:`str` (encoded using UTF-8).

:arg salt:
    salt string to use when generating key.
    may be :class:`!bytes` or :class:`str` (encoded using UTF-8).

:param rounds:
    number of rounds to use to generate key.

:arg keylen:
    number of bytes to generate (if omitted / ``None``, uses digest's native size)

:returns:
    raw :class:`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.
secretr   saltintroundszrounds must be at least 1Nzint or Nonekeylenzkeylen must be at least 0z keylength too large for digest: z > )	r    r   r7   r   r   rh   rX   rangera   )
ra   r   r   r   r   rN   r!   r"   blockr6   s
   &&&&&     r'   pbkdf1r     s    < &1%8"E
 fH-FD'D fc""##FE8<<z455 ~$$##FM8DD	!455		.vjK?K
 	

 ME6]e##% &>r)   c               (    V ^8  d   QhRRRRRRRR/# )rp   ra   r   r   r   r   r   rK   )rs   s   "r'   rt   rt     s.     'O 'O 'Ou 'OE 'O3 'Or)   c                    \        VRR7      p\        VRR7      p\        V 4      p\        P                  ! VP                  WW44      # )a\  pkcs#5 password-based key derivation v2.0 using HMAC + arbitrary digest.

:arg digest:
    digest name or constructor.

:arg secret:
    passphrase to use to generate key.
    may be :class:`!bytes` or :class:`str` (encoded using UTF-8).

:arg salt:
    salt string to use when generating key.
    may be :class:`!bytes` or :class:`str` (encoded using UTF-8).

:param rounds:
    number of rounds to use to generate key.

:arg keylen:
    number of bytes to generate.
    if omitted / ``None``, will use digest's native output size.

:returns:
    raw bytes of generated key

.. versionchanged:: 1.7

    This function will use the first available of the following backends:

    * :func:`hashlib.pbkdf2_hmac` (only available in py2 >= 2.7.8, and py3 >= 3.4)

    See :data:`passlib.crypto.digest.PBKDF2_BACKENDS` to determine
    which backend(s) are in use.
r   r   r   )r   r    r   pbkdf2_hmacr#   )ra   r   r   r   r   r   s   &&&&& r'   r   r     sD    B fH-FD'D f%K{//vNNr)   zhashlib-ssl)r    rw   r   r}   r   r   r   l    l    ))md2r   )r   r   )r   zsha-1)r   zsha-224zsha2-224)r   zsha-256zsha2-256)r   zsha-384zsha2-384)r   zsha-512zsha2-512)r   zblake-2b)r   zblake-2s)r   r   )	ripemd160z
ripemd-160ripemd)@      )    r   )   r   )   r   )   r   )0   r   )r      )r      )r   h   )r   H   )r      )FT)r   >   r   r   r   r   r   r   r   r   r   	shake_128	shake_256r   )Fr/   )2__conditional_annotations__rW   
__future__r   r   r   osr9   warningsr   passlibr   passlib._loggingr   passlib.utilsr   r   r   r	   passlib.utils.compatr
   passlib.utils.decorr   __all__
MAX_UINT32
MAX_UINT64r0   r   r(   r*   __annotations__rH   rZ   r    rw   r}   r   re   rf   r   environri   r   r   r   r   r   r   r   PBKDF2_BACKENDS)r   s   @r'   <module>r      sa  
 #   	 	   # I I 1 1 
 
 > yx	8	8
Hhhi			i		!(
 $& . %H#V1hyx4DG'} G'V  & 2::>>2344 1eCj11	1eCj11	L^:z'OV r)   