+
    THiz"                         R t ^ RIHt ^ RIHt ^ RIHt RR.tRtRt	Rt
R t^tRR ltRsRsRR	 ltR
 tR tR tRt]! ]]]R7      tRR lt]! R4       R tR# )z'scrypt hash frontend and help utilities)warn)exc)to_bytesvalidatescryptc                    V^8  d   \        RV: 24      hV^8  d   \        RV: 24      hW,          \        8  d   \        RV: RV: 24      hV ^8  g   W ^,
          ,          '       d   \        RV : 24      hR# )a-  
helper which validates a set of scrypt config parameters.
scrypt will take ``O(n * r * p)`` time and ``O(n * r)`` memory.
limitations are that ``n = 2**<positive integer>``, ``n < 2**(16*r)``, ``r * p < 2 ** 30``.

:param n: scrypt rounds
:param r: scrypt block size
:param p: scrypt parallel factor
zr must be > 0: r=zp must be > 0: p=zr * p must be < 2**30: r=z, p=z#n must be > 1, and a power of 2: n=T)
ValueErrorMAX_RP)nrps   &&&@/usr/lib/python3/dist-packages/passlib/crypto/scrypt/__init__.pyr   r      s     	1u,QE2331u,QE233uv~ 4QEaUCDD1uU>qeDEE    c                    V^V,          ^ V ^,           ,          \         ,          ,           ,          p\        WC,          4      # )a#  
calculate memory required for parameter combination.
assumes parameters have already been validated.

.. warning::
    this is derived from OpenSSL's scrypt maxmem formula;
    and may not be correct for other implementations
    (additional buffers, different parallelism tradeoffs, etc).
)UINT32_SIZEint)r
   r   r   fudgemaxmems   &&&& r   estimate_maxmemr   <   s1    " #'B!a%L;667Fv~r   Nc                    \        W#V4       \        V RR7      p \        VRR7      pV^8  d   \        R4      hV\        8  d   \        R\        ,          4      h\	        WW#WE4      # )a  run SCrypt key derivation function using specified parameters.

:arg secret:
    passphrase string (str is encoded to bytes using utf-8).

:arg salt:
    salt string (str is encoded to bytes using utf-8).

:arg n:
    integer 'N' parameter

:arg r:
    integer 'r' parameter

:arg p:
    integer 'p' parameter

:arg keylen:
    number of bytes of key to generate.
    defaults to 32 (the internal block size).

:returns:
    a *keylen*-sized bytes instance

SCrypt imposes a number of constraints on it's input parameters:

* ``r * p < 2**30`` -- due to a limitation of PBKDF2-HMAC-SHA256.
* ``keylen < (2**32 - 1) * 32`` -- due to a limitation of PBKDF2-HMAC-SHA256.
* ``n`` must a be a power of 2, and > 1 -- internal limitation of scrypt() implementation

:raises ValueError: if the provided parameters are invalid (see constraints above).

.. warning::

    Unless the third-party ``scrypt <https://pypi.python.org/pypi/scrypt/>``_ package
    is installed, passlib will use a builtin pure-python implementation of scrypt,
    which is *considerably* slower (and thus requires a much lower / less secure
    ``n`` value in order to be usuable). Installing the :mod:`!scrypt` package
    is strongly recommended.
secret)paramsaltzkeylen must be at least 1zkeylen too large, must be <= %d)r   r   r   
MAX_KEYLEN_scrypt)r   r   r
   r   r   keylens   &&&&&&r   r   r   \   sb    R Q1fH-FD'Dz455
:ZGHH6q11r   c                 l    ^dp \        RV ,          \        P                  4       ^RIHp VP
                  # )z<
Load pure-python scrypt implementation built into passlib.
zUsing builtin scrypt backend, which is %dx slower than is required for adequate security. Installing scrypt support (via 'pip install scrypt') is strongly recommended)ScryptEngine)r   r   PasslibSecurityWarning_builtinr   execute)slowdownr   s     r   _load_builtin_backendr"      s:     H	"$,	- 	""	 'r   c                      ^ RI Hp  V #   \         d     Mi ; i ^ RI p\        R\        P
                  4       R#   \         d6   pR\        T4      9  d   \        R\        P
                  4        Rp?R# Rp?ii ; i)z
Try to import the ctypes-based scrypt hash function provided by the
``scrypt <https://pypi.python.org/pypi/scrypt/>``_ package.
)hashNz5'scrypt' package is too old (lacks ``hash()`` method)r   zJ'scrypt' package failed to import correctly (possible installation issue?))r   r$   ImportErrorr   r   PasslibWarningstr)r$   r   errs      r   _load_cffi_backendr)      s}    
 
 	CSEWEW	
   3s8# \"" s!   
 < A<*A77A<c                 F   a  ^ RI Ho T3R lp T #   \         d     R# i ; i)zZ
Attempt to load stdlib scrypt() implement and return wrapper.
Returns None if not found.
)r   Nc           
      N   < \         pV^ 8  d   \        W#V4      pS! WW#WEVR7      # )    )passwordr   r
   r   r   dklenr   )SCRYPT_MAXMEMr   )r   r   r
   r   r   r   r   stdlib_scrypts   &&&&&& r   stdlib_scrypt_wrapper3_load_stdlib_backend.<locals>.stdlib_scrypt_wrapper   s3     A:$Q1-F!AF
 	
r   )hashlibr   r%   )r1   r0   s    @r   _load_stdlib_backendr4      s,    
3
& ! -  s      )stdlibr   builtinc                   V R8X  d   R# V R8X  d2   \          F  p  \        WR7        R# 	  \        P                  ! R4      h\        P                  V 4      pV'       g   \        RV : 24      hV! 4       pV'       g   \        P                  ! RV : R24      hV'       d   R# V sVsR#   \        P                   d     K  i ; i)	z
set backend for scrypt(). if name not specified, loads first available.

:raises ~passlib.exc.MissingBackendError: if backend can't be found

.. note:: mainly intended to be called by unittests, and scrypt hash handler
anyNdefaultdryrunzno scrypt backends availablezunknown scrypt backend: zscrypt backend z not available)	backend_values_set_backendr   MissingBackendError_backend_loadersgetr   backendr   )namer;   loaderr$   s   &&  r   r=   r=      s     u}y"DT1 # %%&DEE!!$'F3D8<==8D%%x~&NOOGG ** s   B((C Cr9   c                 Z     \        V R R7       R #   \        P                   d     R# i ; i)Tr:   F)r=   r   r>   )rB   s   &r   _has_backendrE     s,    T$'"" s    **l    i?)g?)       )F)__doc__warningsr   passlibr   passlib.utilsr   __all__r/   r   r	   r   r   r   r   rA   r   r"   r)   r4   r<   dictr?   r=   rE    r   r   <module>rP      s    -   "   "
 
8 4  02f  <!D 1 ! @ Y r   