
    E#i
                     H    S r SSKrSSKJr  SSKJrJr  S 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_cropc                 P    [        U 5      nUR                  S5      n[        U5      $ )Nz-0b)binlstriplen)numss     `/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/ecdsa/rfc6979.py
bit_lengthr      s!    CA	Aq6M    c                 d    [        [        U 5      S5      n[        U 5      S-  nX1:  a  X#U-
  -	  $ U$ )N      )intr   r
   )dataqlenxls       r   bits2intr      s5    GDM2AD	AAxXHr   c                 Z    [        U [        U5      5      nX!-
  nUS:  a  Un[        X15      $ )Nr   )r   r   r   )r   orderz1z2s       r   bits2octetsr   !   s1    	$
5)	*B	B	Av ++r   c                 N   [        U 5      nU" 5       R                  nUS-   S-  n[        X5      [        X05      -   U-   n	SU-  n
SU-  n[        R
                  " XS-   U	-   U5      R                  5       n[        R
                  " XU5      R                  5       n
[        R
                  " XS-   U	-   U5      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US:  a  X:  a  US::  a  U$ US-  n[        R
                  " XS-   U5      R                  5       n[        R
                  " XU5      R                  5       n
M  )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	&	(;t+C	C
B 	%A 	%A 	K"$i0779A 	y!((*A 	K"$i0779A 	y!((*A  !funy)002AFA !fun
 !"Q;6>A~Q	HHQGY/668HHQ9%,,.' r   )r   r   )__doc__r#   binasciir   utilr   r   r   r   r   r1    r   r   <module>r6      s)   	   9,8/r   