§
    8·tc¹M  ã                   ó2  — d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
mZ d dlmZmZmZmZ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mZmZmZ  ed	d
¦  «        Z  edd¦  «        Z!dd„Z"dd„Z# G d„ de$¦  «        Z%dd„Z&dd„Z'd„ Z(d„ Z)d„ Z*dd„Z+d„ Z,dS ) é    N)Úreduce)ÚtobytesÚbordÚ_copy_bytesÚ
iter_rangeÚtostrÚbchrÚbstr)ÚSHA1ÚSHA256ÚHMACÚCMACÚBLAKE2s)Ústrxor)Úget_random_bytes)ÚsizeÚlong_to_bytesÚbytes_to_long)Úload_pycryptodome_raw_libÚcreate_string_bufferÚget_raw_bufferÚc_size_tzCryptodome.Cipher._Salsa20z–
                    int Salsa20_8_core(const uint8_t *x, const uint8_t *y,
                                       uint8_t *out);
                    zCryptodome.Protocol._scrypta  
                    typedef int (core_t)(const uint8_t [64], const uint8_t [64], uint8_t [64]);
                    int scryptROMix(const uint8_t *data_in, uint8_t *data_out,
                           size_t data_len, unsigned N, core_t *core);
                    éè  c                 ó´  — |st           }t          | ¦  «        } |                     | |z   ¦  «        }|j        }||k    rt	          d|z  ¦  «        ‚t          |¦  «        dk    rt          dt          |¦  «        z  ¦  «        ‚t          |dz
  ¦  «        D ])}|                     |                     ¦   «         ¦  «        }Œ*|                     ¦   «         d|…         S )aY  Derive one key from a password (or passphrase).

    This function performs key derivation according to an old version of
    the PKCS#5 standard (v1.5) or `RFC2898
    <https://www.ietf.org/rfc/rfc2898.txt>`_.

    Args:
     password (string):
        The secret password to generate the key from.
     salt (byte string):
        An 8 byte string to use for better protection from dictionary attacks.
        This value does not need to be kept secret, but it should be randomly
        chosen for each derivation.
     dkLen (integer):
        The length of the desired key. The default is 16 bytes, suitable for
        instance for :mod:`Cryptodome.Cipher.AES`.
     count (integer):
        The number of iterations to carry out. The recommendation is 1000 or
        more.
     hashAlgo (module):
        The hash algorithm to use, as a module or an object from the :mod:`Cryptodome.Hash` package.
        The digest length must be no shorter than ``dkLen``.
        The default algorithm is :mod:`Cryptodome.Hash.SHA1`.

    Return:
        A byte string of length ``dkLen`` that can be used as key.
    z:Selected hash algorithm has a too short digest (%d bytes).é   z,Salt is not 8 bytes long (%d bytes instead).é   N)	r   r   ÚnewÚdigest_sizeÚ	TypeErrorÚlenÚ
