
    ":h
                     F    d Z ddlZddlmZ ddlmZmZ d Zd Zd Z	d
d	Z
y)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_cropc                 P    t        |       }|j                  d      }t        |      S )Nz-0b)binlstriplen)numss     `/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/static_dependencies/ecdsa/rfc6979.py
bit_lengthr      s!    CA	Aq6M    c                 f    t        t        |       d      }t        |       dz  }||kD  r|||z
  z	  S |S )N      )intr   r
   )dataqlenxls       r   bits2intr      s9    GDM2AD	AA4xQXHr   c                 \    t        | t        |            }||z
  }|dk  r|}t        ||      S )Nr   )r   r   r   )r   orderz1z2s       r   bits2octetsr   !   s5    	$
5)	*B	eB	Av U++r   c                 J   t        |       } |       j                  }|dz   dz  }t        ||       t        ||       z   |z   }	d|z  }
d|z  }t	        j
                  ||
dz   |	z   |      j                         }t	        j
                  ||
|      j                         }
t	        j
                  ||
dz   |	z   |      j                         }t	        j
                  ||
|      j                         }
	 d}t        |      |k  r9t	        j
                  ||
|      j                         }
||
z  }t        |      |k  r9t        ||      }|dk\  r|| k  r|dk  r|S |dz  }t	        j
                  ||
dz   |      j                         }t	        j
                  ||
|      j                         }
)a  
        order - order of the DSA generator used in the signature
        secexp - secure exponent (private key) in numeric form
        hash_func - reference to the same hash function used for generating hash
        data - hash in binary form of the signing data
        retry_gen - int - how many good 'k' values to skip before returning
        extra_entropy - extra added data in binary form as per section-3.6 of
            rfc6979
       r          r   r   r   )	r   digest_sizer   r   hmacnewdigestr
   r   )r   secexp	hash_funcr   	retry_genextra_entropyr   holenrolenbxvktsecrets                 r   
generate_kr1   ,   s    eDK##EAXNE	&%	(;tU+C	C
B 	%A 	%A 	AK"$i0779A 	Ay!((*A 	AK"$i0779A 	Ay!((*A  !funAy)002AFA !fun
 !T"Q;6E>A~Q	HHQGY/668HHQ9%,,.' r   )r   r   )__doc__r#   binasciir   utilr   r   r   r   r   r1    r   r   <module>r6      s)   	   9,8/r   