+
    i%                         R t ^ RIHt ^ RIt]P                  ! ]4      t^ RIH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# )zg
passlib.utils.scrypt -- scrypt hash frontend and help utilities

XXX: add this module to public docs?
)absolute_importN)warn)exc)to_bytes)PYPYvalidatescryptc                   V^8  d   \        RV,          4      hV^8  d   \        RV,          4      hW,          \        8  d   \        RV: RV: 24      hV ^8  g   W ^,
          ,          '       d   \        RV ,          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=%rzp must be > 0: p=%rzr * p must be < 2**30: r=z, p=z%n must be > 1, and a power of 2: n=%rT)
ValueErrorMAX_RP)nrps   &&&\/var/www/html/photoedit/myenv/lib/python3.14/site-packages/passlib/crypto/scrypt/__init__.pyr   r   )   st     	1u.2331u.233uv~ !DEE1uU@1DEE    c                    V^V,          ^ V ^,           ,          \         ,          ,           ,          p\        WC,          4      pV# )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   H   s5    " #'B!a%L;667F FMr   c                    \        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 (unicode is encoded to bytes using utf-8).

:arg salt:
    salt string (unicode 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   k   sb    R Q1fH-FD'Dz455
:ZGHH6q11r   c                     \         '       d   ^
M^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   r   PasslibSecurityWarning_builtinr   execute)slowdownr   s     r   _load_builtin_backendr$      s?     TrsH 
#%-
./2/I/IK '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+      sz    
 
Z 	DcFXFXY  %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f1Q$*, 	,r   )hashlibr   r'   )r3   r2   s    @r   _load_stdlib_backendr6      s,    
3,$ ! +  s      )stdlibr   builtinc                   V R8X  d   R# V R8X  d1   \          F  p  \        WR7      u # 	  \        P                  ! R4      h\        P                  V 4      pV'       g   \        RV : 24      hV! 4       pV'       g   \        P                  ! RV ,          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 %r not available)	backend_values_set_backendr   MissingBackendError_backend_loadersgetr
   backendr   )namer=   loaderr&   s   &&  r   r?   r?      s     u}		"D#D88 #
 %%&DEE!%%d+TCDDx))*Kd*RSS ** s   B))CCr;   c                 Z     \        V R R7       R #   \        P                   d     R# i ; i)Tr<   F)r?   r   r@   )rD   s   &r   _has_backendrG     s,    T$'"" s    **l    i?)g?)       )F)!__doc__
__future__r   logging	getLogger__name__logwarningsr   passlibr   passlib.utilsr   passlib.utils.compatr   __all__r1   r   r   r   r   r   r   rC   r   r$   r+   r6   r>   dictrA   r?   rG    r   r   <module>rX      s    ' g''1   " % 
  "
 
8 <  02f	 2!B 1 ! > Y r   