Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 18.219.7.43
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_hashlib.cpython-310.pyc
o

`b��@s�ddlZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZddlmZddlmZddlmZddlmZeed	�Zhd
�Ze�d�ZedurieZndd
�e�d����d�D�Zeddgd�Zeekr�eddgd�Z ndZ zddl!m"Z"m#Z#m$Z$m%Z%Wne&y�dZ"dZ#e'�Z$dd�Z%Ynwzddl(Z(Wne&y�dZ(Ynwe
�)e(d�Z*dd�Z+dZ,dd�Z-Gdd�de
j.�Z/Gdd �d e
j.�Z0e1d!kr�e
�2�dSdS)"�N)�	unhexlify)�support)�_4G�
bigmemtest)�import_fresh_module)�threading_helper)�warnings_helper)�
HTTPExceptionZgettotalrefcount>Zsha3�sha256�sha1�sha512Zblake2�md5ZPY_BUILTIN_HASHLIB_HASHEScCsh|]}|���qS�)�strip)�.0�mrr�:/usr/local/python-3.10/lib/python3.10/test/test_hashlib.py�	<setcomp>%s�r�"�,�hashlib�_hashlib)Zfresh)Zblocked)�HASH�HASHXOF�openssl_md_meth_names�
get_fips_modecCsdS�Nrrrrrrr9srzrequires _blake2cCsLt|t�sJt|���d}d}|D]}|||d?d@||d@7}q|S)NZ0123456789abcdef���)�
isinstance�bytes�repr)�s�h�r�irrr�hexstrDs"r'z(http://www.pythontest.net/hashlib/{}.txtc	cs��t�|�}z	tj|dd�}Wnttfy t�d�|���w|�+|D]}|��}|�	d�s3|s4q&|�
d�}t�|d�|d<|Vq&Wd�dS1sQwYdS)Nzutf-8)�encodingzCould not retrieve {}�#rr)
�URL�formatrZopen_urlresource�OSErrorr	�unittestZSkipTestr�
startswith�splitr!�fromhex)�	hash_name�urlZtestdata�line�partsrrr�read_vectorsOs"�
�
�"�r5csjeZdZdZddhZejdkpeZdd�Z	�fdd�Z
ed	d
��Zedd��Z
d
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd�d&d'�Zd(d)�Zd*d+�Zed,d-��Zd.d/�Z	0	1d�d2d3�Z d4d5�Z!d6d7�Z"d8d9�Z#d:d;�Z$ed<d=��Z%d>d?�Z&d@dA�Z'dBdC�Z(e)�*e+j,e-dDkdE�e.e-dDdFd%dG�dHdI���Z/e)�*e+j,e-dFkdE�e.e-dFdFd%dG�dJdK���Z0dLdM�Z1dNdO�Z2dPdQ�Z3dRdS�Z4dTdU�Z5dVdW�Z6dXdY�Z7dZd[�Z8d\d]�Z9d^d_�Z:d`da�Z;dbdc�Z<ddde�Z=dfdg�Z>dhdi�Z?djdk�Z@dldm�ZAdndo�ZBdpdq�ZCdrds�ZDdtdu�ZEdvdw�ZFedxdy��ZGedzd{��ZHed|d}��ZIed~d��ZJed�d���ZKed�d���ZLed�d���ZMed�d���ZNed�d���ZOed�d���ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]e^j_d�d���Z`d�d��Zaebjcd�d���Zde)�eefd1ud��d�d���Zgd�d��Zh�ZiS)��HashLibTestCase)r
�MD5rZSHA1�sha224ZSHA224r
�SHA256�sha384ZSHA384rZSHA512�blake2b�blake2s�sha3_224�sha3_256�sha3_384�sha3_512�	shake_128�	shake_256rArB�posixc
Cslzt�|�WSty5}z#|jr#|tvr*t�d|�WYd}~dSWYd}~dSWYd}~dSd}~ww)z@Import a module and return a reference to it or None on failure.z%Did a C extension fail to compile? %sN)�	importlib�
import_module�ModuleNotFoundError�_warn_on_extension_import�builtin_hashes�warnings�warn)�self�module_name�errorrrr�_conditional_import_modulels
�
���z*HashLibTestCase._conditional_import_modulec	s�t�}�jD]	}|�|���q��d�}|r|�ddh�i�_|D]}t��j|<q#�j��D]\}}|�tt	|��d|fdd�}|�|�q1��d�}|�_
|r���t|d����t|d���j��D]"\}}t|d	|d�}	|	r�z|	�Wn	t
y�Yqiw|�|	�qi�fd
d�}
��d�}|r�|
d
���d�}|r�|
d���d�}
|
r�|
d�|
d���d�}|r�|
d�|
d�|r�|
d�|
d���d�}|r�|
d�|
d�|
d�|
d�|
d�|
d�tt��j|i|��dS)N�_blake2r;r<c[s.|dur
tj|fi|��Stj||fi|��S�N)r�new)�dataZ_alg�kwargsrrr�_test_algorithm_via_hashlib_new�szAHashLibTestCase.__init__.<locals>._test_algorithm_via_hashlib_newr�openssl_md5Zopenssl_sha1Zopenssl_cs"ttd�|�}�j|�|�dS)N�__get_builtin_constructor)�getattrr�constructors_to_test�add)�name�constructor�rKrr�add_builtin_constructor�sz9HashLibTestCase.__init__.<locals>.add_builtin_constructor�_md5r
�_sha1r�_sha256r8r
�_sha512r:r�_sha3r=r>r?r@rArB)�set�supported_hash_namesrY�lowerrN�updaterX�itemsrWrr�
assertTrue�hasattr�
ValueError�superr6�__init__)rK�argsrSZ
algorithms�	algorithmrO�constructorsrTrr[r]r^r_r`rarb��	__class__r\rrlusn