ValueErrorr   Údigest)ÚpasswordÚsaltÚdkLenÚcountÚhashAlgoÚpHashr"   Úis           ú9/usr/lib/python3/dist-packages/Cryptodome/Protocol/KDF.pyÚPBKDF1r+   7   sÏ   € ð: ð ÝˆÝ�xÑ Ô €HØ�LŠL˜ $™Ñ'Ô'€EØÔ€FØˆv‚~€~ÝÐTÐW]Ñ]Ñ^Ô^Ð^Ý
ˆ4�y„y�A‚~€~ÝÐGÍ#ÈdÉ)Ì)ÑSÑTÔTÐTÝ˜˜a™Ñ Ô ð *ð *ˆØ—	’	˜%Ÿ,š,™.œ.Ñ)Ô)ˆˆØ�<Š<‰>Œ>˜&˜5˜&Ô!Ð!ó    é   c                 ó@  ‡ ‡‡‡
‡— t          ‰ ¦  «        Š t          |¦  «        }‰r‰rt          d¦  «        ‚‰€	‰€t          Š‰st          ‰d¦  «        s•‰€ˆfd„Šˆ ˆfd„Š
d}d}t	          |¦  «        |k     rp ‰‰ |t          j        d|¦  «        z   ¦  «        gd	z  Š|t          t          ˆ
ˆfd
„t          |¦  «        D ¦   «         ¦  «        z  }|dz  }t	          |¦  «        |k     °pn­d}d}t	          |¦  «        |k     r–t          j        ‰ d‰¦  «        }|                     ¦   «                              |t          j        d|¦  «        z   ¦  «                             ¦   «         }	||                     |	|¦  «        z  }|dz  }t	          |¦  «        |k     °–|d|…         S )a   Derive one or more keys from a password (or passphrase).

    This function performs key derivation according to the PKCS#5 standard (v2.0).

    Args:
     password (string or byte string):
        The secret password to generate the key from.
     salt (string or byte string):
        A (byte) string to use for better protection from dictionary attacks.
        This value does not need to be kept secret, but it should be randomly
        chosen for each derivation. It is recommended to use at least 16 bytes.
     dkLen (integer):
        The cumulative length of the keys to produce.

        Due to a flaw in the PBKDF2 design, you should not request more bytes
        than the ``prf`` can output. For instance, ``dkLen`` should not exceed
        20 bytes in combination with ``HMAC-SHA1``.
     count (integer):
        The number of iterations to carry out. The higher the value, the slower
        and the more secure the function becomes.

        You should find the maximum number of iterations that keeps the
        key derivation still acceptable on the slowest hardware you must support.

        Although the default value is 1000, **it is recommended to use at least
        1000000 (1 million) iterations**.
     prf (callable):
        A pseudorandom function. It must be a function that returns a
        pseudorandom byte string from two parameters: a secret and a salt.
        The slower the algorithm, the more secure the derivation function.
        If not specified, **HMAC-SHA1** is used.
     hmac_hash_module (module):
        A module from ``Cryptodome.Hash`` implementing a Merkle-Damgard cryptographic
        hash, which PBKDF2 must use in combination with HMAC.
        This parameter is mutually exclusive with ``prf``.

    Return:
        A byte string of length ``dkLen`` that can be used as key material.
        If you want multiple keys, just break up this string into segments of the desired length.
    z2'prf' and 'hmac_hash_module' are mutually exlusiveNÚ_pbkdf2_hmac_assistc                 óT   •— t          j        | |‰¦  «                             ¦   «         S ©N)r   r   r"   )ÚpÚsÚhmac_hash_modules     €r*   ú<lambda>zPBKDF2.<locals>.<lambda>™   s"   ø€ �dœh q¨!Ð-=Ñ>Ô>×EÒEÑGÔG€ r,   c                 óV   •— | d          ‰‰| d         ¦  «        c| d<   | d<   | d         S )Nr   r   © )r3   r#   Úprfs    €€r*   ÚlinkzPBKDF2.<locals>.link›   s3   ø€ Ø˜1œ˜s˜s 8¨Q¨q¬TÑ2Ô2ˆJˆAˆa‰D�!�A‘$Ø�Q”4ˆKr,   r,   r   z>Ié   c              3   ó.   •K  — | ]} ‰‰¦  «        V — Œd S r1   r7   )Ú.0Újr9   r3   s     €€r*   ú	<genexpr>zPBKDF2.<locals>.<genexpr>£   s+   øè è € Ð"AÐ"A¨q 4 4¨¡7¤7Ð"AÐ"AÐ"AÐ"AÐ"AÐ"Ar,   )r   r!   r   Úhasattrr    ÚstructÚpackr   r   Úranger   r   ÚcopyÚupdater"   r/   )r#   r$   r%   r&   r8   r4   Úkeyr)   ÚbaseÚfirst_digestr9   r3   s   `   ``    @@r*   ÚPBKDF2rH   b   sã  øøøøø€ õT �xÑ Ô €HÝ�4‰=Œ=€Dà
