o
    ýÞhy  ã                	   @   s    d Z ddlmZmZmZ ddedededefdd	„Zd	gZ	e
d
krNedƒ ddlZedƒD ]Ze ¡ \ZZer9 ned dkrGerGede ƒ q-edƒ dS dS )z¿Functions for PKCS#1 version 2 encryption and signing

This module implements certain functionality from PKCS#1 version 2. Main
documentation is RFC 2437: https://tools.ietf.org/html/rfc2437
é    )ÚcommonÚpkcs1Ú	transformúSHA-1ÚseedÚlengthÚhasherÚreturnc              
      s¢   z	t jˆ  ƒ j}W n ty& } ztdjd tt j ¡ ƒ¡d�ƒ|‚d}~ww |d| kr6t	dj|ˆ d�ƒ‚d ‡ ‡fd	d
„t
t ||¡d ƒD ƒ¡}|d|… S )aˆ  
    MGF1 is a Mask Generation Function based on a hash function.

    A mask generation function takes an octet string of variable length and a
    desired output length as input, and outputs an octet string of the desired
    length. The plaintext-awareness of RSAES-OAEP relies on the random nature of
    the output of the mask generation function, which in turn relies on the
    random nature of the underlying hash.

    :param bytes seed: seed from which mask is generated, an octet string
    :param int length: intended length in octets of the mask, at most 2^32(hLen)
    :param str hasher: hash function (hLen denotes the length in octets of the hash
        function output)

    :return: mask, an octet string of length `length`
    :rtype: bytes

    :raise OverflowError: when `length` is too large for the specified `hasher`
    :raise ValueError: when specified `hasher` is invalid
    z=Invalid `hasher` specified. Please select one of: {hash_list}z, )Ú	hash_listNl        zmDesired length should be at most 2**32 times the hasher's output length ({hash_length} for {hasher} function))Úhash_lengthr   ó    c                 3   s,   � | ]}t jˆtj|d d� ˆ d�V  qdS )é   )Ú	fill_size)Úmethod_nameN)r   Úcompute_hashr   Ú	int2bytes)Ú.0Úcounter©r   r   © úL/var/www/html/premium_crap/venv/lib/python3.10/site-packages/rsa/pkcs1_v2.pyÚ	<genexpr>H   s   € üþ
ÿzmgf1.<locals>.<genexpr>é   )r   ÚHASH_METHODSÚdigest_sizeÚKeyErrorÚ
ValueErrorÚformatÚjoinÚsortedÚkeysÚOverflowErrorÚranger   Úceil_div)r   r   r   r   ÚexÚoutputr   r   r   Úmgf1   s0   ÿÿü€ÿýÿû	r&   Ú__main__z'Running doctests 1000x or until failureNiè  éd   z%i timeszDoctests done)r   )Ú__doc__Úrsar   r   r   ÚbytesÚintÚstrr&   Ú__all__Ú__name__ÚprintÚdoctestr"   ÚcountÚtestmodÚfailuresÚtestsr   r   r   r   Ú<module>   s"   9ÿ€ô