�
�




zHashLibTestCase.__init__cCs|j��}tj�|�SrP)rX�values�	itertools�chain�
from_iterable)rKrorrr�hash_constructors�s
z!HashLibTestCase.hash_constructorscCst�SrP)rr\rrr�is_fips_mode�szHashLibTestCase.is_fips_modecCsLt�dtd��}|jD]}||dd�}|j|jvr|�d�q|��qdS)N�b�
F�Zusedforsecurity�)�array�rangervrZ�shakes�	hexdigest)rK�a�cons�crrr�test_hash_array�s

�zHashLibTestCase.test_hash_arraycCs"|�tjtdd�|jD���dS)Ncss�|]	}|��r|VqdSrP)�islower)rZ_algorrr�	<genexpr>�s��z=HashLibTestCase.test_algorithms_guaranteed.<locals>.<genexpr>)�assertEqualr�algorithms_guaranteedrcrdr\rrr�test_algorithms_guaranteed�s�z*HashLibTestCase.test_algorithms_guaranteedcCs|�ttj��tj��dSrP)rhrcrr��issubset�algorithms_availabler\rrr�test_algorithms_available�s�z)HashLibTestCase.test_algorithms_availablecCs�tjddd�|jr|�d�|jD]
}|dd�|ddd�qtjddd�tjdd�|jdurC|jjddd�|jjdd�dSdS)Nr
Trzzskip in FIPS mode�r
)rrQrw�skipTestrvr
rrU�rKr�rrr�test_usedforsecurity_true�s



�z)HashLibTestCase.test_usedforsecurity_truecCsztjddd�|jD]
}|dd�|ddd�q
tjddd�tjdd�|jdur;|jjddd�|jjdd�dSdS)Nr
Frzr�r
)rrQrvr
rrUr�rrr�test_usedforsecurity_false�s