ð OÐð OÝÐMÑNÔNÐNà
€{Ð'Ð/ÝÐà
ð •'Ð*Ð,AÑBÔBð ð ˆ;ØGÐGÐGÐGˆCð	ð 	ð 	ð 	ð 	ð 	ð ˆØˆÝ�#‰hŒh˜ÒÐØ�#�h ¥v¤{°4¸Ñ';Ô';Ñ ;Ñ<Ô<Ð>ÀÑBˆAØ•6�&Ð"AÐ"AÐ"AÐ"AÐ"AµE¸%±L´LÐ"AÑ"AÔ"AÑCÔCÑCˆCØ�‰FˆAõ �#‰hŒh˜ÒÐøð ˆØˆÝ�#‰hŒh�uŠnˆnÝ”8˜H cÐ+;Ñ<Ô<ˆDØŸ9š9™;œ;×-Ò-¨dµV´[ÀÀqÑ5IÔ5IÑ.IÑJÔJ×QÒQÑSÔSˆLØ�4×+Ò+¨L¸%Ñ@Ô@Ñ@ˆCØ�‰FˆAõ	 �#‰hŒh�uŠnˆnð ˆv�ˆvŒ;Ðr,   c                   óB   — e Zd ZdZdd„Zed„ ¦   «         Zd„ Zd„ Zd„ Z	dS )	Ú_S2VzÝString-to-vector PRF as defined in `RFC5297`_.

    This class implements a pseudorandom function family
    based on CMAC that takes as input a vector of strings.

    .. _RFC5297: http://tools.ietf.org/html/rfc5297
    Nc                 óÎ   — t          dd|¦  «        | _        || _        d|j        z  x| _        | _        |j        dz  dz
  | _        |€	i | _        dS t          |¦  «        | _        dS )a‚  Initialize the S2V PRF.

        :Parameters:
          key : byte string
            A secret that can be used as key for CMACs
            based on ciphers from ``ciphermod``.
          ciphermod : module
            A block cipher module from `Cryptodome.Cipher`.
          cipher_params : dictionary
            A set of extra parameters to use to create a cipher instance.
        Nó    r   r   )	r   Ú_keyÚ
_ciphermodÚ
block_sizeÚ_last_stringÚ_cacheÚ
_n_updatesÚ_cipher_paramsÚdict)ÚselfrE   Ú	ciphermodÚcipher_paramss       r*   Ú__init__z_S2V.__init__¼   su   € õ    d¨CÑ0Ô0ˆŒ	Ø#ˆŒØ*1°IÔ4HÑ*HÐHˆÔ˜DœKð $Ô.°Ñ2°QÑ6ˆŒàÐ Ø"$ˆDÔÐÐå"& }Ñ"5Ô"5ˆDÔÐÐr,   c                 ó"   — t          | |¦  «        S )a  Create a new S2V PRF.

        :Parameters:
          key : byte string
            A secret that can be used as key for CMACs
            based on ciphers from ``ciphermod``.
          ciphermod : module
            A block cipher module from `Cryptodome.Cipher`.
        )rJ   )rE   rV   s     r*   r   z_S2V.newÕ   s   € õ �C˜Ñ#Ô#Ð#r,   c                 óÆ   — t          |¦  «        dz  }t          |d         ¦  «        dz  r|dz  }t          |t          |¦  «        ¦  «        t          |¦  «         d …         S )Nr   r   é€   é‡   )r   r   r   r    )rU   ÚbsÚdoubleds      r*   Ú_doublez_S2V._doubleâ   s[   € Ý Ñ#Ô# QÑ&ˆÝ��1”‰;Œ;˜Ñð 	Ø�t‰OˆGÝ˜W¥c¨"¡g¤gÑ.Ô.µ°B±´¨x¨y¨yÔ9Ð9r,   c                 ó\  — | j         dk    rt          d¦  «        ‚| xj         dz  c_         t          j        | j        | j        | j        | j        ¬¦  «        }t          |  	                    | j
        ¦  «        |                     ¦   «         ¦  «        | _
        t          dd|¦  «        | _        dS )ad  Pass the next component of the vector.

        The maximum number of components you can pass is equal to the block
        length of the cipher (in bits) minus 1.

        :Parameters:
          item : byte string
            The next component of the vector.
        :Raise TypeError: when the limit on the number of components has been reached.
        r   z!Too many components passed to S2Vr   ©ÚmsgrV   rW   N)rR   r   r   r   rM   rP   rN   rS   r   r_   rQ   r"   r   )rU   ÚitemÚmacs      r*   rD   z_S2V.updateè   sž   € ð Œ?˜aÒÐÝÐ?Ñ@Ô@Ð@ØˆŒ˜1ÑˆŒåŒh�t”yØÔ,Ø!%¤Ø%)Ô%8ð:ñ :ô :ˆõ ˜TŸ\š\¨$¬+Ñ6Ô6¸¿
