Your IP : 3.15.18.73


Current Path : /opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/IO/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/IO/__pycache__/_PBES.cpython-311.pyc

�

O�Dg�?���ddlmZddlmZmZmZmZddlmZm	Z	ddl
mZmZm
Z
mZmZmZddlmZmZmZmZddlmZmZmZdZdZd	Zd
ZdZdZd
Z dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)Gd�de*��Z+Gd�de,��Z-Gd�de,��Z.dS)�)�Random)�DerSequence�DerOctetString�DerObjectId�
DerInteger)�pad�unpad)�MD5�SHA1�SHA224�SHA256�SHA384�SHA512)�DES�ARC2�DES3�AES)�PBKDF1�PBKDF2�scryptz1.2.840.113549.1.5.3z1.2.840.113549.1.5.6z1.2.840.113549.1.5.10z1.2.840.113549.1.5.11z1.2.840.113549.1.5.13z1.2.840.113549.1.5.12z1.3.6.1.4.1.11591.4.11�1.2.840.113549.2.7z1.2.840.113549.2.8z1.2.840.113549.2.9z1.2.840.113549.2.10z1.2.840.113549.2.11z1.2.840.113549.3.7z2.16.840.1.101.3.4.1.2z2.16.840.1.101.3.4.1.22z2.16.840.1.101.3.4.1.42c��eZdZdS)�	PbesErrorN)�__name__�
__module__�__qualname__���q/builddir/build/BUILD/imunify360-venv-2.4.0/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/IO/_PBES.pyrrCs�������Drrc�(�eZdZdZed���ZdS)�PBES1z�Deprecated encryption scheme with password-based key derivation
    (originally defined in PKCS#5 v1.5, but still present in `v2.0`__).

    .. __: http://www.ietf.org/rfc/rfc2898.txt
    c���t���|��}t���|d��}t���|d��j}t	���|d��j}i}|tkrt}t}ng|tkrt}t}d|d<nH|tkrt}t}n.|tkrt}t}d|d<ntd���t���|dd���}	t���|	d��j}
|	d}t||
d||��}|d	d
�|d
d	�}}
|j|
|j|fi|��}|�|��}t'||j��S)axDecrypt a piece of data using a passphrase and *PBES1*.

        The algorithm to use is automatically detected.

        :Parameters:
          data : byte string
            The piece of data to decrypt.
          passphrase : byte string
            The passphrase to use for decrypting the data.
        :Returns:
          The decrypted data, as a binary string.
        r��@�effective_keylenzUnknown OID for PBES1���nr_elements�N�)r�decoder�payloadr�value�_OID_PBE_WITH_MD5_AND_DES_CBCr