�z*HashLibTestCase.test_usedforsecurity_falsecCs$|�ttjd�|�ttjd�dS)Nzspam spam spam spam spam�)�assertRaisesrjrrQ�	TypeErrorr\rrr�test_unknown_hash�sz!HashLibTestCase.test_unknown_hashcCs|�t�d�jd�dS)Nr9r
)r�rrQrZr\rrr�test_new_upper_to_lower�sz'HashLibTestCase.test_new_upper_to_lowerc	Cs�ttd�}ttd�}|�t|d�zddl}Wnty%|�d�Ynwdtjd<|�	�z|�t|d�Wdt
�vrC|tjd<qXtjd=ndt
�vrS|tjd<wtjd=w|�t|d�|d�}|�||j
�|�t|�d	dg�dS)
NrVZ__builtin_constructor_cache�testrz_md5 module not availabler^r
�r7)rWrr�rjr^�ImportErrorr��sys�modules�clear�localsr�ZassertIsr
r��sorted)rKZget_builtin_constructorZbuiltin_constructor_cacher^r[rrr�test_get_builtin_constructor�s4���



�
z,HashLibTestCase.test_get_builtin_constructorcCs~|jD]9}|dd�}|j|jvr(|�|�d�t�|�t|�d��|�d��q|�|��t�|�t|���|���qdS)NFrzr{)	rvrZr~�assertIsInstance�digestr!r�r'r�rKr�r$rrr�test_hexdigests

�zHashLibTestCase.test_hexdigestcCs�d}|jD]H}|dd�}|j|jvrqtdurt|t�rq|j|jfD])}|�t|d�|D]}|�tt	f��||�Wd�n1sFwYq.q#qdS)N)i l��l
ll����l
Frzi����)
rvrZr~rr r�rr�rj�
OverflowError)rKZlarge_sizesr�r$r��lengthrrr�test_digest_length_overflows"


�����z+HashLibTestCase.test_digest_length_overflowcCsr|jD]3}|dd�}|�|jt�|j|jvr |�|j|j�n|�|j|j�|�|jtj	|jdd�j�qdS)NFrz)
rvr�rZ�strrd�assertIn�assertNotInr�rrQr�rrr�test_name_attribute-s

��z#HashLibTestCase.test_name_attributec
Cs*d}d}d}d}|jD]�}|dd�}|�|�|�|�|�|�|�|�|j|jvr/d}nd}|dd�}|�||||�|�|j|�|j|��|||||dd�}	|�|j|�|	j|��||||dd�}
|
j|�}|
��}|�|�|�|j|�|j|��|�|
j|�|�qdS)	Ns�aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbs~ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccsddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddFrz)r{r)rvrfrZr~r�r��copy)
rKZaasZbeesZceesZdeesr�Zm1rmZm2Zm3Zm4Z	m4_digestZm4_copyrrr�test_large_update:s2








�z!HashLibTestCase.test_large_updateFcKs�t|�d}|��}|j|}|�t|�d�|D]F}||fi|��}	|s)|	��n|	�|�}
|�|
|d|||
t|�|f�|sD|	��n|	�|�}
t�|�}|�|
|�|s_|�t|�|	j	�qdS)N�zrHash algorithm %s constructed using %s returned hexdigest %r for %d byte input data that should have hashed to %r.)
�lenrerXZassertGreaterEqualrr�r�r!r0�digest_size)rKrZrRr�shakerSr�ro�hash_object_constructorrZcomputedr�rrr�checkZs,

���
��zHashLibTestCase.checkcCs&|j|}|D]	}|�t|d�qdS)NZspam)rXr�r�)rKZalgorithm_nameror�rrr�check_no_unicodeos
�z HashLibTestCase.check_no_unicodecC�@|�d�|�d�|�d�|�d�|�d�|�d�dS)Nr
rr8r
r:r�r�r\rrr�test_no_unicodeu�




zHashLibTestCase.test_no_unicodecCs|�d�|�d�dS)Nr;r<r�r\rrr�test_no_unicode_blake2}s
z&HashLibTestCase.test_no_unicode_blake2cCr�)Nr=r>r?r@rArBr�r\rrr�test_no_unicode_sha3�r�z$HashLibTestCase.test_no_unicode_sha3rNcCs�|j|}|D]Z}|dd�}|�|j|�|�|j|�|r7|�t|�|��|�|�t|�|��d|�n|�t|���|�|�t|���d|�|�|j|�|�|�	d�dt
|��qdS)NFrzr��_r)rXr��
block_sizer�r�r�rrZr�r/r")rKrZr�r�Z
digest_lengthror�rrrr�check_blocksize_name�s"