º
¹¼ÑEÔEˆŒÝ'¨¨d°DÑ9Ô9ˆÔÐÐr,   c                 óˆ  — t          | j        ¦  «        dk    r3| j        dd…         t          | j        dd…         | j        ¦  «        z   }n=| j        dz   dz   dd…         }t          ||                      | j        ¦  «        ¦  «        }t          j        | j        || j        | j	        ¬¦  «        }| 
                    ¦   «         S )z„"Derive a secret from the vector of components.

        :Return: a byte string, as long as the block length of the cipher.
        r-   Niðÿÿÿó   €s                  ra   )r    rP   r   rQ   r_   r   r   rM   rN   rS   r"   )rU   ÚfinalÚpaddedrd   s       r*   Úderivez_S2V.deriveÿ   s¼   € õ ˆtÔ Ñ!Ô! RÒ'Ð'àÔ% d s dÔ+­f°TÔ5FÀsÀtÀtÔ5LÈdÌkÑ.ZÔ.ZÑZˆEˆEð Ô'¨'Ñ1°LÑ@À#À2À#ÔFˆFÝ˜6 4§<¢<°´Ñ#<Ô#<Ñ=Ô=ˆEÝŒh�t”yØ Ø!%¤Ø%)Ô%8ð:ñ :ô :ˆð �zŠz‰|Œ|Ðr,   r1   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__rX   Ústaticmethodr   r_   rD   ri   r7   r,   r*   rJ   rJ   ³   sz   € € € € € ðð ð6ð 6ð 6ð 6ð2 ð
$ð 
$ñ „\ð
$ð:ð :ð :ð:ð :ð :ð.ð ð ð ð r,   rJ   r   c                 ór  ‡‡— ‰|z  }|d|j         z  k    rt          d¦  «        ‚|s
d|j         z  }|€d}t          j        || |¬¦  «        }|                     ¦   «         }dg}	d}
d}||k     rrt          j        ||	d	         |z   t          j        d
|
¦  «        z   |¬¦  «        }|	                     |                     ¦   «         ¦  «         ||j         z  }|
dz  }
||k     °rd                     |	¦  «        Š|dk    r
‰d‰…         S ˆˆfd„t          d|‰¦  «        D ¦   «         }t          |d|…         ¦  «        S )a›  Derive one or more keys from a master secret using
    the HMAC-based KDF defined in RFC5869_.

    Args:
     master (byte string):
        The unguessable value used by the KDF to generate the other keys.
        It must be a high-entropy secret, though not necessarily uniform.
        It must not be a password.
     salt (byte string):
        A non-secret, reusable value that strengthens the randomness
        extraction step.
        Ideally, it is as long as the digest size of the chosen hash.
        If empty, a string of zeroes in used.
     key_len (integer):
        The length in bytes of every derived key.
     hashmod (module):
        A cryptographic hash algorithm from :mod:`Cryptodome.Hash`.
        :mod:`Cryptodome.Hash.SHA512` is a good choice.
     num_keys (integer):
        The number of keys to derive. Every key is :data:`key_len` bytes long.
        The maximum cumulative length of all keys is
        255 times the digest size.
     context (byte string):
        Optional identifier describing what the keys are used for.

    Return:
        A byte string or a tuple of byte strings.

    .. _RFC5869: http://tools.ietf.org/html/rfc5869
    éÿ   zToo much secret data to deriverL   Nr,   )Ú	digestmodr   r   éÿÿÿÿÚBc                 ó*   •— g | ]}‰||‰z   …         ‘ŒS r7   r7   )r<   ÚidxÚderived_outputÚkey_lens     €€r*   ú
