File: //usr/local/CyberCP/lib64/python3.10/site-packages/ecdsa/__pycache__/rfc6979.cpython-310.pyc
o
�h" � @ s^ d Z ddlZddlmZ ddlmZmZmZ ddlm Z g d�Z
dd � Zd
d� Zdd
d�Z
dS )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 C s2 t t| �d�}t| �d }||kr||| ? S |S )N� � )�intr �len)�data�qlen�x�l� r �@/usr/local/CyberCP/lib/python3.10/site-packages/ecdsa/rfc6979.pyr s
r c C s, t | t|��}|| }|dk r|}t||�S )Nr )r r r )r �order�z1�z2r r r r s
r � c C sz t | �}|� j}|d d }tt|| ��tt|| ��t|�f} d| }
d| }tj||d�}|�|
d � | D ]}|�|� q7|�� }t�||
|��� }
tj||d�}|�|
d � | D ]}|�|� q\|�� }t�||
|��� }
d}
t |
�|k r�t�||
|��� }
|
|
7 }
t |
�|k szt
|
|�}d| kr�| k r�n n
|d kr�|S |d8 }t�||
d |��� }t�||
|��� }
qr)
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�secretr r r r
+ sF ��
�r
)r r )�__doc__r �binasciir �utilr r r �_compatr �__all__r r r
r r r r �<module> s