HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/nacl/bindings/__pycache__/crypto_pwhash.cpython-38.pyc
U

�֫[B�@s�ddlmZmZmZddlZddlmZddlmZ	ddl
mZmZddlm
Z
e�e�de����dd�Ze��Ze��Ze��Ze��Ze��Ze��Ze��Ze� �Z!e�"�Z#e�$�Z%e�&�Z'e�(�Z)e�*�Z+e�,�Z-e�.�Z/e�0�Z1e�2�Z3e�4�Z5e�6�Z7e�8�Z9e�:�Z;e�<�Z=e�>�Z?e�e�de�@���dd�ZAe�B�ZCe�D�ZEe�F�ZGe�H�ZIe�J�ZKe�L�ZMe�N�ZOe�P�ZQe�R�ZSe�T�ZUe�e�de�V���dd�ZWe�X�ZYe�Z�Z[e�\�Z]e�^�Z_e�`�Zae�b�Zce�d�Zee�f�Zge�h�Zie�j�Zke'Zle)Zme+Zne-ZoeZpeZqdZrdZsd	Ztd
Zueufdd�Zvd
d�Zwdeufdd�Zxelemfdd�Zydd�Zzdd�Z{dd�Z|dd�Z}dd�Z~e~ZdS)�)�absolute_import�division�print_functionN)�
integer_types)�ffi�lib)�ensure�char *��?�?l����icCst|dkdtjd�t|dkdtjd�t||d@dkdtjd�t|dkdtjd�t|t|kd�t�tjd�t|dd	|>ktjd�|d
|}td
}t|d||ktjd�d||dd
}t|t|ktjd�t|tj|ktjd�t|||kdtjd�dS)NrzInvalid block size�ZraisingzInvalid parallelization factor�z Cost factor must be a power of 2zCost factor must be at least 2zp*r is greater than {0}���� �z7Memory limit would be exceeded with the choosen n, r, p)r�exc�
ValueError�
SCRYPT_PR_MAX�format�
UINT64_MAX�sys�maxsize)�n�r�p�maxmemZBlen�iZVlen�r�=/usr/lib/python3/dist-packages/nacl/bindings/crypto_pwhash.py�_check_memory_occupation�sF
�
��
�������r!cCs�|dkrd}d}||dkrRd}|d|}tdd�D]}d||dkr6q�q6nT||d}tdd�D]}d||dkrhq�qh|dd|}|d	kr�d	}||}|||fS)
z/Python implementation of libsodium's pickparamsi��rr
rrrrr
)�range)�opslimit�memlimitrrZmaxnZn_log2Zmaxrprrr � nacl_bindings_pick_scrypt_params�s$r&�@c	Cs�tt|t�td�tt|t�td�tt|t�td�tt|t�td�tt|t�td�t||||�t�d|�}t�	|t
|�|t
|�|||||�	}t|dkdtjd�t�
t�d|�|�dd�S)a1
    Derive a cryptographic key using the ``passwd`` and ``salt``
    given as input.

    The work factor can be tuned by by picking different
    values for the parameters

    :param bytes passwd:
    :param bytes salt:
    :param bytes salt: *must* be *exactly* :py:const:`.SALTBYTES` long
    :param int dklen:
    :param int opslimit:
    :param int n:
    :param int r: block size,
    :param int p: the parallelism factor
    :param int maxmem: the maximum available memory available for scrypt's
                       operations
    :rtype: bytes
    rz	uint8_t[]r�$Unexpected failure in key derivationr	N)r�
isinstancer�	TypeError�bytesr!r�newr�%crypto_pwhash_scryptsalsa208sha256_ll�lenr�RuntimeError�buffer�cast)	�passwd�saltrrrZdklenr�buf�retrrr r-�s<
�
�
�
�
��
�r-cCs@t�dt�}t�||t|�||�}t|dkdtjd�t�	|�S)a
    Derive a cryptographic key using the ``passwd`` and ``salt``
    given as input, returning a string representation which includes
    the salt and the tuning parameters.

    The returned string can be directly stored as a password hash.

    See :py:func:`.crypto_pwhash_scryptsalsa208sha256` for a short
    discussion about ``opslimit`` and ``memlimit`` values.

    :param bytes passwd:
    :param int opslimit:
    :param int memlimit:
    :return: serialized key hash, including salt and tuning parameters
    :rtype: bytes
    �char[]rz&Unexpected failure in password hashingr)
rr,�SCRYPT_STRBYTESr�&crypto_pwhash_scryptsalsa208sha256_strr.rrr/�string)r2r$r%r4r5rrr r8s�
�r8cCsFtt|�tdkdtjd�t�||t|��}t|dkdtjd�dS)z�
    Verifies the ``passwd`` against the ``passwd_hash`` that was generated.
    Returns True or False depending on the success

    :param passwd_hash: bytes
    :param passwd: bytes
    :rtype: boolean
    r