<listcomp>zHKDF.<locals>.<listcomp>K  s7   ø€ ð :ð :ð :Øð ˜#˜c G™mÐ+Ô,ð :ð :ð :r,   )r   r!   r   r   r"   r@   rA   ÚappendÚjoinr   Úlist)Úmasterrw   r$   ÚhashmodÚnum_keysÚcontextÚ
output_lenÚhmacÚprkÚtÚnÚtlenÚkolrv   s    `           @r*   ÚHKDFr‡     sy  øø€ ð@ ˜8Ñ#€JØ�S˜7Ô.Ñ.Ò/Ð/ÝÐ9Ñ:Ô:Ð:Øð -Ø˜Ô,Ñ,ˆØ€Øˆõ Œ8�D˜&¨GÐ4Ñ4Ô4€DØ
�+Š+‰-Œ-€Cð ˆ€AØ	€AØ€DØ
�Ò
Ð
ÝŒx˜˜Q˜rœU W™_­v¬{¸3ÀÑ/BÔ/BÑBÈgÐVÑVÔVˆØ	�Š�—’‘”ÑÔÐØ�Ô#Ñ#ˆØ	ˆQ‰ˆð	 �Ò
Ð
ð
 —X’X˜a‘[”[€NØ�1‚}€}Ø˜h˜w˜hÔ'Ð'ð:ð :ð :ð :ð :Ý   J°Ñ8Ô8ð:ñ :ô :€Cå��I�X�I”ÑÔÐr,   c           	      óÎ  ‡‡— dt          |¦  «        dz
  z  |k    rt          d¦  «        ‚|dk    rt          d¦  «        ‚|dd|z  z  k    rt          d¦  «        ‚d	„ }t          | ||dz  |z  d|¬
¦  «        }t          j        }	t
          j        }
g }t          |¦  «        D ]p}|dz  |z  }t          d|z  ¦  «        } |	|||d|z  z   …         |t          d|z  ¦  «        ||
¦  «        }|rt          d|z  ¦  «        ‚|t          |¦  «        gz  }Œqt          | d                     |¦  «        ‰|z  d|¬
¦  «        Š|dk    r‰S ˆˆfd„t          d‰|z  ‰¦  «        D ¦   «         }|S )uH  Derive one or more keys from a passphrase.

    Args:
     password (string):
        The secret pass phrase to generate the keys from.
     salt (string):
        A string to use for better protection from dictionary attacks.
        This value does not need to be kept secret,
        but it should be randomly chosen for each derivation.
        It is recommended to be at least 16 bytes long.
     key_len (integer):
        The length in bytes of every derived key.
     N (integer):
        CPU/Memory cost parameter. It must be a power of 2 and less
        than :math:`2^{32}`.
     r (integer):
        Block size parameter.
     p (integer):
        Parallelization parameter.
        It must be no greater than :math:`(2^{32}-1)/(4r)`.
     num_keys (integer):
        The number of keys to derive. Every key is :data:`key_len` bytes long.
        By default, only 1 key is generated.
        The maximum cumulative length of all keys is :math:`(2^{32}-1)*32`
        (that is, 128TB).

    A good choice of parameters *(N, r , p)* was suggested
    by Colin Percival in his `presentation in 2009`__:

    - *( 2Â¹â�´, 8, 1 )* for interactive logins (â‰¤100ms)
    - *( 2Â²â�°, 8, 1 )* for file encryption (â‰¤5s)

    Return:
        A byte string or a tuple of byte strings.

    .. __: http://www.tarsnap.com/scrypt/scrypt-slides.pdf
    r:   r   zN must be a power of 2l        zN is too bigl   àÿ r[   zp or r are too bigc                 ó\   — t          j        | |t          ¦  «                             ¦   «         S r1   )r   r   r   r"   )r2   r3   s     r*   r5   zscrypt.<locals>.<lambda>  s    € ¥4¤8¨A¨qµ&Ñ#9Ô#9×#@Ò#@Ñ#BÔ#B€ r,   )r8   zError %X while running scryptr,   c                 ó*   •— g | ]}‰||‰z   …         ‘ŒS r7   r7   )r<   ru   Údkrw   s     €€r*   rx   zscrypt.<locals>.<listcomp>œ  s=   ø€ ð Bð Bð BØð ˆc�#˜‘-ÐÔ ð Bð Bð Br,   r   )Úbit_sizer!   rH   Ú_raw_scrypt_libÚscryptROMixÚ_raw_salsa20_libÚSalsa20_8_corer   r   r   r   rz   )r#   r$   rw   ÚNÚrr2   r~   Úprf_hmac_sha256Ústage_1rŽ   ÚcoreÚdata_outÚflowru   Ú
buffer_outÚresultr†   r‹   s     `              @r*   Úscryptrš   Q  sÝ  øø€ ðN 	�X�a‰[Œ[˜1‰_Ñ Ò"Ð"ÝÐ1Ñ2Ô2Ð2ØˆG‚|€|Ý˜Ñ(Ô(Ð(ØÐ S¨1¡WÑ-Ò-Ð-ÝÐ-Ñ.Ô.Ð.àBÐB€Oå�X˜t Q¨¡W¨q¡[°!¸ÐIÑIÔI€Gå!Ô-€KÝÔ*€Dð €HÝ˜1‘”ð 
3ð 
3ˆØ�S‰j˜1‰nˆÝ)¨#°©'Ñ2Ô2ˆ
Ø�˜W S¨3°°q±©=Ð%8Ô9Ø'Ý% c¨A¡gÑ.Ô.ØØ!ñ	#ô #ˆð
 ð 	GÝÐ<¸vÑEÑFÔFÐFØ•n ZÑ0Ô0Ð2Ñ2ˆˆå	�Ø—’˜Ñ"Ô"Ø˜(Ñ" AØ#ð
%ñ 
%ô 
%€Bð
 �1‚}€}Øˆ	ðBð Bð Bð Bð BÝ   G¨hÑ$6¸Ñ@Ô@ðBñ Bô B€Cà€Jr,   c                 óŽ  ‡— d}g Š| D ][}t          t          |¦  «        ¦  «        dd …                              d¦  «        }‰                     t	          |¦  «        ¦  «         Œ\d                     ‰¦  «        Šˆfd„t          dt          ‰¦  «        d¦  «        D ¦   «         }g }|d d…         D ]-}t          |d¦  «        }|                     ||         ¦  «         Œ.|d         }t          |d¦  «        dt          |¦  «        z
  z  }|                     ||         ¦  «         d	                     |¦  «        }t          |¦  «        S )