r�_OID_PBE_WITH_MD5_AND_RC2_CBCr�_OID_PBE_WITH_SHA1_AND_DES_CBCr�_OID_PBE_WITH_SHA1_AND_RC2_CBCrr�new�MODE_CBC�decryptr	�
block_size)�data�
passphrase�enc_private_key_info�encrypted_algorithm�encrypted_data�pbe_oid�
cipher_params�hashmod�	ciphermod�
pbe_params�salt�
iterations�key_iv�key�iv�cipher�pts                 rr4z
PBES1.decryptys��� +�}�}�3�3�D�9�9��)�m�m�2�2�3G��3J�K�K��'�)�)�0�0�1E�a�1H�I�I�Q���-�-�&�&�':�1�'=�>�>�D���
��3�3�3��G��I�I�
�5�
5�
5��G��I�02�M�,�-�-�
�6�
6�
6��G��I�I�
�6�
6�
6��G��I�02�M�,�-�-��3�4�4�4� �]�]�)�)�*=�a�*@�a�)�P�P�
����&�&�z�!�}�5�5�=����]�
��
�D�"�j�'�B�B����!��*�f�Q�R�R�j�R�����s�I�$6��L�L�m�L�L��
�^�^�N�
+�
+���R��*�+�+�+rN)rrr�__doc__�staticmethodr4rrrr!r!rs9���������2,�2,��\�2,�2,�2,rr!c�@�eZdZdZedd���Zed���ZdS)�PBES2z�Encryption scheme with password-based key derivation
    (defined in `PKCS#5 v2.0`__).

    .. __: http://www.ietf.org/rfc/rfc2898.txt.Nc���|�i}|�tj��j}|dkrd}t}tj}t
}nr|dvrd}t}tj}t}nQ|dvrd}t}tj}t}n0|dvrd}t}tj}t}ntd	���||j��}	||�d
d����}
|�
d��ru|�d
d��}t||
||��}tt!t"��tt%|
��t'|��g��g��}
n�|�d
d��}|�dd��}|�dd��}t)||
||||��}tt!t*��tt%|
��t'|��t'|��t'|��g��g��}
|�|||	��}|�t/||j����}tt!|��t%|	��g��}ttt!t0��t|
|g��g��t%|��g��}|���S)a�	Encrypt a piece of data using a passphrase and *PBES2*.

        :Parameters:
          data : byte string
            The piece of data to encrypt.
          passphrase : byte string
            The passphrase to use for encrypting the data.
          protection : string
            The identifier of the encryption algorithm to use.
            The default value is '``PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC``'.
          prot_params : dictionary
            Parameters of the protection algorithm.

            +------------------+-----------------------------------------------+
            | Key              | Description                                   |
            +==================+===============================================+
            | iteration_count  | The KDF algorithm is repeated several times to|
            |                  | slow down brute force attacks on passwords    |
            |                  | (called *N* or CPU/memory cost in scrypt).    |
            |                  |                                               |
            |                  | The default value for PBKDF2 is 1 000.        |
            |                  | The default value for scrypt is 16 384.       |
            +------------------+-----------------------------------------------+
            | salt_size        | Salt is used to thwart dictionary and rainbow |
            |                  | attacks on passwords. The default value is 8  |
            |                  | bytes.                                        |
            +------------------+-----------------------------------------------+
            | block_size       | *(scrypt only)* Memory-cost (r). The default  |
            |                  | value is 8.                                   |
            +------------------+-----------------------------------------------+
            | parallelization  | *(scrypt only)* CPU-cost (p). The default     |
            |                  | value is 1.                                   |
            +------------------+-----------------------------------------------+


          randfunc : callable
            Random number generation function; it should accept
            a single integer N and return a string of random data,
            N bytes long. If not specified, a new RNG will be
            instantiated from ``Crypto.Random``.

        :Returns:
          The encrypted data, as a binary string.
        Nz"PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC�)z PBKDF2WithHMAC-SHA1AndAES128-CBCzscryptAndAES128-CBCr))z PBKDF2WithHMAC-SHA1AndAES192-CBCzscryptAndAES192-CBC)z PBKDF2WithHMAC-SHA1AndAES256-CBCzscryptAndAES256-CBC� zUnknown PBES2 mode�	salt_sizer*r�iteration_counti�i@r5�parallelizationr#)rr2�readrr3�_OID_DES_EDE3_CBCr�_OID_AES128_CBC�_OID_AES192_CBC�_OID_AES256_CBC�
ValueErrorr5�get�
startswithrrr�_OID_PBKDF2rrr�_OID_SCRYPT�encryptr�
_OID_PBES2�encode)r6r7�
protection�prot_params�randfunc�key_size�module�cipher_mode�enc_oidrDr@�countrC�kdf_info�scrypt_r�scrypt_prEr:�enc_infor8s                    rr[z
PBES2.encrypt�s��^���K����z�|�|�(�H��=�=�=��H��F��-�K�'�G�G�
�'�'�'��H��F��,�K�%�G�G�
�'�'�'��H��F��,�K�%�G�G�
�'�'�'��H��F��,�K�%�G�G��1�2�2�2��X�f�'�
(�
(���x�����Q�7�7�8�8��� � ��*�*�	��O�O�$5�t�<�<�E���T�8�U�;�;�C�"���,�,��&�t�,�,�"�5�)�)�!���$���H�H� �O�O�$5�u�=�=�E�"���|�Q�7�7�H�"���'8�!�<�<�H���T�8���(�4�4�C�"���,�,��&�t�,�,�"�5�)�)�"�8�,�,�"�8�,�,�	!���$���H����C��b�1�1������D�&�2C�(D�(D�E�E����G�$�$��r�"�"� 
���� +���J�'�'��������
�
�
�>�*�*�
,
�
 �
 ��$�*�*�,�,�,rc�	��t���|d���}t���|d��}t���|d��j}t	���|d��j}|tkrtd���t���|dd���}t���|dd���}t	���|d��j}d}	|tkr�t���|dd���}