zInvalid password hashrr�Wrong passwordT)rr.r7rrr�-crypto_pwhash_scryptsalsa208sha256_str_verify�InvalidkeyError�Zpasswd_hashr2r5rrr r;$s
���r;cCs�|tkrn|tkr"t�d�t���n|tkr:t�d�t���|tkrTt�d�t���q�|tkr�t�d�t���nx|tkr�|t	kr�t�d�t	���n|t
kr�t�d�t
���|tkr�t�d�t���q�|tkr�t�d�t���n
t�
d��dS)Nz#memlimit must be at least {0} bytesz"memlimit must be at most {0} byteszopslimit must be at least {0}zopslimit must be at most {0}zUnsupported algorithm)�crypto_pwhash_ALG_ARGON2I13�"crypto_pwhash_argon2i_MEMLIMIT_MINrrr�"crypto_pwhash_argon2i_MEMLIMIT_MAX�"crypto_pwhash_argon2i_OPSLIMIT_MIN�"crypto_pwhash_argon2i_OPSLIMIT_MAX�crypto_pwhash_ALG_ARGON2ID13�#crypto_pwhash_argon2id_MEMLIMIT_MIN�#crypto_pwhash_argon2id_MEMLIMIT_MAX�#crypto_pwhash_argon2id_OPSLIMIT_MIN�#crypto_pwhash_argon2id_OPSLIMIT_MAXr*)r$r%�algrrr �_check_argon2_limits_alg;sF��������rIc
Cstt|t�tjd�tt|t�tjd�tt|t�tjd�tt|t�tjd�tt|t�tjd�t|�tkr�t�d�	t���|t
kr�t�d�	t
���n|tkr�t�d�	t���t|||�t
�d|�}t�|||t|�||||�}t|dkdtjd�t
�||�dd�S)	a�
    Derive a raw cryptographic key using the ``passwd`` and the ``salt``
    given as input to the ``alg`` algorithm.

    :param outlen: the length of the derived key
    :type outlen: int
    :param passwd: The input password
    :type passwd: bytes
    :param opslimit: computational cost
    :type opslimit: int
    :param memlimit: memory cost
    :type memlimit: int
    :param alg: algorithm identifier
    :type alg: int
    :return: derived key
    :rtype: bytes
    rz#salt must be exactly {0} bytes longz+derived key must be at least {0} bytes longz*derived key must be at most {0} bytes longzunsigned char[]rr(N)rr)rrr*r+r.�crypto_pwhash_SALTBYTESrr�crypto_pwhash_BYTES_MIN�crypto_pwhash_BYTES_MAXrIrr,rZ
crypto_pwhashr/r0)Zoutlenr2r3r$r%rH�outbufr5rrr �crypto_pwhash_alg\sV
�
�
�
�
�������
�rNcCs�tt|t�td�tt|t�td�tt|t�td�t|||�t�dd�}t�	||t
|�|||�}t|dkdtjd�t�
|�S)a
    Derive a cryptographic key using the ``passwd`` given as input
    and a random ``salt``, returning a string representation which
    includes the salt, the tuning parameters and the used algorithm.

    :param passwd: The input password
    :type passwd: bytes
    :param opslimit: computational cost
    :type opslimit: int
    :param memlimit: memory cost
    :type memlimit: int
    :param alg: The algorithm to use
    :type alg: int
    :return: serialized derived key and parameters
    :rtype: bytes
    rr6rrr()rr)rr*r+rIrr,r�crypto_pwhash_str_algr.rr/r9)r2r$r%rHrMr5rrr rO�s(
�
�
��
�rOcCsftt|t�td�tt|t�td�tt|�dkdtjd�t�||t|��}t|dkdtj	d�dS)a4
    Verifies the ``passwd`` against a given password hash.

    Returns True on success, raises InvalidkeyError on failure
    :param passwd_hash: saved password hash
    :type passwd_hash: bytes
    :param passwd: password to be checked
    :type passwd: bytes
    :return: success
    :rtype: boolean
    r�z#Hash must be at most 127 bytes longrr:T)