Nú@./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789r:   r   r,   c                 ó*   •— g | ]}‰||d z   …         ‘ŒS )é   r7   ©r<   ru   Úbitss     €r*   rx   z"_bcrypt_encode.<locals>.<listcomp>ª  ó%   ø€ ÐAÐAÐA #ˆd�3�s˜1‘u�9ŒoÐAÐAÐAr,   r   rž   rr   Ú )
Úbinr   Úzfillry   r
   rz   rB   r    Úintr   )	Údatar3   ÚcÚbits_cÚbits6r™   Úgru   r    s	           @r*   Ú_bcrypt_encoder«   ¡  s1  ø€ ØJ€Aà€DØð "ð "ˆÝ•T˜!‘W”W‘”˜a˜b˜bÔ!×'Ò'¨Ñ*Ô*ˆØ�Š•D˜‘L”LÑ!Ô!Ð!Ð!Ø�8Š8�D‰>Œ>€DàAÐAÐAÐA­¨qµ#°d±)´)¸QÑ)?Ô)?ÐAÑAÔA€Eà€FØ�3�B�3ŒZð ð ˆÝ�!�Q‰iŒiˆØ�Š�a˜”fÑÔÐÐàˆbŒ	€AÝ
ˆa�‰)Œ)˜�C ™FœF™
Ñ
#€CØ
‡M‚M�!�C”&ÑÔÐØ�WŠW�V‰_Œ_€Få�6‰?Œ?Ðr,   c           	      ó‚  ‡	— d}g Š	t          | ¦  «        D ]V}|                     |¦  «        }t          |¦  «        dd …                              d¦  «        }‰	                     |¦  «         ŒWd                     ‰	¦  «        Š	t          | ¦  «        dz  }|dk    rt          d¦  «        ‚|dk    r‰	d d…         Š	n|d	k    r
‰	d d
…         Š	ˆ	fd„t          dt          ‰	¦  «        d¦  «        D ¦   «         }g }|D ]2}|                     t          t          |d¦  «        ¦  «        ¦  «         Œ3d                     |¦  «        }|S )Nrœ   r:   rž   r¢   é   r   zIncorrect lengthéüÿÿÿé   éþÿÿÿc                 ó*   •— g | ]}‰||d z   …         ‘ŒS )r   r7   rŸ   s     €r*   rx   z"_bcrypt_decode.<locals>.<listcomp>Ë  r¡   r,   r   r   r,   )r   Úfindr£   r¤   ry   rz   r    r!   rB   r	   r¥   )
r¦   r3   r§   ru   r©   Úmodulo4Úbits8r™   rª   r    s
            @r*   Ú_bcrypt_decoderµ   ¹  sC  ø€ ØJ€Aà€DÝ�4‰[Œ[ð ð ˆØ�fŠf�Q‰iŒiˆÝ�C‘”˜˜˜”×"Ò" 1Ñ%Ô%ˆØ�Š�EÑÔÐÐØ�7Š7�4‰=Œ=€Då�$‰iŒi˜!‰m€GØ�!‚|€|ÝÐ+Ñ,Ô,Ð,Ø	�AŠˆØ�C�R�CŒyˆˆØ	�AŠˆØ�C�R�CŒyˆàAÐAÐAÐA­¨qµ#°d±)´)¸QÑ)?Ô)?ÐAÑAÔA€Eà€FØð 'ð 'ˆØ�Š•d�3˜q !™9œ9‘o”oÑ&Ô&Ð&Ð&Ø�XŠX�fÑÔ€Fà€Mr,   c                 ó   — ddl m} t          | ¦  «        dk    rt          d¦  «        ‚d|cxk    rdk    sn t          d¦  «        ‚|                     | |j        |||¦  «        }|}t          d¦  «        D ]}|                     |¦  «        }Œ|S )	Nr   )Ú_EKSBlowfishéH   z6The password is too long. It must be 72 bytes at most.r­   é   z-bcrypt cost factor must be in the range 4..31é@   )ÚCryptodome.Cipherr·   r    r!   r   ÚMODE_ECBrB   Úencrypt)	r#   Úcostr$   ÚconstantÚinvertr·   ÚcipherÚctextÚ_s	            r*   Ú_bcrypt_hashrÄ   Õ  sª   € Ø.Ð.Ð.Ð.Ð.Ð.å
ˆ8�}„}�rÒÐÝÐQÑRÔRÐRà�ˆOˆOŠOˆO˜ŠOˆOˆOˆOÝÐHÑIÔIÐIà×Ò˜h¨Ô(=¸tÀTÈ6ÑRÔR€FØ€EÝ�2‰YŒYð &ð &ˆØ—’˜uÑ%Ô%ˆˆØ€Lr,   c                 ó   — t          | d¦  «        } |                      t          d¦  «        d         ¦  «        dk    rt          d¦  «        ‚t	          | ¦  «        dk     r| dz  } |€t          d¦  «        }t	          |¦  «        dk    rt          d	¦  «        ‚t          | ||d
d¦  «        }dt          t          |¦  «         	                    d¦  «        ¦  «        z   }dt          |¦  «        z   }t          |dd…         ¦  «        }d|z   |z   |z   S )a>  Hash a password into a key, using the OpenBSD bcrypt protocol.

    Args:
      password (byte string or string):
        The secret password or pass phrase.
        It must be at most 72 bytes long.
        It must not contain the zero byte.
        Unicode strings will be encoded as UTF-8.
      cost (integer):
        The exponential factor that makes it slower to compute the hash.
        It must be in the range 4 to 31.
        A value of at least 12 is recommended.
      salt (byte string):
        Optional. Random byte string to thwarts dictionary and rainbow table
        attacks. It must be 16 bytes long.
        If not passed, a random value is generated.

    Return (byte string):
        The bcrypt hash

    Raises:
        ValueError: if password is longer than 72 bytes or if it contains the zero byte

   zutf-8r   rr   z#The password contains the zero byter¸   rL   Nr-   z!bcrypt salt must be 16 bytes longs   OrpheanBeholderScryDoubtTó   $r:   s   $2a)r   r²   r	   r!   r    r   rÄ   r
   Ústrr¤   r«   )r#   r¾   r$   rÂ   Úcost_encÚsalt_encÚhash_encs          r*   ÚbcryptrË   å  s  € õ4 �x Ñ)Ô)€Hà‡}‚}•T˜!‘W”W˜Q”ZÑ Ô  BÒ&Ð&ÝÐ>Ñ?Ô?Ð?å
