
    Tf"                     Z    d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 g dZ
d Zd	 ZddZdS )a  
RFC 6979:
    Deterministic Usage of the Digital Signature Algorithm (DSA) and
    Elliptic Curve Digital Signature Algorithm (ECDSA)

    http://tools.ietf.org/html/rfc6979

Many thanks to Coda Hale for his implementation in Go language:
    https://github.com/codahale/rfc6979
    N)hexlify   )number_to_stringnumber_to_string_crop
bit_length)hmac_compat)r   bits2intbits2octets
generate_kc                     t          t          |           d          }t          |           dz  }||k    r|||z
  z	  S |S )N      )intr   len)dataqlenxls       ?/var/www/html/env/lib/python3.11/site-packages/ecdsa/rfc6979.pyr	   r	      sB    GDMM2AD		AA4xxQXH    c                 v    t          | t          |                    }||z
  }|dk     r|}t          ||          S )Nr   )r	   r   r   )r   orderz1z2s       r   r
   r
       s@    	$
5))	*	*B	eB	Avv U+++r   r   c                    t          |           } |            j        }|dz   dz  }t          t          ||                     t          t	          ||                     t          |          f}	d|z  }
d|z  }t          j        ||          }|                    |
dz              |	D ]}|                    |           |                                }t          j        ||
|                                          }
t          j        ||          }|                    |
dz              |	D ]}|                    |           |                                }t          j        ||
|                                          }
	 d}t          |          |k     r@t          j        ||
|                                          }
||
z  }t          |          |k     @t          ||          }d|cxk    r| k     rn n|d	k    r|S |dz  }t          j        ||
dz   |                                          }t          j        ||
|                                          }
)
aD  
    Generate the ``k`` value - the nonce for DSA.

    :param int order: order of the DSA generator used in the signature
    :param int secexp: secure exponent (private key) in numeric form
    :param hash_func: reference to the same hash function used for generating
        hash, like :py:class:`hashlib.sha1`
    :param bytes data: hash in binary form of the signing data
    :param int retry_gen: how many good 'k' values to skip before returning
    :param bytes extra_entropy: additional added data in binary form as per
        section-3.6 of rfc6979
    :rtype: int
       r          )	digestmodTr   r   r   )r   digest_sizer   r   r
   hmacnewupdatedigestr   r	   )r   secexp	hash_funcr   	retry_genextra_entropyr   holenrolenbxvkitsecrets                  r   r   r   +   sX    eDIKK#EAX!OE$VU3344Ke,,--M""
B 	%A 	%A 	i(((AHHQ[  		

A 	Ay!!((**A 	i(((AHHQ[  		

A 	Ay!!((**A/ !ffunnAy))0022AFA !ffunn
 !T""A~~NIHQGY//6688HQ9%%,,..%/r   )r   r   )__doc__r!   binasciir   utilr   r   r   _compatr   __all__r	   r
   r    r   r   <module>r7      s   	 	        E E E E E E E E E E            
 B
A
A  , , ,F/ F/ F/ F/ F/ F/r   