rr)r+r*r.rrr�crypto_pwhash_str_verifyr<r=rrr rQ�s 
�
���rQ)�Z
__future__rrrrZsixrZnacl.exceptions�
exceptionsrZnacl._sodiumrrrr9r1Z,crypto_pwhash_scryptsalsa208sha256_strprefixZ,crypto_pwhash_scryptsalsa208sha256_STRPREFIXZ,crypto_pwhash_scryptsalsa208sha256_saltbytesZ,crypto_pwhash_scryptsalsa208sha256_SALTBYTESZ+crypto_pwhash_scryptsalsa208sha256_strbytesZ+crypto_pwhash_scryptsalsa208sha256_STRBYTESZ-crypto_pwhash_scryptsalsa208sha256_passwd_minZ-crypto_pwhash_scryptsalsa208sha256_PASSWD_MINZ-crypto_pwhash_scryptsalsa208sha256_passwd_maxZ-crypto_pwhash_scryptsalsa208sha256_PASSWD_MAXZ,crypto_pwhash_scryptsalsa208sha256_bytes_minZ,crypto_pwhash_scryptsalsa208sha256_BYTES_MINZ,crypto_pwhash_scryptsalsa208sha256_bytes_maxZ,crypto_pwhash_scryptsalsa208sha256_BYTES_MAXZ/crypto_pwhash_scryptsalsa208sha256_memlimit_minZ/crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MINZ/crypto_pwhash_scryptsalsa208sha256_memlimit_maxZ/crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAXZ/crypto_pwhash_scryptsalsa208sha256_opslimit_minZ/crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MINZ/crypto_pwhash_scryptsalsa208sha256_opslimit_maxZ/crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAXZ7crypto_pwhash_scryptsalsa208sha256_opslimit_interactiveZ7crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVEZ7crypto_pwhash_scryptsalsa208sha256_memlimit_interactiveZ7crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVEZ5crypto_pwhash_scryptsalsa208sha256_opslimit_sensitiveZ5crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVEZ5crypto_pwhash_scryptsalsa208sha256_memlimit_sensitiveZ5crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVEZcrypto_pwhash_alg_argon2i13r>Zcrypto_pwhash_alg_argon2id13rCZcrypto_pwhash_alg_defaultZcrypto_pwhash_ALG_DEFAULTZcrypto_pwhash_saltbytesrJZcrypto_pwhash_strbytesZcrypto_pwhash_STRBYTESZcrypto_pwhash_passwd_minZcrypto_pwhash_PASSWD_MINZcrypto_pwhash_passwd_maxZcrypto_pwhash_PASSWD_MAXZcrypto_pwhash_bytes_minrKZcrypto_pwhash_bytes_maxrLZcrypto_pwhash_argon2i_strprefixZcrypto_pwhash_argon2i_STRPREFIXZ"crypto_pwhash_argon2i_memlimit_minr?Z"crypto_pwhash_argon2i_memlimit_maxr@Z"crypto_pwhash_argon2i_opslimit_minrAZ"crypto_pwhash_argon2i_opslimit_maxrBZ*crypto_pwhash_argon2i_opslimit_interactiveZ*crypto_pwhash_argon2i_OPSLIMIT_INTERACTIVEZ*crypto_pwhash_argon2i_memlimit_interactiveZ*crypto_pwhash_argon2i_MEMLIMIT_INTERACTIVEZ'crypto_pwhash_argon2i_opslimit_moderateZ'crypto_pwhash_argon2i_OPSLIMIT_MODERATEZ'crypto_pwhash_argon2i_memlimit_moderateZ'crypto_pwhash_argon2i_MEMLIMIT_MODERATEZ(crypto_pwhash_argon2i_opslimit_sensitiveZ(crypto_pwhash_argon2i_OPSLIMIT_SENSITIVEZ(crypto_pwhash_argon2i_memlimit_sensitiveZ(crypto_pwhash_argon2i_MEMLIMIT_SENSITIVEZ crypto_pwhash_argon2id_strprefixZ crypto_pwhash_argon2id_STRPREFIXZ#crypto_pwhash_argon2id_memlimit_minrDZ#crypto_pwhash_argon2id_memlimit_maxrEZ#crypto_pwhash_argon2id_opslimit_minrFZ#crypto_pwhash_argon2id_opslimit_maxrGZ+crypto_pwhash_argon2id_opslimit_interactiveZ+crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVEZ+crypto_pwhash_argon2id_memlimit_interactiveZ+crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVEZ(crypto_pwhash_argon2id_opslimit_moderateZ(crypto_pwhash_argon2id_OPSLIMIT_MODERATEZ(crypto_pwhash_argon2id_memlimit_moderateZ(crypto_pwhash_argon2id_MEMLIMIT_MODERATEZ)crypto_pwhash_argon2id_opslimit_sensitiveZ)crypto_pwhash_argon2id_OPSLIMIT_SENSITIVEZ)crypto_pwhash_argon2id_memlimit_sensitiveZ)crypto_pwhash_argon2id_MEMLIMIT_SENSITIVEZSCRYPT_OPSLIMIT_INTERACTIVEZSCRYPT_MEMLIMIT_INTERACTIVEZSCRYPT_OPSLIMIT_SENSITIVEZSCRYPT_MEMLIMIT_SENSITIVEZSCRYPT_SALTBYTESr7rZLOG2_UINT64_MAXrZSCRYPT_MAX_MEMr!r&r-r8r;rIrNrOrQZ crypto_pwhash_argon2i_str_verifyrrrr �<module>s�
����������������
������������
������������������(�
1�
 !8%