ˆ8�}„}�rÒÐØ�GÑˆà€|Ý Ñ#Ô#ˆÝ
ˆ4�y„y�B‚€ÝÐ<Ñ=Ô=Ð=å˜ 4¨Ð/JÈDÑQÔQ€Eà•d�3˜t™9œ9Ÿ?š?¨1Ñ-Ô-Ñ.Ô.Ñ.€HØ•n TÑ*Ô*Ñ*€HÝ˜e C R CœjÑ)Ô)€HØ�HÑ˜xÑ'¨(Ñ2Ð2r,   c                 ó  — t          |¦  «        }t          |¦  «        dk    rt          dt          |¦  «        z  ¦  «        ‚|dd…         dk    rt          d¦  «        ‚t          j        d¦  «        }|                     |¦  «        }|st          d¦  «        ‚t          |                     d	¦  «        ¦  «        }d|cxk    rd
k    sn t          d¦  «        ‚t          |                     d¦  «        ¦  «        }t          | ||¦  «        }t          d¦  «        }t          j        d||¬¦  «                             ¦   «         }t          j        d||¬¦  «                             ¦   «         }	||	k    rt          d¦  «        ‚dS )aé  Verify if the provided password matches the given bcrypt hash.

    Args:
      password (byte string or string):
        The secret password or pass phrase to test.
        It must be at most 72 bytes long.
        It must not contain the zero byte.
        Unicode strings will be encoded as UTF-8.
      bcrypt_hash (byte string, bytearray):
        The reference bcrypt hash the password needs to be checked against.

    Raises:
        ValueError: if the password does not match
    é<   z;Incorrect length of the bcrypt hash: %d bytes instead of 60Nr­   s   $2a$zUnsupported prefixs@   \$2a\$([0-9][0-9])\$([A-Za-z0-9./]{22,22})([A-Za-z0-9./]{31,31})zIncorrect bcrypt hash formatr   r¹   zIncorrect costr:   r-   é    )Údigest_bitsrE   r¦   zIncorrect bcrypt hash)r   r    r!   ÚreÚcompileÚmatchr¥   Úgrouprµ   rË   r   r   r   r"   )