���z$HashLibTestCase.check_blocksize_namecCsX|�ddd�|�ddd�|�ddd�|�ddd	�|�d
dd�|�d
dd�dS)Nr
�@r{r�r8�r
� r:��0r�r�r\rrr�test_blocksize_name�sz#HashLibTestCase.test_blocksize_namecCs\|�ddd�|�ddd�|�ddd	�|�d
dd�|�d
ddd�|�dddd�dS)Nr=�r�r>�r�r?�hr�r@�Hr�rA�rrBr�r\rrr�test_blocksize_name_sha3�sz(HashLibTestCase.test_blocksize_name_sha3cCsl|j|}|D],}|�}tdurt|t�rq|�||d�|�|j|�|�|j|�|�|j|�qdS)Ni@)rXrr r�Z_capacity_bitsZ
_rate_bitsZ_suffix)rKrZZcapacityZrate�suffixror�rrrr�
check_sha3�s
�zHashLibTestCase.check_sha3cCsd|�dddd�|�dddd�|�dd	d
d�|�ddd
d�|�dddd�|�dddd�dS)Nr=i�i��r>�i@r?ii@r@�i@rA�i@�rB)r�r\rrr�test_extra_sha3�szHashLibTestCase.test_extra_sha3cCs |�ddd�|�ddd�dS)Nr;r�r�r<r�r�r\rrr�test_blocksize_name_blake2�sz*HashLibTestCase.test_blocksize_name_blake2cC�|jddddd�dS)Nr
r�Z d41d8cd98f00b204e9800998ecf8427eFrz�r�r\rrr�test_case_md5_0��
�zHashLibTestCase.test_case_md5_0cCr�)Nr
�abcZ 900150983cd24fb0d6963f7d28e17f72Frzr�r\rrr�test_case_md5_1�r�zHashLibTestCase.test_case_md5_1cCr�)Nr
s>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789Z d174ab98d277d9f5a5611c2c9f419d9fFrzr�r\rrr�test_case_md5_2�s
�zHashLibTestCase.test_case_md5_2�z!test cannot run on 32-bit systemsr�)�sizeZmemuse�dry_runcC�|�dd|d�dS)Nr
�AZ c9af2dff37468ce5dfee8f2cfc0a9c6dr��rKr�rrr�test_case_md5_huge��z"HashLibTestCase.test_case_md5_hugecCr�)Nr
r�Z 28138d306ff1b8281f1a9067e1a1a2b3r�r�rrr�test_case_md5_uintmax�r�z%HashLibTestCase.test_case_md5_uintmaxcC�|�ddd�dS)Nrr�Z(da39a3ee5e6b4b0d3255bfef95601890afd80709r�r\rrr�test_case_sha1_0���z HashLibTestCase.test_case_sha1_0cCr�)Nrr�Z(a9993e364706816aba3e25717850c26c9cd0d89dr�r\rrr�test_case_sha1_1�r�z HashLibTestCase.test_case_sha1_1cCr�)Nr�8abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqZ(84983e441c3bd26ebaae4aa1f95129e5e54670f1r�r\rrr�test_case_sha1_2���z HashLibTestCase.test_case_sha1_2cC�|�dddd�dS)Nr�a�@BZ(34aa973cd4c4daa4f61eeb2bdbad27316534016fr�r\rrr�test_case_sha1_3���z HashLibTestCase.test_case_sha1_3cCr�)Nr8r�Z8d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42fr�r\rrr�test_case_sha224_0�r�z"HashLibTestCase.test_case_sha224_0cCr�)Nr8r�Z823097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7r�r\rrr�test_case_sha224_1r�z"HashLibTestCase.test_case_sha224_1cCr�)Nr8r�Z875388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525r�r\rrr�test_case_sha224_2r�z"HashLibTestCase.test_case_sha224_2cCr�)Nr8r�r�Z820794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67r�r\rrr�test_case_sha224_3r�z"HashLibTestCase.test_case_sha224_3cCr�)Nr
r�Z@e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855r�r\rrr�test_case_sha256_0r�z"HashLibTestCase.test_case_sha256_0cCr�)Nr
r�Z@ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015adr�r\rrr�test_case_sha256_1r�z"HashLibTestCase.test_case_sha256_1cCr�)Nr
r�Z@248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1r�r\rrr�test_case_sha256_2r�z"HashLibTestCase.test_case_sha256_2cCr�)Nr
r�r�Z@cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0r�r\rrr�test_case_sha256_3r�z"HashLibTestCase.test_case_sha256_3cCr�)Nr:r�Z`38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95br�r\rrr�test_case_sha384_0"r�z"HashLibTestCase.test_case_sha384_0cCr�)Nr:r�Z`cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7r�r\rrr�test_case_sha384_1'r�z"HashLibTestCase.test_case_sha384_1cCr�)Nr:�pabcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstuZ`09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039r�r\rrr�test_case_sha384_2,��z"HashLibTestCase.test_case_sha384_2cCr�)Nr:r�r�Z`9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985r�r\rrr�test_case_sha384_33r�z"HashLibTestCase.test_case_sha384_3cCr�)Nrr�Z�cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3er�r\rrr�test_case_sha512_09r�z"HashLibTestCase.test_case_sha512_0cCr�)Nrr�Z�ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49fr�r\rrr�test_case_sha512_1>r�z"HashLibTestCase.test_case_sha512_1cCr�)Nrr�Z�8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909r�r\rrr�test_case_sha512_2Cr�z"HashLibTestCase.test_case_sha512_2cCr�)Nrr�r�Z�e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09br�r\rrr�test_case_sha512_3Jr�z"HashLibTestCase.test_case_sha512_3cCs|�|j|�t|d�D]	}|d|d�q
d|d}|jt||d�|�|j|�t|d�D]	}|d|d�q2d|d}	|jt||	d�|�|j|�td|d�D]}||d�qX|jt|dd�|jt|dd�|jt||dd�|�|j|�t|d�D]	}|d|d�q�d|d}
|jt||
d�|�|���|d	d����tdd
�D]}||d�q�|jt|dd�|jt|d
d�tdd
�D]}||d�q�|jt|dd�|jt|dd�|jt|d
d�tdd
�D]}||d
�q�|jt|dd
�|jt|d
d
�td|d�D]}||d��q|jt|dd�|jt||dd�|dd�|dd�|jt|dd�|jt	|dd�|dd�||d�|jt|dd�|jt	||dd�|jt
|d	d�|jt
|d	d�|�t
|d�|d	d	d	d	dddd
ddddd�dS)Nr�r���salt)�person�r����r��keyr�r�)�fanout)�depth)�
node_depth)�
inner_size)�	leaf_size���l)�node_offset)rR)�stringr�r��T)rrrr�rr	rrr
r�	last_node)r�Z	SALT_SIZEr}r�rjZPERSON_SIZEZMAX_DIGEST_SIZEZMAX_KEY_SIZErr�r�)rKr[Z	salt_sizeZperson_sizeZkey_sizer�Z
max_offsetr&rrrrrr�check_blake2Os��




�zHashLibTestCase.check_blake2cCsxdd�}|dd�}|D],}|D]'}|||�}|||�}	|||d�}
|�|
���|||	|d�}|�|���qq|��S)NcSsTd}d||@}d}t|�}t|�D]}|||@}||}}|d?d@||<q|S)Nr
l�KZ=r���)�	bytearrayr})r��seed�maskr�rx�outr&�trrr�selftest_seq�s
z4HashLibTestCase.blake2_rfc7693.<locals>.selftest_seqr�r)rr�)rfr�r)rKr[Zmd_lenZin_lenrZouterZoutlenZinlenZindatarZunkeyedZkeyedrrr�blake2_rfc7693�s



�zHashLibTestCase.blake2_rfc7693cC�B|�tjddddd�gd�}gd�}|�|�tj||�d�dS)Nr{r�l����)r�r�r�r�)rr�r��rr�Z@c23a7800d98123bd10f506c61e29da5603d763b8bbad2e737f5e765a7bccd475)rrr;r�r)rKZ
b2b_md_lenZ
b2b_in_lenrrr�test_blake2b���zHashLibTestCase.test_blake2bcCr�)Nr;r�Z�786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2cer�r\rrr�test_case_blake2b_0���z#HashLibTestCase.test_case_blake2b_0cCr�)Nr;r�Z�ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923r�r\rrr�test_case_blake2b_1�r"z#HashLibTestCase.test_case_blake2b_1cC�*|jddddddddd	d
ddd
dd�dS)Nr;�fooZ 920568b0c5873b2f0ab67bedb6cf1b2br{�bar�baz�bingr�r�rr��rT�r�rrrrr	rrr
rrr�r\rrr� test_case_blake2b_all_parameters��
�z0HashLibTestCase.test_case_blake2b_all_parameterscC�4td�D]\}}}t�|�}|jd|||d�qdS)Nr;r�r5r!r0r��rK�msgr�mdrrr�test_blake2b_vectors��
�z$HashLibTestCase.test_blake2b_vectorscCr)N�r�l���)r{r�r�r�)rr�r��Arr�Z@6a411f08ce25adcdfb02aba641451cec53c598b24f4fc787fbdc88797f4c1dfe)rrr<r�r)rKZ
b2s_md_lenZ
b2s_in_lenrrr�test_blake2s�r zHashLibTestCase.test_blake2scCr�)Nr<r�Z@69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9r�r\rrr�test_case_blake2s_0�r"z#HashLibTestCase.test_case_blake2s_0cCr�)Nr<r�Z@508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982r�r\rrr�test_case_blake2s_1�r"z#HashLibTestCase.test_case_blake2s_1cCr$)Nr<r%Z bf2a8f7fe3c555012a6f8046e646bc75r{r&r'r(r�r�rr�r)rTr*r�r\rrr� test_case_blake2s_all_parameters�r,z0HashLibTestCase.test_case_blake2s_all_parameterscCr-)Nr<rr.r/rrr�test_blake2s_vectorsr3z$HashLibTestCase.test_blake2s_vectorscCr�)Nr=r�Z86b4e03423667dbb73b6e15454f0eb1abd4597f9a1b078e3f5b5a6bc7r�r\rrr�test_case_sha3_224_0r�z$HashLibTestCase.test_case_sha3_224_0cC�$td�D]\}}|�d||�qdS)Nr=�r5r��rKr0r1rrr�test_case_sha3_224_vector��z)HashLibTestCase.test_case_sha3_224_vectorcCr�)Nr>r�Z@a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434ar�r\rrr�test_case_sha3_256_0r�z$HashLibTestCase.test_case_sha3_256_0cCr<)Nr>r=r>rrr�test_case_sha3_256_vectorr@z)HashLibTestCase.test_case_sha3_256_vectorcCr�)Nr?r�Z`0c63a75b845e4f7d01107d852e4c2485c51a50aaaa94fc61995e71bbee983a2ac3713831264adb47fb6bd1e058d5f004r�r\rrr�test_case_sha3_384_0r�z$HashLibTestCase.test_case_sha3_384_0cCr<)Nr?r=r>rrr�test_case_sha3_384_vector!r@z)HashLibTestCase.test_case_sha3_384_vectorcCr�)Nr@r�Z�a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26r�r\rrr�test_case_sha3_512_0%r�z$HashLibTestCase.test_case_sha3_512_0cCr<)Nr@r=r>rrr�test_case_sha3_512_vector*r@z)HashLibTestCase.test_case_sha3_512_vectorcC�$|�dddd�|�dddd�dS)NrAr�Z@7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26TZ7f9cr�r\rrr�test_case_shake_128_0.�
�z%HashLibTestCase.test_case_shake_128_0cC�&td�D]\}}|�d||d�qdS)NrATr=r>rrr�test_case_shake128_vector4��z)HashLibTestCase.test_case_shake128_vectorcCrG)NrBr�Z@46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762fTZ46b9r�r\rrr�test_case_shake_256_08rIz%HashLibTestCase.test_case_shake_256_0cCrJ)NrBTr=r>rrr�test_case_shake256_vector>rLz)HashLibTestCase.test_case_shake256_vectorcCs�d}|jD]%}|dd�}|�d�|�d|�|�d�|d|dd�}|�d�qt��}|�d�|�d|�|�d�|�|��d�t�dd|d�}|�|��d�dS)NiFrz�1�#�xZ@1cfceca95989f51f658e3f3ffe7f1cd43726c9e088c13ee10b46f57cef135b94)rvrfrr
r�r)rKZgil_minsizer�rrrr�test_gilBs*





