
    ei
                     H    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
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_cropc                 h    t          |           }|                    d          }t          |          S )Nz-0b)binlstriplen)numss     d/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/static_dependencies/ecdsa/rfc6979.py
bit_lengthr      s'    CA	Aq66M    c                     t          t          |           d          }t          |           dz  }||k    r|||z
  z	  S |S )N      )intr   r
   )dataqlenxls       r   bits2intr      sB    GDMM2AD		AA4xxQXHr   c                 v    t          | t          |                    }||z
  }|dk     r|}t          ||          S )Nr   )r   r   r   )r   orderz1z2s       r   bits2octetsr   !   s@    	$
5))	*	*B	eB	Avv U+++r   r   c                    t          |           } |            j        }|dz   dz  }t          ||           t          ||           z   |z   }	d|z  }
d|z  }t	          j        ||
dz   |	z   |                                          }t	          j        ||
|                                          }
t	          j        ||
dz   |	z   |                                          }t	          j        ||
|                                          }
	 d}t          |          |k     r@t	          j        ||
|                                          }
||
z  }t          |          |k     @t          ||          }|dk    r|| k     r|dk    r|S |dz  }t	          j        ||
dz   |                                          }t	          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          Tr   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IKK#EAXNE	&%	(	(;tU+C+C	C
B 	%A 	%A 	AK"$i007799A 	Ay!!((**A 	AK"$i007799A 	Ay!!((**A/ !ffunnAy))0022AFA !ffunn
 !T""Q;;6E>>A~~Q	HQGY//6688HQ9%%,,..'/r   )r   r   )__doc__r#   binasciir   utilr   r   r   r   r   r1    r   r   <module>r6      s   	 	        9 9 9 9 9 9 9 9    , , ,8/ 8/ 8/ 8/ 8/ 8/r   