r#   Úbcrypt_hashr2   r’   r¾   r$   Úbcrypt_hash2ÚsecretÚmac1Úmac2s
             r*   Úbcrypt_checkrÙ     so  € õ  ˜+Ñ&Ô&€Kå
ˆ;ÑÔ˜2ÒÐÝÐVÕY\Ð]hÑYiÔYiÑiÑjÔjÐjà�2�A�2„˜'Ò!Ð!ÝÐ-Ñ.Ô.Ð.å
Œ
ÐWÑXÔX€AØ	�Š�ÑÔ€AØð 9ÝÐ7Ñ8Ô8Ð8åˆq�wŠw�q‰zŒz‰?Œ?€DØ�ˆOˆOŠOˆO˜ŠOˆOˆOˆOÝÐ)Ñ*Ô*Ð*å˜!Ÿ'š' !™*œ*Ñ%Ô%€Då˜8 T¨4Ñ0Ô0€Lå˜bÑ!Ô!€FåŒ; 3¨F¸ÐEÑEÔE×LÒLÑNÔN€DÝŒ; 3¨F¸ÐFÑFÔF×MÒMÑOÔO€DØˆt‚|€|ÝÐ0Ñ1Ô1Ð1ð €|r,   )r   N)r-   r   NN)r   N)r   r1   )-rÐ   r@   Ú	functoolsr   ÚCryptodome.Util.py3compatr   r   r   r   r   r	   r
   ÚCryptodome.Hashr   r   r   r   r   ÚCryptodome.Util.strxorr   ÚCryptodome.Randomr   ÚCryptodome.Util.numberr   rŒ   r   r   ÚCryptodome.Util._raw_apir   r   r   r   r�   r�   r+   rH   ÚobjectrJ   r‡   rš   r«   rµ   rÄ   rË   rÙ   r7   r,   r*   ú<module>râ      sR  ðð2 
€	€	€	Ø €€€Ø Ð Ð Ð Ð Ð ð5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð >Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ø )Ð )Ð )Ð )Ð )Ð )Ø .Ð .Ð .Ð .Ð .Ð .Ø QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ Qð<ð <ð <ð <ð <ð <ð <ð <ð <ð <ð <ð <ð -Ð,Ð-Iðñô Ð ð ,Ð+Ð,Iðñô €ð("ð ("ð ("ð ("ðVNð Nð Nð Nðb]ð ]ð ]ð ]ð ]ˆ6ñ ]ô ]ð ]ð@: ð : ð : ð : ð|Mð Mð Mð Mð`ð ð ð0ð ð ð8ð ð ð ,3ð ,3ð ,3ð ,3ð^*2ð *2ð *2ð *2ð *2r,   