��zHashLibTestCase.test_gilc	s�t���d}d}|d�t��|���}��fdd�}g}t|�D]'}t��d|}|�|d�|�|t|�d�tj||fd�}|�	|�q"|D]}|�
�qL|D]}|��qU|�|����dS)	Nr�sswineflui@
csBd}|t��kr���|||��||7}|t��ksdSdSr)r�rf)�
chunk_size�index�rRZhasherrr�hash_in_chunksms
�z=HashLibTestCase.test_threaded_hashing.<locals>.hash_in_chunksryr)�targetrm)rrrr}r�Z
assertGreaterr��	threading�Thread�append�start�join)	rKZnum_threadsZ
smallest_dataZ
expected_hashrV�threadsZ	threadnumrS�threadrrUr�test_threaded_hashing_s(�

z%HashLibTestCase.test_threaded_hashingcCs"|j}|dur|�|t�dSdSrP)rwr��int)rKZ	fips_moderrr�test_get_fips_mode�s�z"HashLibTestCase.test_get_fips_modec
Cs�|j��D]<\}}|�d�rq|D]/}z|�}Wn	ty!Yqw|j|d��t�|t|��Wd�n1s;wYqqdS)N)Zsha3_r�Zblake)r[)rXrgr.rj�subTestr�check_disallow_instantiation�type)rKrnror[r$rrr�test_disallow_instantiation�s

�����z+HashLibTestCase.test_disallow_instantiationz
need _hashlibcCst�|t�t�|t�dSrP)rrcrrr\rrr� test_hash_disallow_instantiation�sz0HashLibTestCase.test_hash_disallow_instantiationcCs�|j��D]I\}}|D]B}zt|��}Wn	tyYqw|j|d��!|�td��d|_Wd�n1s9wYWd�n1sHwYqqdS)N)�	hash_typezimmutable typeF)rXrgrdrjrb�assertRaisesRegexr��value)rKrnror[rgrrr�test_readonly_types�s �������z#HashLibTestCase.test_readonly_types)F)rrN)j�__name__�
__module__�__qualname__rdr~�osrZ�COMPILED_WITH_PYDEBUGrGrNrl�propertyrvrwr�r�r�r�r�r�r�r�r�r�r�r�r�r�r��requires_blake2r�r�r�r�r�r�r�r�r�r�r�r-�skipIfr��maxsizerrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr!r#r+r2r6r7r8r9r:r;r?rArBrCrDrErFrHrKrMrNrRrZreap_threadsr_rarZcpython_onlyre�
skipUnlessrrfrj�
__classcell__rrrprr6_s�	J

	


 

�
	O










#

r6c	@szeZdZgd�Zddddded�fdddd	ded
�fddd
d	ded�fgZe�d�dfe�d�dfe�d�dfe�d�dfe�d�dfge�d�dfe�d�dfe�d�dfe�d�dfe�d�dfge�d�dfe�d�dfe�d�dfe�d�d fe�d!�dfgd"�Zd#d$�Z	e
�edud%�d&d'��Z
e
�eed(�d)�d*d+��Ze
�eed,�d-�e
je�d.d/�d0d1���Zd2d3�ZdS)4�KDFTests))�password�saltr�N)rwrxr�N)rwrx�N)spasswordPASSWORDpasswords$saltSALTsaltSALTsaltSALTsaltSALTsaltryr)s	passwordssaltryr{r�r{r�Z�77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906rwsNaClr�r4Z�fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640s
pleaseletmeinsSodiumChloridei@Z�7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887Z(0c60c80f961f0e71f3a9b524af6012062fe037a6NZ(ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957Z(4b007901b765489abead49d926f721d065a429c1Z23d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038�Z 56fa6aa75548099dcc37d7f03425e0c3Z@120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17bZ@ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43Z@c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134aZP348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1c635518c7dac47e9�(Z 89b69d0516f829893c696226650a8687Z�867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fceZ�e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4eZ�d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5Z�8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8r�Z 9d9e9c4cd21fe4be24d5b8244c759665)rr
rcCs�|j��D]q\}}||vrqt|j�D]b\}}|\}}}	}
||\}}|r'|}
|||||	|
�}
|�|
|||||	|
f�||t|�t|�|	|
�}
|�|
|�||t|�t|�|	|
�}
|�|
|�|
duru|||||	�}
|�|
|||||	f�qq|�td��|dddd�Wd�n1s�wYd|vr�|�	t
|dddd�|�	t
|ddd	d�|�	t|dddd
�|�	t|dddd�|�	t|ddddd
�|�	t|ddddd�|dddddd
�}
|�|
|jdd
d
�dSdS)Nz.*unsupported.*�unknownspassrxr�rssha1�passrrrrw)r1�passwordrZ
iterations�dklen)�pbkdf2_resultsrg�	enumerate�pbkdf2_test_vectorsr��
memoryviewrrhrjr�r�)rKZpbkdf2Z	supportedZdigest_name�resultsr&Zvectorr~r�roundsr�expectedZoverwrite_dklenrrrr�_test_pbkdf2_hmac�sl�

