HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/oscrypto/__pycache__/kdf.cpython-39.pyc
a

�,�h��@s*ddlmZmZmZmZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
mZmZddlmZdd	lmZmZe	�Zed
kr�ddlmZmZnBedks�ed
kr�ddlmZmZddlmZmZnddlmZmZgd�Zejdk�rdd�Z dd�Z!ndd�Z dd�Z!ddd�Z"dd�Z#dS)�)�unicode_literals�division�absolute_import�print_functionN)�datetime�)�backend)�
rand_bytes)�	type_name�byte_cls�	int_types)�pretty_message)�new�deref�mac)�pbkdf2�
pkcs12_kdf�winZ	winlegacy)�kernel32�handle_error)�pbkdf1r�pbkdf2_iteration_calculatorr�win32cCs$ttd�}t�|�}t|�t|�S)NzLARGE_INTEGER *)rrZQueryPerformanceCounterrr)�number�res�r�=/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/oscrypto/kdf.py�
_get_start$s

rcCst�|}t|d�S)Ng@�@)r�int)�start�lengthrrr�_get_elapsed*s
r!cCst��S)N)r�nowrrrrr/scCs:t��|}|j|jdd}|jd}t||d�S)N�ii�)rr"�seconds�days�microsecondsr)rr r$Zmillisecondsrrrr!2s
�dFcs*�tgd��vr"ttdt�����t�t�s>ttdt������dkrXttdt�����t�t�stttdt������dkr�ttdt�����tj	r�t
td���d	�d
�d��t����������fdd
�}|�}t
�|d��|�}�|��dkr�dnd}t
t�|��}|dk�r&|dd}|S)a�
    Runs pbkdf2() twice to determine the approximate number of iterations to
    use to hit a desired time per run. Use this on a production machine to
    dynamically adjust the number of iterations as high as you can.

    :param hash_algorithm:
        The string name of the hash algorithm to use: "md5", "sha1", "sha224",
        "sha256", "sha384", "sha512"

    :param key_length:
        The length of the desired key in bytes

    :param target_ms:
        The number of milliseconds the derivation should take

    :param quiet:
        If no output should be printed as attempts are made

    :return:
        An integer number of iterations of PBKDF2 using the specified hash
        that will take at least target_ms
    )�sha1�sha224�sha256�sha384�sha512zz
            hash_algorithm must be one of "sha1", "sha224", "sha256", "sha384",
            "sha512", not %s
            �?
            key_length must be an integer, not %s
            r�C
            key_length must be greater than 0 - is %s
            z>
            target_ms must be an integer, not %s
            zB
            target_ms must be greater than 0 - is %s
            z�
            Only a very slow, pure-python version of PBKDF2 is available,
            making this function useless
            i'zthis is a testzutf-8cs>t�}t������t|�}�s2td�|f�d�|S)Nz%s iterations in %smsg�?)rrr!�print)rZobserved_ms��hash_algorithm�
iterations�
key_length�password�quiet�salt�	target_msrr�_measure�sz-pbkdf2_iteration_calculator.<locals>._measureg@i��������i Ni�)�set�
ValueErrorr
�repr�
isinstancer�	TypeErrorr
rZpure_python�OSError�encoder	r�round)r1r3r7r5r8�fractionZround_factor�resultrr0rr9sT�
��
���


rcCsbt|t�sttdt|����t|t�s8ttdt|����t|t�sTttdt|����|dkrnttdt|����t|t�s�ttdt|����|dkr�ttdt|����|tgd��vr�ttd	t|����|d
kr�|tddg�vr�ttd
|t|�f���|dk�r|dk�rttdt|����t	t
|�}|||���}td|d�D]}||���}�qB|d|�S)aF
    An implementation of PBKDF1 - should only be used for interop with legacy
    systems, not new architectures

    :param hash_algorithm:
        The string name of the hash algorithm to use: "md2", "md5", "sha1"

    :param password:
        A byte string of the password to use an input to the KDF

    :param salt:
        A cryptographic random byte string

    :param iterations:
        The numbers of iterations to use when deriving the key

    :param key_length:
        The length of the desired key in bytes

    :return:
        The derived key as a byte string
    z@
            password must be a byte string, not %s
            z<
            salt must be a byte string, not %s
            z?
            iterations must be an integer, not %s
            rzC
            iterations must be greater than 0 - is %s
            r-r.)�md2�md5r(zT
            hash_algorithm must be one of "md2", "md5", "sha1", not %s
            �rErFzM
            key_length can not be longer than 16 for %s - is %s
            �r(zO
            key_length can not be longer than 20 for sha1 - is %s
            �N)
r>rr?r
r
rr<r=r;�getattr�hashlib�digest�range)r1r4r6r2r3�algo�output�_rrrr�sd
�
�
��
���
��
r)r'F)$�
__future__rrrr�sysrKr�r�utilr	�_typesr
rr�_errorsr
Z_ffirrZ_backendZ	_mac.utilrrZ	_win.utilZ_win._kernel32rrZ
_openssl.util�__all__�platformrr!rrrrrr�<module>s.

g