
    [Ah"                     Z    S r SSKrSSKJr  SSKJrJrJr  SSKJ	r	  / SQr
S rS	 rSS
 jrg)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                 d    [        [        U 5      S5      n[        U 5      S-  nX1:  a  X#U-
  -	  $ U$ )N      )intr   len)dataqlenxls       TC:\Users\julio\Documents\inmobiliaria_backend\env\Lib\site-packages\ecdsa/rfc6979.pyr	   r	      s5    GDM2AD	AAxXH    c                 Z    [        U [        U5      5      nX!-
  nUS:  a  Un[        X15      $ )Nr   )r	   r   r   )r   orderz1z2s       r   r
   r
       s1    	$
5)	*B	B	Av ++r   c                 $   [        U 5      nU" 5       R                  nUS-   S-  n[        [        X5      5      [        [	        X05      5      [        U5      4n	SU-  n
SU-  n[
        R                  " XS9nUR                  U
S-   5        U	 H  nUR                  U5        M     UR                  5       n[
        R                  " XU5      R                  5       n
[
        R                  " XS9nUR                  U
S-   5        U	 H  nUR                  U5        M     UR                  5       n[
        R                  " XU5      R                  5       n
 Sn[        U5      U:  a:  [
        R                  " XU5      R                  5       n
X-  n[        U5      U:  a  M:  [        X5      nSUs=::  a  U :  a  O  OUS::  a  U$ US-  n[
        R                  " XS-   U5      R                  5       n[
        R                  " XU5      R                  5       n
M  )	a  
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          )	digestmodr   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   +   s    eDK##EAX!OE$V34K,-M"
B 	%A 	%A 	(AHHQ[	 	
A 	y!((*A 	(AHHQ[	 	
A 	y!((*A  !funy)002AFA !fun
 !"A~NIHHQGY/668HHQ9%,,.% r   )r   r   )__doc__r!   binasciir   utilr   r   r   _compatr   __all__r	   r
   r    r   r   <module>r7      s3   	   E E  
 B,F/r   