�

�
������������zKDFTests._test_pbkdf2_hmacztest requires builtin_hashlibcCs<t���|�tjt�Wd�dS1swYdSrP)rZcheck_warningsr��builtin_hashlib�pbkdf2_hmacrHr\rrr�test_pbkdf2_hmac_pys

�"�zKDFTests.test_pbkdf2_hmac_pyr�z   test requires OpenSSL > 1.0cCs|�tjt�dSrP)r��openssl_hashlibr�rr\rrr�test_pbkdf2_hmac_cszKDFTests.test_pbkdf2_hmac_c�scryptz   test requires OpenSSL > 1.1zscrypt is blocked in FIPS mode)�reasonc

Cs|jD]\}}}}}}tj|||||d�}|�||�qtjdddddd�|�t��tjdddddd�Wd�n1s@wY|�t��tjdddddd�Wd�n1s_wY|�t��
t�d�Wd�n1sywY|�t��t�dd�Wd�n1s�wY|�t��tjdddddd	�Wd�n1s�wYd
D]$}|�tttf��tjdd|ddd�Wd�n1s�wYq�dD]%}|�tttf��tjddd|dd�Wd�n	1�swYq�dD]&}|�tttf��tjdddd|d�Wd�n	1�s)wY�q	dD]'}|�tttf��tjddddd|d
�Wd�n	1�sSwY�q2dD]'}	|�tttf��tjddddd|	d�Wd�n	1�s}wY�q\dS)N)r�nr%�prwrxr�r4r�r~rr)rrr�N)rrN)rN)rr�r%r��maxmem)rr�r%r�r)�scrypt_test_vectorsrr�r�r�r�rjr�)
rKr~rr�r%r�r��resultr�rrrr�test_scrypt"sb������������������zKDFTests.test_scryptcCs |�dtj�|�dtj�dS)NZ
blake2b512zsha3-512)r�rr�r\rrr�test_normalized_nameJszKDFTests.test_normalized_name)rkrlrmr�rr�r!r0r�r�r-rrr�r�rtrir�r�rrr�r�rrrrrv�sp�	��
�����
������&1
�
�%rv�__main__)3r|ZbinasciirrrDrsrnr�Z	sysconfigrXr-rIr�rZtest.supportrrZtest.support.import_helperrrrZhttp.clientr	riroZdefault_builtin_hashesZget_config_varrHrrer/r�r�rrrrrr��	frozensetrOrtrqr'r*r5ZTestCaser6rvrk�mainrrrr�<module>st

���	S$�
© 2025 GrazzMean