
     h                         d dl mZmZmZmZ ddlmZ ddlmZm	Z	 ddl
mZmZmZ ddlmZ ddlmZmZmZ g d	Zed
k     rddlmZ n
d Zde_        d ZdS )    )unicode_literalsdivisionabsolute_importprint_function   )pretty_message)buffer_from_bytesbytes_from_buffer   )	libcryptolibcrypto_version_infohandle_openssl_error)
rand_bytes)	type_namebyte_cls	int_types)pbkdf2
pkcs12_kdfr   )r   )r   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          d          t          |t
                    s*t          t          dt	          |                              |dk     rt          d          | t          g d          vr*t          t          d	t          |                               	 t          j
        t          j        t          j        t          j        t          j        d|                      }t          |          }t          j        |t#          |          |t#          |          ||||          }t%          |           t'          |          S )
a  
        PBKDF2 from PKCS#5

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

        :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

        :raises:
            ValueError - when any of the parameters contain an invalid value
            TypeError - when any of the parameters are of the wrong type

        :return:
            The derived key as a byte string
        zH
                password must be a byte string, not %s
                zD
                salt must be a byte string, not %s
                zG
                iterations must be an integer, not %s
                r   z!iterations must be greater than 0zG
                key_length must be an integer, not %s
                z!key_length must be greater than 0)sha1sha224sha256sha384sha512z
                hash_algorithm must be one of "sha1", "sha224", "sha256", "sha384",
                "sha512", not %s
                )
isinstancer   	TypeErrorr   r   r   
ValueErrorsetreprr   EVP_sha1
EVP_sha224
EVP_sha256
EVP_sha384
EVP_sha512r	   PKCS5_PBKDF2_HMAClenr   r
   )hash_algorithmpasswordsalt
iterations
key_lengthevp_mdoutput_bufferresults           R/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/oscrypto/_openssl/util.pyr   r      s2   6 (H-- 	N (##	     $)) 	N $	     *i00 	N *%%	     >>@AAA*i00 	N *%%	     >>@AAA%U%U%U!V!VVV^ ^$$    &****
 
    **55,MMII	
 	
 	V$$$ ///    Fc                 p   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          |                               |t          g d
          vr*t          t          dt          |                              |	                    d          
                    d          dz   }	 t          j        t          j        t          j        t          j        t          j        t          j        d|                      }t%          |          }t          j        |t)          |          |t)          |          |||||	  	        }	t+          |	           t-          |          S )a0  
    KDF from RFC7292 appendix B.2 - https://tools.ietf.org/html/rfc7292#page-19

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

    :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

    :param id_:
        The ID of the usage - 1 for key, 2 for iv, 3 for mac

    :raises:
        ValueError - when any of the parameters contain an invalid value
        TypeError - when any of the parameters are of the wrong type

    :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
            z?
            key_length must be an integer, not %s
            zC
            key_length must be greater than 0 - is %s
            )md5r   r   r   r   r   z
            hash_algorithm must be one of "md5", "sha1", "sha224", "sha256",
            "sha384", "sha512", not %s
            )r   r      z<
            id_ must be one of 1, 2, 3, not %s
            zutf-8zutf-16bes     )r   r   r   r   r   r   r   r   r   decodeencoder   EVP_md5r    r!   r"   r#   r$   r	   PKCS12_key_gen_unir&   r   r
   )
r'   r(   r)   r*   r+   id_utf16_passworddigest_typer-   r.   s
             r/   r   r   {   s   < h))  h	
 
   	 dH%%  dOO	
 
   	 j),,  j!!	
 
   	 A~~ 	
 
   	 j),,  j!!	
 
   	 A~~ 	
 
   	 S!X!X!XYYYY   
 
   	 #iii..   II	
 
   	 __W--44Z@@;NN "&&&&    K &j11M)ND		
 
F    ]+++r0   N)
__future__r   r   r   r   _errorsr   _ffir	   r
   
_libcryptor   r   r   _randr   _typesr   r   r   __all___pkcs5r   pure_pythonr    r0   r/   <module>rE      s   R R R R R R R R R R R R $ $ $ $ $ $ 7 7 7 7 7 7 7 7 O O O O O O O O O O       3 3 3 3 3 3 3 3 3 3   D  _0 _0 _0B Fx, x, x, x, x,r0   