t���|
d��j}|
d}t|
��dz
}
d}|
dkr'	|
|dz
}	|
dz}
|dz
}n#t$rYnwxYwd}|
dkrSt���|
|��}t	���|d��j}n�|tkr�t���|dd	����t����d��j}�fd
�dD��\}}}t���dkr	�d}	nd}	ntd
���t���|d��}t	���|d��j}|tkr
t}d}nN|tkr
t}d}n9|t kr
t}d}n$|t"kr
t}d}ntd���|	r|	|krtd���t���|d��j}|tkr�|t$krt&}n^|t(krt*}nK|t,krt.}n8|t0krt2}n%|t4krt6}ntd|z���t9|||||���}nt;||||||��}|�||j|��}|� |��}tC||j"��S)axDecrypt a piece of data using a passphrase and *PBES2*.

        The algorithm to use is automatically detected.

        :Parameters:
          data : byte string
            The piece of data to decrypt.
          passphrase : byte string
            The passphrase to use for decrypting the data.
        :Returns:
          The decrypted data, as a binary string.
        r&r'rr#zNot a PBES2 objectN)r&��r)rl�c� ��g|]
}�|��Srr)�.0�x�
scrypt_paramss  �r�
<listcomp>z!PBES2.decrypt.<locals>.<listcomp>us5���3G�3G�3G�78�4A��3C�3G�3G�3Gr)r#r&rkrlzUnsupported PBES2 KDFrLr)rMzUnsupported PBES2 cipherz9Mismatch between PBES2 KDF parameters and selected cipherzUnsupported HMAC %s)�hmac_hash_module)#rr+rr,rr-r\rrY�len�	TypeErrorrZrRrrSrrTrU�_OID_HMAC_SHA1r�_OID_HMAC_SHA224r�_OID_HMAC_SHA256r
�_OID_HMAC_SHA384r�_OID_HMAC_SHA512rrrr2r3r4r	r5)r6r7r8�enc_algor:r;�pbes2_paramsrf�kdf_oid�kdf_key_length�
pbkdf2_paramsr@rO�left�idx�pbkdf2_prf_oid�pbkdf2_prf_algo_idrgrhrirdr>ra�IVrsrCrErFrqs                            @rr4z
PBES2.decrypt:s���� +�}�}�3�3�D�a�3�H�H���=�=�'�'�(<�Q�(?�@�@��'�)�)�0�0�1E�a�1H�I�I�Q���-�-�&�&�x��{�3�3�9���j� � ��0�1�1�1�"�}�}�+�+�H�Q�K�Q�+�G�G���=�=�'�'��Q��Q�'�G�G���-�-�&�&�x��{�3�3�9�����k�!�!�'�M�M�0�0��!��)�0�T�T�M�!�#�#�*�*�=��+;�<�<�D�D�+�A�.�O��}�%�%��)�D��C��a�x�x��%2�3�%7�!�%;�N��A�I�D��1�H�C�C�� �����D�����2�N��a�x�x�%0�]�]�%9�%9�-��:L�%M�%M�"�!,���!5�!5�6H��6K�!L�!L�!R���
��
#�
#�'�M�M�0�0��!��&�0�Q�Q�M�!�#�#�*�*�=��+;�<�<�D�D�3G�3G�3G�3G�<E�3G�3G�3G�/�O�X�x��=�!�!�A�%�%�!.�q�!1���!%����3�4�4�4��=�=�'�'��Q��8�8���-�-�&�&�x��{�3�3�9���'�'�'��I��H�H�
��
'�
'��I��H�H�
��
'�
'��I��H�H�
��
'�
'��I��H�H��6�7�7�7��	4�n��8�8��3�4�4�
4��
�
�
$�
$�X�a�[�
1�
1�
9���k�!�!���/�/�#'� � ��#3�3�3�#)� � ��#3�3�3�#)� � ��#3�3�3�#)� � ��#3�3�3�#)� � �� 5�� F�G�G�G���T�8�_�*:�<�<�<�C�C���T�8�_�!�8�-�-�C����s�I�$6��;�;���^�^�N�
+�
+���R��*�+�+�+s�G�
G$�#G$)NN)rrrrGrHr[r4rrrrJrJ�sc������3�3�
�B-�B-�B-��\�B-�H�x,�x,��\�x,�x,�x,rrJN)/�Cryptor�Crypto.Util.asn1rrrr�Crypto.Util.Paddingrr	�Crypto.Hashr
rrr
rr�
Crypto.Cipherrrrr�Crypto.Protocol.KDFrrrr.r/r0r1r\rYrZrvrwrxryrzrRrSrTrUrVr�objectr!rJrrr�<module>r�s���D������������������
+�*�*�*�*�*�*�*�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�A�.�.�.�.�.�.�.�.�.�.�.�.�6�6�6�6�6�6�6�6�6�6� 6�� 6��!8��!8��
$�
�%��&��%��'��'��(��(��(��*��+��+��	�	�	�	�	�
�	�	�	�^:,�:,�:,�:,�:,�F�:,�:,�:,�zD,�D,�D,�D,�D,�F�D,�D,�D,�D,�D,r

?>