
    &g              	           d Z ddlmZmZmZ ddedededefdZd	gZ	e
d
k    rY ed           ddlZ ed          D ]1Z ej                    \  ZZer nedz  dk    rer edez             2 ed           dS dS )zFunctions 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                 "    	 t          j                             j        }nr# t          $ re}t	          d                    d                    t          t           j                                                                                |d}~ww xY w|d|z  k    r$t          d                    |                    d                     fd	t          t          j        ||          d
z             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   r   K   | ]1}t          j        t          j        |d           z             V  2dS )   )	fill_size)method_nameN)r   compute_hashr   	int2bytes).0counterr	   r   s     >/var/www/api/venv/lib/python3.11/site-packages/rsa/pkcs1_v2.py	<genexpr>zmgf1.<locals>.<genexpr>H   sf        
 	 	9&w!<<<<	
 	
 	
     r      )r   HASH_METHODSdigest_sizeKeyError
ValueErrorformatjoinsortedkeysOverflowErrorranger   ceil_div)r   r   r	   r   exoutputs   ` `   r   mgf1r'      sE   ,(022>   KRR))F5+=+B+B+D+D$E$EFF S  
 
 		 ;&'';;A6' <B < <
 
 	
 XX     
 V_V[AAAEFF    F '6'?s   # 
BA BB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tests r   r   <module>r8      s*            5 5u 5c 53 5U 5 5 5 5r  z	E
3444NNNt & &+GO--5 	E3;!E*u$%%%	E/ r   