o
    Ìn~ba  ã                   @   sd   d dl Z d dlmZ d dlmZmZmZmZmZm	Z	 eddƒZ
dd„ Zdd	„ Zd
ZdZed dƒZdS )é    N)Ú_create_cipher)Úload_pycryptodome_raw_libÚVoidPointerÚSmartPointerÚc_size_tÚc_uint8_ptrÚc_uintz"Cryptodome.Cipher._raw_eksblowfishaa  
        int EKSBlowfish_start_operation(const uint8_t key[],
                                        size_t key_len,
                                        const uint8_t salt[16],
                                        size_t salt_len,
                                        unsigned cost,
                                        unsigned invert,
                                        void **pResult);
        int EKSBlowfish_encrypt(const void *state,
                                const uint8_t *in,
                                uint8_t *out,
                                size_t data_len);
        int EKSBlowfish_decrypt(const void *state,
                                const uint8_t *in,
                                uint8_t *out,
                                size_t data_len);
        int EKSBlowfish_stop_operation(void *state);
        c           
   
   C   sà   z|   d¡}|   d¡}|   d¡}W n ty% } ztdt|ƒ ƒ‚d}~ww |   dd¡}t|ƒtvr:tdt|ƒ ƒ‚tj}tj	}t
ƒ }|t|ƒtt|ƒƒt|ƒtt|ƒƒt|ƒtt|ƒƒ| ¡ ƒ}	|	ritd	|	 ƒ‚t| ¡ |ƒS )
zˆThis method instantiates and returns a smart pointer to
    a low-level base cipher. It will absorb named parameters in
    the process.ÚkeyÚsaltÚcostzMissing EKSBlowfish parameter: NÚinvertTz+Incorrect EKSBlowfish key length (%d bytes)z3Error %X while instantiating the EKSBlowfish cipher)ÚpopÚKeyErrorÚ	TypeErrorÚstrÚlenÚkey_sizeÚ
ValueErrorÚ_raw_blowfish_libZEKSBlowfish_start_operationZEKSBlowfish_stop_operationr   r   r   r   ÚintZ
address_ofr   Úget)
Zdict_parametersr	   r
   r   Úer   Zstart_operationZstop_operationZvoid_pÚresult© r   úI/usr/local/lib/python3.10/dist-packages/Cryptodome/Cipher/_EKSBlowfish.pyÚ_create_base_cipher=   s6   

€ÿ


úÿr   c                 C   s&   |||dœ}t tjt | |fi |¤ŽS )a‚  Create a new EKSBlowfish cipher
    
    Args:

      key (bytes, bytearray, memoryview):
        The secret key to use in the symmetric cipher.
        Its length can vary from 0 to 72 bytes.

      mode (one of the supported ``MODE_*`` constants):
        The chaining mode to use for encryption or decryption.

      salt (bytes, bytearray, memoryview):
        The salt that bcrypt uses to thwart rainbow table attacks

      cost (integer):
        The complexity factor in bcrypt

      invert (bool):
        If ``False``, in the inner loop use ``ExpandKey`` first over the salt
        and then over the key, as defined in
        the `original bcrypt specification <https://www.usenix.org/legacy/events/usenix99/provos/provos_html/node4.html>`_.
        If ``True``, reverse the order, as in the first implementation of
        `bcrypt` in OpenBSD.

    :Return: an EKSBlowfish object
    )r
   r   r   )r   ÚsysÚmodulesÚ__name__)r	   Úmoder
   r   r   Úkwargsr   r   r   Únew^   s   r!   é   é   éI   )r   ZCryptodome.Cipherr   ZCryptodome.Util._raw_apir   r   r   r   r   r   r   r   r!   ZMODE_ECBÚ
block_sizeÚranger   r   r   r   r   Ú<module>   s    þ! 