
     h                     D   d dl mZmZmZmZ d dlZd dlZd dlmZ ddlm	Z	 ddl
mZ ddlmZmZmZ ddlmZ dd	lmZmZ  e	            Zed
k    r	ddlmZmZ n%edk    sedk    rddlmZmZ ddlmZmZ nddlmZmZ g dZej        dk    rd Z d Z!nd Z d Z!ddZ"d Z#dS )    )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win	winlegacy)kernel32handle_error)pbkdf1r   pbkdf2_iteration_calculatorr   win32c                      t          t          d          } t          j        |           }t          |           t	          |           S )NzLARGE_INTEGER *)r   r   QueryPerformanceCounterr   r   )numberress     H/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/oscrypto/kdf.py
_get_startr    $   s<    X011.v66SV}}    c                 H    t                      | z
  }t          |dz            S )Ng     @@)r    int)startlengths     r   _get_elapsedr&   *   s"    %6F?###r!   c                  (    t          j                    S )N)r   now r!   r   r    r    /   s    |~~r!   c                     t          j                    | z
  }|j        |j        dz  dz  z   }|j        dz  }t          ||dz  z             S )N   i  i  )r   r(   secondsdaysmicrosecondsr#   )r$   r%   r,   millisecondss       r   r&   r&   2   sO    %'.FK"$4t$;<+g5<7W#45666r!   d   Fc                    	
  t          g d          vr*t          t          dt                                         t	          t
                    s*t          t          dt                                        dk     r*t          t          dt                                        t	          t
                    s*t          t          dt                                        dk     r*t          t          dt                                        t          j	        rt          t          d                    d	d
                    d          	t                    
 	
fd} |            }t          |z  dz             |            }|z  dk     rdnd}t          t          |                    }|dk    r|dz  dz  }|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'  zthis is a testzutf-8c                      t                      } t                     t          |           }st          d|d           dz  |z  S )Nz iterations in msg      ?)r    r   r&   print)	r$   observed_mshash_algorithm
iterations
key_lengthpasswordquietsalt	target_mss	     r   _measurez-pbkdf2_iteration_calculator.<locals>._measure   sb    ~xz:FFF"5)) 	GZZZEFFFY,,r!   g       @i i N  i  )set
ValueErrorr   repr
isinstancer   	TypeErrorr   r   pure_pythonOSErrorencoder
   r#   round)r=   r?   rC   rA   rD   fractionround_factorresultr>   r@   rB   s   ````    @@@r   r   r   9   s`   0 S!Q!Q!QRRRR   
 
   	 j),,  j!!	
 
   	 A~~ 	
 
   	 i++  i  	
 
   	 1}} OO	
 
   	  n
 
   	 J&&w//Hj!!D- - - - - - - - - - - xzzHZ(*S011JxzzHh&J
 $f,,22"Lz<0011F~~D.D(Mr!   c           	         t          |t                    s*t          t          dt	          |                              t          |t                    s*t          t          dt	          |                              t          |t
                    s*t          t          dt	          |                              |dk     r*t          t          dt          |                              t          |t
                    s*t          t          dt	          |                              |dk     r*t          t          dt          |                              | t          g d          vr*t          t          d	t          |                               |d
k    r?| t          ddg          v r,t          t          d| t          |          f                    |dk    r0| dk    r*t          t          dt          |                              t          t          |           } |||z                                             }t          d|dz             D ]} ||                                          } |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
            r   zC
            iterations must be greater than 0 - is %s
            r7   r8   )md2md5r2   zT
            hash_algorithm must be one of "md2", "md5", "sha1", not %s
               rT   rU   zM
            key_length can not be longer than 16 for %s - is %s
               r2   zO
            key_length can not be longer than 20 for sha1 - is %s
               N)rJ   r   rK   r   r   r   rH   rI   rG   getattrhashlibdigestrange)r=   r@   rB   r>   r?   algooutput_s           r   r   r      s   0 h))  x  	
 
   	 dH%%  t__	
 
   	 j),,  z""	
 
   	 A~~ 	
 
   	 j),,  z""	
 
   	 A~~ 	
 
   	 S!7!7!78888   	
 
   	 B>S%-@-@@@ T*--.	
 
   	 B>V33 	
 
   	 7N++DT(T/""))++F1j1n%% ' 'f$$&&+:+r!   )r0   F)$
__future__r   r   r   r   sysrZ   r    r	   utilr
   _typesr   r   r   _errorsr   _ffir   r   _backend	_mac.utilr   r   	_win.util_win._kernel32r   r   _openssl.util__all__platformr    r&   r   r   r)   r!   r   <module>rn      s   R R R R R R R R R R R R 



                    2 2 2 2 2 2 2 2 2 2 # # # # # #         799 u---------(k11--------66666666611111111   <7  $ $ $ $
  7 7 7d d d dNe e e e er!   