%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/passlib/crypto/scrypt/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/passlib/crypto/scrypt/__pycache__/__init__.cpython-39.pyc

a

f�Wc�%�@s�dZddlmZddlZe�e�ZddlmZddl	m
Z
ddlmZddl
mZdd	gZd
ZdZdZd
d�ZdZd"dd�Zdadad#dd	�Zdd�Zdd�Zdd�ZdZeeeed�Zd$dd�Zed�d d!�Z dS)%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�scrypt���l��i���?cCsh|dkrtd|��|dkr(td|��||tkrDtd||f��|dksX||d@rdtd|��dS)aI
    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
    �zr must be > 0: r=%rzp must be > 0: p=%rz!r * p must be < 2**30: r=%r, p=%r�z%n must be > 1, and a power of 2: n=%rT)�
ValueError�MAX_RP)�n�r�p�r�B/usr/lib/python3.9/site-packages/passlib/crypto/scrypt/__init__.pyr)s
���������?cCs,|d|d|dt}t||�}|S)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).
    �� r)�UINT32_SIZE�int)rrrZfudge�maxmemrrr�estimate_maxmemHsrr
rcCsZt|||�t|dd�}t|dd�}|dkr4td��|tkrHtdt��t||||||�S)a4run 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)Zparam�saltr
zkeylen must be at least 1zkeylen too large, must be <= %d)rrr�
MAX_KEYLEN�_scrypt)rrrrr�keylenrrrrks)cCs.trdnd}td|tj�ddlm}|jS)zD
    Load pure-python scrypt implementation built into passlib.
    �
�dz�Using builtin scrypt backend, which is %dx slower than is required for adequate security. Installing scrypt support (via 'pip install scrypt') is strongly recommendedr
)�ScryptEngine)rrrZPasslibSecurityWarningZ_builtinr"Zexecute)Zslowdownr"rrr�_load_builtin_backend�s��r#c
Cs�zddlm}|WSty$Yn0zddl}Wn<tyn}z$dt|�vrZtdtj�WYd}~nd}~00tdtj�dS)z�
    Try to import the ctypes-based scrypt hash function provided by the
    ``scrypt <https://pypi.python.org/pypi/scrypt/>``_ package.
    r)�hashNrzJ'scrypt' package failed to import correctly (possible installation issue?)z5'scrypt' package is too old (lacks ``hash()`` method))rr$�ImportError�strrrZPasslibWarning)r$r�errrrr�_load_cffi_backend�s�r(cs6zddlm�Wnty$YdS0�fdd�}|S)zf
    Attempt to load stdlib scrypt() implement and return wrapper.
    Returns None if not found.
    r)rNc	s.t}|dkrt|||�}�|||||||d�S)Nr)�passwordrrrrZdklenr)�
SCRYPT_MAXMEMr)rrrrrrr�Z
stdlib_scryptrr�stdlib_scrypt_wrapper�s�z3_load_stdlib_backend.<locals>.stdlib_scrypt_wrapper)Zhashlibrr%)r,rr+r�_load_stdlib_backend�sr-)ZstdlibrZbuiltinFc	Cs�|dkrdS|dkrVtD]0}zt||d�WStjyFYqYq0qt�d��nDt�|�}|srtd|f��|�}|s�t�d|��|r�dS|a|adS)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��dryrunzno scrypt backends availablezunknown scrypt backend: %rzscrypt backend %r not available)	�backend_values�_set_backendr�MissingBackendError�_backend_loaders�getr�backendr)�namer1�loaderr$rrrr3�s&
r3r/cCs.zt|dd�WdStjy(YdS0dS)NTr0F)r3rr4)r8rrr�_has_backends
r:)r)r
r)F)!�__doc__Z
__future__rZloggingZ	getLogger�__name__�log�warningsrZpasslibrZ
passlib.utilsrZpasslib.utils.compatr�__all__r*rr
rrrrr7rr#r(r-r2�dictr5r3r:rrrr�<module>s<�

3!�


Zerion Mini Shell 1.0